def test_in_bounds_given_point_outside_bounds(self): time = '2019-08-01 00:15:00' bounds = locate.bounds(['2019-08-01 00:00:00'], dt.timedelta(minutes=15)) result = locate.in_bounds(bounds, time) expect = [False] np.testing.assert_array_equal(expect, result)
def test_in_bounds(self): time = '2019-08-01 00:14:59' bounds = locate.bounds(['2019-08-01 00:00:00'], dt.timedelta(minutes=15)) result = locate.in_bounds(bounds, time) expect = [True] np.testing.assert_array_equal(expect, result)
def test_time_bounds(self): dates = [dt.datetime(2019, 8, 1)] length = dt.timedelta(minutes=15) result = locate.bounds(dates, length) expect = np.array([['2019-08-01 00:00:00', '2019-08-01 00:15:00']], dtype='datetime64[s]') np.testing.assert_array_equal(expect, result)
def find_file(self, valid_date): paths = np.array(self.paths) # Note: timeout cache in use) bounds = locate.bounds(self.dates(paths), dt.timedelta(minutes=15)) pts = locate.in_bounds(bounds, valid_date) found = paths[pts] if len(found) > 0: return found[0] else: raise FileNotFound("RDT: '{}' not found in {}".format( valid_date, bounds))
def find_index(self, times, time, length): dtype = 'datetime64[s]' if isinstance(times, list): times = np.asarray(times, dtype=dtype) bounds = locate.bounds(times, length) inside = locate.in_bounds(bounds, time) valid_times = np.ma.array(times, mask=~inside) if valid_times.mask.all(): msg = "{}: not found".format(time) raise IndexNotFound(msg) return np.ma.argmax(valid_times)
def find_index(times, time, length): """Search for index inside array of datetime64[s] values""" dtype = "datetime64[s]" if isinstance(times, list): times = np.asarray(times, dtype=dtype) if isinstance(time, (dt.datetime, str)): time = np.datetime64(time, "s") bounds = locate.bounds(times, length) inside = locate.in_bounds(bounds, time) valid_times = np.ma.array(times, mask=~inside) if valid_times.mask.all(): msg = "{}: not found".format(time) raise IndexNotFound(msg) return _natargmax(valid_times.filled())