Skip to content

Commit 392cc12

Browse files
committed
sty: pep8 and better error messages
1 parent 234c555 commit 392cc12

File tree

1 file changed

+59
-35
lines changed

1 file changed

+59
-35
lines changed

nipype/interfaces/c3.py

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,62 +62,80 @@ class C3dAffineTool(SEMLikeCommandLine):
6262

6363

6464
class C3dInputSpec(CommandLineInputSpec):
65-
in_file = InputMultiPath(File(),
65+
in_file = InputMultiPath(
66+
File(),
6667
position=1,
6768
argstr="%s",
6869
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,
7173
argstr="-o %s",
7274
position=-1,
7375
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(),
7679
argstr="-oo %s",
7780
xor=["out_file"],
7881
position=-1,
7982
desc=("Write all images on the convert3d stack as multiple files."
8083
" Supports both list of output files or a pattern for the output"
8184
" 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",
8387
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(),
8792
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(),
9097
argstr="-shift %s",
9198
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",
93101
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,
104117
usedefault=True,
105118
argstr="-mcr",
106119
position=0,
107120
desc="Enable reading of multi-component images.")
108-
is_4d = traits.Bool(False,
121+
is_4d = traits.Bool(
122+
False,
109123
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+
111127

112128
class C3dOutputSpec(TraitedSpec):
113129
out_files = OutputMultiPath(File(exists=False))
114130

131+
115132
class C3d(CommandLine):
116133
"""
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:
121139
https://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md
122140
123141
@@ -153,8 +171,10 @@ def _is_4d(self):
153171

154172
def _run_interface(self, runtime):
155173
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
158178
self._gen_outfile()
159179
runtime = super(C3d, self)._run_interface(runtime)
160180
self._cmd = cmd
@@ -163,11 +183,14 @@ def _run_interface(self, runtime):
163183
def _gen_outfile(self):
164184
# if many infiles, raise exception
165185
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`.")
167188
_, fn, ext = split_filename(self.inputs.in_file[0])
168189
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`.")
171194

172195
def _list_outputs(self):
173196
outputs = self.output_spec().get()
@@ -177,8 +200,9 @@ def _list_outputs(self):
177200
if len(self.inputs.out_files) == 1:
178201
_out_files = glob(os.path.abspath(self.inputs.out_files[0]))
179202
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))]
182205
outputs["out_files"] = _out_files
183206

184207
return outputs
208+

0 commit comments

Comments
 (0)