Skip to content

FIX: Copy affine_to_rasmm when slicing a Tractogram object #462

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

Merged
merged 2 commits into from
Jun 27, 2016
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
8 changes: 8 additions & 0 deletions nibabel/streamlines/tests/test_tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

def setup():
global DATA
DATA['rng'] = np.random.RandomState(1234)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you're seeding with a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless nosetest sets the seed of np.random I prefer having reproducible tests. In practice, it should work with any seed, so there is no reason really. We also use a seed in test_array_sequence.py.

DATA['streamlines'] = [np.arange(1*3, dtype="f4").reshape((1, 3)),
np.arange(2*3, dtype="f4").reshape((2, 3)),
np.arange(5*3, dtype="f4").reshape((5, 3))]
Expand Down Expand Up @@ -373,6 +374,13 @@ def test_tractogram_getitem(self):
DATA['tractogram'].data_per_streamline[::-1],
DATA['tractogram'].data_per_point[::-1])

# Make sure slicing conserves the affine_to_rasmm property.
tractogram = DATA['tractogram'].copy()
tractogram.affine_to_rasmm = DATA['rng'].rand(4, 4)
tractogram_view = tractogram[::2]
assert_array_equal(tractogram_view.affine_to_rasmm,
tractogram.affine_to_rasmm)

def test_tractogram_add_new_data(self):
# Tractogram with only streamlines
t = DATA['simple_tractogram'].copy()
Expand Down
3 changes: 2 additions & 1 deletion nibabel/streamlines/tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def __getitem__(self, idx):
if isinstance(idx, (numbers.Integral, np.integer)):
return TractogramItem(pts, data_per_streamline, data_per_point)

return Tractogram(pts, data_per_streamline, data_per_point)
return Tractogram(pts, data_per_streamline, data_per_point,
affine_to_rasmm=self.affine_to_rasmm)

def __len__(self):
return len(self.streamlines)
Expand Down