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
@@ -18,8 +18,11 @@
18
18
  #
19
19
  import argparse
20
20
  import sys
21
+ from argparse import Namespace
22
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
21
23
 
22
24
  import numpy as np
25
+ from numpy.typing import NDArray
23
26
 
24
27
  import rapidtide.correlate as tide_corr
25
28
  import rapidtide.filter as tide_filt
@@ -28,9 +31,32 @@ import rapidtide.io as tide_io
28
31
  import rapidtide.miscmath as tide_math
29
32
 
30
33
 
31
- def _get_parser():
34
+ def _get_parser() -> Any:
32
35
  """
33
- Argument parser for pixelcomp
36
+ Argument parser for spatialmi.
37
+
38
+ This function constructs and returns an `argparse.ArgumentParser` object configured
39
+ to parse command-line arguments for the `spatialmi` tool, which calculates localized
40
+ spatial mutual information between two NIfTI images.
41
+
42
+ Returns
43
+ -------
44
+ argparse.ArgumentParser
45
+ Configured argument parser for the spatial mutual information calculation tool.
46
+
47
+ Notes
48
+ -----
49
+ The parser requires four mandatory positional arguments: two input NIfTI image filenames,
50
+ two corresponding mask filenames, and an output root name. Optional arguments allow
51
+ customization of the calculation, including neighborhood shape, filtering, normalization,
52
+ and debugging output.
53
+
54
+ Examples
55
+ --------
56
+ >>> parser = _get_parser()
57
+ >>> args = parser.parse_args()
58
+ >>> print(args.inputfilename1)
59
+ 'input1.nii.gz'
34
60
  """
35
61
  parser = argparse.ArgumentParser(
36
62
  prog="spatialmi",
@@ -138,23 +164,77 @@ def _get_parser():
138
164
 
139
165
 
140
166
  def getneighborhood(
141
- indata,
142
- xloc,
143
- yloc,
144
- zloc,
145
- xsize,
146
- ysize,
147
- zsize,
148
- radius,
149
- spherical=False,
150
- kernelwidth=1.5,
151
- slop=0.01,
152
- debug=False,
153
- ):
167
+ indata: NDArray[np.floating[Any]],
168
+ xloc: Any,
169
+ yloc: Any,
170
+ zloc: Any,
171
+ xsize: Any,
172
+ ysize: Any,
173
+ zsize: Any,
174
+ radius: Any,
175
+ spherical: bool = False,
176
+ kernelwidth: float = 1.5,
177
+ slop: float = 0.01,
178
+ debug: bool = False,
179
+ ) -> NDArray[np.floating[Any]]:
180
+ """
181
+ Extract a neighborhood from a 3D dataset, either as a weighted kernel or a spherical region.
182
+
183
+ This function retrieves a local neighborhood around a specified 3D location in a dataset.
184
+ The neighborhood can be extracted either as a cubic region with a Gaussian-weighted kernel
185
+ (when `spherical=False`) or as a spherical region (when `spherical=True`).
186
+
187
+ Parameters
188
+ ----------
189
+ indata : NDArray[np.floating[Any]]
190
+ Input 3D dataset from which the neighborhood is extracted.
191
+ xloc, yloc, zloc : float or int
192
+ The center coordinates of the neighborhood in the dataset.
193
+ xsize, ysize, zsize : int
194
+ Dimensions of the input dataset along each axis.
195
+ radius : float or int
196
+ The radius of the neighborhood. For `spherical=False`, this defines the cubic
197
+ kernel size. For `spherical=True`, it defines the spherical radius.
198
+ spherical : bool, optional
199
+ If True, extracts a spherical neighborhood. If False, extracts a cubic neighborhood
200
+ with a Gaussian kernel. Default is False.
201
+ kernelwidth : float, optional
202
+ Width parameter for the Gaussian kernel used when `spherical=False`. Default is 1.5.
203
+ slop : float, optional
204
+ Tolerance for spherical radius checking. Default is 0.01.
205
+ debug : bool, optional
206
+ If True, prints debug information about the index list initialization. Default is False.
207
+
208
+ Returns
209
+ -------
210
+ NDArray[np.floating[Any]]
211
+ A flattened array of the neighborhood values. When `spherical=False`, the values
212
+ are weighted by a Gaussian kernel. When `spherical=True`, the values are unweighted.
213
+
214
+ Notes
215
+ -----
216
+ - The function uses global variables `kernel`, `usedwidth`, `indexlist`, and `usedradius`
217
+ to cache computations for performance. These are initialized on first call.
218
+ - For `spherical=False`, the function returns a flattened array of the kernel-weighted
219
+ neighborhood.
220
+ - For `spherical=True`, the function returns a flattened array of values within the
221
+ spherical neighborhood.
222
+
223
+ Examples
224
+ --------
225
+ >>> import numpy as np
226
+ >>> data = np.random.rand(10, 10, 10)
227
+ >>> neighborhood = getneighborhood(data, 5, 5, 5, 10, 10, 10, 2, spherical=False)
228
+ >>> print(neighborhood.shape)
229
+ (125,)
230
+ >>> neighborhood = getneighborhood(data, 5, 5, 5, 10, 10, 10, 2, spherical=True)
231
+ >>> print(neighborhood.shape)
232
+ (33,)
233
+ """
154
234
  if not spherical:
