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.
Files changed (139) hide show
  1. rapidtide/Colortables.py +492 -27
  2. rapidtide/OrthoImageItem.py +1049 -46
  3. rapidtide/RapidtideDataset.py +1533 -86
  4. rapidtide/_version.py +3 -3
  5. rapidtide/calccoherence.py +196 -29
  6. rapidtide/calcnullsimfunc.py +191 -40
  7. rapidtide/calcsimfunc.py +245 -42
  8. rapidtide/correlate.py +1210 -393
  9. rapidtide/data/examples/src/testLD +56 -0
  10. rapidtide/data/examples/src/testalign +1 -1
  11. rapidtide/data/examples/src/testdelayvar +0 -1
  12. rapidtide/data/examples/src/testfmri +19 -1
  13. rapidtide/data/examples/src/testglmfilt +5 -5
  14. rapidtide/data/examples/src/testhappy +25 -3
  15. rapidtide/data/examples/src/testppgproc +17 -0
  16. rapidtide/data/examples/src/testrolloff +11 -0
  17. rapidtide/data/models/model_cnn_pytorch/best_model.pth +0 -0
  18. rapidtide/data/models/model_cnn_pytorch/loss.png +0 -0
  19. rapidtide/data/models/model_cnn_pytorch/loss.txt +1 -0
  20. rapidtide/data/models/model_cnn_pytorch/model.pth +0 -0
  21. rapidtide/data/models/model_cnn_pytorch/model_meta.json +68 -0
  22. rapidtide/decorators.py +91 -0
  23. rapidtide/dlfilter.py +2225 -108
  24. rapidtide/dlfiltertorch.py +4843 -0
  25. rapidtide/externaltools.py +327 -12
  26. rapidtide/fMRIData_class.py +79 -40
  27. rapidtide/filter.py +1899 -810
  28. rapidtide/fit.py +2004 -574
  29. rapidtide/genericmultiproc.py +93 -18
  30. rapidtide/happy_supportfuncs.py +2044 -171
  31. rapidtide/helper_classes.py +584 -43
  32. rapidtide/io.py +2363 -370
  33. rapidtide/linfitfiltpass.py +341 -75
  34. rapidtide/makelaggedtcs.py +211 -20
  35. rapidtide/maskutil.py +423 -53
  36. rapidtide/miscmath.py +827 -121
  37. rapidtide/multiproc.py +210 -22
  38. rapidtide/patchmatch.py +234 -33
  39. rapidtide/peakeval.py +32 -30
  40. rapidtide/ppgproc.py +2203 -0
  41. rapidtide/qualitycheck.py +352 -39
  42. rapidtide/refinedelay.py +422 -57
  43. rapidtide/refineregressor.py +498 -184
  44. rapidtide/resample.py +671 -185
  45. rapidtide/scripts/applyppgproc.py +28 -0
  46. rapidtide/simFuncClasses.py +1052 -77
  47. rapidtide/simfuncfit.py +260 -46
  48. rapidtide/stats.py +540 -238
  49. rapidtide/tests/happycomp +9 -0
  50. rapidtide/tests/test_dlfiltertorch.py +627 -0
  51. rapidtide/tests/test_findmaxlag.py +24 -8
  52. rapidtide/tests/test_fullrunhappy_v1.py +0 -2
  53. rapidtide/tests/test_fullrunhappy_v2.py +0 -2
  54. rapidtide/tests/test_fullrunhappy_v3.py +1 -0
  55. rapidtide/tests/test_fullrunhappy_v4.py +2 -2
  56. rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
  57. rapidtide/tests/test_simroundtrip.py +8 -8
  58. rapidtide/tests/utils.py +9 -8
  59. rapidtide/tidepoolTemplate.py +142 -38
  60. rapidtide/tidepoolTemplate_alt.py +165 -44
  61. rapidtide/tidepoolTemplate_big.py +189 -52
  62. rapidtide/util.py +1217 -118
  63. rapidtide/voxelData.py +684 -37
  64. rapidtide/wiener.py +19 -12
  65. rapidtide/wiener2.py +113 -7
  66. rapidtide/wiener_doc.py +255 -0
  67. rapidtide/workflows/adjustoffset.py +105 -3
  68. rapidtide/workflows/aligntcs.py +85 -2
  69. rapidtide/workflows/applydlfilter.py +87 -10
  70. rapidtide/workflows/applyppgproc.py +522 -0
  71. rapidtide/workflows/atlasaverage.py +210 -47
  72. rapidtide/workflows/atlastool.py +100 -3
  73. rapidtide/workflows/calcSimFuncMap.py +294 -64
  74. rapidtide/workflows/calctexticc.py +201 -9
  75. rapidtide/workflows/ccorrica.py +97 -4
  76. rapidtide/workflows/cleanregressor.py +168 -29
  77. rapidtide/workflows/delayvar.py +163 -10
  78. rapidtide/workflows/diffrois.py +81 -3
  79. rapidtide/workflows/endtidalproc.py +144 -4
  80. rapidtide/workflows/fdica.py +195 -15
  81. rapidtide/workflows/filtnifti.py +70 -3
  82. rapidtide/workflows/filttc.py +74 -3
  83. rapidtide/workflows/fitSimFuncMap.py +206 -48
  84. rapidtide/workflows/fixtr.py +73 -3
  85. rapidtide/workflows/gmscalc.py +113 -3
  86. rapidtide/workflows/happy.py +801 -199
  87. rapidtide/workflows/happy2std.py +144 -12
  88. rapidtide/workflows/happy_parser.py +138 -9
  89. rapidtide/workflows/histnifti.py +118 -2
  90. rapidtide/workflows/histtc.py +84 -3
  91. rapidtide/workflows/linfitfilt.py +117 -4
  92. rapidtide/workflows/localflow.py +328 -28
  93. rapidtide/workflows/mergequality.py +79 -3
  94. rapidtide/workflows/niftidecomp.py +322 -18
  95. rapidtide/workflows/niftistats.py +174 -4
  96. rapidtide/workflows/pairproc.py +88 -2
  97. rapidtide/workflows/pairwisemergenifti.py +85 -2
  98. rapidtide/workflows/parser_funcs.py +1421 -40
  99. rapidtide/workflows/physiofreq.py +137 -11
  100. rapidtide/workflows/pixelcomp.py +208 -5
  101. rapidtide/workflows/plethquality.py +103 -21
  102. rapidtide/workflows/polyfitim.py +151 -11
  103. rapidtide/workflows/proj2flow.py +75 -2
  104. rapidtide/workflows/rankimage.py +111 -4
  105. rapidtide/workflows/rapidtide.py +272 -15
  106. rapidtide/workflows/rapidtide2std.py +98 -2
  107. rapidtide/workflows/rapidtide_parser.py +109 -9
  108. rapidtide/workflows/refineDelayMap.py +143 -33
  109. rapidtide/workflows/refineRegressor.py +682 -93
  110. rapidtide/workflows/regressfrommaps.py +152 -31
  111. rapidtide/workflows/resamplenifti.py +85 -3
  112. rapidtide/workflows/resampletc.py +91 -3
  113. rapidtide/workflows/retrolagtcs.py +98 -6
  114. rapidtide/workflows/retroregress.py +165 -9
  115. rapidtide/workflows/roisummarize.py +173 -5
  116. rapidtide/workflows/runqualitycheck.py +71 -3
  117. rapidtide/workflows/showarbcorr.py +147 -4
  118. rapidtide/workflows/showhist.py +86 -2
  119. rapidtide/workflows/showstxcorr.py +160 -3
  120. rapidtide/workflows/showtc.py +159 -3
  121. rapidtide/workflows/showxcorrx.py +184 -4
  122. rapidtide/workflows/showxy.py +185 -15
  123. rapidtide/workflows/simdata.py +262 -36
  124. rapidtide/workflows/spatialfit.py +77 -2
  125. rapidtide/workflows/spatialmi.py +251 -27
  126. rapidtide/workflows/spectrogram.py +305 -32
  127. rapidtide/workflows/synthASL.py +154 -3
  128. rapidtide/workflows/tcfrom2col.py +76 -2
  129. rapidtide/workflows/tcfrom3col.py +74 -2
  130. rapidtide/workflows/tidepool.py +2969 -130
  131. rapidtide/workflows/utils.py +19 -14
  132. rapidtide/workflows/utils_doc.py +293 -0
  133. rapidtide/workflows/variabilityizer.py +116 -3
  134. {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/METADATA +3 -2
  135. {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/RECORD +139 -122
  136. {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/entry_points.txt +1 -0
  137. {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/WHEEL +0 -0
  138. {rapidtide-3.0.11.dist-info → rapidtide-3.1.dist-info}/licenses/LICENSE +0 -0
  139. {rapidtide-3.0.11.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)
@@ -7,7 +7,6 @@ delayvar \
7
7
  --nprocs -1 \
8
8
  --windowsize 30 \
9
9
  --systemicfittype pca \
10
- --trainrange -999 -999 \
11
10
  --pcacomponents 0.8 \
12
11
  --outputlevel max \
13
12
  --focaldebug \
@@ -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-RAPIDTIDETEST_flexipass
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, returnintercept=True, debug=True
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,15 +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
+
72
90
  happy \
73
91
  sub-HAPPYTEST.nii.gz \
74
92
  sub-HAPPYTEST.json \
75
- ../dst/happy_mask \
76
- --processmask sub-HAPPYTEST_mask.nii.gz \
93
+ ../dst/happy_pytorch \
94
+ --increaseoutputlevel \
95
+ --usenewvesselmethod \
77
96
  --nprocs -1
78
97
 
79
98
  happy \
80
99
  sub-HAPPYTEST.nii.gz \
81
100
  sub-HAPPYTEST.json \
82
- ../dst/happy \
101
+ ../dst/happy_tensorflow \
102
+ --increaseoutputlevel \
103
+ --usenewvesselmethod \
104
+ --usetensorflow \
83
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
@@ -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
@@ -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
+ }
@@ -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