Skip to content

Commit

Permalink
[ENH] Add error handling to
Browse files Browse the repository at this point in the history
  • Loading branch information
dPys committed Mar 24, 2020
1 parent 5e64dfa commit 85a285a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions dmriprep/interfaces/images.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
13 changes: 12 additions & 1 deletion dmriprep/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 85a285a

Please sign in to comment.