niwrap-mrtrix 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. niwrap_mrtrix/mrtrix/__init__.py +263 -0
  2. niwrap_mrtrix/mrtrix/afdconnectivity.py +527 -0
  3. niwrap_mrtrix/mrtrix/amp2response.py +560 -0
  4. niwrap_mrtrix/mrtrix/amp2sh.py +870 -0
  5. niwrap_mrtrix/mrtrix/connectome2tck.py +583 -0
  6. niwrap_mrtrix/mrtrix/connectomeedit.py +413 -0
  7. niwrap_mrtrix/mrtrix/connectomestats.py +956 -0
  8. niwrap_mrtrix/mrtrix/dcmedit.py +552 -0
  9. niwrap_mrtrix/mrtrix/dcminfo.py +529 -0
  10. niwrap_mrtrix/mrtrix/dirflip.py +440 -0
  11. niwrap_mrtrix/mrtrix/dirgen.py +514 -0
  12. niwrap_mrtrix/mrtrix/dirmerge.py +446 -0
  13. niwrap_mrtrix/mrtrix/dirorder.py +421 -0
  14. niwrap_mrtrix/mrtrix/dirsplit.py +436 -0
  15. niwrap_mrtrix/mrtrix/dirstat.py +640 -0
  16. niwrap_mrtrix/mrtrix/dwi2adc.py +531 -0
  17. niwrap_mrtrix/mrtrix/dwi2fod.py +1156 -0
  18. niwrap_mrtrix/mrtrix/dwi2mask.py +570 -0
  19. niwrap_mrtrix/mrtrix/dwi2response.py +1774 -0
  20. niwrap_mrtrix/mrtrix/dwi2tensor.py +715 -0
  21. niwrap_mrtrix/mrtrix/dwibiascorrect.py +673 -0
  22. niwrap_mrtrix/mrtrix/dwidenoise.py +570 -0
  23. niwrap_mrtrix/mrtrix/dwiextract.py +1111 -0
  24. niwrap_mrtrix/mrtrix/dwigradcheck.py +665 -0
  25. niwrap_mrtrix/mrtrix/fixel2peaks.py +613 -0
  26. niwrap_mrtrix/mrtrix/fixel2sh.py +430 -0
  27. niwrap_mrtrix/mrtrix/fixel2tsf.py +435 -0
  28. niwrap_mrtrix/mrtrix/fixel2voxel.py +523 -0
  29. niwrap_mrtrix/mrtrix/fixelcfestats.py +1179 -0
  30. niwrap_mrtrix/mrtrix/fixelconnectivity.py +477 -0
  31. niwrap_mrtrix/mrtrix/fixelconvert.py +850 -0
  32. niwrap_mrtrix/mrtrix/fixelcorrespondence.py +455 -0
  33. niwrap_mrtrix/mrtrix/fixelcrop.py +422 -0
  34. niwrap_mrtrix/mrtrix/fixelfilter.py +882 -0
  35. niwrap_mrtrix/mrtrix/fixelreorient.py +435 -0
  36. niwrap_mrtrix/mrtrix/fod2dec.py +571 -0
  37. niwrap_mrtrix/mrtrix/fod2fixel.py +646 -0
  38. niwrap_mrtrix/mrtrix/label2colour.py +426 -0
  39. niwrap_mrtrix/mrtrix/label2mesh.py +417 -0
  40. niwrap_mrtrix/mrtrix/labelconvert.py +460 -0
  41. niwrap_mrtrix/mrtrix/labelstats.py +418 -0
  42. niwrap_mrtrix/mrtrix/maskdump.py +404 -0
  43. niwrap_mrtrix/mrtrix/maskfilter.py +730 -0
  44. niwrap_mrtrix/mrtrix/mesh2voxel.py +422 -0
  45. niwrap_mrtrix/mrtrix/meshconvert.py +514 -0
  46. niwrap_mrtrix/mrtrix/meshfilter.py +452 -0
  47. niwrap_mrtrix/mrtrix/mraverageheader.py +485 -0
  48. niwrap_mrtrix/mrtrix/mrcalc.py +4302 -0
  49. niwrap_mrtrix/mrtrix/mrcat.py +467 -0
  50. niwrap_mrtrix/mrtrix/mrcentroid.py +418 -0
  51. niwrap_mrtrix/mrtrix/mrcheckerboardmask.py +446 -0
  52. niwrap_mrtrix/mrtrix/mrclusterstats.py +930 -0
  53. niwrap_mrtrix/mrtrix/mrcolour.py +490 -0
  54. niwrap_mrtrix/mrtrix/mrconvert.py +1967 -0
  55. niwrap_mrtrix/mrtrix/mrdegibbs.py +535 -0
  56. niwrap_mrtrix/mrtrix/mrdump.py +423 -0
  57. niwrap_mrtrix/mrtrix/mredit.py +737 -0
  58. niwrap_mrtrix/mrtrix/mrfilter.py +971 -0
  59. niwrap_mrtrix/mrtrix/mrgrid.py +1079 -0
  60. niwrap_mrtrix/mrtrix/mrhistmatch.py +494 -0
  61. niwrap_mrtrix/mrtrix/mrhistogram.py +484 -0
  62. niwrap_mrtrix/mrtrix/mrinfo.py +1282 -0
  63. niwrap_mrtrix/mrtrix/mrmath.py +503 -0
  64. niwrap_mrtrix/mrtrix/mrmetric.py +525 -0
  65. niwrap_mrtrix/mrtrix/mrregister.py +2098 -0
  66. niwrap_mrtrix/mrtrix/mrstats.py +534 -0
  67. niwrap_mrtrix/mrtrix/mrthreshold.py +666 -0
  68. niwrap_mrtrix/mrtrix/mrtransform.py +1372 -0
  69. niwrap_mrtrix/mrtrix/mtnormalise.py +725 -0
  70. niwrap_mrtrix/mrtrix/peaks2amp.py +403 -0
  71. niwrap_mrtrix/mrtrix/peaks2fixel.py +422 -0
  72. niwrap_mrtrix/mrtrix/responsemean.py +385 -0
  73. niwrap_mrtrix/mrtrix/sh2amp.py +844 -0
  74. niwrap_mrtrix/mrtrix/sh2peaks.py +632 -0
  75. niwrap_mrtrix/mrtrix/sh2power.py +427 -0
  76. niwrap_mrtrix/mrtrix/sh2response.py +481 -0
  77. niwrap_mrtrix/mrtrix/shbasis.py +445 -0
  78. niwrap_mrtrix/mrtrix/shconv.py +661 -0
  79. niwrap_mrtrix/mrtrix/tck2connectome.py +727 -0
  80. niwrap_mrtrix/mrtrix/tck2fixel.py +447 -0
  81. niwrap_mrtrix/mrtrix/tckconvert.py +775 -0
  82. niwrap_mrtrix/mrtrix/tckdfc.py +684 -0
  83. niwrap_mrtrix/mrtrix/tckedit.py +1478 -0
  84. niwrap_mrtrix/mrtrix/tckgen.py +2733 -0
  85. niwrap_mrtrix/mrtrix/tckglobal.py +944 -0
  86. niwrap_mrtrix/mrtrix/tckinfo.py +402 -0
  87. niwrap_mrtrix/mrtrix/tckmap.py +1004 -0
  88. niwrap_mrtrix/mrtrix/tckresample.py +760 -0
  89. niwrap_mrtrix/mrtrix/tcksample.py +497 -0
  90. niwrap_mrtrix/mrtrix/tcksift.py +739 -0
  91. niwrap_mrtrix/mrtrix/tcksift2.py +902 -0
  92. niwrap_mrtrix/mrtrix/tckstats.py +550 -0
  93. niwrap_mrtrix/mrtrix/tcktransform.py +414 -0
  94. niwrap_mrtrix/mrtrix/tensor2metric.py +659 -0
  95. niwrap_mrtrix/mrtrix/transformcalc.py +421 -0
  96. niwrap_mrtrix/mrtrix/transformcompose.py +625 -0
  97. niwrap_mrtrix/mrtrix/transformconvert.py +423 -0
  98. niwrap_mrtrix/mrtrix/tsfdivide.py +414 -0
  99. niwrap_mrtrix/mrtrix/tsfinfo.py +421 -0
  100. niwrap_mrtrix/mrtrix/tsfmult.py +401 -0
  101. niwrap_mrtrix/mrtrix/tsfsmooth.py +420 -0
  102. niwrap_mrtrix/mrtrix/tsfthreshold.py +428 -0
  103. niwrap_mrtrix/mrtrix/tsfvalidate.py +398 -0
  104. niwrap_mrtrix/mrtrix/v_5tt2gmwmi.py +432 -0
  105. niwrap_mrtrix/mrtrix/v_5tt2vis.py +505 -0
  106. niwrap_mrtrix/mrtrix/v_5ttcheck.py +409 -0
  107. niwrap_mrtrix/mrtrix/v_5ttedit.py +513 -0
  108. niwrap_mrtrix/mrtrix/v_5ttgen.py +1107 -0
  109. niwrap_mrtrix/mrtrix/vectorstats.py +736 -0
  110. niwrap_mrtrix/mrtrix/voxel2fixel.py +430 -0
  111. niwrap_mrtrix/mrtrix/voxel2mesh.py +454 -0
  112. niwrap_mrtrix/mrtrix/warp2metric.py +556 -0
  113. niwrap_mrtrix/mrtrix/warpconvert.py +498 -0
  114. niwrap_mrtrix/mrtrix/warpcorrect.py +448 -0
  115. niwrap_mrtrix/mrtrix/warpinit.py +425 -0
  116. niwrap_mrtrix/mrtrix/warpinvert.py +448 -0
  117. niwrap_mrtrix-0.8.0.dist-info/METADATA +8 -0
  118. niwrap_mrtrix-0.8.0.dist-info/RECORD +119 -0
  119. niwrap_mrtrix-0.8.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,1372 @@
