|
24 | 24 | Nifti1Pair, Nifti1Extension, Nifti1Extensions,
|
25 | 25 | data_type_codes, extension_codes, slice_order_codes)
|
26 | 26 |
|
| 27 | +from ..freesurfer import load as mghload |
| 28 | + |
27 | 29 | from .test_arraywriters import rt_err_estimate, IUINT_TYPES
|
28 | 30 | from .test_helpers import bytesio_filemap, bytesio_round_trip
|
| 31 | +from .nibabel_data import get_nibabel_data, needs_nibabel_data |
29 | 32 |
|
30 | 33 | from numpy.testing import (assert_array_equal, assert_array_almost_equal,
|
31 | 34 | assert_almost_equal)
|
@@ -242,7 +245,7 @@ def test_magic_offset_checks(self):
|
242 | 245 | 'file nifti1; setting to minimum value '
|
243 | 246 | 'of ' + str(hdr.single_vox_offset))
|
244 | 247 |
|
245 |
| - def test_freesurfer_hack(self): |
| 248 | + def test_freesurfer_large_vector_hack(self): |
246 | 249 | # For large vector images, Freesurfer appears to set dim[1] to -1 and
|
247 | 250 | # then use glmin for the vector length (an i4)
|
248 | 251 | HC = self.header_class
|
@@ -288,6 +291,40 @@ def test_freesurfer_hack(self):
|
288 | 291 | hdr.set_data_shape(constructor(shape))
|
289 | 292 | assert_equal(hdr.get_data_shape(), shape)
|
290 | 293 |
|
| 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 | + |
291 | 328 | def test_qform_sform(self):
|
292 | 329 | HC = self.header_class
|
293 | 330 | hdr = HC()
|
|
0 commit comments