Skip to content

Commit

Permalink
Start work on reading state vector first
Browse files Browse the repository at this point in the history
  • Loading branch information
titodalcanton committed Aug 5, 2024
1 parent 1c6ad7e commit f5bba57
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
20 changes: 12 additions & 8 deletions pycbc/frame/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ def _read_frame(self, blocksize):
return TimeSeries(data.data.data, delta_t=data.deltaT,
epoch=self.read_pos,
dtype=dtype)
except Exception:
raise RuntimeError('Cannot read {0} frame data'.format(self.channel_name))
except:
raise RuntimeError(f'Cannot read {self.channel_name} frame data')

def null_advance(self, blocksize):
"""Advance and insert zeros
Expand Down Expand Up @@ -826,19 +826,22 @@ def indices_of_flag(self, start_time, duration, times, padding=0):
return idx

def advance(self, blocksize):
""" Add blocksize seconds more to the buffer, push blocksize seconds
from the beginning.
"""Read `blocksize` seconds of new status data, append it to the end of
the internal status buffer, and drop `blocksize` seconds from the
beginning of the buffer. Check if the newly added status data indicates
usable or unusable strain data.
Parameters
----------
blocksize: int
The number of seconds to attempt to read from the channel
The number of seconds to attempt to read from the channel.
Returns
-------
status: boolean
Returns True if all of the status information if valid,
False if any is not.
Returns True if all of the status information if valid, False if
any is not, None if there was a problem reading the status
information.
"""
try:
if self.increment_update_cache:
Expand All @@ -847,7 +850,8 @@ def advance(self, blocksize):
return self.check_valid(ts)
except RuntimeError:
self.null_advance(blocksize)
return False
return None


class iDQBuffer(object):

Expand Down
55 changes: 36 additions & 19 deletions pycbc/strain/strain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1863,17 +1863,47 @@ def advance(self, blocksize, timeout=10):
status: boolean
Returns True if this block is analyzable.
"""
ts = super(StrainBuffer, self).attempt_advance(blocksize, timeout=timeout)
self.blocksize = blocksize
if self.state:
# We are using information from the state vector, so check what is
# says about the new strain data.
state_advance_result = self.state.advance(blocksize)
if not state_advance_result:
# Something about the state vector indicates a problem.
if state_advance_result is None:
logger.warning(
"Failed to read %s state vector. Problem with the "
"frame files, or analysis configured incorrectly",
self.detector
)
else:
logger.info(
"%s state vector indicates unusable data", self.detector
)
# Either way, give up here; we will not analyze the new segment
# of strain data.
self.add_hard_count()
self.null_advance_strain(blocksize)
if self.dq:
self.dq.null_advance(blocksize)
if self.idq:
self.idq.null_advance(blocksize)
return False

# Either we are not using the state vector, or the state vector says
# the data is ok to analyze. So try to get the next segment of data.
ts = super(StrainBuffer, self).attempt_advance(
blocksize, timeout=timeout
)
self.blocksize = blocksize
self.gate_params = []

# We have given up so there is no time series
if ts is None:
logger.info("%s frame is late, giving up", self.detector)
logger.warning(
"Failed to read %s strain channel. Problem with the frame "
"files, or analysis configured incorrectly",
self.detector
)
self.null_advance_strain(blocksize)
if self.state:
self.state.null_advance(blocksize)
if self.dq:
self.dq.null_advance(blocksize)
if self.idq:
Expand All @@ -1883,19 +1913,6 @@ def advance(self, blocksize, timeout=10):
# We collected some data so we are closer to being able to analyze data
self.wait_duration -= blocksize

# If the data we got was invalid, reset the counter on how much to collect
# This behavior corresponds to how we handle CAT1 vetoes
if self.state and self.state.advance(blocksize) is False:
self.add_hard_count()
self.null_advance_strain(blocksize)
if self.dq:
self.dq.null_advance(blocksize)
if self.idq:
self.idq.null_advance(blocksize)
logger.info("%s time has invalid data, resetting buffer",
self.detector)
return False

# Also advance the dq vector and idq timeseries in lockstep
if self.dq:
self.dq.advance(blocksize)
Expand Down

0 comments on commit f5bba57

Please sign in to comment.