From bc18f0883d865abfb01c5509c9709a0e519b7b16 Mon Sep 17 00:00:00 2001 From: Francesco Pannarale Date: Thu, 30 Jan 2025 04:47:33 -0800 Subject: [PATCH 1/6] Empty tables fixes --- bin/pygrb/pycbc_pygrb_page_tables | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/bin/pygrb/pycbc_pygrb_page_tables b/bin/pygrb/pycbc_pygrb_page_tables index dd584ab96b6..5e5ffaeb785 100755 --- a/bin/pygrb/pycbc_pygrb_page_tables +++ b/bin/pygrb/pycbc_pygrb_page_tables @@ -497,10 +497,11 @@ if onsource_file: on_trigs_bestnrs = on_trigs['network/reweighted_snr'][...] # Gather bestNR index - bestNR_event = np.argmax(on_trigs_bestnrs) - loud_on_bestnr_trigs, loud_on_bestnr = \ - (on_trigs['network/event_id'][bestNR_event], - on_trigs_bestnrs[bestNR_event]) + if on_trigs_bestnrs.size > 0: + bestNR_event = np.argmax(on_trigs_bestnrs) + loud_on_bestnr_trigs, loud_on_bestnr = \ + (on_trigs['network/event_id'][bestNR_event], + on_trigs_bestnrs[bestNR_event]) # If the loudest event has bestnr = 0, there is no event at all! if loud_on_bestnr == 0: loud_on_bestnr_trigs = None @@ -536,9 +537,6 @@ if onsource_file: [on_trigs[ifo+'/snr'][ifo_trig_index[ifo]] for ifo in ifos] + \ [loud_on_bestnr] td.append(d) - else: - td.append(["There are no events"] + [0 for number in range(11)] + - [0 for ifo in ifos] + [0]) # Table header th = ['p-value', 'GPS time', 'Rec. m1', 'Rec. m2', 'Rec. Mc', @@ -547,6 +545,10 @@ if onsource_file: td = list(zip(*td)) + # Handle the case in which there is no data to be placed in the table + if not td: + td = [[] for i in np.arange(len(th))] + # Write to h5 file logging.info("Writing loudest onsource trigger to h5 file.") with HFile(lont_h5_outfile, 'w') as lont_h5_fp: @@ -562,7 +564,11 @@ if onsource_file: format_strings.extend(['##.##' for ifo in ifos]) format_strings.extend(['##.##']) - # Table data + # Table data: assemble human readable message when no trigger is recovered + if not loud_on_bestnr_trigs: + td = [["There are no events"] + ["-" for number in range(11)] + + ["-" for ifo in ifos] + ["-"]] + td = list(zip(*td)) td = [np.asarray(d) for d in td] html_table = pycbc.results.html_table(td, th, format_strings=format_strings, @@ -646,6 +652,10 @@ if found_missed_file is not None: len(td)) td = list(zip(*td)) + # Handle the case in which there is no data to be placed in the table + if not td: + td = [[] for i in np.arange(len(th))] + # Write to h5 file with HFile(qf_h5_outfile, 'w') as qf_h5_fp: for i, key in enumerate(th): From 1b43cf7013565b096decb781d717569692c2c731 Mon Sep 17 00:00:00 2001 From: Francesco Pannarale Date: Thu, 30 Jan 2025 05:36:34 -0800 Subject: [PATCH 2/6] Fix table when there are no loud offsource triggers --- bin/pygrb/pycbc_pygrb_page_tables | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/pygrb/pycbc_pygrb_page_tables b/bin/pygrb/pycbc_pygrb_page_tables index 5e5ffaeb785..45252b0eb8a 100755 --- a/bin/pygrb/pycbc_pygrb_page_tables +++ b/bin/pygrb/pycbc_pygrb_page_tables @@ -430,6 +430,11 @@ if lofft_outfile: th.extend([ifo+' time shift (s)' for ifo in ifos]) th.append('BestNR') + # When len(offsource_trigs) == 0, the loop above leaves td = [] unchanged + # and this case needs to be handled adequately prior to moving on + if not td: + td = [[] for i in np.arange(len(th))] + # To ensure desired formatting in the h5 file and html table: # 1) "transpose" the data preserving its dtype td = list(zip(*td)) From 56665c2d678441397f3cbb692696f484b081e925 Mon Sep 17 00:00:00 2001 From: Francesco Pannarale Date: Thu, 30 Jan 2025 06:06:16 -0800 Subject: [PATCH 3/6] First review comment --- bin/pygrb/pycbc_pygrb_page_tables | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/pygrb/pycbc_pygrb_page_tables b/bin/pygrb/pycbc_pygrb_page_tables index 45252b0eb8a..f4cc3f23a17 100755 --- a/bin/pygrb/pycbc_pygrb_page_tables +++ b/bin/pygrb/pycbc_pygrb_page_tables @@ -504,9 +504,8 @@ if onsource_file: # Gather bestNR index if on_trigs_bestnrs.size > 0: bestNR_event = np.argmax(on_trigs_bestnrs) - loud_on_bestnr_trigs, loud_on_bestnr = \ - (on_trigs['network/event_id'][bestNR_event], - on_trigs_bestnrs[bestNR_event]) + loud_on_bestnr_trigs = on_trigs['network/event_id'][bestNR_event] + loud_on_bestnr = on_trigs_bestnrs[bestNR_event] # If the loudest event has bestnr = 0, there is no event at all! if loud_on_bestnr == 0: loud_on_bestnr_trigs = None From 20c6cba5c4d532a3bcfdcf209cf107bf038a79c5 Mon Sep 17 00:00:00 2001 From: Francesco Pannarale Date: Thu, 30 Jan 2025 15:06:37 +0100 Subject: [PATCH 4/6] Update bin/pygrb/pycbc_pygrb_page_tables Co-authored-by: Tito Dal Canton --- bin/pygrb/pycbc_pygrb_page_tables | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pygrb/pycbc_pygrb_page_tables b/bin/pygrb/pycbc_pygrb_page_tables index f4cc3f23a17..0dcaf7b8d89 100755 --- a/bin/pygrb/pycbc_pygrb_page_tables +++ b/bin/pygrb/pycbc_pygrb_page_tables @@ -551,7 +551,7 @@ if onsource_file: # Handle the case in which there is no data to be placed in the table if not td: - td = [[] for i in np.arange(len(th))] + td = [[]] * len(th) # Write to h5 file logging.info("Writing loudest onsource trigger to h5 file.") From b1b3c7f7dd487ed9809c07b5f1ab003048c44193 Mon Sep 17 00:00:00 2001 From: Francesco Pannarale Date: Thu, 30 Jan 2025 06:08:24 -0800 Subject: [PATCH 5/6] Second set of review comment --- bin/pygrb/pycbc_pygrb_page_tables | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/pygrb/pycbc_pygrb_page_tables b/bin/pygrb/pycbc_pygrb_page_tables index 0dcaf7b8d89..87df64bc37b 100755 --- a/bin/pygrb/pycbc_pygrb_page_tables +++ b/bin/pygrb/pycbc_pygrb_page_tables @@ -433,7 +433,7 @@ if lofft_outfile: # When len(offsource_trigs) == 0, the loop above leaves td = [] unchanged # and this case needs to be handled adequately prior to moving on if not td: - td = [[] for i in np.arange(len(th))] + td = [[]] * len(th) # To ensure desired formatting in the h5 file and html table: # 1) "transpose" the data preserving its dtype @@ -658,7 +658,7 @@ if found_missed_file is not None: # Handle the case in which there is no data to be placed in the table if not td: - td = [[] for i in np.arange(len(th))] + td = [[]] * len(th) # Write to h5 file with HFile(qf_h5_outfile, 'w') as qf_h5_fp: From 0f6217e2dbc34458594ecfe59abde9dccb52baad Mon Sep 17 00:00:00 2001 From: Francesco Pannarale Date: Thu, 30 Jan 2025 15:10:54 +0100 Subject: [PATCH 6/6] Update bin/pygrb/pycbc_pygrb_page_tables Co-authored-by: Tito Dal Canton --- bin/pygrb/pycbc_pygrb_page_tables | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/pygrb/pycbc_pygrb_page_tables b/bin/pygrb/pycbc_pygrb_page_tables index 87df64bc37b..1c9939195e7 100755 --- a/bin/pygrb/pycbc_pygrb_page_tables +++ b/bin/pygrb/pycbc_pygrb_page_tables @@ -570,9 +570,8 @@ if onsource_file: # Table data: assemble human readable message when no trigger is recovered if not loud_on_bestnr_trigs: - td = [["There are no events"] + ["-" for number in range(11)] + - ["-" for ifo in ifos] + ["-"]] - td = list(zip(*td)) + td = [list("-" * len(format_strings))] + td[0][0] = "There are no events" td = [np.asarray(d) for d in td] html_table = pycbc.results.html_table(td, th, format_strings=format_strings,