Skip to content

Commit de1d708

Browse files
committed
Merge pull request #426 from chrisfilo/fix/abspaths
Fixed output files hashing and returned paths.
2 parents 1b8fc66 + cc07242 commit de1d708

File tree

6 files changed

+73
-59
lines changed

6 files changed

+73
-59
lines changed

doc/devel/interface_specs.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ Common
194194
TraitError: The 'infile' trait of a BetInputSpec instance must be a file
195195
name, but a value of 'does_not_exist.nii' <type 'str'> was specified.
196196
197+
``hash_files``
198+
To be used with inputs that are defining output filenames. When this flag is set to false any Nipype will not try to hash any files described by this input. This is useful to avoid rerunning when the specified output file already exists and has changed.
199+
197200
``desc``
198201
All trait objects have a set of default metadata attributes. ``desc``
199202
is one of those and is used as a simple, one-line docstring. The

nipype/interfaces/fsl/dti.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _list_outputs(self):
102102

103103
class EddyCorrectInputSpec(FSLCommandInputSpec):
104104
in_file = File(exists=True, desc='4D input file', argstr='%s', position=0, mandatory=True)
105-
out_file = File(desc='4D output file', argstr='%s', position=1, genfile=True)
105+
out_file = File(desc='4D output file', argstr='%s', position=1, genfile=True, hash_files=False)
106106
ref_num = traits.Int(argstr='%d', position=2, desc='reference number', mandatory=True)
107107

108108

@@ -143,6 +143,7 @@ def _list_outputs(self):
143143
outputs['eddy_corrected'] = self.inputs.out_file
144144
if not isdefined(outputs['eddy_corrected']):
145145
outputs['eddy_corrected'] = self._gen_fname(self.inputs.in_file, suffix='_edc')
146+
outputs['eddy_corrected'] = os.path.abspath(outputs['eddy_corrected'])
146147
return outputs
147148

148149
def _gen_filename(self, name):
@@ -492,7 +493,7 @@ class VecRegInputSpec(FSLCommandInputSpec):
492493
in_file = File(exists=True, argstr='-i %s', desc='filename for input vector or tensor field',
493494
mandatory=True)
494495
out_file = File(argstr='-o %s', desc='filename for output registered vector or tensor field',
495-
genfile=True)
496+
genfile=True, hash_files=False)
496497
ref_vol = File(exists=True, argstr='-r %s', desc='filename for reference (target) volume',
497498
mandatory=True)
498499
affine_mat = File(exists=True, argstr='-t %s',
@@ -554,6 +555,7 @@ def _list_outputs(self):
554555
pth, base_name = os.path.split(self.inputs.in_file)
555556
outputs['out_file'] = self._gen_fname(base_name, cwd=os.path.abspath(pth),
556557
suffix='_vreg')
558+
outputs['out_file'] = os.path.abspath(outputs['out_file'])
557559
return outputs
558560

559561
def _gen_filename(self, name):
@@ -610,7 +612,7 @@ def _list_outputs(self):
610612
class FindTheBiggestInputSpec(FSLCommandInputSpec):
611613
in_files = traits.List(File, exists=True, argstr='%s', desc='a list of input volumes or a singleMatrixFile',
612614
position=0, mandatory=True)
613-
out_file = File(argstr='%s', desc='file with the resulting segmentation', position=2, genfile=True)
615+
out_file = File(argstr='%s', desc='file with the resulting segmentation', position=2, genfile=True, hash_files=False)
614616

615617

616618
class FindTheBiggestOutputSpec(TraitedSpec):
@@ -648,6 +650,7 @@ def _list_outputs(self):
648650
outputs['out_file'] = self.inputs.out_file
649651
if not isdefined(outputs['out_file']):
650652
outputs['out_file'] = self._gen_fname('biggestSegmentation', suffix='')
653+
outputs['out_file'] = os.path.abspath(outputs['out_file'])
651654
return outputs
652655

653656
def _gen_filename(self, name):
@@ -762,8 +765,8 @@ class DistanceMapInputSpec(FSLCommandInputSpec):
762765
desc="binary mask to contrain calculations")
763766
invert_input = traits.Bool(argstr="--invert", desc="invert input image")
764767
local_max_file = traits.Either(traits.Bool, File, argstr="--localmax=%s",
765-
desc="write an image of the local maxima")
766-
distance_map = File(genfile=True, argstr="--out=%s", desc="distance map to write")
768+
desc="write an image of the local maxima", hash_files=False)
769+
distance_map = File(genfile=True, argstr="--out=%s", desc="distance map to write", hash_files=False)
767770

768771

