-
Notifications
You must be signed in to change notification settings - Fork 262
BF FreeSurfer nifti surfaces can have >3 dimensions #332
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,19 +261,29 @@ def test_freesurfer_large_vector_hack(self): | |
hdr.set_data_shape((too_big-1, 1, 1)) | ||
assert_equal(hdr.get_data_shape(), (too_big-1, 1, 1)) | ||
# The freesurfer case | ||
full_shape = (too_big, 1, 1, 1, 1, 1, 1) | ||
for dim in range(3, 8): | ||
# First element in 'dim' field is number of dimensions | ||
expected_dim = np.array([dim, -1, 1, 1, 1, 1, 1, 1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add comment like:
I got a bit confused reading this first time. |
||
with suppress_warnings(): | ||
hdr.set_data_shape(full_shape[:dim]) | ||
assert_equal(hdr.get_data_shape(), full_shape[:dim]) | ||
assert_array_equal(hdr['dim'], expected_dim) | ||
assert_equal(hdr['glmin'], too_big) | ||
# Allow the fourth dimension to vary | ||
with suppress_warnings(): | ||
hdr.set_data_shape((too_big, 1, 1)) | ||
assert_equal(hdr.get_data_shape(), (too_big, 1, 1)) | ||
assert_array_equal(hdr['dim'][:4], [3, -1, 1, 1]) | ||
assert_equal(hdr['glmin'], too_big) | ||
# This only works for the case of a 3D with -1, 1, 1 | ||
hdr.set_data_shape((too_big, 1, 1, 4)) | ||
assert_equal(hdr.get_data_shape(), (too_big, 1, 1, 4)) | ||
assert_array_equal(hdr['dim'][:5], np.array([4, -1, 1, 1, 4])) | ||
# This only works when the first 3 dimensions are -1, 1, 1 | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (too_big,)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (too_big,1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think PEP8 is going to complain about the lack of spaces between values in the tuple. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I go ahead and PEP8 clean the whole file? It's got a ton of complaints, but they're not all really relevant to the PR, so I can go either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah - sorry - I was reading color-blind, didn't notice this was white text not green - so ignore me, let's not extend PEP8 editing beyond your current changes. |
||
assert_raises(HeaderDataError, hdr.set_data_shape, (too_big,1,2)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (too_big,2,1)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, too_big)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, too_big, 1)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, 1, too_big)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, 1, 1, too_big)) | ||
# Outside range of glmin raises error | ||
far_too_big = int(np.iinfo(glmin).max) + 1 | ||
with suppress_warnings(): | ||
|
@@ -295,9 +305,22 @@ def test_freesurfer_large_vector_hack(self): | |
def test_freesurfer_ico7_hack(self): | ||
HC = self.header_class | ||
hdr = HC() | ||
full_shape = (163842, 1, 1, 1, 1, 1, 1) | ||
# Test that using ico7 shape automatically uses factored dimensions | ||
hdr.set_data_shape((163842, 1, 1)) | ||
assert_array_equal(hdr._structarr['dim'][1:4], np.array([27307, 1, 6])) | ||
for dim in range(3, 8): | ||
expected_dim = np.array([dim, 27307, 1, 6, 1, 1, 1, 1]) | ||
hdr.set_data_shape(full_shape[:dim]) | ||
assert_equal(hdr.get_data_shape(), full_shape[:dim]) | ||
assert_array_equal(hdr._structarr['dim'], expected_dim) | ||
# Only works on dimensions >= 3 | ||
assert_raises(HeaderDataError, hdr.set_data_shape, full_shape[:1]) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, full_shape[:2]) | ||
# Bad shapes | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (163842, 2, 1)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (163842, 1, 2)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, 163842, 1)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, 1, 163842)) | ||
assert_raises(HeaderDataError, hdr.set_data_shape, (1, 1, 1, 163842)) | ||
# Test consistency of data in .mgh and mri_convert produced .nii | ||
nitest_path = os.path.join(get_nibabel_data(), 'nitest-freesurfer') | ||
mgh = mghload(os.path.join(nitest_path, 'fsaverage', 'surf', | ||
|
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.
Maybe 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 - scratch that - I see it's at the top of the function already.