rapidtide 3.0.11__py3-none-any.whl → 3.1.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 (144) 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 +188 -40
  7. rapidtide/calcsimfunc.py +242 -42
  8. rapidtide/correlate.py +1203 -383
  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 +53 -3
  13. rapidtide/data/examples/src/testglmfilt +5 -5
  14. rapidtide/data/examples/src/testhappy +29 -7
  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 +2226 -110
  24. rapidtide/dlfiltertorch.py +4842 -0
  25. rapidtide/externaltools.py +327 -12
  26. rapidtide/fMRIData_class.py +79 -40
  27. rapidtide/filter.py +1899 -810
  28. rapidtide/fit.py +2011 -581
  29. rapidtide/genericmultiproc.py +93 -18
  30. rapidtide/happy_supportfuncs.py +2047 -172
  31. rapidtide/helper_classes.py +584 -43
  32. rapidtide/io.py +2370 -372
  33. rapidtide/linfitfiltpass.py +346 -99
  34. rapidtide/makelaggedtcs.py +210 -24
  35. rapidtide/maskutil.py +448 -62
  36. rapidtide/miscmath.py +827 -121
  37. rapidtide/multiproc.py +210 -22
  38. rapidtide/patchmatch.py +242 -42
  39. rapidtide/peakeval.py +31 -31
  40. rapidtide/ppgproc.py +2203 -0
  41. rapidtide/qualitycheck.py +352 -39
  42. rapidtide/refinedelay.py +431 -57
  43. rapidtide/refineregressor.py +494 -189
  44. rapidtide/resample.py +671 -185
  45. rapidtide/scripts/applyppgproc.py +28 -0
  46. rapidtide/scripts/showxcorr_legacy.py +7 -7
  47. rapidtide/scripts/stupidramtricks.py +15 -17
  48. rapidtide/simFuncClasses.py +1052 -77
  49. rapidtide/simfuncfit.py +269 -69
  50. rapidtide/stats.py +540 -238
  51. rapidtide/tests/happycomp +9 -0
  52. rapidtide/tests/test_cleanregressor.py +1 -2
  53. rapidtide/tests/test_dlfiltertorch.py +627 -0
  54. rapidtide/tests/test_findmaxlag.py +24 -8
  55. rapidtide/tests/test_fullrunhappy_v1.py +0 -2
  56. rapidtide/tests/test_fullrunhappy_v2.py +0 -2
  57. rapidtide/tests/test_fullrunhappy_v3.py +11 -4
  58. rapidtide/tests/test_fullrunhappy_v4.py +10 -2
  59. rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
  60. rapidtide/tests/test_getparsers.py +11 -3
  61. rapidtide/tests/test_refinedelay.py +0 -1
  62. rapidtide/tests/test_simroundtrip.py +16 -8
  63. rapidtide/tests/test_stcorrelate.py +3 -1
  64. rapidtide/tests/utils.py +9 -8
  65. rapidtide/tidepoolTemplate.py +142 -38
  66. rapidtide/tidepoolTemplate_alt.py +165 -44
  67. rapidtide/tidepoolTemplate_big.py +189 -52
  68. rapidtide/util.py +1217 -118
  69. rapidtide/voxelData.py +684 -37
  70. rapidtide/wiener.py +136 -23
  71. rapidtide/wiener2.py +113 -7
  72. rapidtide/workflows/adjustoffset.py +105 -3
  73. rapidtide/workflows/aligntcs.py +85 -2
  74. rapidtide/workflows/applydlfilter.py +87 -10
  75. rapidtide/workflows/applyppgproc.py +540 -0
  76. rapidtide/workflows/atlasaverage.py +210 -47
  77. rapidtide/workflows/atlastool.py +100 -3
  78. rapidtide/workflows/calcSimFuncMap.py +288 -69
  79. rapidtide/workflows/calctexticc.py +201 -9
  80. rapidtide/workflows/ccorrica.py +101 -6
  81. rapidtide/workflows/cleanregressor.py +165 -31
  82. rapidtide/workflows/delayvar.py +171 -23
  83. rapidtide/workflows/diffrois.py +81 -3
  84. rapidtide/workflows/endtidalproc.py +144 -4
  85. rapidtide/workflows/fdica.py +195 -15
  86. rapidtide/workflows/filtnifti.py +70 -3
  87. rapidtide/workflows/filttc.py +74 -3
  88. rapidtide/workflows/fitSimFuncMap.py +202 -51
  89. rapidtide/workflows/fixtr.py +73 -3
  90. rapidtide/workflows/gmscalc.py +113 -3
  91. rapidtide/workflows/happy.py +801 -199
  92. rapidtide/workflows/happy2std.py +144 -12
  93. rapidtide/workflows/happy_parser.py +163 -23
  94. rapidtide/workflows/histnifti.py +118 -2
  95. rapidtide/workflows/histtc.py +84 -3
  96. rapidtide/workflows/linfitfilt.py +117 -4
  97. rapidtide/workflows/localflow.py +328 -28
  98. rapidtide/workflows/mergequality.py +79 -3
  99. rapidtide/workflows/niftidecomp.py +322 -18
  100. rapidtide/workflows/niftistats.py +174 -4
  101. rapidtide/workflows/pairproc.py +98 -4
  102. rapidtide/workflows/pairwisemergenifti.py +85 -2
  103. rapidtide/workflows/parser_funcs.py +1421 -40
  104. rapidtide/workflows/physiofreq.py +137 -11
  105. rapidtide/workflows/pixelcomp.py +207 -5
  106. rapidtide/workflows/plethquality.py +103 -21
  107. rapidtide/workflows/polyfitim.py +151 -11
  108. rapidtide/workflows/proj2flow.py +75 -2
  109. rapidtide/workflows/rankimage.py +111 -4
  110. rapidtide/workflows/rapidtide.py +368 -76
  111. rapidtide/workflows/rapidtide2std.py +98 -2
  112. rapidtide/workflows/rapidtide_parser.py +109 -9
  113. rapidtide/workflows/refineDelayMap.py +144 -33
  114. rapidtide/workflows/refineRegressor.py +675 -96
  115. rapidtide/workflows/regressfrommaps.py +161 -37
  116. rapidtide/workflows/resamplenifti.py +85 -3
  117. rapidtide/workflows/resampletc.py +91 -3
  118. rapidtide/workflows/retrolagtcs.py +99 -9
  119. rapidtide/workflows/retroregress.py +176 -26
  120. rapidtide/workflows/roisummarize.py +174 -5
  121. rapidtide/workflows/runqualitycheck.py +71 -3
  122. rapidtide/workflows/showarbcorr.py +149 -6
  123. rapidtide/workflows/showhist.py +86 -2
  124. rapidtide/workflows/showstxcorr.py +160 -3
  125. rapidtide/workflows/showtc.py +159 -3
  126. rapidtide/workflows/showxcorrx.py +190 -10
  127. rapidtide/workflows/showxy.py +185 -15
  128. rapidtide/workflows/simdata.py +264 -38
  129. rapidtide/workflows/spatialfit.py +77 -2
  130. rapidtide/workflows/spatialmi.py +250 -27
  131. rapidtide/workflows/spectrogram.py +305 -32
  132. rapidtide/workflows/synthASL.py +154 -3
  133. rapidtide/workflows/tcfrom2col.py +76 -2
  134. rapidtide/workflows/tcfrom3col.py +74 -2
  135. rapidtide/workflows/tidepool.py +2971 -130
  136. rapidtide/workflows/utils.py +19 -14
  137. rapidtide/workflows/utils_doc.py +293 -0
  138. rapidtide/workflows/variabilityizer.py +116 -3
  139. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/METADATA +10 -8
  140. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/RECORD +144 -128
  141. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/entry_points.txt +1 -0
  142. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/WHEEL +0 -0
  143. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/licenses/LICENSE +0 -0
  144. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/top_level.txt +0 -0
