@@ -1578,3 +1578,122 @@ def _gen_filename(self, name):
1578
1578
return self ._list_outputs ()[name ]
1579
1579
1580
1580
return None
1581
+
1582
+
1583
+
1584
+
1585
+ class ConvertWarpInputSpec (FSLCommandInputSpec ):
1586
+ reference = File (exists = True , argstr = '--ref=%s' , mandatory = True ,
1587
+ desc = ('Name of a file in target space of the full transform.' ))
1588
+
1589
+ out_file = File (genfile = True , hash_files = False , argstr = '--out=%s' ,
1590
+ desc = ('Name of output file, containing warps that are the combination of all '
1591
+ 'those given as arguments. The format of this will be a field-file (rather '
1592
+ 'than spline coefficients) with any affine components included.' ))
1593
+
1594
+ premat = File (exists = True , argstr = '--premat=%s' ,
1595
+ desc = 'filename for pre-transform (affine matrix)' )
1596
+
1597
+ warp1 = File (exists = True , argstr = '--warp1=%s' ,
1598
+ desc = ('Name of file containing warp-fields/coefficients. This could e.g. be a '
1599
+ 'fnirt-transform from a subjects structural scan to an average of a group '
1600
+ 'of subjects.' ))
1601
+
1602
+ warp2 = File (exists = True , argstr = '--warp2=%s' ,
1603
+ desc = ('Name of file containing warp-fields/coefficients. This could e.g. be a '
1604
+ 'fnirt-transform from the average of a group of subjects to some standard '
1605
+ 'space (e.g. MNI152).' ))
1606
+
1607
+ postmat = File (exists = True , argstr = '--postmat=%s' ,
1608
+ desc = ('Name of file containing an affine transform. It could e.g. be an affine '
1609
+ 'transform that maps the MNI152-space into a better approximation to the '
1610
+ 'Talairach-space (if indeed there is one).' ))
1611
+
1612
+ shift_in_file = File (exists = True , argstr = '--shiftmap=%s' ,
1613
+ desc = ('Name of file containing a "shiftmap", a non-linear transform with '
1614
+ 'displacements only in one direction. This would typically be a '
1615
+ 'fieldmap that has been pre-processed using fugue that maps a '
1616
+ 'subjects functional (EPI) data onto an undistorted space (i.e. a space '
1617
+ 'that corresponds to his/her true anatomy).' ))
1618
+
1619
+ shift_direction = traits .Enum ('-y' ,'y' ,'x' ,'-x' ,'z' ,'-z' ,
1620
+ argstr = "--shiftdir=%s" , requires = ['shift_in_file' ],
1621
+ desc = ('Indicates the direction that the distortions from '
1622
+ '--shiftmap goes. It depends on the direction and '
1623
+ 'polarity of the phase-encoding in the EPI sequence.' ))
1624
+
1625
+ cons_jacobian = traits .Bool (False , argstr = '--constrainj' ,
1626
+ desc = ('Constrain the Jacobian of the warpfield to lie within specified '
1627
+ 'min/max limits.' ))
1628
+
1629
+ jacobian_min = traits .Float (argstr = '--jmin=%f' ,
1630
+ desc = ('Minimum acceptable Jacobian value for '
1631
+ 'constraint (default 0.01)' ))
1632
+ jacobian_max = traits .Float (argstr = '--jmax=%f' ,
1633
+ desc = ('Maximum acceptable Jacobian value for '
1634
+ 'constraint (default 100.0)' ))
1635
+
1636
+ abswarp = traits .Bool (argstr = '--abs' , xor = ['relwarp' ],
1637
+ desc = ('If set it indicates that the warps in --warp1 and --warp2 should be '
1638
+ 'interpreted as absolute. I.e. the values in --warp1/2 are the '
1639
+ 'coordinates in the next space, rather than displacements. This flag '
1640
+ 'is ignored if --warp1/2 was created by fnirt, which always creates '
1641
+ 'relative displacements.' ))
1642
+
1643
+ relwarp = traits .Bool (argstr = '--rel' , xor = ['abswarp' ],
1644
+ desc = ('If set it indicates that the warps in --warp1/2 should be interpreted '
1645
+ 'as relative. I.e. the values in --warp1/2 are displacements from the '
1646
+ 'coordinates in the next space.' ))
1647
+
1648
+ out_abswarp = traits .Bool (argstr = '--absout' , xor = ['out_relwarp' ],
1649
+ desc = ('If set it indicates that the warps in --out should be relative, i.e. '
1650
+ 'the vaulues in --out are displacements from the coordinates in --ref.' ))
1651
+
1652
+ out_relwarp = traits .Bool (argstr = '--relout' , xor = ['out_abswarp' ],
1653
+ desc = ('If set it indicates that the warps in --out should be relative, i.e. '
1654
+ 'the vaulues in --out are displacements from the coordinates in --ref.' ))
1655
+
1656
+
1657
+ class ConvertWarpOutputSpec (TraitedSpec ):
1658
+ out_file = File (exists = True ,
1659
+ desc = ('Name of output file, containing the warp as field or coefficients.' ))
1660
+
1661
+
1662
+ class ConvertWarp (FSLCommand ):
1663
+ """Use FSL `convertwarp <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/fnirt/warp_utils.html>`_
1664
+ for combining multiple transforms into one.
1665
+
1666
+
1667
+ Examples::
1668
+
1669
+ >>> from nipype.interfaces.fsl import ConvertWarp
1670
+ >>> warputils = ConvertWarp()
1671
+ >>> warputils.inputs.warp1 = "warpfield.nii"
1672
+ >>> warputils.inputs.reference = "T1.nii"
1673
+ >>> warputils.inputs.relwarp = True
1674
+ >>> warputils.cmdline # doctest: +ELLIPSIS
1675
+ 'convertwarp --out=.../T1_concatwarps.nii.gz --ref=T1.nii --rel --warp1=warpfield.nii'
1676
+ >>> res = invwarp.run() # doctest: +SKIP
1677
+ """
1678
+
1679
+ input_spec = ConvertWarpInputSpec
1680
+ output_spec = ConvertWarpOutputSpec
1681
+
1682
+ _cmd = 'convertwarp'
1683
+
1684
+ def _list_outputs (self ):
1685
+ outputs = self .output_spec ().get ()
1686
+ outputs ['out_file' ] = self .inputs .out_file
1687
+
1688
+ if not isdefined (outputs ['out_file' ]):
1689
+ outputs ['out_file' ] = self ._gen_fname (self .inputs .reference ,
1690
+ suffix = '_concatwarps' )
1691
+
1692
+ outputs ['out_file' ] = os .path .abspath (outputs ['out_file' ])
1693
+ return outputs
1694
+
1695
+ def _gen_filename (self , name ):
1696
+ if name == 'out_file' :
1697
+ return self ._list_outputs ()[name ]
1698
+
1699
+ return None
0 commit comments