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
@@ -17,17 +17,69 @@
17
17
  #
18
18
  #
19
19
  import gc
20
+ import logging
21
+ from typing import Any
20
22
 
21
23
  import numpy as np
24
+ from numpy.typing import NDArray
22
25
 
23
26
  import rapidtide.genericmultiproc as tide_genericmultiproc
24
27
 
25
28
 
26
29
  def _procOneVoxelMakelagtc(
27
- vox,
28
- voxelargs,
29
- **kwargs,
30
- ):
30
+ vox: int,
31
+ voxelargs: list,
32
+ **kwargs: Any,
33
+ ) -> tuple[int, NDArray]:
34
+ """
35
+ Process a single voxel to compute lag timecourse using lag timecourse generator.
36
+
37
+ This function takes a voxel index and associated arguments to compute a lag
38
+ timecourse using the provided lag timecourse generator. The computation involves
39
+ evaluating the generator at timepoints shifted by the specified lag value.
40
+
41
+ Parameters
42
+ ----------
43
+ vox : int
44
+ Voxel index identifier used for tracking and debugging purposes.
45
+ voxelargs : list
46
+ List containing three elements:
47
+ 1. `lagtcgenerator` - Lag timecourse generator object with `yfromx` method
48
+ 2. `thelag` - Lag value to be subtracted from time axis
49
+ 3. `timeaxis` - Time axis array for evaluation
50
+ **kwargs : Any
51
+ Additional keyword arguments that can override default options:
52
+ - `rt_floatset` : float type for computations (default: np.float64)
53
+ - `debug` : boolean for debug printing (default: False)
54
+
55
+ Returns
56
+ -------
57
+ tuple[int, NDArray]
58
+ Tuple containing:
59
+ - `vox` : Input voxel index
60
+ - `thelagtc` : Computed lag timecourse array
61
+
62
+ Notes
63
+ -----
64
+ The lag value is subtracted from the time axis as of 10/18. Alternative approaches
65
+ of adding the lag value resulted in poor performance.
66
+
67
+ Examples
68
+ --------
69
+ >>> import numpy as np
70
+ >>>
71
+ >>> # Example usage with mock generator
72
+ >>> class MockGenerator:
73
+ ... def yfromx(self, x):
74
+ ... return x**2
75
+ ...
76
+ >>> generator = MockGenerator()
77
+ >>> time_axis = np.array([0, 1, 2, 3, 4])
78
+ >>> voxel_args = [generator, 1.0, time_axis]
79
+ >>> result = _procOneVoxelMakelagtc(0, voxel_args)
80
+ >>> print(result)
81
+ (0, array([0., 1., 4., 9., 16.]))
82
+ """
31
83
  # unpack arguments
