rapidtide 3.0.10__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 +1053 -47
- 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 +30 -1
- 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/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm.nii.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm_mask.nii.gz +0 -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 +813 -201
- rapidtide/workflows/happy2std.py +144 -12
- rapidtide/workflows/happy_parser.py +149 -8
- 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 +2972 -133
- rapidtide/workflows/utils.py +19 -14
- rapidtide/workflows/utils_doc.py +293 -0
- rapidtide/workflows/variabilityizer.py +116 -3
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/METADATA +10 -9
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/RECORD +141 -122
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/entry_points.txt +1 -0
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/WHEEL +0 -0
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import numpy as np
|
|
5
|
+
import statsmodels.api as sma
|
|
6
|
+
import statsmodels.tsa.stattools as smts
|
|
7
|
+
from scipy import signal
|
|
8
|
+
from statsmodels.tsa.ar_model import AutoReg
|
|
9
|
+
|
|
10
|
+
import rapidtide.io as tide_io
|
|
11
|
+
|
|
12
|
+
debug = True
|
|
13
|
+
insamplerate, instarttime, incolumns, indata, incompressed, incolsource = tide_io.readbidstsv(
|
|
14
|
+
"../dst/sub-RAPIDTIDETEST_desc-oversampledmovingregressor_timeseries.json",
|
|
15
|
+
neednotexist=False,
|
|
16
|
+
debug=debug,
|
|
17
|
+
)
|
|
18
|
+
print(f"{indata.shape=}")
|
|
19
|
+
nlags = 15
|
|
20
|
+
|
|
21
|
+
p = 2
|
|
22
|
+
d = 0
|
|
23
|
+
q = 0
|
|
24
|
+
|
|
25
|
+
for i in range(indata.shape[0]):
|
|
26
|
+
sigma_v, arcoefs, pacf, sigma, phi = smts.levinson_durbin(indata[i, :], nlags=nlags, isacov=False)
|
|
27
|
+
|
|
28
|
+
print(f"{sigma_v=}")
|
|
29
|
+
print(f"{arcoefs=}")
|
|
30
|
+
print(f"{pacf=}")
|
|
31
|
+
print(f"{sigma=}")
|
|
32
|
+
print(f"{phi=}")
|
|
33
|
+
|
|
34
|
+
plt.plot(arcoefs)
|
|
35
|
+
plt.show()
|
|
36
|
+
|
|
37
|
+
plt.plot(pacf)
|
|
38
|
+
plt.show()
|
|
39
|
+
|
|
40
|
+
plt.plot(sigma)
|
|
41
|
+
plt.show()
|
|
42
|
+
|
|
43
|
+
ar_model = AutoReg(indata[i, :], lags=nlags)
|
|
44
|
+
ar_fit = ar_model.fit()
|
|
45
|
+
ar_params = ar_fit.params
|
|
46
|
+
|
|
47
|
+
# The prewhitening filter coefficients are 1 for the numerator and
|
|
48
|
+
# (1, -ar_params[1]) for the denominator
|
|
49
|
+
b = [1]
|
|
50
|
+
a = np.insert(-ar_params[1:], 0, 1)
|
|
51
|
+
|
|
52
|
+
# 3. Apply the filter to prewhiten the signal
|
|
53
|
+
prewhitened_signal = signal.lfilter(b, a, indata[i, :])
|
|
54
|
+
plt.plot(indata[i, :] / np.std(indata[i, :]))
|
|
55
|
+
plt.plot(prewhitened_signal / np.std(prewhitened_signal))
|
|
56
|
+
plt.show()
|
|
@@ -41,7 +41,7 @@ alignedvec, maxdelay, maxval, failreason = tide_corr.aligntcwithref(
|
|
|
41
41
|
)
|
|
42
42
|
print(f"{maxdelay=}, {maxval=}, {failreason=}")
|
|
43
43
|
|
|
44
|
-
filteredvec, datatoremove, R, coffs = tide_fit.linfitfilt(fixedvec, alignedvec, debug=True)
|
|
44
|
+
filteredvec, datatoremove, R, coffs, dummy = tide_fit.linfitfilt(fixedvec, alignedvec, debug=True)
|
|
45
45
|
|
|
46
46
|
offset = 0.0
|
|
47
47
|
plt.plot(xaxis, fixedvec + offset)
|
|
@@ -14,8 +14,26 @@ rapidtide \
|
|
|
14
14
|
--nofitfilt \
|
|
15
15
|
--refinedelayeachpass \
|
|
16
16
|
--similaritymetric correlation \
|
|
17
|
+
--nonumba \
|
|
17
18
|
sub-RAPIDTIDETEST.nii.gz \
|
|
18
|
-
../dst/sub-
|
|
19
|
+
../dst/sub-RAPIDTIDETEST_nonumba
|
|
20
|
+
|
|
21
|
+
rapidtide \
|
|
22
|
+
--spatialfilt 2.5 \
|
|
23
|
+
--nprocs -1 \
|
|
24
|
+
--searchrange -7.5 30 \
|
|
25
|
+
--simcalcrange 50 -1 \
|
|
26
|
+
--outputlevel more \
|
|
27
|
+
--graymattermask sub-RAPIDTIDETEST_synthseg.nii.gz:SSEG_GRAY \
|
|
28
|
+
--brainmask sub-RAPIDTIDETEST_brainmask.nii.gz \
|
|
29
|
+
--whitemattermask sub-RAPIDTIDETEST_synthseg.nii.gz:SSEG_WHITE \
|
|
30
|
+
--csfmask sub-RAPIDTIDETEST_synthseg.nii.gz:SSEG_CSF \
|
|
31
|
+
--cleanrefined \
|
|
32
|
+
--nofitfilt \
|
|
33
|
+
--refinedelayeachpass \
|
|
34
|
+
--similaritymetric correlation \
|
|
35
|
+
sub-RAPIDTIDETEST.nii.gz \
|
|
36
|
+
../dst/sub-RAPIDTIDETEST_numba
|
|
19
37
|
|
|
20
38
|
#rapidtide \
|
|
21
39
|
#--spatialfilt 2.5 \
|
|
@@ -35,7 +35,7 @@ noisevec = noiseamp * np.random.rand(arrlen)
|
|
|
35
35
|
invec = datavec + noisevec
|
|
36
36
|
|
|
37
37
|
filtered, datatoremove, R, outcoffs, outintercept = tide_fit.linfitfilt(
|
|
38
|
-
invec, evs,
|
|
38
|
+
invec, evs, debug=True
|
|
39
39
|
)
|
|
40
40
|
|
|
41
41
|
incoffs = [amp1, amp2, amp3]
|
|
@@ -60,7 +60,7 @@ plt.plot(datavec - datatoremove + offset)
|
|
|
60
60
|
print(R)
|
|
61
61
|
plt.show()
|
|
62
62
|
|
|
63
|
-
filtered, datatoremove, R, coffs = tide_fit.linfitfilt(invec, evs[:, 0], debug=True)
|
|
63
|
+
filtered, datatoremove, R, coffs, dummy = tide_fit.linfitfilt(invec, evs[:, 0], debug=True)
|
|
64
64
|
|
|
65
65
|
"""
|
|
66
66
|
offset = 0.0
|
|
@@ -82,7 +82,7 @@ invec2 = (
|
|
|
82
82
|
+ noiseamp * np.random.rand(arrlen)
|
|
83
83
|
)
|
|
84
84
|
|
|
85
|
-
filtered, datatoremove, R, coffs = tide_fit.linfitfilt(invec2, evs, debug=True)
|
|
85
|
+
filtered, datatoremove, R, coffs, dummy = tide_fit.linfitfilt(invec2, evs, debug=True)
|
|
86
86
|
|
|
87
87
|
"""
|
|
88
88
|
offset = 0.0
|
|
@@ -118,7 +118,7 @@ print(R)
|
|
|
118
118
|
plt.show()
|
|
119
119
|
"""
|
|
120
120
|
|
|
121
|
-
filtered, datatoremove, R, coffs = tide_fit.linfitfilt(invec2, thenewevs, debug=True)
|
|
121
|
+
filtered, datatoremove, R, coffs, dummy = tide_fit.linfitfilt(invec2, thenewevs, debug=True)
|
|
122
122
|
"""
|
|
123
123
|
offset = 0.0
|
|
124
124
|
plt.plot(invec2 + offset)
|
|
@@ -140,7 +140,7 @@ alignedev, maxdelay, maxval, failreason = tide_corr.aligntcwithref(
|
|
|
140
140
|
verbose=True,
|
|
141
141
|
)
|
|
142
142
|
print(f"{maxdelay=}, {maxval=}, {failreason=}")
|
|
143
|
-
filtered, datatoremove, R, coffs = tide_fit.linfitfilt(invec3, alignedev, debug=True)
|
|
143
|
+
filtered, datatoremove, R, coffs, dummy = tide_fit.linfitfilt(invec3, alignedev, debug=True)
|
|
144
144
|
offset = 0.0
|
|
145
145
|
plt.plot(evs[:, 0])
|
|
146
146
|
offset += 1.0
|
|
@@ -69,8 +69,37 @@
|
|
|
69
69
|
#../dst/happy_mpdetrend_mpphaseproj_nocache \
|
|
70
70
|
#--nprocs -1
|
|
71
71
|
|
|
72
|
+
#happy \
|
|
73
|
+
#sub-HAPPYTEST.nii.gz \
|
|
74
|
+
#sub-HAPPYTEST.json \
|
|
75
|
+
#../dst/happy_mask \
|
|
76
|
+
#--processmask sub-HAPPYTEST_mask.nii.gz \
|
|
77
|
+
#--nprocs -1
|
|
78
|
+
|
|
79
|
+
# --motionfile sub-HAPPYTEST_mcf.par \
|
|
80
|
+
|
|
81
|
+
#happy \
|
|
82
|
+
#sub-HAPPYTEST.nii.gz \
|
|
83
|
+
#sub-HAPPYTEST.json \
|
|
84
|
+
#../dst/happy \
|
|
85
|
+
#--increaseoutputlevel \
|
|
86
|
+
#--model model_cnn_pytorch \
|
|
87
|
+
#--usepytorch \
|
|
88
|
+
#--nprocs -1
|
|
89
|
+
|
|
90
|
+
happy \
|
|
91
|
+
sub-HAPPYTEST.nii.gz \
|
|
92
|
+
sub-HAPPYTEST.json \
|
|
93
|
+
../dst/happy_pytorch \
|
|
94
|
+
--increaseoutputlevel \
|
|
95
|
+
--usenewvesselmethod \
|
|
96
|
+
--nprocs -1
|
|
97
|
+
|
|
72
98
|
happy \
|
|
73
99
|
sub-HAPPYTEST.nii.gz \
|
|
74
100
|
sub-HAPPYTEST.json \
|
|
75
|
-
../dst/
|
|
101
|
+
../dst/happy_tensorflow \
|
|
102
|
+
--increaseoutputlevel \
|
|
103
|
+
--usenewvesselmethod \
|
|
104
|
+
--usetensorflow \
|
|
76
105
|
--nprocs -1
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
applyppgproc \
|
|
4
|
+
../dst/happy_desc-slicerescardfromfmri_timeseries \
|
|
5
|
+
ppgtest \
|
|
6
|
+
--process_noise 0.001 \
|
|
7
|
+
--hr_estimate 65.0 \
|
|
8
|
+
--qual_thresh 0.7 \
|
|
9
|
+
--display --debug
|
|
10
|
+
|
|
11
|
+
applyppgproc \
|
|
12
|
+
../dst/happy_desc-stdrescardfromfmri_timeseries \
|
|
13
|
+
ppgtest \
|
|
14
|
+
--process_noise 0.001 \
|
|
15
|
+
--hr_estimate 65.0 \
|
|
16
|
+
--qual_thresh 0.7 \
|
|
17
|
+
--display --debug
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
for STOP in 2 3 4 5 6 7 8
|
|
4
|
+
do
|
|
5
|
+
filttc ../dst/happy_desc-stdrescardfromfmri_timeseries.json:cardiacfromfmri_25.0Hz \
|
|
6
|
+
../dst/stopfreq_${STOP} \
|
|
7
|
+
--filterfreqs 0.0 1.0 \
|
|
8
|
+
--filterstopfreqs 0.0 ${STOP}
|
|
9
|
+
done
|
|
10
|
+
|
|
11
|
+
showtc ../dst/stopfreq*.json --format separate
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
model_cnn_w060_l19_fn50_fl05_e025_t4.0_ct0.72_s20_d1_relu_normaligned: Prediction Error: 0.6981142062735153 Raw Error: 0.3174055677061575
|
|
Binary file
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dofft":false,
|
|
3
|
+
"dropout_rate":0.3,
|
|
4
|
+
"excludethresh":4.0,
|
|
5
|
+
"loss":[
|
|
6
|
+
0.30441974932999954,
|
|
7
|
+
0.18183457710591377,
|
|
8
|
+
0.16851514196375392,
|
|
9
|
+
0.16202728616720213,
|
|
10
|
+
0.15842841755073914,
|
|
11
|
+
0.1564911107478273,
|
|
12
|
+
0.15509463905571252,
|
|
13
|
+
0.15409289958448344,
|
|
14
|
+
0.15318550205312645,
|
|
15
|
+
0.15253183263581233,
|
|
16
|
+
0.15208946124896972,
|
|
17
|
+
0.15148001061784444,
|
|
18
|
+
0.1511366076229774,
|
|
19
|
+
0.15075672873619086,
|
|
20
|
+
0.15030987919196231,
|
|
21
|
+
0.15001051545245542,
|
|
22
|
+
0.14959304444363847,
|
|
23
|
+
0.1489250477134567,
|
|
24
|
+
0.14856653524837954,
|
|
25
|
+
0.1484835542405594,
|
|
26
|
+
0.14787971300050565,
|
|
27
|
+
0.14812416058430558,
|
|
28
|
+
0.14733259612854405,
|
|
29
|
+
0.14742844921770373,
|
|
30
|
+
0.14675265647906208
|
|
31
|
+
],
|
|
32
|
+
"modelname":"model_cnn_w060_l19_fn50_fl05_e025_t4.0_ct0.72_s20_d1_relu_normaligned",
|
|
33
|
+
"nettype":"cnn",
|
|
34
|
+
"num_epochs":25,
|
|
35
|
+
"num_layers":19,
|
|
36
|
+
"prediction_error":0.6981142062735153,
|
|
37
|
+
"raw_error":0.3174055677061575,
|
|
38
|
+
"train_arch":"darwin",
|
|
39
|
+
"usebadpts":false,
|
|
40
|
+
"val_loss":[
|
|
41
|
+
0.15530714135745477,
|
|
42
|
+
0.15717816753634092,
|
|
43
|
+
0.1481180809695145,
|
|
44
|
+
0.1516780706315205,
|
|
45
|
+
0.13553270055302258,
|
|
46
|
+
0.1337960820259719,
|
|
47
|
+
0.13654720783233643,
|
|
48
|
+
0.1334461883738123,
|
|
49
|
+
0.12724334592449255,
|
|
50
|
+
0.12903443785576985,
|
|
51
|
+
0.12892387956380844,
|
|
52
|
+
0.12977149404328445,
|
|
53
|
+
0.13186248186333427,
|
|
54
|
+
0.12963887345174263,
|
|
55
|
+
0.12839905814877872,
|
|
56
|
+
0.12711975148011898,
|
|
57
|
+
0.13404886912682962,
|
|
58
|
+
0.1291459808575696,
|
|
59
|
+
0.12991093941803636,
|
|
60
|
+
0.13404125077971096,
|
|
61
|
+
0.14513506406340107,
|
|
62
|
+
0.12982086087095326,
|
|
63
|
+
0.12413997182558323,
|
|
64
|
+
0.1283193161775326,
|
|
65
|
+
0.13076527128959525
|
|
66
|
+
],
|
|
67
|
+
"window_size":60
|
|
68
|
+
}
|
rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm.nii.gz
ADDED
|
Binary file
|
|
Binary file
|
rapidtide/decorators.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2016-2025 Blaise Frederick
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
#
|
|
19
|
+
from typing import Callable
|
|
20
|
+
|
|
21
|
+
# ----------------------------------------- Conditional imports ---------------------------------------
|
|
22
|
+
donotbeaggressive = True
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from numba import jit
|
|
26
|
+
except ImportError:
|
|
27
|
+
donotusenumba = True
|
|
28
|
+
else:
|
|
29
|
+
donotusenumba = False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def getdecoratorvars():
|
|
33
|
+
return donotusenumba, donotbeaggressive
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def conditionaljit() -> Callable:
|
|
37
|
+
"""
|
|
38
|
+
Wrap functions in jit if numba is enabled.
|
|
39
|
+
|
|
40
|
+
This function creates a decorator that conditionally applies Numba's jit
|
|
41
|
+
decorator to functions. If the `donotusenumba` flag is True, the original
|
|
42
|
+
function is returned unchanged. Otherwise, the function is compiled with
|
|
43
|
+
`jit(nopython=True)` for optimal performance.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
Callable
|
|
48
|
+
A decorator function that can be applied to other functions.
|
|
49
|
+
|
|
50
|
+
Notes
|
|
51
|
+
-----
|
|
52
|
+
This decorator provides a convenient way to conditionally enable Numba
|
|
53
|
+
compilation based on a global flag. It's useful for debugging and
|
|
54
|
+
development where you want to disable JIT compilation temporarily.
|
|
55
|
+
|
|
56
|
+
Examples
|
|
57
|
+
--------
|
|
58
|
+
>>> @conditionaljit()
|
|
59
|
+
... def my_function(x):
|
|
60
|
+
... return x * 2
|
|
61
|
+
...
|
|
62
|
+
>>> result = my_function(5)
|
|
63
|
+
>>> print(result)
|
|
64
|
+
10
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def resdec(f):
|
|
68
|
+
if donotusenumba:
|
|
69
|
+
return f
|
|
70
|
+
return jit(f, nopython=True)
|
|
71
|
+
|
|
72
|
+
return resdec
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def conditionaljit2() -> Callable:
|
|
76
|
+
"""Return a decorator that conditionally applies numba JIT compilation (conservative mode).
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
decorator
|
|
81
|
+
A decorator that applies numba JIT compilation with nopython=True if numba
|
|
82
|
+
is enabled and aggressive optimization is allowed, otherwise returns the function unchanged.
|
|
83
|
+
This is more conservative than conditionaljit() as it also checks the donotbeaggressive flag.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
def resdec(f):
|
|
87
|
+
if donotusenumba or donotbeaggressive:
|
|
88
|
+
return f
|
|
89
|
+
return jit(f, nopython=True)
|
|
90
|
+
|
|
91
|
+
return resdec
|