Skip to content

Commit 91a0194

Browse files
committed
Merge branch 'enh/FSLstd2imgcoords' into fix/1407
Integrate the code from that branch that was stale waiting for `terminal_output` to be revised. Close #1398.
2 parents 037e932 + 51a7e72 commit 91a0194

File tree

4 files changed

+115
-2
lines changed

4 files changed

+115
-2
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Upcoming release
22
================
33

4+
* ENH: Improve terminal_output feature (https://github.com/nipy/nipype/pull/2209)
5+
* ENH: Simple interface to FSL std2imgcoords (https://github.com/nipy/nipype/pull/2209, prev #1398)
6+
47

58
0.13.1 (May 20, 2017)
69
=====================
@@ -21,6 +24,7 @@ Upcoming release
2124
0.13.0 (May 11, 2017)
2225
=====================
2326

27+
<<<<<<< HEAD
2428
* ENH: Multi-stage recon-all directives (https://github.com/nipy/nipype/pull/1991)
2529
* FIX: FEAT "folder does not exist" error (https://github.com/nipy/nipype/pull/2000)
2630
* ENH: Niftyfit interfaces (https://github.com/nipy/nipype/pull/1910)

nipype/interfaces/fsl/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
PlotTimeSeries, PlotMotionParams, ConvertXFM,
1919
SwapDimensions, PowerSpectrum, Reorient2Std,
2020
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints,
21-
WarpPointsToStd, RobustFOV, CopyGeom, MotionOutliers)
21+
WarpPointsToStd, WarpPointsFromStd, RobustFOV,
22+
CopyGeom, MotionOutliers)
23+
2224
from .epi import (PrepareFieldmap, TOPUP, ApplyTOPUP, Eddy, EPIDeWarp,
2325
SigLoss, EddyCorrect, EpiReg)
2426
from .dti import (BEDPOSTX, XFibres, DTIFit,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from ....testing import assert_equal
3+
from ..utils import WarpPointsFromStd
4+
5+
6+
def test_WarpPointsFromStd_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
coord_mm=dict(argstr='-mm',
10+
xor=[u'coord_vox'],
11+
),
12+
coord_vox=dict(argstr='-vox',
13+
xor=[u'coord_mm'],
14+
),
15+
environ=dict(nohash=True,
16+
usedefault=True,
17+
),
18+
ignore_exception=dict(nohash=True,
19+
usedefault=True,
20+
),
21+
img_file=dict(argstr='-img %s',
22+
mandatory=True,
23+
),
24+
in_coords=dict(argstr='%s',
25+
mandatory=True,
26+
position=-2,
27+
),
28+
std_file=dict(argstr='-std %s',
29+
mandatory=True,
30+
),
31+
terminal_output=dict(nohash=True,
32+
),
33+
warp_file=dict(argstr='-warp %s',
34+
xor=[u'xfm_file'],
35+
),
36+
xfm_file=dict(argstr='-xfm %s',
37+
xor=[u'warp_file'],
38+
),
39+
)
40+
inputs = WarpPointsFromStd.input_spec()
41+
42+
for key, metadata in list(input_map.items()):
43+
for metakey, value in list(metadata.items()):
44+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
45+
46+
47+
def test_WarpPointsFromStd_outputs():
48+
output_map = dict(out_file=dict(),
49+
)
50+
outputs = WarpPointsFromStd.output_spec()
51+
52+
for key, metadata in list(output_map.items()):
53+
for metakey, value in list(metadata.items()):
54+
yield assert_equal, getattr(outputs.traits()[key], metakey), value

nipype/interfaces/fsl/utils.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
os.chdir(datadir)
1818
"""
1919
from __future__ import print_function, division, unicode_literals, absolute_import
20-
from builtins import map, range
20+
from builtins import map, range, open
2121

2222
import os
2323
import os.path as op
@@ -2110,6 +2110,59 @@ class WarpPointsToStd(WarpPoints):
21102110
input_spec = WarpPointsToStdInputSpec
21112111
output_spec = WarpPointsOutputSpec
21122112
_cmd = 'img2stdcoord'
2113+
_terminal_output = 'file_split'
2114+
2115+
2116+
class WarpPointsFromStdInputSpec(CommandLineInputSpec):
2117+
img_file = File(exists=True, argstr='-img %s', mandatory=True,
2118+
desc='filename of a destination image')
2119+
std_file = File(exists=True, argstr='-std %s', mandatory=True,
2120+
desc='filename of the image in standard space')
2121+
in_coords = File(exists=True, position=-2, argstr='%s', mandatory=True,
2122+
desc='filename of file containing coordinates')
2123+
xfm_file = File(exists=True, argstr='-xfm %s', xor=['warp_file'],
2124+
desc='filename of affine transform (e.g. source2dest.mat)')
2125+
warp_file = File(exists=True, argstr='-warp %s', xor=['xfm_file'],
2126+
desc='filename of warpfield (e.g. '
2127+
'intermediate2dest_warp.nii.gz)')
2128+
coord_vox = traits.Bool(True, argstr='-vox', xor=['coord_mm'],
2129+
desc='all coordinates in voxels - default')
2130+
coord_mm = traits.Bool(False, argstr='-mm', xor=['coord_vox'],
2131+
desc='all coordinates in mm')
2132+
2133+
2134+
class WarpPointsFromStd(CommandLine):
2135+
"""
2136+
Use FSL `std2imgcoord <http://fsl.fmrib.ox.ac.uk/fsl/fsl-4.1.9/flirt/overview.html>`_
2137+
to transform point sets to standard space coordinates. Accepts plain text coordinates
2138+
files.
2139+
2140+
2141+
Examples
2142+
--------
2143+
2144+
>>> from nipype.interfaces.fsl import WarpPointsFromStd
2145+
>>> warppoints = WarpPointsFromStd()
2146+
>>> warppoints.inputs.in_coords = 'surf.txt'
2147+
>>> warppoints.inputs.img_file = 'T1.nii'
2148+
>>> warppoints.inputs.std_file = 'mni.nii'
2149+
>>> warppoints.inputs.warp_file = 'warpfield.nii'
2150+
>>> warppoints.inputs.coord_mm = True
2151+
>>> warppoints.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE
2152+
'std2imgcoord -mm -img T1.nii -std mni.nii -warp warpfield.nii surf.txt'
2153+
>>> res = warppoints.run() # doctest: +SKIP
2154+
2155+
2156+
"""
2157+
2158+
input_spec = WarpPointsFromStdInputSpec
2159+
output_spec = WarpPointsOutputSpec
2160+
_cmd = 'std2imgcoord'
2161+
2162+
def _list_outputs(self):
2163+
outputs = self.output_spec().get()
2164+
outputs['out_file'] = op.abspath('stdout.nipype')
2165+
return outputs
21132166

21142167

21152168
class MotionOutliersInputSpec(FSLCommandInputSpec):

0 commit comments

Comments
 (0)