|
1 | 1 | """ANTs' utilities."""
|
2 | 2 | import os
|
| 3 | +from warnings import warn |
3 | 4 | from ..base import traits, isdefined, TraitedSpec, File, Str, InputMultiObject
|
4 | 5 | from ..mixins import CopyHeaderInterface
|
5 | 6 | from .base import ANTSCommandInputSpec, ANTSCommand
|
@@ -103,13 +104,46 @@ class ImageMath(ANTSCommand, CopyHeaderInterface):
|
103 | 104 | ... op2='0.005 0.999 256').cmdline
|
104 | 105 | 'ImageMath 3 structural_maths.nii TruncateImageIntensity structural.nii 0.005 0.999 256'
|
105 | 106 |
|
| 107 | + >>> pad = ImageMath( |
| 108 | + ... op1='structural.nii', |
| 109 | + ... operation='PadImage', |
| 110 | + ... op2='0.005 0.999 256') |
| 111 | + >>> pad.inputs.copy_header |
| 112 | + False |
| 113 | +
|
| 114 | + >>> pad.inputs.copy_header = True |
| 115 | + >>> pad.inputs.copy_header |
| 116 | + False |
| 117 | +
|
| 118 | + >>> pad.inputs.operation = "ME" |
| 119 | + >>> pad.inputs.copy_header = True |
| 120 | + >>> pad.inputs.copy_header |
| 121 | + True |
| 122 | +
|
106 | 123 | """
|
107 | 124 |
|
108 | 125 | _cmd = "ImageMath"
|
109 | 126 | input_spec = ImageMathInputSpec
|
110 | 127 | output_spec = ImageMathOuputSpec
|
111 | 128 | _copy_header_map = {"output_image": "op1"}
|
112 | 129 |
|
| 130 | + def __init__(self, **inputs): |
| 131 | + super(ImageMath, self).__init__(**inputs) |
| 132 | + if self.inputs.operation in ("PadImage", ): |
| 133 | + self.inputs.copy_header = False |
| 134 | + |
| 135 | + self.inputs.on_trait_change(self._operation_update, "operation") |
| 136 | + self.inputs.on_trait_change(self._copyheader_update, "copy_header") |
| 137 | + |
| 138 | + def _operation_update(self): |
| 139 | + if self.inputs.operation in ("PadImage", ): |
| 140 | + self.inputs.copy_header = False |
| 141 | + |
| 142 | + def _copyheader_update(self): |
| 143 | + if self.inputs.copy_header and self.inputs.operation in ("PadImage", ): |
| 144 | + warn("copy_header cannot be updated to True with PadImage as operation.") |
| 145 | + self.inputs.copy_header = False |
| 146 | + |
113 | 147 |
|
114 | 148 | class ResampleImageBySpacingInputSpec(ANTSCommandInputSpec):
|
115 | 149 | dimension = traits.Int(
|
@@ -147,19 +181,13 @@ class ResampleImageBySpacingInputSpec(ANTSCommandInputSpec):
|
147 | 181 | nn_interp = traits.Bool(
|
148 | 182 | argstr="%d", desc="nn interpolation", position=-1, requires=["addvox"]
|
149 | 183 | )
|
150 |
| - copy_header = traits.Bool( |
151 |
| - True, |
152 |
| - mandatory=True, |
153 |
| - usedefault=True, |
154 |
| - desc="copy headers of the original image into the output (corrected) file", |
155 |
| - ) |
156 | 184 |
|
157 | 185 |
|
158 | 186 | class ResampleImageBySpacingOutputSpec(TraitedSpec):
|
159 | 187 | output_image = File(exists=True, desc="resampled file")
|
160 | 188 |
|
161 | 189 |
|
162 |
| -class ResampleImageBySpacing(ANTSCommand, CopyHeaderInterface): |
| 190 | +class ResampleImageBySpacing(ANTSCommand): |
163 | 191 | """
|
164 | 192 | Resample an image with a given spacing.
|
165 | 193 |
|
@@ -195,7 +223,6 @@ class ResampleImageBySpacing(ANTSCommand, CopyHeaderInterface):
|
195 | 223 | _cmd = "ResampleImageBySpacing"
|
196 | 224 | input_spec = ResampleImageBySpacingInputSpec
|
197 | 225 | output_spec = ResampleImageBySpacingOutputSpec
|
198 |
| - _copy_header_map = {"output_image": "input_image"} |
199 | 226 |
|
200 | 227 | def _format_arg(self, name, trait_spec, value):
|
201 | 228 | if name == "out_spacing":
|
|
0 commit comments