From e3d8c19a7229722e3a12b182efd5231a419e7dc0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 28 Dec 2022 00:55:16 -0500 Subject: [PATCH] Drop edge case from `slice_from_time()` Doesn't seem like we really need to handle the situation where the start or stop input time stamps are outside the index range of the data since the new binary search handling via `numpy.searchsorted()` covers this case at minimal runtime cost and with an equally correct output. Allows us to drop some other indexing endpoint internal variables as well. --- piker/data/_pathops.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/piker/data/_pathops.py b/piker/data/_pathops.py index 90ea4d5e..25e2c451 100644 --- a/piker/data/_pathops.py +++ b/piker/data/_pathops.py @@ -309,25 +309,9 @@ def slice_from_time( times = arr['time'] t_first = round(times[0]) - t_last = round(times[-1]) - index = arr['index'] - i_first = index[0] - # i_last = index[-1] read_i_max = arr.shape[0] - if ( - start_t < t_first - and stop_t > t_last - ): - read_i_start = 0 - read_i_stop = read_i_max - read_slc = slice( - 0, - read_i_max, - ) - return read_slc - if step is None: step = round(times[-1] - times[-2]) if step == 0: @@ -359,11 +343,9 @@ def slice_from_time( # NOTE: this is usually the result of a time series with time gaps # where it is expected that each index step maps to a uniform step # in the time stamp series. - i_iv_start = index[read_i_start] t_iv_start = times[read_i_start] if ( - i_iv_start >= i_first - and t_iv_start > i_start_t + t_iv_start > i_start_t ): # do a binary search for the best index mapping to ``start_t`` # given we measured an overshoot using the uniform-time-step @@ -396,7 +378,6 @@ def slice_from_time( # ) read_i_start = new_read_i_start - 1 - # i_iv_stop = index[read_i_stop - 1] t_iv_stop = times[read_i_stop - 1] if ( t_iv_stop > i_stop_t @@ -441,6 +422,7 @@ def slice_from_time( # NOTE: if caller needs absolute buffer indices they can # slice the buffer abs index like so: + # index = arr['index'] # abs_indx = index[read_slc] # abs_slc = slice( # int(abs_indx[0]),