Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index at bug #36

Merged
5 commits merged into from
Dec 6, 2010
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions nitime/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,21 @@ def test_Events():
yield npt.assert_equal(ev2.index.i1,i1)


@decotest.parametric
def test_index_at_20101206():
"""Test for incorrect handling of negative t0 for time.index_at

https://github.com/nipy/nitime/issues#issue/35

bug reported by Jonathan Taylor on 2010-12-06
"""
A=np.random.standard_normal(40)
#negative t0
TS_A=ts.TimeSeries(A,t0=-20,sampling_interval=2)
yield npt.assert_equal(TS_A.time.index_at(TS_A.time),np.arange(40))
#positive t0
TS_A=ts.TimeSeries(A,t0=15,sampling_interval=2)
yield npt.assert_equal(TS_A.time.index_at(TS_A.time),np.arange(40))
#no t0
TS_A=ts.TimeSeries(A,sampling_interval=2)
yield npt.assert_equal(TS_A.time.index_at(TS_A.time),np.arange(40))
4 changes: 1 addition & 3 deletions nitime/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ def index_at(self,t,boolean=False):
# check that index is within range
if ta.min() < self.t0 or ta.max() >= self.t0 + self.duration:
raise ValueError, 'index out of range'

idx = ta.view(np.ndarray)//int(self.sampling_interval)
idx -= self.t0/self._conversion_factor
idx = (ta.view(np.ndarray) - self.t0)//self.sampling_interval
if boolean:
bool_idx = np.zeros(len(self),dtype=bool)
bool_idx[idx] = True
Expand Down