Skip to content

Commit 0c1d650

Browse files
committed
RF: Improve footer handling
1 parent d910ad8 commit 0c1d650

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

nibabel/freesurfer/mghformat.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
]
4141
# Optional footer. Also has more stuff after this, optionally
4242
footer_dtd = [
43-
('mrparms', '>f4', (4,))
43+
('tr', '>f4'), # 0; repetition time
44+
('flip_angle', '>f4'), # 4; flip angle
45+
('te', '>f4'), # 8; echo time
46+
('ti', '>f4'), # 12; inversion time
47+
('fov', '>f4'), # 16; field of view (unused)
4448
]
4549

4650
header_dtype = np.dtype(header_dtd)
@@ -104,6 +108,14 @@ def __init__(self,
104108
if endianness != '>':
105109
raise ValueError("MGHHeader is big-endian")
106110

111+
min_size = self._hdrdtype.itemsize
112+
full_size = self.template_dtype.itemsize
113+
if binaryblock is not None and len(binaryblock) >= min_size:
114+
# Right zero-pad or truncate binaryblock to appropriate size
115+
# Footer is optional and may contain variable-length text fields,
116+
# so limit to fixed fields
117+
binaryblock = (binaryblock[:full_size] +
118+
b'\x00' * (full_size - len(binaryblock)))
107119
super(MGHHeader, self).__init__(binaryblock=binaryblock,
108120
endianness=endianness,
109121
check=False)

0 commit comments

Comments
 (0)