|
| 1 | +from pydra.engine import specs |
| 2 | +from pydra import ShellCommandTask |
| 3 | +import typing as ty |
| 4 | + |
| 5 | + |
| 6 | +def complex_output(inputs, in_file): |
| 7 | + import attr |
| 8 | + |
| 9 | + if inputs.complex_cartesian: |
| 10 | + in_file = inputs.real_in_file |
| 11 | + elif inputs.complex_polar: |
| 12 | + in_file = inputs.magnitude_in_file |
| 13 | + elif inputs.complex_split or inputs.complex_merge: |
| 14 | + in_file = inputs.complex_in_file |
| 15 | + else: |
| 16 | + return None |
| 17 | + return f"{in_file}_cplx" |
| 18 | + |
| 19 | + |
| 20 | +input_fields = [ |
| 21 | + ( |
| 22 | + "complex_in_file", |
| 23 | + specs.File, |
| 24 | + {"help_string": "", "argstr": "{complex_in_file}", "position": 2}, |
| 25 | + ), |
| 26 | + ( |
| 27 | + "complex_in_file2", |
| 28 | + specs.File, |
| 29 | + {"help_string": "", "argstr": "{complex_in_file2}", "position": 3}, |
| 30 | + ), |
| 31 | + ( |
| 32 | + "real_in_file", |
| 33 | + specs.File, |
| 34 | + {"help_string": "", "argstr": "{real_in_file}", "position": 2}, |
| 35 | + ), |
| 36 | + ( |
| 37 | + "imaginary_in_file", |
| 38 | + specs.File, |
| 39 | + {"help_string": "", "argstr": "{imaginary_in_file}", "position": 3}, |
| 40 | + ), |
| 41 | + ( |
| 42 | + "magnitude_in_file", |
| 43 | + specs.File, |
| 44 | + {"help_string": "", "argstr": "{magnitude_in_file}", "position": 2}, |
| 45 | + ), |
| 46 | + ( |
| 47 | + "phase_in_file", |
| 48 | + specs.File, |
| 49 | + {"help_string": "", "argstr": "{phase_in_file}", "position": 3}, |
| 50 | + ), |
| 51 | + ( |
| 52 | + "complex_out_file", |
| 53 | + str, |
| 54 | + { |
| 55 | + "help_string": "", |
| 56 | + "argstr": "{complex_out_file}", |
| 57 | + "position": -3, |
| 58 | + "xor": [ |
| 59 | + "complex_out_file", |
| 60 | + "magnitude_out_file", |
| 61 | + "phase_out_file", |
| 62 | + "real_out_file", |
| 63 | + "imaginary_out_file", |
| 64 | + "real_polar", |
| 65 | + "real_cartesian", |
| 66 | + ], |
| 67 | + }, |
| 68 | + ), |
| 69 | + ( |
| 70 | + "magnitude_out_file", |
| 71 | + str, |
| 72 | + { |
| 73 | + "help_string": "", |
| 74 | + "argstr": "{magnitude_out_file}", |
| 75 | + "position": -4, |
| 76 | + "xor": [ |
| 77 | + "complex_out_file", |
| 78 | + "real_out_file", |
| 79 | + "imaginary_out_file", |
| 80 | + "real_cartesian", |
| 81 | + "complex_cartesian", |
| 82 | + "complex_polar", |
| 83 | + "complex_split", |
| 84 | + "complex_merge", |
| 85 | + ], |
| 86 | + "output_file_template": "{in_file}_mag", |
| 87 | + }, |
| 88 | + ), |
| 89 | + ( |
| 90 | + "phase_out_file", |
| 91 | + str, |
| 92 | + { |
| 93 | + "help_string": "", |
| 94 | + "argstr": "{phase_out_file}", |
| 95 | + "position": -3, |
| 96 | + "xor": [ |
| 97 | + "complex_out_file", |
| 98 | + "real_out_file", |
| 99 | + "imaginary_out_file", |
| 100 | + "real_cartesian", |
| 101 | + "complex_cartesian", |
| 102 | + "complex_polar", |
| 103 | + "complex_split", |
| 104 | + "complex_merge", |
| 105 | + ], |
| 106 | + "output_file_template": "{in_file}_phase", |
| 107 | + }, |
| 108 | + ), |
| 109 | + ( |
| 110 | + "real_out_file", |
| 111 | + str, |
| 112 | + { |
| 113 | + "help_string": "", |
| 114 | + "argstr": "{real_out_file}", |
| 115 | + "position": -4, |
| 116 | + "xor": [ |
| 117 | + "complex_out_file", |
| 118 | + "magnitude_out_file", |
| 119 | + "phase_out_file", |
| 120 | + "real_polar", |
| 121 | + "complex_cartesian", |
| 122 | + "complex_polar", |
| 123 | + "complex_split", |
| 124 | + "complex_merge", |
| 125 | + ], |
| 126 | + "output_file_template": "{in_file}_real", |
| 127 | + }, |
| 128 | + ), |
| 129 | + ( |
| 130 | + "imaginary_out_file", |
| 131 | + str, |
| 132 | + { |
| 133 | + "help_string": "", |
| 134 | + "argstr": "{imaginary_out_file}", |
| 135 | + "position": -3, |
| 136 | + "xor": [ |
| 137 | + "complex_out_file", |
| 138 | + "magnitude_out_file", |
| 139 | + "phase_out_file", |
| 140 | + "real_polar", |
| 141 | + "complex_cartesian", |
| 142 | + "complex_polar", |
| 143 | + "complex_split", |
| 144 | + "complex_merge", |
| 145 | + ], |
| 146 | + "output_file_template": "{in_file}_imag", |
| 147 | + }, |
| 148 | + ), |
| 149 | + ("start_vol", int, {"help_string": "", "argstr": "{start_vol}", "position": -2}), |
| 150 | + ("end_vol", int, {"help_string": "", "argstr": "{end_vol}", "position": -1}), |
| 151 | + ( |
| 152 | + "real_polar", |
| 153 | + bool, |
| 154 | + { |
| 155 | + "help_string": "", |
| 156 | + "argstr": "-realpolar", |
| 157 | + "position": 1, |
| 158 | + "xor": [ |
| 159 | + "real_polar", |
| 160 | + "real_cartesian", |
| 161 | + "complex_cartesian", |
| 162 | + "complex_polar", |
| 163 | + "complex_split", |
| 164 | + "complex_merge", |
| 165 | + ], |
| 166 | + }, |
| 167 | + ), |
| 168 | + ( |
| 169 | + "real_cartesian", |
| 170 | + bool, |
| 171 | + { |
| 172 | + "help_string": "", |
| 173 | + "argstr": "-realcartesian", |
| 174 | + "position": 1, |
| 175 | + "xor": [ |
| 176 | + "real_polar", |
| 177 | + "real_cartesian", |
| 178 | + "complex_cartesian", |
| 179 | + "complex_polar", |
| 180 | + "complex_split", |
| 181 | + "complex_merge", |
| 182 | + ], |
| 183 | + }, |
| 184 | + ), |
| 185 | + ( |
| 186 | + "complex_cartesian", |
| 187 | + bool, |
| 188 | + { |
| 189 | + "help_string": "", |
| 190 | + "argstr": "-complex", |
| 191 | + "position": 1, |
| 192 | + "xor": [ |
| 193 | + "real_polar", |
| 194 | + "real_cartesian", |
| 195 | + "complex_cartesian", |
| 196 | + "complex_polar", |
| 197 | + "complex_split", |
| 198 | + "complex_merge", |
| 199 | + ], |
| 200 | + }, |
| 201 | + ), |
| 202 | + ( |
| 203 | + "complex_polar", |
| 204 | + bool, |
| 205 | + { |
| 206 | + "help_string": "", |
| 207 | + "argstr": "-complexpolar", |
| 208 | + "position": 1, |
| 209 | + "xor": [ |
| 210 | + "real_polar", |
| 211 | + "real_cartesian", |
| 212 | + "complex_cartesian", |
| 213 | + "complex_polar", |
| 214 | + "complex_split", |
| 215 | + "complex_merge", |
| 216 | + ], |
| 217 | + }, |
| 218 | + ), |
| 219 | + ( |
| 220 | + "complex_split", |
| 221 | + bool, |
| 222 | + { |
| 223 | + "help_string": "", |
| 224 | + "argstr": "-complexsplit", |
| 225 | + "position": 1, |
| 226 | + "xor": [ |
| 227 | + "real_polar", |
| 228 | + "real_cartesian", |
| 229 | + "complex_cartesian", |
| 230 | + "complex_polar", |
| 231 | + "complex_split", |
| 232 | + "complex_merge", |
| 233 | + ], |
| 234 | + }, |
| 235 | + ), |
| 236 | + ( |
| 237 | + "complex_merge", |
| 238 | + bool, |
| 239 | + { |
| 240 | + "help_string": "", |
| 241 | + "argstr": "-complexmerge", |
| 242 | + "position": 1, |
| 243 | + "xor": [ |
| 244 | + "real_polar", |
| 245 | + "real_cartesian", |
| 246 | + "complex_cartesian", |
| 247 | + "complex_polar", |
| 248 | + "complex_split", |
| 249 | + "complex_merge", |
| 250 | + "start_vol", |
| 251 | + "end_vol", |
| 252 | + ], |
| 253 | + }, |
| 254 | + ), |
| 255 | +] |
| 256 | +Complex_input_spec = specs.SpecInfo( |
| 257 | + name="Input", fields=input_fields, bases=(specs.ShellSpec,) |
| 258 | +) |
| 259 | + |
| 260 | +output_fields = [] |
| 261 | +Complex_output_spec = specs.SpecInfo( |
| 262 | + name="Output", fields=output_fields, bases=(specs.ShellOutSpec,) |
| 263 | +) |
| 264 | + |
| 265 | + |
| 266 | +class Complex(ShellCommandTask): |
| 267 | + input_spec = Complex_input_spec |
| 268 | + output_spec = Complex_output_spec |
| 269 | + executable = "fslcomplex" |
0 commit comments