@@ -46,14 +46,14 @@ class FieldMapInputSpec(SPMCommandInputSpec):
46
46
desc = "one of: calculatevdm, applyvdm" ,
47
47
)
48
48
phase_file = File (
49
- #mandatory=True,
49
+ # mandatory=True,
50
50
exists = True ,
51
51
copyfile = False ,
52
52
field = "subj.data.presubphasemag.phase" ,
53
53
desc = "presubstracted phase file" ,
54
54
)
55
55
magnitude_file = File (
56
- #mandatory=True,
56
+ # mandatory=True,
57
57
exists = True ,
58
58
copyfile = False ,
59
59
field = "subj.data.presubphasemag.magnitude" ,
@@ -62,7 +62,7 @@ class FieldMapInputSpec(SPMCommandInputSpec):
62
62
echo_times = traits .Tuple (
63
63
traits .Float ,
64
64
traits .Float ,
65
- #mandatory=True,
65
+ # mandatory=True,
66
66
field = "subj.defaults.defaultsval.et" ,
67
67
desc = "short and long echo times" ,
68
68
)
@@ -169,7 +169,7 @@ class FieldMapInputSpec(SPMCommandInputSpec):
169
169
epi_file = File (
170
170
copyfile = False ,
171
171
exists = True ,
172
- #mandatory=True,
172
+ # mandatory=True,
173
173
field = "subj.session.epi" ,
174
174
desc = "EPI to unwarp" ,
175
175
)
@@ -196,59 +196,78 @@ class FieldMapInputSpec(SPMCommandInputSpec):
196
196
)
197
197
198
198
in_files = InputMultiObject (
199
- traits .Either (ImageFileSPM (exists = True ),
200
- traits .List (ImageFileSPM (exists = True ))),
201
- field = 'data.scans' ,mandatory = True ,
199
+ traits .Either (
200
+ ImageFileSPM (exists = True ), traits .List (ImageFileSPM (exists = True ))
201
+ ),
202
+ field = "data.scans" ,
203
+ mandatory = True ,
202
204
copyfile = True ,
203
- desc = 'list of filenames to apply the vdm to' )
205
+ desc = "list of filenames to apply the vdm to" ,
206
+ )
204
207
vdmfile = File (
205
- field = 'data.vdmfile' ,
206
- desc = 'Voxel displacement map to use' ,mandatory = True ,
207
- copyfile = True )
208
+ field = "data.vdmfile" ,
209
+ desc = "Voxel displacement map to use" ,
210
+ mandatory = True ,
211
+ copyfile = True ,
212
+ )
208
213
distortion_direction = traits .Int (
209
- 2 , field = 'roptions.pedir' , desc = 'phase encode direction input data have been acquired with' ,
210
- usedefault = True )
214
+ 2 ,
215
+ field = "roptions.pedir" ,
216
+ desc = "phase encode direction input data have been acquired with" ,
217
+ usedefault = True ,
218
+ )
211
219
write_which = traits .ListInt (
212
220
[2 , 1 ],
213
- field = ' roptions.which' ,
221
+ field = " roptions.which" ,
214
222
minlen = 2 ,
215
223
maxlen = 2 ,
216
224
usedefault = True ,
217
- desc = 'determines which images to apply vdm to' )
225
+ desc = "determines which images to apply vdm to" ,
226
+ )
218
227
interpolation = traits .Int (
219
- 4 , field = 'roptions.rinterp' , desc = 'phase encode direction input data have been acquired with' ,
220
- usedefault = True )
228
+ 4 ,
229
+ field = "roptions.rinterp" ,
230
+ desc = "phase encode direction input data have been acquired with" ,
231
+ usedefault = True ,
232
+ )
221
233
reslice_interp = traits .Range (
222
234
low = 0 ,
223
235
high = 7 ,
224
- field = 'roptions.rinterp' ,
225
- desc = 'degree of b-spline used for interpolation' )
236
+ field = "roptions.rinterp" ,
237
+ desc = "degree of b-spline used for interpolation" ,
238
+ )
226
239
write_wrap = traits .List (
227
240
traits .Int (),
228
241
minlen = 3 ,
229
242
maxlen = 3 ,
230
- field = 'roptions.wrap' ,
231
- desc = ('Check if interpolation should wrap in [x,y,z]' ))
243
+ field = "roptions.wrap" ,
244
+ desc = ("Check if interpolation should wrap in [x,y,z]" ),
245
+ )
232
246
write_mask = traits .Bool (
233
- field = 'roptions.mask' , desc = 'True/False mask time series images' )
247
+ field = "roptions.mask" , desc = "True/False mask time series images"
248
+ )
234
249
out_prefix = traits .String (
235
- 'u' ,
236
- field = ' roptions.prefix' ,
250
+ "u" ,
251
+ field = " roptions.prefix" ,
237
252
usedefault = True ,
238
- desc = 'fieldmap corrected output prefix' )
253
+ desc = "fieldmap corrected output prefix" ,
254
+ )
239
255
240
256
241
257
class FieldMapOutputSpec (TraitedSpec ):
242
258
vdm = File (exists = True , desc = "voxel difference map" )
243
259
244
260
out_files = OutputMultiPath (
245
261
traits .Either (traits .List (File (exists = True )), File (exists = True )),
246
- desc = ('If jobtype is applyvdm, '
247
- 'these will be the fieldmap corrected files.'
248
- ' Otherwise, they will be copies '
249
- 'of in_files that have had their '
250
- 'headers rewritten.' ))
251
- mean_image = File (exists = True , desc = 'Mean image' )
262
+ desc = (
263
+ "If jobtype is applyvdm, "
264
+ "these will be the fieldmap corrected files."
265
+ " Otherwise, they will be copies "
266
+ "of in_files that have had their "
267
+ "headers rewritten."
268
+ ),
269
+ )
270
+ mean_image = File (exists = True , desc = "Mean image" )
252
271
253
272
254
273
class FieldMap (SPMCommand ):
@@ -283,75 +302,94 @@ class FieldMap(SPMCommand):
283
302
def _format_arg (self , opt , spec , val ):
284
303
"""Convert input to appropriate format for spm"""
285
304
286
- if ((self .inputs .jobtype == "calculatevdm" ) and (opt in ['phase_file' , 'magnitude_file' , 'anat_file' , 'epi_file' ])):
305
+ if (self .inputs .jobtype == "calculatevdm" ) and (
306
+ opt in ["phase_file" , "magnitude_file" , "anat_file" , "epi_file" ]
307
+ ):
287
308
return scans_for_fname (ensure_list (val ))
288
309
289
- if (( self .inputs .jobtype == "applyvdm" ) and (opt == ' in_files' ) ):
310
+ if (self .inputs .jobtype == "applyvdm" ) and (opt == " in_files" ):
290
311
return scans_for_fnames (ensure_list (val ))
291
- if (( self .inputs .jobtype == "applyvdm" ) and (opt == ' vdmfile' ) ):
312
+ if (self .inputs .jobtype == "applyvdm" ) and (opt == " vdmfile" ):
292
313
return scans_for_fname (ensure_list (val ))
293
314
return super (FieldMap , self )._format_arg (opt , spec , val )
294
315
295
-
296
316
def _parse_inputs (self ):
297
317
"""validate spm fieldmap options if set to None ignore"""
298
318
299
319
if self .inputs .jobtype == "applyvdm" :
300
- einputs = (super (FieldMap , self )
301
- ._parse_inputs (skip = ('jobtype' ,'phase_file' , 'magnitude_file' ,
302
- 'echo_times' , 'blip_direction' ,
303
- 'total_readout_time' ,'maskbrain' ,
304
- 'epifm' ,'jacobian_modulation' ,
305
- 'method' ,'unwarp_fwhm' ,'pad' ,'ws' ,
306
- 'template' ,'mask_fwhm' ,'nerode' ,'ndilate' ,
307
- 'thresh' ,'reg' ,'epi_file' ,'matchvdm' ,
308
- 'sessname' ,'writeunwarped' ,
309
- 'anat_file' ,'matchanat' )))
320
+ einputs = super (FieldMap , self )._parse_inputs (
321
+ skip = (
322
+ "jobtype" ,
323
+ "phase_file" ,
324
+ "magnitude_file" ,
325
+ "echo_times" ,
326
+ "blip_direction" ,
327
+ "total_readout_time" ,
328
+ "maskbrain" ,
329
+ "epifm" ,
330
+ "jacobian_modulation" ,
331
+ "method" ,
332
+ "unwarp_fwhm" ,
333
+ "pad" ,
334
+ "ws" ,
335
+ "template" ,
336
+ "mask_fwhm" ,
337
+ "nerode" ,
338
+ "ndilate" ,
339
+ "thresh" ,
340
+ "reg" ,
341
+ "epi_file" ,
342
+ "matchvdm" ,
343
+ "sessname" ,
344
+ "writeunwarped" ,
345
+ "anat_file" ,
346
+ "matchanat" ,
347
+ )
348
+ )
310
349
311
350
else :
312
- einputs = (super (FieldMap , self )
313
- ._parse_inputs (skip = ('jobtype' ,'in_files' , 'vdmfile' )))
351
+ einputs = super (FieldMap , self )._parse_inputs (
352
+ skip = ("jobtype" , "in_files" , "vdmfile" )
353
+ )
314
354
jobtype = self .inputs .jobtype
315
355
316
- return [{'%s' % (jobtype ): einputs [0 ]}]
317
-
356
+ return [{"%s" % (jobtype ): einputs [0 ]}]
318
357
319
358
def _list_outputs (self ):
320
359
outputs = self ._outputs ().get ()
321
360
jobtype = self .inputs .jobtype
322
- resliced_all = self .inputs .write_which [0 ] > 0
361
+ resliced_all = self .inputs .write_which [0 ] > 0
323
362
resliced_mean = self .inputs .write_which [1 ] > 0
324
363
if jobtype == "calculatevdm" :
325
- outputs [' vdm' ] = fname_presuffix (self .inputs .phase_file , prefix = ' vdm5_sc' )
364
+ outputs [" vdm" ] = fname_presuffix (self .inputs .phase_file , prefix = " vdm5_sc" )
326
365
elif jobtype == "applyvdm" :
327
366
if resliced_mean :
328
367
if isinstance (self .inputs .in_files [0 ], list ):
329
368
first_image = self .inputs .in_files [0 ][0 ]
330
369
else :
331
370
first_image = self .inputs .in_files [0 ]
332
- outputs ['mean_image' ] = fname_presuffix (
333
- first_image , prefix = 'meanu' )
371
+ outputs ["mean_image" ] = fname_presuffix (first_image , prefix = "meanu" )
334
372
335
373
if resliced_all :
336
- outputs [' out_files' ] = []
374
+ outputs [" out_files" ] = []
337
375
for idx , imgf in enumerate (ensure_list (self .inputs .in_files )):
338
376
appliedvdm_run = []
339
377
if isinstance (imgf , list ):
340
378
for i , inner_imgf in enumerate (ensure_list (imgf )):
341
- newfile = fname_presuffix (inner_imgf ,
342
- prefix = self .inputs .out_prefix )
379
+ newfile = fname_presuffix (
380
+ inner_imgf , prefix = self .inputs .out_prefix
381
+ )
343
382
appliedvdm_run .append (newfile )
344
383
else :
345
- appliedvdm_run = fname_presuffix (imgf ,
346
- prefix = self .inputs .out_prefix )
347
- outputs ['out_files' ].append (appliedvdm_run )
384
+ appliedvdm_run = fname_presuffix (
385
+ imgf , prefix = self .inputs .out_prefix
386
+ )
387
+ outputs ["out_files" ].append (appliedvdm_run )
348
388
return outputs
349
389
350
-
351
390
return outputs
352
391
353
392
354
-
355
393
class SliceTimingInputSpec (SPMCommandInputSpec ):
356
394
in_files = InputMultiPath (
357
395
traits .Either (
0 commit comments