Skip to content

Commit 814538a

Browse files
committed
New FSL interface for fslcpgeom
1 parent 8df64cd commit 814538a

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
PlotTimeSeries, PlotMotionParams, ConvertXFM,
1818
SwapDimensions, PowerSpectrum, Reorient2Std,
1919
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints,
20-
WarpPointsToStd, RobustFOV)
20+
WarpPointsToStd, RobustFOV, CopyGeom)
2121

2222
from .epi import (PrepareFieldmap, TOPUP, ApplyTOPUP, Eddy, EPIDeWarp,
2323
SigLoss, EddyCorrect, EpiReg)

nipype/interfaces/fsl/utils.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,56 @@
2626
from ..base import (traits, TraitedSpec, OutputMultiPath, File,
2727
CommandLine, CommandLineInputSpec, isdefined)
2828
from ...utils.filemanip import (load_json, save_json, split_filename,
29-
fname_presuffix)
29+
fname_presuffix, copyfile)
3030

3131
warn = warnings.warn
3232
warnings.filterwarnings('always', category=UserWarning)
3333

34+
class CopyGeomInputSpec(FSLCommandInputSpec):
35+
in_file = File(exists=True, mandatory=True, argstr="%s", position=0,
36+
desc="source image")
37+
dest_file = File(exists=True, mandatory=True, argstr="%s", position=1,
38+
desc="destination image", copyfile=True)
39+
ignore_dims = traits.Bool(desc=('Do not copy image dimensions'),
40+
argstr='-d', position="-1")
41+
42+
class CopyGeomOutputSpec(TraitedSpec):
43+
out_file = File(exists=True, desc="image with new geometry header")
44+
45+
class CopyGeom(FSLCommand):
46+
"""Use fslcpgeom to copy the header geometry information to another image.
47+
48+
Copy certain parts of the header information (image dimensions, voxel dimensions,
49+
voxel dimensions units string, image orientation/origin or qform/sform info)
50+
from one image to another. Note that only copies from Analyze to Analyze
51+
or Nifti to Nifti will work properly. Copying from different files will result
52+
in loss of information or potentially incorrect settings.
53+
54+
"""
55+
_cmd = "fslcpgeom"
56+
input_spec = CopyGeomInputSpec
57+
output_spec = CopyGeomOutputSpec
58+
59+
def _run_interface(self, runtime):
60+
# Copy destination file to new local file to prevent overwriting
61+
# and update destination file
62+
out_file = self._gen_filename('out_file')
63+
copyfile(self.inputs.dest_file, out_file, copy=True)
64+
self.inputs.dest_file = out_file
65+
return super(CopyGeom, self)._run_interface(runtime)
66+
67+
def _gen_filename(self, name):
68+
if name == 'out_file':
69+
return self._gen_fname(self.inputs.dest_file, suffix="_newhd")
70+
return None
71+
72+
def _list_outputs(self):
73+
outputs = self.output_spec().get()
74+
# Use the new destination file updated by _run_interface
75+
outputs['out_file'] = self.inputs.dest_file
76+
return outputs
77+
78+
3479
class RobustFOVInputSpec(FSLCommandInputSpec):
3580
in_file = File(exists=True,
3681
desc='input filename',

0 commit comments

Comments
 (0)