-
Notifications
You must be signed in to change notification settings - Fork 431
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
Conversation
…econciling streamlines and grids with different voxel orders
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent to the left
There was a problem hiding this comment.
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?
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. |
On Sat, Sep 10, 2016 at 9:43 PM, Eleftherios Garyfallidis <
|
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. |
Hey @kesshijordan : do you understand why these test failures are happening? |
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? |
Current coverage is 80.96% (diff: 99.24%)@@ 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
|
1 similar comment
@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. |
BF - fix _min_at function
1 similar comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8
There was a problem hiding this comment.
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])) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
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
1 similar comment
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. |
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.