769772
class DistanceMapOutputSpec(TraitedSpec):
@@ -804,13 +807,15 @@ def _list_outputs(self):
804807
suffix="_dstmap",
805808
use_ext=True,
806809
newpath=os.getcwd())
810+
outputs["distance_map"] = os.path.abspath(outputs["distance_map"])
807811
if isdefined(_si.local_max_file):
808812
outputs["local_max_file"] = _si.local_max_file
809813
if isinstance(_si.local_max_file, bool):
810814
outputs["local_max_file"] = fname_presuffix(_si.in_file,
811815
suffix="_lclmax",
812816
use_ext=True,
813817
newpath=os.getcwd())
818+
outputs["local_max_file"] = os.path.abspath(outputs["local_max_file"]))
814819
return outputs
815820

816821
def _gen_filename(self, name):
@@ -905,7 +910,7 @@ class MakeDyadicVectorsInputSpec(FSLCommandInputSpec):
905910
theta_vol = File(exists=True, mandatory=True, position=0, argstr="%s")
906911
phi_vol = File(exists=True, mandatory=True, position=1, argstr="%s")
907912
mask = File(exists=True, position=2, argstr="%s")
908-
output = File("dyads", position=3, usedefault=True, argstr="%s")
913+
output = File("dyads", position=3, usedefault=True, argstr="%s", hash_files=False)
909914
perc = traits.Float(desc="the {perc}% angle of the output cone of \
910915
uncertainty (output will be in degrees)",
911916
position=4,

nipype/interfaces/fsl/maths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MathsInput(FSLCommandInputSpec):
1616

1717
in_file = File(position=2, argstr="%s", exists=True, mandatory=True,
1818
desc="image to operate on")
19-
out_file = File(genfile=True, position=-2, argstr="%s", desc="image to write")
19+
out_file = File(genfile=True, position=-2, argstr="%s", desc="image to write", hash_files=False)
2020
_dtypes = ["float", "char", "int", "short", "double", "input"]
2121
internal_datatype = traits.Enum(*_dtypes, position=1, argstr="-dt %s",
2222
desc="datatype to use for calculations (default is float)")
@@ -39,9 +39,10 @@ class MathsCommand(FSLCommand):
3939

4040
def _list_outputs(self):
4141
outputs = self.output_spec().get()
42-
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
42+
outputs["out_file"] = self.inputs.out_file
4343
if not isdefined(self.inputs.out_file):
4444
outputs["out_file"] = self._gen_fname(self.inputs.in_file, suffix=self._suffix)
45+
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
4546
return outputs
4647

4748
def _gen_filename(self, name):

nipype/interfaces/fsl/model.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,28 +1285,28 @@ class ClusterInputSpec(FSLCommandInputSpec):
12851285
desc='threshold for input volume')
12861286
out_index_file = traits.Either(traits.Bool, File,
12871287
argstr='--oindex=%s',
1288-
desc='output of cluster index (in size order)')
1288+
desc='output of cluster index (in size order)', hash_files=False)
12891289
out_threshold_file = traits.Either(traits.Bool, File,
12901290
argstr='--othresh=%s',
1291-
desc='thresholded image')
1291+
desc='thresholded image', hash_files=False)
12921292
out_localmax_txt_file = traits.Either(traits.Bool, File,
12931293
argstr='--olmax=%s',
1294-
desc='local maxima text file')
1294+
desc='local maxima text file', hash_files=False)
12951295
out_localmax_vol_file = traits.Either(traits.Bool, File,
12961296
argstr='--olmaxim=%s',
1297-
desc='output of local maxima volume')
1297+
desc='output of local maxima volume', hash_files=False)
12981298
out_size_file = traits.Either(traits.Bool, File,
12991299
argstr='--osize=%s',
1300-
desc='filename for output of size image')
1300+
desc='filename for output of size image', hash_files=False)
13011301
out_max_file = traits.Either(traits.Bool, File,
13021302
argstr='--omax=%s',
1303-
desc='filename for output of max image')
1303+
desc='filename for output of max image', hash_files=False)
13041304
out_mean_file = traits.Either(traits.Bool, File,
13051305
argstr='--omean=%s',
1306-
desc='filename for output of mean image')
1306+
desc='filename for output of mean image', hash_files=False)
13071307
out_pval_file = traits.Either(traits.Bool, File,
13081308
argstr='--opvals=%s',
1309-
desc='filename for image output of log pvals')
1309+
desc='filename for image output of log pvals', hash_files=False)
13101310
pthreshold = traits.Float(argstr='--pthresh=%.10f',
13111311
requires=['dlh', 'volume'],
13121312
desc='p-threshold for clusters')
@@ -1387,7 +1387,7 @@ def _list_outputs(self):
13871387
suffix='_' + suffix,
13881388
change_ext=change_ext)
13891389
else:
1390-
outputs[outkey] = inval
1390+
outputs[outkey] = os.pardir.abspath(inval)
13911391
return outputs
13921392

13931393
def _format_arg(self, name, spec, value):

0 commit comments

Comments
 (0)