Skip to content

Commit

Permalink
Handle RA and dec in radians in pygrb (#4787)
Browse files Browse the repository at this point in the history
* Always handle RA and dec in radians (but keep displaying them in degrees in the summary table)

* Better args in grb info table
  • Loading branch information
pannarale authored Jun 17, 2024
1 parent c535963 commit fa0c248
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
30 changes: 15 additions & 15 deletions bin/pygrb/pycbc_pygrb_grb_info_table
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ __program__ = "pycbc_pygrb_grb_info_table"
parser = argparse.ArgumentParser(description=__doc__, formatter_class=
argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--version", action="version", version=__version__)
parser.add_argument("--trigger-time", action="store",
default=None, required=True,
parser.add_argument("--trigger-time", type=int,
required=True,
help="GPS time of the GRB.")
parser.add_argument("--ra", action="store",
default=None, required=True,
help="Right ascention (degrees) of the GRB.")
parser.add_argument("--dec", action="store",
default=None, required=True,
help="Declination (degrees) of the GRB.")
parser.add_argument("--sky-error", action="store",
parser.add_argument("--ra", type=float,
required=True,
help="Right ascension (radians) of the GRB.")
parser.add_argument("--dec", type=float,
required=True,
help="Declination (radians) of the GRB.")
parser.add_argument("--sky-error", type=float,
default=0, required=False,
help="Sky-localisation error (degrees) of the GRB.")
help="Sky-localisation error (radians) of the GRB.")
parser.add_argument("--ifos", action="store", nargs='+',
default=None, required=True,
help="List containing the active IFOs.")
Expand All @@ -69,14 +69,14 @@ data = [[]]
data[0].append(str(opts.trigger_time))
headers.append('GPS Time')

utc_time = datetime(*lal.GPSToUTC(int(opts.trigger_time))[0:6]).strftime("%B %d %Y, %H:%M:%S UTC")
utc_time = datetime(*lal.GPSToUTC(opts.trigger_time)[0:6]).strftime("%B %d %Y, %H:%M:%S UTC")
data[0].append(utc_time)
headers.append('Coordinated Universal Time')

data[0].append(str(opts.ra))
data[0].append(str(numpy.rad2deg(opts.ra)))
headers.append('R.A. (deg)')

data[0].append(str(opts.dec))
data[0].append(str(numpy.rad2deg(opts.dec)))
headers.append('Dec (deg)')

data[0].append(str(opts.sky_error))
Expand All @@ -88,8 +88,8 @@ headers.append('IFOs')
for ifo in opts.ifos:
antenna = Detector(ifo)
factor = get_antenna_dist_factor(antenna,
numpy.deg2rad(float(opts.ra)),
numpy.deg2rad(float(opts.dec)),
opts.ra,
opts.dec,
float(opts.trigger_time))
data[0].append('%.3f' % factor)
headers.append(ifo + ' Antenna Factor')
Expand Down
12 changes: 6 additions & 6 deletions bin/pygrb/pycbc_pygrb_page_tables
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def load_missed_found_injections(hdf_file, ifos, snr_threshold, bank_file,
found_data['rec_mass1'],
found_data['rec_mass2'])
# Recovered RA and Dec
found_data['rec_ra'] = np.degrees(inj_data['network/ra'][...])
found_data['rec_dec'] = np.degrees(inj_data['network/dec'][...])
found_data['rec_ra'] = inj_data['network/ra'][...]
found_data['rec_dec'] = inj_data['network/dec'][...]
# Statistics values
for param in ['coherent_snr', 'reweighted_snr', 'null_snr']:
found_data[param] = inj_data['network/%s' % param][...]
Expand Down Expand Up @@ -375,8 +375,8 @@ if lofft_outfile:
mchirps[trig_index],
bank_data['spin1z'][trig_data['network/template_id'][trig_index]],
bank_data['spin2z'][trig_data['network/template_id'][trig_index]],
np.degrees(trig_data['network/ra'][trig_index]),
np.degrees(trig_data['network/dec'][trig_index]),
trig_data['network/ra'][trig_index],
trig_data['network/dec'][trig_index],
trig_data['network/coherent_snr'][trig_index],
trig_data['network/my_network_chisq'][trig_index],
trig_data['network/null_snr'][trig_index]]
Expand Down Expand Up @@ -500,8 +500,8 @@ if onsource_file:
mchirps[on_trigs['network/template_id'][trig_index]],
bank_data['spin1z'][on_trigs['network/template_id'][trig_index]],
bank_data['spin2z'][on_trigs['network/template_id'][trig_index]],
np.degrees(on_trigs['network/ra'][trig_index]),
np.degrees(on_trigs['network/dec'][trig_index]),
on_trigs['network/ra'][trig_index],
on_trigs['network/dec'][trig_index],
on_trigs['network/coherent_snr'][trig_index],
on_trigs['network/my_network_chisq'][trig_index],
on_trigs['network/null_snr'][trig_index]] + \
Expand Down
8 changes: 3 additions & 5 deletions pycbc/workflow/matched_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import os
import logging
from math import radians

from pycbc.workflow.core import FileList, make_analysis_dir
from pycbc.workflow.jobsetup import (select_matchedfilter_class,
Expand Down Expand Up @@ -243,12 +242,11 @@ def setup_matchedfltr_dax_generated_multi(workflow, science_segs, datafind_outs,

if match_fltr_exe == 'pycbc_multi_inspiral':
exe_class = select_matchedfilter_class(match_fltr_exe)
# Right ascension + declination provided in degrees,
# so convert to radians
# Right ascension + declination must be provided in radians
cp.set('inspiral', 'ra',
str(radians(float(cp.get('workflow', 'ra')))))
cp.get('workflow', 'ra'))
cp.set('inspiral', 'dec',
str(radians(float(cp.get('workflow', 'dec')))))
cp.get('workflow', 'dec'))
# At the moment we aren't using sky grids, but when we do this code
# might be used then.
# from pycbc.workflow.grb_utils import get_sky_grid_scale
Expand Down

0 comments on commit fa0c248

Please sign in to comment.