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

Update streamlines formats example #1928

Merged
merged 7 commits into from Jul 30, 2019

Conversation

@frheault
Copy link
Contributor

commented Jul 27, 2019

Considering the new StatefulTractogram and the fact that the old example only covered the Dpy format. This update now contain a more complete list of file format, the new API and new data that can be fetched.

@pep8speaks

This comment has been minimized.

Copy link

commented Jul 27, 2019

Hello @frheault, Thank you for updating !

Line 77:81: E501 line too long (81 > 80 characters)
Line 123:73: W291 trailing whitespace
Line 152:62: W291 trailing whitespace
Line 153:78: W291 trailing whitespace

Comment last updated at 2019-07-29 21:25:51 UTC
@codecov-io

This comment has been minimized.

Copy link

commented Jul 28, 2019

Codecov Report

❗️ No coverage uploaded for pull request base (master@3f61e9b). Click here to learn what that means.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1928   +/-   ##
=========================================
  Coverage          ?   84.52%           
=========================================
  Files             ?      118           
  Lines             ?    14700           
  Branches          ?     2332           
=========================================
  Hits              ?    12425           
  Misses            ?     1728           
  Partials          ?      547
Impacted Files Coverage Δ
dipy/io/stateful_tractogram.py 68.11% <ø> (ø)
dipy/tracking/utils.py 88.41% <0%> (ø)
dipy/data/fetcher.py 35.01% <28.57%> (ø)
dipy/io/streamline.py 53.28% <40%> (ø)
dipy/io/utils.py 65.41% <54.54%> (ø)
@skoudoro
Copy link
Member

left a comment

This is a really nice tutorial @frheault. Maybe we should put it on the Getting Started because it is essential and a little bit hidden.
Otherwise, there is some typo. When you correct them, it is ready to be merged.

Thank you


import dipy

This comment has been minimized.

Copy link
@skoudoro

skoudoro Jul 29, 2019

Member

Can you replace this by from dipy.io.stateful_tractogram import StatefulTractogram

@@ -177,6 +182,8 @@ def get_reference_info(reference):
elif isinstance(reference, dict) and 'magic_number' in reference:
header = reference
is_trk = True
elif isinstance(reference, dipy.io.stateful_tractogram.StatefulTractogram):

This comment has been minimized.

Copy link
@skoudoro

skoudoro Jul 29, 2019

Member

To follow up the comment above, Can you just use StatefulTractogram here

an header can be generated to then generate a fake NIFTI file.
If you wish to manually save Trk and Tck file using nibabel streamlines
API for more freedom of action (not recommanded for beginner) you can

This comment has been minimized.

Copy link
@skoudoro

skoudoro Jul 29, 2019

Member

typo, recommended


"""
Replacing streamlines is possible, but if the state was modified between
operation such as this one is not recommanded:

This comment has been minimized.

Copy link
@skoudoro

skoudoro Jul 29, 2019

Member

same as above recommended

operation such as this one is not recommanded:
-> cc_sft.streamlines = cc_streamlines_vox
It is recommanded to re-create a new StatefulTractogram object and

This comment has been minimized.

Copy link
@skoudoro

skoudoro Jul 29, 2019

Member

typo recommended

-> cc_sft.streamlines = cc_streamlines_vox
It is recommanded to re-create a new StatefulTractogram object and
explicitely specified in which space the streamline are. Be careful to follow

This comment has been minimized.

Copy link
@skoudoro

skoudoro Jul 29, 2019

Member

typo explicitly and streamlines

@skoudoro

This comment has been minimized.

Copy link
Member

commented Jul 29, 2019

Thank you for the fix, I do not understand why Travis is failing, that's strange...

@frheault

This comment has been minimized.

Copy link
Contributor Author

commented Jul 29, 2019

@skoudoro I fixed it, I just remember why I imported Dipy only instead of StatefulTractogram in dipy/io/utils.py. It was a cyclical important causing everything to crash.

I put it back, it is working now

@skoudoro

This comment has been minimized.

Copy link
Member

commented Jul 29, 2019

It was a cyclical important causing everything to crash.

wow, I really do not like that. That is not good, We really need to understand why it is so easy to create a cyclical import when we create a tutorial and correct that. I will put it up on my todo list

@skoudoro

This comment has been minimized.

Copy link
Member

commented Jul 29, 2019

Maybe get_reference_info should go back to dipy.io.stateful_tractogram.

In any case, it will be on another PR. Need to think more about it.

@skoudoro skoudoro added this to the 1.0 milestone Jul 29, 2019

@@ -9,78 +9,223 @@
DIPY_ can read and write many different file formats. In this example
we give a short introduction on how to use it for loading or saving
streamlines.
streamlines. The new statefull tractogram class was made to reduce errors
cause by spatial transformation and complex file format convention.

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

caused by spatial transformations and complex file format conventions.

support
These files contain invalid streamlines (negative values once in voxel space)
This is not considered a valid tractography file, but it is possible to load
it anyway

This comment has been minimized.

Copy link
@Garyfallidis

"""
Write one track
If a TRK was generated with a valid header, but the reference NIFTI was lost
an header can be generated to then generate a fake NIFTI file.

