Skip to content

Commit

Permalink
Fix subtle bug when using LIGOTimeGPS with TimeSeries.at_time()
Browse files Browse the repository at this point in the history
  • Loading branch information
titodalcanton committed Aug 2, 2024
1 parent 63c0ecf commit b76b31f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pycbc/types/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,12 @@ def get_sample_times(self):

def at_time(self, time, nearest_sample=False,
interpolate=None, extrapolate=None):
""" Return the value at the specified gps time
""" Return the value of the TimeSeries at the specified GPS time.
Parameters
----------
time: scalar or array-like
GPS time at which the value is wanted.
nearest_sample: bool
Return the sample at the time nearest to the chosen time rather
than rounded down.
Expand Down Expand Up @@ -278,9 +280,9 @@ def at_time(self, time, nearest_sample=False,
keep_idx = _numpy.where(left & right)[0]
vtime = vtime[keep_idx]
else:
raise ValueError("Unsuported extrapolate: %s" % extrapolate)
raise ValueError(f"Unsuported extrapolate: {extrapolate}")

fi = (vtime - float(self.start_time))*self.sample_rate
fi = (vtime - float(self.start_time)) * self.sample_rate
i = _numpy.asarray(_numpy.floor(fi)).astype(int)
di = fi - i

Expand All @@ -305,10 +307,9 @@ def at_time(self, time, nearest_sample=False,
ans[keep_idx] = old
ans = _numpy.array(ans, ndmin=1)

if _numpy.isscalar(time):
if _numpy.ndim(time) == 0:
return ans[0]
else:
return ans
return ans

at_times = at_time

Expand Down

0 comments on commit b76b31f

Please sign in to comment.