155
235
  global usedwidth, kernel
156
236
  try:
157
- kernel
237
+ dummy = kernel
158
238
  except NameError:
159
239
  usedwidth = kernelwidth
160
240
  kernel = None
@@ -230,7 +310,66 @@ def getneighborhood(
230
310
  return np.array(outdata)
231
311
 
232
312
 
233
- def getMI(x, y, norm=True, bins=-1, init=False, prebin=True, sigma=0.25, debug=False):
313
+ def getMI(
314
+ x: Any,
315
+ y: Any,
316
+ norm: bool = True,
317
+ bins: int = -1,
318
+ init: bool = False,
319
+ prebin: bool = True,
320
+ sigma: float = 0.25,
321
+ debug: bool = False,
322
+ ) -> None:
323
+ """
324
+ Compute the mutual information between two variables using binned estimation.
325
+
326
+ This function calculates the mutual information between two input arrays `x` and `y`,
327
+ using a binned approach. It supports normalization, automatic bin selection, and
328
+ optional pre-binning for performance optimization.
329
+
330
+ Parameters
331
+ ----------
332
+ x : array-like
333
+ First input variable.
334
+ y : array-like
335
+ Second input variable.
336
+ norm : bool, optional
337
+ If True, normalize the input variables using standard normalization
338
+ (zero mean, unit variance). Default is True.
339
+ bins : int, optional
340
+ Number of bins to use for the 2D histogram. If less than 1, the number
341
+ of bins is automatically determined as `max(int(sqrt(len(x) / 5)), 3)`.
342
+ Default is -1.
343
+ init : bool, optional
344
+ If True, reinitialize the global binning structure. Default is False.
345
+ prebin : bool, optional
346
+ If True, use precomputed bin edges. If False, use the number of bins
347
+ directly. Default is True.
348
+ sigma : float, optional
349
+ Standard deviation for Gaussian smoothing in the mutual information
350
+ calculation. Default is 0.25.
351
+ debug : bool, optional
352
+ If True, print debugging information during execution. Default is False.
353
+
354
+ Returns
355
+ -------
356
+ None
357
+ The function returns the result of `tide_corr.mutual_info_2d`, which is
358
+ not explicitly returned here but is the core output of the function.
359
+
360
+ Notes
361
+ -----
362
+ The function uses a global variable `thebins` to store binning information.
363
+ If `init` is True or `thebins` is None, bin edges are computed and stored
364
+ in `thebins`. The function relies on `tide_math.stdnormalize` for normalization
365
+ and `tide_corr.mutual_info_2d` for the actual mutual information computation.
366
+
367
+ Examples
368
+ --------
369
+ >>> x = [1, 2, 3, 4, 5]
370
+ >>> y = [2, 4, 6, 8, 10]
371
+ >>> getMI(x, y, norm=True, bins=10, debug=False)
372
+ """
234
373
  global thebins
235
374
 
236
375
  if norm:
@@ -274,18 +413,103 @@ def getMI(x, y, norm=True, bins=-1, init=False, prebin=True, sigma=0.25, debug=F
274
413
  f"normy min, max, mean, std: {np.min(normy)}, {np.max(normy)}, {np.mean(normy)}, {np.std(normy)}"
275
414
  )
276
415
 
277
- return tide_corr.mutual_info_2d(
278
- normx,
279
- normy,
280
- bins=thebins,
281
- normalized=norm,
282
- fast=fast,
283
- sigma=sigma,
284
- debug=debug,
285
- )
416
+ if fast:
417
+ return tide_corr.mutual_info_2d_fast(
418
+ normx,
419
+ normy,
420
+ thebins,
421
+ normalized=norm,
422
+ sigma=sigma,
423
+ debug=debug,
424
+ )
425
+ else:
426
+ return tide_corr.mutual_info_2d(
427
+ normx,
428
+ normy,
429
+ thebins,
430
+ normalized=norm,
431
+ sigma=sigma,
432
+ debug=debug,
433
+ )
434
+
286
435
 
287
436
 
288
- def spatialmi(args):
437
+ def spatialmi(args: Any) -> None:
438
+ """
439
+ Compute spatial mutual information (MI) between two 3D images over a specified neighborhood.
440
+
441
+ This function reads two input NIfTI images and their corresponding masks, computes the
442
+ mutual information between the images within a local neighborhood for each voxel,
443
+ and saves the result as a NIfTI file. Optional spatial filtering can be applied
444
+ before computing the MI.
445
+
446
+ Parameters
447
+ ----------
448
+ args : Any
449
+ Parsed command-line arguments containing:
450
+ - inputfilename1 : str
451
+ Path to the first input NIfTI image.
452
+ - inputfilename2 : str
453
+ Path to the second input NIfTI image.
454
+ - maskfilename1 : str
455
+ Path to the mask for the first image.
456
+ - maskfilename2 : str
457
+ Path to the mask for the second image.
458
+ - index1 : int, optional
459
+ Index of the time point to use from the first image (default is 0).
460
+ - index2 : int, optional
461
+ Index of the time point to use from the second image (default is 0).
462
+ - radius : float
463
+ Neighborhood radius for computing mutual information.
464
+ - sigma : float, optional
465
+ Standard deviation for spatial smoothing (default is None).
466
+ - spherical : bool
467
+ Whether to use a spherical neighborhood (default is False).
468
+ - kernelwidth : float
469
+ Width of the kernel for neighborhood computation (default is None).
470
+ - norm : bool
471
+ Whether to normalize the data before computing MI (default is False).
472
+ - prebin : bool
473
+ Whether to pre-bin the data (default is False).
474
+ - debug : bool
475
+ Enable debug output (default is False).
476
+ - outputroot : str
477
+ Root name for the output NIfTI file.
478
+
479
+ Returns
480
+ -------
481
+ None
482
+ The function writes the computed spatial mutual information to a NIfTI file
483
+ named `<outputroot>_result.nii.gz`.
484
+
485
+ Notes
486
+ -----
487
+ - The function requires that both input images and their masks have matching spatial dimensions.
488
+ - If `sigma` is specified, spatial filtering is applied using a Gaussian kernel.
489
+ - The neighborhood is defined by the `radius` and `spherical` parameters.
490
+ - The output file contains mutual information values for each voxel in the masked region.
491
+
492
+ Examples
493
+ --------
494
+ >>> import argparse
495
+ >>> args = argparse.Namespace(
496
+ ... inputfilename1='image1.nii.gz',
497
+ ... inputfilename2='image2.nii.gz',
498
+ ... maskfilename1='mask1.nii.gz',
499
+ ... maskfilename2='mask2.nii.gz',
500
+ ... index1=0,
501
+ ... index2=0,
502
+ ... radius=5.0,
503
+ ... sigma=None,
504
+ ... spherical=True,
505
+ ... kernelwidth=None,
506
+ ... norm=False,
507
+ ... prebin=False,
508
+ ... debug=False,
509
+ ... outputroot='output'
510
+ ... )
511
+ >>> spatialmi(args)
512
+ """
289
513
  global thebins
290
514
  thebins = None
291
515