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.
epoch_indexing_and_dataviz_layer
Tyler Goodlet 2022-12-28 00:55:16 -05:00
parent a7d78a3f40
commit fc17187ff4
1 changed files with 2 additions and 20 deletions

View File

@ -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]),