From a52af7b0496fffb8b07b7c3e7c4753e18a2b1bb1 Mon Sep 17 00:00:00 2001 From: Joshua Teves Date: Mon, 19 Jul 2021 11:07:12 -0400 Subject: [PATCH] Coerces images to 32-bit --- tedana/io.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tedana/io.py b/tedana/io.py index e60559882..b60a41c5c 100644 --- a/tedana/io.py +++ b/tedana/io.py @@ -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): @@ -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)