Skip to content

Commit ae3591c

Browse files
author
bpinsard
committed
fslcomplex interface + fix line removed inadvertently
1 parent 20efcda commit ae3591c

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

nipype/interfaces/fsl/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class FASTInputSpec(FSLCommandInputSpec):
199199
argstr='%s', position=-1, mandatory=True)
200200
out_basename = File(desc='base name of output files',
201201
argstr='-o %s') # uses in_file name as basename if none given
202-
202+
number_classes = traits.Range(low=1, high=10, argstr='-n %d',
203203
desc='number of tissue-type classes')
204204
output_biasfield = traits.Bool(desc='output estimated bias field',
205205
argstr='-b')

nipype/interfaces/fsl/utils.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,3 +1236,129 @@ def _list_outputs(self):
12361236
else:
12371237
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
12381238
return outputs
1239+
1240+
1241+
class ComplexInputSpec(FSLCommandInputSpec):
1242+
complex_in_file = File(exists=True, argstr="%s", position=2)
1243+
complex_in_file2 = File(exists=True, argstr="%s", position=3)
1244+
1245+
real_in_file = File(exists=True, argstr="%s", position=2)
1246+
imaginary_in_file = File(exists=True, argstr="%s", position=3)
1247+
magnitude_in_file = File(exists=True, argstr="%s", position=2)
1248+
phase_in_file = File(exists=True, argstr='%s', position=3)
1249+
1250+
_ofs = ['complex_out_file',
1251+
'magnitude_out_file','phase_out_file',
1252+
'real_out_file','imaginary_out_file']
1253+
_conversion = ['real_polar','real_cartesian',
1254+
'complex_cartesian','complex_polar',
1255+
'complex_split','complex_merge',]
1256+
1257+
complex_out_file = File(genfile=True, argstr="%s", position=-3,
1258+
xor=_ofs+_conversion[:2])
1259+
magnitude_out_file = File(genfile=True, argstr="%s", position=-4,
1260+
xor=_ofs[:1]+_ofs[3:]+_conversion[1:])
1261+
phase_out_file = File(genfile=True, argstr="%s", position=-3,
1262+
xor=_ofs[:1]+_ofs[3:]+_conversion[1:])
1263+
real_out_file = File(genfile=True, argstr="%s", position=-4,
1264+
xor=_ofs[:3]+_conversion[:1]+_conversion[2:])
1265+
imaginary_out_file = File(genfile=True, argstr="%s", position=-3,
1266+
xor=_ofs[:3]+_conversion[:1]+_conversion[2:])
1267+
1268+
start_vol = traits.Int(position=-2, argstr='%d')
1269+
end_vol = traits.Int(position=-1, argstr='%d')
1270+
1271+
real_polar = traits.Bool(
1272+
argstr = '-realpolar', xor = _conversion, position=1,)
1273+
# requires=['complex_in_file','magnitude_out_file','phase_out_file'])
1274+
real_cartesian = traits.Bool(
1275+
argstr = '-realcartesian', xor = _conversion, position=1,)
1276+
# requires=['complex_in_file','real_out_file','imaginary_out_file'])
1277+
complex_cartesian = traits.Bool(
1278+
argstr = '-complex', xor = _conversion, position=1,)
1279+
# requires=['real_in_file','imaginary_in_file','complex_out_file'])
1280+
complex_polar = traits.Bool(
1281+
argstr = '-complexpolar', xor = _conversion, position=1,)
1282+
# requires=['magnitude_in_file','phase_in_file',
1283+
# 'magnitude_out_file','phase_out_file'])
1284+
complex_split = traits.Bool(
1285+
argstr = '-complexsplit', xor = _conversion, position=1,)
1286+
# requires=['complex_in_file','complex_out_file'])
1287+
complex_merge = traits.Bool(
1288+
argstr = '-complexmerge', xor = _conversion + ['start_vol','end_vol'],
1289+
position=1,)
1290+
# requires=['complex_in_file','complex_in_file2','complex_out_file'])
1291+
1292+
class ComplexOuputSpec(TraitedSpec):
1293+
magnitude_out_file = File()
1294+
phase_out_file = File()
1295+
real_out_file = File()
1296+
imaginary_out_file = File()
1297+
complex_out_file = File()
1298+
1299+
1300+
class Complex(FSLCommand):
1301+
"""fslcomplex is a tool for converting complex data
1302+
Examples
1303+
--------
1304+
>>> complex = Complex()
1305+
>>> complex.inputs.complex_in_file = "complex.nii"
1306+
>>> res = complex.run() # doctest: +SKIP
1307+
1308+
"""
1309+
_cmd = 'fslcomplex'
1310+
input_spec = ComplexInputSpec
1311+
output_spec = ComplexOuputSpec
1312+
1313+
def _parse_inputs(self, skip=None):
1314+
if skip == None:
1315+
skip = []
1316+
if self.inputs.real_cartesian:
1317+
skip += self.inputs._ofs[:3]
1318+
elif self.inputs.real_polar:
1319+
skip += self.inputs._ofs[:1]+self.inputs._ofs[3:]
1320+
else:
1321+
skip += self.inputs._ofs[1:]
1322+
return super(Complex,self)._parse_inputs(skip)
1323+
1324+
def _gen_filename(self, name):
1325+
if name == 'complex_out_file':
1326+
if self.inputs.complex_cartesian:
1327+
in_file = self.inputs.real_in_file
1328+
elif self.inputs.complex_polar:
1329+
in_file = self.inputs.magnitude_in_file
1330+
elif self.inputs.complex_split or self.inputs.complex_merge:
1331+
in_file = self.inputs.complex_in_file
1332+
else:
1333+
return None
1334+
return self._gen_fname(in_file, suffix="_cplx")
1335+
elif name =='magnitude_out_file':
1336+
return self._gen_fname(self.inputs.complex_in_file, suffix="_mag")
1337+
elif name =='phase_out_file':
1338+
return self._gen_fname(self.inputs.complex_in_file,suffix="_phase")
1339+
elif name =='real_out_file':
1340+
return self._gen_fname(self.inputs.complex_in_file, suffix="_real")
1341+
elif name =='imaginary_out_file':
1342+
return self._gen_fname(self.inputs.complex_in_file, suffix="_imag")
1343+
return None
1344+
1345+
def _get_output(self,name):
1346+
output = getattr(self.inputs,name)
1347+
if not isdefined(output):
1348+
output = self._gen_filename(name)
1349+
return os.path.abspath(output)
1350+
1351+
def _list_outputs(self):
1352+
outputs = self.output_spec().get()
1353+
if self.inputs.complex_cartesian or self.inputs.complex_polar or \
1354+
self.inputs.complex_split or self.inputs.complex_merge:
1355+
outputs['complex_out_file'] = self._get_output('complex_out_file')
1356+
elif self.inputs.real_cartesian:
1357+
outputs['real_out_file'] = self._get_output('real_out_file')
1358+
outputs['imaginary_out_file'] = self._get_output('imaginary_out_file')
1359+
elif self.inputs.real_polar:
1360+
outputs['magnitude_out_file'] = self._get_output('magnitude_out_file')
1361+
outputs['phase_out_file'] = self._get_output('phase_out_file')
1362+
return outputs
1363+
1364+

0 commit comments

Comments
 (0)