diff --git a/pycbc/frame/frame.py b/pycbc/frame/frame.py index a67a3d090d9..bfc742b0ea6 100644 --- a/pycbc/frame/frame.py +++ b/pycbc/frame/frame.py @@ -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 @@ -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: @@ -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): diff --git a/pycbc/strain/strain.py b/pycbc/strain/strain.py index 4ff3b01d061..b383cd5c9e3 100644 --- a/pycbc/strain/strain.py +++ b/pycbc/strain/strain.py @@ -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: @@ -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)