@@ -261,19 +261,28 @@ def test_freesurfer_large_vector_hack(self):
261
261
hdr .set_data_shape ((too_big - 1 , 1 , 1 ))
262
262
assert_equal (hdr .get_data_shape (), (too_big - 1 , 1 , 1 ))
263
263
# The freesurfer case
264
+ full_shape = (too_big , 1 , 1 , 1 , 1 , 1 , 1 )
265
+ for dim in range (3 , 7 ):
266
+ expected_dim = np .array ([dim , - 1 , 1 , 1 , 1 , 1 , 1 , 1 ])
267
+ with suppress_warnings ():
268
+ hdr .set_data_shape (full_shape [:dim ])
269
+ assert_equal (hdr .get_data_shape (), full_shape [:dim ])
270
+ assert_array_equal (hdr ['dim' ], expected_dim )
271
+ assert_equal (hdr ['glmin' ], too_big )
272
+ # Allow the fourth dimension to vary
264
273
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
274
+ hdr .set_data_shape ((too_big , 1 , 1 , 4 ))
275
+ assert_equal (hdr .get_data_shape (), (too_big , 1 , 1 , 4 ))
276
+ assert_array_equal (hdr ['dim' ][:5 ], np .array ([4 , - 1 , 1 , 1 , 4 ]))
277
+ # This only works when the first 3 dimensions are -1, 1, 1
270
278
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,))
271
279
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,1 ))
272
280
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,1 ,2 ))
273
281
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,2 ,1 ))
274
282
assert_raises (HeaderDataError , hdr .set_data_shape , (1 , too_big ))
275
283
assert_raises (HeaderDataError , hdr .set_data_shape , (1 , too_big , 1 ))
276
284
assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , too_big ))
285
+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 1 , too_big ))
277
286
# Outside range of glmin raises error
278
287
far_too_big = int (np .iinfo (glmin ).max ) + 1
279
288
with suppress_warnings ():
@@ -295,9 +304,22 @@ def test_freesurfer_large_vector_hack(self):
295
304
def test_freesurfer_ico7_hack (self ):
296
305
HC = self .header_class
297
306
hdr = HC ()
307
+ full_shape = (163842 , 1 , 1 , 1 , 1 , 1 , 1 )
298
308
# 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 ]))
309
+ for dim in range (3 , 7 ):
310
+ expected_dim = np .array ([dim , 27307 , 1 , 6 , 1 , 1 , 1 , 1 ])
311
+ hdr .set_data_shape (full_shape [:dim ])
312
+ assert_equal (hdr .get_data_shape (), full_shape [:dim ])
313
+ assert_array_equal (hdr ._structarr ['dim' ], expected_dim )
314
+ # Only works on dimensions >= 3
315
+ assert_raises (HeaderDataError , hdr .set_data_shape , full_shape [:1 ])
316
+ assert_raises (HeaderDataError , hdr .set_data_shape , full_shape [:2 ])
317
+ # Bad shapes
318
+ assert_raises (HeaderDataError , hdr .set_data_shape , (163842 , 2 , 1 ))
319
+ assert_raises (HeaderDataError , hdr .set_data_shape , (163842 , 1 , 2 ))
320
+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 163842 , 1 ))
321
+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 163842 ))
322
+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 1 , 163842 ))
301
323
# Test consistency of data in .mgh and mri_convert produced .nii
302
324
nitest_path = os .path .join (get_nibabel_data (), 'nitest-freesurfer' )
303
325
mgh = mghload (os .path .join (nitest_path , 'fsaverage' , 'surf' ,
0 commit comments