rapidtide 3.0.11__py3-none-any.whl → 3.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 +191 -40
- rapidtide/calcsimfunc.py +245 -42
- rapidtide/correlate.py +1210 -393
- 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 +19 -1
- rapidtide/data/examples/src/testglmfilt +5 -5
- rapidtide/data/examples/src/testhappy +25 -3
- 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 +2225 -108
- rapidtide/dlfiltertorch.py +4843 -0
- rapidtide/externaltools.py +327 -12
- rapidtide/fMRIData_class.py +79 -40
- rapidtide/filter.py +1899 -810
- rapidtide/fit.py +2004 -574
- rapidtide/genericmultiproc.py +93 -18
- rapidtide/happy_supportfuncs.py +2044 -171
- rapidtide/helper_classes.py +584 -43
- rapidtide/io.py +2363 -370
- rapidtide/linfitfiltpass.py +341 -75
- rapidtide/makelaggedtcs.py +211 -20
- rapidtide/maskutil.py +423 -53
- rapidtide/miscmath.py +827 -121
- rapidtide/multiproc.py +210 -22
- rapidtide/patchmatch.py +234 -33
- rapidtide/peakeval.py +32 -30
- rapidtide/ppgproc.py +2203 -0
- rapidtide/qualitycheck.py +352 -39
- rapidtide/refinedelay.py +422 -57
- rapidtide/refineregressor.py +498 -184
- rapidtide/resample.py +671 -185
- rapidtide/scripts/applyppgproc.py +28 -0
- rapidtide/simFuncClasses.py +1052 -77
- rapidtide/simfuncfit.py +260 -46
- rapidtide/stats.py +540 -238
- rapidtide/tests/happycomp +9 -0
- 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 +1 -0
- rapidtide/tests/test_fullrunhappy_v4.py +2 -2
- rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
- rapidtide/tests/test_simroundtrip.py +8 -8
- 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 +19 -12
- rapidtide/wiener2.py +113 -7
- rapidtide/wiener_doc.py +255 -0
- rapidtide/workflows/adjustoffset.py +105 -3
- rapidtide/workflows/aligntcs.py +85 -2
- rapidtide/workflows/applydlfilter.py +87 -10
- rapidtide/workflows/applyppgproc.py +522 -0
- rapidtide/workflows/atlasaverage.py +210 -47
- rapidtide/workflows/atlastool.py +100 -3
- rapidtide/workflows/calcSimFuncMap.py +294 -64
- rapidtide/workflows/calctexticc.py +201 -9
- rapidtide/workflows/ccorrica.py +97 -4
- rapidtide/workflows/cleanregressor.py +168 -29
- rapidtide/workflows/delayvar.py +163 -10
- 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 +206 -48
- 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 +138 -9
- 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 +88 -2
- rapidtide/workflows/pairwisemergenifti.py +85 -2
- rapidtide/workflows/parser_funcs.py +1421 -40
- rapidtide/workflows/physiofreq.py +137 -11
- rapidtide/workflows/pixelcomp.py +208 -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 +272 -15
- rapidtide/workflows/rapidtide2std.py +98 -2
- rapidtide/workflows/rapidtide_parser.py +109 -9
- rapidtide/workflows/refineDelayMap.py +143 -33
- rapidtide/workflows/refineRegressor.py +682 -93
- rapidtide/workflows/regressfrommaps.py +152 -31
- rapidtide/workflows/resamplenifti.py +85 -3
- rapidtide/workflows/resampletc.py +91 -3
- rapidtide/workflows/retrolagtcs.py +98 -6
- rapidtide/workflows/retroregress.py +165 -9
- rapidtide/workflows/roisummarize.py +173 -5
- rapidtide/workflows/runqualitycheck.py +71 -3
- rapidtide/workflows/showarbcorr.py +147 -4
- rapidtide/workflows/showhist.py +86 -2
- rapidtide/workflows/showstxcorr.py +160 -3
- rapidtide/workflows/showtc.py +159 -3
- rapidtide/workflows/showxcorrx.py +184 -4
- rapidtide/workflows/showxy.py +185 -15
- rapidtide/workflows/simdata.py +262 -36
- rapidtide/workflows/spatialfit.py +77 -2
- rapidtide/workflows/spatialmi.py +251 -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 +2969 -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.dist-info}/METADATA +3 -2
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/RECORD +139 -122
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/entry_points.txt +1 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/WHEEL +0 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/top_level.txt +0 -0
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
#
|
|
18
18
|
#
|
|
19
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
20
|
+
|
|
19
21
|
import numpy as np
|
|
22
|
+
from numpy.typing import NDArray
|
|
20
23
|
from scipy import ndimage
|
|
21
24
|
|
|
22
25
|
import rapidtide.io as tide_io
|
|
@@ -28,48 +31,197 @@ import rapidtide.util as tide_util
|
|
|
28
31
|
|
|
29
32
|
|
|
30
33
|
def fitSimFunc(
|
|
31
|
-
fmri_data_valid,
|
|
32
|
-
validsimcalcstart,
|
|
33
|
-
validsimcalcend,
|
|
34
|
-
osvalidsimcalcstart,
|
|
35
|
-
osvalidsimcalcend,
|
|
36
|
-
initial_fmri_x,
|
|
37
|
-
os_fmri_x,
|
|
38
|
-
theMutualInformationator,
|
|
39
|
-
cleaned_referencetc,
|
|
40
|
-
corrout,
|
|
41
|
-
outputname,
|
|
42
|
-
validvoxels,
|
|
43
|
-
nativespaceshape,
|
|
44
|
-
bidsbasedict,
|
|
45
|
-
numspatiallocs,
|
|
46
|
-
gaussout,
|
|
47
|
-
theinitialdelay,
|
|
48
|
-
windowout,
|
|
49
|
-
R2,
|
|
50
|
-
thesizes,
|
|
51
|
-
internalspaceshape,
|
|
52
|
-
numvalidspatiallocs,
|
|
53
|
-
theinputdata,
|
|
54
|
-
theheader,
|
|
55
|
-
theFitter,
|
|
56
|
-
fitmask,
|
|
57
|
-
lagtimes,
|
|
58
|
-
lagstrengths,
|
|
59
|
-
lagsigma,
|
|
60
|
-
failreason,
|
|
61
|
-
outmaparray,
|
|
62
|
-
trimmedcorrscale,
|
|
63
|
-
similaritytype,
|
|
64
|
-
thepass,
|
|
65
|
-
optiondict,
|
|
66
|
-
LGR,
|
|
67
|
-
TimingLGR,
|
|
68
|
-
simplefit=False,
|
|
69
|
-
upsampfac=8,
|
|
70
|
-
rt_floatset=np.float64,
|
|
71
|
-
rt_floattype="float64",
|
|
72
|
-
):
|
|
34
|
+
fmri_data_valid: NDArray[np.floating[Any]],
|
|
35
|
+
validsimcalcstart: int,
|
|
36
|
+
validsimcalcend: int,
|
|
37
|
+
osvalidsimcalcstart: int,
|
|
38
|
+
osvalidsimcalcend: int,
|
|
39
|
+
initial_fmri_x: NDArray[np.floating[Any]],
|
|
40
|
+
os_fmri_x: NDArray[np.floating[Any]],
|
|
41
|
+
theMutualInformationator: Any,
|
|
42
|
+
cleaned_referencetc: Any,
|
|
43
|
+
corrout: NDArray[np.floating[Any]],
|
|
44
|
+
outputname: str,
|
|
45
|
+
validvoxels: Any,
|
|
46
|
+
nativespaceshape: Any,
|
|
47
|
+
bidsbasedict: Any,
|
|
48
|
+
numspatiallocs: Any,
|
|
49
|
+
gaussout: Any,
|
|
50
|
+
theinitialdelay: Any,
|
|
51
|
+
windowout: Any,
|
|
52
|
+
R2: Any,
|
|
53
|
+
thesizes: Any,
|
|
54
|
+
internalspaceshape: Any,
|
|
55
|
+
numvalidspatiallocs: Any,
|
|
56
|
+
theinputdata: Any,
|
|
57
|
+
theheader: Any,
|
|
58
|
+
theFitter: Any,
|
|
59
|
+
fitmask: Any,
|
|
60
|
+
lagtimes: Any,
|
|
61
|
+
lagstrengths: Any,
|
|
62
|
+
lagsigma: Any,
|
|
63
|
+
failreason: Any,
|
|
64
|
+
outmaparray: Any,
|
|
65
|
+
trimmedcorrscale: Any,
|
|
66
|
+
similaritytype: Any,
|
|
67
|
+
thepass: Any,
|
|
68
|
+
optiondict: Any,
|
|
69
|
+
LGR: Any,
|
|
70
|
+
TimingLGR: Any,
|
|
71
|
+
simplefit: bool = False,
|
|
72
|
+
upsampfac: int = 8,
|
|
73
|
+
rt_floatset: Any = np.float64,
|
|
74
|
+
rt_floattype: str = "float64",
|
|
75
|
+
) -> NDArray | None:
|
|
76
|
+
"""
|
|
77
|
+
Perform similarity function fitting and time lag estimation for fMRI data.
|
|
78
|
+
|
|
79
|
+
This function conducts either a simple or full fitting process for estimating time lags
|
|
80
|
+
between fMRI signals and a reference time course. It supports hybrid similarity metrics
|
|
81
|
+
and includes optional despeckling and patch shifting steps.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
fmri_data_valid : NDArray[np.floating[Any]]
|
|
86
|
+
Valid fMRI data for processing.
|
|
87
|
+
validsimcalcstart : int
|
|
88
|
+
Start index for valid similarity calculation.
|
|
89
|
+
validsimcalcend : int
|
|
90
|
+
End index for valid similarity calculation.
|
|
91
|
+
osvalidsimcalcstart : int
|
|
92
|
+
Start index for oversampled valid similarity calculation.
|
|
93
|
+
osvalidsimcalcend : int
|
|
94
|
+
End index for oversampled valid similarity calculation.
|
|
95
|
+
initial_fmri_x : NDArray[np.floating[Any]]
|
|
96
|
+
Initial fMRI x values.
|
|
97
|
+
os_fmri_x : NDArray[np.floating[Any]]
|
|
98
|
+
Oversampled fMRI x values.
|
|
99
|
+
theMutualInformationator : object
|
|
100
|
+
Mutual information calculator.
|
|
101
|
+
cleaned_referencetc : array_like
|
|
102
|
+
Cleaned reference time course.
|
|
103
|
+
corrout : NDArray[np.floating[Any]]
|
|
104
|
+
Correlation output array.
|
|
105
|
+
outputname : str
|
|
106
|
+
Output filename prefix.
|
|
107
|
+
validvoxels : array_like
|
|
108
|
+
Indices of valid voxels.
|
|
109
|
+
nativespaceshape : tuple
|
|
110
|
+
Native space shape of the data.
|
|
111
|
+
bidsbasedict : dict
|
|
112
|
+
BIDS-based dictionary for output metadata.
|
|
113
|
+
numspatiallocs : int
|
|
114
|
+
Number of spatial locations.
|
|
115
|
+
gaussout : array_like
|
|
116
|
+
Gaussian output array.
|
|
117
|
+
theinitialdelay : float
|
|
118
|
+
Initial delay value.
|
|
119
|
+
windowout : array_like
|
|
120
|
+
Window output array.
|
|
121
|
+
R2 : array_like
|
|
122
|
+
R-squared values.
|
|
123
|
+
thesizes : array_like
|
|
124
|
+
Sizes for processing.
|
|
125
|
+
internalspaceshape : tuple
|
|
126
|
+
Internal space shape.
|
|
127
|
+
numvalidspatiallocs : int
|
|
128
|
+
Number of valid spatial locations.
|
|
129
|
+
theinputdata : object
|
|
130
|
+
Input data object.
|
|
131
|
+
theheader : dict
|
|
132
|
+
Header information.
|
|
133
|
+
theFitter : object
|
|
134
|
+
Fitter object for similarity function fitting.
|
|
135
|
+
fitmask : array_like
|
|
136
|
+
Mask for fitting.
|
|
137
|
+
lagtimes : array_like
|
|
138
|
+
Array to store estimated lag times.
|
|
139
|
+
lagstrengths : array_like
|
|
140
|
+
Array to store lag strengths.
|
|
141
|
+
lagsigma : array_like
|
|
142
|
+
Array to store sigma values for lags.
|
|
143
|
+
failreason : array_like
|
|
144
|
+
Array to store failure reasons.
|
|
145
|
+
outmaparray : array_like
|
|
146
|
+
Output map array.
|
|
147
|
+
trimmedcorrscale : array_like
|
|
148
|
+
Trimmed correlation scale.
|
|
149
|
+
similaritytype : str
|
|
150
|
+
Type of similarity metric used.
|
|
151
|
+
thepass : int
|
|
152
|
+
Current pass number.
|
|
153
|
+
optiondict : dict
|
|
154
|
+
Dictionary of options for processing.
|
|
155
|
+
LGR : object
|
|
156
|
+
Logger for general messages.
|
|
157
|
+
TimingLGR : object
|
|
158
|
+
Logger for timing information.
|
|
159
|
+
simplefit : bool, optional
|
|
160
|
+
If True, perform simple fitting using upsampling. Default is False.
|
|
161
|
+
upsampfac : int, optional
|
|
162
|
+
Upsampling factor for simple fitting. Default is 8.
|
|
163
|
+
rt_floatset : dtype, optional
|
|
164
|
+
Real-time floating-point data type. Default is np.float64.
|
|
165
|
+
rt_floattype : str, optional
|
|
166
|
+
Real-time floating-point type as string. Default is "float64".
|
|
167
|
+
|
|
168
|
+
Returns
|
|
169
|
+
-------
|
|
170
|
+
internaldespeckleincludemask : NDArray[np.floating[Any]] or None
|
|
171
|
+
Mask indicating which voxels were included in despeckling, or None if no despeckling was performed.
|
|
172
|
+
|
|
173
|
+
Notes
|
|
174
|
+
-----
|
|
175
|
+
- This function supports both simple and hybrid similarity metrics.
|
|
176
|
+
- Despeckling and patch shifting steps are optional and controlled by `optiondict`.
|
|
177
|
+
- The function modifies `lagtimes`, `lagstrengths`, `lagsigma`, and `fitmask` in-place.
|
|
178
|
+
|
|
179
|
+
Examples
|
|
180
|
+
--------
|
|
181
|
+
>>> fitSimFunc(
|
|
182
|
+
... fmri_data_valid,
|
|
183
|
+
... validsimcalcstart,
|
|
184
|
+
... validsimcalcend,
|
|
185
|
+
... osvalidsimcalcstart,
|
|
186
|
+
... osvalidsimcalcend,
|
|
187
|
+
... initial_fmri_x,
|
|
188
|
+
... os_fmri_x,
|
|
189
|
+
... theMutualInformationator,
|
|
190
|
+
... cleaned_referencetc,
|
|
191
|
+
... corrout,
|
|
192
|
+
... outputname,
|
|
193
|
+
... validvoxels,
|
|
194
|
+
... nativespaceshape,
|
|
195
|
+
... bidsbasedict,
|
|
196
|
+
... numspatiallocs,
|
|
197
|
+
... gaussout,
|
|
198
|
+
... theinitialdelay,
|
|
199
|
+
... windowout,
|
|
200
|
+
... R2,
|
|
201
|
+
... thesizes,
|
|
202
|
+
... internalspaceshape,
|
|
203
|
+
... numvalidspatiallocs,
|
|
204
|
+
... theinputdata,
|
|
205
|
+
... theheader,
|
|
206
|
+
... theFitter,
|
|
207
|
+
... fitmask,
|
|
208
|
+
... lagtimes,
|
|
209
|
+
... lagstrengths,
|
|
210
|
+
... lagsigma,
|
|
211
|
+
... failreason,
|
|
212
|
+
... outmaparray,
|
|
213
|
+
... trimmedcorrscale,
|
|
214
|
+
... similaritytype,
|
|
215
|
+
... thepass,
|
|
216
|
+
... optiondict,
|
|
217
|
+
... LGR,
|
|
218
|
+
... TimingLGR,
|
|
219
|
+
... simplefit=False,
|
|
220
|
+
... upsampfac=8,
|
|
221
|
+
... rt_floatset=np.float64,
|
|
222
|
+
... rt_floattype="float64",
|
|
223
|
+
... )
|
|
224
|
+
"""
|
|
73
225
|
# Do a peak prefit if doing hybrid
|
|
74
226
|
if optiondict["similaritymetric"] == "hybrid":
|
|
75
227
|
LGR.info(f"\n\nPeak prefit calculation, pass {thepass}")
|
|
@@ -115,7 +267,9 @@ def fitSimFunc(
|
|
|
115
267
|
delaystep = (trimmedcorrscale[1] - trimmedcorrscale[0]) / upsampfac
|
|
116
268
|
for thevox in range(numvalidspatiallocs):
|
|
117
269
|
fitmask[thevox] = 1
|
|
118
|
-
upsampcorrout = tide_resample.upsample(
|
|
270
|
+
upsampcorrout = tide_resample.upsample(
|
|
271
|
+
corrout[thevox, :], 1, upsampfac, intfac=True, dofilt=False
|
|
272
|
+
)
|
|
119
273
|
if optiondict["bipolar"]:
|
|
120
274
|
thismax = np.argmax(np.fabs(upsampcorrout))
|
|
121
275
|
else:
|
|
@@ -193,9 +347,9 @@ def fitSimFunc(
|
|
|
193
347
|
outmaparray[validvoxels] = eval("lagtimes")[:]
|
|
194
348
|
|
|
195
349
|
# find voxels to despeckle
|
|
196
|
-
medianlags = ndimage.median_filter(
|
|
197
|
-
|
|
198
|
-
)
|
|
350
|
+
medianlags = ndimage.median_filter(
|
|
351
|
+
outmaparray.reshape(nativespaceshape), 3
|
|
352
|
+
).reshape(numspatiallocs)
|
|
199
353
|
# voxels that we're happy with have initlags set to -1000000.0
|
|
200
354
|
initlags = np.where(
|
|
201
355
|
np.abs(outmaparray - medianlags) > optiondict["despeckle_thresh"],
|
|
@@ -235,7 +389,9 @@ def fitSimFunc(
|
|
|
235
389
|
rt_floatset=rt_floatset,
|
|
236
390
|
rt_floattype=rt_floattype,
|
|
237
391
|
)
|
|
238
|
-
tide_util.enablemkl(
|
|
392
|
+
tide_util.enablemkl(
|
|
393
|
+
optiondict["mklthreads"], debug=optiondict["threaddebug"]
|
|
394
|
+
)
|
|
239
395
|
|
|
240
396
|
voxelsprocessed_fc_ds += voxelsprocessed_thispass
|
|
241
397
|
optiondict[
|
|
@@ -258,7 +414,9 @@ def fitSimFunc(
|
|
|
258
414
|
0.0,
|
|
259
415
|
)
|
|
260
416
|
if optiondict["savedespecklemasks"] and (optiondict["despeckle_passes"] > 0):
|
|
261
|
-
despecklesavemask = np.where(
|
|
417
|
+
despecklesavemask = np.where(
|
|
418
|
+
internaldespeckleincludemask[validvoxels] == 0.0, 0, 1
|
|
419
|
+
)
|
|
262
420
|
if thepass == optiondict["passes"]:
|
|
263
421
|
if theinputdata.filetype != "text":
|
|
264
422
|
if theinputdata.filetype == "cifti":
|
rapidtide/workflows/fixtr.py
CHANGED
|
@@ -17,13 +17,39 @@
|
|
|
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 rapidtide.io as tide_io
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def _get_parser():
|
|
26
|
+
def _get_parser() -> Any:
|
|
25
27
|
"""
|
|
26
|
-
Argument parser for resamplenifti
|
|
28
|
+
Argument parser for resamplenifti.
|
|
29
|
+
|
|
30
|
+
Creates and configures an argument parser for the resamplenifti command-line tool
|
|
31
|
+
that changes the TR (repetition time) in a NIFTI header.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
argparse.ArgumentParser
|
|
36
|
+
Configured argument parser object with all required and optional arguments
|
|
37
|
+
for the resamplenifti tool.
|
|
38
|
+
|
|
39
|
+
Notes
|
|
40
|
+
-----
|
|
41
|
+
The parser is configured with:
|
|
42
|
+
- Required positional arguments: inputfile, outputfile, and outputtr
|
|
43
|
+
- Optional debug flag for additional output
|
|
44
|
+
- Program name set to "fixtr"
|
|
45
|
+
- Description explaining the purpose of changing TR in NIFTI headers
|
|
46
|
+
|
|
47
|
+
Examples
|
|
48
|
+
--------
|
|
49
|
+
>>> parser = _get_parser()
|
|
50
|
+
>>> args = parser.parse_args(['input.nii', 'output', '2.0'])
|
|
51
|
+
>>> print(args.inputfile)
|
|
52
|
+
'input.nii'
|
|
27
53
|
"""
|
|
28
54
|
parser = argparse.ArgumentParser(
|
|
29
55
|
prog="fixtr",
|
|
@@ -45,7 +71,51 @@ def _get_parser():
|
|
|
45
71
|
return parser
|
|
46
72
|
|
|
47
73
|
|
|
48
|
-
def fixtr(args):
|
|
74
|
+
def fixtr(args: Any) -> None:
|
|
75
|
+
"""
|
|
76
|
+
Fix the temporal resolution (TR) of a NIfTI file.
|
|
77
|
+
|
|
78
|
+
This function reads a NIfTI file and modifies its header to change the
|
|
79
|
+
temporal resolution (TR) while preserving the original data. The output
|
|
80
|
+
file is saved with the new TR value in the header.
|
|
81
|
+
|
|
82
|
+
Parameters
|
|
83
|
+
----------
|
|
84
|
+
args : Any
|
|
85
|
+
An object containing the following attributes:
|
|
86
|
+
- inputfile : str
|
|
87
|
+
Path to the input NIfTI file
|
|
88
|
+
- outputfile : str
|
|
89
|
+
Path to the output NIfTI file
|
|
90
|
+
- outputtr : float
|
|
91
|
+
Desired output temporal resolution in seconds
|
|
92
|
+
- debug : bool, optional
|
|
93
|
+
If True, print debug information including input timepoints and TR
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
None
|
|
98
|
+
This function does not return a value but saves the modified NIfTI file
|
|
99
|
+
to the specified output path.
|
|
100
|
+
|
|
101
|
+
Notes
|
|
102
|
+
-----
|
|
103
|
+
The function preserves the original data type and spatial dimensions of the
|
|
104
|
+
input file. The temporal dimension (t) in the output header is updated based
|
|
105
|
+
on the units specified in the input header. If the input header specifies
|
|
106
|
+
millisecond units, the output TR is converted from seconds to milliseconds.
|
|
107
|
+
|
|
108
|
+
Examples
|
|
109
|
+
--------
|
|
110
|
+
>>> class Args:
|
|
111
|
+
... def __init__(self):
|
|
112
|
+
... self.inputfile = "input.nii"
|
|
113
|
+
... self.outputfile = "output.nii"
|
|
114
|
+
... self.outputtr = 2.0
|
|
115
|
+
... self.debug = False
|
|
116
|
+
>>> args = Args()
|
|
117
|
+
>>> fixtr(args)
|
|
118
|
+
"""
|
|
49
119
|
# get the input TR
|
|
50
120
|
inputtr, numinputtrs = tide_io.fmritimeinfo(args.inputfile)
|
|
51
121
|
if args.debug:
|
rapidtide/workflows/gmscalc.py
CHANGED
|
@@ -20,8 +20,11 @@ import argparse
|
|
|
20
20
|
import platform
|
|
21
21
|
import sys
|
|
22
22
|
import time
|
|
23
|
+
from argparse import Namespace
|
|
24
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
23
25
|
|
|
24
26
|
import numpy as np
|
|
27
|
+
from numpy.typing import NDArray
|
|
25
28
|
|
|
26
29
|
import rapidtide.filter as tide_filt
|
|
27
30
|
import rapidtide.io as tide_io
|
|
@@ -30,7 +33,33 @@ import rapidtide.util as tide_util
|
|
|
30
33
|
import rapidtide.workflows.parser_funcs as pf
|
|
31
34
|
|
|
32
35
|
|
|
33
|
-
def _get_parser():
|
|
36
|
+
def _get_parser() -> Any:
|
|
37
|
+
"""
|
|
38
|
+
Construct and return an argument parser for the gmscalc tool.
|
|
39
|
+
|
|
40
|
+
This function sets up an `argparse.ArgumentParser` with required and optional
|
|
41
|
+
arguments needed to run the global mean signal calculation and filtering
|
|
42
|
+
pipeline. It includes support for specifying input data, output root, data mask,
|
|
43
|
+
normalization options, smoothing, and debugging.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
argparse.ArgumentParser
|
|
48
|
+
Configured argument parser with all required and optional arguments
|
|
49
|
+
for the gmscalc tool.
|
|
50
|
+
|
|
51
|
+
Notes
|
|
52
|
+
-----
|
|
53
|
+
The parser is configured with `allow_abbrev=False` to enforce full argument
|
|
54
|
+
names and avoid ambiguity.
|
|
55
|
+
|
|
56
|
+
Examples
|
|
57
|
+
--------
|
|
58
|
+
>>> parser = _get_parser()
|
|
59
|
+
>>> args = parser.parse_args(['data.nii', 'output_root'])
|
|
60
|
+
>>> print(args.datafile)
|
|
61
|
+
'data.nii'
|
|
62
|
+
"""
|
|
34
63
|
parser = argparse.ArgumentParser(
|
|
35
64
|
prog="gmscalc",
|
|
36
65
|
description="Calculate the global mean signal, and filtered versions",
|
|
@@ -86,7 +115,54 @@ def _get_parser():
|
|
|
86
115
|
return parser
|
|
87
116
|
|
|
88
117
|
|
|
89
|
-
def makecommandlinelist(
|
|
118
|
+
def makecommandlinelist(
|
|
119
|
+
arglist: Any, starttime: Any, endtime: Any, extra: Optional[Any] = None
|
|
120
|
+
) -> None:
|
|
121
|
+
"""
|
|
122
|
+
Create a list of command line information for logging purposes.
|
|
123
|
+
|
|
124
|
+
This function generates a list of descriptive strings containing processing
|
|
125
|
+
information including date, duration, version details, and the actual command
|
|
126
|
+
that was executed.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
arglist : Any
|
|
131
|
+
List of command line arguments to be joined into a command string.
|
|
132
|
+
starttime : Any
|
|
133
|
+
Start time of the process, typically a timestamp.
|
|
134
|
+
endtime : Any
|
|
135
|
+
End time of the process, typically a timestamp.
|
|
136
|
+
extra : Any, optional
|
|
137
|
+
Additional descriptive text to include in the output list. Default is None.
|
|
138
|
+
|
|
139
|
+
Returns
|
|
140
|
+
-------
|
|
141
|
+
list of str
|
|
142
|
+
List containing the following elements in order:
|
|
143
|
+
- Processing date and time
|
|
144
|
+
- Processing duration
|
|
145
|
+
- Node and version information
|
|
146
|
+
- Extra information (if provided)
|
|
147
|
+
- The actual command line string
|
|
148
|
+
|
|
149
|
+
Notes
|
|
150
|
+
-----
|
|
151
|
+
The function uses `time.strftime` to format the start time and `tide_util.version()`
|
|
152
|
+
to retrieve version information. The command line is constructed by joining
|
|
153
|
+
the `arglist` elements with spaces.
|
|
154
|
+
|
|
155
|
+
Examples
|
|
156
|
+
--------
|
|
157
|
+
>>> import time
|
|
158
|
+
>>> args = ['python', 'script.py', '--input', 'data.txt']
|
|
159
|
+
>>> start = time.time()
|
|
160
|
+
>>> # ... some processing ...
|
|
161
|
+
>>> end = time.time()
|
|
162
|
+
>>> info = makecommandlinelist(args, start, end)
|
|
163
|
+
>>> print(info[0])
|
|
164
|
+
'# Processed on Mon, 01 Jan 2024 12:00:00 UTC.'
|
|
165
|
+
"""
|
|
90
166
|
# get the processing date
|
|
91
167
|
dateline = (
|
|
92
168
|
"# Processed on "
|
|
@@ -123,7 +199,41 @@ def makecommandlinelist(arglist, starttime, endtime, extra=None):
|
|
|
123
199
|
return [dateline, timeline, nodeline, commandline]
|
|
124
200
|
|
|
125
201
|
|
|
126
|
-
def gmscalc_main():
|
|
202
|
+
def gmscalc_main() -> None:
|
|
203
|
+
"""
|
|
204
|
+
Main function to calculate global mean signal (GMS) from fMRI data.
|
|
205
|
+
|
|
206
|
+
This function reads NIfTI-formatted fMRI data, applies optional smoothing,
|
|
207
|
+
masks the data if a mask is provided, and computes the global mean signal
|
|
208
|
+
across valid voxels. It then applies low-frequency (LFO) and high-frequency
|
|
209
|
+
(HF) filtering to the global signal and writes the results to text files.
|
|
210
|
+
|
|
211
|
+
The function uses the `tide_io` module for reading and writing data, and
|
|
212
|
+
`tide_filt` and `tide_math` for filtering and normalization.
|
|
213
|
+
|
|
214
|
+
Notes
|
|
215
|
+
-----
|
|
216
|
+
The function expects a command-line interface to be set up with `_get_parser()`
|
|
217
|
+
and uses `sys.argv` to parse arguments. It prints diagnostic information
|
|
218
|
+
during execution.
|
|
219
|
+
|
|
220
|
+
Examples
|
|
221
|
+
--------
|
|
222
|
+
Assuming the script is called as `gmscalc_main.py` and properly configured:
|
|
223
|
+
|
|
224
|
+
>>> gmscalc_main()
|
|
225
|
+
|
|
226
|
+
This will read the input data, perform processing, and write output files
|
|
227
|
+
with names based on the `outputroot` argument.
|
|
228
|
+
|
|
229
|
+
See Also
|
|
230
|
+
--------
|
|
231
|
+
tide_io.readfromnifti : Reads NIfTI files.
|
|
232
|
+
tide_io.writevec : Writes vectors to text files.
|
|
233
|
+
tide_filt.ssmooth : Applies spatial smoothing.
|
|
234
|
+
tide_filt.NoncausalFilter : Applies non-causal filtering.
|
|
235
|
+
tide_math.normalize : Normalizes a signal.
|
|
236
|
+
"""
|
|
127
237
|
try:
|
|
128
238
|
args = _get_parser().parse_args()
|
|
129
239
|
except SystemExit:
|