Skip to content

Commit c6526f7

Browse files
committed
TEST: FreeSurfer ico7 surface NIfTI hack
1 parent d26215e commit c6526f7

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

nibabel/tests/test_nifti1.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
Nifti1Pair, Nifti1Extension, Nifti1Extensions,
2525
data_type_codes, extension_codes, slice_order_codes)
2626

27+
from ..freesurfer import load as mghload
28+
2729
from .test_arraywriters import rt_err_estimate, IUINT_TYPES
2830
from .test_helpers import bytesio_filemap, bytesio_round_trip
31+
from .nibabel_data import get_nibabel_data, needs_nibabel_data
2932

3033
from numpy.testing import (assert_array_equal, assert_array_almost_equal,
3134
assert_almost_equal)
@@ -242,7 +245,7 @@ def test_magic_offset_checks(self):
242245
'file nifti1; setting to minimum value '
243246
'of ' + str(hdr.single_vox_offset))
244247

245-
def test_freesurfer_hack(self):
248+
def test_freesurfer_large_vector_hack(self):
246249
# For large vector images, Freesurfer appears to set dim[1] to -1 and
247250
# then use glmin for the vector length (an i4)
248251
HC = self.header_class
@@ -288,6 +291,40 @@ def test_freesurfer_hack(self):
288291
hdr.set_data_shape(constructor(shape))
289292
assert_equal(hdr.get_data_shape(), shape)
290293

294+
@needs_nibabel_data('nitest-freesurfer')
295+
def test_freesurfer_ico7_hack(self):
296+
HC = self.header_class
297+
hdr = HC()
298+
299+
# Test that using ico7 shape automatically uses factored dimensions
300+
hdr.set_data_shape((163842, 1, 1))
301+
assert_array_equal(hdr._structarr['dim'][1:4], np.array([27307, 1, 6]))
302+
303+
# Test consistency of data in .mgh and mri_convert produced .nii
304+
nib_data = get_nibabel_data()
305+
nitest_path = os.path.join(nib_data, 'nitest-freesurfer')
306+
307+
mgh = mghload(os.path.join(nitest_path, 'fsaverage', 'surf',
308+
'lh.orig.avg.area.mgh'))
309+
nii = load(os.path.join(nitest_path, 'derivative', 'fsaverage', 'surf',
310+
'lh.orig.avg.area.nii'))
311+
312+
assert_equal(mgh.shape, nii.shape)
313+
assert_array_equal(mgh.get_data(), nii.get_data())
314+
assert_array_equal(nii.header._structarr['dim'][1:4],
315+
np.array([27307, 1, 6]))
316+
317+
# Test writing produces consistent nii files
318+
with InTemporaryDirectory():
319+
nii.to_filename('test.nii')
320+
321+
nii2 = load('test.nii')
322+
323+
assert_equal(nii.shape, nii2.shape)
324+
assert_array_equal(nii.get_data(), nii2.get_data())
325+
assert_array_equal(nii.get_affine(), nii2.get_affine())
326+
327+
291328
def test_qform_sform(self):
292329
HC = self.header_class
293330
hdr = HC()

nibabel/tests/test_nifti2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class _Nifti2Mixin(object):
3434
sizeof_hdr = Nifti2Header.sizeof_hdr
3535
quat_dtype = np.float64
3636

37-
def test_freesurfer_hack(self):
37+
def test_freesurfer_large_vector_hack(self):
38+
# Disable this check
39+
pass
40+
41+
def test_freesurfer_ico7_hack(self):
3842
# Disable this check
3943
pass
4044

0 commit comments

Comments
 (0)