@@ -42,8 +42,6 @@ def test_fullrunhappy_v1(debug=False, local=False, displayplots=False):
42
42
  "--mklthreads",
43
43
  "-1",
44
44
  "--spatialregression",
45
- "--model",
46
- "model_revised_tf2",
47
45
  ]
48
46
  happy_workflow.happy_main(happy_parser.process_args(inputargs=inputargs))
49
47
 
@@ -45,8 +45,6 @@ def test_fullrunhappy_v2(debug=False, local=False, displayplots=False):
45
45
  os.path.join(exampleroot, "sub-HAPPYTEST_smallmask.nii.gz"),
46
46
  "--mklthreads",
47
47
  "-1",
48
- "--model",
49
- "model_revised_tf2",
50
48
  "--fliparteries",
51
49
  "--temporalregression",
52
50
  "--cardiacfile",
@@ -24,6 +24,13 @@ import rapidtide.workflows.happy as happy_workflow
24
24
  import rapidtide.workflows.happy_parser as happy_parser
25
25
  from rapidtide.tests.utils import get_examples_path, get_test_temp_path
26
26
 
27
+ try:
28
+ import tensorflow as tf
29
+
30
+ tensorflowexists = True
31
+ except ImportError:
32
+ tensorflowexists = False
33
+
27
34
 
