@@ -261,19 +261,29 @@ def test_freesurfer_large_vector_hack(self):
261261 hdr .set_data_shape ((too_big - 1 , 1 , 1 ))
262262 assert_equal (hdr .get_data_shape (), (too_big - 1 , 1 , 1 ))
263263 # The freesurfer case
264+ full_shape = (too_big , 1 , 1 , 1 , 1 , 1 , 1 )
265+ for dim in range (3 , 8 ):
266+ # First element in 'dim' field is number of dimensions
267+ expected_dim = np .array ([dim , - 1 , 1 , 1 , 1 , 1 , 1 , 1 ])
268+ with suppress_warnings ():
269+ hdr .set_data_shape (full_shape [:dim ])
270+ assert_equal (hdr .get_data_shape (), full_shape [:dim ])
271+ assert_array_equal (hdr ['dim' ], expected_dim )
272+ assert_equal (hdr ['glmin' ], too_big )
273+ # Allow the fourth dimension to vary
264274 with suppress_warnings ():
265- hdr .set_data_shape ((too_big , 1 , 1 ))
266- assert_equal (hdr .get_data_shape (), (too_big , 1 , 1 ))
267- assert_array_equal (hdr ['dim' ][:4 ], [3 , - 1 , 1 , 1 ])
268- assert_equal (hdr ['glmin' ], too_big )
269- # This only works for the case of a 3D with -1, 1, 1
275+ hdr .set_data_shape ((too_big , 1 , 1 , 4 ))
276+ assert_equal (hdr .get_data_shape (), (too_big , 1 , 1 , 4 ))
277+ assert_array_equal (hdr ['dim' ][:5 ], np .array ([4 , - 1 , 1 , 1 , 4 ]))
278+ # This only works when the first 3 dimensions are -1, 1, 1
270279 assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,))
271280 assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,1 ))
272281 assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,1 ,2 ))
273282 assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,2 ,1 ))
274283 assert_raises (HeaderDataError , hdr .set_data_shape , (1 , too_big ))
275284 assert_raises (HeaderDataError , hdr .set_data_shape , (1 , too_big , 1 ))
276285 assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , too_big ))
286+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 1 , too_big ))
277287 # Outside range of glmin raises error
278288 far_too_big = int (np .iinfo (glmin ).max ) + 1
279289 with suppress_warnings ():
@@ -295,9 +305,22 @@ def test_freesurfer_large_vector_hack(self):
295305 def test_freesurfer_ico7_hack (self ):
296306 HC = self .header_class
297307 hdr = HC ()
308+ full_shape = (163842 , 1 , 1 , 1 , 1 , 1 , 1 )
298309 # Test that using ico7 shape automatically uses factored dimensions
299- hdr .set_data_shape ((163842 , 1 , 1 ))
300- assert_array_equal (hdr ._structarr ['dim' ][1 :4 ], np .array ([27307 , 1 , 6 ]))
310+ for dim in range (3 , 8 ):
311+ expected_dim = np .array ([dim , 27307 , 1 , 6 , 1 , 1 , 1 , 1 ])
312+ hdr .set_data_shape (full_shape [:dim ])
313+ assert_equal (hdr .get_data_shape (), full_shape [:dim ])
314+ assert_array_equal (hdr ._structarr ['dim' ], expected_dim )
315+ # Only works on dimensions >= 3
316+ assert_raises (HeaderDataError , hdr .set_data_shape , full_shape [:1 ])
317+ assert_raises (HeaderDataError , hdr .set_data_shape , full_shape [:2 ])
318+ # Bad shapes
319+ assert_raises (HeaderDataError , hdr .set_data_shape , (163842 , 2 , 1 ))
320+ assert_raises (HeaderDataError , hdr .set_data_shape , (163842 , 1 , 2 ))
321+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 163842 , 1 ))
322+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 163842 ))
323+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 1 , 163842 ))
301324 # Test consistency of data in .mgh and mri_convert produced .nii
302325 nitest_path = os .path .join (get_nibabel_data (), 'nitest-freesurfer' )
303326 mgh = mghload (os .path .join (nitest_path , 'fsaverage' , 'surf' ,
0 commit comments