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

FIX: Ensure dataobj datatype is altered #527

Merged
merged 4 commits into from
May 26, 2020
Merged
Changes from 2 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
10 changes: 9 additions & 1 deletion niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,16 @@ def _run_interface(self, runtime):
# load updated NIfTI
nii = nb.load(out_file, mmap=False)
data_dtype = np.dtype(data_dtype)
if nii.get_data_dtype() != data_dtype:
orig_dtype = nii.get_data_dtype()
if orig_dtype != data_dtype:
LOGGER.warning(
f"Changing {out_file} dtype from {orig_dtype} to {data_dtype}"
)
# coerce dataobj to new data dtype
new_data = np.asanyarray(nii.dataobj, dtype=data_dtype)
# and set header to match
nii.set_data_dtype(data_dtype)
nii = nii.__class__(new_data, nii.affine, nii.header)
nii.to_filename(out_file)

if len(self._results["out_file"]) == 1:
Expand Down