28
35
  def test_fullrunhappy_v3(debug=False, local=False, displayplots=False):
29
36
  # set input and output directories
@@ -45,12 +52,12 @@ def test_fullrunhappy_v3(debug=False, local=False, displayplots=False):
45
52
  os.path.join(exampleroot, "sub-HAPPYTEST_smallmask.nii.gz"),
46
53
  "--mklthreads",
47
54
  "-1",
48
- "--model",
49
- "model_revised_tf2",
50
55
  "--cardcalconly",
51
56
  ]
52
- # "--motionfile",
53
- # os.path.join(exampleroot, "sub-HAPPYTEST_mcf.par"),
57
+ if tensorflowexists:
58
+ inputargs.append("--usetensorflow")
59
+ inputargs.append("--model")
60
+ inputargs.append("model_revised_tf2")
54
61
  happy_workflow.happy_main(happy_parser.process_args(inputargs=inputargs))
55
62
 
56
63
 
@@ -24,7 +24,14 @@ import rapidtide.workflows.happy as happy_workflow
24
24
  import rapidtide.workflows.happy_parser as happy_parser
25
25
  from rapidtide.tests.utils import get_examples_path, get_test_temp_path
26
26
 
27
+ try:
28
+ import tensorflow as tf
27
29
 
30
+ tensorflowexists = True
31
+ except ImportError:
32
+ tensorflowexists = False
33
+
34
+
28
35
  def test_fullrunhappy_v4(debug=False, local=False, displayplots=False):
29
36
  # set input and output directories
30
37
  if local:
@@ -45,12 +52,13 @@ def test_fullrunhappy_v4(debug=False, local=False, displayplots=False):
45
52
  os.path.join(exampleroot, "sub-HAPPYTEST_smallmask.nii.gz"),
46
53
  "--mklthreads",
47
54
  "-1",
48
- "--model",
49
- "model_revised_tf2",
55
+ "--usenewvesselmethod",
50
56
  "--motionfile",
51
57
  os.path.join(exampleroot, "sub-HAPPYTEST_mcf.par"),
52
58
  "--aliasedcorrelation",
53
59
  ]
60
+ if tensorflowexists:
61
+ inputargs.append("--usetensorflow")
54
62
  happy_workflow.happy_main(happy_parser.process_args(inputargs=inputargs))
55
63
 
56
64
 
@@ -81,7 +81,7 @@ def test_fullrunrapidtide_v7(debug=False, local=False, displayplots=False):
81
81
  rapidtide_retroregress.retroregress(rapidtide_retroregress.process_args(inputargs=inputargs))
82
82
 
83
83
  # check to see that rapidtide and retroregress output match
84
- msethresh = 1e-6
84
+ msethresh = 2e-6
85
85
  aethresh = 2
86
86
  tclist = ["brain", "GM", "WM", "CSF"]
87
87
  for timecourse in tclist:
@@ -20,7 +20,6 @@ import numpy as np
20
20
 
21
21
  from rapidtide.workflows.adjustoffset import _get_parser as adjustoffset_getparser
22
22
  from rapidtide.workflows.aligntcs import _get_parser as aligntcs_getparser
23
- from rapidtide.workflows.applydlfilter import _get_parser as applydlfilter_getparser
24
23
  from rapidtide.workflows.atlasaverage import _get_parser as atlasaverage_getparser
25
24
  from rapidtide.workflows.atlastool import _get_parser as atlastool_getparser
26
25
  from rapidtide.workflows.calctexticc import _get_parser as calctexticc_getparser
@@ -84,7 +83,6 @@ def test_parsers(debug=False):
84
83
  parserlist = [
85
84
  adjustoffset_getparser,
86
85
  aligntcs_getparser,
87
- applydlfilter_getparser,
88
86
  atlasaverage_getparser,
89
87
  atlastool_getparser,
90
88
  calctexticc_getparser,
@@ -137,7 +135,17 @@ def test_parsers(debug=False):
137
135
  tcfrom3col_getparser,
138
136
  variabilityizer_getparser,
139
137
  ]
140
-
138
+ try:
139
+ import tensorflow as tf
140
+ dlfilterloads = True
141
+ except ImportError:
142
+ dlfilterloads = False
143
+ if dlfilterloads:
144
+ from rapidtide.workflows.applydlfilter import (
145
+ _get_parser as applydlfilter_getparser,
146
+ )
147
+ parserlist.append(applydlfilter_getparser)
148
+
141
149
  for thegetparser in parserlist:
