From 85a285a80e40d89508ab80613499f371a79c9c55 Mon Sep 17 00:00:00 2001 From: dPys Date: Tue, 24 Mar 2020 12:19:34 -0500 Subject: [PATCH] [ENH] Add error handling to --- dmriprep/interfaces/images.py | 5 ++--- dmriprep/utils/images.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dmriprep/interfaces/images.py b/dmriprep/interfaces/images.py index 7e76a730..40a0b0a3 100644 --- a/dmriprep/interfaces/images.py +++ b/dmriprep/interfaces/images.py @@ -1,12 +1,11 @@ """Image tools interfaces.""" -from dmriprep.utils.images import rescale_b0, median, match_transforms, extract_b0 +from pathlib import Path from nipype import logging from nipype.interfaces.base import ( traits, TraitedSpec, BaseInterfaceInputSpec, SimpleInterface, File, InputMultiObject, OutputMultiObject ) - -from dmriprep.utils.images import extract_b0, median, rescale_b0 +from dmriprep.utils.images import extract_b0, median, rescale_b0, match_transforms LOGGER = logging.getLogger('nipype.interface') diff --git a/dmriprep/utils/images.py b/dmriprep/utils/images.py index fe3d0379..c176e091 100644 --- a/dmriprep/utils/images.py +++ b/dmriprep/utils/images.py @@ -362,7 +362,18 @@ def save_3d_to_4d(in_files): >>> out_file = save_3d_to_4d(threeD_files) >>> assert len(threeD_files) == nb.load(out_file).shape[-1] """ - img_4d = nb.funcs.concat_images([nb.load(img_3d) for img_3d in in_files]) + # Remove one-sized extra dimensions + nii_list = [] + for i, f in enumerate(in_files): + filenii = nb.load(f) + filenii = nb.squeeze_image(filenii) + if len(filenii.shape) == 5: + raise RuntimeError('Input image (%s) is 5D.' % f) + if filenii.dataobj.ndim == 4: + nii_list += nb.four_to_three(filenii) + else: + nii_list.append(filenii) + img_4d = nb.funcs.concat_images(nii_list) out_file = fname_presuffix(in_files[0], suffix="_merged") img_4d.to_filename(out_file) return out_file