From c1201c164c6ed7dc8d9a659828c1c76783cf7809 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 8 Jun 2023 18:46:14 -0400 Subject: [PATCH] Parametrize index margin around gap detection segment --- piker/data/_timeseries.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/piker/data/_timeseries.py b/piker/data/_timeseries.py index 81d380c7..f43e0c73 100644 --- a/piker/data/_timeseries.py +++ b/piker/data/_timeseries.py @@ -194,16 +194,33 @@ def slice_from_time( return read_slc -def detect_null_time_gap(shm: ShmArray) -> tuple[float, float] | None: - # detect if there are any zero-epoch stamped rows +def detect_null_time_gap( + shm: ShmArray, + imargin: int = 1, + +) -> tuple[float, float] | None: + ''' + Detect if there are any zero-epoch stamped rows in + the presumed 'time' field-column. + + Filter to the gap and return a surrounding index range. + + NOTE: for now presumes only ONE gap XD + + ''' zero_pred: np.ndarray = shm.array['time'] == 0 zero_t: np.ndarray = shm.array[zero_pred] if zero_t.size: istart, iend = zero_t['index'][[0, -1]] start, end = shm._array['time'][ - [istart - 2, iend + 2] + [istart - imargin, iend + imargin] ] - return istart - 2, start, end, iend + 2 + return ( + istart - imargin, + start, + end, + iend + imargin, + ) return None