Skip to content

Commit

Permalink
Fix problem on pycbc live due to numpy 2 (gwastro#4914)
Browse files Browse the repository at this point in the history
* Modify the sanity checks of the PSD to be compatible with numpy 2.x
and add sanity check on the PSD of the XML file.
Modify gracedb.py to be up to date with numpy2.x

* New commit to add the import to pass test

* Correcting the import of LigoLWEventSource

* Satisfy codeclimate

---------

Co-authored-by: jacquot <jacquot@>
Co-authored-by: Tito Dal Canton <[email protected]>
  • Loading branch information
Thomas-JACQUOT and titodalcanton authored Oct 23, 2024
1 parent 7ecfd8d commit e89f1be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions examples/live/check_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ligo.lw.utils import load_filename as load_xml_doc
from ligo.lw import lsctables
from pycbc import conversions as conv

from ligo.skymap.io import LigoLWEventSource

def close(a, b, c):
return abs(a - b) <= c
Expand Down Expand Up @@ -39,7 +39,7 @@ def check_single_results(args):
continue

# check that PSD is sane
psd = group['psd'][:] / pycbc.DYN_RANGE_FAC ** 2
psd = group['psd'][:].astype(np.float64) / pycbc.DYN_RANGE_FAC ** 2
psd_df = group['psd'].attrs['delta_f']
psd_f = np.arange(len(psd)) * psd_df
psd_epoch = group['psd'].attrs['epoch']
Expand Down Expand Up @@ -142,6 +142,17 @@ def check_found_events(args):
si_table = lsctables.SnglInspiralTable.get_table(xmldoc)
ci_table = lsctables.CoincInspiralTable.get_table(xmldoc)

#check the PSD of the XML file
event, = LigoLWEventSource(ctrigfp, psd_file=ctrigfp, coinc_def=None).values()
for entry in event.singles:
psd = entry.psd.data.data
if (psd < 1e-48).any() \
or (psd > 1e-40).any() \
or not np.isfinite(psd).all() :
log.error('Invalid PSD in %s', ctrigfp)
found_fail = True


trig_props['tc'][x] = si_table[0].end
trig_props['mass1'][x] = si_table[0].mass1
trig_props['mass2'][x] = si_table[0].mass2
Expand Down
5 changes: 4 additions & 1 deletion pycbc/io/gracedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ def __init__(self, coinc_ifos, ifos, coinc_results, **kwargs):
fseries = lal.CreateREAL8FrequencySeries(
"psd", psd.epoch, kwargs['low_frequency_cutoff'], psd.delta_f,
lal.StrainUnit**2 / lal.HertzUnit, len(psd) - kmin)
fseries.data.data = psd.numpy()[kmin:] / pycbc.DYN_RANGE_FAC ** 2.0
fseries.data.data = (
psd.numpy()[kmin:].astype(numpy.float64)
/ pycbc.DYN_RANGE_FAC ** 2.0
)
psds_lal[ifo] = fseries
make_psd_xmldoc(psds_lal, outdoc)

Expand Down

0 comments on commit e89f1be

Please sign in to comment.