Repository navigation
Conversation
Normalize slice starts against the signal length and apply the stride to the sampling period in both bare and tuple indexing. Negative or clipped starts then refer to the samples actually selected, and a bare stride has the same timing as its tuple equivalent.
|
I have requested @apdavison to help review this. |
apdavison
left a comment
There was a problem hiding this comment.
This is great, many thanks for catching and fixing this.
I have one suggested improvement - see the inline comments.
| obj.sampling_period *= j.step | ||
| start, _, step = j.indices(len(self)) | ||
| obj.t_start = self.t_start + start * self.sampling_period | ||
| obj.sampling_period = self.sampling_period * step |
There was a problem hiding this comment.
Setting sampling_period here sends the rate through 1/(1/rate), which leads to floating-point problems:
sig = AnalogSignal(..., sampling_rate=25000*pq.Hz)
sig[:].sampling_rate == 25000*pq.Hz
# master: True
# PR: False (24999.999999999996)
It would be better to set obj.sampling_rate = self.sampling_rate / step to avoid the conversion.
| obj.t_start = self.t_start + i.start * self.sampling_period | ||
| start, _, step = i.indices(len(self)) | ||
| obj.t_start = self.t_start + start * self.sampling_period | ||
| obj.sampling_period = self.sampling_period * step |
|
Changed both slice paths to set |
68e405f to
5cb7efd
Compare
signal[::2]currently keeps the original sampling period, and negative slice starts are treated as literal time offsets. For example, a ten-sample signal starting at 2 s at 4 Hz reportssignal[-3:].t_startas 1.25 s instead of 3.75 s.Normalize the start against the signal length and adjust the sampling rate by direct division for both bare and tuple slices. Add regressions for negative/clipped starts, forward/reverse strides, nested slices and exact sampling-rate preservation. The separate author-list commit follows the first-contribution instructions.
Validation: 634 core tests and 51 subtests pass; Black passes on the changed Python files. On recorded EEGMMIDB S001/R04 data, all 30 slicing configurations match absolute sample-index timestamps after the fix, correcting 18 configurations and 227 event-window selections. All sample values and event-window selections remain correct. Direct rate division avoids the reciprocal-round-trip drift reported in review. This changes
__getitem__; thetime_slicechange in #1905 remains separate.