Skip to content

Commit

Permalink
Address Gareth's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtrevor committed Aug 14, 2024
1 parent 8f409b5 commit dd5a583
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/pycbc_live
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ with ctx:
for key in results[ifo]:
if len(results[ifo][key]):
results[ifo][key] = results[ifo][key][idx]
if data_reader[ifo].idq:
if data_reader[ifo].idq is not None:
logging.info("Reading %s's iDQ information", ifo)
start = data_reader[ifo].start_time
times = results[ifo]['end_time']
Expand Down
13 changes: 6 additions & 7 deletions pycbc/events/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2300,14 +2300,13 @@ def check_low_latency(self, key):
ifo = key.split('-')[0]
with h5py.File(self.files[key], 'r') as dq_file:
ifo_grp = dq_file[ifo]
if 'dq_segments' in ifo_grp.keys():
# if segs are in stat file, we are not in LL
assert not self.low_latency, 'Should not have segments in LL'
else:
# we must be in LL, shouldn't have segments
assert not self.dq_state_segments, \
'Should not have segments in LL'
if 'dq_segments' not in ifo_grp.keys():
# if segs are not in file, we must be in LL
if self.dq_state_segments is not None:
raise ValueError('Either all dq stat files must have segments or none')
self.low_latency = True
elif self.low_latency:
raise ValueError('Either all dq stat files must have segments or none')

def assign_template_bins(self, key):
"""
Expand Down
25 changes: 19 additions & 6 deletions pycbc/frame/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,32 +905,45 @@ def flag_at_times(self, start_time, duration, times, padding=0):
Beginning time to request for
duration: int
Number of seconds to check.
times: array of floats
Times to check for an active flag
padding: float
Amount of time in seconds to flag around glitchy times
Amount of time in seconds to flag around samples
below the iDQ FAP threshold
Returns
-------
flag_state: numpy.ndarray
Boolean array of whether flag was on at given times
"""
from pycbc.events.veto import indices_within_times

# convert start and end times to buffer indices
sr = self.idq.raw_buffer.sample_rate
s = int((start_time - self.idq.raw_buffer.start_time - padding) * sr) - 1
e = s + int((duration + padding) * sr) + 1
idq_fap = self.idq.raw_buffer[s:e]
stamps = idq_fap.sample_times.numpy()

# find samples when iDQ FAP is below threshold and state is valid
idq_fap = self.idq.raw_buffer[s:e]
low_fap = idq_fap.numpy() <= self.threshold
idq_valid = self.idq_state.raw_buffer[s:e]
idq_valid = idq_valid.numpy().astype(bool)
valid_low_fap = numpy.logical_and(idq_valid, low_fap)

# find times corresponding to the valid low FAP samples
glitch_idx = numpy.flatnonzero(valid_low_fap)
stamps = idq_fap.sample_times.numpy()
glitch_times = stamps[glitch_idx]

# construct start and end times of flag segments
starts = glitch_times - padding
ends = starts + 1.0 / sr + padding * 2.0

# check if times were flagged
idx = indices_within_times(times, starts, ends)
out = numpy.zeros(len(times), dtype=bool)
out[idx] = True
return out
flagged_bool = numpy.zeros(len(times), dtype=bool)
flagged_bool[idx] = True
return flagged_bool

def advance(self, blocksize):
""" Add blocksize seconds more to the buffer, push blocksize seconds
Expand Down

0 comments on commit dd5a583

Please sign in to comment.