From e89f1be70ffab0238c9863380bc0d2a56e55ea80 Mon Sep 17 00:00:00 2001 From: Thomas-JACQUOT Date: Wed, 23 Oct 2024 10:38:41 +0200 Subject: [PATCH] Fix problem on pycbc live due to numpy 2 (#4914) * 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 Co-authored-by: Tito Dal Canton --- examples/live/check_results.py | 15 +++++++++++++-- pycbc/io/gracedb.py | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/live/check_results.py b/examples/live/check_results.py index 79fd67b9c8f..42b932ae88e 100755 --- a/examples/live/check_results.py +++ b/examples/live/check_results.py @@ -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 @@ -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'] @@ -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 diff --git a/pycbc/io/gracedb.py b/pycbc/io/gracedb.py index 0692eec3c60..52dc240a358 100644 --- a/pycbc/io/gracedb.py +++ b/pycbc/io/gracedb.py @@ -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)