@@ -62,62 +62,80 @@ class C3dAffineTool(SEMLikeCommandLine):
62
62
63
63
64
64
class C3dInputSpec (CommandLineInputSpec ):
65
- in_file = InputMultiPath (File (),
65
+ in_file = InputMultiPath (
66
+ File (),
66
67
position = 1 ,
67
68
argstr = "%s" ,
68
69
mandatory = True ,
69
- desc = "Input file (wildcard and multiple are supported)" )
70
- out_file = File (exists = False ,
70
+ desc = "Input file (wildcard and multiple are supported)." )
71
+ out_file = File (
72
+ exists = False ,
71
73
argstr = "-o %s" ,
72
74
position = - 1 ,
73
75
xor = ["out_files" ],
74
- desc = "Output file of last image on the stack" )
75
- out_files = InputMultiPath (File (),
76
+ desc = "Output file of last image on the stack." )
77
+ out_files = InputMultiPath (
78
+ File (),
76
79
argstr = "-oo %s" ,
77
80
xor = ["out_file" ],
78
81
position = - 1 ,
79
82
desc = ("Write all images on the convert3d stack as multiple files."
80
83
" Supports both list of output files or a pattern for the output"
81
84
" filenames (using %d substituion)." ))
82
- pix_type = traits .Enum ("float" , "char" , "uchar" , "short" , "ushort" , "int" , "uint" , "double" ,
85
+ pix_type = traits .Enum (
86
+ "float" , "char" , "uchar" , "short" , "ushort" , "int" , "uint" , "double" ,
83
87
argstr = "-type %s" ,
84
- desc = ("Specifies the pixel type for the output image. By default, images are written in"
85
- " floating point (float) format" ))
86
- scale = traits .Either (traits .Int (), traits .Float (),
88
+ desc = ("Specifies the pixel type for the output image. By default,"
89
+ " images are written in floating point (float) format" ))
90
+ scale = traits .Either (
91
+ traits .Int (), traits .Float (),
87
92
argstr = "-scale %s" ,
88
- desc = "Multiplies the intensity of each voxel in the last image on the stack by the given factor." )
89
- shift = traits .Either (traits .Int (), traits .Float (),
93
+ desc = ("Multiplies the intensity of each voxel in the last image on the"
94
+ " stack by the given factor." )
95
+ shift = traits .Either (
96
+ traits .Int (), traits .Float (),
90
97
argstr = "-shift %s" ,
91
98
desc = 'Adds the given constant to every voxel.' )
92
- interp = traits .Enum ("Linear" , "NearestNeighbor" , "Cubic" , "Sinc" , "Gaussian" ,
99
+ interp = traits .Enum (
100
+ "Linear" , "NearestNeighbor" , "Cubic" , "Sinc" , "Gaussian" ,
93
101
argstr = "-interpolation %s" ,
94
- desc = "Specifies the interpolation used with -resample and other commands. Default is Linear." )
95
- resample = traits .Str (argstr = "-resample %s" ,
96
- desc = ("Resamples the image, keeping the bounding box the same, but changing the number of"
97
- " voxels in the image. The dimensions can be specified as a percentage, for example to"
98
- " double the number of voxels in each direction. The -interpolation flag affects how"
99
- " sampling is performed." ))
100
- smooth = traits .Str (argstr = "-smooth %s" ,
101
- desc = ("Applies Gaussian smoothing to the image. The parameter vector specifies the"
102
- " standard deviation of the Gaussian kernel." ))
103
- multicomp_split = traits .Bool (False ,
102
+ desc = ("Specifies the interpolation used with -resample and other"
103
+ " commands. Default is Linear." )
104
+ resample = traits .Str (
105
+ argstr = "-resample %s" ,
106
+ desc = ("Resamples the image, keeping the bounding box the same, but"
107
+ " changing the number of voxels in the image. The dimensions can be"
108
+ " specified as a percentage, for example to double the number of voxels"
109
+ " in each direction. The -interpolation flag affects how sampling is"
110
+ " performed." ))
111
+ smooth = traits .Str (
112
+ argstr = "-smooth %s" ,
113
+ desc = ("Applies Gaussian smoothing to the image. The parameter vector"
114
+ " specifies the standard deviation of the Gaussian kernel." ))
115
+ multicomp_split = traits .Bool (
116
+ False ,
104
117
usedefault = True ,
105
118
argstr = "-mcr" ,
106
119
position = 0 ,
107
120
desc = "Enable reading of multi-component images." )
108
- is_4d = traits .Bool (False ,
121
+ is_4d = traits .Bool (
122
+ False ,
109
123
usedefault = True ,
110
- desc = "Changes command to support 4D file operations (default is false)." )
124
+ desc = ("Changes command to support 4D file operations (default is"
125
+ " false)." )
126
+
111
127
112
128
class C3dOutputSpec (TraitedSpec ):
113
129
out_files = OutputMultiPath (File (exists = False ))
114
130
131
+
115
132
class C3d (CommandLine ):
116
133
"""
117
- Convert3d is a command-line tool for converting 3D (or 4D) images between common
118
- file formats. The tool also includes a growing list of commands for image manipulation,
119
- such as thresholding and resampling. The tool can also be used to obtain information about
120
- image files. More information on Convert3d can be found at:
134
+ Convert3d is a command-line tool for converting 3D (or 4D) images between
135
+ common file formats. The tool also includes a growing list of commands for
136
+ image manipulation, such as thresholding and resampling. The tool can also
137
+ be used to obtain information about image files. More information on
138
+ Convert3d can be found at:
121
139
https://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md
122
140
123
141
@@ -153,8 +171,10 @@ def _is_4d(self):
153
171
154
172
def _run_interface (self , runtime ):
155
173
cmd = self ._cmd
156
- # by default, does not want to override file, so we define a new output file
157
- if not isdefined (self .inputs .out_file ) and not isdefined (self .inputs .out_files ):
174
+ if (not isdefined (self .inputs .out_file )
175
+ and not isdefined (self .inputs .out_files )):
176
+ # Convert3d does not want to override file, by default
177
+ # so we define a new output file
158
178
self ._gen_outfile ()
159
179
runtime = super (C3d , self )._run_interface (runtime )
160
180
self ._cmd = cmd
@@ -163,11 +183,14 @@ def _run_interface(self, runtime):
163
183
def _gen_outfile (self ):
164
184
# if many infiles, raise exception
165
185
if (len (self .inputs .in_file ) > 1 ) or ("*" in self .inputs .in_file [0 ]):
166
- raise AttributeError ("Multiple in_files found - specify either out_file or out_files" )
186
+ raise AttributeError ("Multiple in_files found - specify either"
187
+ " `out_file` or `out_files`." )
167
188
_, fn , ext = split_filename (self .inputs .in_file [0 ])
168
189
self .inputs .out_file = fn + "_generated" + ext
169
- assert not os .path .exists (os .path .abspath (self .inputs .out_file ))
170
- iflogger .info ("Generating out_file to avoid overwriting" )
190
+ # if generated file will overwrite, raise error
191
+ if os .path .exists (os .path .abspath (self .inputs .out_file )):
192
+ raise IOError ("File already found - to overwrite, use `out_file`." )
193
+ iflogger .info ("Generating `out_file`." )
171
194
172
195
def _list_outputs (self ):
173
196
outputs = self .output_spec ().get ()
@@ -177,8 +200,9 @@ def _list_outputs(self):
177
200
if len (self .inputs .out_files ) == 1 :
178
201
_out_files = glob (os .path .abspath (self .inputs .out_files [0 ]))
179
202
else :
180
- _out_files = [os .path .abspath (fl ) for fl in self .inputs .out_files
181
- if os .path .exists (os .path .abspath (fl ))]
203
+ _out_files = [os .path .abspath (f ) for f in self .inputs .out_files
204
+ if os .path .exists (os .path .abspath (f ))]
182
205
outputs ["out_files" ] = _out_files
183
206
184
207
return outputs
208
+
0 commit comments