Skip to content

Commit 848ca49

Browse files
committed
FIX: Finalize NIfTI dtype before calling Analyze.to_file_map
1 parent d33336a commit 848ca49

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

nibabel/nifti1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,25 @@ def get_data_dtype(self, finalize=False):
21802180
self.set_data_dtype(datatype) # Clears the alias
21812181
return super().get_data_dtype()
21822182

2183+
def to_file_map(self, file_map=None, dtype=None):
2184+
""" Write image to `file_map` or contained ``self.file_map``
2185+
2186+
Parameters
2187+
----------
2188+
file_map : None or mapping, optional
2189+
files mapping. If None (default) use object's ``file_map``
2190+
attribute instead
2191+
dtype : dtype-like, optional
2192+
The on-disk data type to coerce the data array.
2193+
"""
2194+
img_dtype = self.get_data_dtype()
2195+
self.get_data_dtype(finalize=True)
2196+
try:
2197+
super().to_file_map(file_map, dtype)
2198+
finally:
2199+
self.set_data_dtype(img_dtype)
2200+
2201+
21832202
def as_reoriented(self, ornt):
21842203
"""Apply an orientation change and return a new image
21852204

0 commit comments

Comments
 (0)