Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Coerce images to 32-bit #759

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
tsalo marked this conversation as resolved.
Show resolved Hide resolved
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