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
|
@@ -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
|
|
|
21
24
|
import rapidtide.calcsimfunc as tide_calcsimfunc
|
|
22
25
|
import rapidtide.io as tide_io
|
|
@@ -27,21 +30,86 @@ import rapidtide.util as tide_util
|
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
def makeRIPTiDeRegressors(
|
|
30
|
-
initial_fmri_x,
|
|
31
|
-
lagmin,
|
|
32
|
-
lagmax,
|
|
33
|
-
lagtcgenerator,
|
|
34
|
-
LGR,
|
|
35
|
-
nprocs=1,
|
|
36
|
-
alwaysmultiproc=False,
|
|
37
|
-
showprogressbar=True,
|
|
38
|
-
chunksize=1000,
|
|
39
|
-
targetstep=2.5,
|
|
40
|
-
edgepad=0,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
initial_fmri_x: Any,
|
|
34
|
+
lagmin: Any,
|
|
35
|
+
lagmax: Any,
|
|
36
|
+
lagtcgenerator: Any,
|
|
37
|
+
LGR: Any,
|
|
38
|
+
nprocs: int = 1,
|
|
39
|
+
alwaysmultiproc: bool = False,
|
|
40
|
+
showprogressbar: bool = True,
|
|
41
|
+
chunksize: int = 1000,
|
|
42
|
+
targetstep: float = 2.5,
|
|
43
|
+
edgepad: int = 0,
|
|
44
|
+
rt_floattype: np.dtype = np.float64,
|
|
45
|
+
debug: bool = False,
|
|
46
|
+
) -> Tuple[NDArray, NDArray]:
|
|
47
|
+
"""
|
|
48
|
+
Generate regressors for RIPTiDe (Regressors for Inverse Temporal Deconvolution).
|
|
49
|
+
|
|
50
|
+
This function creates a set of lagged temporal regressors based on the provided
|
|
51
|
+
parameters, which are used in the context of fMRI data analysis for temporal
|
|
52
|
+
deconvolution. It leverages the `tide_makelagged.makelaggedtcs` function to
|
|
53
|
+
compute the actual regressor matrix.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
initial_fmri_x : array_like
|
|
58
|
+
The initial fMRI time series data used to generate the regressors.
|
|
59
|
+
lagmin : float
|
|
60
|
+
The minimum lag (in seconds) to consider for regressor generation.
|
|
61
|
+
lagmax : float
|
|
62
|
+
The maximum lag (in seconds) to consider for regressor generation.
|
|
63
|
+
lagtcgenerator : callable
|
|
64
|
+
A function or callable object that generates lagged time courses.
|
|
65
|
+
LGR : object
|
|
66
|
+
An object containing parameters for the lagged time course generation.
|
|
67
|
+
nprocs : int, optional
|
|
68
|
+
Number of processes to use for parallel computation (default is 1).
|
|
69
|
+
alwaysmultiproc : bool, optional
|
|
70
|
+
If True, always use multiprocessing even for small datasets (default is False).
|
|
71
|
+
showprogressbar : bool, optional
|
|
72
|
+
If True, display a progress bar during computation (default is True).
|
|
73
|
+
chunksize : int, optional
|
|
74
|
+
Size of chunks for processing in multiprocessing (default is 1000).
|
|
75
|
+
targetstep : float, optional
|
|
76
|
+
Target step size (in seconds) between lags (default is 2.5).
|
|
77
|
+
edgepad : int, optional
|
|
78
|
+
Number of padding steps at the beginning and end of the lag range (default is 0).
|
|
79
|
+
rt_floattype : np.dtype, optional
|
|
80
|
+
Data type for the regressor matrix (default is np.float64).
|
|
81
|
+
debug : bool, optional
|
|
82
|
+
If True, print debug information during execution (default is False).
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
tuple of (NDArray, NDArray)
|
|
87
|
+
A tuple containing:
|
|
88
|
+
- regressorset : NDArray
|
|
89
|
+
The computed regressor matrix of shape (num_lags, num_timepoints).
|
|
90
|
+
- delaystouse : NDArray
|
|
91
|
+
The array of delay values used for regressor generation.
|
|
92
|
+
|
|
93
|
+
Notes
|
|
94
|
+
-----
|
|
95
|
+
This function is intended for use in fMRI data analysis workflows where
|
|
96
|
+
temporal deconvolution is required. The regressors generated can be used
|
|
97
|
+
in subsequent steps such as GLM fitting or temporal filtering.
|
|
98
|
+
|
|
99
|
+
Examples
|
|
100
|
+
--------
|
|
101
|
+
>>> import numpy as np
|
|
102
|
+
>>> fmri_data = np.random.rand(100, 50)
|
|
103
|
+
>>> regressors, delays = makeRIPTiDeRegressors(
|
|
104
|
+
... initial_fmri_x=fmri_data,
|
|
105
|
+
... lagmin=0.0,
|
|
106
|
+
... lagmax=10.0,
|
|
107
|
+
... lagtcgenerator=my_lag_generator,
|
|
108
|
+
... LGR=my_lgr_object,
|
|
109
|
+
... nprocs=4,
|
|
110
|
+
... debug=True
|
|
111
|
+
... )
|
|
112
|
+
"""
|
|
45
113
|
# make the RIPTiDe evs
|
|
46
114
|
numdelays = int(np.round((lagmax - lagmin) / targetstep, 0))
|
|
47
115
|
numregressors = numdelays + 2 * edgepad
|
|
@@ -62,7 +130,7 @@ def makeRIPTiDeRegressors(
|
|
|
62
130
|
print(f"{delaystouse=}, {len(delaystouse)}")
|
|
63
131
|
print(f"{len(initial_fmri_x)}")
|
|
64
132
|
|
|
65
|
-
regressorset = np.zeros((len(delaystouse), len(initial_fmri_x)), dtype=
|
|
133
|
+
regressorset = np.zeros((len(delaystouse), len(initial_fmri_x)), dtype=rt_floattype)
|
|
66
134
|
|
|
67
135
|
dummy = tide_makelagged.makelaggedtcs(
|
|
68
136
|
lagtcgenerator,
|
|
@@ -75,7 +143,6 @@ def makeRIPTiDeRegressors(
|
|
|
75
143
|
alwaysmultiproc=alwaysmultiproc,
|
|
76
144
|
showprogressbar=showprogressbar,
|
|
77
145
|
chunksize=chunksize,
|
|
78
|
-
rt_floatset=rt_floatset,
|
|
79
146
|
rt_floattype=rt_floattype,
|
|
80
147
|
debug=debug,
|
|
81
148
|
)
|
|
@@ -87,54 +154,209 @@ def makeRIPTiDeRegressors(
|
|
|
87
154
|
|
|
88
155
|
|
|
89
156
|
def calcSimFunc(
|
|
90
|
-
numvalidspatiallocs,
|
|
91
|
-
fmri_data_valid,
|
|
92
|
-
validsimcalcstart,
|
|
93
|
-
validsimcalcend,
|
|
94
|
-
osvalidsimcalcstart,
|
|
95
|
-
osvalidsimcalcend,
|
|
96
|
-
initial_fmri_x,
|
|
97
|
-
os_fmri_x,
|
|
98
|
-
theCorrelator,
|
|
99
|
-
theMutualInformationator,
|
|
100
|
-
cleaned_referencetc,
|
|
101
|
-
corrout,
|
|
102
|
-
regressorset,
|
|
103
|
-
delayvals,
|
|
104
|
-
sLFOfitmean,
|
|
105
|
-
r2value,
|
|
106
|
-
fitcoeff,
|
|
107
|
-
fitNorm,
|
|
108
|
-
meanval,
|
|
109
|
-
corrscale,
|
|
110
|
-
outputname,
|
|
111
|
-
outcorrarray,
|
|
112
|
-
validvoxels,
|
|
113
|
-
nativecorrshape,
|
|
114
|
-
theinputdata,
|
|
115
|
-
theheader,
|
|
116
|
-
lagmininpts,
|
|
117
|
-
lagmaxinpts,
|
|
118
|
-
thepass,
|
|
119
|
-
optiondict,
|
|
120
|
-
LGR,
|
|
121
|
-
TimingLGR,
|
|
122
|
-
similaritymetric="correlation",
|
|
123
|
-
simcalcoffset=0,
|
|
124
|
-
echocancel=False,
|
|
125
|
-
checkpoint=False,
|
|
126
|
-
nprocs=1,
|
|
127
|
-
alwaysmultiproc=False,
|
|
128
|
-
oversampfactor=2,
|
|
129
|
-
interptype="univariate",
|
|
130
|
-
showprogressbar=True,
|
|
131
|
-
chunksize=1000,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
157
|
+
numvalidspatiallocs: Any,
|
|
158
|
+
fmri_data_valid: Any,
|
|
159
|
+
validsimcalcstart: Any,
|
|
160
|
+
validsimcalcend: Any,
|
|
161
|
+
osvalidsimcalcstart: Any,
|
|
162
|
+
osvalidsimcalcend: Any,
|
|
163
|
+
initial_fmri_x: Any,
|
|
164
|
+
os_fmri_x: Any,
|
|
165
|
+
theCorrelator: Any,
|
|
166
|
+
theMutualInformationator: Any,
|
|
167
|
+
cleaned_referencetc: Any,
|
|
168
|
+
corrout: Any,
|
|
169
|
+
regressorset: Any,
|
|
170
|
+
delayvals: Any,
|
|
171
|
+
sLFOfitmean: Any,
|
|
172
|
+
r2value: Any,
|
|
173
|
+
fitcoeff: Any,
|
|
174
|
+
fitNorm: Any,
|
|
175
|
+
meanval: Any,
|
|
176
|
+
corrscale: Any,
|
|
177
|
+
outputname: Any,
|
|
178
|
+
outcorrarray: Any,
|
|
179
|
+
validvoxels: Any,
|
|
180
|
+
nativecorrshape: Any,
|
|
181
|
+
theinputdata: Any,
|
|
182
|
+
theheader: Any,
|
|
183
|
+
lagmininpts: Any,
|
|
184
|
+
lagmaxinpts: Any,
|
|
185
|
+
thepass: Any,
|
|
186
|
+
optiondict: Any,
|
|
187
|
+
LGR: Any,
|
|
188
|
+
TimingLGR: Any,
|
|
189
|
+
similaritymetric: str = "correlation",
|
|
190
|
+
simcalcoffset: int = 0,
|
|
191
|
+
echocancel: bool = False,
|
|
192
|
+
checkpoint: bool = False,
|
|
193
|
+
nprocs: int = 1,
|
|
194
|
+
alwaysmultiproc: bool = False,
|
|
195
|
+
oversampfactor: int = 2,
|
|
196
|
+
interptype: str = "univariate",
|
|
197
|
+
showprogressbar: bool = True,
|
|
198
|
+
chunksize: int = 1000,
|
|
199
|
+
rt_floattype: np.dtype = np.float64,
|
|
200
|
+
mklthreads: int = 1,
|
|
201
|
+
threaddebug: bool = False,
|
|
202
|
+
debug: bool = False,
|
|
203
|
+
) -> str:
|
|
204
|
+
"""
|
|
205
|
+
Compute similarity metrics (correlation, mutual information, or RIPtiDe) between fMRI data and a reference time series.
|
|
206
|
+
|
|
207
|
+
This function performs similarity calculations across voxels using either correlation, mutual information,
|
|
208
|
+
or a hybrid method, depending on the specified `similaritymetric`. It supports multi-processing and can
|
|
209
|
+
optionally save intermediate results.
|
|
210
|
+
|
|
211
|
+
Parameters
|
|
212
|
+
----------
|
|
213
|
+
numvalidspatiallocs : Any
|
|
214
|
+
Number of valid spatial locations in the fMRI data.
|
|
215
|
+
fmri_data_valid : Any
|
|
216
|
+
Valid fMRI data array, typically of shape (n_voxels, n_timepoints).
|
|
217
|
+
validsimcalcstart : Any
|
|
218
|
+
Start index for valid timepoints to use in similarity calculation.
|
|
219
|
+
validsimcalcend : Any
|
|
220
|
+
End index for valid timepoints to use in similarity calculation.
|
|
221
|
+
osvalidsimcalcstart : Any
|
|
222
|
+
Start index for oversampled valid timepoints.
|
|
223
|
+
osvalidsimcalcend : Any
|
|
224
|
+
End index for oversampled valid timepoints.
|
|
225
|
+
initial_fmri_x : Any
|
|
226
|
+
Initial fMRI timepoints (e.g., for correlation).
|
|
227
|
+
os_fmri_x : Any
|
|
228
|
+
Oversampled fMRI timepoints.
|
|
229
|
+
theCorrelator : Any
|
|
230
|
+
Correlator object used for computing correlations.
|
|
231
|
+
theMutualInformationator : Any
|
|
232
|
+
Mutual information calculator object.
|
|
233
|
+
cleaned_referencetc : Any
|
|
234
|
+
Cleaned reference time series.
|
|
235
|
+
corrout : Any
|
|
236
|
+
Output array for storing correlation results.
|
|
237
|
+
regressorset : Any
|
|
238
|
+
Set of regressors for fitting.
|
|
239
|
+
delayvals : Any
|
|
240
|
+
Array of delay values for RIPtiDe calculation.
|
|
241
|
+
sLFOfitmean : Any
|
|
242
|
+
Mean value for fitting.
|
|
243
|
+
r2value : Any
|
|
244
|
+
R² values for model fit.
|
|
245
|
+
fitcoeff : Any
|
|
246
|
+
Fitting coefficients.
|
|
247
|
+
fitNorm : Any
|
|
248
|
+
Normalization values for fitting.
|
|
249
|
+
meanval : Any
|
|
250
|
+
Mean value used in normalization.
|
|
251
|
+
corrscale : Any
|
|
252
|
+
Correlation scale for lag calculation.
|
|
253
|
+
outputname : Any
|
|
254
|
+
Base name for output files.
|
|
255
|
+
outcorrarray : Any
|
|
256
|
+
Array to store correlation output for checkpointing.
|
|
257
|
+
validvoxels : Any
|
|
258
|
+
Indices of valid voxels.
|
|
259
|
+
nativecorrshape : Any
|
|
260
|
+
Shape of the native correlation array.
|
|
261
|
+
theinputdata : Any
|
|
262
|
+
Input data object.
|
|
263
|
+
theheader : Any
|
|
264
|
+
Header information for NIfTI output.
|
|
265
|
+
lagmininpts : Any
|
|
266
|
+
Minimum lag in timepoints.
|
|
267
|
+
lagmaxinpts : Any
|
|
268
|
+
Maximum lag in timepoints.
|
|
269
|
+
thepass : Any
|
|
270
|
+
Pass number for tracking multiple iterations.
|
|
271
|
+
optiondict : Any
|
|
272
|
+
Dictionary of options for saving results.
|
|
273
|
+
LGR : Any
|
|
274
|
+
Logger for general messages.
|
|
275
|
+
TimingLGR : Any
|
|
276
|
+
Logger for timing information.
|
|
277
|
+
similaritymetric : str, optional
|
|
278
|
+
Type of similarity metric to compute. Options are:
|
|
279
|
+
'correlation', 'mutualinfo', 'riptide', or 'hybrid'. Default is 'correlation'.
|
|
280
|
+
simcalcoffset : int, optional
|
|
281
|
+
Offset to subtract from computed lags. Default is 0.
|
|
282
|
+
echocancel : bool, optional
|
|
283
|
+
Whether to cancel echo effects. Default is False.
|
|
284
|
+
checkpoint : bool, optional
|
|
285
|
+
Whether to save intermediate results. Default is False.
|
|
286
|
+
nprocs : int, optional
|
|
287
|
+
Number of processes for multiprocessing. Default is 1.
|
|
288
|
+
alwaysmultiproc : bool, optional
|
|
289
|
+
Force multiprocessing even for single-core cases. Default is False.
|
|
290
|
+
oversampfactor : int, optional
|
|
291
|
+
Oversampling factor for interpolation. Default is 2.
|
|
292
|
+
interptype : str, optional
|
|
293
|
+
Interpolation type. Default is 'univariate'.
|
|
294
|
+
showprogressbar : bool, optional
|
|
295
|
+
Whether to show a progress bar. Default is True.
|
|
296
|
+
chunksize : int, optional
|
|
297
|
+
Size of chunks for processing. Default is 1000.
|
|
298
|
+
rt_floattype : np.dtype, optional
|
|
299
|
+
Rapidtide floating-point data type. Default is np.float64.
|
|
300
|
+
mklthreads : int, optional
|
|
301
|
+
Number of threads for Intel MKL. Default is 1.
|
|
302
|
+
threaddebug : bool, optional
|
|
303
|
+
Enable thread debugging. Default is False.
|
|
304
|
+
debug : bool, optional
|
|
305
|
+
Enable debug mode. Default is False.
|
|
306
|
+
|
|
307
|
+
Returns
|
|
308
|
+
-------
|
|
309
|
+
str
|
|
310
|
+
The type of similarity metric used in the calculation.
|
|
311
|
+
|
|
312
|
+
Notes
|
|
313
|
+
-----
|
|
314
|
+
- For 'riptide', the function fits linear models to delayed regressors.
|
|
315
|
+
- The function logs timing and processing information using `TimingLGR` and `LGR`.
|
|
316
|
+
- If `checkpoint` is True, intermediate correlation results are saved to disk.
|
|
317
|
+
- This function modifies `corrout` and `outcorrarray` in-place.
|
|
318
|
+
|
|
319
|
+
Examples
|
|
320
|
+
--------
|
|
321
|
+
>>> calcSimFunc(
|
|
322
|
+
... numvalidspatiallocs=100,
|
|
323
|
+
... fmri_data_valid=np.random.rand(100, 100),
|
|
324
|
+
... validsimcalcstart=0,
|
|
325
|
+
... validsimcalcend=99,
|
|
326
|
+
... osvalidsimcalcstart=0,
|
|
327
|
+
... osvalidsimcalcend=99,
|
|
328
|
+
... initial_fmri_x=np.linspace(0, 1, 100),
|
|
329
|
+
... os_fmri_x=np.linspace(0, 1, 100),
|
|
330
|
+
... theCorrelator=correlator_obj,
|
|
331
|
+
... theMutualInformationator=mi_obj,
|
|
332
|
+
... cleaned_referencetc=np.random.rand(100),
|
|
333
|
+
... corrout=np.zeros((100, 100)),
|
|
334
|
+
... regressorset=np.random.rand(10, 100),
|
|
335
|
+
... delayvals=np.array([0, 1, 2]),
|
|
336
|
+
... sLFOfitmean=np.mean(np.random.rand(100)),
|
|
337
|
+
... r2value=np.zeros(100),
|
|
338
|
+
... fitcoeff=np.zeros((100, 1)),
|
|
339
|
+
... fitNorm=np.ones(100),
|
|
340
|
+
... meanval=np.mean(np.random.rand(100)),
|
|
341
|
+
... corrscale=np.arange(100),
|
|
342
|
+
... outputname="test_output",
|
|
343
|
+
... outcorrarray=np.zeros((100, 100)),
|
|
344
|
+
... validvoxels=np.arange(100),
|
|
345
|
+
... nativecorrshape=(100, 100),
|
|
346
|
+
... theinputdata=input_data_obj,
|
|
347
|
+
... theheader=header,
|
|
348
|
+
... lagmininpts=-5,
|
|
349
|
+
... lagmaxinpts=5,
|
|
350
|
+
... thepass=1,
|
|
351
|
+
... optiondict={},
|
|
352
|
+
... LGR=logging.getLogger(),
|
|
353
|
+
... TimingLGR=logging.getLogger(),
|
|
354
|
+
... similaritymetric="correlation",
|
|
355
|
+
... nprocs=2,
|
|
356
|
+
... checkpoint=True,
|
|
357
|
+
... )
|
|
358
|
+
'Correlation'
|
|
359
|
+
"""
|
|
138
360
|
# Step 1 - Correlation step
|
|
139
361
|
if similaritymetric == "mutualinfo":
|
|
140
362
|
similaritytype = "Mutual information"
|
|
@@ -170,7 +392,6 @@ def calcSimFunc(
|
|
|
170
392
|
interptype=interptype,
|
|
171
393
|
showprogressbar=showprogressbar,
|
|
172
394
|
chunksize=chunksize,
|
|
173
|
-
rt_floatset=rt_floatset,
|
|
174
395
|
rt_floattype=rt_floattype,
|
|
175
396
|
debug=debug,
|
|
176
397
|
)
|
|
@@ -195,7 +416,6 @@ def calcSimFunc(
|
|
|
195
416
|
interptype=interptype,
|
|
196
417
|
showprogressbar=showprogressbar,
|
|
197
418
|
chunksize=chunksize,
|
|
198
|
-
rt_floatset=rt_floatset,
|
|
199
419
|
rt_floattype=rt_floattype,
|
|
200
420
|
debug=debug,
|
|
201
421
|
)
|
|
@@ -216,13 +436,12 @@ def calcSimFunc(
|
|
|
216
436
|
None,
|
|
217
437
|
None,
|
|
218
438
|
coefficientsonly=True,
|
|
219
|
-
|
|
439
|
+
constantevs=True,
|
|
220
440
|
nprocs=nprocs,
|
|
221
441
|
alwaysmultiproc=alwaysmultiproc,
|
|
222
442
|
showprogressbar=showprogressbar,
|
|
223
443
|
verbose=(LGR is not None),
|
|
224
444
|
chunksize=chunksize,
|
|
225
|
-
rt_floatset=rt_floatset,
|
|
226
445
|
rt_floattype=rt_floattype,
|
|
227
446
|
debug=debug,
|
|
228
447
|
)
|
|
@@ -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
|
from scipy.linalg import pinv
|
|
26
29
|
|
|
27
30
|
import rapidtide.io as tide_io
|
|
@@ -30,7 +33,42 @@ import rapidtide.util as tide_util
|
|
|
30
33
|
from rapidtide.workflows.parser_funcs import is_valid_file
|
|
31
34
|
|
|
32
35
|
|
|
33
|
-
def _get_parser():
|
|
36
|
+
def _get_parser() -> Any:
|
|
37
|
+
"""
|
|
38
|
+
Create and configure an argument parser for the calcicc command-line tool.
|
|
39
|
+
|
|
40
|
+
This function sets up an `argparse.ArgumentParser` with required and optional
|
|
41
|
+
arguments needed to run the ICC(3,1) calculation on text-based data files.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
argparse.ArgumentParser
|
|
46
|
+
Configured argument parser object with all required and optional arguments
|
|
47
|
+
for the calcicc tool.
|
|
48
|
+
|
|
49
|
+
Notes
|
|
50
|
+
-----
|
|
51
|
+
The parser is configured with:
|
|
52
|
+
- A program name "calcicc"
|
|
53
|
+
- A description explaining the purpose of the tool
|
|
54
|
+
- Three required positional arguments:
|
|
55
|
+
1. `datafile`: comma-separated list of 2D text files
|
|
56
|
+
2. `measurementlist`: multicolumn file specifying how to group measurements
|
|
57
|
+
3. `outputroot`: root name for output text files
|
|
58
|
+
- Several optional flags for controlling behavior:
|
|
59
|
+
- `--demedian`: subtract median from each map before ICC calculation
|
|
60
|
+
- `--demean`: subtract mean from each map before ICC calculation
|
|
61
|
+
- `--nocache`: disable caching for ICC calculation (not recommended)
|
|
62
|
+
- `--debug`: enable basic debugging output
|
|
63
|
+
- `--deepdebug`: enable verbose debugging output
|
|
64
|
+
|
|
65
|
+
Examples
|
|
66
|
+
--------
|
|
67
|
+
>>> parser = _get_parser()
|
|
68
|
+
>>> args = parser.parse_args(['file1.txt', 'measurements.txt', 'output_root'])
|
|
69
|
+
>>> print(args.datafile)
|
|
70
|
+
'file1.txt'
|
|
71
|
+
"""
|
|
34
72
|
parser = argparse.ArgumentParser(
|
|
35
73
|
prog="calcicc",
|
|
36
74
|
description="Calculate per-column ICC(3,1) on a set of text files.",
|
|
@@ -105,7 +143,55 @@ def _get_parser():
|
|
|
105
143
|
return parser
|
|
106
144
|
|
|
107
145
|
|
|
108
|
-
def parsetextmeasurementlist(
|
|
146
|
+
def parsetextmeasurementlist(
|
|
147
|
+
measlist: Any, numfiles: Any, debug: bool = False
|
|
148
|
+
) -> Tuple[NDArray, NDArray]:
|
|
149
|
+
"""
|
|
150
|
+
Parse a measurement list from text format into file and volume indices.
|
|
151
|
+
|
|
152
|
+
This function processes a 2D array of strings representing measurement entries,
|
|
153
|
+
where each entry is expected to contain either one or two comma-separated values.
|
|
154
|
+
The first value represents the file index, and the second represents the volume index.
|
|
155
|
+
If only one value is present, the file index is assumed to be 0.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
----------
|
|
159
|
+
measlist : array-like
|
|
160
|
+
A 2D array of strings where each string contains either one or two
|
|
161
|
+
comma-separated integers representing file and volume indices.
|
|
162
|
+
numfiles : int
|
|
163
|
+
The total number of available files, used to validate file indices.
|
|
164
|
+
debug : bool, optional
|
|
165
|
+
If True, prints debug information for each parsed element. Default is False.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
tuple of ndarray
|
|
170
|
+
A tuple containing two 2D arrays:
|
|
171
|
+
- `filesel`: File indices for each measurement.
|
|
172
|
+
- `volumesel`: Volume indices for each measurement.
|
|
173
|
+
|
|
174
|
+
Notes
|
|
175
|
+
-----
|
|
176
|
+
- Each entry in `measlist` should be a string of the form "file,volume" or "volume".
|
|
177
|
+
- File indices are validated to ensure they do not exceed `numfiles - 1`.
|
|
178
|
+
- The function will exit with an error if:
|
|
179
|
+
1. An entry contains more than one comma.
|
|
180
|
+
2. A file index is out of bounds.
|
|
181
|
+
|
|
182
|
+
Examples
|
|
183
|
+
--------
|
|
184
|
+
>>> import numpy as np
|
|
185
|
+
>>> measlist = np.array([["0,1", "1,2"], ["0", "2,3"]])
|
|
186
|
+
>>> numfiles = 3
|
|
187
|
+
>>> filesel, volumesel = parsetextmeasurementlist(measlist, numfiles)
|
|
188
|
+
>>> print(filesel)
|
|
189
|
+
[[0 1]
|
|
190
|
+
[0 2]]
|
|
191
|
+
>>> print(volumesel)
|
|
192
|
+
[[1 2]
|
|
193
|
+
[0 3]]
|
|
194
|
+
"""
|
|
109
195
|
# how do we get the number of subjects?
|
|
110
196
|
nummeas, numsubjs = measlist.shape[0], measlist.shape[1]
|
|
111
197
|
filesel = np.zeros((nummeas, numsubjs), dtype=int)
|
|
@@ -134,7 +220,54 @@ def parsetextmeasurementlist(measlist, numfiles, debug=False):
|
|
|
134
220
|
return filesel, volumesel
|
|
135
221
|
|
|
136
222
|
|
|
137
|
-
def makdcommandlinelist(
|
|
223
|
+
def makdcommandlinelist(
|
|
224
|
+
arglist: Any, starttime: Any, endtime: Any, extra: Optional[Any] = None
|
|
225
|
+
) -> Tuple[str, str, str, str, str] | Tuple[str, str, str, str]:
|
|
226
|
+
"""
|
|
227
|
+
Create a list of command line information for processing metadata.
|
|
228
|
+
|
|
229
|
+
This function generates a list of descriptive strings containing processing
|
|
230
|
+
information including timestamps, version details, and the command line
|
|
231
|
+
that was executed.
|
|
232
|
+
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
arglist : Any
|
|
236
|
+
List of command line arguments that were used to invoke the process
|
|
237
|
+
starttime : Any
|
|
238
|
+
Start time of the process, typically a timestamp or time object
|
|
239
|
+
endtime : Any
|
|
240
|
+
End time of the process, typically a timestamp or time object
|
|
241
|
+
extra : Any, optional
|
|
242
|
+
Additional descriptive text to include in the output list, by default None
|
|
243
|
+
|
|
244
|
+
Returns
|
|
245
|
+
-------
|
|
246
|
+
list of str
|
|
247
|
+
List containing metadata strings with processing information:
|
|
248
|
+
- Processing date and time
|
|
249
|
+
- Processing duration
|
|
250
|
+
- Version and system information
|
|
251
|
+
- Extra information (if provided)
|
|
252
|
+
- The original command line
|
|
253
|
+
|
|
254
|
+
Notes
|
|
255
|
+
-----
|
|
256
|
+
The function uses `time.strftime` to format the start time and calculates
|
|
257
|
+
the processing duration by subtracting starttime from endtime. It also
|
|
258
|
+
retrieves version information using `tide_util.version()` and system
|
|
259
|
+
information using `platform.node()`.
|
|
260
|
+
|
|
261
|
+
Examples
|
|
262
|
+
--------
|
|
263
|
+
>>> import time
|
|
264
|
+
>>> args = ['python', 'script.py', '--input', 'data.txt']
|
|
265
|
+
>>> start = time.time() - 10
|
|
266
|
+
>>> end = time.time()
|
|
267
|
+
>>> result = makdcommandlinelist(args, start, end)
|
|
268
|
+
>>> print(result[0])
|
|
269
|
+
'# Processed on Mon, 01 Jan 2024 12:00:00 UTC.'
|
|
270
|
+
"""
|
|
138
271
|
# get the processing date
|
|
139
272
|
dateline = (
|
|
140
273
|
"# Processed on "
|
|
@@ -166,12 +299,71 @@ def makdcommandlinelist(arglist, starttime, endtime, extra=None):
|
|
|
166
299
|
commandline = " ".join(arglist)
|
|
167
300
|
|
|
168
301
|
if extra is not None:
|
|
169
|
-
return
|
|
302
|
+
return dateline, timeline, nodeline, f"# {extra}", commandline
|
|
170
303
|
else:
|
|
171
|
-
return
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
def calctexticc(args):
|
|
304
|
+
return dateline, timeline, nodeline, commandline
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def calctexticc(args: Any) -> None:
|
|
308
|
+
"""
|
|
309
|
+
Calculate intraclass correlation coefficients (ICC) for text-based measurement data across subjects.
|
|
310
|
+
|
|
311
|
+
This function reads measurement lists and corresponding data files, processes the data to
|
|
312
|
+
compute ICC(3,1) values for each voxel, and writes out the results along with variance components
|
|
313
|
+
and session effect F-values.
|
|
314
|
+
|
|
315
|
+
Parameters
|
|
316
|
+
----------
|
|
317
|
+
args : Any
|
|
318
|
+
An object containing command-line arguments. Expected attributes include:
|
|
319
|
+
- datafile : str
|
|
320
|
+
Comma-separated list of input data file paths.
|
|
321
|
+
- measurementlist : str
|
|
322
|
+
Path to the measurement list file.
|
|
323
|
+
- outputroot : str
|
|
324
|
+
Root name for output files.
|
|
325
|
+
- debug : bool, optional
|
|
326
|
+
Enable debug printing.
|
|
327
|
+
- deepdebug : bool, optional
|
|
328
|
+
Enable deep debug printing.
|
|
329
|
+
- demedian : bool, optional
|
|
330
|
+
Remove median from each subject's measurements.
|
|
331
|
+
- demean : bool, optional
|
|
332
|
+
Remove mean from each subject's measurements.
|
|
333
|
+
- nocache : bool, optional
|
|
334
|
+
Disable caching during ICC calculation.
|
|
335
|
+
|
|
336
|
+
Returns
|
|
337
|
+
-------
|
|
338
|
+
None
|
|
339
|
+
The function does not return a value but writes multiple output files:
|
|
340
|
+
- `{outputroot}_ICC.txt`
|
|
341
|
+
- `{outputroot}_r_var.txt`
|
|
342
|
+
- `{outputroot}_e_var.txt`
|
|
343
|
+
- `{outputroot}_session_effect_F.txt`
|
|
344
|
+
- `{outputroot}_commandline.txt`
|
|
345
|
+
|
|
346
|
+
Notes
|
|
347
|
+
-----
|
|
348
|
+
The function reshapes data into a voxel-by-subject-by-measurement format and computes ICC(3,1)
|
|
349
|
+
using a repeated measures ANOVA approach. It supports optional mean/median removal for each
|
|
350
|
+
subject and measurement.
|
|
351
|
+
|
|
352
|
+
Examples
|
|
353
|
+
--------
|
|
354
|
+
>>> import argparse
|
|
355
|
+
>>> args = argparse.Namespace(
|
|
356
|
+
... datafile="data1.txt,data2.txt",
|
|
357
|
+
... measurementlist="meas_list.txt",
|
|
358
|
+
... outputroot="output",
|
|
359
|
+
... debug=False,
|
|
360
|
+
... deepdebug=False,
|
|
361
|
+
... demedian=False,
|
|
362
|
+
... demean=False,
|
|
363
|
+
... nocache=False
|
|
364
|
+
... )
|
|
365
|
+
>>> calctexticc(args)
|
|
366
|
+
"""
|
|
175
367
|
runstarttime = time.time()
|
|
176
368
|
|
|
177
369
|
datafiles = (args.datafile).split(",")
|
|
@@ -297,4 +489,4 @@ def calctexticc(args):
|
|
|
297
489
|
|
|
298
490
|
runendtime = time.time()
|
|
299
491
|
thecommandfilelines = makdcommandlinelist(sys.argv, runstarttime, runendtime, extra=extraline)
|
|
300
|
-
tide_io.writevec(thecommandfilelines, args.outputroot + "_commandline.txt")
|
|
492
|
+
tide_io.writevec(np.asarray(thecommandfilelines), args.outputroot + "_commandline.txt")
|