Skip to content

Commit

Permalink
Coerces images to 32-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Teves committed Jul 19, 2021
1 parent 12f16eb commit a52af7b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tedana/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def save_img(self, data, name):
Data to save to a file.
name : str
Full file path for output file.
Notes
-----
Will coerce 64-bit float and int arrays into 32-bit arrays.
"""
data_type = type(data)
if not isinstance(data, np.ndarray):
Expand All @@ -225,6 +229,14 @@ def save_img(self, data, name):
"Data must have number of dimensions in (1, 2), not "
f"{data.ndim}"
)
# Coerce data to be 32-bit max in the cases of float64, int64
# Note that int64 niftis cannot be read by mricroGL, AFNI
vox_type = data.dtype
if vox_type == np.int64:
data = np.int32(data)
elif vox_type == np.float64:
data = np.float32(data)
# Make new img and save
img = new_nii_like(self.reference_img, data)
img.to_filename(name)

Expand Down

0 comments on commit a52af7b

Please sign in to comment.