1
+ # This file was auto generated by Styx.
2
+ # Do not edit this file directly.
3
+
4
+ import typing
5
+ import pathlib
6
+ from styxdefs import *
7
+
8
+ MRTRANSFORM_METADATA = Metadata(
9
+ id="3eb2d0d1d0da497152ef0293f2b94667de8b3275.boutiques",
10
+ name="mrtransform",
11
+ package="mrtrix",
12
+ container_image_tag="mrtrix3/mrtrix3:3.0.4",
13
+ )
14
+
15
+
16
+ _MrtransformFslgradParamsDictNoTag = typing.TypedDict('_MrtransformFslgradParamsDictNoTag', {
17
+ "bvecs": InputPathType,
18
+ "bvals": InputPathType,
19
+ })
20
+ MrtransformFslgradParamsDictTagged = typing.TypedDict('MrtransformFslgradParamsDictTagged', {
21
+ "@type": typing.Literal["fslgrad"],
22
+ "bvecs": InputPathType,
23
+ "bvals": InputPathType,
24
+ })
25
+ MrtransformFslgradParamsDict = _MrtransformFslgradParamsDictNoTag | MrtransformFslgradParamsDictTagged
26
+
27
+
28
+ _MrtransformExportGradFslParamsDictNoTag = typing.TypedDict('_MrtransformExportGradFslParamsDictNoTag', {
29
+ "bvecs_path": str,
30
+ "bvals_path": str,
31
+ })
32
+ MrtransformExportGradFslParamsDictTagged = typing.TypedDict('MrtransformExportGradFslParamsDictTagged', {
33
+ "@type": typing.Literal["export_grad_fsl"],
34
+ "bvecs_path": str,
35
+ "bvals_path": str,
36
+ })
37
+ MrtransformExportGradFslParamsDict = _MrtransformExportGradFslParamsDictNoTag | MrtransformExportGradFslParamsDictTagged
38
+
39
+
40
+ _MrtransformVariousStringParamsDictNoTag = typing.TypedDict('_MrtransformVariousStringParamsDictNoTag', {
41
+ "obj": str,
42
+ })
43
+ MrtransformVariousStringParamsDictTagged = typing.TypedDict('MrtransformVariousStringParamsDictTagged', {
44
+ "@type": typing.Literal["VariousString"],
45
+ "obj": str,
46
+ })
47
+ MrtransformVariousStringParamsDict = _MrtransformVariousStringParamsDictNoTag | MrtransformVariousStringParamsDictTagged
48
+
49
+
50
+ _MrtransformVariousFileParamsDictNoTag = typing.TypedDict('_MrtransformVariousFileParamsDictNoTag', {
51
+ "obj": InputPathType,
52
+ })
53
+ MrtransformVariousFileParamsDictTagged = typing.TypedDict('MrtransformVariousFileParamsDictTagged', {
54
+ "@type": typing.Literal["VariousFile"],
55
+ "obj": InputPathType,
56
+ })
57
+ MrtransformVariousFileParamsDict = _MrtransformVariousFileParamsDictNoTag | MrtransformVariousFileParamsDictTagged
58
+
59
+
60
+ _MrtransformConfigParamsDictNoTag = typing.TypedDict('_MrtransformConfigParamsDictNoTag', {
61
+ "key": str,
62
+ "value": str,
63
+ })
64
+ MrtransformConfigParamsDictTagged = typing.TypedDict('MrtransformConfigParamsDictTagged', {
65
+ "@type": typing.Literal["config"],
66
+ "key": str,
67
+ "value": str,
68
+ })
69
+ MrtransformConfigParamsDict = _MrtransformConfigParamsDictNoTag | MrtransformConfigParamsDictTagged
70
+
71
+
72
+ _MrtransformParamsDictNoTag = typing.TypedDict('_MrtransformParamsDictNoTag', {
73
+ "linear": typing.NotRequired[InputPathType | None],
74
+ "flip": typing.NotRequired[list[int] | None],
75
+ "inverse": bool,
76
+ "half": bool,
77
+ "replace": typing.NotRequired[InputPathType | None],
78
+ "identity": bool,
79
+ "template": typing.NotRequired[InputPathType | None],
80
+ "midway_space": bool,
81
+ "interp": typing.NotRequired[str | None],
82
+ "oversample": typing.NotRequired[list[int] | None],
83
+ "warp": typing.NotRequired[InputPathType | None],
84
+ "warp_full": typing.NotRequired[InputPathType | None],
85
+ "from": typing.NotRequired[int | None],
86
+ "modulate": typing.NotRequired[str | None],
87
+ "directions": typing.NotRequired[InputPathType | None],
88
+ "reorient_fod": typing.NotRequired[str | None],
89
+ "grad": typing.NotRequired[InputPathType | None],
90
+ "fslgrad": typing.NotRequired[MrtransformFslgradParamsDict | None],
91
+ "export_grad_mrtrix": typing.NotRequired[str | None],
92
+ "export_grad_fsl": typing.NotRequired[MrtransformExportGradFslParamsDict | None],
93
+ "datatype": typing.NotRequired[str | None],
94
+ "strides": typing.NotRequired[typing.Union[MrtransformVariousStringParamsDictTagged, MrtransformVariousFileParamsDictTagged] | None],
95
+ "nan": bool,
96
+ "no_reorientation": bool,
97
+ "info": bool,
98
+ "quiet": bool,
99
+ "debug": bool,
100
+ "force": bool,
101
+ "nthreads": typing.NotRequired[int | None],
102
+ "config": typing.NotRequired[list[MrtransformConfigParamsDict] | None],
103
+ "help": bool,
104
+ "version": bool,
105
+ "input": InputPathType,
106
+ "output": str,
107
+ })
108
+ MrtransformParamsDictTagged = typing.TypedDict('MrtransformParamsDictTagged', {
109
+ "@type": typing.Literal["mrtrix/mrtransform"],
110
+ "linear": typing.NotRequired[InputPathType | None],
111
+ "flip": typing.NotRequired[list[int] | None],
112
+ "inverse": bool,
113
+ "half": bool,
114
+ "replace": typing.NotRequired[InputPathType | None],
115
+ "identity": bool,
116
+ "template": typing.NotRequired[InputPathType | None],
117
+ "midway_space": bool,
118
+ "interp": typing.NotRequired[str | None],
119
+ "oversample": typing.NotRequired[list[int] | None],
120
+ "warp": typing.NotRequired[InputPathType | None],
121
+ "warp_full": typing.NotRequired[InputPathType | None],
122
+ "from": typing.NotRequired[int | None],
123
+ "modulate": typing.NotRequired[str | None],
124
+ "directions": typing.NotRequired[InputPathType | None],
125
+ "reorient_fod": typing.NotRequired[str | None],
126
+ "grad": typing.NotRequired[InputPathType | None],
127
+ "fslgrad": typing.NotRequired[MrtransformFslgradParamsDict | None],
128
+ "export_grad_mrtrix": typing.NotRequired[str | None],
129
+ "export_grad_fsl": typing.NotRequired[MrtransformExportGradFslParamsDict | None],
130
+ "datatype": typing.NotRequired[str | None],
131
+ "strides": typing.NotRequired[typing.Union[MrtransformVariousStringParamsDictTagged, MrtransformVariousFileParamsDictTagged] | None],
132
+ "nan": bool,
133
+ "no_reorientation": bool,
134
+ "info": bool,
135
+ "quiet": bool,
136
+ "debug": bool,
137
+ "force": bool,
138
+ "nthreads": typing.NotRequired[int | None],
139
+ "config": typing.NotRequired[list[MrtransformConfigParamsDict] | None],
140
+ "help": bool,
141
+ "version": bool,
142
+ "input": InputPathType,
143
+ "output": str,
144
+ })
145
+ MrtransformParamsDict = _MrtransformParamsDictNoTag | MrtransformParamsDictTagged
146
+
147
+
148
+ def mrtransform_strides_cargs_dyn_fn(
149
+ t: str,
150
+ ) -> typing.Any:
151
+ """
152
+ Get build cargs function by command type.
153
+
154
+ Args:
155
+ t: Command type.
156
+ Returns:
157
+ Build cargs function.
158
+ """
159
+ return {
160
+ "VariousString": mrtransform_various_string_cargs,
161
+ "VariousFile": mrtransform_various_file_cargs,
162
+ }.get(t)
163
+
164
+
165
+ def mrtransform_strides_validate_dyn_fn(
166
+ t: str,
167
+ ) -> typing.Any:
168
+ """
169
+ Get validate params function by command type.
170
+
171
+ Args:
172
+ t: Command type.
173
+ Returns:
174
+ Validate params function.
175
+ """
176
+ return {
177
+ "VariousString": mrtransform_various_string_validate,
178
+ "VariousFile": mrtransform_various_file_validate,
179
+ }.get(t)
180
+
181
+
182
+ def mrtransform_fslgrad(
183
+ bvecs: InputPathType,
184
+ bvals: InputPathType,
185
+ ) -> MrtransformFslgradParamsDictTagged:
186
+ """
187
+ Build parameters.
188
+
189
+ Args:
190
+ bvecs: Provide the diffusion-weighted gradient scheme used in the\
191
+ acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
192
+ scheme is present in the input image header, the data provided with\
193
+ this option will be instead used.
194
+ bvals: Provide the diffusion-weighted gradient scheme used in the\
195
+ acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
196
+ scheme is present in the input image header, the data provided with\
197
+ this option will be instead used.
198
+ Returns:
199
+ Parameter dictionary
200
+ """
201
+ params = {
202
+ "@type": "fslgrad",
203
+ "bvecs": bvecs,
204
+ "bvals": bvals,
205
+ }
206
+ return params
207
+
208
+
209
+ def mrtransform_fslgrad_validate(
210
+ params: typing.Any,
211
+ ) -> None:
212
+ """
213
+ Validate parameters. Throws an error if `params` is not a valid
214
+ `MrtransformFslgradParamsDict` object.
215
+
216
+ Args:
217
+ params: The parameters object to validate.
218
+ """
219
+ if params is None or not isinstance(params, dict):
220
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
221
+ if params.get("bvecs", None) is None:
222
+ raise StyxValidationError("`bvecs` must not be None")
223
+ if not isinstance(params["bvecs"], (pathlib.Path, str)):
224
+ raise StyxValidationError(f'`bvecs` has the wrong type: Received `{type(params.get("bvecs", None))}` expected `InputPathType`')
225
+ if params.get("bvals", None) is None:
226
+ raise StyxValidationError("`bvals` must not be None")
227
+ if not isinstance(params["bvals"], (pathlib.Path, str)):
228
+ raise StyxValidationError(f'`bvals` has the wrong type: Received `{type(params.get("bvals", None))}` expected `InputPathType`')
229
+
230
+
231
+ def mrtransform_fslgrad_cargs(
232
+ params: MrtransformFslgradParamsDict,
233
+ execution: Execution,
234
+ ) -> list[str]:
235
+ """
236
+ Build command-line arguments from parameters.
237
+
238
+ Args:
239
+ params: The parameters.
240
+ execution: The execution object for resolving input paths.
241
+ Returns:
242
+ Command-line arguments.
243
+ """
244
+ cargs = []
245
+ cargs.append("-fslgrad")
246
+ cargs.append(execution.input_file(params.get("bvecs", None)))
247
+ cargs.append(execution.input_file(params.get("bvals", None)))
248
+ return cargs
249
+
250
+
251
+ class MrtransformExportGradFslOutputs(typing.NamedTuple):
252
+ """
253
+ Output object returned when calling `MrtransformExportGradFslParamsDict | None(...)`.
254
+ """
255
+ root: OutputPathType
256
+ """Output root folder. This is the root folder for all outputs."""
257
+ bvecs_path: OutputPathType
258
+ """export the diffusion-weighted gradient table to files in FSL (bvecs /
259
+ bvals) format"""
260
+ bvals_path: OutputPathType
261
+ """export the diffusion-weighted gradient table to files in FSL (bvecs /
262
+ bvals) format"""
263
+
264
+
265
+ def mrtransform_export_grad_fsl(
266
+ bvecs_path: str,
267
+ bvals_path: str,
268
+ ) -> MrtransformExportGradFslParamsDictTagged:
269
+ """
270
+ Build parameters.
271
+
272
+ Args:
273
+ bvecs_path: export the diffusion-weighted gradient table to files in\
274
+ FSL (bvecs / bvals) format.
275
+ bvals_path: export the diffusion-weighted gradient table to files in\
276
+ FSL (bvecs / bvals) format.
277
+ Returns:
278
+ Parameter dictionary
279
+ """
280
+ params = {
281
+ "@type": "export_grad_fsl",
282
+ "bvecs_path": bvecs_path,
283
+ "bvals_path": bvals_path,
284
+ }
285
+ return params
286
+
287
+
288
+ def mrtransform_export_grad_fsl_validate(
289
+ params: typing.Any,
290
+ ) -> None:
291
+ """
292
+ Validate parameters. Throws an error if `params` is not a valid
293
+ `MrtransformExportGradFslParamsDict` object.
294
+
295
+ Args:
296
+ params: The parameters object to validate.
297
+ """
298
+ if params is None or not isinstance(params, dict):
299
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
300
+ if params.get("bvecs_path", None) is None:
301
+ raise StyxValidationError("`bvecs_path` must not be None")
302
+ if not isinstance(params["bvecs_path"], str):
303
+ raise StyxValidationError(f'`bvecs_path` has the wrong type: Received `{type(params.get("bvecs_path", None))}` expected `str`')
304
+ if params.get("bvals_path", None) is None:
305
+ raise StyxValidationError("`bvals_path` must not be None")
306
+ if not isinstance(params["bvals_path"], str):
307
+ raise StyxValidationError(f'`bvals_path` has the wrong type: Received `{type(params.get("bvals_path", None))}` expected `str`')
308
+
309
+
310
+ def mrtransform_export_grad_fsl_cargs(
311
+ params: MrtransformExportGradFslParamsDict,
312
+ execution: Execution,
313
+ ) -> list[str]:
314
+ """
315
+ Build command-line arguments from parameters.
316
+
317
+ Args:
318
+ params: The parameters.
319
+ execution: The execution object for resolving input paths.
320
+ Returns:
321
+ Command-line arguments.
322
+ """
323
+ cargs = []
324
+ cargs.append("-export_grad_fsl")
325
+ cargs.append(params.get("bvecs_path", None))
326
+ cargs.append(params.get("bvals_path", None))
327
+ return cargs
328
+
329
+
330
+ def mrtransform_export_grad_fsl_outputs(
331
+ params: MrtransformExportGradFslParamsDict,
332
+ execution: Execution,
333
+ ) -> MrtransformExportGradFslOutputs:
334
+ """
335
+ Build outputs object containing output file paths and possibly stdout/stderr.
336
+
337
+ Args:
338
+ params: The parameters.
339
+ execution: The execution object for resolving input paths.
340
+ Returns:
341
+ Outputs object.
342
+ """
343
+ ret = MrtransformExportGradFslOutputs(
344
+ root=execution.output_file("."),
345
+ bvecs_path=execution.output_file(params.get("bvecs_path", None)),
346
+ bvals_path=execution.output_file(params.get("bvals_path", None)),
347
+ )
348
+ return ret
349
+
350
+
351
+ def mrtransform_various_string(
352
+ obj: str,
353
+ ) -> MrtransformVariousStringParamsDictTagged:
354
+ """
355
+ Build parameters.
356
+
357
+ Args:
358
+ obj: String object.
359
+ Returns:
360
+ Parameter dictionary
361
+ """
362
+ params = {
363
+ "@type": "VariousString",
364
+ "obj": obj,
365
+ }
366
+ return params
367
+
368
+
369
+ def mrtransform_various_string_validate(
370
+ params: typing.Any,
371
+ ) -> None:
372
+ """
373
+ Validate parameters. Throws an error if `params` is not a valid
374
+ `MrtransformVariousStringParamsDict` object.
375
+
376
+ Args:
377
+ params: The parameters object to validate.
378
+ """
379
+ if params is None or not isinstance(params, dict):
380
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
381
+ if params.get("obj", None) is None:
382
+ raise StyxValidationError("`obj` must not be None")
383
+ if not isinstance(params["obj"], str):
384
+ raise StyxValidationError(f'`obj` has the wrong type: Received `{type(params.get("obj", None))}` expected `str`')
385
+
386
+
387
+ def mrtransform_various_string_cargs(
388
+ params: MrtransformVariousStringParamsDict,
389
+ execution: Execution,
390
+ ) -> list[str]:
391
+ """
392
+ Build command-line arguments from parameters.
393
+
394
+ Args:
395
+ params: The parameters.
396
+ execution: The execution object for resolving input paths.
397
+ Returns:
398
+ Command-line arguments.
399
+ """
400
+ cargs = []
401
+ cargs.append(params.get("obj", None))
402
+ return cargs
403
+
404
+
405
+ def mrtransform_various_file(
406
+ obj: InputPathType,
407
+ ) -> MrtransformVariousFileParamsDictTagged:
408
+ """
409
+ Build parameters.
410
+
411
+ Args:
412
+ obj: File object.
413
+ Returns:
414
+ Parameter dictionary
415
+ """
416
+ params = {
417
+ "@type": "VariousFile",
418
+ "obj": obj,
419
+ }
420
+ return params
421
+
422
+
423
+ def mrtransform_various_file_validate(
424
+ params: typing.Any,
425
+ ) -> None:
426
+ """
427
+ Validate parameters. Throws an error if `params` is not a valid
428
+ `MrtransformVariousFileParamsDict` object.
429
+
430
+ Args:
431
+ params: The parameters object to validate.
432
+ """
433
+ if params is None or not isinstance(params, dict):
434
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
435
+ if params.get("obj", None) is None:
436
+ raise StyxValidationError("`obj` must not be None")
437
+ if not isinstance(params["obj"], (pathlib.Path, str)):
438
+ raise StyxValidationError(f'`obj` has the wrong type: Received `{type(params.get("obj", None))}` expected `InputPathType`')
439
+
440
+
441
+ def mrtransform_various_file_cargs(
442
+ params: MrtransformVariousFileParamsDict,
443
+ execution: Execution,
444
+ ) -> list[str]:
445
+ """
446
+ Build command-line arguments from parameters.
447
+
448
+ Args:
449
+ params: The parameters.
450
+ execution: The execution object for resolving input paths.
451
+ Returns:
452
+ Command-line arguments.
453
+ """
454
+ cargs = []
455
+ cargs.append(execution.input_file(params.get("obj", None)))
456
+ return cargs
457
+
458
+
459
+ def mrtransform_config(
460
+ key: str,
461
+ value: str,
462
+ ) -> MrtransformConfigParamsDictTagged:
463
+ """
464
+ Build parameters.
465
+
466
+ Args:
467
+ key: temporarily set the value of an MRtrix config file entry.
468
+ value: temporarily set the value of an MRtrix config file entry.
469
+ Returns:
470
+ Parameter dictionary
471
+ """
472
+ params = {
473
+ "@type": "config",
474
+ "key": key,
475
+ "value": value,
476
+ }
477
+ return params
478
+
479
+
480
+ def mrtransform_config_validate(
481
+ params: typing.Any,
482
+ ) -> None:
483
+ """
484
+ Validate parameters. Throws an error if `params` is not a valid
485
+ `MrtransformConfigParamsDict` object.
486
+
487
+ Args:
488
+ params: The parameters object to validate.
489
+ """
490
+ if params is None or not isinstance(params, dict):
491
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
492
+ if params.get("key", None) is None:
493
+ raise StyxValidationError("`key` must not be None")
494
+ if not isinstance(params["key"], str):
495
+ raise StyxValidationError(f'`key` has the wrong type: Received `{type(params.get("key", None))}` expected `str`')
496
+ if params.get("value", None) is None:
497
+ raise StyxValidationError("`value` must not be None")
498
+ if not isinstance(params["value"], str):
499
+ raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `str`')
500
+
501
+
502
+ def mrtransform_config_cargs(
503
+ params: MrtransformConfigParamsDict,
504
+ execution: Execution,
505
+ ) -> list[str]:
506
+ """
507
+ Build command-line arguments from parameters.
508
+
509
+ Args:
510
+ params: The parameters.
511
+ execution: The execution object for resolving input paths.
512
+ Returns:
513
+ Command-line arguments.
514
+ """
515
+ cargs = []
516
+ cargs.append("-config")
517
+ cargs.append(params.get("key", None))
518
+ cargs.append(params.get("value", None))
519
+ return cargs
520
+
521
+
522
+ class MrtransformOutputs(typing.NamedTuple):
523
+ """
524
+ Output object returned when calling `MrtransformParamsDict(...)`.
525
+ """
526
+ root: OutputPathType
527
+ """Output root folder. This is the root folder for all outputs."""
528
+ output: OutputPathType
529
+ """the output image."""
530
+ export_grad_mrtrix: OutputPathType | None
531
+ """export the diffusion-weighted gradient table to file in MRtrix format """
532
+ export_grad_fsl: MrtransformExportGradFslOutputs | None
533
+ """Outputs from `mrtransform_export_grad_fsl_outputs`."""
534
+
535
+
536
+ def mrtransform_params(
537
+ input_: InputPathType,
538
+ output: str,
539
+ linear: InputPathType | None = None,
540
+ flip: list[int] | None = None,
541
+ inverse: bool = False,
542
+ half: bool = False,
543
+ replace: InputPathType | None = None,
544
+ identity: bool = False,
545
+ template: InputPathType | None = None,
546
+ midway_space: bool = False,
547
+ interp: str | None = None,
548
+ oversample: list[int] | None = None,
549
+ warp: InputPathType | None = None,
550
+ warp_full: InputPathType | None = None,
551
+ from_: int | None = None,
552
+ modulate: str | None = None,
553
+ directions: InputPathType | None = None,
554
+ reorient_fod: str | None = None,
555
+ grad: InputPathType | None = None,
556
+ fslgrad: MrtransformFslgradParamsDict | None = None,
557
+ export_grad_mrtrix: str | None = None,
558
+ export_grad_fsl: MrtransformExportGradFslParamsDict | None = None,
559
+ datatype: str | None = None,
560
+ strides: typing.Union[MrtransformVariousStringParamsDictTagged, MrtransformVariousFileParamsDictTagged] | None = None,
561
+ nan: bool = False,
562
+ no_reorientation: bool = False,
563
+ info: bool = False,
564
+ quiet: bool = False,
565
+ debug: bool = False,
566
+ force: bool = False,
567
+ nthreads: int | None = None,
568
+ config: list[MrtransformConfigParamsDict] | None = None,
569
+ help_: bool = False,
570
+ version: bool = False,
571
+ ) -> MrtransformParamsDictTagged:
572
+ """
573
+ Build parameters.
574
+
575
+ Args:
576
+ input_: input image to be transformed.
577
+ output: the output image.
578
+ linear: specify a linear transform to apply, in the form of a 3x4 or\
579
+ 4x4 ascii file. Note the standard 'reverse' convention is used, where\
580
+ the transform maps points in the template image to the moving image.\
581
+ Note that the reverse convention is still assumed even if no -template\
582
+ image is supplied.
583
+ flip: flip the specified axes, provided as a comma-separated list of\
584
+ indices (0:x, 1:y, 2:z).
585
+ inverse: apply the inverse transformation.
586
+ half: apply the matrix square root of the transformation. This can be\
587
+ combined with the inverse option.
588
+ replace: replace the linear transform of the original image by that\
589
+ specified, rather than applying it to the original image. The specified\
590
+ transform can be either a template image, or a 3x4 or 4x4 ascii file.
591
+ identity: set the header transform of the image to the identity matrix.
592
+ template: reslice the input image to match the specified template image\
593
+ grid.
594
+ midway_space: reslice the input image to the midway space. Requires\
595
+ either the -template or -warp option. If used with -template and\
596
+ -linear option the input image will be resliced onto the grid halfway\
597
+ between the input and template. If used with the -warp option the input\
598
+ will be warped to the midway space defined by the grid of the input\
599
+ warp (i.e. half way between image1 and image2).
600
+ interp: set the interpolation method to use when reslicing (choices:\
601
+ nearest, linear, cubic, sinc. Default: cubic).
602
+ oversample: set the amount of over-sampling (in the target space) to\
603
+ perform when regridding. This is particularly relevant when downsamping\
604
+ a high-resolution image to a low-resolution image, to avoid aliasing\
605
+ artefacts. This can consist of a single integer, or a comma-separated\
606
+ list of 3 integers if different oversampling factors are desired along\
607
+ the different axes. Default is determined from ratio of voxel\
608
+ dimensions (disabled for nearest-neighbour interpolation).
609
+ warp: apply a non-linear 4D deformation field to warp the input image.\
610
+ Each voxel in the deformation field must define the scanner space\
611
+ position that will be used to interpolate the input image during\
612
+ warping (i.e. pull-back/reverse warp convention). If the -template\
613
+ image is also supplied the deformation field will be resliced first to\
614
+ the template image grid. If no -template option is supplied then the\
615
+ output image will have the same image grid as the deformation field.\
616
+ This option can be used in combination with the -affine option, in\
617
+ which case the affine will be applied first).
618
+ warp_full: warp the input image using a 5D warp file output from\
619
+ mrregister. Any linear transforms in the warp image header will also be\
620
+ applied. The -warp_full option must be used in combination with either\
621
+ the -template option or the -midway_space option. If a -template image\
622
+ is supplied then the full warp will be used. By default the\
623
+ image1->image2 transform will be applied, however the -from 2 option\
624
+ can be used to apply the image2->image1 transform. Use the\
625
+ -midway_space option to warp the input image to the midway space. The\
626
+ -from option can also be used to define which warp to use when\
627
+ transforming to midway space.
628
+ from_: used to define which space the input image is when using the\
629
+ -warp_mid option. Use -from 1 to warp from image1 or -from 2 to warp\
630
+ from image2.
631
+ modulate: Valid choices are: fod and jac.\
632
+ fod: modulate FODs during reorientation to preserve the apparent\
633
+ fibre density across fibre bundle widths before and after the\
634
+ transformation.\
635
+ jac: modulate the image intensity with the determinant of the\
636
+ Jacobian of the warp of linear transformation to preserve the total\
637
+ intensity before and after the transformation.
638
+ directions: directions defining the number and orientation of the\
639
+ apodised point spread functions used in FOD reorientation (Default: 300\
640
+ directions).
641
+ reorient_fod: specify whether to perform FOD reorientation. This is\
642
+ required if the number of volumes in the 4th dimension corresponds to\
643
+ the number of coefficients in an antipodally symmetric spherical\
644
+ harmonic series with lmax >= 2 (i.e. 6, 15, 28, 45, 66 volumes).
645
+ grad: Provide the diffusion-weighted gradient scheme used in the\
646
+ acquisition in a text file. This should be supplied as a 4xN text file\
647
+ with each line is in the format [ X Y Z b ], where [ X Y Z ] describe\
648
+ the direction of the applied gradient, and b gives the b-value in units\
649
+ of s/mm^2. If a diffusion gradient scheme is present in the input image\
650
+ header, the data provided with this option will be instead used.
651
+ fslgrad: Provide the diffusion-weighted gradient scheme used in the\
652
+ acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
653
+ scheme is present in the input image header, the data provided with\
654
+ this option will be instead used.
655
+ export_grad_mrtrix: export the diffusion-weighted gradient table to\
656
+ file in MRtrix format.
657
+ export_grad_fsl: export the diffusion-weighted gradient table to files\
658
+ in FSL (bvecs / bvals) format.
659
+ datatype: specify output image data type. Valid choices are: float32,\
660
+ float32le, float32be, float64, float64le, float64be, int64, uint64,\
661
+ int64le, uint64le, int64be, uint64be, int32, uint32, int32le, uint32le,\
662
+ int32be, uint32be, int16, uint16, int16le, uint16le, int16be, uint16be,\
663
+ cfloat32, cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be,\
664
+ int8, uint8, bit.
665
+ strides: specify the strides of the output data in memory; either as a\
666
+ comma-separated list of (signed) integers, or as a template image from\
667
+ which the strides shall be extracted and used. The actual strides\
668
+ produced will depend on whether the output image format can support it.
669
+ nan: Use NaN as the out of bounds value (Default: 0.0).
670
+ no_reorientation: deprecated, use -reorient_fod instead.
671
+ info: display information messages.
672
+ quiet: do not display information messages or progress status;\
673
+ alternatively, this can be achieved by setting the MRTRIX_QUIET\
674
+ environment variable to a non-empty string.
675
+ debug: display debugging messages.
676
+ force: force overwrite of output files (caution: using the same file as\
677
+ input and output might cause unexpected behaviour).
678
+ nthreads: use this number of threads in multi-threaded applications\
679
+ (set to 0 to disable multi-threading).
680
+ config: temporarily set the value of an MRtrix config file entry.
681
+ help_: display this information page and exit.
682
+ version: display version information and exit.
683
+ Returns:
684
+ Parameter dictionary
685
+ """
686
+ params = {
687
+ "@type": "mrtrix/mrtransform",
688
+ "inverse": inverse,
689
+ "half": half,
690
+ "identity": identity,
691
+ "midway_space": midway_space,
692
+ "nan": nan,
693
+ "no_reorientation": no_reorientation,
694
+ "info": info,
695
+ "quiet": quiet,
696
+ "debug": debug,
697
+ "force": force,
698
+ "help": help_,
699
+ "version": version,
700
+ "input": input_,
701
+ "output": output,
702
+ }
703
+ if linear is not None:
704
+ params["linear"] = linear
705
+ if flip is not None:
706
+ params["flip"] = flip
707
+ if replace is not None:
708
+ params["replace"] = replace
709
+ if template is not None:
710
+ params["template"] = template
711
+ if interp is not None:
712
+ params["interp"] = interp
713
+ if oversample is not None:
714
+ params["oversample"] = oversample
715
+ if warp is not None:
716
+ params["warp"] = warp
717
+ if warp_full is not None:
718
+ params["warp_full"] = warp_full
719
+ if from_ is not None:
720
+ params["from"] = from_
721
+ if modulate is not None:
722
+ params["modulate"] = modulate
723
+ if directions is not None:
724
+ params["directions"] = directions
725
+ if reorient_fod is not None:
726
+ params["reorient_fod"] = reorient_fod
727
+ if grad is not None:
728
+ params["grad"] = grad
729
+ if fslgrad is not None:
730
+ params["fslgrad"] = fslgrad
731
+ if export_grad_mrtrix is not None:
732
+ params["export_grad_mrtrix"] = export_grad_mrtrix
733
+ if export_grad_fsl is not None:
734
+ params["export_grad_fsl"] = export_grad_fsl
735
+ if datatype is not None:
736
+ params["datatype"] = datatype
737
+ if strides is not None:
738
+ params["strides"] = strides
739
+ if nthreads is not None:
740
+ params["nthreads"] = nthreads
741
+ if config is not None:
742
+ params["config"] = config
743
+ return params
744
+
745
+
746
+ def mrtransform_validate(
747
+ params: typing.Any,
748
+ ) -> None:
749
+ """
750
+ Validate parameters. Throws an error if `params` is not a valid
751
+ `MrtransformParamsDict` object.
752
+
753
+ Args:
754
+ params: The parameters object to validate.
755
+ """
756
+ if params is None or not isinstance(params, dict):
757
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
758
+ if params.get("linear", None) is not None:
759
+ if not isinstance(params["linear"], (pathlib.Path, str)):
760
+ raise StyxValidationError(f'`linear` has the wrong type: Received `{type(params.get("linear", None))}` expected `InputPathType | None`')
761
+ if params.get("flip", None) is not None:
762
+ if not isinstance(params["flip"], list):
763
+ raise StyxValidationError(f'`flip` has the wrong type: Received `{type(params.get("flip", None))}` expected `list[int] | None`')
764
+ for e in params["flip"]:
765
+ if not isinstance(e, int):
766
+ raise StyxValidationError(f'`flip` has the wrong type: Received `{type(params.get("flip", None))}` expected `list[int] | None`')
767
+ if params.get("inverse", False) is None:
768
+ raise StyxValidationError("`inverse` must not be None")
769
+ if not isinstance(params["inverse"], bool):
770
+ raise StyxValidationError(f'`inverse` has the wrong type: Received `{type(params.get("inverse", False))}` expected `bool`')
771
+ if params.get("half", False) is None:
772
+ raise StyxValidationError("`half` must not be None")
773
+ if not isinstance(params["half"], bool):
774
+ raise StyxValidationError(f'`half` has the wrong type: Received `{type(params.get("half", False))}` expected `bool`')
775
+ if params.get("replace", None) is not None:
776
+ if not isinstance(params["replace"], (pathlib.Path, str)):
777
+ raise StyxValidationError(f'`replace` has the wrong type: Received `{type(params.get("replace", None))}` expected `InputPathType | None`')
778
+ if params.get("identity", False) is None:
779
+ raise StyxValidationError("`identity` must not be None")
780
+ if not isinstance(params["identity"], bool):
781
+ raise StyxValidationError(f'`identity` has the wrong type: Received `{type(params.get("identity", False))}` expected `bool`')
782
+ if params.get("template", None) is not None:
783
+ if not isinstance(params["template"], (pathlib.Path, str)):
784
+ raise StyxValidationError(f'`template` has the wrong type: Received `{type(params.get("template", None))}` expected `InputPathType | None`')
785
+ if params.get("midway_space", False) is None:
786
+ raise StyxValidationError("`midway_space` must not be None")
787
+ if not isinstance(params["midway_space"], bool):
788
+ raise StyxValidationError(f'`midway_space` has the wrong type: Received `{type(params.get("midway_space", False))}` expected `bool`')
789
+ if params.get("interp", None) is not None:
790
+ if not isinstance(params["interp"], str):
791
+ raise StyxValidationError(f'`interp` has the wrong type: Received `{type(params.get("interp", None))}` expected `str | None`')
792
+ if params.get("oversample", None) is not None:
793
+ if not isinstance(params["oversample"], list):
794
+ raise StyxValidationError(f'`oversample` has the wrong type: Received `{type(params.get("oversample", None))}` expected `list[int] | None`')
795
+ for e in params["oversample"]:
796
+ if not isinstance(e, int):
797
+ raise StyxValidationError(f'`oversample` has the wrong type: Received `{type(params.get("oversample", None))}` expected `list[int] | None`')
798
+ if params.get("warp", None) is not None:
799
+ if not isinstance(params["warp"], (pathlib.Path, str)):
800
+ raise StyxValidationError(f'`warp` has the wrong type: Received `{type(params.get("warp", None))}` expected `InputPathType | None`')
801
+ if params.get("warp_full", None) is not None:
802
+ if not isinstance(params["warp_full"], (pathlib.Path, str)):
803
+ raise StyxValidationError(f'`warp_full` has the wrong type: Received `{type(params.get("warp_full", None))}` expected `InputPathType | None`')
804
+ if params.get("from", None) is not None:
805
+ if not isinstance(params["from"], int):
806
+ raise StyxValidationError(f'`from` has the wrong type: Received `{type(params.get("from", None))}` expected `int | None`')
807
+ if params.get("modulate", None) is not None:
808
+ if not isinstance(params["modulate"], str):
809
+ raise StyxValidationError(f'`modulate` has the wrong type: Received `{type(params.get("modulate", None))}` expected `str | None`')
810
+ if params.get("directions", None) is not None:
811
+ if not isinstance(params["directions"], (pathlib.Path, str)):
812
+ raise StyxValidationError(f'`directions` has the wrong type: Received `{type(params.get("directions", None))}` expected `InputPathType | None`')
813
+ if params.get("reorient_fod", None) is not None:
814
+ if not isinstance(params["reorient_fod"], str):
815
+ raise StyxValidationError(f'`reorient_fod` has the wrong type: Received `{type(params.get("reorient_fod", None))}` expected `str | None`')
816
+ if params.get("grad", None) is not None:
817
+ if not isinstance(params["grad"], (pathlib.Path, str)):
818
+ raise StyxValidationError(f'`grad` has the wrong type: Received `{type(params.get("grad", None))}` expected `InputPathType | None`')
819
+ if params.get("fslgrad", None) is not None:
820
+ mrtransform_fslgrad_validate(params["fslgrad"])
821
+ if params.get("export_grad_mrtrix", None) is not None:
822
+ if not isinstance(params["export_grad_mrtrix"], str):
823
+ raise StyxValidationError(f'`export_grad_mrtrix` has the wrong type: Received `{type(params.get("export_grad_mrtrix", None))}` expected `str | None`')
824
+ if params.get("export_grad_fsl", None) is not None:
825
+ mrtransform_export_grad_fsl_validate(params["export_grad_fsl"])
826
+ if params.get("datatype", None) is not None:
827
+ if not isinstance(params["datatype"], str):
828
+ raise StyxValidationError(f'`datatype` has the wrong type: Received `{type(params.get("datatype", None))}` expected `str | None`')
829
+ if params.get("strides", None) is not None:
830
+ if not isinstance(params["strides"], dict):
831
+ raise StyxValidationError(f'Params object has the wrong type \'{type(params["strides"])}\'')
832
+ if "@type" not in params["strides"]:
833
+ raise StyxValidationError("Params object is missing `@type`")
834
+ if params["strides"]["@type"] not in ["VariousString", "VariousFile"]:
835
+ raise StyxValidationError("Parameter `strides`s `@type` must be one of [\"VariousString\", \"VariousFile\"]")
836
+ mrtransform_strides_validate_dyn_fn(params["strides"]["@type"])(params["strides"])
837
+ if params.get("nan", False) is None:
838
+ raise StyxValidationError("`nan` must not be None")
839
+ if not isinstance(params["nan"], bool):
840
+ raise StyxValidationError(f'`nan` has the wrong type: Received `{type(params.get("nan", False))}` expected `bool`')
841
+ if params.get("no_reorientation", False) is None:
842
+ raise StyxValidationError("`no_reorientation` must not be None")
843
+ if not isinstance(params["no_reorientation"], bool):
844
+ raise StyxValidationError(f'`no_reorientation` has the wrong type: Received `{type(params.get("no_reorientation", False))}` expected `bool`')
845
+ if params.get("info", False) is None:
846
+ raise StyxValidationError("`info` must not be None")
847
+ if not isinstance(params["info"], bool):
848
+ raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
849
+ if params.get("quiet", False) is None:
850
+ raise StyxValidationError("`quiet` must not be None")
851
+ if not isinstance(params["quiet"], bool):
852
+ raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
853
+ if params.get("debug", False) is None:
854
+ raise StyxValidationError("`debug` must not be None")
855
+ if not isinstance(params["debug"], bool):
856
+ raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
857
+ if params.get("force", False) is None:
858
+ raise StyxValidationError("`force` must not be None")
859
+ if not isinstance(params["force"], bool):
860
+ raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
861
+ if params.get("nthreads", None) is not None:
862
+ if not isinstance(params["nthreads"], int):
863
+ raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
864
+ if params.get("config", None) is not None:
865
+ if not isinstance(params["config"], list):
866
+ raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[MrtransformConfigParamsDict] | None`')
867
+ for e in params["config"]:
868
+ mrtransform_config_validate(e)
869
+ if params.get("help", False) is None:
870
+ raise StyxValidationError("`help` must not be None")
871
+ if not isinstance(params["help"], bool):
872
+ raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
873
+ if params.get("version", False) is None:
874
+ raise StyxValidationError("`version` must not be None")
875
+ if not isinstance(params["version"], bool):
876
+ raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')
877
+ if params.get("input", None) is None:
878
+ raise StyxValidationError("`input` must not be None")
879
+ if not isinstance(params["input"], (pathlib.Path, str)):
880
+ raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
881
+ if params.get("output", None) is None:
882
+ raise StyxValidationError("`output` must not be None")
883
+ if not isinstance(params["output"], str):
884
+ raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
885
+
886
+
887
+ def mrtransform_cargs(
888
+ params: MrtransformParamsDict,
889
+ execution: Execution,
890
+ ) -> list[str]:
891
+ """
892
+ Build command-line arguments from parameters.
893
+
894
+ Args:
895
+ params: The parameters.
896
+ execution: The execution object for resolving input paths.
897
+ Returns:
898
+ Command-line arguments.
899
+ """
900
+ cargs = []
901
+ cargs.append("mrtransform")
902
+ if params.get("linear", None) is not None:
903
+ cargs.extend([
904
+ "-linear",
905
+ execution.input_file(params.get("linear", None))
906
+ ])
907
+ if params.get("flip", None) is not None:
908
+ cargs.extend([
909
+ "-flip",
910
+ ",".join(map(str, params.get("flip", None)))
911
+ ])
912
+ if params.get("inverse", False):
913
+ cargs.append("-inverse")
914
+ if params.get("half", False):
915
+ cargs.append("-half")
916
+ if params.get("replace", None) is not None:
917
+ cargs.extend([
918
+ "-replace",
919
+ execution.input_file(params.get("replace", None))
920
+ ])
921
+ if params.get("identity", False):
922
+ cargs.append("-identity")
923
+ if params.get("template", None) is not None:
924
+ cargs.extend([
925
+ "-template",
926
+ execution.input_file(params.get("template", None))
927
+ ])
928
+ if params.get("midway_space", False):
929
+ cargs.append("-midway_space")
930
+ if params.get("interp", None) is not None:
931
+ cargs.extend([
932
+ "-interp",
933
+ params.get("interp", None)
934
+ ])
935
+ if params.get("oversample", None) is not None:
936
+ cargs.extend([
937
+ "-oversample",
938
+ ",".join(map(str, params.get("oversample", None)))
939
+ ])
940
+ if params.get("warp", None) is not None:
941
+ cargs.extend([
942
+ "-warp",
943
+ execution.input_file(params.get("warp", None))
944
+ ])
945
+ if params.get("warp_full", None) is not None:
946
+ cargs.extend([
947
+ "-warp_full",
948
+ execution.input_file(params.get("warp_full", None))
949
+ ])
950
+ if params.get("from", None) is not None:
951
+ cargs.extend([
952
+ "-from",
953
+ str(params.get("from", None))
954
+ ])
955
+ if params.get("modulate", None) is not None:
956
+ cargs.extend([
957
+ "-modulate",
958
+ params.get("modulate", None)
959
+ ])
960
+ if params.get("directions", None) is not None:
961
+ cargs.extend([
962
+ "-directions",
963
+ execution.input_file(params.get("directions", None))
964
+ ])
965
+ if params.get("reorient_fod", None) is not None:
966
+ cargs.extend([
967
+ "-reorient_fod",
968
+ params.get("reorient_fod", None)
969
+ ])
970
+ if params.get("grad", None) is not None:
971
+ cargs.extend([
972
+ "-grad",
973
+ execution.input_file(params.get("grad", None))
974
+ ])
975
+ if params.get("fslgrad", None) is not None:
976
+ cargs.extend(mrtransform_fslgrad_cargs(params.get("fslgrad", None), execution))
977
+ if params.get("export_grad_mrtrix", None) is not None:
978
+ cargs.extend([
979
+ "-export_grad_mrtrix",
980
+ params.get("export_grad_mrtrix", None)
981
+ ])
982
+ if params.get("export_grad_fsl", None) is not None:
983
+ cargs.extend(mrtransform_export_grad_fsl_cargs(params.get("export_grad_fsl", None), execution))
984
+ if params.get("datatype", None) is not None:
985
+ cargs.extend([
986
+ "-datatype",
987
+ params.get("datatype", None)
988
+ ])
989
+ if params.get("strides", None) is not None:
990
+ cargs.extend([
991
+ "-strides",
992
+ *mrtransform_strides_cargs_dyn_fn(params.get("strides", None)["@type"])(params.get("strides", None), execution)
993
+ ])
994
+ if params.get("nan", False):
995
+ cargs.append("-nan")
996
+ if params.get("no_reorientation", False):
997
+ cargs.append("-no_reorientation")
998
+ if params.get("info", False):
999
+ cargs.append("-info")
1000
+ if params.get("quiet", False):
1001
+ cargs.append("-quiet")
1002
+ if params.get("debug", False):
1003
+ cargs.append("-debug")
1004
+ if params.get("force", False):
1005
+ cargs.append("-force")
1006
+ if params.get("nthreads", None) is not None:
1007
+ cargs.extend([
1008
+ "-nthreads",
1009
+ str(params.get("nthreads", None))
1010
+ ])
1011
+ if params.get("config", None) is not None:
1012
+ cargs.extend([a for c in [mrtransform_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
1013
+ if params.get("help", False):
1014
+ cargs.append("-help")
1015
+ if params.get("version", False):
1016
+ cargs.append("-version")
1017
+ cargs.append(execution.input_file(params.get("input", None)))
1018
+ cargs.append(params.get("output", None))
1019
+ return cargs
1020
+
1021
+
1022
+ def mrtransform_outputs(
1023
+ params: MrtransformParamsDict,
1024
+ execution: Execution,
1025
+ ) -> MrtransformOutputs:
1026
+ """
1027
+ Build outputs object containing output file paths and possibly stdout/stderr.
1028
+
1029
+ Args:
1030
+ params: The parameters.
1031
+ execution: The execution object for resolving input paths.
1032
+ Returns:
1033
+ Outputs object.
1034
+ """
1035
+ ret = MrtransformOutputs(
1036
+ root=execution.output_file("."),
1037
+ output=execution.output_file(params.get("output", None)),
1038
+ export_grad_mrtrix=execution.output_file(params.get("export_grad_mrtrix", None)) if (params.get("export_grad_mrtrix") is not None) else None,
1039
+ export_grad_fsl=mrtransform_export_grad_fsl_outputs(params.get("export_grad_fsl"), execution) if params.get("export_grad_fsl") else None,
1040
+ )
1041
+ return ret
1042
+
1043
+
1044
+ def mrtransform_execute(
1045
+ params: MrtransformParamsDict,
1046
+ runner: Runner | None = None,
1047
+ ) -> MrtransformOutputs:
1048
+ """
1049
+ mrtransform
1050
+
1051
+ Apply spatial transformations to an image.
1052
+
1053
+ If a linear transform is applied without a template image the command will
1054
+ modify the image header transform matrix
1055
+
1056
+ FOD reorientation (with apodised point spread functions) can be performed if
1057
+ the number of volumes in the 4th dimension equals the number of coefficients
1058
+ in an antipodally symmetric spherical harmonic series (e.g. 6, 15, 28 etc).
1059
+ For such data, the -reorient_fod yes/no option must be used to specify if
1060
+ reorientation is required.
1061
+
1062
+ The output image intensity can be modulated using the (local or global)
1063
+ volume change if a linear or nonlinear transformation is applied. 'FOD'
1064
+ modulation preserves the apparent fibre density across the fibre bundle
1065
+ width and can only be applied if FOD reorientation is used. Alternatively,
1066
+ non-directional scaling by the Jacobian determinant can be applied to any
1067
+ image type.
1068
+
1069
+ If a DW scheme is contained in the header (or specified separately), and the
1070
+ number of directions matches the number of volumes in the images, any
1071
+ transformation applied using the -linear option will also be applied to the
1072
+ directions.
1073
+
1074
+ When the -template option is used to specify the target image grid, the
1075
+ image provided via this option will not influence the axis data strides of
1076
+ the output image; these are determined based on the input image, or the
1077
+ input to the -strides option.
1078
+
1079
+ References:
1080
+
1081
+ * If FOD reorientation is being performed:
1082
+ Raffelt, D.; Tournier, J.-D.; Crozier, S.; Connelly, A. & Salvado, O.
1083
+ Reorientation of fiber orientation distributions using apodized point spread
1084
+ functions. Magnetic Resonance in Medicine, 2012, 67, 844-855
1085
+
1086
+ * If FOD modulation is being performed:
1087
+ Raffelt, D.; Tournier, J.-D.; Rose, S.; Ridgway, G.R.; Henderson, R.;
1088
+ Crozier, S.; Salvado, O.; Connelly, A.; Apparent Fibre Density: a novel
1089
+ measure for the analysis of diffusion-weighted magnetic resonance images.
1090
+ NeuroImage, 2012, 15;59(4), 3976-94.
1091
+
1092
+ Author: MRTrix3 Developers
1093
+
1094
+ URL: https://www.mrtrix.org/
1095
+
1096
+ Args:
1097
+ params: The parameters.
1098
+ runner: Command runner.
1099
+ Returns:
1100
+ NamedTuple of outputs (described in `MrtransformOutputs`).
1101
+ """
1102
+ mrtransform_validate(params)
1103
+ runner = runner or get_global_runner()
1104
+ execution = runner.start_execution(MRTRANSFORM_METADATA)
1105
+ params = execution.params(params)
1106
+ cargs = mrtransform_cargs(params, execution)
1107
+ ret = mrtransform_outputs(params, execution)
1108
+ execution.run(cargs)
1109
+ return ret
1110
+
1111
+
1112
+ def mrtransform(
1113
+ input_: InputPathType,
1114
+ output: str,
1115
+ linear: InputPathType | None = None,
1116
+ flip: list[int] | None = None,
1117
+ inverse: bool = False,
1118
+ half: bool = False,
1119
+ replace: InputPathType | None = None,
1120
+ identity: bool = False,
1121
+ template: InputPathType | None = None,
1122
+ midway_space: bool = False,
1123
+ interp: str | None = None,
1124
+ oversample: list[int] | None = None,
1125
+ warp: InputPathType | None = None,
1126
+ warp_full: InputPathType | None = None,
1127
+ from_: int | None = None,
1128
+ modulate: str | None = None,
1129
+ directions: InputPathType | None = None,
1130
+ reorient_fod: str | None = None,
1131
+ grad: InputPathType | None = None,
1132
+ fslgrad: MrtransformFslgradParamsDict | None = None,
1133
+ export_grad_mrtrix: str | None = None,
1134
+ export_grad_fsl: MrtransformExportGradFslParamsDict | None = None,
1135
+ datatype: str | None = None,
1136
+ strides: typing.Union[MrtransformVariousStringParamsDictTagged, MrtransformVariousFileParamsDictTagged] | None = None,
1137
+ nan: bool = False,
1138
+ no_reorientation: bool = False,
1139
+ info: bool = False,
1140
+ quiet: bool = False,
1141
+ debug: bool = False,
1142
+ force: bool = False,
1143
+ nthreads: int | None = None,
1144
+ config: list[MrtransformConfigParamsDict] | None = None,
1145
+ help_: bool = False,
1146
+ version: bool = False,
1147
+ runner: Runner | None = None,
1148
+ ) -> MrtransformOutputs:
1149
+ """
1150
+ mrtransform
1151
+
1152
+ Apply spatial transformations to an image.
1153
+
1154
+ If a linear transform is applied without a template image the command will
1155
+ modify the image header transform matrix
1156
+
1157
+ FOD reorientation (with apodised point spread functions) can be performed if
1158
+ the number of volumes in the 4th dimension equals the number of coefficients
1159
+ in an antipodally symmetric spherical harmonic series (e.g. 6, 15, 28 etc).
1160
+ For such data, the -reorient_fod yes/no option must be used to specify if
1161
+ reorientation is required.
1162
+
1163
+ The output image intensity can be modulated using the (local or global)
1164
+ volume change if a linear or nonlinear transformation is applied. 'FOD'
1165
+ modulation preserves the apparent fibre density across the fibre bundle
1166
+ width and can only be applied if FOD reorientation is used. Alternatively,
1167
+ non-directional scaling by the Jacobian determinant can be applied to any
1168
+ image type.
1169
+
1170
+ If a DW scheme is contained in the header (or specified separately), and the
1171
+ number of directions matches the number of volumes in the images, any
1172
+ transformation applied using the -linear option will also be applied to the
1173
+ directions.
1174
+
1175
+ When the -template option is used to specify the target image grid, the
1176
+ image provided via this option will not influence the axis data strides of
1177
+ the output image; these are determined based on the input image, or the
1178
+ input to the -strides option.
1179
+
1180
+ References:
1181
+
1182
+ * If FOD reorientation is being performed:
1183
+ Raffelt, D.; Tournier, J.-D.; Crozier, S.; Connelly, A. & Salvado, O.
1184
+ Reorientation of fiber orientation distributions using apodized point spread
1185
+ functions. Magnetic Resonance in Medicine, 2012, 67, 844-855
1186
+
1187
+ * If FOD modulation is being performed:
1188
+ Raffelt, D.; Tournier, J.-D.; Rose, S.; Ridgway, G.R.; Henderson, R.;
1189
+ Crozier, S.; Salvado, O.; Connelly, A.; Apparent Fibre Density: a novel
1190
+ measure for the analysis of diffusion-weighted magnetic resonance images.
1191
+ NeuroImage, 2012, 15;59(4), 3976-94.
1192
+
1193
+ Author: MRTrix3 Developers
1194
+
1195
+ URL: https://www.mrtrix.org/
1196
+
1197
+ Args:
1198
+ input_: input image to be transformed.
1199
+ output: the output image.
1200
+ linear: specify a linear transform to apply, in the form of a 3x4 or\
1201
+ 4x4 ascii file. Note the standard 'reverse' convention is used, where\
1202
+ the transform maps points in the template image to the moving image.\
1203
+ Note that the reverse convention is still assumed even if no -template\
1204
+ image is supplied.
1205
+ flip: flip the specified axes, provided as a comma-separated list of\
1206
+ indices (0:x, 1:y, 2:z).
1207
+ inverse: apply the inverse transformation.
1208
+ half: apply the matrix square root of the transformation. This can be\
1209
+ combined with the inverse option.
1210
+ replace: replace the linear transform of the original image by that\
1211
+ specified, rather than applying it to the original image. The specified\
1212
+ transform can be either a template image, or a 3x4 or 4x4 ascii file.
1213
+ identity: set the header transform of the image to the identity matrix.
1214
+ template: reslice the input image to match the specified template image\
1215
+ grid.
1216
+ midway_space: reslice the input image to the midway space. Requires\
1217
+ either the -template or -warp option. If used with -template and\
1218
+ -linear option the input image will be resliced onto the grid halfway\
1219
+ between the input and template. If used with the -warp option the input\
1220
+ will be warped to the midway space defined by the grid of the input\
1221
+ warp (i.e. half way between image1 and image2).
1222
+ interp: set the interpolation method to use when reslicing (choices:\
1223
+ nearest, linear, cubic, sinc. Default: cubic).
1224
+ oversample: set the amount of over-sampling (in the target space) to\
1225
+ perform when regridding. This is particularly relevant when downsamping\
1226
+ a high-resolution image to a low-resolution image, to avoid aliasing\
1227
+ artefacts. This can consist of a single integer, or a comma-separated\
1228
+ list of 3 integers if different oversampling factors are desired along\
1229
+ the different axes. Default is determined from ratio of voxel\
1230
+ dimensions (disabled for nearest-neighbour interpolation).
1231
+ warp: apply a non-linear 4D deformation field to warp the input image.\
1232
+ Each voxel in the deformation field must define the scanner space\
1233
+ position that will be used to interpolate the input image during\
1234
+ warping (i.e. pull-back/reverse warp convention). If the -template\
1235
+ image is also supplied the deformation field will be resliced first to\
1236
+ the template image grid. If no -template option is supplied then the\
1237
+ output image will have the same image grid as the deformation field.\
1238
+ This option can be used in combination with the -affine option, in\
1239
+ which case the affine will be applied first).
1240
+ warp_full: warp the input image using a 5D warp file output from\
1241
+ mrregister. Any linear transforms in the warp image header will also be\
1242
+ applied. The -warp_full option must be used in combination with either\
1243
+ the -template option or the -midway_space option. If a -template image\
1244
+ is supplied then the full warp will be used. By default the\
1245
+ image1->image2 transform will be applied, however the -from 2 option\
1246
+ can be used to apply the image2->image1 transform. Use the\
1247
+ -midway_space option to warp the input image to the midway space. The\
1248
+ -from option can also be used to define which warp to use when\
1249
+ transforming to midway space.
1250
+ from_: used to define which space the input image is when using the\
1251
+ -warp_mid option. Use -from 1 to warp from image1 or -from 2 to warp\
1252
+ from image2.
1253
+ modulate: Valid choices are: fod and jac.\
1254
+ fod: modulate FODs during reorientation to preserve the apparent\
1255
+ fibre density across fibre bundle widths before and after the\
1256
+ transformation.\
1257
+ jac: modulate the image intensity with the determinant of the\
1258
+ Jacobian of the warp of linear transformation to preserve the total\
1259
+ intensity before and after the transformation.
1260
+ directions: directions defining the number and orientation of the\
1261
+ apodised point spread functions used in FOD reorientation (Default: 300\
1262
+ directions).
1263
+ reorient_fod: specify whether to perform FOD reorientation. This is\
1264
+ required if the number of volumes in the 4th dimension corresponds to\
1265
+ the number of coefficients in an antipodally symmetric spherical\
1266
+ harmonic series with lmax >= 2 (i.e. 6, 15, 28, 45, 66 volumes).
1267
+ grad: Provide the diffusion-weighted gradient scheme used in the\
1268
+ acquisition in a text file. This should be supplied as a 4xN text file\
1269
+ with each line is in the format [ X Y Z b ], where [ X Y Z ] describe\
1270
+ the direction of the applied gradient, and b gives the b-value in units\
1271
+ of s/mm^2. If a diffusion gradient scheme is present in the input image\
1272
+ header, the data provided with this option will be instead used.
1273
+ fslgrad: Provide the diffusion-weighted gradient scheme used in the\
1274
+ acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
1275
+ scheme is present in the input image header, the data provided with\
1276
+ this option will be instead used.
1277
+ export_grad_mrtrix: export the diffusion-weighted gradient table to\
1278
+ file in MRtrix format.
1279
+ export_grad_fsl: export the diffusion-weighted gradient table to files\
1280
+ in FSL (bvecs / bvals) format.
1281
+ datatype: specify output image data type. Valid choices are: float32,\
1282
+ float32le, float32be, float64, float64le, float64be, int64, uint64,\
1283
+ int64le, uint64le, int64be, uint64be, int32, uint32, int32le, uint32le,\
1284
+ int32be, uint32be, int16, uint16, int16le, uint16le, int16be, uint16be,\
1285
+ cfloat32, cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be,\
1286
+ int8, uint8, bit.
1287
+ strides: specify the strides of the output data in memory; either as a\
1288
+ comma-separated list of (signed) integers, or as a template image from\
1289
+ which the strides shall be extracted and used. The actual strides\
1290
+ produced will depend on whether the output image format can support it.
1291
+ nan: Use NaN as the out of bounds value (Default: 0.0).
1292
+ no_reorientation: deprecated, use -reorient_fod instead.
1293
+ info: display information messages.
1294
+ quiet: do not display information messages or progress status;\
1295
+ alternatively, this can be achieved by setting the MRTRIX_QUIET\
1296
+ environment variable to a non-empty string.
1297
+ debug: display debugging messages.
1298
+ force: force overwrite of output files (caution: using the same file as\
1299
+ input and output might cause unexpected behaviour).
1300
+ nthreads: use this number of threads in multi-threaded applications\
1301
+ (set to 0 to disable multi-threading).
1302
+ config: temporarily set the value of an MRtrix config file entry.
1303
+ help_: display this information page and exit.
1304
+ version: display version information and exit.
1305
+ runner: Command runner.
1306
+ Returns:
1307
+ NamedTuple of outputs (described in `MrtransformOutputs`).
1308
+ """
1309
+ params = mrtransform_params(
1310
+ linear=linear,
1311
+ flip=flip,
1312
+ inverse=inverse,
1313
+ half=half,
1314
+ replace=replace,
1315
+ identity=identity,
1316
+ template=template,
1317
+ midway_space=midway_space,
1318
+ interp=interp,
1319
+ oversample=oversample,
1320
+ warp=warp,
1321
+ warp_full=warp_full,
1322
+ from_=from_,
1323
+ modulate=modulate,
1324
+ directions=directions,
1325
+ reorient_fod=reorient_fod,
1326
+ grad=grad,
1327
+ fslgrad=fslgrad,
1328
+ export_grad_mrtrix=export_grad_mrtrix,
1329
+ export_grad_fsl=export_grad_fsl,
1330
+ datatype=datatype,
1331
+ strides=strides,
1332
+ nan=nan,
1333
+ no_reorientation=no_reorientation,
1334
+ info=info,
1335
+ quiet=quiet,
1336
+ debug=debug,
1337
+ force=force,
1338
+ nthreads=nthreads,
1339
+ config=config,
1340
+ help_=help_,
1341
+ version=version,
1342
+ input_=input_,
1343
+ output=output,
1344
+ )
1345
+ return mrtransform_execute(params, runner)
1346
+
1347
+
1348
+ __all__ = [
1349
+ "MRTRANSFORM_METADATA",
1350
+ "MrtransformConfigParamsDict",
1351
+ "MrtransformConfigParamsDictTagged",
1352
+ "MrtransformExportGradFslOutputs",
1353
+ "MrtransformExportGradFslParamsDict",
1354
+ "MrtransformExportGradFslParamsDictTagged",
1355
+ "MrtransformFslgradParamsDict",
1356
+ "MrtransformFslgradParamsDictTagged",
1357
+ "MrtransformOutputs",
1358
+ "MrtransformParamsDict",
1359
+ "MrtransformParamsDictTagged",
1360
+ "MrtransformVariousFileParamsDict",
1361
+ "MrtransformVariousFileParamsDictTagged",
1362
+ "MrtransformVariousStringParamsDict",
1363
+ "MrtransformVariousStringParamsDictTagged",
1364
+ "mrtransform",
1365
+ "mrtransform_config",
1366
+ "mrtransform_execute",
1367
+ "mrtransform_export_grad_fsl",
1368
+ "mrtransform_fslgrad",
1369
+ "mrtransform_params",
1370
+ "mrtransform_various_file",
1371
+ "mrtransform_various_string",
1372
+ ]