@@ -1152,6 +1152,54 @@ def _list_outputs(self):
1152
1152
basename = 'maskexf' )
1153
1153
return outputs
1154
1154
1155
+ class SigLossInputSpec (FSLCommandInputSpec ):
1156
+ in_file = File (mandatory = True ,
1157
+ exists = True ,
1158
+ argstr = '-i %s' ,
1159
+ desc = 'b0 fieldmap file' )
1160
+ out_file = File (argstr = '-s %s' ,
1161
+ desc = 'output signal loss estimate file' ,
1162
+ genfile = True )
1163
+
1164
+ mask_file = File (exists = True ,
1165
+ argstr = '-m %s' ,
1166
+ desc = 'brain mask file' )
1167
+ echo_time = traits .Float (argstr = '--te=%f' ,
1168
+ desc = 'echo time in seconds' )
1169
+ slice_direction = traits .Enum ('x' ,'y' ,'z' ,
1170
+ argstr = '-d %s' ,
1171
+ desc = 'slicing direction' )
1172
+ class SigLossOuputSpec (TraitedSpec ):
1173
+ out_file = File (exists = True ,
1174
+ desc = 'signal loss estimate file' )
1175
+
1176
+ class SigLoss (FSLCommand ):
1177
+ """Estimates signal loss from a field map (in rad/s)
1178
+
1179
+ Examples
1180
+ --------
1181
+ >>> sigloss = SigLoss()
1182
+ >>> sigloss.inputs.in_file = "phase.nii"
1183
+ >>> sigloss.inputs.echo_time = 0.03
1184
+ >>> res = sigloss.run() # doctest: +SKIP
1185
+ """
1186
+ input_spec = SigLossInputSpec
1187
+ output_spec = SigLossOuputSpec
1188
+ _cmd = 'sigloss'
1189
+
1190
+ def _list_outputs (self ):
1191
+ outputs = self .output_spec ().get ()
1192
+ outputs ['out_file' ] = self .inputs .out_file
1193
+ if not isdefined (outputs ['out_file' ]) and isdefined (self .inputs .in_file ):
1194
+ outputs ['out_file' ]= self ._gen_fname (self .inputs .in_file ,
1195
+ suffix = '_sigloss' )
1196
+ return outputs
1197
+
1198
+ def _gen_filename (self , name ):
1199
+ if name == 'out_file' :
1200
+ return self ._list_outputs ()['out_file' ]
1201
+ return None
1202
+
1155
1203
class Reorient2StdInputSpec (FSLCommandInputSpec ):
1156
1204
in_file = File (exists = True , mandatory = True , argstr = "%s" )
1157
1205
out_file = File (genfile = True , hash_files = False , argstr = "%s" )
@@ -1188,3 +1236,130 @@ def _list_outputs(self):
1188
1236
else :
1189
1237
outputs ['out_file' ] = os .path .abspath (self .inputs .out_file )
1190
1238
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
+ >>> cplx = Complex()
1305
+ >>> cplx.inputs.complex_in_file = "complex.nii"
1306
+ >>> cplx.real_polar = True
1307
+ >>> res = cplx.run() # doctest: +SKIP
1308
+
1309
+ """
1310
+ _cmd = 'fslcomplex'
1311
+ input_spec = ComplexInputSpec
1312
+ output_spec = ComplexOuputSpec
1313
+
1314
+ def _parse_inputs (self , skip = None ):
1315
+ if skip == None :
1316
+ skip = []
1317
+ if self .inputs .real_cartesian :
1318
+ skip += self .inputs ._ofs [:3 ]
1319
+ elif self .inputs .real_polar :
1320
+ skip += self .inputs ._ofs [:1 ]+ self .inputs ._ofs [3 :]
1321
+ else :
1322
+ skip += self .inputs ._ofs [1 :]
1323
+ return super (Complex ,self )._parse_inputs (skip )
1324
+
1325
+ def _gen_filename (self , name ):
1326
+ if name == 'complex_out_file' :
1327
+ if self .inputs .complex_cartesian :
1328
+ in_file = self .inputs .real_in_file
1329
+ elif self .inputs .complex_polar :
1330
+ in_file = self .inputs .magnitude_in_file
1331
+ elif self .inputs .complex_split or self .inputs .complex_merge :
1332
+ in_file = self .inputs .complex_in_file
1333
+ else :
1334
+ return None
1335
+ return self ._gen_fname (in_file , suffix = "_cplx" )
1336
+ elif name == 'magnitude_out_file' :
1337
+ return self ._gen_fname (self .inputs .complex_in_file , suffix = "_mag" )
1338
+ elif name == 'phase_out_file' :
1339
+ return self ._gen_fname (self .inputs .complex_in_file ,suffix = "_phase" )
1340
+ elif name == 'real_out_file' :
1341
+ return self ._gen_fname (self .inputs .complex_in_file , suffix = "_real" )
1342
+ elif name == 'imaginary_out_file' :
1343
+ return self ._gen_fname (self .inputs .complex_in_file , suffix = "_imag" )
1344
+ return None
1345
+
1346
+ def _get_output (self ,name ):
1347
+ output = getattr (self .inputs ,name )
1348
+ if not isdefined (output ):
1349
+ output = self ._gen_filename (name )
1350
+ return os .path .abspath (output )
1351
+
1352
+ def _list_outputs (self ):
1353
+ outputs = self .output_spec ().get ()
1354
+ if self .inputs .complex_cartesian or self .inputs .complex_polar or \
1355
+ self .inputs .complex_split or self .inputs .complex_merge :
1356
+ outputs ['complex_out_file' ] = self ._get_output ('complex_out_file' )
1357
+ elif self .inputs .real_cartesian :
1358
+ outputs ['real_out_file' ] = self ._get_output ('real_out_file' )
1359
+ outputs ['imaginary_out_file' ] = self ._get_output ('imaginary_out_file' )
1360
+ elif self .inputs .real_polar :
1361
+ outputs ['magnitude_out_file' ] = self ._get_output ('magnitude_out_file' )
1362
+ outputs ['phase_out_file' ] = self ._get_output ('phase_out_file' )
1363
+ return outputs
1364
+
1365
+
0 commit comments