Skip to content

Commit 0a3b0b8

Browse files
committed
BF FreeSurfer nifti surfaces can have >3 dimensions
1 parent 60d4b72 commit 0a3b0b8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

nibabel/nifti1.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,15 +707,15 @@ def get_data_shape(self):
707707
'''
708708
shape = super(Nifti1Header, self).get_data_shape()
709709
# Apply freesurfer hack for vector
710-
if shape == (-1, 1, 1):
710+
if shape[:3] == (-1, 1, 1):
711711
vec_len = int(self._structarr['glmin'])
712712
if vec_len == 0:
713713
raise HeaderDataError('-1 in dim[1] but 0 in glmin; '
714714
'inconsistent freesurfer type header?')
715-
return (vec_len, 1, 1)
715+
return (vec_len, 1, 1) + shape[3:]
716716
# Apply freesurfer hack for ico7 surface
717-
elif shape == (27307, 1, 6):
718-
return (163842, 1, 1)
717+
elif shape[:3] == (27307, 1, 6):
718+
return (163842, 1, 1) + shape[3:]
719719
else: # Normal case
720720
return shape
721721

@@ -746,10 +746,10 @@ def set_data_shape(self, shape):
746746
shape = tuple(shape)
747747

748748
# Apply freesurfer hack for ico7 surface
749-
if shape == (163842, 1, 1):
750-
shape = (27307, 1, 6)
749+
if shape[:3] == (163842, 1, 1):
750+
shape = (27307, 1, 6) + shape[3:]
751751
# Apply freesurfer hack for vector
752-
elif (len(shape) == 3 and shape[1:] == (1, 1) and
752+
elif (len(shape) >= 3 and shape[1:3] == (1, 1) and
753753
shape[0] > np.iinfo(hdr['dim'].dtype.base).max):
754754
try:
755755
hdr['glmin'] = shape[0]
@@ -762,7 +762,7 @@ def set_data_shape(self, shape):
762762
shape[0])
763763
warnings.warn('Using large vector Freesurfer hack; header will '
764764
'not be compatible with SPM or FSL', stacklevel=2)
765-
shape = (-1, 1, 1)
765+
shape = (-1, 1, 1) + shape[3:]
766766
super(Nifti1Header, self).set_data_shape(shape)
767767

768768
def get_qform_quaternion(self):

0 commit comments

Comments
 (0)