Skip to content

Commit 2e37160

Browse files
committed
Merge pull request #524 from moloney/bf-split-nifti
BF: Fix SplitNifti to generate unique filenames for outputs.
2 parents 8390d70 + 0501bee commit 2e37160

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

nipype/interfaces/dcmstack.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ class NiftiGeneratorBaseInputSpec(TraitedSpec):
5050
class NiftiGeneratorBase(BaseInterface):
5151
'''Base class for interfaces that produce Nifti files, potentially with
5252
embeded meta data.'''
53-
def _get_out_path(self, meta):
53+
def _get_out_path(self, meta, idx=None):
5454
'''Return the output path for the gernerated Nifti.'''
5555
if self.inputs.out_format:
5656
out_fmt = self.inputs.out_format
5757
else:
5858
#If no out_format is specified, use a sane default that will work
5959
#with the provided meta data.
6060
out_fmt = []
61+
if not idx is None:
62+
out_fmt.append('%03d' % idx)
6163
if 'SeriesNumber' in meta:
6264
out_fmt.append('%(SeriesNumber)03d')
6365
if 'ProtocolName' in meta:
@@ -371,9 +373,9 @@ def _run_interface(self, runtime):
371373
split_dim = None
372374
else:
373375
split_dim = self.inputs.split_dim
374-
for split_nw in nw.split(split_dim):
376+
for split_idx, split_nw in enumerate(nw.split(split_dim)):
375377
const_meta = split_nw.meta_ext.get_class_dict(('global', 'const'))
376-
out_path = self._get_out_path(const_meta)
378+
out_path = self._get_out_path(const_meta, idx=split_idx)
377379
nb.save(split_nw.nii_img, out_path)
378380
self.out_list.append(out_path)
379381

0 commit comments

Comments
 (0)