Skip to content

BF: #596 First point of LazyTractogram is not saved #588

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 7 commits into from
Jan 12, 2018

Conversation

MarcCote
Copy link
Contributor

With this PR, we now assume tractogram objects can be iterated over only once at saving time.

This PR fixes issue #586.
Thanks to @nilgoyette for providing the missing unit test and part of the solution 👍.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.006%) to 96.325% when pulling 859143b on MarcCote:bf_586 into b8545ef on nipy:master.

@nilgoyette
Copy link

Much cleaner than my version. Thank you.

@codecov-io
Copy link

codecov-io commented Jan 3, 2018

Codecov Report

Merging #588 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #588      +/-   ##
==========================================
+ Coverage   94.46%   94.46%   +<.01%     
==========================================
  Files         177      177              
  Lines       25153    24936     -217     
  Branches     2684     2659      -25     
==========================================
- Hits        23760    23556     -204     
+ Misses        914      908       -6     
+ Partials      479      472       -7
Impacted Files Coverage Δ
nibabel/streamlines/tck.py 98.89% <100%> (+0.01%) ⬆️
nibabel/streamlines/tests/test_streamlines.py 98.78% <100%> (+0.07%) ⬆️
nibabel/streamlines/tests/test_array_sequence.py 99.5% <100%> (ø) ⬆️
nibabel/streamlines/tractogram.py 99.66% <100%> (+2.98%) ⬆️
nibabel/streamlines/trk.py 94.29% <100%> (-0.98%) ⬇️
nibabel/streamlines/tests/test_tractogram.py 97.75% <100%> (+0.07%) ⬆️
nibabel/streamlines/utils.py 100% <100%> (ø) ⬆️
nibabel/tests/test_nifti1.py 98.38% <0%> (-0.01%) ⬇️
nibabel/tests/test_volumeutils.py 98.94% <0%> (ø) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8545ef...94c5390. Read the comment docs.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 96.354% when pulling 89dabaf on MarcCote:bf_586 into b8545ef on nipy:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 96.354% when pulling 8a41145 on MarcCote:bf_586 into b8545ef on nipy:master.

@MarcCote
Copy link
Contributor Author

MarcCote commented Jan 5, 2018

This PR is ready for reviews. :-)
@nilgoyette @effigies @matthew-brett

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me. Thanks for upping the test coverage. Will merge tomorrow AM unless someone else has concerns.

Noting that I don't use tractography at all, so this is purely a code audit.

@nilgoyette
Copy link

I don't have any concern with this PR; it fixes the problem and it's clean. +1 to merge.

try:
first_item = next(iter(self.tractogram))
# Use the first element to check
Copy link
Member

Choose a reason for hiding this comment

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

I guess you could refactor this out into:

def peek_next(iterable):
    next_item = next(iterable)
    return next_item, itertools.chain([next_item], iterable)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -423,8 +424,20 @@ def save(self, fileobj):
i4_dtype = np.dtype("<i4") # Always save in little-endian.
f4_dtype = np.dtype("<f4") # Always save in little-endian.

# Make sure streamlines are in rasmm then send them to voxmm.
Copy link
Member

Choose a reason for hiding this comment

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

Could you say a bit more about this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because self.tractogram could be a LazyTractogram, peeking the first element requires to call iter() on it (i.e. start looping through the TractogramItems), but later I have to send the streamlines to voxmm, that is calling apply_affine on self.tractogram which would have been advanced by one element (because of peek_next).

The alternative would have been to create a new LazyTractogram from the iterable return by peek_next, then call the apply_affine function. I just thought it would be simpler to do the transformation first. It shouldn't change the overall logic of the method: peek element to get some data type information, apply affine and save to disk.

Copy link
Member

Choose a reason for hiding this comment

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

Could you add something like this as an explanation in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 96.359% when pulling d0b2c29 on MarcCote:bf_586 into b8545ef on nipy:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 96.359% when pulling c0f5120 on MarcCote:bf_586 into b8545ef on nipy:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 96.359% when pulling 94c5390 on MarcCote:bf_586 into b8545ef on nipy:master.

@matthew-brett
Copy link
Member

Yes, looks good - in it goes.

@matthew-brett matthew-brett merged commit f824222 into nipy:master Jan 12, 2018
@MarcCote MarcCote deleted the bf_586 branch January 12, 2018 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants