@@ -1451,3 +1451,130 @@ def _list_outputs(self):
1451
1451
outputs ['magnitude_out_file' ] = self ._get_output ('magnitude_out_file' )
1452
1452
outputs ['phase_out_file' ] = self ._get_output ('phase_out_file' )
1453
1453
return outputs
1454
+
1455
+
1456
+
1457
+ class WarpUtilsInputSpec (FSLCommandInputSpec ):
1458
+ in_file = File (exists = True , argstr = '--in=%s' , mandatory = True ,
1459
+ desc = ('Name of file containing warp-coefficients/fields. This '
1460
+ 'would typically be the output from the --cout switch of '
1461
+ 'fnirt (but can also use fields, like the output from '
1462
+ '--fout).' ))
1463
+ reference = File (exists = True , argstr = '--ref=%s' , mandatory = True ,
1464
+ desc = ('Name of a file in target space. Note that the '
1465
+ 'target space is now different from the target '
1466
+ 'space that was used to create the --warp file. It '
1467
+ 'would typically be the file that was specified '
1468
+ 'with the --in argument when running fnirt.' ))
1469
+
1470
+ out_format = traits .Either ('field' , 'spline' , argstr = '--outformat=%s' ,
1471
+ desc = ('Specifies the output format. If set to field (default) '
1472
+ 'the output will be a (4D) field-file. If set to spline '
1473
+ 'the format will be a (4D) file of spline coefficients.' ))
1474
+
1475
+ warp_resolution = traits .Tuple (traits .Float , traits .Float , traits .Float ,
1476
+ argstr = '--warpres=%0.4f,%0.4f,%0.4f' ,
1477
+ desc = ('Specifes the resolution/knot-spacing of the splines pertaining to '
1478
+ 'the coefficients in the --out file. This parameter is only relevant '
1479
+ 'if --outformat is set to spline. It should be noted that if the '
1480
+ '--in file has a higher resolution, the resulting coefficents will '
1481
+ 'pertain to the closest (in a least-squares sense) file in the space '
1482
+ 'of fields with the --warpres resolution. It should also be noted '
1483
+ 'that the resolution will always be an integer multiple of the voxel '
1484
+ 'size.' ))
1485
+
1486
+ knot_space = traits .Tuple (traits .Int , traits .Int , traits .Int ,
1487
+ argstr = '--knotspace=%d,%d,%d' ,
1488
+ desc = ('Alternative (to --warpres) specifikation of the resolution of '
1489
+ 'the output spline-field.' ))
1490
+
1491
+ out_file = File (genfile = True , hash_files = False , argstr = '--out=%s' ,
1492
+ desc = ('Name of output file. The format of the output depends on what other '
1493
+ 'parameters are set. The default format is a (4D) field-file. If the '
1494
+ '--outformat is set to spline the format will be a (4D) file of spline '
1495
+ 'coefficients.' ))
1496
+
1497
+ write_jacobian = traits .Bool (False , mandatory = True , usedefault = True ,
1498
+ desc = 'Switch on --jac flag with automatically generated filename' )
1499
+
1500
+ out_jacobian = File (argstr = '--jac=%s' ,
1501
+ desc = ('Specifies that a (3D) file of Jacobian determinants corresponding '
1502
+ 'to --in should be produced and written to filename.' ))
1503
+
1504
+ with_affine = traits .Bool (False , argstr = '--withaff' ,
1505
+ desc = ('Specifies that the affine transform (i.e. that which was '
1506
+ 'specified for the --aff parameter in fnirt) should be '
1507
+ 'included as displacements in the --out file. That can be '
1508
+ 'useful for interfacing with software that cannot decode '
1509
+ 'FSL/fnirt coefficient-files (where the affine transform is '
1510
+ 'stored separately from the displacements).' ))
1511
+
1512
+ class WarpUtilsOutputSpec (TraitedSpec ):
1513
+ out_file = File (exists = True ,
1514
+ desc = ('Name of output file, containing the warp as field or coefficients.' ))
1515
+ out_jacobian = File (exists = True ,
1516
+ desc = ('Name of output file, containing the map of the determinant of '
1517
+ 'the Jacobian' ))
1518
+
1519
+
1520
+ class WarpUtils (FSLCommand ):
1521
+ """Use FSL `fnirtfileutils <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/fnirt/warp_utils.html>`_
1522
+ to convert field->coefficients, coefficients->field, coefficients->other_coefficients etc
1523
+
1524
+
1525
+ Examples::
1526
+
1527
+ >>> from nipype.interfaces.fsl import WarpUtils
1528
+ >>> warputils = WarpUtils()
1529
+ >>> warputils.inputs.in_file = "warpfield.nii"
1530
+ >>> warputils.inputs.reference = "T1.nii"
1531
+ >>> warputils.inputs.out_format = 'spline'
1532
+ >>> warputils.inputs.warp_resolution = (10,10,10)
1533
+ >>> warputils.cmdline # doctest: +ELLIPSIS
1534
+ 'fnirtfileutils --in=warpfield.nii --out=.../warpfield_coeffs.nii.gz --outformat=spline --ref=T1.nii --warpres=10.0000,10.0000,10.0000'
1535
+ >>> res = invwarp.run() # doctest: +SKIP
1536
+ """
1537
+
1538
+ input_spec = WarpUtilsInputSpec
1539
+ output_spec = WarpUtilsOutputSpec
1540
+
1541
+ _cmd = 'fnirtfileutils'
1542
+
1543
+ def _parse_inputs (self , skip = None ):
1544
+ if skip is None :
1545
+ skip = []
1546
+
1547
+ if self .inputs .write_jacobian :
1548
+ if not isdefined (self .inputs .out_jacobian ):
1549
+ self .inputs .out_jacobian = self ._gen_fname (self .inputs .in_file ,
1550
+ suffix = '_jac' )
1551
+ skip += ['write_jacobian' ]
1552
+ return super (WarpUtils , self )._parse_inputs (skip = skip )
1553
+
1554
+
1555
+
1556
+ def _list_outputs (self ):
1557
+ outputs = self .output_spec ().get ()
1558
+ outputs ['out_file' ] = self .inputs .out_file
1559
+
1560
+ suffix = 'field'
1561
+
1562
+ if isdefined (self .inputs .out_format ) and self .inputs .out_format == 'spline' :
1563
+ suffix = 'coeffs'
1564
+
1565
+
1566
+ if not isdefined (outputs ['out_file' ]):
1567
+ outputs ['out_file' ] = self ._gen_fname (self .inputs .in_file ,
1568
+ suffix = '_' + suffix )
1569
+
1570
+ if isdefined (self .inputs .out_jacobian ):
1571
+ outputs ['out_jacobian' ] = os .path .abspath (self .inputs .out_jacobian )
1572
+
1573
+ outputs ['out_file' ] = os .path .abspath (outputs ['out_file' ])
1574
+ return outputs
1575
+
1576
+ def _gen_filename (self , name ):
1577
+ if name == 'out_file' :
1578
+ return self ._list_outputs ()[name ]
1579
+
1580
+ return None
0 commit comments