This comment has been minimized.

Copy link
@Garyfallidis
an header can be generated to then generate a fake NIFTI file.
If you wish to manually save Trk and Tck file using nibabel streamlines
API for more freedom of action (not recommended for beginner) you can

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

beginners

If you wish to manually save Trk and Tck file using nibabel streamlines
API for more freedom of action (not recommended for beginner) you can
create valid header using create_tractogram_header

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

create a valid

or one track each time.
Once loaded, no matter the original file format, the stateful tractogram is
self contained and maintain a valid state and can be easily be manipulated
Let's save all file as TRK to visualize in TrackVis for example.

This comment has been minimized.

Copy link
@Garyfallidis

"""
or one track each time.
Once loaded, no matter the original file format, the stateful tractogram is
self contained and maintain a valid state and can be easily be manipulated

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

maintains (too many ands?). cut sentence in parts.
be twice?

Once loaded, no matter the original file format, the stateful tractogram is
self contained and maintain a valid state and can be easily be manipulated
Let's save all file as TRK to visualize in TrackVis for example.
However, when loaded the lpt and rpt files contains invalid streamlines and

This comment has been minimized.

Copy link
@Garyfallidis
save_tractogram(rpt_sft, 'rpt.trk')

"""
Some functions in dipy require streamlines to be in voxel space so computation

This comment has been minimized.

Copy link
@Garyfallidis
"""
Some functions in dipy require streamlines to be in voxel space so computation
can be perfomed on a grid (connectivity matrix, ROIs masking, density map).
The stateful tractogram class provided safe function for such manipulation.

This comment has been minimized.

Copy link
@Garyfallidis

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

functions?

Some functions in dipy require streamlines to be in voxel space so computation
can be perfomed on a grid (connectivity matrix, ROIs masking, density map).
The stateful tractogram class provided safe function for such manipulation.
These function can be called safely over and over, by knowing in which state

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

functions

can be perfomed on a grid (connectivity matrix, ROIs masking, density map).
The stateful tractogram class provided safe function for such manipulation.
These function can be called safely over and over, by knowing in which state
the tractogram is the operation is computed only necessary.

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

the tractogram is operating and compute only necessary transformations

These function can be called safely over and over, by knowing in which state
the tractogram is the operation is computed only necessary.
No matter the state, function such as saving or removing invalid coordinate

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

functions... coordinates

the tractogram is the operation is computed only necessary.
No matter the state, function such as saving or removing invalid coordinate
can be called safely and the transformation are handle internally if needed.

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

transformations are handled internally when needed.


"""
Replacing streamlines is possible, but if the state was modified between
operation such as this one is not recommended:

This comment has been minimized.

Copy link
@Garyfallidis

Garyfallidis Jul 29, 2019

Member

operations

-> cc_sft.streamlines = cc_streamlines_vox
It is recommended to re-create a new StatefulTractogram object and
explicitly specified in which space the streamlines are. Be careful to follow

This comment has been minimized.

Copy link
@Garyfallidis
If the tractogram was from a Trk file with metadata, this will be lost.
If you wish to keep metadata while manipulating the number or the order
look the function StatefulTractogram.remove_invalid_streamlines() for more

This comment has been minimized.

Copy link
@Garyfallidis
@skoudoro

This comment has been minimized.

Copy link
Member

commented Jul 30, 2019

Thank you @frheault, merging

@skoudoro skoudoro merged commit f7dcb40 into nipy:master Jul 30, 2019

2 of 3 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.