Skip to content

Commit 67a0981

Browse files
Merge pull request NeuralEnsemble#1298 from zm711/analog-proxy-fix
ensure analog signal proxy and analog signal behave the same for time slices
2 parents 3d781df + 836f96f commit 67a0981

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

neo/io/proxyobjects.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,25 @@ def _time_slice_indices(self, time_slice, strict_slicing=True):
187187
assert self.t_start <= t_start <= self.t_stop, 't_start is outside'
188188
else:
189189
t_start = max(t_start, self.t_start)
190-
# the i_start is necessary ceil
191-
i_start = int(np.ceil((t_start - self.t_start).magnitude * sr.magnitude))
192-
# this needed to get the real t_start of the first sample
193-
# because do not necessary match what is demanded
190+
# the i_start is rounded to the nearest sample
191+
i_start = np.rint((t_start - self.t_start).magnitude * sr.magnitude).astype(np.int64)
192+
# this is needed to get the real t_start of the first sample
193+
# because it does not necessary match what is demanded
194194
sig_t_start = self.t_start + i_start / sr
195195

196196
if t_stop is None:
197197
i_stop = None
198198
else:
199199
t_stop = ensure_second(t_stop)
200200
if strict_slicing:
201-
assert self.t_start <= t_stop <= self.t_stop, 't_stop is outside'
201+
assert self.t_start <= t_stop <= self.t_stop, 't_stop is outside possible time range'
202202
else:
203203
t_stop = min(t_stop, self.t_stop)
204-
i_stop = int((t_stop - self.t_start).magnitude * sr.magnitude)
204+
# calculate duration demanded then round it to nearest sample number
205+
# add this to i_start to get i_stop
206+
delta = (t_stop - t_start) * sr
207+
i_stop = i_start + int(np.rint(delta.simplified.magnitude))
208+
205209
return i_start, i_stop, sig_t_start
206210

207211
def load(self, time_slice=None, strict_slicing=True,

0 commit comments

Comments
 (0)