@@ -56,11 +56,23 @@ def add_wiki_row(outfile, cols):
56
56
57
57
58
58
def make_timeseries_plot (workflow , trig_file , snr_type , central_time ,
59
- shift_time , out_dir , ifo = None , tags = None ):
59
+ out_dir , ifo = None , seg_files = None ,
60
+ veto_file = None , tags = None ):
60
61
"""Adds a node for a timeseries of PyGRB results to the workflow"""
61
62
62
63
tags = [] if tags is None else tags
63
64
65
+ # Ensure that zero-lag data is used in these follow-up plots and store
66
+ # the slide-id option originally provided
67
+ orig_slide_id = None
68
+ if workflow .cp .has_option ('pygrb_plot_snr_timeseries' ,'slide-id' ):
69
+ orig_slide_id = workflow .cp .get ('pygrb_plot_snr_timeseries' ,'slide-id' )
70
+ workflow .cp .add_options_to_section (
71
+ 'pygrb_plot_snr_timeseries' ,
72
+ [('slide-id' , '0' )],
73
+ True
74
+ )
75
+
64
76
# Initialize job node with its tags
65
77
grb_name = workflow .cp .get ('workflow' , 'trigger-name' )
66
78
extra_tags = ['GRB' + grb_name ]
@@ -71,28 +83,42 @@ def make_timeseries_plot(workflow, trig_file, snr_type, central_time,
71
83
ifos = workflow .ifos , out_dir = out_dir ,
72
84
tags = tags + extra_tags ).create_node ()
73
85
node .add_input_opt ('--trig-file' , trig_file )
86
+ # Include the onsource trial if this is a follow up on the onsource
87
+ if 'loudest_onsource_event' in tags :
88
+ node .add_opt ('--onsource' )
89
+ # Pass the segments files and veto file
90
+ if seg_files :
91
+ node .add_input_list_opt ('--seg-files' , seg_files )
92
+ if veto_file :
93
+ node .add_input_opt ('--veto-file' , veto_file )
74
94
node .new_output_file_opt (workflow .analysis_time , '.png' ,
75
95
'--output-file' , tags = extra_tags )
76
96
# Quantity to be displayed on the y-axis of the plot
77
97
node .add_opt ('--y-variable' , snr_type )
78
98
if ifo is not None :
79
99
node .add_opt ('--ifo' , ifo )
80
- reset_central_time = shift_time - central_time
81
- # Horizontal axis range the = prevents errors with negative times
82
- x_lims = str (- 5. + reset_central_time )+ ',' + str (reset_central_time + 5. )
83
- node .add_opt ('--x-lims=' + x_lims )
100
+ node .add_opt ('--x-lims=-5.,5.' )
84
101
# Plot title
85
102
if ifo is not None :
86
103
title_str = f"'{ ifo } SNR at { central_time :.3f} (s)'"
87
104
else :
88
- title_str = "'%s SNR at %.3f (s)'" % (snr_type .capitalize (),
89
- central_time )
105
+ title_str = f"'{ snr_type .capitalize ()} SNR at { central_time :.3f} (s)'"
90
106
node .add_opt ('--trigger-time' , central_time )
91
107
node .add_opt ('--plot-title' , title_str )
92
108
93
109
# Add job node to workflow
94
110
workflow += node
95
111
112
+ # Revert the config parser back to how it was given
113
+ if orig_slide_id :
114
+ workflow .cp .add_options_to_section (
115
+ 'pygrb_plot_snr_timeseries' ,
116
+ [('slide-id' , orig_slide_id )],
117
+ True
118
+ )
119
+ else :
120
+ workflow .cp .remove_option ('pygrb_plot_snr_timeseries' ,'slide-id' )
121
+
96
122
return node .output_files
97
123
98
124
@@ -107,6 +133,11 @@ parser.add_argument('--followups-file',
107
133
help = "HDF file with the triggers/injections to follow up" )
108
134
parser .add_argument ('--wiki-file' ,
109
135
help = "Name of file to save wiki-formatted table in" )
136
+ parser .add_argument ("-a" , "--seg-files" , nargs = "+" , action = "store" ,
137
+ default = [], help = "The location of the buffer, " +
138
+ "onsource and offsource txt segment files." )
139
+ parser .add_argument ("-V" , "--veto-file" , action = "store" ,
140
+ help = "The location of the xml veto file." )
110
141
wf .add_workflow_command_line_group (parser )
111
142
wf .add_workflow_settings_cli (parser , include_subdax_opts = True )
112
143
ppu .pygrb_add_bestnr_cut_opt (parser )
@@ -142,50 +173,68 @@ trig_file = resolve_url_to_file(os.path.abspath(args.trig_file))
142
173
ifos = ppu .extract_ifos (os .path .abspath (args .trig_file ))
143
174
num_ifos = len (ifos )
144
175
176
+ # File instance of the veto file
177
+ veto_file = args .veto_file
178
+ start_rundir = os .getcwd ()
179
+ if veto_file :
180
+ veto_file = os .path .join (start_rundir , args .veto_file )
181
+ veto_file = wf .resolve_url_to_file (veto_file )
182
+
183
+ # Convert the segments files to a FileList
184
+ seg_files = wf .FileList ([
185
+ wf .resolve_url_to_file (os .path .join (start_rundir , f ))
186
+ for f in args .seg_files
187
+ ])
188
+
145
189
# (Loudest) off/on-source events are on time-slid data so the
146
190
# try will succeed, as it finds the time shift columns.
147
191
is_injection_followup = True
148
192
try :
149
193
time_shift = fp [ifos [0 ]+ ' time shift (s)' ][0 ]
150
194
is_injection_followup = False
151
- except :
195
+ except KeyError :
152
196
pass
153
197
154
-
155
198
# Loop over triggers/injections to be followed up
156
199
for num_event in range (num_events ):
157
200
files = FileList ([])
158
- logging .info ('Processing event: %s' , num_event )
201
+ logging .info ('Processing event: %s' , num_event + 1 )
159
202
gps_time = fp ['GPS time' ][num_event ]
160
203
gps_time = gps_time .astype (float )
204
+ tags = args .tags + [str (num_event + 1 )]
161
205
if wiki_file :
162
206
row = []
163
207
for key in fp .keys ():
164
208
row .append (fp [key ][num_event ])
165
209
add_wiki_row (wiki_file , row )
166
- # Handle off/on-source loudest triggers follow-up (which are on slid data)
167
- if not is_injection_followup :
168
- for ifo in ifos :
169
- time_shift = fp [ifo + ' time shift (s)' ][num_event ]
170
- ifo_time = gps_time - time_shift
171
- files += make_timeseries_plot (workflow , trig_file ,
172
- 'single' , gps_time , ifo_time ,
173
- args .output_dir , ifo = ifo ,
174
- tags = args .tags + [str (num_event )])
175
- files += mini .make_qscan_plot (workflow , ifo , ifo_time ,
176
- args .output_dir ,
177
- tags = args .tags + [str (num_event )])
178
210
# Handle injections (which are on unslid data)
179
- else :
211
+ if is_injection_followup :
180
212
for snr_type in ['reweighted' , 'coherent' ]:
181
213
files += make_timeseries_plot (workflow , trig_file ,
182
- snr_type , gps_time , gps_time ,
214
+ snr_type , gps_time ,
183
215
args .output_dir , ifo = None ,
184
- tags = args .tags + [str (num_event )])
216
+ seg_files = seg_files ,
217
+ veto_file = veto_file ,
218
+ tags = tags )
185
219
for ifo in ifos :
186
220
files += mini .make_qscan_plot (workflow , ifo , gps_time ,
187
221
args .output_dir ,
188
- tags = args .tags + [str (num_event )])
222
+ tags = tags )
223
+ # Handle off/on-source loudest triggers follow-up (which may be on slid
224
+ # data in the case of the off-source)
225
+ else :
226
+ for i_ifo , ifo in enumerate (ifos ):
227
+ time_shift = fp [ifo + ' time shift (s)' ][num_event ]
228
+ ifo_time = gps_time + time_shift
229
+ files += make_timeseries_plot (workflow , trig_file ,
230
+ 'single' , ifo_time ,
231
+ args .output_dir , ifo = ifo ,
232
+ seg_files = seg_files ,
233
+ veto_file = veto_file ,
234
+ tags = tags )
235
+ files += mini .make_qscan_plot (workflow , ifo , ifo_time ,
236
+ args .output_dir ,
237
+ tags = tags )
189
238
190
239
layouts += list (layout .grouper (files , 2 ))
191
240
0 commit comments