rapidtide 3.0.11__py3-none-any.whl → 3.1.1__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.
- rapidtide/Colortables.py +492 -27
- rapidtide/OrthoImageItem.py +1049 -46
- rapidtide/RapidtideDataset.py +1533 -86
- rapidtide/_version.py +3 -3
- rapidtide/calccoherence.py +196 -29
- rapidtide/calcnullsimfunc.py +188 -40
- rapidtide/calcsimfunc.py +242 -42
- rapidtide/correlate.py +1203 -383
- rapidtide/data/examples/src/testLD +56 -0
- rapidtide/data/examples/src/testalign +1 -1
- rapidtide/data/examples/src/testdelayvar +0 -1
- rapidtide/data/examples/src/testfmri +53 -3
- rapidtide/data/examples/src/testglmfilt +5 -5
- rapidtide/data/examples/src/testhappy +29 -7
- rapidtide/data/examples/src/testppgproc +17 -0
- rapidtide/data/examples/src/testrolloff +11 -0
- rapidtide/data/models/model_cnn_pytorch/best_model.pth +0 -0
- rapidtide/data/models/model_cnn_pytorch/loss.png +0 -0
- rapidtide/data/models/model_cnn_pytorch/loss.txt +1 -0
- rapidtide/data/models/model_cnn_pytorch/model.pth +0 -0
- rapidtide/data/models/model_cnn_pytorch/model_meta.json +68 -0
- rapidtide/decorators.py +91 -0
- rapidtide/dlfilter.py +2226 -110
- rapidtide/dlfiltertorch.py +4842 -0
- rapidtide/externaltools.py +327 -12
- rapidtide/fMRIData_class.py +79 -40
- rapidtide/filter.py +1899 -810
- rapidtide/fit.py +2011 -581
- rapidtide/genericmultiproc.py +93 -18
- rapidtide/happy_supportfuncs.py +2047 -172
- rapidtide/helper_classes.py +584 -43
- rapidtide/io.py +2370 -372
- rapidtide/linfitfiltpass.py +346 -99
- rapidtide/makelaggedtcs.py +210 -24
- rapidtide/maskutil.py +448 -62
- rapidtide/miscmath.py +827 -121
- rapidtide/multiproc.py +210 -22
- rapidtide/patchmatch.py +242 -42
- rapidtide/peakeval.py +31 -31
- rapidtide/ppgproc.py +2203 -0
- rapidtide/qualitycheck.py +352 -39
- rapidtide/refinedelay.py +431 -57
- rapidtide/refineregressor.py +494 -189
- rapidtide/resample.py +671 -185
- rapidtide/scripts/applyppgproc.py +28 -0
- rapidtide/scripts/showxcorr_legacy.py +7 -7
- rapidtide/scripts/stupidramtricks.py +15 -17
- rapidtide/simFuncClasses.py +1052 -77
- rapidtide/simfuncfit.py +269 -69
- rapidtide/stats.py +540 -238
- rapidtide/tests/happycomp +9 -0
- rapidtide/tests/test_cleanregressor.py +1 -2
- rapidtide/tests/test_dlfiltertorch.py +627 -0
- rapidtide/tests/test_findmaxlag.py +24 -8
- rapidtide/tests/test_fullrunhappy_v1.py +0 -2
- rapidtide/tests/test_fullrunhappy_v2.py +0 -2
- rapidtide/tests/test_fullrunhappy_v3.py +11 -4
- rapidtide/tests/test_fullrunhappy_v4.py +10 -2
- rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
- rapidtide/tests/test_getparsers.py +11 -3
- rapidtide/tests/test_refinedelay.py +0 -1
- rapidtide/tests/test_simroundtrip.py +16 -8
- rapidtide/tests/test_stcorrelate.py +3 -1
- rapidtide/tests/utils.py +9 -8
- rapidtide/tidepoolTemplate.py +142 -38
- rapidtide/tidepoolTemplate_alt.py +165 -44
- rapidtide/tidepoolTemplate_big.py +189 -52
- rapidtide/util.py +1217 -118
- rapidtide/voxelData.py +684 -37
- rapidtide/wiener.py +136 -23
- rapidtide/wiener2.py +113 -7
- rapidtide/workflows/adjustoffset.py +105 -3
- rapidtide/workflows/aligntcs.py +85 -2
- rapidtide/workflows/applydlfilter.py +87 -10
- rapidtide/workflows/applyppgproc.py +540 -0
- rapidtide/workflows/atlasaverage.py +210 -47
- rapidtide/workflows/atlastool.py +100 -3
- rapidtide/workflows/calcSimFuncMap.py +288 -69
- rapidtide/workflows/calctexticc.py +201 -9
- rapidtide/workflows/ccorrica.py +101 -6
- rapidtide/workflows/cleanregressor.py +165 -31
- rapidtide/workflows/delayvar.py +171 -23
- rapidtide/workflows/diffrois.py +81 -3
- rapidtide/workflows/endtidalproc.py +144 -4
- rapidtide/workflows/fdica.py +195 -15
- rapidtide/workflows/filtnifti.py +70 -3
- rapidtide/workflows/filttc.py +74 -3
- rapidtide/workflows/fitSimFuncMap.py +202 -51
- rapidtide/workflows/fixtr.py +73 -3
- rapidtide/workflows/gmscalc.py +113 -3
- rapidtide/workflows/happy.py +801 -199
- rapidtide/workflows/happy2std.py +144 -12
- rapidtide/workflows/happy_parser.py +163 -23
- rapidtide/workflows/histnifti.py +118 -2
- rapidtide/workflows/histtc.py +84 -3
- rapidtide/workflows/linfitfilt.py +117 -4
- rapidtide/workflows/localflow.py +328 -28
- rapidtide/workflows/mergequality.py +79 -3
- rapidtide/workflows/niftidecomp.py +322 -18
- rapidtide/workflows/niftistats.py +174 -4
- rapidtide/workflows/pairproc.py +98 -4
- rapidtide/workflows/pairwisemergenifti.py +85 -2
- rapidtide/workflows/parser_funcs.py +1421 -40
- rapidtide/workflows/physiofreq.py +137 -11
- rapidtide/workflows/pixelcomp.py +207 -5
- rapidtide/workflows/plethquality.py +103 -21
- rapidtide/workflows/polyfitim.py +151 -11
- rapidtide/workflows/proj2flow.py +75 -2
- rapidtide/workflows/rankimage.py +111 -4
- rapidtide/workflows/rapidtide.py +368 -76
- rapidtide/workflows/rapidtide2std.py +98 -2
- rapidtide/workflows/rapidtide_parser.py +109 -9
- rapidtide/workflows/refineDelayMap.py +144 -33
- rapidtide/workflows/refineRegressor.py +675 -96
- rapidtide/workflows/regressfrommaps.py +161 -37
- rapidtide/workflows/resamplenifti.py +85 -3
- rapidtide/workflows/resampletc.py +91 -3
- rapidtide/workflows/retrolagtcs.py +99 -9
- rapidtide/workflows/retroregress.py +176 -26
- rapidtide/workflows/roisummarize.py +174 -5
- rapidtide/workflows/runqualitycheck.py +71 -3
- rapidtide/workflows/showarbcorr.py +149 -6
- rapidtide/workflows/showhist.py +86 -2
- rapidtide/workflows/showstxcorr.py +160 -3
- rapidtide/workflows/showtc.py +159 -3
- rapidtide/workflows/showxcorrx.py +190 -10
- rapidtide/workflows/showxy.py +185 -15
- rapidtide/workflows/simdata.py +264 -38
- rapidtide/workflows/spatialfit.py +77 -2
- rapidtide/workflows/spatialmi.py +250 -27
- rapidtide/workflows/spectrogram.py +305 -32
- rapidtide/workflows/synthASL.py +154 -3
- rapidtide/workflows/tcfrom2col.py +76 -2
- rapidtide/workflows/tcfrom3col.py +74 -2
- rapidtide/workflows/tidepool.py +2971 -130
- rapidtide/workflows/utils.py +19 -14
- rapidtide/workflows/utils_doc.py +293 -0
- rapidtide/workflows/variabilityizer.py +116 -3
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/METADATA +10 -8
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/RECORD +144 -128
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/entry_points.txt +1 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/WHEEL +0 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/top_level.txt +0 -0
rapidtide/workflows/polyfitim.py
CHANGED
|
@@ -18,17 +18,49 @@
|
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
20
|
import sys
|
|
21
|
+
from argparse import Namespace
|
|
22
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
21
23
|
|
|
22
24
|
import numpy as np
|
|
25
|
+
from numpy.typing import NDArray
|
|
23
26
|
|
|
24
27
|
import rapidtide.fit as tide_fit
|
|
25
28
|
import rapidtide.io as tide_io
|
|
26
29
|
from rapidtide.workflows.parser_funcs import is_valid_file
|
|
27
30
|
|
|
28
31
|
|
|
29
|
-
def _get_parser():
|
|
32
|
+
def _get_parser() -> Any:
|
|
30
33
|
"""
|
|
31
|
-
Argument parser for polyfitim
|
|
34
|
+
Argument parser for polyfitim.
|
|
35
|
+
|
|
36
|
+
This function constructs and returns an `argparse.ArgumentParser` object configured
|
|
37
|
+
to parse command-line arguments for the `polyfitim` tool. It is designed to handle
|
|
38
|
+
the fitting of a spatial template to 3D or 4D NIFTI files, with optional region-specific
|
|
39
|
+
fitting using an atlas file.
|
|
40
|
+
|
|
41
|
+
Returns
|
|
42
|
+
-------
|
|
43
|
+
argparse.ArgumentParser
|
|
44
|
+
Configured argument parser for `polyfitim` command-line interface.
|
|
45
|
+
|
|
46
|
+
Notes
|
|
47
|
+
-----
|
|
48
|
+
The parser expects several required NIFTI files:
|
|
49
|
+
- Data file (`datafile`)
|
|
50
|
+
- Data mask file (`datamask`)
|
|
51
|
+
- Template file (`templatefile`)
|
|
52
|
+
- Template mask file (`templatemask`)
|
|
53
|
+
|
|
54
|
+
Optional arguments include:
|
|
55
|
+
- `--regionatlas`: File containing a 3D NIFTI atlas for region-specific fitting.
|
|
56
|
+
- `--order`: Polynomial order for the fit (default is 1).
|
|
57
|
+
|
|
58
|
+
Examples
|
|
59
|
+
--------
|
|
60
|
+
>>> parser = _get_parser()
|
|
61
|
+
>>> args = parser.parse_args(['data.nii', 'mask.nii', 'template.nii', 'template_mask.nii', 'output'])
|
|
62
|
+
>>> print(args.datafile)
|
|
63
|
+
'data.nii'
|
|
32
64
|
"""
|
|
33
65
|
parser = argparse.ArgumentParser(
|
|
34
66
|
prog="polyfitim",
|
|
@@ -78,14 +110,69 @@ def _get_parser():
|
|
|
78
110
|
|
|
79
111
|
|
|
80
112
|
def polyfitim(
|
|
81
|
-
datafile,
|
|
82
|
-
datamask,
|
|
83
|
-
templatefile,
|
|
84
|
-
templatemask,
|
|
85
|
-
outputroot,
|
|
86
|
-
regionatlas=None,
|
|
87
|
-
order=1,
|
|
88
|
-
):
|
|
113
|
+
datafile: Any,
|
|
114
|
+
datamask: Any,
|
|
115
|
+
templatefile: Any,
|
|
116
|
+
templatemask: Any,
|
|
117
|
+
outputroot: Any,
|
|
118
|
+
regionatlas: Optional[Any] = None,
|
|
119
|
+
order: int = 1,
|
|
120
|
+
) -> None:
|
|
121
|
+
"""
|
|
122
|
+
Fit polynomial models to time series data within regions defined by masks.
|
|
123
|
+
|
|
124
|
+
This function performs polynomial fitting of specified order to time series data
|
|
125
|
+
within spatial regions defined by a template mask. It supports both global and
|
|
126
|
+
region-specific fitting, and outputs fitted time series, polynomial coefficients,
|
|
127
|
+
and R² values.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
datafile : Any
|
|
132
|
+
Path to the input NIfTI file containing the time series data.
|
|
133
|
+
datamask : Any
|
|
134
|
+
Path to the NIfTI file containing the data mask. Can be 3D or 4D.
|
|
135
|
+
templatefile : Any
|
|
136
|
+
Path to the NIfTI file containing the template (e.g., a regressor) for fitting.
|
|
137
|
+
templatemask : Any
|
|
138
|
+
Path to the NIfTI file containing the mask for the template.
|
|
139
|
+
outputroot : Any
|
|
140
|
+
Root name for output files (e.g., 'output' will produce 'output_fit.nii.gz').
|
|
141
|
+
regionatlas : Any, optional
|
|
142
|
+
Path to the NIfTI file containing region labels. If provided, fitting is
|
|
143
|
+
performed separately for each region. Default is None.
|
|
144
|
+
order : int, optional
|
|
145
|
+
Order of the polynomial to fit. Must be >= 1. Default is 1 (linear fit).
|
|
146
|
+
|
|
147
|
+
Returns
|
|
148
|
+
-------
|
|
149
|
+
None
|
|
150
|
+
Function writes multiple output files:
|
|
151
|
+
- Fitted time series (NIfTI format)
|
|
152
|
+
- Residuals (NIfTI format)
|
|
153
|
+
- R² values (text file)
|
|
154
|
+
- Polynomial coefficients (text files)
|
|
155
|
+
|
|
156
|
+
Notes
|
|
157
|
+
-----
|
|
158
|
+
- The function assumes that all input files are in NIfTI format.
|
|
159
|
+
- If `datamask` is 4D, it is treated as a time-varying mask.
|
|
160
|
+
- If `regionatlas` is provided, fitting is performed separately for each region.
|
|
161
|
+
- The function uses `tide_io` for reading/writing NIfTI files and `tide_fit.mlregress`
|
|
162
|
+
for polynomial regression.
|
|
163
|
+
|
|
164
|
+
Examples
|
|
165
|
+
--------
|
|
166
|
+
>>> polyfitim(
|
|
167
|
+
... datafile='data.nii.gz',
|
|
168
|
+
... datamask='mask.nii.gz',
|
|
169
|
+
... templatefile='template.nii.gz',
|
|
170
|
+
... templatemask='template_mask.nii.gz',
|
|
171
|
+
... outputroot='output',
|
|
172
|
+
... regionatlas='atlas.nii.gz',
|
|
173
|
+
... order=2
|
|
174
|
+
... )
|
|
175
|
+
"""
|
|
89
176
|
# check the order
|
|
90
177
|
if order < 1:
|
|
91
178
|
print("order must be >= 1")
|
|
@@ -279,7 +366,60 @@ def polyfitim(
|
|
|
279
366
|
)
|
|
280
367
|
|
|
281
368
|
|
|
282
|
-
def main(args):
|
|
369
|
+
def main(args: Any) -> None:
|
|
370
|
+
"""
|
|
371
|
+
Main function to perform polynomial fitting on imaging data.
|
|
372
|
+
|
|
373
|
+
This function serves as the entry point for polynomial fitting operations
|
|
374
|
+
on medical imaging data using template-based registration and fitting.
|
|
375
|
+
|
|
376
|
+
Parameters
|
|
377
|
+
----------
|
|
378
|
+
args : Any
|
|
379
|
+
Namespace object containing all required arguments for the polynomial fitting
|
|
380
|
+
operation. Expected attributes include:
|
|
381
|
+
|
|
382
|
+
- datafile : str
|
|
383
|
+
Path to the input data file to be fitted
|
|
384
|
+
- datamask : str
|
|
385
|
+
Path to the data mask file for region of interest specification
|
|
386
|
+
- templatefile : str
|
|
387
|
+
Path to the template file for reference
|
|
388
|
+
- templatemask : str
|
|
389
|
+
Path to the template mask file for reference region specification
|
|
390
|
+
- outputroot : str
|
|
391
|
+
Root path for output files
|
|
392
|
+
- regionatlas : str, optional
|
|
393
|
+
Path to region atlas file for anatomical labeling
|
|
394
|
+
- order : int, optional
|
|
395
|
+
Order of the polynomial to fit (default is typically 1)
|
|
396
|
+
|
|
397
|
+
Returns
|
|
398
|
+
-------
|
|
399
|
+
None
|
|
400
|
+
This function does not return any value. It performs the polynomial fitting
|
|
401
|
+
operation and saves results to the specified output directory.
|
|
402
|
+
|
|
403
|
+
Notes
|
|
404
|
+
-----
|
|
405
|
+
The function internally calls `polyfitim` with the provided arguments to
|
|
406
|
+
perform the actual polynomial fitting computation. All input files must be
|
|
407
|
+
properly formatted and accessible.
|
|
408
|
+
|
|
409
|
+
Examples
|
|
410
|
+
--------
|
|
411
|
+
>>> import argparse
|
|
412
|
+
>>> args = argparse.Namespace(
|
|
413
|
+
... datafile='data.nii.gz',
|
|
414
|
+
... datamask='data_mask.nii.gz',
|
|
415
|
+
... templatefile='template.nii.gz',
|
|
416
|
+
... templatemask='template_mask.nii.gz',
|
|
417
|
+
... outputroot='output',
|
|
418
|
+
... regionatlas='atlas.nii.gz',
|
|
419
|
+
... order=2
|
|
420
|
+
... )
|
|
421
|
+
>>> main(args)
|
|
422
|
+
"""
|
|
283
423
|
polyfitim(
|
|
284
424
|
args.datafile,
|
|
285
425
|
args.datamask,
|
rapidtide/workflows/proj2flow.py
CHANGED
|
@@ -18,14 +18,44 @@
|
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
20
|
import copy
|
|
21
|
+
from argparse import Namespace
|
|
22
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
21
23
|
|
|
22
24
|
import numpy as np
|
|
25
|
+
from numpy.typing import NDArray
|
|
23
26
|
|
|
24
27
|
import rapidtide.filter as tide_filt
|
|
25
28
|
import rapidtide.io as tide_io
|
|
26
29
|
|
|
27
30
|
|
|
28
|
-
def _get_parser():
|
|
31
|
+
def _get_parser() -> Any:
|
|
32
|
+
"""
|
|
33
|
+
Create and configure argument parser for phase projection to velocity map conversion.
|
|
34
|
+
|
|
35
|
+
This function sets up the command line argument parser for the proj2flow tool,
|
|
36
|
+
which converts phase projection movies to velocity maps. It defines required
|
|
37
|
+
positional arguments for input and output files, as well as optional debugging
|
|
38
|
+
flag.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
argparse.ArgumentParser
|
|
43
|
+
Configured argument parser object with defined command line arguments
|
|
44
|
+
|
|
45
|
+
Notes
|
|
46
|
+
-----
|
|
47
|
+
The function currently has commented-out frequency filter arguments (lowestfreq
|
|
48
|
+
and highestfreq) that can be enabled if needed for specific use cases.
|
|
49
|
+
|
|
50
|
+
Examples
|
|
51
|
+
--------
|
|
52
|
+
>>> parser = _get_parser()
|
|
53
|
+
>>> args = parser.parse_args(['input.nii', 'output_root'])
|
|
54
|
+
>>> print(args.inputfilename)
|
|
55
|
+
'input.nii'
|
|
56
|
+
>>> print(args.outputroot)
|
|
57
|
+
'output_root'
|
|
58
|
+
"""
|
|
29
59
|
# get the command line parameters
|
|
30
60
|
parser = argparse.ArgumentParser(
|
|
31
61
|
prog="proj2flow",
|
|
@@ -57,7 +87,50 @@ def _get_parser():
|
|
|
57
87
|
return parser
|
|
58
88
|
|
|
59
89
|
|
|
60
|
-
def proj2flow(args):
|
|
90
|
+
def proj2flow(args: Any) -> None:
|
|
91
|
+
"""
|
|
92
|
+
Compute 3D velocity fields from projected 4D fMRI data using forward and backward differences.
|
|
93
|
+
|
|
94
|
+
This function reads 4D NIfTI fMRI data, computes velocity fields at each timepoint by
|
|
95
|
+
calculating forward and backward differences in spatial and temporal dimensions, and
|
|
96
|
+
saves the resulting velocity fields as 3D NIfTI files. It also saves an average velocity
|
|
97
|
+
field across all timepoints.
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
args : argparse.Namespace
|
|
102
|
+
Command-line arguments parsed by `_get_parser()`. Expected attributes include:
|
|
103
|
+
- `inputfilename` : str
|
|
104
|
+
Path to the input NIfTI file containing 4D fMRI data.
|
|
105
|
+
- `outputroot` : str
|
|
106
|
+
Root name for output NIfTI files.
|
|
107
|
+
- `debug` : bool, optional
|
|
108
|
+
If True, enables debug printing and additional checks.
|
|
109
|
+
|
|
110
|
+
Returns
|
|
111
|
+
-------
|
|
112
|
+
None
|
|
113
|
+
This function does not return a value. It writes NIfTI files to disk.
|
|
114
|
+
|
|
115
|
+
Notes
|
|
116
|
+
-----
|
|
117
|
+
- The function assumes the input data is in the same spatial and temporal dimensions
|
|
118
|
+
as specified by the NIfTI header.
|
|
119
|
+
- Forward and backward differences are computed using a 3x3x3 neighborhood in space
|
|
120
|
+
and a single timepoint difference.
|
|
121
|
+
- Velocity fields are saved with intent code 2003 (indicating a vector field).
|
|
122
|
+
- The output files are named using the format:
|
|
123
|
+
- `{outputroot}_{timepoint:02d}.nii.gz` for each timepoint
|
|
124
|
+
- `{outputroot}_average.nii.gz` for the average velocity field
|
|
125
|
+
|
|
126
|
+
Examples
|
|
127
|
+
--------
|
|
128
|
+
>>> import argparse
|
|
129
|
+
>>> args = argparse.Namespace(inputfilename='fmri_data.nii.gz',
|
|
130
|
+
... outputroot='velocity',
|
|
131
|
+
... debug=False)
|
|
132
|
+
>>> proj2flow(args)
|
|
133
|
+
"""
|
|
61
134
|
# set default variable values
|
|
62
135
|
displayplots = False
|
|
63
136
|
|
rapidtide/workflows/rankimage.py
CHANGED
|
@@ -17,16 +17,41 @@
|
|
|
17
17
|
#
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
|
+
from argparse import Namespace
|
|
21
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
20
22
|
|
|
21
23
|
import numpy as np
|
|
24
|
+
from numpy.typing import NDArray
|
|
22
25
|
from scipy.stats import rankdata
|
|
23
26
|
|
|
24
27
|
import rapidtide.io as tide_io
|
|
25
28
|
|
|
26
29
|
|
|
27
|
-
def _get_parser():
|
|
30
|
+
def _get_parser() -> Any:
|
|
28
31
|
"""
|
|
29
|
-
Argument parser for
|
|
32
|
+
Argument parser for rankimage.
|
|
33
|
+
|
|
34
|
+
Creates and configures an argument parser for the rankimage tool that converts
|
|
35
|
+
3D or 4D nifti images into percentile maps.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
argparse.ArgumentParser
|
|
40
|
+
Configured argument parser object with all required and optional arguments
|
|
41
|
+
for the rankimage tool.
|
|
42
|
+
|
|
43
|
+
Notes
|
|
44
|
+
-----
|
|
45
|
+
The parser is configured with:
|
|
46
|
+
- Required arguments: inputfilename, maskfilename, outputroot
|
|
47
|
+
- Optional argument: --debug flag for additional debugging information
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
--------
|
|
51
|
+
>>> parser = _get_parser()
|
|
52
|
+
>>> args = parser.parse_args(['input.nii', 'mask.nii', 'output_root'])
|
|
53
|
+
>>> print(args.inputfilename)
|
|
54
|
+
'input.nii'
|
|
30
55
|
"""
|
|
31
56
|
parser = argparse.ArgumentParser(
|
|
32
57
|
prog="rankimage",
|
|
@@ -50,7 +75,44 @@ def _get_parser():
|
|
|
50
75
|
return parser
|
|
51
76
|
|
|
52
77
|
|
|
53
|
-
def imtopercentile(image, mask, debug=False):
|
|
78
|
+
def imtopercentile(image: Any, mask: Any, debug: bool = False) -> None:
|
|
79
|
+
"""
|
|
80
|
+
Convert image values to percentile scores within masked region.
|
|
81
|
+
|
|
82
|
+
This function computes percentile rankings for all voxels within a specified
|
|
83
|
+
mask region of a 3D image. The percentile scores are calculated using the
|
|
84
|
+
'dense' ranking method, where tied values receive the same rank.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
image : array-like
|
|
89
|
+
Input 3D image data array
|
|
90
|
+
mask : array-like
|
|
91
|
+
Binary mask defining the region of interest (values > 0 are considered valid)
|
|
92
|
+
debug : bool, optional
|
|
93
|
+
If True, print debugging information about processing (default is False)
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
NDArray
|
|
98
|
+
Array of same shape as input image containing percentile scores for
|
|
99
|
+
valid voxels, with zeros for masked-out voxels
|
|
100
|
+
|
|
101
|
+
Notes
|
|
102
|
+
-----
|
|
103
|
+
- Only voxels where mask > 0 are processed
|
|
104
|
+
- Percentile calculation uses 'dense' ranking method
|
|
105
|
+
- The percentile score ranges from 0 to 100
|
|
106
|
+
- Invalid voxels (where mask <= 0) are set to 0 in output
|
|
107
|
+
|
|
108
|
+
Examples
|
|
109
|
+
--------
|
|
110
|
+
>>> import numpy as np
|
|
111
|
+
>>> image = np.random.rand(10, 10, 10)
|
|
112
|
+
>>> mask = np.ones((10, 10, 10))
|
|
113
|
+
>>> mask[0:5, :, :] = 0 # Mask out first 5 slices
|
|
114
|
+
>>> result = imtopercentile(image, mask)
|
|
115
|
+
"""
|
|
54
116
|
outmaparray = image * 0.0
|
|
55
117
|
nativespaceshape = image.shape
|
|
56
118
|
validvoxels = np.where(mask > 0)
|
|
@@ -69,7 +131,52 @@ def imtopercentile(image, mask, debug=False):
|
|
|
69
131
|
return outmaparray.reshape(nativespaceshape)
|
|
70
132
|
|
|
71
133
|
|
|
72
|
-
def rankimage(args):
|
|
134
|
+
def rankimage(args: Any) -> None:
|
|
135
|
+
"""
|
|
136
|
+
Convert input NIfTI image data to percentile-ranked values using a mask.
|
|
137
|
+
|
|
138
|
+
This function reads an input NIfTI image and a corresponding mask, checks
|
|
139
|
+
that their spatial dimensions match, and computes percentile-ranked values
|
|
140
|
+
for each voxel within the mask. The result is saved as a new NIfTI file with
|
|
141
|
+
associated BIDS metadata.
|
|
142
|
+
|
|
143
|
+
Parameters
|
|
144
|
+
----------
|
|
145
|
+
args : Any
|
|
146
|
+
An object containing the following attributes:
|
|
147
|
+
- inputfilename : str
|
|
148
|
+
Path to the input NIfTI image file.
|
|
149
|
+
- maskfilename : str
|
|
150
|
+
Path to the mask NIfTI file.
|
|
151
|
+
- outputroot : str
|
|
152
|
+
Root name for the output NIfTI file (without extension).
|
|
153
|
+
- debug : bool, optional
|
|
154
|
+
If True, enables debug output. Default is False.
|
|
155
|
+
|
|
156
|
+
Returns
|
|
157
|
+
-------
|
|
158
|
+
None
|
|
159
|
+
The function writes the percentile-ranked image to a NIfTI file and
|
|
160
|
+
a JSON metadata file, but does not return any value.
|
|
161
|
+
|
|
162
|
+
Notes
|
|
163
|
+
-----
|
|
164
|
+
- The function supports both 3D and 4D NIfTI files.
|
|
165
|
+
- For 4D files, the percentile ranking is computed separately for each
|
|
166
|
+
timepoint.
|
|
167
|
+
- The output file is saved with the extension `.nii.gz`.
|
|
168
|
+
- BIDS metadata is saved in a `.json` file with the same root name.
|
|
169
|
+
|
|
170
|
+
Examples
|
|
171
|
+
--------
|
|
172
|
+
>>> class Args:
|
|
173
|
+
... inputfilename = "input.nii.gz"
|
|
174
|
+
... maskfilename = "mask.nii.gz"
|
|
175
|
+
... outputroot = "output"
|
|
176
|
+
... debug = False
|
|
177
|
+
>>> args = Args()
|
|
178
|
+
>>> rankimage(args)
|
|
179
|
+
"""
|
|
73
180
|
input_img, input_data, input_hdr, thedims, thesizes = tide_io.readfromnifti(args.inputfilename)
|
|
74
181
|
(
|
|
75
182
|
mask_img,
|