-
Notifications
You must be signed in to change notification settings - Fork 357
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
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc18f08
Empty tables fixes
pannarale 1b43cf7
Fix table when there are no loud offsource triggers
pannarale 56665c2
First review comment
pannarale 20c6cba
Update bin/pygrb/pycbc_pygrb_page_tables
pannarale b1b3c7f
Second set of review comment
pannarale 0f6217e
Update bin/pygrb/pycbc_pygrb_page_tables
pannarale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
@@ -497,10 +502,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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this assignment is more readable in two lines. |
||
# 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 +542,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 +550,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))] | ||
pannarale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 +569,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)) | ||
pannarale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
td = [np.asarray(d) for d in td] | ||
html_table = pycbc.results.html_table(td, th, | ||
format_strings=format_strings, | ||
|
@@ -646,6 +657,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))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment on similar block above. |
||
|
||
# Write to h5 file | ||
with HFile(qf_h5_outfile, 'w') as qf_h5_fp: | ||
for i, key in enumerate(th): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on similar block below.