@@ -48,30 +48,6 @@ __program__ = "pycbc_pygrb_plot_snr_timeseries"
48
48
# =============================================================================
49
49
# Functions
50
50
# =============================================================================
51
- # Load trigger data
52
- def load_data (input_file , ifos , vetoes , rw_snr_threshold = None ,
53
- injections = False , slide_id = None ):
54
- """Load data from a trigger/injection file"""
55
-
56
- trigs_or_injs = None
57
- if input_file :
58
- if injections :
59
- logging .info ("Loading injections..." )
60
- # This will eventually become load_injections
61
- trigs_or_injs = \
62
- ppu .load_triggers (input_file , ifos , vetoes ,
63
- rw_snr_threshold = rw_snr_threshold ,
64
- slide_id = slide_id )
65
- else :
66
- logging .info ("Loading triggers..." )
67
- trigs_or_injs = \
68
- ppu .load_triggers (input_file , ifos , vetoes ,
69
- rw_snr_threshold = rw_snr_threshold ,
70
- slide_id = slide_id )
71
-
72
- return trigs_or_injs
73
-
74
-
75
51
# Find start and end times of trigger/injecton data relative to a given time
76
52
def get_start_end_times (data_time , central_time ):
77
53
"""Determine padded start and end times of data relative to central_time"""
@@ -108,6 +84,8 @@ parser.add_argument("--trigger-time", type=float, default=0,
108
84
parser .add_argument ("-y" , "--y-variable" , default = None ,
109
85
choices = ['coherent' , 'single' , 'reweighted' , 'null' ],
110
86
help = "Quantity to plot on the vertical axis." )
87
+ parser .add_argument ("--onsource" , default = False , action = "store_true" ,
88
+ help = "Include onsource data in the plot (CAUTION!)" )
111
89
ppu .pygrb_add_bestnr_cut_opt (parser )
112
90
ppu .pygrb_add_slide_opts (parser )
113
91
opts = parser .parse_args ()
@@ -132,48 +110,83 @@ outdir = os.path.split(os.path.abspath(opts.output_file))[0]
132
110
if not os .path .isdir (outdir ):
133
111
os .makedirs (outdir )
134
112
135
- # Extract IFOs and vetoes
136
- ifos , vetoes = ppu .extract_ifos_and_vetoes (trig_file , opts .veto_files ,
137
- opts .veto_category )
113
+ # Extract IFOs
114
+ ifos = ppu .extract_ifos (trig_file )
115
+
116
+ # Generate time-slides dictionary
117
+ slide_dict = ppu .load_time_slides (trig_file )
118
+
119
+ # Generate segments dictionary
120
+ segment_dict = ppu .load_segment_dict (trig_file )
121
+
122
+ # Construct trials removing vetoed times
123
+ trial_dict , total_trials = ppu .construct_trials (
124
+ opts .seg_files ,
125
+ segment_dict ,
126
+ ifos ,
127
+ slide_dict ,
128
+ opts .veto_file ,
129
+ hide_onsource = (not opts .onsource )
130
+ )
138
131
139
132
# Load trigger and injections data: when plotting reweighted SNR, keep all
140
133
# points to show the impact of the cut, otherwise remove points with
141
134
# reweighted SNR below threshold
142
- if snr_type == 'reweighted' :
143
- trig_data = load_data (trig_file , ifos , vetoes ,
135
+ rw_snr_threshold = None if snr_type == 'reweighted' else opts .newsnr_threshold
136
+ # When including the onsource, avoid printing to screen via logging the number
137
+ # of triggers found
138
+ data_tag = 'trigs' if opts .onsource else None
139
+ trig_data = ppu .load_data (trig_file , ifos , data_tag = data_tag ,
140
+ rw_snr_threshold = rw_snr_threshold ,
144
141
slide_id = opts .slide_id )
145
- trig_data ['network/reweighted_snr' ] = \
146
- reweightedsnr_cut (trig_data ['network/reweighted_snr' ],
147
- opts .newsnr_threshold )
148
- inj_data = load_data (inj_file , ifos , vetoes , injections = True ,
142
+ inj_data = ppu .load_data (inj_file , ifos , data_tag = 'injs' ,
143
+ rw_snr_threshold = rw_snr_threshold ,
149
144
slide_id = 0 )
150
- if inj_data is not None :
151
- inj_data ['network/reweighted_snr' ] = \
152
- reweightedsnr_cut (inj_data ['network/reweighted_snr' ],
153
- opts .newsnr_threshold )
154
- else :
155
- trig_data = load_data (trig_file , ifos , vetoes ,
156
- rw_snr_threshold = opts .newsnr_threshold ,
157
- slide_id = opts .slide_id )
158
- inj_data = load_data (inj_file , ifos , vetoes ,
159
- rw_snr_threshold = opts .newsnr_threshold ,
160
- injections = True , slide_id = 0 )
161
145
162
146
# Specify HDF file keys for x quantity (time) and y quantity (SNR)
163
- if snr_type == 'single' :
147
+ if opts . y_variable == 'single' :
164
148
x_key = opts .ifo + '/end_time'
165
149
y_key = opts .ifo + '/snr'
166
150
else :
167
151
x_key = 'network/end_time_gc'
168
- y_key = 'network/' + snr_type + '_snr'
169
-
170
- # Obtain times
171
- trig_data_time = trig_data [x_key ][:]
172
- inj_data_time = inj_data [x_key ][:] if inj_file else None
173
-
174
- # Obtain SNRs
175
- trig_data_snr = trig_data [y_key ][:]
176
- inj_data_snr = inj_data [y_key ][:] if inj_file else None
152
+ y_key = 'network/' + opts .y_variable + '_snr'
153
+
154
+ # Extract needed trigger properties and store them as dictionaries
155
+ # Based on trial_dict: if vetoes were applied, trig_* are the veto survivors
156
+ found_trigs = ppu .extract_trig_properties (
157
+ trial_dict ,
158
+ trig_data ,
159
+ slide_dict ,
160
+ segment_dict ,
161
+ [x_key , y_key ]
162
+ )
163
+
164
+ # Gather injections found surviving vetoes
165
+ found_after_vetoes , * _ = ppu .apply_vetoes_to_found_injs (
166
+ opts .found_missed_file ,
167
+ inj_data ,
168
+ ifos ,
169
+ veto_file = opts .veto_file ,
170
+ keys = [x_key , y_key ]
171
+ )
172
+
173
+ # Obtain times and SNRs
174
+ trig_data_time = numpy .concatenate ([found_trigs [x_key ][slide_id ][:] for slide_id in slide_dict ])
175
+ trig_data_snr = numpy .concatenate ([found_trigs [y_key ][slide_id ][:] for slide_id in slide_dict ])
176
+ inj_data_time = found_after_vetoes [x_key ][:] if inj_file else None
177
+ inj_data_snr = found_after_vetoes [y_key ][:] if inj_file else None
178
+
179
+ # Apply reweighted SNR threshold keeping downweighted points
180
+ if snr_type == 'reweighted' :
181
+ trig_data_snr = reweightedsnr_cut (
182
+ trig_data_snr ,
183
+ opts .newsnr_threshold
184
+ )
185
+ if inj_file :
186
+ inj_data_snr = reweightedsnr_cut (
187
+ inj_data_snr ,
188
+ opts .newsnr_threshold
189
+ )
177
190
178
191
# Determine the central time (t=0) for the plot
179
192
central_time = opts .trigger_time
@@ -191,7 +204,7 @@ logging.info("Plotting...")
191
204
192
205
# Determine what goes on the vertical axis
193
206
y_labels = {'coherent' : "Coherent SNR" ,
194
- 'single' : "%s SNR" % ifo ,
207
+ 'single' : f" { ifo } SNR" ,
195
208
'null' : "Null SNR" ,
196
209
'reweighted' : "Reweighted SNR" }
197
210
y_label = y_labels [snr_type ]
@@ -205,11 +218,9 @@ if opts.plot_caption is None:
205
218
opts .plot_caption += ("Red crosses: injections triggers." )
206
219
207
220
# Single IFO SNR versus time plots
208
- xlims = [start , end ]
209
- if opts .x_lims :
210
- xlims = opts .x_lims
211
- xlims = map (float , xlims .split (',' ))
221
+ if not opts .x_lims :
222
+ opts .x_lims = f"{ start } ,{ end } "
212
223
plu .pygrb_plotter ([trig_data_time , trig_data_snr ],
213
224
[inj_data_time , inj_data_snr ],
214
- "Time since % .3f (s)" % ( central_time ) , y_label ,
225
+ f "Time since { central_time : .3f} (s)" , y_label ,
215
226
opts , cmd = ' ' .join (sys .argv ))
0 commit comments