32
84
  options = {
33
85
  "rt_floatset": np.float64,
@@ -50,29 +102,168 @@ def _procOneVoxelMakelagtc(
50
102
  )
51
103
 
52
104
 
53
- def _packvoxeldata(voxnum, voxelargs):
105
+ def _packvoxeldata(voxnum: int, voxelargs: list) -> list:
106
+ """
107
+ Pack voxel data into a list format.
108
+
109
+ Parameters
110
+ ----------
111
+ voxnum : int
112
+ The index used to select an element from the second element of voxelargs.
113
+ voxelargs : list
114
+ A list containing three elements where:
115
+ - voxelargs[0] is the first element to be returned
116
+ - voxelargs[1] is a list or array from which an element is selected using voxnum
117
+ - voxelargs[2] is the third element to be returned
118
+
119
+ Returns
120
+ -------
121
+ list
122
+ A list containing three elements: [voxelargs[0], voxelargs[1][voxnum], voxelargs[2]]
123
+
124
+ Notes
125
+ -----
126
+ This function assumes that voxelargs[1] is indexable and that voxnum is a valid index
127
+ for accessing elements in voxelargs[1]. The function does not perform any validation
128
+ of the input parameters.
129
+
130
+ Examples
131
+ --------
132
+ >>> _packvoxeldata(1, [10, [20, 30, 40], 50])
133
+ [10, 30, 50]
134
+
135
+ >>> _packvoxeldata(0, ['a', ['b', 'c', 'd'], 'e'])
136
+ ['a', 'b', 'e']
137
+ """
54
138
  return [voxelargs[0], (voxelargs[1])[voxnum], voxelargs[2]]
55
139
 
56
140
 
57
- def _unpackvoxeldata(retvals, voxelproducts):
141
+ def _unpackvoxeldata(retvals: tuple, voxelproducts: list) -> None:
142
+ """
143
+ Unpack voxel data into the specified voxel products array.
144
+
145
+ This function takes return values and assigns them to a specific location
146
+ in the voxel products array. It is typically used as part of a larger
147
+ voxel processing pipeline.
148
+
149
+ Parameters
150
+ ----------
151
+ retvals : tuple
152
+ A tuple containing the data to be unpacked. The first element is used
153
+ as an index for the voxel products array, and the second element contains
154
+ the actual data to be assigned.
155
+ voxelproducts : list
156
+ A list of arrays where the voxel data will be stored. The function
157
+ modifies the first element of this list in-place.
158
+
159
+ Returns
160
+ -------
161
+ None
162
+ This function modifies the voxelproducts list in-place and does not
163
+ return any value.
164
+
165
+ Notes
166
+ -----
167
+ The function assumes that retvals[0] is a valid index for the first element
168
+ of voxelproducts and that retvals[1] has compatible dimensions for assignment.
169
+
170
+ Examples
171
+ --------
172
+ >>> retvals = (5, [1, 2, 3, 4, 5])
173
+ >>> voxelproducts = [[0] * 10]
174
+ >>> _unpackvoxeldata(retvals, voxelproducts)
175
+ >>> print(voxelproducts[0])
176
+ [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]
177
+ """
58
178
  (voxelproducts[0])[retvals[0], :] = retvals[1]
59
179
 
60
180
 
61
181
  def makelaggedtcs(
62
- lagtcgenerator,
63
- timeaxis,
64
- lagmask,
65
- lagtimes,
66
- lagtc,
67
- LGR=None,
68
- nprocs=1,
69
- alwaysmultiproc=False,
70
- showprogressbar=True,
71
- chunksize=1000,
72
- rt_floatset=np.float64,
73
- rt_floattype="float64",
74
- debug=False,
75
- ):
182
+ lagtcgenerator: Any,
183
+ timeaxis: NDArray,
184
+ lagmask: NDArray,
185
+ lagtimes: NDArray,
186
+ lagtc: NDArray,
187
+ LGR: logging.Logger | None = None,
188
+ nprocs: int = 1,
189
+ alwaysmultiproc: bool = False,
190
+ showprogressbar: bool = True,
191
+ chunksize: int = 1000,
192
+ rt_floatset: type = np.float64,
193
+ rt_floattype: str = "float64",
194
+ debug: bool = False,
195
+ ) -> int:
196
+ """
197
+ Generate lagged timecourses for a set of voxels using multiprocessing.
198
+
199
+ This function computes lagged timecourses for each voxel specified in the mask,
200
+ using the provided lag timecourse generator and time axis. It supports
201
+ parallel processing for performance optimization.
202
+
203
+ Parameters
204
+ ----------
205
+ lagtcgenerator : Any
206
+ A callable or object that generates lagged timecourses for a single voxel.
207
+ timeaxis : numpy.ndarray
208
+ 1D array representing the time axis (e.g., TRs or time points).
209
+ lagmask : numpy.ndarray
210
+ 3D or 4D boolean or integer array defining the voxels to process.
211
+ Non-zero entries indicate voxels to be processed.
212
+ lagtimes : numpy.ndarray
213
+ 1D array of lag times (in seconds or time units) to be applied.
214
+ lagtc : numpy.ndarray
215
+ 4D array of shape (ntimepoints, nvoxels, nlags) to store the output lagged
216
+ timecourses. This is updated in-place.
217
+ LGR : logging.Logger, optional
218
+ Logger instance for logging messages. If None, no logging is performed.
219
+ nprocs : int, optional
220
+ Number of processes to use for multiprocessing. Default is 1.
221
+ alwaysmultiproc : bool, optional
222
+ If True, always use multiprocessing even for single voxel processing.
223
+ Default is False.
224
+ showprogressbar : bool, optional
225
+ If True, display a progress bar during processing. Default is True.
226
+ chunksize : int, optional
227
+ Size of chunks to process in each step when using multiprocessing.
228
+ Default is 1000.
229
+ rt_floatset : type, optional
230
+ The floating-point type to use for internal computations.
231
+ Default is `np.float64`.
232
+ rt_floattype : str, optional
233
+ String representation of the floating-point type.
234
+ Default is "float64".
235
+ debug : bool, optional
236
+ If True, print debug information. Default is False.
237
+
238
+ Returns
239
+ -------
240
+ int
241
+ Total number of voxels processed.
242
+
243
+ Notes
244
+ -----
245
+ This function uses `tide_genericmultiproc.run_multiproc` internally to
246
+ distribute voxel processing across multiple processes. It is designed for
247
+ efficient batch processing of large 4D datasets.
248
+
249
+ Examples
250
+ --------
251
+ >>> import numpy as np
252
+ >>> from some_module import makelaggedtcs
253
+ >>> timeaxis = np.arange(100)
254
+ >>> lagtimes = np.array([0, 1, 2])
255
+ >>> lagmask = np.ones((10, 10, 10), dtype=bool)
256
+ >>> lagtc = np.zeros((100, 1000, 3))
257
+ >>> result = makelaggedtcs(
258
+ ... lagtcgenerator=my_generator,
259
+ ... timeaxis=timeaxis,
260
+ ... lagmask=lagmask,
261
+ ... lagtimes=lagtimes,
262
+ ... lagtc=lagtc,
263
+ ... nprocs=4
264
+ ... )
265
+ >>> print(f"Processed {result} voxels")
266
+ """
76
267
  if debug:
77
268
  print("makelaggedtcs: Starting")
78
269
  print(f"\t{lagtc.shape=}")