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

flexible grid to streamline affine generation and pathlength function #1114

Merged
merged 26 commits into from
Oct 28, 2016

Conversation

kesshijordan
Copy link
Contributor

Included are two related additions :

NF: The path_length function computes the shortest path, along any streamline, between the roi and each voxel. @MrBago and I are using this for a particular project we're working on, but it could be useful in other applications.

NF: The other supporting functions (flexi tvis affine, etc.) are used in path_length, but also address a problem that I've found particularly difficult as a going-up-the-learning-curve user: mapping between grid and streamline spaces with different voxel orders. After the change to using affines instead of providing voxel sizes to functions like target, one has to sort through a lot of information in the headers to get everything in the same space. These flexi tvis affine functions are extremely helpful for painless targeting and fvtk renderings.


def flexi_tvis_affine(sl_vox_order, grid_affine, dim, voxel_size):
""" Computes the mapping from voxel indices to streamline points,
reconciling streamlines and grids with different voxel orders
Copy link
Contributor

Choose a reason for hiding this comment

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

indent to the left

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? I think the def is against the left edge, and the docstring is indented like the rest of the functions in this file?

@Garyfallidis
Copy link
Contributor

Also you may want to look at the new streamline API available in DIPY. This should solve many different problems with dealing with streamline datasets.

@arokem
Copy link
Contributor

arokem commented Sep 11, 2016

On Sat, Sep 10, 2016 at 9:43 PM, Eleftherios Garyfallidis <
notifications@github.com> wrote:

Also you may want to look at the new streamline API available in DIPY.
This should solve many different problems with dealing with streamline
datasets.

Do you mean the new streamline API in nibabel? Worth taking a look at
that, for sure:
http://nipy.org/nibabel/reference/nibabel.streamlines.html#module-nibabel.streamlines


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#1114 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAHPNlX4a1k_dZpquyOK1GRhzxf34EiPks5qo4bogaJpZM4JzTI7
.

@kesshijordan
Copy link
Contributor Author

Thank you for the comments. I have fixed most of the formatting issues (not sure I know what you mean regarding indentation), and commented on the number of parameters question. I also noticed that there are supposed to be two lines between each function, so I corrected that, as well. I will check out the nibabel API to see if that fixes some of these issues.

@arokem
Copy link
Contributor

arokem commented Sep 29, 2016

Hey @kesshijordan : do you understand why these test failures are happening?

@kesshijordan
Copy link
Contributor Author

Hi, @arokem. Thanks for checking in. I think I figured it out: I found errors I recognized when I scrolled to the bottom of the Travis build outputs. I addressed them, resubmitted to Travis, and only one build failed (#1.5; I think because of the numpy version) "AttributeError: 'numpy.ufunc' object has no attribute 'at'", referring to a use of np.minimum.at(a,(i,j,k),b)... so I replaced it with a[i,j,k]=np.minimum(a[i,j,k],b) so that all of the builds work. Is there anything else I should be looking for besides the big ERRORs?

@codecov-io
Copy link

codecov-io commented Sep 29, 2016

Current coverage is 80.96% (diff: 99.24%)

Merging #1114 into master will increase coverage by 0.09%

@@             master      #1114   diff @@
==========================================
  Files           217        217          
  Lines         24593      24717   +124   
  Methods           0          0          
  Messages          0          0          
  Branches       2491       2499     +8   
==========================================
+ Hits          19888      20011   +123   
  Misses         4194       4194          
- Partials        511        512     +1   

Powered by Codecov. Last update da31980...a59c50f

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 83.303% when pulling a78e5e0 on kesshijordan:master into 994d43f on nipy:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 83.303% when pulling a78e5e0 on kesshijordan:master into 994d43f on nipy:master.

@kesshijordan
Copy link
Contributor Author

@MrBago just pointed out that substituting a[i,j,k]=np.minimum(a[i,j,k],b) for np.minimum.at(a,(i,j,k),b) introduces errors and recommended fixing it with a little function that replaces np.minimum.at if the numpy version is less than 8.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 82.814% when pulling 6abccfc on kesshijordan:master into 994d43f on nipy:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 83.318% when pulling 2dfaa4c on kesshijordan:master into 994d43f on nipy:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 83.318% when pulling 2dfaa4c on kesshijordan:master into 994d43f on nipy:master.

Copy link
Contributor

@arokem arokem left a comment

Choose a reason for hiding this comment

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

Sorry that this has languished. The code looks good to me now, and is almost ready to merge. I had just a few small formatting suggestions.

sl_vox_order : string of length 3
a string that describes the voxel order of the streamlines (ex: LPS)
grid_affine : array (4, 4),
An affine matrix describing the current space of the grid in relation to RAS+ scanner space
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP8

Copy link
Contributor

Choose a reason for hiding this comment

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

Line's too long, I believe.


sl_ornt = orientation_from_string(str(sl_vox_order))
grid_ornt = nib.io_orientation(grid_affine)
reorder_grid = reorder_voxels_affine(grid_ornt, sl_ornt, np.array(dim)-1, np.array([1,1,1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here as well: line is longer than 80 characters (PEP8)

----------
tvis_hdr : header from a trackvis file
nii_aff : array (4, 4),
An affine matrix describing the current space of the grid in relation to RAS+ scanner space
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP8 (line length)

nii_aff : array (4, 4),
An affine matrix describing the current space of the grid in relation to RAS+ scanner space
nii_data : nd array
3D array, each with shape (x, y, z) corresponding to the shape of the brain volume,
Copy link
Contributor

Choose a reason for hiding this comment

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

Period instead of comma at the end of the sentence?


origin = np.dot(affine, [0, 0, 0, 1])
assert_array_almost_equal(origin[:3], np.multiply(dim,voxel_size)-voxel_size/2)

Copy link
Contributor

Choose a reason for hiding this comment

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

One more linebreak here (PEP8)

trk_point = np.dot(affine, np.append(vox_point, 1))

assert_array_almost_equal(trk_point[:3], (vox_point[[1, 2, 0]] + 0.5) * vsz)

Copy link
Contributor

Choose a reason for hiding this comment

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

One more linebreak here (PEP8)

Conflicts:
	dipy/tracking/tests/test_utils.py
Conflicts:
	dipy/tracking/tests/test_utils.py
Conflicts:
	dipy/tracking/tests/test_utils.py
Conflicts:
	dipy/tracking/tests/test_utils.py
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 83.024% when pulling a59c50f on kesshijordan:master into da31980 on nipy:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 83.024% when pulling a59c50f on kesshijordan:master into da31980 on nipy:master.

@arokem arokem merged commit 9bbb5a4 into dipy:master Oct 28, 2016
@arokem
Copy link
Contributor

arokem commented Oct 28, 2016

Thanks! Please do consider adding documentation examples using these functions, so that we can see how exactly this is useful to you. If you need a hand with that, just let me know.

@kesshijordan
Copy link
Contributor Author

Sorry this took so long, @arokem. I just made a PR for the documentation that goes with this #1631.

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.

None yet

6 participants