Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling empty table in PyGRB #5026

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions bin/pygrb/pycbc_pygrb_page_tables
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[]] * len(th)

# To ensure desired formatting in the h5 file and html table:
# 1) "transpose" the data preserving its dtype
td = list(zip(*td))
Expand Down Expand Up @@ -497,10 +502,10 @@ 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 = 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
Expand Down Expand Up @@ -536,9 +541,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',
Expand All @@ -547,6 +549,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 = [[]] * 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:
Expand All @@ -562,7 +568,10 @@ 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 = [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,
Expand Down Expand Up @@ -646,6 +655,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 = [[]] * len(th)

# Write to h5 file
with HFile(qf_h5_outfile, 'w') as qf_h5_fp:
for i, key in enumerate(th):
Expand Down
Loading