rapidtide 3.1__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/OrthoImageItem.py +4 -4
- rapidtide/_version.py +3 -3
- rapidtide/calccoherence.py +4 -4
- rapidtide/calcnullsimfunc.py +2 -5
- rapidtide/calcsimfunc.py +1 -4
- rapidtide/correlate.py +130 -127
- rapidtide/data/examples/src/testfmri +41 -9
- rapidtide/data/examples/src/testhappy +8 -8
- rapidtide/dlfilter.py +21 -22
- rapidtide/dlfiltertorch.py +18 -19
- rapidtide/filter.py +4 -4
- rapidtide/fit.py +18 -18
- rapidtide/happy_supportfuncs.py +84 -82
- rapidtide/helper_classes.py +2 -2
- rapidtide/io.py +88 -83
- rapidtide/linfitfiltpass.py +30 -49
- rapidtide/makelaggedtcs.py +11 -16
- rapidtide/maskutil.py +30 -14
- rapidtide/miscmath.py +2 -2
- rapidtide/patchmatch.py +10 -11
- rapidtide/peakeval.py +1 -3
- rapidtide/ppgproc.py +3 -3
- rapidtide/qualitycheck.py +2 -2
- rapidtide/refinedelay.py +12 -3
- rapidtide/refineregressor.py +20 -29
- rapidtide/scripts/showxcorr_legacy.py +7 -7
- rapidtide/scripts/stupidramtricks.py +15 -17
- rapidtide/simFuncClasses.py +2 -2
- rapidtide/simfuncfit.py +27 -41
- rapidtide/tests/test_cleanregressor.py +1 -2
- rapidtide/tests/test_fullrunhappy_v3.py +11 -5
- rapidtide/tests/test_fullrunhappy_v4.py +9 -1
- rapidtide/tests/test_getparsers.py +11 -3
- rapidtide/tests/test_refinedelay.py +0 -1
- rapidtide/tests/test_simroundtrip.py +8 -0
- rapidtide/tests/test_stcorrelate.py +3 -1
- rapidtide/util.py +6 -6
- rapidtide/voxelData.py +1 -1
- rapidtide/wiener.py +122 -16
- rapidtide/wiener2.py +3 -3
- rapidtide/workflows/applyppgproc.py +33 -15
- rapidtide/workflows/calcSimFuncMap.py +11 -22
- rapidtide/workflows/ccorrica.py +4 -2
- rapidtide/workflows/cleanregressor.py +6 -11
- rapidtide/workflows/delayvar.py +8 -13
- rapidtide/workflows/fitSimFuncMap.py +2 -9
- rapidtide/workflows/happy.py +6 -6
- rapidtide/workflows/happy_parser.py +36 -25
- rapidtide/workflows/pairproc.py +10 -2
- rapidtide/workflows/pixelcomp.py +1 -2
- rapidtide/workflows/rankimage.py +1 -1
- rapidtide/workflows/rapidtide.py +98 -63
- rapidtide/workflows/refineDelayMap.py +7 -6
- rapidtide/workflows/refineRegressor.py +6 -16
- rapidtide/workflows/regressfrommaps.py +9 -6
- rapidtide/workflows/retrolagtcs.py +5 -7
- rapidtide/workflows/retroregress.py +11 -17
- rapidtide/workflows/roisummarize.py +11 -10
- rapidtide/workflows/showarbcorr.py +2 -2
- rapidtide/workflows/showxcorrx.py +6 -6
- rapidtide/workflows/simdata.py +31 -31
- rapidtide/workflows/spatialmi.py +0 -1
- rapidtide/workflows/tidepool.py +6 -4
- {rapidtide-3.1.dist-info → rapidtide-3.1.1.dist-info}/METADATA +8 -7
- {rapidtide-3.1.dist-info → rapidtide-3.1.1.dist-info}/RECORD +69 -70
- rapidtide/wiener_doc.py +0 -255
- {rapidtide-3.1.dist-info → rapidtide-3.1.1.dist-info}/WHEEL +0 -0
- {rapidtide-3.1.dist-info → rapidtide-3.1.1.dist-info}/entry_points.txt +0 -0
- {rapidtide-3.1.dist-info → rapidtide-3.1.1.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.1.dist-info → rapidtide-3.1.1.dist-info}/top_level.txt +0 -0
rapidtide/linfitfiltpass.py
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
#
|
|
18
18
|
#
|
|
19
|
-
from typing import Any
|
|
19
|
+
from typing import Any
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
from numpy.typing import NDArray
|
|
@@ -33,9 +33,8 @@ def _procOneRegressionFitItem(
|
|
|
33
33
|
vox: int,
|
|
34
34
|
theevs: NDArray,
|
|
35
35
|
thedata: NDArray,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
) -> tuple[int, Any, Any, Any, Any, Any, NDArray, NDArray]:
|
|
36
|
+
rt_floattype: np.dtype = np.float64,
|
|
37
|
+
) -> tuple[int, float, float, float, float | NDArray, Any, NDArray, NDArray]:
|
|
39
38
|
"""
|
|
40
39
|
Perform single regression fit on voxel data and return fit results.
|
|
41
40
|
|
|
@@ -47,28 +46,26 @@ def _procOneRegressionFitItem(
|
|
|
47
46
|
----------
|
|
48
47
|
vox : int
|
|
49
48
|
Voxel index.
|
|
50
|
-
theevs :
|
|
49
|
+
theevs : NDArray
|
|
51
50
|
Experimental design matrix. If 2D, dimension 0 is number of points,
|
|
52
51
|
dimension 1 is number of evs.
|
|
53
|
-
thedata :
|
|
52
|
+
thedata : NDArray
|
|
54
53
|
Dependent variable data corresponding to the evs.
|
|
55
|
-
rt_floatset : type, optional
|
|
56
|
-
Data type for floating-point results, default is ``np.float64``.
|
|
57
54
|
rt_floattype : str, optional
|
|
58
|
-
String representation of the floating-point type, default is ``
|
|
55
|
+
String representation of the floating-point type, default is ``np.float64``.
|
|
59
56
|
|
|
60
57
|
Returns
|
|
61
58
|
-------
|
|
62
|
-
tuple[int,
|
|
59
|
+
tuple[int, float, float, float, float, Any, NDArray, NDArray]
|
|
63
60
|
A tuple containing:
|
|
64
61
|
- voxel index (`int`)
|
|
65
|
-
- intercept term (`
|
|
66
|
-
- signed square root of R-squared (`
|
|
67
|
-
- R-squared value (`
|
|
68
|
-
- fit coefficients (`
|
|
62
|
+
- intercept term (`float`)
|
|
63
|
+
- signed square root of R-squared (`float`)
|
|
64
|
+
- R-squared value (`float`)
|
|
65
|
+
- fit coefficients (`float` or `NDArray`)
|
|
69
66
|
- normalized fit coefficients (`Any`)
|
|
70
|
-
- data removed by fitting (`
|
|
71
|
-
- residuals (`
|
|
67
|
+
- data removed by fitting (`NDArray`)
|
|
68
|
+
- residuals (`NDArray`)
|
|
72
69
|
|
|
73
70
|
Notes
|
|
74
71
|
-----
|
|
@@ -80,7 +77,6 @@ def _procOneRegressionFitItem(
|
|
|
80
77
|
Examples
|
|
81
78
|
--------
|
|
82
79
|
>>> import numpy as np
|
|
83
|
-
>>> from tide_fit import mlregress
|
|
84
80
|
>>> theevs = np.array([[1, 2], [3, 4], [5, 6]], dtype=np.float64)
|
|
85
81
|
>>> thedata = np.array([1, 2, 3], dtype=np.float64)
|
|
86
82
|
>>> result = _procOneRegressionFitItem(0, theevs, thedata)
|
|
@@ -92,31 +88,31 @@ def _procOneRegressionFitItem(
|
|
|
92
88
|
if theevs.ndim > 1:
|
|
93
89
|
if thefit is None:
|
|
94
90
|
thefit = np.matrix(np.zeros((1, theevs.shape[1] + 1), dtype=rt_floattype))
|
|
95
|
-
fitcoeffs =
|
|
91
|
+
fitcoeffs = (thefit[0, 1:]).astype(rt_floattype)
|
|
96
92
|
if fitcoeffs[0, 0] < 0.0:
|
|
97
93
|
coeffsign = -1.0
|
|
98
94
|
else:
|
|
99
95
|
coeffsign = 1.0
|
|
100
96
|
datatoremove = theevs[:, 0] * 0.0
|
|
101
97
|
for j in range(theevs.shape[1]):
|
|
102
|
-
datatoremove +=
|
|
98
|
+
datatoremove += (thefit[0, 1 + j] * theevs[:, j]).astype(rt_floattype)
|
|
103
99
|
if np.any(fitcoeffs) != 0.0:
|
|
104
100
|
pass
|
|
105
101
|
else:
|
|
106
102
|
R2 = 0.0
|
|
107
103
|
return (
|
|
108
104
|
vox,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
thefit[0, 0],
|
|
106
|
+
coeffsign * np.sqrt(R2),
|
|
107
|
+
R2,
|
|
112
108
|
fitcoeffs,
|
|
113
|
-
|
|
109
|
+
(thefit[0, 1:] / thefit[0, 0]).astype(rt_floattype),
|
|
114
110
|
datatoremove,
|
|
115
|
-
|
|
111
|
+
(thedata - datatoremove).astype(rt_floattype),
|
|
116
112
|
)
|
|
117
113
|
else:
|
|
118
|
-
fitcoeff =
|
|
119
|
-
datatoremove =
|
|
114
|
+
fitcoeff = (thefit[0, 1]).astype(rt_floattype)
|
|
115
|
+
datatoremove = (fitcoeff * theevs).astype(rt_floattype)
|
|
120
116
|
if fitcoeff < 0.0:
|
|
121
117
|
coeffsign = -1.0
|
|
122
118
|
else:
|
|
@@ -125,13 +121,13 @@ def _procOneRegressionFitItem(
|
|
|
125
121
|
R2 = 0.0
|
|
126
122
|
return (
|
|
127
123
|
vox,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
thefit[0, 0],
|
|
125
|
+
coeffsign * np.sqrt(R2),
|
|
126
|
+
R2,
|
|
131
127
|
fitcoeff,
|
|
132
|
-
|
|
128
|
+
(thefit[0, 1] / thefit[0, 0]).astype(rt_floattype),
|
|
133
129
|
datatoremove,
|
|
134
|
-
|
|
130
|
+
(thedata - datatoremove).astype(rt_floattype),
|
|
135
131
|
)
|
|
136
132
|
|
|
137
133
|
|
|
@@ -146,7 +142,7 @@ def linfitfiltpass(
|
|
|
146
142
|
fitcoeff: NDArray | None,
|
|
147
143
|
fitNorm: NDArray | None,
|
|
148
144
|
datatoremove: NDArray | None,
|
|
149
|
-
filtereddata: NDArray,
|
|
145
|
+
filtereddata: NDArray | None,
|
|
150
146
|
nprocs: int = 1,
|
|
151
147
|
alwaysmultiproc: bool = False,
|
|
152
148
|
constantevs: bool = False,
|
|
@@ -155,8 +151,7 @@ def linfitfiltpass(
|
|
|
155
151
|
procbyvoxel: bool = True,
|
|
156
152
|
showprogressbar: bool = True,
|
|
157
153
|
chunksize: int = 1000,
|
|
158
|
-
|
|
159
|
-
rt_floattype: str = "float64",
|
|
154
|
+
rt_floattype: np.dtype = np.float64,
|
|
160
155
|
verbose: bool = True,
|
|
161
156
|
debug: bool = False,
|
|
162
157
|
) -> int:
|
|
@@ -207,10 +202,8 @@ def linfitfiltpass(
|
|
|
207
202
|
If True, display a progress bar during processing.
|
|
208
203
|
chunksize : int, default: 1000
|
|
209
204
|
Size of chunks for multiprocessing.
|
|
210
|
-
|
|
205
|
+
rt_floattype : str, default: np.float64
|
|
211
206
|
Data type for internal floating-point calculations.
|
|
212
|
-
rt_floattype : str, default: "float64"
|
|
213
|
-
String representation of the floating-point data type.
|
|
214
207
|
verbose : bool, default: True
|
|
215
208
|
If True, print verbose output.
|
|
216
209
|
debug : bool, default: False
|
|
@@ -303,7 +296,6 @@ def linfitfiltpass(
|
|
|
303
296
|
val,
|
|
304
297
|
theevs,
|
|
305
298
|
fmri_data[val, :],
|
|
306
|
-
rt_floatset=rt_floatset,
|
|
307
299
|
rt_floattype=rt_floattype,
|
|
308
300
|
)
|
|
309
301
|
)
|
|
@@ -313,7 +305,6 @@ def linfitfiltpass(
|
|
|
313
305
|
val,
|
|
314
306
|
theevs[val, :],
|
|
315
307
|
fmri_data[val, :],
|
|
316
|
-
rt_floatset=rt_floatset,
|
|
317
308
|
rt_floattype=rt_floattype,
|
|
318
309
|
)
|
|
319
310
|
)
|
|
@@ -324,7 +315,6 @@ def linfitfiltpass(
|
|
|
324
315
|
val,
|
|
325
316
|
theevs,
|
|
326
317
|
fmri_data[:, val],
|
|
327
|
-
rt_floatset=rt_floatset,
|
|
328
318
|
rt_floattype=rt_floattype,
|
|
329
319
|
)
|
|
330
320
|
)
|
|
@@ -334,7 +324,6 @@ def linfitfiltpass(
|
|
|
334
324
|
val,
|
|
335
325
|
theevs[:, val],
|
|
336
326
|
fmri_data[:, val],
|
|
337
|
-
rt_floatset=rt_floatset,
|
|
338
327
|
rt_floattype=rt_floattype,
|
|
339
328
|
)
|
|
340
329
|
)
|
|
@@ -449,7 +438,6 @@ def linfitfiltpass(
|
|
|
449
438
|
vox,
|
|
450
439
|
theevs,
|
|
451
440
|
thedata,
|
|
452
|
-
rt_floatset=rt_floatset,
|
|
453
441
|
rt_floattype=rt_floattype,
|
|
454
442
|
)
|
|
455
443
|
elif coefficientsonly:
|
|
@@ -467,7 +455,6 @@ def linfitfiltpass(
|
|
|
467
455
|
vox,
|
|
468
456
|
theevs[vox, :],
|
|
469
457
|
thedata,
|
|
470
|
-
rt_floatset=rt_floatset,
|
|
471
458
|
rt_floattype=rt_floattype,
|
|
472
459
|
)
|
|
473
460
|
else:
|
|
@@ -484,7 +471,6 @@ def linfitfiltpass(
|
|
|
484
471
|
vox,
|
|
485
472
|
theevs,
|
|
486
473
|
thedata,
|
|
487
|
-
rt_floatset=rt_floatset,
|
|
488
474
|
rt_floattype=rt_floattype,
|
|
489
475
|
)
|
|
490
476
|
else:
|
|
@@ -501,7 +487,6 @@ def linfitfiltpass(
|
|
|
501
487
|
vox,
|
|
502
488
|
theevs[vox, :],
|
|
503
489
|
thedata,
|
|
504
|
-
rt_floatset=rt_floatset,
|
|
505
490
|
rt_floattype=rt_floattype,
|
|
506
491
|
)
|
|
507
492
|
itemstotal += 1
|
|
@@ -528,7 +513,6 @@ def linfitfiltpass(
|
|
|
528
513
|
timepoint,
|
|
529
514
|
theevs,
|
|
530
515
|
thedata,
|
|
531
|
-
rt_floatset=rt_floatset,
|
|
532
516
|
rt_floattype=rt_floattype,
|
|
533
517
|
)
|
|
534
518
|
elif coefficientsonly:
|
|
@@ -546,7 +530,6 @@ def linfitfiltpass(
|
|
|
546
530
|
timepoint,
|
|
547
531
|
theevs[:, timepoint],
|
|
548
532
|
thedata,
|
|
549
|
-
rt_floatset=rt_floatset,
|
|
550
533
|
rt_floattype=rt_floattype,
|
|
551
534
|
)
|
|
552
535
|
else:
|
|
@@ -563,7 +546,6 @@ def linfitfiltpass(
|
|
|
563
546
|
timepoint,
|
|
564
547
|
theevs,
|
|
565
548
|
thedata,
|
|
566
|
-
rt_floatset=rt_floatset,
|
|
567
549
|
rt_floattype=rt_floattype,
|
|
568
550
|
)
|
|
569
551
|
else:
|
|
@@ -580,7 +562,6 @@ def linfitfiltpass(
|
|
|
580
562
|
timepoint,
|
|
581
563
|
theevs[:, timepoint],
|
|
582
564
|
thedata,
|
|
583
|
-
rt_floatset=rt_floatset,
|
|
584
565
|
rt_floattype=rt_floattype,
|
|
585
566
|
)
|
|
586
567
|
|
rapidtide/makelaggedtcs.py
CHANGED
|
@@ -49,7 +49,7 @@ def _procOneVoxelMakelagtc(
|
|
|
49
49
|
3. `timeaxis` - Time axis array for evaluation
|
|
50
50
|
**kwargs : Any
|
|
51
51
|
Additional keyword arguments that can override default options:
|
|
52
|
-
- `
|
|
52
|
+
- `rt_floattype` : float type for computations (default: np.float64)
|
|
53
53
|
- `debug` : boolean for debug printing (default: False)
|
|
54
54
|
|
|
55
55
|
Returns
|
|
@@ -82,11 +82,11 @@ def _procOneVoxelMakelagtc(
|
|
|
82
82
|
"""
|
|
83
83
|
# unpack arguments
|
|
84
84
|
options = {
|
|
85
|
-
"
|
|
85
|
+
"rt_floattype": np.float64,
|
|
86
86
|
"debug": False,
|
|
87
87
|
}
|
|
88
88
|
options.update(kwargs)
|
|
89
|
-
|
|
89
|
+
rt_floattype = options["rt_floattype"]
|
|
90
90
|
debug = options["debug"]
|
|
91
91
|
(lagtcgenerator, thelag, timeaxis) = voxelargs
|
|
92
92
|
if debug:
|
|
@@ -94,7 +94,7 @@ def _procOneVoxelMakelagtc(
|
|
|
94
94
|
|
|
95
95
|
# question - should maxlag be added or subtracted? As of 10/18, it is subtracted
|
|
96
96
|
# potential answer - tried adding, results are terrible.
|
|
97
|
-
thelagtc =
|
|
97
|
+
thelagtc = (lagtcgenerator.yfromx(timeaxis - thelag)).astype(rt_floattype)
|
|
98
98
|
|
|
99
99
|
return (
|
|
100
100
|
vox,
|
|
@@ -189,8 +189,7 @@ def makelaggedtcs(
|
|
|
189
189
|
alwaysmultiproc: bool = False,
|
|
190
190
|
showprogressbar: bool = True,
|
|
191
191
|
chunksize: int = 1000,
|
|
192
|
-
|
|
193
|
-
rt_floattype: str = "float64",
|
|
192
|
+
rt_floattype: np.dtype = np.float64,
|
|
194
193
|
debug: bool = False,
|
|
195
194
|
) -> int:
|
|
196
195
|
"""
|
|
@@ -204,14 +203,14 @@ def makelaggedtcs(
|
|
|
204
203
|
----------
|
|
205
204
|
lagtcgenerator : Any
|
|
206
205
|
A callable or object that generates lagged timecourses for a single voxel.
|
|
207
|
-
timeaxis :
|
|
206
|
+
timeaxis : NDArray
|
|
208
207
|
1D array representing the time axis (e.g., TRs or time points).
|
|
209
|
-
lagmask :
|
|
208
|
+
lagmask : NDArray
|
|
210
209
|
3D or 4D boolean or integer array defining the voxels to process.
|
|
211
210
|
Non-zero entries indicate voxels to be processed.
|
|
212
|
-
lagtimes :
|
|
211
|
+
lagtimes : NDArray
|
|
213
212
|
1D array of lag times (in seconds or time units) to be applied.
|
|
214
|
-
lagtc :
|
|
213
|
+
lagtc : NDArray
|
|
215
214
|
4D array of shape (ntimepoints, nvoxels, nlags) to store the output lagged
|
|
216
215
|
timecourses. This is updated in-place.
|
|
217
216
|
LGR : logging.Logger, optional
|
|
@@ -226,12 +225,9 @@ def makelaggedtcs(
|
|
|
226
225
|
chunksize : int, optional
|
|
227
226
|
Size of chunks to process in each step when using multiprocessing.
|
|
228
227
|
Default is 1000.
|
|
229
|
-
rt_floatset : type, optional
|
|
230
|
-
The floating-point type to use for internal computations.
|
|
231
|
-
Default is `np.float64`.
|
|
232
228
|
rt_floattype : str, optional
|
|
233
229
|
String representation of the floating-point type.
|
|
234
|
-
Default is
|
|
230
|
+
Default is `np.float64`.
|
|
235
231
|
debug : bool, optional
|
|
236
232
|
If True, print debug information. Default is False.
|
|
237
233
|
|
|
@@ -249,7 +245,6 @@ def makelaggedtcs(
|
|
|
249
245
|
Examples
|
|
250
246
|
--------
|
|
251
247
|
>>> import numpy as np
|
|
252
|
-
>>> from some_module import makelaggedtcs
|
|
253
248
|
>>> timeaxis = np.arange(100)
|
|
254
249
|
>>> lagtimes = np.array([0, 1, 2])
|
|
255
250
|
>>> lagmask = np.ones((10, 10, 10), dtype=bool)
|
|
@@ -294,7 +289,7 @@ def makelaggedtcs(
|
|
|
294
289
|
alwaysmultiproc,
|
|
295
290
|
showprogressbar,
|
|
296
291
|
chunksize,
|
|
297
|
-
|
|
292
|
+
rt_floattype=rt_floattype,
|
|
298
293
|
)
|
|
299
294
|
if LGR is not None:
|
|
300
295
|
LGR.info(f"\nLagged timecourses created for {volumetotal} voxels")
|
rapidtide/maskutil.py
CHANGED
|
@@ -44,7 +44,7 @@ def resampmask(themask: ArrayLike, thetargetres: float) -> NDArray:
|
|
|
44
44
|
|
|
45
45
|
Returns
|
|
46
46
|
-------
|
|
47
|
-
|
|
47
|
+
NDArray
|
|
48
48
|
Resampled mask array with the specified target resolution.
|
|
49
49
|
|
|
50
50
|
Notes
|
|
@@ -445,7 +445,7 @@ def getregionsignal(
|
|
|
445
445
|
signalgenmethod: str = "sum",
|
|
446
446
|
pcacomponents: Union[float, str] = 0.8,
|
|
447
447
|
signame: str = "global mean",
|
|
448
|
-
|
|
448
|
+
rt_floattype: type = np.float64,
|
|
449
449
|
debug: bool = False,
|
|
450
450
|
) -> Tuple[NDArray, NDArray]:
|
|
451
451
|
"""
|
|
@@ -482,7 +482,7 @@ def getregionsignal(
|
|
|
482
482
|
if "mle", uses maximum likelihood estimation. Default is 0.8.
|
|
483
483
|
signame : str, optional
|
|
484
484
|
Name of the signal for logging purposes. Default is "global mean".
|
|
485
|
-
|
|
485
|
+
rt_floattype : type, optional
|
|
486
486
|
Data type for internal computations. Default is np.float64.
|
|
487
487
|
debug : bool, optional
|
|
488
488
|
If True, print debugging information. Default is False.
|
|
@@ -522,7 +522,7 @@ def getregionsignal(
|
|
|
522
522
|
themask = themask * (1 - excludemask)
|
|
523
523
|
|
|
524
524
|
# combine all the voxels using one of the three methods
|
|
525
|
-
globalmean =
|
|
525
|
+
globalmean = (indata[0, :]).astype(rt_floattype)
|
|
526
526
|
thesize = np.shape(themask)
|
|
527
527
|
numvoxelsused = int(np.sum(np.where(themask > 0.0, 1, 0)))
|
|
528
528
|
selectedvoxels = indata[np.where(themask > 0.0), :][0]
|
|
@@ -532,36 +532,49 @@ def getregionsignal(
|
|
|
532
532
|
if signalgenmethod == "sum":
|
|
533
533
|
globalmean = np.mean(selectedvoxels, axis=0)
|
|
534
534
|
globalmean -= np.mean(globalmean)
|
|
535
|
+
if debug:
|
|
536
|
+
print("Sum method")
|
|
537
|
+
print(f"getregionsignal: {globalmean.shape=}")
|
|
535
538
|
elif signalgenmethod == "meanscale":
|
|
536
539
|
themean = np.mean(indata, axis=1)
|
|
537
540
|
for vox in range(0, thesize[0]):
|
|
538
541
|
if themask[vox] > 0.0:
|
|
539
542
|
if themean[vox] != 0.0:
|
|
540
543
|
globalmean += indata[vox, :] / themean[vox] - 1.0
|
|
544
|
+
if debug:
|
|
545
|
+
print("Meanscale method")
|
|
546
|
+
print(f"getregionsignal: {globalmean.shape=}")
|
|
541
547
|
elif signalgenmethod == "pca":
|
|
542
548
|
themean = np.mean(indata, axis=1)
|
|
543
549
|
thevar = np.var(indata, axis=1)
|
|
544
|
-
scaledvoxels = selectedvoxels
|
|
550
|
+
scaledvoxels = np.zeros_like(selectedvoxels)
|
|
545
551
|
for vox in range(0, selectedvoxels.shape[0]):
|
|
546
552
|
scaledvoxels[vox, :] = selectedvoxels[vox, :] - themean[vox]
|
|
547
553
|
if thevar[vox] > 0.0:
|
|
548
554
|
scaledvoxels[vox, :] = selectedvoxels[vox, :] / thevar[vox]
|
|
549
555
|
try:
|
|
550
|
-
thefit = PCA(n_components=pcacomponents).fit(
|
|
556
|
+
thefit = PCA(n_components=pcacomponents).fit(scaledvoxels)
|
|
551
557
|
except ValueError:
|
|
552
558
|
if pcacomponents == "mle":
|
|
553
559
|
LGR.warning("mle estimation failed - falling back to pcacomponents=0.8")
|
|
554
|
-
thefit = PCA(n_components=0.8).fit(
|
|
560
|
+
thefit = PCA(n_components=0.8).fit(scaledvoxels)
|
|
555
561
|
else:
|
|
556
562
|
raise ValueError("unhandled math exception in PCA refinement - exiting")
|
|
557
563
|
|
|
558
564
|
varex = 100.0 * np.cumsum(thefit.explained_variance_ratio_)[len(thefit.components_) - 1]
|
|
559
|
-
thetransform = thefit.transform(np.transpose(scaledvoxels))
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
globalmean = np.mean(
|
|
565
|
+
# thetransform = thefit.transform(np.transpose(scaledvoxels))
|
|
566
|
+
thetransform = thefit.transform(scaledvoxels)
|
|
567
|
+
cleanedvoxels = thefit.inverse_transform(thetransform) * thevar[:, None]
|
|
568
|
+
globalmean = np.mean(cleanedvoxels, axis=0)
|
|
563
569
|
globalmean -= np.mean(globalmean)
|
|
564
570
|
if debug:
|
|
571
|
+
print("PCA method")
|
|
572
|
+
print(
|
|
573
|
+
f"getregionsignal: {cleanedvoxels.shape=}, {thetransform.shape=}, {scaledvoxels.shape=}, {globalmean.shape=}"
|
|
574
|
+
)
|
|
575
|
+
print(
|
|
576
|
+
f"getregionsignal: {(thefit.components_).shape=}, {thefit.n_samples_=}, {thefit.n_features_in_=}"
|
|
577
|
+
)
|
|
565
578
|
print(f"getregionsignal: {varex=}")
|
|
566
579
|
LGR.info(
|
|
567
580
|
f"Using {len(thefit.components_)} component(s), accounting for "
|
|
@@ -569,6 +582,9 @@ def getregionsignal(
|
|
|
569
582
|
)
|
|
570
583
|
elif signalgenmethod == "random":
|
|
571
584
|
globalmean = np.random.standard_normal(size=len(globalmean))
|
|
585
|
+
if debug:
|
|
586
|
+
print("Random method")
|
|
587
|
+
print(f"getregionsignal: {globalmean.shape=}")
|
|
572
588
|
else:
|
|
573
589
|
raise ValueError(f"illegal signal generation method: {signalgenmethod}")
|
|
574
590
|
LGR.info(f"used {numvoxelsused} voxels to calculate {signame} signal")
|
|
@@ -593,7 +609,7 @@ def saveregionaltimeseries(
|
|
|
593
609
|
suffix: str = "",
|
|
594
610
|
signalgenmethod: str = "sum",
|
|
595
611
|
pcacomponents: Union[float, str] = 0.8,
|
|
596
|
-
|
|
612
|
+
rt_floattype: type = np.float64,
|
|
597
613
|
debug: bool = False,
|
|
598
614
|
) -> Tuple[NDArray, NDArray]:
|
|
599
615
|
"""
|
|
@@ -632,7 +648,7 @@ def saveregionaltimeseries(
|
|
|
632
648
|
Method for generating the signal ('sum', 'mean', 'pca', etc.)
|
|
633
649
|
pcacomponents : Union[float, str], default=0.8
|
|
634
650
|
Number of PCA components to use (or fraction of variance explained)
|
|
635
|
-
|
|
651
|
+
rt_floattype : np.dtype, default=np.float64
|
|
636
652
|
Data type for floating point operations
|
|
637
653
|
debug : bool, default=False
|
|
638
654
|
If True, enables debug mode for additional logging
|
|
@@ -678,7 +694,7 @@ def saveregionaltimeseries(
|
|
|
678
694
|
signalgenmethod=signalgenmethod,
|
|
679
695
|
pcacomponents=pcacomponents,
|
|
680
696
|
signame=tcdesc,
|
|
681
|
-
|
|
697
|
+
rt_floattype=rt_floattype,
|
|
682
698
|
debug=debug,
|
|
683
699
|
)
|
|
684
700
|
tide_io.writebidstsv(
|
rapidtide/miscmath.py
CHANGED
|
@@ -565,12 +565,12 @@ def stdnormalize(vector: NDArray) -> NDArray:
|
|
|
565
565
|
|
|
566
566
|
Parameters
|
|
567
567
|
----------
|
|
568
|
-
vector :
|
|
568
|
+
vector : NDArray
|
|
569
569
|
Input vector to be standardized.
|
|
570
570
|
|
|
571
571
|
Returns
|
|
572
572
|
-------
|
|
573
|
-
|
|
573
|
+
NDArray
|
|
574
574
|
Standardized vector with zero mean and unit variance. If the input vector
|
|
575
575
|
has zero standard deviation, the demeaned vector is returned unchanged.
|
|
576
576
|
|
rapidtide/patchmatch.py
CHANGED
|
@@ -21,7 +21,6 @@ import math
|
|
|
21
21
|
import os
|
|
22
22
|
import sys
|
|
23
23
|
import warnings
|
|
24
|
-
from typing import Any
|
|
25
24
|
|
|
26
25
|
import numpy as np
|
|
27
26
|
from numpy.typing import NDArray
|
|
@@ -41,15 +40,15 @@ def interpolate_masked_voxels(
|
|
|
41
40
|
from the unmasked region. Supports boundary extrapolation and multiple interpolation methods.
|
|
42
41
|
|
|
43
42
|
Parameters:
|
|
44
|
-
data (
|
|
45
|
-
mask (
|
|
43
|
+
data (NDArray): A 3D numpy array containing the data.
|
|
44
|
+
mask (NDArray): A 3D binary numpy array of the same shape as `data`,
|
|
46
45
|
where 1 indicates masked voxels and 0 indicates unmasked voxels.
|
|
47
46
|
method (str): Interpolation method ('linear', 'nearest', or 'cubic').
|
|
48
47
|
extrapolate (bool): Whether to extrapolate values for masked voxels outside the convex hull
|
|
49
48
|
of the unmasked points.
|
|
50
49
|
|
|
51
50
|
Returns:
|
|
52
|
-
|
|
51
|
+
NDArray: A new 3D array with interpolated (and optionally extrapolated)
|
|
53
52
|
values replacing masked regions.
|
|
54
53
|
"""
|
|
55
54
|
if data.shape != mask.shape:
|
|
@@ -97,7 +96,7 @@ def get_bounding_box(mask: NDArray, value: int, buffer: int = 0) -> tuple[tuple,
|
|
|
97
96
|
|
|
98
97
|
Parameters
|
|
99
98
|
----------
|
|
100
|
-
mask :
|
|
99
|
+
mask : NDArray
|
|
101
100
|
A 3D binary mask where non-zero values indicate the masked region.
|
|
102
101
|
value : int
|
|
103
102
|
The masked region value to compute the bounding box for.
|
|
@@ -411,19 +410,19 @@ def _smooth_array(
|
|
|
411
410
|
|
|
412
411
|
Parameters
|
|
413
412
|
----------
|
|
414
|
-
arr : :class:`
|
|
413
|
+
arr : :class:`NDArray`
|
|
415
414
|
4D array, with image number as last dimension. 3D arrays are also
|
|
416
415
|
accepted.
|
|
417
416
|
|
|
418
|
-
affine : :class:`
|
|
417
|
+
affine : :class:`NDArray`
|
|
419
418
|
(4, 4) matrix, giving affine transformation for image. (3, 3) matrices
|
|
420
419
|
are also accepted (only these coefficients are used).
|
|
421
420
|
If `fwhm='fast'`, the affine is not used and can be None.
|
|
422
421
|
|
|
423
|
-
fwhm : scalar, :class:`
|
|
422
|
+
fwhm : scalar, :class:`NDArray`/:obj:`tuple`/:obj:`list`, 'fast' or None, optional
|
|
424
423
|
Smoothing strength, as a full-width at half maximum, in millimeters.
|
|
425
424
|
If a nonzero scalar is given, width is identical in all 3 directions.
|
|
426
|
-
A :class:`
|
|
425
|
+
A :class:`NDArray`, :obj:`tuple`, or :obj:`list` must have 3 elements,
|
|
427
426
|
giving the FWHM along each axis.
|
|
428
427
|
If any of the elements is zero or None, smoothing is not performed
|
|
429
428
|
along that axis.
|
|
@@ -443,7 +442,7 @@ def _smooth_array(
|
|
|
443
442
|
|
|
444
443
|
Returns
|
|
445
444
|
-------
|
|
446
|
-
:class:`
|
|
445
|
+
:class:`NDArray`
|
|
447
446
|
Filtered `arr`.
|
|
448
447
|
|
|
449
448
|
Notes
|
|
@@ -517,7 +516,7 @@ def difference_of_gaussian(
|
|
|
517
516
|
Parameters
|
|
518
517
|
----------
|
|
519
518
|
fdata : numpy.memmap from Niimg-like object
|
|
520
|
-
affine : :class:`
|
|
519
|
+
affine : :class:`NDArray`
|
|
521
520
|
(4, 4) matrix, giving affine transformation for image. (3, 3) matrices
|
|
522
521
|
are also accepted (only these coefficients are used).
|
|
523
522
|
fwhmNarrow : int
|
rapidtide/peakeval.py
CHANGED
|
@@ -79,8 +79,7 @@ def peakevalpass(
|
|
|
79
79
|
interptype: str = "univariate",
|
|
80
80
|
showprogressbar: bool = True,
|
|
81
81
|
chunksize: int = 1000,
|
|
82
|
-
|
|
83
|
-
rt_floattype: str = "float64",
|
|
82
|
+
rt_floattype: np.dtype = np.float64,
|
|
84
83
|
) -> tuple[int, dict]:
|
|
85
84
|
"""
|
|
86
85
|
|
|
@@ -100,7 +99,6 @@ def peakevalpass(
|
|
|
100
99
|
interptype
|
|
101
100
|
showprogressbar
|
|
102
101
|
chunksize
|
|
103
|
-
rt_floatset
|
|
104
102
|
rt_floattype
|
|
105
103
|
|
|
106
104
|
Returns
|
rapidtide/ppgproc.py
CHANGED
|
@@ -1623,7 +1623,7 @@ class HeartRateExtractor:
|
|
|
1623
1623
|
|
|
1624
1624
|
Parameters
|
|
1625
1625
|
----------
|
|
1626
|
-
ppg_signal :
|
|
1626
|
+
ppg_signal : NDArray
|
|
1627
1627
|
Input photoplethysmography (PPG) signal.
|
|
1628
1628
|
hr_range : tuple of float, optional
|
|
1629
1629
|
Expected heart rate range in beats per minute (BPM). Default is (40.0, 180.0).
|
|
@@ -1636,9 +1636,9 @@ class HeartRateExtractor:
|
|
|
1636
1636
|
frequency : float or None
|
|
1637
1637
|
Dominant frequency in Hz. Returns None if no valid peak is found in the
|
|
1638
1638
|
specified range.
|
|
1639
|
-
psd :
|
|
1639
|
+
psd : NDArray
|
|
1640
1640
|
Power spectral density values corresponding to the frequency array.
|
|
1641
|
-
freqs :
|
|
1641
|
+
freqs : NDArray
|
|
1642
1642
|
Frequency values corresponding to the power spectral density.
|
|
1643
1643
|
|
|
1644
1644
|
Notes
|
rapidtide/qualitycheck.py
CHANGED
|
@@ -226,9 +226,9 @@ def gethistmetrics(
|
|
|
226
226
|
|
|
227
227
|
Parameters
|
|
228
228
|
----------
|
|
229
|
-
themap :
|
|
229
|
+
themap : NDArray
|
|
230
230
|
The input data array from which metrics are computed.
|
|
231
|
-
themask :
|
|
231
|
+
themask : NDArray
|
|
232
232
|
A boolean or numeric mask array used to select valid data points.
|
|
233
233
|
thedict : dict[str, Any]
|
|
234
234
|
Dictionary to store computed metrics. Keys will be updated with statistical
|
rapidtide/refinedelay.py
CHANGED
|
@@ -20,7 +20,7 @@ from typing import Any, Callable, Optional, Tuple, Union
|
|
|
20
20
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
import numpy.polynomial.polynomial as poly
|
|
23
|
-
from numpy.typing import
|
|
23
|
+
from numpy.typing import NDArray
|
|
24
24
|
from scipy.interpolate import CubicSpline, UnivariateSpline
|
|
25
25
|
from scipy.ndimage import median_filter
|
|
26
26
|
from statsmodels.robust import mad
|
|
@@ -101,7 +101,7 @@ def trainratiotooffset(
|
|
|
101
101
|
----------
|
|
102
102
|
lagtcgenerator : Any
|
|
103
103
|
An object that provides the `yfromx` method for generating lagged time courses.
|
|
104
|
-
timeaxis :
|
|
104
|
+
timeaxis : NDArray
|
|
105
105
|
The time axis (in seconds) for the fMRI data.
|
|
106
106
|
outputname : str
|
|
107
107
|
Base name for output files (e.g., BIDS entity).
|
|
@@ -555,6 +555,7 @@ def getderivratios(
|
|
|
555
555
|
TimingLGR: Optional[Any],
|
|
556
556
|
optiondict: dict,
|
|
557
557
|
regressderivs: int = 1,
|
|
558
|
+
timemask: Optional[NDArray] = None,
|
|
558
559
|
starttr: Optional[int] = None,
|
|
559
560
|
endtr: Optional[int] = None,
|
|
560
561
|
debug: bool = False,
|
|
@@ -611,6 +612,8 @@ def getderivratios(
|
|
|
611
612
|
Dictionary of options for regression and processing.
|
|
612
613
|
regressderivs : int, optional
|
|
613
614
|
Number of derivative regressors to include (default is 1).
|
|
615
|
+
timemask : NDArray, optional
|
|
616
|
+
Mask of timepoints to include in regression filtering.
|
|
614
617
|
starttr : Optional[int], optional
|
|
615
618
|
Start timepoint for processing (default is 0).
|
|
616
619
|
endtr : Optional[int], optional
|
|
@@ -672,6 +675,11 @@ def getderivratios(
|
|
|
672
675
|
print(f"\t{starttr=}")
|
|
673
676
|
print(f"\t{endtr=}")
|
|
674
677
|
|
|
678
|
+
if timemask is not None:
|
|
679
|
+
trimmedtimemask = timemask[starttr:endtr]
|
|
680
|
+
else:
|
|
681
|
+
trimmedtimemask = None
|
|
682
|
+
|
|
675
683
|
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
676
684
|
fmri_data_valid[:, starttr:endtr],
|
|
677
685
|
validvoxels,
|
|
@@ -701,6 +709,7 @@ def getderivratios(
|
|
|
701
709
|
showprogressbar=optiondict["showprogressbar"],
|
|
702
710
|
alwaysmultiproc=optiondict["alwaysmultiproc"],
|
|
703
711
|
coefficientsonly=True,
|
|
712
|
+
timemask=trimmedtimemask,
|
|
704
713
|
debug=debug,
|
|
705
714
|
)
|
|
706
715
|
|
|
@@ -726,7 +735,7 @@ def filterderivratios(
|
|
|
726
735
|
patchthresh: float = 3.0,
|
|
727
736
|
gausssigma: float = 0,
|
|
728
737
|
filetype: str = "nifti",
|
|
729
|
-
rt_floattype:
|
|
738
|
+
rt_floattype: np.dtype = np.float64,
|
|
730
739
|
verbose: bool = True,
|
|
731
740
|
debug: bool = False,
|
|
732
741
|
) -> Tuple[NDArray, NDArray, float]:
|