Skip to content

Commit 54e0a03

Browse files
committed
BF: lack of proper get_zooms and set_zooms led to test failures.
also fixed a buggy get_data_dtype()
1 parent 455a8cb commit 54e0a03

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

nibabel/freesurfer/mghformat.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
# caveat 2: Note that the bytespervox you get is in str ( not an int)
4747
_dtdefs = ( # code, conversion function, dtype, bytes per voxel
4848
(0, 'uint8', '>u1', '1', 'MRI_UCHAR', np.uint8, np.dtype(np.uint8),
49-
np.dtype(np.uint8).newbyteorder('S')),
49+
np.dtype(np.uint8).newbyteorder('B')),
5050
(4, 'int16', '>i2', '2', 'MRI_SHORT', np.int16, np.dtype(np.int16),
51-
np.dtype(np.int16).newbyteorder('S')),
51+
np.dtype(np.int16).newbyteorder('B')),
5252
(1, 'int32', '>i4', '4', 'MRI_INT', np.int32, np.dtype(np.int32),
53-
np.dtype(np.int32).newbyteorder('S')),
53+
np.dtype(np.int32).newbyteorder('B')),
5454
(3, 'float', '>f4', '4', 'MRI_FLOAT', np.float32, np.dtype(np.float32),
55-
np.dtype(np.float32).newbyteorder('S')))
55+
np.dtype(np.float32).newbyteorder('B')))
5656

5757
# make full code alias bank, including dtype column
5858
data_type_codes = Recoder(_dtdefs, fields=('code', 'label', 'dtype',
@@ -243,7 +243,7 @@ def get_data_dtype(self):
243243
For examples see ``set_data_dtype``
244244
'''
245245
code = int(self._header_data['type'])
246-
dtype = self._data_type_codes.dtype[code]
246+
dtype = self._data_type_codes.numpy_dtype[code]
247247
return dtype
248248

249249
def set_data_dtype(self, datatype):
@@ -255,6 +255,34 @@ def set_data_dtype(self, datatype):
255255
raise MGHError('datatype dtype "%s" not recognized' % datatype)
256256
self._header_data['type'] = code
257257

258+
def get_zooms(self):
259+
''' Get zooms from header
260+
261+
Returns
262+
-------
263+
z : tuple
264+
tuple of header zoom values
265+
'''
266+
hdr = self._header_data
267+
zooms = hdr['delta']
268+
return tuple(zooms[:])
269+
270+
def set_zooms(self, zooms):
271+
''' Set zooms into header fields
272+
273+
See docstring for ``get_zooms`` for examples
274+
'''
275+
hdr = self._header_data
276+
zooms = np.asarray(zooms)
277+
if len(zooms) != hdr['delta']:
278+
raise HeaderDataError('Expecting %d zoom values for ndim'
279+
% hdr['delta'])
280+
if np.any(zooms < 0):
281+
raise HeaderDataError('zooms must be positive')
282+
delta = hdr['delta']
283+
delta[:] = zooms[:]
284+
285+
258286
def get_data_shape(self):
259287
''' Get shape of data
260288
'''

0 commit comments

Comments
 (0)