142
150
  theusage = thegetparser().format_help()
143
151
  if debug:
@@ -144,7 +144,6 @@ def eval_refinedelay(
144
144
  theheader["pixdim"][4] = 1.0
145
145
 
146
146
  rt_floattype = "float64"
147
- rt_floatset = np.float64
148
147
  sLFOfitmean = np.zeros(numlags, dtype=rt_floattype)
149
148
  rvalue = np.zeros(numlags, dtype=rt_floattype)
150
149
  r2value = np.zeros(numlags, dtype=rt_floattype)
@@ -37,11 +37,14 @@ def test_simroundtrip(debug=False, local=False, displayplots=False):
37
37
  exampleroot = get_examples_path()
38
38
  testtemproot = get_test_temp_path()
39
39
 
40
-
41
40
  # run initial rapidtide
42
41
  inputargs = [
43
42
  os.path.join(exampleroot, "sub-RAPIDTIDETEST.nii.gz"),
44
43
  os.path.join(testtemproot, "sub-RAPIDTIDETESTSIM"),
44
+ "--corrmask",
45
+ os.path.join(exampleroot, "sub-RAPIDTIDETEST_restrictedmask.nii.gz"),
46
+ "--globalmeaninclude",
47
+ os.path.join(exampleroot, "sub-RAPIDTIDETEST_brainmask.nii.gz"),
45
48
  "--spatialfilt",
46
49
  "2",
47
50
  "--simcalcrange",
@@ -58,24 +61,29 @@ def test_simroundtrip(debug=False, local=False, displayplots=False):
58
61
  ]
59
62
  rapidtide_workflow.rapidtide_main(rapidtide_parser.process_args(inputargs=inputargs))
60
63
 
64
+ print("initial rapidtide run complete")
65
+
61
66
  # now simulate data from maps
62
67
  print(testtemproot)
63
68
  inputargs = [
64
69
  "1.5",
65
70
  "260",
66
- os.path.join( testtemproot, "sub-RAPIDTIDETESTSIM_desc-unfiltmean_map.nii.gz"),
67
- os.path.join( testtemproot, "simulatedfmri_vn05"),
71
+ os.path.join(testtemproot, "sub-RAPIDTIDETESTSIM_desc-unfiltmean_map.nii.gz"),
72
+ os.path.join(testtemproot, "simulatedfmri_vn05"),
68
73
  "--lfopctfile",
69
- os.path.join( testtemproot, "sub-RAPIDTIDETESTSIM_desc-maxcorr_map.nii.gz"),
74
+ os.path.join(testtemproot, "sub-RAPIDTIDETESTSIM_desc-maxcorr_map.nii.gz"),
70
75
  "--lfolagfile",
71
- os.path.join( testtemproot, "sub-RAPIDTIDETESTSIM_desc-maxtimerefined_map.nii.gz"),
76
+ os.path.join(testtemproot, "sub-RAPIDTIDETESTSIM_desc-maxtimerefined_map.nii.gz"),
72
77
  "--lforegressor",
73
- os.path.join(testtemproot, "sub-RAPIDTIDETESTSIM_desc-movingregressor_timeseries.json:pass2"),
78
+ os.path.join(
79
+ testtemproot, "sub-RAPIDTIDETESTSIM_desc-movingregressor_timeseries.json:pass2"
80
+ ),
74
81
  "--voxelnoiselevel",
75
- "5.0"
82
+ "5.0",
76
83
  ]
77
84
 
78
85
  pf.generic_init(rapidtide_simdata._get_parser, rapidtide_simdata.simdata, inputargs=inputargs)
86
+ print("simulated dataset generated")
79
87
 
80
88
  # run repeat rapidtide
81
89
  inputargs = [
@@ -96,6 +104,7 @@ def test_simroundtrip(debug=False, local=False, displayplots=False):
96
104
  "4.0",
97
105
  ]
98
106
  rapidtide_workflow.rapidtide_main(rapidtide_parser.process_args(inputargs=inputargs))
107
+ print("repeat rapidtide completed")
99
108
 
100
109
  absthresh = 1e-10
101
110
  msethresh = 1e-12
@@ -118,7 +127,6 @@ def test_simroundtrip(debug=False, local=False, displayplots=False):
118
127
  )"""
119
128
 
120
129
 
121
-
122
130
  if __name__ == "__main__":
123
131
  mpl.use("TkAgg")
124
132
  test_simroundtrip(debug=True, local=True, displayplots=True)
@@ -58,6 +58,7 @@ def test_stcorrelate(debug=False):
58
58
  times, corrpertime, ppertime = shorttermcorr_1D(
59
59
  sig1, sig2, tr, windowtime, samplestep=int(stepsize // tr), detrendorder=0
60
60
  )
61
+ print(f"1D correlation: {corrpertime=}, {ppertime=}")
61
62
  # plength = len(times)
62
63
  times, xcorrpertime, Rvals, delayvals, valid = shorttermcorr_2D(
63
64
  sig1,
@@ -67,8 +68,9 @@ def test_stcorrelate(debug=False):
67
68
  samplestep=int(stepsize // tr),
68
69
  weighting=corrweighting,
69
70
  detrendorder=0,
70
- displayplots=False,
71
+ displayplots=debug,
71
72
  )
73
+ print(f"2D correlation: {Rvals=}, {delayvals=}, {valid=}")
72
74
  # xlength = len(times)
73
75
  writenpvecs(corrpertime, outfilename + "_pearson.txt")
74
76
  writenpvecs(ppertime, outfilename + "_pvalue.txt")
rapidtide/tests/utils.py CHANGED
@@ -23,9 +23,10 @@ Utility functions for testing rapidtide.
23
23
  import os
24
24
 
25
25
  import numpy as np
26
+ import numpy.typing as npt
26
27
 
27
28
 
28
- def get_rapidtide_root():
29
+ def get_rapidtide_root() -> str:
29
30
  """
