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.
Files changed (141) hide show
  1. rapidtide/Colortables.py +492 -27
  2. rapidtide/OrthoImageItem.py +1053 -47
  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 +30 -1
  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/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm.nii.gz +0 -0
  23. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm_mask.nii.gz +0 -0
  24. rapidtide/decorators.py +91 -0
  25. rapidtide/dlfilter.py +2225 -108
  26. rapidtide/dlfiltertorch.py +4843 -0
  27. rapidtide/externaltools.py +327 -12
  28. rapidtide/fMRIData_class.py +79 -40
  29. rapidtide/filter.py +1899 -810
  30. rapidtide/fit.py +2004 -574
  31. rapidtide/genericmultiproc.py +93 -18
  32. rapidtide/happy_supportfuncs.py +2044 -171
  33. rapidtide/helper_classes.py +584 -43
  34. rapidtide/io.py +2363 -370
  35. rapidtide/linfitfiltpass.py +341 -75
  36. rapidtide/makelaggedtcs.py +211 -20
  37. rapidtide/maskutil.py +423 -53
  38. rapidtide/miscmath.py +827 -121
  39. rapidtide/multiproc.py +210 -22
  40. rapidtide/patchmatch.py +234 -33
  41. rapidtide/peakeval.py +32 -30
  42. rapidtide/ppgproc.py +2203 -0
  43. rapidtide/qualitycheck.py +352 -39
  44. rapidtide/refinedelay.py +422 -57
  45. rapidtide/refineregressor.py +498 -184
  46. rapidtide/resample.py +671 -185
  47. rapidtide/scripts/applyppgproc.py +28 -0
  48. rapidtide/simFuncClasses.py +1052 -77
  49. rapidtide/simfuncfit.py +260 -46
  50. rapidtide/stats.py +540 -238
  51. rapidtide/tests/happycomp +9 -0
  52. rapidtide/tests/test_dlfiltertorch.py +627 -0
  53. rapidtide/tests/test_findmaxlag.py +24 -8
  54. rapidtide/tests/test_fullrunhappy_v1.py +0 -2
  55. rapidtide/tests/test_fullrunhappy_v2.py +0 -2
  56. rapidtide/tests/test_fullrunhappy_v3.py +1 -0
  57. rapidtide/tests/test_fullrunhappy_v4.py +2 -2
  58. rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
  59. rapidtide/tests/test_simroundtrip.py +8 -8
  60. rapidtide/tests/utils.py +9 -8
  61. rapidtide/tidepoolTemplate.py +142 -38
  62. rapidtide/tidepoolTemplate_alt.py +165 -44
  63. rapidtide/tidepoolTemplate_big.py +189 -52
  64. rapidtide/util.py +1217 -118
  65. rapidtide/voxelData.py +684 -37
  66. rapidtide/wiener.py +19 -12
  67. rapidtide/wiener2.py +113 -7
  68. rapidtide/wiener_doc.py +255 -0
  69. rapidtide/workflows/adjustoffset.py +105 -3
  70. rapidtide/workflows/aligntcs.py +85 -2
  71. rapidtide/workflows/applydlfilter.py +87 -10
  72. rapidtide/workflows/applyppgproc.py +522 -0
  73. rapidtide/workflows/atlasaverage.py +210 -47
  74. rapidtide/workflows/atlastool.py +100 -3
  75. rapidtide/workflows/calcSimFuncMap.py +294 -64
  76. rapidtide/workflows/calctexticc.py +201 -9
  77. rapidtide/workflows/ccorrica.py +97 -4
  78. rapidtide/workflows/cleanregressor.py +168 -29
  79. rapidtide/workflows/delayvar.py +163 -10
  80. rapidtide/workflows/diffrois.py +81 -3
  81. rapidtide/workflows/endtidalproc.py +144 -4
  82. rapidtide/workflows/fdica.py +195 -15
  83. rapidtide/workflows/filtnifti.py +70 -3
  84. rapidtide/workflows/filttc.py +74 -3
  85. rapidtide/workflows/fitSimFuncMap.py +206 -48
  86. rapidtide/workflows/fixtr.py +73 -3
  87. rapidtide/workflows/gmscalc.py +113 -3
  88. rapidtide/workflows/happy.py +813 -201
  89. rapidtide/workflows/happy2std.py +144 -12
  90. rapidtide/workflows/happy_parser.py +149 -8
  91. rapidtide/workflows/histnifti.py +118 -2
  92. rapidtide/workflows/histtc.py +84 -3
  93. rapidtide/workflows/linfitfilt.py +117 -4
  94. rapidtide/workflows/localflow.py +328 -28
  95. rapidtide/workflows/mergequality.py +79 -3
  96. rapidtide/workflows/niftidecomp.py +322 -18
  97. rapidtide/workflows/niftistats.py +174 -4
  98. rapidtide/workflows/pairproc.py +88 -2
  99. rapidtide/workflows/pairwisemergenifti.py +85 -2
  100. rapidtide/workflows/parser_funcs.py +1421 -40
  101. rapidtide/workflows/physiofreq.py +137 -11
  102. rapidtide/workflows/pixelcomp.py +208 -5
  103. rapidtide/workflows/plethquality.py +103 -21
  104. rapidtide/workflows/polyfitim.py +151 -11
  105. rapidtide/workflows/proj2flow.py +75 -2
  106. rapidtide/workflows/rankimage.py +111 -4
  107. rapidtide/workflows/rapidtide.py +272 -15
  108. rapidtide/workflows/rapidtide2std.py +98 -2
  109. rapidtide/workflows/rapidtide_parser.py +109 -9
  110. rapidtide/workflows/refineDelayMap.py +143 -33
  111. rapidtide/workflows/refineRegressor.py +682 -93
  112. rapidtide/workflows/regressfrommaps.py +152 -31
  113. rapidtide/workflows/resamplenifti.py +85 -3
  114. rapidtide/workflows/resampletc.py +91 -3
  115. rapidtide/workflows/retrolagtcs.py +98 -6
  116. rapidtide/workflows/retroregress.py +165 -9
  117. rapidtide/workflows/roisummarize.py +173 -5
  118. rapidtide/workflows/runqualitycheck.py +71 -3
  119. rapidtide/workflows/showarbcorr.py +147 -4
  120. rapidtide/workflows/showhist.py +86 -2
  121. rapidtide/workflows/showstxcorr.py +160 -3
  122. rapidtide/workflows/showtc.py +159 -3
  123. rapidtide/workflows/showxcorrx.py +184 -4
  124. rapidtide/workflows/showxy.py +185 -15
  125. rapidtide/workflows/simdata.py +262 -36
  126. rapidtide/workflows/spatialfit.py +77 -2
  127. rapidtide/workflows/spatialmi.py +251 -27
  128. rapidtide/workflows/spectrogram.py +305 -32
  129. rapidtide/workflows/synthASL.py +154 -3
  130. rapidtide/workflows/tcfrom2col.py +76 -2
  131. rapidtide/workflows/tcfrom3col.py +74 -2
  132. rapidtide/workflows/tidepool.py +2972 -133
  133. rapidtide/workflows/utils.py +19 -14
  134. rapidtide/workflows/utils_doc.py +293 -0
  135. rapidtide/workflows/variabilityizer.py +116 -3
  136. {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/METADATA +10 -9
  137. {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/RECORD +141 -122
  138. {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/entry_points.txt +1 -0
  139. {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/WHEEL +0 -0
  140. {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/licenses/LICENSE +0 -0
  141. {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/top_level.txt +0 -0
rapidtide/calcsimfunc.py CHANGED
@@ -19,8 +19,10 @@
19
19
  import gc
20
20
  import logging
21
21
  import warnings
22
+ from typing import Any
22
23
 
23
24
  import numpy as np
25
+ from numpy.typing import NDArray
24
26
 
25
27
  import rapidtide.genericmultiproc as tide_genericmultiproc
26
28
  import rapidtide.resample as tide_resample
@@ -30,10 +32,72 @@ LGR = logging.getLogger("GENERAL")
30
32
 
31
33
 
32
34
  def _procOneVoxelCorrelation(
33
- vox,
34
- voxelargs,
35
- **kwargs,
36
- ):
35
+ vox: int,
36
+ voxelargs: list[Any],
37
+ **kwargs: Any,
38
+ ) -> tuple[int, float, NDArray, NDArray, float, list[float]]:
39
+ """
40
+ Process correlation for a single voxel.
41
+
42
+ This function performs correlation analysis on a single voxel using the provided
43
+ fMRI data and correlation parameters. It handles resampling of fMRI data based
44
+ on the oversampling factor and computes the correlation between the resampled
45
+ data and the target time course.
46
+
47
+ Parameters
48
+ ----------
49
+ vox : int
50
+ The voxel index being processed.
51
+ voxelargs : list[Any]
52
+ List containing the following elements in order:
53
+ - thetc : array-like
54
+ - theCorrelator : object
55
+ - fmri_x : array-like
56
+ - fmritc : array-like
57
+ - os_fmri_x : array-like
58
+ - theglobalmaxlist : list
59
+ - thexcorr_y : array-like
60
+ **kwargs : Any
61
+ Additional keyword arguments that override default options:
62
+ - oversampfactor : int, optional
63
+ Oversampling factor for resampling (default: 1)
64
+ - interptype : str, optional
65
+ Interpolation type for resampling (default: "univariate")
66
+ - debug : bool, optional
67
+ Enable debug printing (default: False)
68
+
69
+ Returns
70
+ -------
71
+ tuple[int, float, NDArray, NDArray, float, list[float]]
72
+ A tuple containing:
73
+ - vox : int
74
+ The input voxel index
75
+ - np.mean(thetc) : float
76
+ Mean of the processed time course
77
+ - thexcorr_y : NDArray
78
+ Correlation values
79
+ - thexcorr_x : NDArray
80
+ Correlation lags
81
+ - theglobalmax : float
82
+ Global maximum correlation value
83
+ - theglobalmaxlist : list[float]
84
+ List of global maximum correlation values
85
+
86
+ Notes
87
+ -----
88
+ The function modifies the input `thetc` array in-place with the resampled data.
89
+ If oversampfactor is less than 1, no resampling is performed and the original
90
+ time course is used.
91
+
92
+ Examples
93
+ --------
94
+ >>> result = _procOneVoxelCorrelation(
95
+ ... vox=100,
96
+ ... voxelargs=[thetc, correlator, fmri_x, fmritc, os_fmri_x, globalmaxlist, xcorr_y],
97
+ ... oversampfactor=2,
98
+ ... debug=True
99
+ ... )
100
+ """
37
101
  options = {
38
102
  "oversampfactor": 1,
39
103
  "interptype": "univariate",
@@ -56,7 +120,43 @@ def _procOneVoxelCorrelation(
56
120
  return vox, np.mean(thetc), thexcorr_y, thexcorr_x, theglobalmax, theglobalmaxlist
57
121
 
58
122
 
59
- def _packvoxeldata(voxnum, voxelargs):
123
+ def _packvoxeldata(voxnum: int, voxelargs: list[Any]) -> list[Any]:
124
+ """
125
+ Pack voxel data into a structured list format.
126
+
127
+ This function extracts and organizes voxel data from a list of arguments,
128
+ specifically selecting a slice from the fourth element based on the voxel number.
129
+
130
+ Parameters
131
+ ----------
132
+ voxnum : int
133
+ The voxel index used to select a specific row from the fourth element
134
+ of voxelargs, which is expected to be a 2D array-like structure.
135
+ voxelargs : list[Any]
136
+ A list containing voxel-related arguments. The expected structure is:
137
+ [arg0, arg1, arg2, array_2d, arg4, arg5, arg6]
138
+ where the fourth element (index 3) should be a 2D array-like object
139
+ from which a row will be selected using voxnum.
140
+
141
+ Returns
142
+ -------
143
+ list[Any]
144
+ A list containing the packed voxel data with the following structure:
145
+ [voxelargs[0], voxelargs[1], voxelargs[2],
146
+ voxelargs[3][voxnum, :], voxelargs[4], voxelargs[5], voxelargs[6]]
147
+ where the fourth element is the selected row from the 2D array.
148
+
149
+ Notes
150
+ -----
151
+ The function assumes that voxelargs[3] is a 2D array-like structure and
152
+ that voxnum is a valid index for selecting a row from this array.
153
+
154
+ Examples
155
+ --------
156
+ >>> voxelargs = [1, 2, 3, [[10, 20], [30, 40]], 5, 6, 7]
157
+ >>> _packvoxeldata(1, voxelargs)
158
+ [1, 2, 3, [30, 40], 5, 6, 7]
159
+ """
60
160
  return [
61
161
  voxelargs[0],
62
162
  voxelargs[1],
@@ -68,7 +168,52 @@ def _packvoxeldata(voxnum, voxelargs):
68
168
  ]
69
169
 
70
170
 
71
- def _unpackvoxeldata(retvals, voxelproducts):
171
+ def _unpackvoxeldata(retvals: tuple[Any, ...], voxelproducts: list[Any]) -> None:
172
+ """
173
+ Unpack voxel data from retvals into voxelproducts structure.
174
+
175
+ Parameters
176
+ ----------
177
+ retvals : tuple[Any, ...]
178
+ Tuple containing voxel data to be unpacked. Expected to contain at least 5 elements
179
+ where:
180
+ - retvals[0]: index/key for first assignment
181
+ - retvals[1]: value for first assignment
182
+ - retvals[2]: array-like data for second assignment
183
+ - retvals[3]: value for third assignment
184
+ - retvals[4]: value for fourth assignment (will be incremented by 0)
185
+ voxelproducts : list[Any]
186
+ List containing voxel data structures where unpacked data will be stored:
187
+ - voxelproducts[0]: dict or array-like structure for first assignment
188
+ - voxelproducts[1]: 2D array-like structure for second assignment
189
+ - voxelproducts[2]: scalar or single value storage
190
+ - voxelproducts[3]: list-like structure for appending fourth assignment
191
+
192
+ Returns
193
+ -------
194
+ None
195
+ This function modifies voxelproducts in-place and does not return any value.
196
+
197
+ Notes
198
+ -----
199
+ This function performs in-place modifications of the voxelproducts list elements.
200
+ The fourth assignment uses `retvals[4] + 0` which effectively creates a copy of
201
+ the value to ensure no reference issues.
202
+
203
+ Examples
204
+ --------
205
+ >>> retvals = (0, 'value1', [1, 2, 3], 42, 10)
206
+ >>> voxelproducts = [{}, [[0]*3], 0, []]
207
+ >>> _unpackvoxeldata(retvals, voxelproducts)
208
+ >>> voxelproducts[0]
209
+ {0: 'value1'}
210
+ >>> voxelproducts[1]
211
+ [[1, 2, 3]]
212
+ >>> voxelproducts[2]
213
+ 42
214
+ >>> voxelproducts[3]
215
+ [10]
216
+ """
72
217
  (voxelproducts[0])[retvals[0]] = retvals[1]
73
218
  (voxelproducts[1])[retvals[0], :] = retvals[2]
74
219
  voxelproducts[2] = retvals[3]
@@ -76,50 +221,108 @@ def _unpackvoxeldata(retvals, voxelproducts):
76
221
 
77
222
 
78
223
  def correlationpass(
79
- fmridata,
80
- referencetc,
81
- theCorrelator,
82
- fmri_x,
83
- os_fmri_x,
84
- lagmininpts,
85
- lagmaxinpts,
86
- corrout,
87
- meanval,
88
- nprocs=1,
89
- alwaysmultiproc=False,
90
- oversampfactor=1,
91
- interptype="univariate",
92
- showprogressbar=True,
93
- chunksize=1000,
94
- rt_floatset=np.float64,
95
- rt_floattype="float64",
96
- debug=False,
97
- ):
224
+ fmridata: NDArray,
225
+ referencetc: NDArray,
226
+ theCorrelator: Any,
227
+ fmri_x: NDArray,
228
+ os_fmri_x: NDArray,
229
+ lagmininpts: int,
230
+ lagmaxinpts: int,
231
+ corrout: NDArray,
232
+ meanval: NDArray,
233
+ nprocs: int = 1,
234
+ alwaysmultiproc: bool = False,
235
+ oversampfactor: int = 1,
236
+ interptype: str = "univariate",
237
+ showprogressbar: bool = True,
238
+ chunksize: int = 1000,
239
+ rt_floatset: type = np.float64,
240
+ rt_floattype: str = "float64",
241
+ debug: bool = False,
242
+ ) -> tuple[int, list[float], NDArray]:
98
243
  """
244
+ Compute correlation-based similarity function across MRI voxels using multi-processing.
245
+
246
+ This function computes a correlation-based similarity measure between a reference time course
247
+ and fMRI data across voxels, using a specified correlator object. It supports both single and
248
+ multi-processing modes and allows for various interpolation and oversampling options.
99
249
 
100
250
  Parameters
101
251
  ----------
102
- fmridata
103
- referencetc - the reference regressor, already oversampled
104
- theCorrelator
105
- fmri_x
106
- os_fmri_x
107
- tr
108
- lagmininpts
109
- lagmaxinpts
110
- corrout
111
- meanval
112
- nprocs
113
- oversampfactor
114
- interptype
115
- showprogressbar
116
- chunksize
117
- rt_floatset
118
- rt_floattype
252
+ fmridata : ndarray
253
+ 4D fMRI data array of shape (time, x, y, z).
254
+ referencetc : ndarray
255
+ Reference time course of shape (time,).
256
+ theCorrelator : object
257
+ An object implementing the `setreftc` and `setlimits` methods for correlation computation.
258
+ fmri_x : ndarray
259
+ Time points corresponding to fMRI data, shape (time,).
260
+ os_fmri_x : ndarray
261
+ Oversampled time points, shape (oversampled_time,).
262
+ lagmininpts : int
263
+ Minimum lag in samples to consider for correlation.
264
+ lagmaxinpts : int
265
+ Maximum lag in samples to consider for correlation.
266
+ corrout : ndarray
267
+ Output array to store correlation values, shape (time, x, y, z).
268
+ meanval : ndarray
269
+ Array to store mean values, shape (x, y, z).
270
+ nprocs : int, optional
271
+ Number of processes to use for parallel computation. Default is 1.
272
+ alwaysmultiproc : bool, optional
273
+ If True, always use multiprocessing even for single voxel processing. Default is False.
274
+ oversampfactor : int, optional
275
+ Oversampling factor for interpolation. Default is 1.
276
+ interptype : str, optional
277
+ Interpolation type, e.g., 'univariate'. Default is 'univariate'.
278
+ showprogressbar : bool, optional
279
+ Whether to display a progress bar. Default is True.
280
+ chunksize : int, optional
281
+ Size of chunks for multiprocessing. Default is 1000.
282
+ rt_floatset : type, optional
283
+ Floating-point type for internal computations. Default is np.float64.
284
+ rt_floattype : str, optional
285
+ String representation of floating-point type. Default is 'float64'.
286
+ debug : bool, optional
287
+ If True, enable debug logging. Default is False.
119
288
 
120
289
  Returns
121
290
  -------
291
+ tuple of (int, list of float, ndarray)
292
+ - Total number of voxels processed.
293
+ - List of global maximum correlation values.
294
+ - Correlation scale array.
295
+
296
+ Notes
297
+ -----
298
+ The function uses `tide_genericmultiproc.run_multiproc` to perform multi-voxel correlation
299
+ computations in parallel. It initializes a correlator object and sets the reference time course
300
+ and lag limits before starting the computation.
122
301
 
302
+ Examples
303
+ --------
304
+ >>> import numpy as np
305
+ >>> from some_module import correlationpass, SomeCorrelator
306
+ >>> fmri_data = np.random.rand(100, 64, 64, 32)
307
+ >>> ref_tc = np.random.rand(100)
308
+ >>> correlator = SomeCorrelator()
309
+ >>> fmri_x = np.linspace(0, 100, 100)
310
+ >>> os_fmri_x = np.linspace(0, 100, 200)
311
+ >>> corr_out = np.zeros_like(fmri_data)
312
+ >>> mean_val = np.zeros((64, 64, 32))
313
+ >>> total_voxels, max_vals, corr_scale = correlationpass(
314
+ ... fmridata=fmri_data,
315
+ ... referencetc=ref_tc,
316
+ ... theCorrelator=correlator,
317
+ ... fmri_x=fmri_x,
318
+ ... os_fmri_x=os_fmri_x,
319
+ ... lagmininpts=-10,
320
+ ... lagmaxinpts=10,
321
+ ... corrout=corr_out,
322
+ ... meanval=mean_val,
323
+ ... nprocs=4,
324
+ ... debug=False
325
+ ... )
123
326
  """
124
327
  if debug:
125
328
  print(f"calling setreftc in calcsimfunc with length {len(referencetc)}")