|
26 | 26 | from ..base import (traits, TraitedSpec, OutputMultiPath, File,
|
27 | 27 | CommandLine, CommandLineInputSpec, isdefined)
|
28 | 28 | from ...utils.filemanip import (load_json, save_json, split_filename,
|
29 |
| - fname_presuffix) |
| 29 | + fname_presuffix, copyfile) |
30 | 30 |
|
31 | 31 | warn = warnings.warn
|
32 | 32 | warnings.filterwarnings('always', category=UserWarning)
|
33 | 33 |
|
| 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 | + |
34 | 79 | class RobustFOVInputSpec(FSLCommandInputSpec):
|
35 | 80 | in_file = File(exists=True,
|
36 | 81 | desc='input filename',
|
|
0 commit comments