30
31
  Returns the path to the base rapidtide directory, terminated with separator.
31
32
  Based on function by Yaroslav Halchenko used in Neurosynth Python package.
@@ -34,7 +35,7 @@ def get_rapidtide_root():
34
35
  return os.path.join(thisdir, "..") + os.path.sep
35
36
 
36
37
 
37
- def get_scripts_path():
38
+ def get_scripts_path() -> str:
38
39
  """
39
40
  Returns the path to test datasets, terminated with separator. Test-related
40
41
  data are kept in tests folder in "testdata".
@@ -43,7 +44,7 @@ def get_scripts_path():
43
44
  return os.path.realpath(os.path.join(get_rapidtide_root(), "scripts")) + os.path.sep
44
45
 
45
46
 
46
- def get_test_data_path():
47
+ def get_test_data_path() -> str:
47
48
  """
48
49
  Returns the path to test datasets, terminated with separator. Test-related
49
50
  data are kept in tests folder in "testdata".
@@ -52,7 +53,7 @@ def get_test_data_path():
52
53
  return os.path.realpath(os.path.join(get_rapidtide_root(), "tests", "testdata")) + os.path.sep
53
54
 
54
55
 
55
- def get_test_target_path():
56
+ def get_test_target_path() -> str:
56
57
  """
57
58
  Returns the path to test comparison data, terminated with separator. Test-related
58
59
  data are kept in tests folder in "testtargets".
@@ -63,7 +64,7 @@ def get_test_target_path():
63
64
  )
64
65
 
65
66
 
66
- def get_test_temp_path():
67
+ def get_test_temp_path() -> str:
67
68
  """
68
69
  Returns the path to test temporary directory, terminated with separator.
69
70
  Based on function by Yaroslav Halchenko used in Neurosynth Python package.
@@ -71,7 +72,7 @@ def get_test_temp_path():
71
72
  return os.path.realpath(os.path.join(get_rapidtide_root(), "tests", "tmp")) + os.path.sep
72
73
 
73
74
 
74
- def get_examples_path():
75
+ def get_examples_path() -> str:
75
76
  """
76
77
  Returns the path to examples src directory, where larger test files live, terminated with separator. Test-related
77
78
  data are kept in tests folder in "data".
@@ -83,7 +84,7 @@ def get_examples_path():
83
84
  )
84
85
 
85
86
 
86
- def create_dir(thedir, debug=False):
87
+ def create_dir(thedir: str, debug: bool = False) -> None:
87
88
  # create a directory if it doesn't exist
88
89
  try:
89
90
  os.makedirs(thedir)
@@ -96,7 +97,7 @@ def create_dir(thedir, debug=False):
96
97
  pass
97
98
 
98
99
 
99
- def mse(ndarr1, ndarr2):
100
+ def mse(ndarr1: npt.NDArray, ndarr2: npt.NDArray) -> np.floating:
100
101
  """
101
102
  Compute mean-squared error.
102
103
  """