@@ -261,19 +261,29 @@ 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 , 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
264
274
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
270
279
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,))
271
280
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,1 ))
272
281
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,1 ,2 ))
273
282
assert_raises (HeaderDataError , hdr .set_data_shape , (too_big ,2 ,1 ))
274
283
assert_raises (HeaderDataError , hdr .set_data_shape , (1 , too_big ))
275
284
assert_raises (HeaderDataError , hdr .set_data_shape , (1 , too_big , 1 ))
276
285
assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , too_big ))
286
+ assert_raises (HeaderDataError , hdr .set_data_shape , (1 , 1 , 1 , too_big ))
277
287
# Outside range of glmin raises error
278
288
far_too_big = int (np .iinfo (glmin ).max ) + 1
279
289
with suppress_warnings ():
@@ -295,9 +305,22 @@ def test_freesurfer_large_vector_hack(self):
295
305
def test_freesurfer_ico7_hack (self ):
296
306
HC = self .header_class
297
307
hdr = HC ()
308
+ full_shape = (163842 , 1 , 1 , 1 , 1 , 1 , 1 )
298
309
# 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 ))
301
324
# Test consistency of data in .mgh and mri_convert produced .nii
302
325
nitest_path = os .path .join (get_nibabel_data (), 'nitest-freesurfer' )
303
326
mgh = mghload (os .path .join (nitest_path , 'fsaverage' , 'surf' ,
0 commit comments