@@ -50,14 +50,16 @@ class NiftiGeneratorBaseInputSpec(TraitedSpec):
50
50
class NiftiGeneratorBase (BaseInterface ):
51
51
'''Base class for interfaces that produce Nifti files, potentially with
52
52
embeded meta data.'''
53
- def _get_out_path (self , meta ):
53
+ def _get_out_path (self , meta , idx = None ):
54
54
'''Return the output path for the gernerated Nifti.'''
55
55
if self .inputs .out_format :
56
56
out_fmt = self .inputs .out_format
57
57
else :
58
58
#If no out_format is specified, use a sane default that will work
59
59
#with the provided meta data.
60
60
out_fmt = []
61
+ if not idx is None :
62
+ out_fmt .append ('%03d' % idx )
61
63
if 'SeriesNumber' in meta :
62
64
out_fmt .append ('%(SeriesNumber)03d' )
63
65
if 'ProtocolName' in meta :
@@ -371,9 +373,9 @@ def _run_interface(self, runtime):
371
373
split_dim = None
372
374
else :
373
375
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 ) ):
375
377
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 )
377
379
nb .save (split_nw .nii_img , out_path )
378
380
self .out_list .append (out_path )
379
381
0 commit comments