|
39 | 39 |
|
40 | 40 |
|
41 | 41 | class FieldMapInputSpec(SPMCommandInputSpec):
|
| 42 | + |
42 | 43 | jobtype = traits.Enum(
|
43 | 44 | "calculatevdm",
|
44 |
| - "applyvdm", |
45 | 45 | usedefault=True,
|
46 |
| - desc="one of: calculatevdm, applyvdm", |
| 46 | + deprecated="1.9.0", # Two minor releases in the future |
| 47 | + desc="Must be 'calculatevdm'; to apply VDM, use the ApplyVDM interface.", |
47 | 48 | )
|
| 49 | + |
48 | 50 | phase_file = File(
|
49 | 51 | mandatory=True,
|
50 | 52 | exists=True,
|
@@ -231,22 +233,148 @@ class FieldMap(SPMCommand):
|
231 | 233 |
|
232 | 234 | def _format_arg(self, opt, spec, val):
|
233 | 235 | """Convert input to appropriate format for spm"""
|
| 236 | + |
234 | 237 | if opt in ["phase_file", "magnitude_file", "anat_file", "epi_file"]:
|
| 238 | + |
235 | 239 | return scans_for_fname(ensure_list(val))
|
236 | 240 |
|
237 | 241 | return super(FieldMap, self)._format_arg(opt, spec, val)
|
238 | 242 |
|
239 | 243 | def _parse_inputs(self):
|
240 | 244 | """validate spm fieldmap options if set to None ignore"""
|
| 245 | + |
241 | 246 | einputs = super(FieldMap, self)._parse_inputs()
|
242 |
| - return [{self.inputs.jobtype: einputs[0]}] |
| 247 | + return [{"calculatevdm": einputs[0]}] |
243 | 248 |
|
244 | 249 | def _list_outputs(self):
|
245 | 250 | outputs = self._outputs().get()
|
246 | 251 | jobtype = self.inputs.jobtype
|
247 |
| - if jobtype == "calculatevdm": |
248 |
| - outputs["vdm"] = fname_presuffix(self.inputs.phase_file, prefix="vdm5_sc") |
249 | 252 |
|
| 253 | + outputs["vdm"] = fname_presuffix(self.inputs.phase_file, prefix="vdm5_sc") |
| 254 | + |
| 255 | + return outputs |
| 256 | + |
| 257 | + |
| 258 | +class ApplyVDMInputSpec(SPMCommandInputSpec): |
| 259 | + |
| 260 | + in_files = InputMultiObject( |
| 261 | + ImageFileSPM(exists=True), |
| 262 | + field="data.scans", |
| 263 | + mandatory=True, |
| 264 | + copyfile=True, |
| 265 | + desc="list of filenames to apply the vdm to", |
| 266 | + ) |
| 267 | + vdmfile = File( |
| 268 | + field="data.vdmfile", |
| 269 | + desc="Voxel displacement map to use", |
| 270 | + mandatory=True, |
| 271 | + copyfile=True, |
| 272 | + ) |
| 273 | + distortion_direction = traits.Int( |
| 274 | + 2, |
| 275 | + field="roptions.pedir", |
| 276 | + desc="phase encode direction input data have been acquired with", |
| 277 | + usedefault=True, |
| 278 | + ) |
| 279 | + write_which = traits.ListInt( |
| 280 | + [2, 1], |
| 281 | + field="roptions.which", |
| 282 | + minlen=2, |
| 283 | + maxlen=2, |
| 284 | + usedefault=True, |
| 285 | + desc="If the first value is non-zero, reslice all images. If the second value is non-zero, reslice a mean image.", |
| 286 | + ) |
| 287 | + interpolation = traits.Range( |
| 288 | + value=4, |
| 289 | + low=0, |
| 290 | + high=7, |
| 291 | + field="roptions.rinterp", |
| 292 | + desc="degree of b-spline used for interpolation", |
| 293 | + ) |
| 294 | + write_wrap = traits.List( |
| 295 | + traits.Int(), |
| 296 | + minlen=3, |
| 297 | + maxlen=3, |
| 298 | + field="roptions.wrap", |
| 299 | + desc=("Check if interpolation should wrap in [x,y,z]"), |
| 300 | + ) |
| 301 | + write_mask = traits.Bool( |
| 302 | + field="roptions.mask", desc="True/False mask time series images" |
| 303 | + ) |
| 304 | + out_prefix = traits.String( |
| 305 | + "u", |
| 306 | + field="roptions.prefix", |
| 307 | + usedefault=True, |
| 308 | + desc="fieldmap corrected output prefix", |
| 309 | + ) |
| 310 | + |
| 311 | + |
| 312 | +class ApplyVDMOutputSpec(TraitedSpec): |
| 313 | + out_files = OutputMultiPath( |
| 314 | + traits.Either(traits.List(File(exists=True)), File(exists=True)), |
| 315 | + desc=("These will be the fieldmap corrected files."), |
| 316 | + ) |
| 317 | + mean_image = File(exists=True, desc="Mean image") |
| 318 | + |
| 319 | + |
| 320 | +class ApplyVDM(SPMCommand): |
| 321 | + """Use the fieldmap toolbox from spm to apply the voxel displacement map (VDM) to some epi files. |
| 322 | +
|
| 323 | + http://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf#page=173 |
| 324 | +
|
| 325 | + .. important:: |
| 326 | +
|
| 327 | + This interface does not deal with real/imag magnitude images nor |
| 328 | + with the two phase files case. |
| 329 | +
|
| 330 | + """ |
| 331 | + |
| 332 | + input_spec = ApplyVDMInputSpec |
| 333 | + output_spec = ApplyVDMOutputSpec |
| 334 | + _jobtype = "tools" |
| 335 | + _jobname = "fieldmap" |
| 336 | + |
| 337 | + def _format_arg(self, opt, spec, val): |
| 338 | + """Convert input to appropriate format for spm""" |
| 339 | + |
| 340 | + if opt in ["in_files", "vdmfile"]: |
| 341 | + return scans_for_fname(ensure_list(val)) |
| 342 | + return super(FieldMap, self)._format_arg(opt, spec, val) |
| 343 | + |
| 344 | + def _parse_inputs(self): |
| 345 | + """validate spm fieldmap options if set to None ignore""" |
| 346 | + |
| 347 | + einputs = super(ApplyVDM, self)._parse_inputs() |
| 348 | + |
| 349 | + return [{"applymap": einputs[0]}] |
| 350 | + |
| 351 | + def _list_outputs(self): |
| 352 | + outputs = self._outputs().get() |
| 353 | + jobtype = self.inputs.jobtype |
| 354 | + resliced_all = self.inputs.write_which[0] > 0 |
| 355 | + resliced_mean = self.inputs.write_which[1] > 0 |
| 356 | + if resliced_mean: |
| 357 | + if isinstance(self.inputs.in_files[0], list): |
| 358 | + first_image = self.inputs.in_files[0][0] |
| 359 | + else: |
| 360 | + first_image = self.inputs.in_files[0] |
| 361 | + outputs["mean_image"] = fname_presuffix(first_image, prefix="meanu") |
| 362 | + |
| 363 | + if resliced_all: |
| 364 | + outputs["out_files"] = [] |
| 365 | + for idx, imgf in enumerate(ensure_list(self.inputs.in_files)): |
| 366 | + appliedvdm_run = [] |
| 367 | + if isinstance(imgf, list): |
| 368 | + for i, inner_imgf in enumerate(ensure_list(imgf)): |
| 369 | + newfile = fname_presuffix( |
| 370 | + inner_imgf, prefix=self.inputs.out_prefix |
| 371 | + ) |
| 372 | + appliedvdm_run.append(newfile) |
| 373 | + else: |
| 374 | + appliedvdm_run = fname_presuffix( |
| 375 | + imgf, prefix=self.inputs.out_prefix |
| 376 | + ) |
| 377 | + outputs["out_files"].append(appliedvdm_run) |
250 | 378 | return outputs
|
251 | 379 |
|
252 | 380 |
|
|
0 commit comments