rapidtide 2.9.5__py3-none-any.whl → 3.1.3__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 (405) hide show
  1. cloud/gmscalc-HCPYA +1 -1
  2. cloud/mount-and-run +2 -0
  3. cloud/rapidtide-HCPYA +3 -3
  4. rapidtide/Colortables.py +538 -38
  5. rapidtide/OrthoImageItem.py +1094 -51
  6. rapidtide/RapidtideDataset.py +1709 -114
  7. rapidtide/__init__.py +0 -8
  8. rapidtide/_version.py +4 -4
  9. rapidtide/calccoherence.py +242 -97
  10. rapidtide/calcnullsimfunc.py +240 -140
  11. rapidtide/calcsimfunc.py +314 -129
  12. rapidtide/correlate.py +1211 -389
  13. rapidtide/data/examples/src/testLD +56 -0
  14. rapidtide/data/examples/src/test_findmaxlag.py +2 -2
  15. rapidtide/data/examples/src/test_mlregressallt.py +32 -17
  16. rapidtide/data/examples/src/testalign +1 -1
  17. rapidtide/data/examples/src/testatlasaverage +35 -7
  18. rapidtide/data/examples/src/testboth +21 -0
  19. rapidtide/data/examples/src/testcifti +11 -0
  20. rapidtide/data/examples/src/testdelayvar +13 -0
  21. rapidtide/data/examples/src/testdlfilt +25 -0
  22. rapidtide/data/examples/src/testfft +35 -0
  23. rapidtide/data/examples/src/testfileorfloat +37 -0
  24. rapidtide/data/examples/src/testfmri +94 -27
  25. rapidtide/data/examples/src/testfuncs +3 -3
  26. rapidtide/data/examples/src/testglmfilt +8 -6
  27. rapidtide/data/examples/src/testhappy +84 -51
  28. rapidtide/data/examples/src/testinitdelay +19 -0
  29. rapidtide/data/examples/src/testmodels +33 -0
  30. rapidtide/data/examples/src/testnewrefine +26 -0
  31. rapidtide/data/examples/src/testnoiseamp +21 -0
  32. rapidtide/data/examples/src/testppgproc +17 -0
  33. rapidtide/data/examples/src/testrefineonly +22 -0
  34. rapidtide/data/examples/src/testretro +26 -13
  35. rapidtide/data/examples/src/testretrolagtcs +16 -0
  36. rapidtide/data/examples/src/testrolloff +11 -0
  37. rapidtide/data/examples/src/testsimdata +45 -28
  38. rapidtide/data/models/model_cnn_pytorch/loss.png +0 -0
  39. rapidtide/data/models/model_cnn_pytorch/loss.txt +1 -0
  40. rapidtide/data/models/model_cnn_pytorch/model.pth +0 -0
  41. rapidtide/data/models/model_cnn_pytorch/model_meta.json +68 -0
  42. rapidtide/data/models/model_cnn_pytorch_fulldata/loss.png +0 -0
  43. rapidtide/data/models/model_cnn_pytorch_fulldata/loss.txt +1 -0
  44. rapidtide/data/models/model_cnn_pytorch_fulldata/model.pth +0 -0
  45. rapidtide/data/models/model_cnn_pytorch_fulldata/model_meta.json +80 -0
  46. rapidtide/data/models/model_cnnbp_pytorch_fullldata/loss.png +0 -0
  47. rapidtide/data/models/model_cnnbp_pytorch_fullldata/loss.txt +1 -0
  48. rapidtide/data/models/model_cnnbp_pytorch_fullldata/model.pth +0 -0
  49. rapidtide/data/models/model_cnnbp_pytorch_fullldata/model_meta.json +138 -0
  50. rapidtide/data/models/model_cnnfft_pytorch_fulldata/loss.png +0 -0
  51. rapidtide/data/models/model_cnnfft_pytorch_fulldata/loss.txt +1 -0
  52. rapidtide/data/models/model_cnnfft_pytorch_fulldata/model.pth +0 -0
  53. rapidtide/data/models/model_cnnfft_pytorch_fulldata/model_meta.json +128 -0
  54. rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/loss.png +0 -0
  55. rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/loss.txt +1 -0
  56. rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/model.pth +0 -0
  57. rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/model_meta.json +49 -0
  58. rapidtide/data/models/model_revised_tf2/model.keras +0 -0
  59. rapidtide/data/models/{model_serdar → model_revised_tf2}/model_meta.json +1 -1
  60. rapidtide/data/models/model_serdar2_tf2/model.keras +0 -0
  61. rapidtide/data/models/{model_serdar2 → model_serdar2_tf2}/model_meta.json +1 -1
  62. rapidtide/data/models/model_serdar_tf2/model.keras +0 -0
  63. rapidtide/data/models/{model_revised → model_serdar_tf2}/model_meta.json +1 -1
  64. rapidtide/data/reference/HCP1200v2_MTT_2mm.nii.gz +0 -0
  65. rapidtide/data/reference/HCP1200v2_binmask_2mm.nii.gz +0 -0
  66. rapidtide/data/reference/HCP1200v2_csf_2mm.nii.gz +0 -0
  67. rapidtide/data/reference/HCP1200v2_gray_2mm.nii.gz +0 -0
  68. rapidtide/data/reference/HCP1200v2_graylaghist.json +7 -0
  69. rapidtide/data/reference/HCP1200v2_graylaghist.tsv.gz +0 -0
  70. rapidtide/data/reference/HCP1200v2_laghist.json +7 -0
  71. rapidtide/data/reference/HCP1200v2_laghist.tsv.gz +0 -0
  72. rapidtide/data/reference/HCP1200v2_mask_2mm.nii.gz +0 -0
  73. rapidtide/data/reference/HCP1200v2_maxcorr_2mm.nii.gz +0 -0
  74. rapidtide/data/reference/HCP1200v2_maxtime_2mm.nii.gz +0 -0
  75. rapidtide/data/reference/HCP1200v2_maxwidth_2mm.nii.gz +0 -0
  76. rapidtide/data/reference/HCP1200v2_negmask_2mm.nii.gz +0 -0
  77. rapidtide/data/reference/HCP1200v2_timepercentile_2mm.nii.gz +0 -0
  78. rapidtide/data/reference/HCP1200v2_white_2mm.nii.gz +0 -0
  79. rapidtide/data/reference/HCP1200v2_whitelaghist.json +7 -0
  80. rapidtide/data/reference/HCP1200v2_whitelaghist.tsv.gz +0 -0
  81. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1-seg2.xml +131 -0
  82. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1-seg2_regions.txt +60 -0
  83. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1-seg2_space-MNI152NLin6Asym_2mm.nii.gz +0 -0
  84. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm.nii.gz +0 -0
  85. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm_mask.nii.gz +0 -0
  86. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin6Asym_2mm_mask.nii.gz +0 -0
  87. rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL2_space-MNI152NLin6Asym_2mm_mask.nii.gz +0 -0
  88. rapidtide/data/reference/MNI152_T1_1mm_Brain_FAST_seg.nii.gz +0 -0
  89. rapidtide/data/reference/MNI152_T1_1mm_Brain_Mask.nii.gz +0 -0
  90. rapidtide/data/reference/MNI152_T1_2mm_Brain_FAST_seg.nii.gz +0 -0
  91. rapidtide/data/reference/MNI152_T1_2mm_Brain_Mask.nii.gz +0 -0
  92. rapidtide/decorators.py +91 -0
  93. rapidtide/dlfilter.py +2553 -414
  94. rapidtide/dlfiltertorch.py +5201 -0
  95. rapidtide/externaltools.py +328 -13
  96. rapidtide/fMRIData_class.py +178 -0
  97. rapidtide/ffttools.py +168 -0
  98. rapidtide/filter.py +2704 -1462
  99. rapidtide/fit.py +2361 -579
  100. rapidtide/genericmultiproc.py +197 -0
  101. rapidtide/happy_supportfuncs.py +3255 -548
  102. rapidtide/helper_classes.py +590 -1181
  103. rapidtide/io.py +2569 -468
  104. rapidtide/linfitfiltpass.py +784 -0
  105. rapidtide/makelaggedtcs.py +267 -97
  106. rapidtide/maskutil.py +555 -25
  107. rapidtide/miscmath.py +867 -137
  108. rapidtide/multiproc.py +217 -44
  109. rapidtide/patchmatch.py +752 -0
  110. rapidtide/peakeval.py +32 -32
  111. rapidtide/ppgproc.py +2205 -0
  112. rapidtide/qualitycheck.py +353 -40
  113. rapidtide/refinedelay.py +854 -0
  114. rapidtide/refineregressor.py +939 -0
  115. rapidtide/resample.py +725 -204
  116. rapidtide/scripts/__init__.py +1 -0
  117. rapidtide/scripts/{adjustoffset → adjustoffset.py} +7 -2
  118. rapidtide/scripts/{aligntcs → aligntcs.py} +7 -2
  119. rapidtide/scripts/{applydlfilter → applydlfilter.py} +7 -2
  120. rapidtide/scripts/applyppgproc.py +28 -0
  121. rapidtide/scripts/{atlasaverage → atlasaverage.py} +7 -2
  122. rapidtide/scripts/{atlastool → atlastool.py} +7 -2
  123. rapidtide/scripts/{calcicc → calcicc.py} +7 -2
  124. rapidtide/scripts/{calctexticc → calctexticc.py} +7 -2
  125. rapidtide/scripts/{calcttest → calcttest.py} +7 -2
  126. rapidtide/scripts/{ccorrica → ccorrica.py} +7 -2
  127. rapidtide/scripts/delayvar.py +28 -0
  128. rapidtide/scripts/{diffrois → diffrois.py} +7 -2
  129. rapidtide/scripts/{endtidalproc → endtidalproc.py} +7 -2
  130. rapidtide/scripts/{fdica → fdica.py} +7 -2
  131. rapidtide/scripts/{filtnifti → filtnifti.py} +7 -2
  132. rapidtide/scripts/{filttc → filttc.py} +7 -2
  133. rapidtide/scripts/{fingerprint → fingerprint.py} +20 -16
  134. rapidtide/scripts/{fixtr → fixtr.py} +7 -2
  135. rapidtide/scripts/{gmscalc → gmscalc.py} +7 -2
  136. rapidtide/scripts/{happy → happy.py} +7 -2
  137. rapidtide/scripts/{happy2std → happy2std.py} +7 -2
  138. rapidtide/scripts/{happywarp → happywarp.py} +8 -4
  139. rapidtide/scripts/{histnifti → histnifti.py} +7 -2
  140. rapidtide/scripts/{histtc → histtc.py} +7 -2
  141. rapidtide/scripts/{glmfilt → linfitfilt.py} +7 -4
  142. rapidtide/scripts/{localflow → localflow.py} +7 -2
  143. rapidtide/scripts/{mergequality → mergequality.py} +7 -2
  144. rapidtide/scripts/{pairproc → pairproc.py} +7 -2
  145. rapidtide/scripts/{pairwisemergenifti → pairwisemergenifti.py} +7 -2
  146. rapidtide/scripts/{physiofreq → physiofreq.py} +7 -2
  147. rapidtide/scripts/{pixelcomp → pixelcomp.py} +7 -2
  148. rapidtide/scripts/{plethquality → plethquality.py} +7 -2
  149. rapidtide/scripts/{polyfitim → polyfitim.py} +7 -2
  150. rapidtide/scripts/{proj2flow → proj2flow.py} +7 -2
  151. rapidtide/scripts/{rankimage → rankimage.py} +7 -2
  152. rapidtide/scripts/{rapidtide → rapidtide.py} +7 -2
  153. rapidtide/scripts/{rapidtide2std → rapidtide2std.py} +7 -2
  154. rapidtide/scripts/{resamplenifti → resamplenifti.py} +7 -2
  155. rapidtide/scripts/{resampletc → resampletc.py} +7 -2
  156. rapidtide/scripts/retrolagtcs.py +28 -0
  157. rapidtide/scripts/retroregress.py +28 -0
  158. rapidtide/scripts/{roisummarize → roisummarize.py} +7 -2
  159. rapidtide/scripts/{runqualitycheck → runqualitycheck.py} +7 -2
  160. rapidtide/scripts/{showarbcorr → showarbcorr.py} +7 -2
  161. rapidtide/scripts/{showhist → showhist.py} +7 -2
  162. rapidtide/scripts/{showstxcorr → showstxcorr.py} +7 -2
  163. rapidtide/scripts/{showtc → showtc.py} +7 -2
  164. rapidtide/scripts/{showxcorr_legacy → showxcorr_legacy.py} +8 -8
  165. rapidtide/scripts/{showxcorrx → showxcorrx.py} +7 -2
  166. rapidtide/scripts/{showxy → showxy.py} +7 -2
  167. rapidtide/scripts/{simdata → simdata.py} +7 -2
  168. rapidtide/scripts/{spatialdecomp → spatialdecomp.py} +7 -2
  169. rapidtide/scripts/{spatialfit → spatialfit.py} +7 -2
  170. rapidtide/scripts/{spatialmi → spatialmi.py} +7 -2
  171. rapidtide/scripts/{spectrogram → spectrogram.py} +7 -2
  172. rapidtide/scripts/stupidramtricks.py +238 -0
  173. rapidtide/scripts/{synthASL → synthASL.py} +7 -2
  174. rapidtide/scripts/{tcfrom2col → tcfrom2col.py} +7 -2
  175. rapidtide/scripts/{tcfrom3col → tcfrom3col.py} +7 -2
  176. rapidtide/scripts/{temporaldecomp → temporaldecomp.py} +7 -2
  177. rapidtide/scripts/{testhrv → testhrv.py} +1 -1
  178. rapidtide/scripts/{threeD → threeD.py} +7 -2
  179. rapidtide/scripts/{tidepool → tidepool.py} +7 -2
  180. rapidtide/scripts/{variabilityizer → variabilityizer.py} +7 -2
  181. rapidtide/simFuncClasses.py +2113 -0
  182. rapidtide/simfuncfit.py +312 -108
  183. rapidtide/stats.py +579 -247
  184. rapidtide/tests/.coveragerc +27 -6
  185. rapidtide-2.9.5.data/scripts/fdica → rapidtide/tests/cleanposttest +4 -6
  186. rapidtide/tests/happycomp +9 -0
  187. rapidtide/tests/resethappytargets +1 -1
  188. rapidtide/tests/resetrapidtidetargets +1 -1
  189. rapidtide/tests/resettargets +1 -1
  190. rapidtide/tests/runlocaltest +3 -3
  191. rapidtide/tests/showkernels +1 -1
  192. rapidtide/tests/test_aliasedcorrelate.py +4 -4
  193. rapidtide/tests/test_aligntcs.py +1 -1
  194. rapidtide/tests/test_calcicc.py +1 -1
  195. rapidtide/tests/test_cleanregressor.py +184 -0
  196. rapidtide/tests/test_congrid.py +70 -81
  197. rapidtide/tests/test_correlate.py +1 -1
  198. rapidtide/tests/test_corrpass.py +4 -4
  199. rapidtide/tests/test_delayestimation.py +54 -59
  200. rapidtide/tests/test_dlfiltertorch.py +437 -0
  201. rapidtide/tests/test_doresample.py +2 -2
  202. rapidtide/tests/test_externaltools.py +69 -0
  203. rapidtide/tests/test_fastresampler.py +9 -5
  204. rapidtide/tests/test_filter.py +96 -57
  205. rapidtide/tests/test_findmaxlag.py +50 -19
  206. rapidtide/tests/test_fullrunhappy_v1.py +15 -10
  207. rapidtide/tests/test_fullrunhappy_v2.py +19 -13
  208. rapidtide/tests/test_fullrunhappy_v3.py +28 -13
  209. rapidtide/tests/test_fullrunhappy_v4.py +30 -11
  210. rapidtide/tests/test_fullrunhappy_v5.py +62 -0
  211. rapidtide/tests/test_fullrunrapidtide_v1.py +61 -7
  212. rapidtide/tests/test_fullrunrapidtide_v2.py +27 -15
  213. rapidtide/tests/test_fullrunrapidtide_v3.py +28 -8
  214. rapidtide/tests/test_fullrunrapidtide_v4.py +16 -8
  215. rapidtide/tests/test_fullrunrapidtide_v5.py +15 -6
  216. rapidtide/tests/test_fullrunrapidtide_v6.py +142 -0
  217. rapidtide/tests/test_fullrunrapidtide_v7.py +114 -0
  218. rapidtide/tests/test_fullrunrapidtide_v8.py +66 -0
  219. rapidtide/tests/test_getparsers.py +158 -0
  220. rapidtide/tests/test_io.py +59 -18
  221. rapidtide/tests/{test_glmpass.py → test_linfitfiltpass.py} +10 -10
  222. rapidtide/tests/test_mi.py +1 -1
  223. rapidtide/tests/test_miscmath.py +1 -1
  224. rapidtide/tests/test_motionregress.py +5 -5
  225. rapidtide/tests/test_nullcorr.py +6 -9
  226. rapidtide/tests/test_padvec.py +216 -0
  227. rapidtide/tests/test_parserfuncs.py +101 -0
  228. rapidtide/tests/test_phaseanalysis.py +1 -1
  229. rapidtide/tests/test_rapidtideparser.py +59 -53
  230. rapidtide/tests/test_refinedelay.py +296 -0
  231. rapidtide/tests/test_runmisc.py +5 -5
  232. rapidtide/tests/test_sharedmem.py +60 -0
  233. rapidtide/tests/test_simroundtrip.py +132 -0
  234. rapidtide/tests/test_simulate.py +1 -1
  235. rapidtide/tests/test_stcorrelate.py +4 -2
  236. rapidtide/tests/test_timeshift.py +2 -2
  237. rapidtide/tests/test_valtoindex.py +1 -1
  238. rapidtide/tests/test_zRapidtideDataset.py +5 -3
  239. rapidtide/tests/utils.py +10 -9
  240. rapidtide/tidepoolTemplate.py +88 -70
  241. rapidtide/tidepoolTemplate.ui +60 -46
  242. rapidtide/tidepoolTemplate_alt.py +88 -53
  243. rapidtide/tidepoolTemplate_alt.ui +62 -52
  244. rapidtide/tidepoolTemplate_alt_qt6.py +921 -0
  245. rapidtide/tidepoolTemplate_big.py +1125 -0
  246. rapidtide/tidepoolTemplate_big.ui +2386 -0
  247. rapidtide/tidepoolTemplate_big_qt6.py +1129 -0
  248. rapidtide/tidepoolTemplate_qt6.py +793 -0
  249. rapidtide/util.py +1389 -148
  250. rapidtide/voxelData.py +1048 -0
  251. rapidtide/wiener.py +138 -25
  252. rapidtide/wiener2.py +114 -8
  253. rapidtide/workflows/adjustoffset.py +107 -5
  254. rapidtide/workflows/aligntcs.py +86 -3
  255. rapidtide/workflows/applydlfilter.py +231 -89
  256. rapidtide/workflows/applyppgproc.py +540 -0
  257. rapidtide/workflows/atlasaverage.py +309 -48
  258. rapidtide/workflows/atlastool.py +130 -9
  259. rapidtide/workflows/calcSimFuncMap.py +490 -0
  260. rapidtide/workflows/calctexticc.py +202 -10
  261. rapidtide/workflows/ccorrica.py +123 -15
  262. rapidtide/workflows/cleanregressor.py +415 -0
  263. rapidtide/workflows/delayvar.py +1268 -0
  264. rapidtide/workflows/diffrois.py +84 -6
  265. rapidtide/workflows/endtidalproc.py +149 -9
  266. rapidtide/workflows/fdica.py +197 -17
  267. rapidtide/workflows/filtnifti.py +71 -4
  268. rapidtide/workflows/filttc.py +76 -5
  269. rapidtide/workflows/fitSimFuncMap.py +578 -0
  270. rapidtide/workflows/fixtr.py +74 -4
  271. rapidtide/workflows/gmscalc.py +116 -6
  272. rapidtide/workflows/happy.py +1242 -480
  273. rapidtide/workflows/happy2std.py +145 -13
  274. rapidtide/workflows/happy_parser.py +277 -59
  275. rapidtide/workflows/histnifti.py +120 -4
  276. rapidtide/workflows/histtc.py +85 -4
  277. rapidtide/workflows/{glmfilt.py → linfitfilt.py} +128 -14
  278. rapidtide/workflows/localflow.py +329 -29
  279. rapidtide/workflows/mergequality.py +80 -4
  280. rapidtide/workflows/niftidecomp.py +323 -19
  281. rapidtide/workflows/niftistats.py +178 -8
  282. rapidtide/workflows/pairproc.py +99 -5
  283. rapidtide/workflows/pairwisemergenifti.py +86 -3
  284. rapidtide/workflows/parser_funcs.py +1488 -56
  285. rapidtide/workflows/physiofreq.py +139 -12
  286. rapidtide/workflows/pixelcomp.py +211 -9
  287. rapidtide/workflows/plethquality.py +105 -23
  288. rapidtide/workflows/polyfitim.py +159 -19
  289. rapidtide/workflows/proj2flow.py +76 -3
  290. rapidtide/workflows/rankimage.py +115 -8
  291. rapidtide/workflows/rapidtide.py +1833 -1919
  292. rapidtide/workflows/rapidtide2std.py +101 -3
  293. rapidtide/workflows/rapidtide_parser.py +607 -372
  294. rapidtide/workflows/refineDelayMap.py +249 -0
  295. rapidtide/workflows/refineRegressor.py +1215 -0
  296. rapidtide/workflows/regressfrommaps.py +308 -0
  297. rapidtide/workflows/resamplenifti.py +86 -4
  298. rapidtide/workflows/resampletc.py +92 -4
  299. rapidtide/workflows/retrolagtcs.py +442 -0
  300. rapidtide/workflows/retroregress.py +1501 -0
  301. rapidtide/workflows/roisummarize.py +176 -7
  302. rapidtide/workflows/runqualitycheck.py +72 -7
  303. rapidtide/workflows/showarbcorr.py +172 -16
  304. rapidtide/workflows/showhist.py +87 -3
  305. rapidtide/workflows/showstxcorr.py +161 -4
  306. rapidtide/workflows/showtc.py +172 -10
  307. rapidtide/workflows/showxcorrx.py +250 -62
  308. rapidtide/workflows/showxy.py +186 -16
  309. rapidtide/workflows/simdata.py +418 -112
  310. rapidtide/workflows/spatialfit.py +83 -8
  311. rapidtide/workflows/spatialmi.py +252 -29
  312. rapidtide/workflows/spectrogram.py +306 -33
  313. rapidtide/workflows/synthASL.py +157 -6
  314. rapidtide/workflows/tcfrom2col.py +77 -3
  315. rapidtide/workflows/tcfrom3col.py +75 -3
  316. rapidtide/workflows/tidepool.py +3829 -666
  317. rapidtide/workflows/utils.py +45 -19
  318. rapidtide/workflows/utils_doc.py +293 -0
  319. rapidtide/workflows/variabilityizer.py +118 -5
  320. {rapidtide-2.9.5.dist-info → rapidtide-3.1.3.dist-info}/METADATA +30 -223
  321. rapidtide-3.1.3.dist-info/RECORD +393 -0
  322. {rapidtide-2.9.5.dist-info → rapidtide-3.1.3.dist-info}/WHEEL +1 -1
  323. rapidtide-3.1.3.dist-info/entry_points.txt +65 -0
  324. rapidtide-3.1.3.dist-info/top_level.txt +2 -0
  325. rapidtide/calcandfitcorrpairs.py +0 -262
  326. rapidtide/data/examples/src/testoutputsize +0 -45
  327. rapidtide/data/models/model_revised/model.h5 +0 -0
  328. rapidtide/data/models/model_serdar/model.h5 +0 -0
  329. rapidtide/data/models/model_serdar2/model.h5 +0 -0
  330. rapidtide/data/reference/ASPECTS_nlin_asym_09c_2mm.nii.gz +0 -0
  331. rapidtide/data/reference/ASPECTS_nlin_asym_09c_2mm_mask.nii.gz +0 -0
  332. rapidtide/data/reference/ATTbasedFlowTerritories_split_nlin_asym_09c_2mm.nii.gz +0 -0
  333. rapidtide/data/reference/ATTbasedFlowTerritories_split_nlin_asym_09c_2mm_mask.nii.gz +0 -0
  334. rapidtide/data/reference/HCP1200_binmask_2mm_2009c_asym.nii.gz +0 -0
  335. rapidtide/data/reference/HCP1200_lag_2mm_2009c_asym.nii.gz +0 -0
  336. rapidtide/data/reference/HCP1200_mask_2mm_2009c_asym.nii.gz +0 -0
  337. rapidtide/data/reference/HCP1200_negmask_2mm_2009c_asym.nii.gz +0 -0
  338. rapidtide/data/reference/HCP1200_sigma_2mm_2009c_asym.nii.gz +0 -0
  339. rapidtide/data/reference/HCP1200_strength_2mm_2009c_asym.nii.gz +0 -0
  340. rapidtide/glmpass.py +0 -434
  341. rapidtide/refine_factored.py +0 -641
  342. rapidtide/scripts/retroglm +0 -23
  343. rapidtide/workflows/glmfrommaps.py +0 -202
  344. rapidtide/workflows/retroglm.py +0 -643
  345. rapidtide-2.9.5.data/scripts/adjustoffset +0 -23
  346. rapidtide-2.9.5.data/scripts/aligntcs +0 -23
  347. rapidtide-2.9.5.data/scripts/applydlfilter +0 -23
  348. rapidtide-2.9.5.data/scripts/atlasaverage +0 -23
  349. rapidtide-2.9.5.data/scripts/atlastool +0 -23
  350. rapidtide-2.9.5.data/scripts/calcicc +0 -22
  351. rapidtide-2.9.5.data/scripts/calctexticc +0 -23
  352. rapidtide-2.9.5.data/scripts/calcttest +0 -22
  353. rapidtide-2.9.5.data/scripts/ccorrica +0 -23
  354. rapidtide-2.9.5.data/scripts/diffrois +0 -23
  355. rapidtide-2.9.5.data/scripts/endtidalproc +0 -23
  356. rapidtide-2.9.5.data/scripts/filtnifti +0 -23
  357. rapidtide-2.9.5.data/scripts/filttc +0 -23
  358. rapidtide-2.9.5.data/scripts/fingerprint +0 -593
  359. rapidtide-2.9.5.data/scripts/fixtr +0 -23
  360. rapidtide-2.9.5.data/scripts/glmfilt +0 -24
  361. rapidtide-2.9.5.data/scripts/gmscalc +0 -22
  362. rapidtide-2.9.5.data/scripts/happy +0 -25
  363. rapidtide-2.9.5.data/scripts/happy2std +0 -23
  364. rapidtide-2.9.5.data/scripts/happywarp +0 -350
  365. rapidtide-2.9.5.data/scripts/histnifti +0 -23
  366. rapidtide-2.9.5.data/scripts/histtc +0 -23
  367. rapidtide-2.9.5.data/scripts/localflow +0 -23
  368. rapidtide-2.9.5.data/scripts/mergequality +0 -23
  369. rapidtide-2.9.5.data/scripts/pairproc +0 -23
  370. rapidtide-2.9.5.data/scripts/pairwisemergenifti +0 -23
  371. rapidtide-2.9.5.data/scripts/physiofreq +0 -23
  372. rapidtide-2.9.5.data/scripts/pixelcomp +0 -23
  373. rapidtide-2.9.5.data/scripts/plethquality +0 -23
  374. rapidtide-2.9.5.data/scripts/polyfitim +0 -23
  375. rapidtide-2.9.5.data/scripts/proj2flow +0 -23
  376. rapidtide-2.9.5.data/scripts/rankimage +0 -23
  377. rapidtide-2.9.5.data/scripts/rapidtide +0 -23
  378. rapidtide-2.9.5.data/scripts/rapidtide2std +0 -23
  379. rapidtide-2.9.5.data/scripts/resamplenifti +0 -23
  380. rapidtide-2.9.5.data/scripts/resampletc +0 -23
  381. rapidtide-2.9.5.data/scripts/retroglm +0 -23
  382. rapidtide-2.9.5.data/scripts/roisummarize +0 -23
  383. rapidtide-2.9.5.data/scripts/runqualitycheck +0 -23
  384. rapidtide-2.9.5.data/scripts/showarbcorr +0 -23
  385. rapidtide-2.9.5.data/scripts/showhist +0 -23
  386. rapidtide-2.9.5.data/scripts/showstxcorr +0 -23
  387. rapidtide-2.9.5.data/scripts/showtc +0 -23
  388. rapidtide-2.9.5.data/scripts/showxcorr_legacy +0 -536
  389. rapidtide-2.9.5.data/scripts/showxcorrx +0 -23
  390. rapidtide-2.9.5.data/scripts/showxy +0 -23
  391. rapidtide-2.9.5.data/scripts/simdata +0 -23
  392. rapidtide-2.9.5.data/scripts/spatialdecomp +0 -23
  393. rapidtide-2.9.5.data/scripts/spatialfit +0 -23
  394. rapidtide-2.9.5.data/scripts/spatialmi +0 -23
  395. rapidtide-2.9.5.data/scripts/spectrogram +0 -23
  396. rapidtide-2.9.5.data/scripts/synthASL +0 -23
  397. rapidtide-2.9.5.data/scripts/tcfrom2col +0 -23
  398. rapidtide-2.9.5.data/scripts/tcfrom3col +0 -23
  399. rapidtide-2.9.5.data/scripts/temporaldecomp +0 -23
  400. rapidtide-2.9.5.data/scripts/threeD +0 -236
  401. rapidtide-2.9.5.data/scripts/tidepool +0 -23
  402. rapidtide-2.9.5.data/scripts/variabilityizer +0 -23
  403. rapidtide-2.9.5.dist-info/RECORD +0 -357
  404. rapidtide-2.9.5.dist-info/top_level.txt +0 -86
  405. {rapidtide-2.9.5.dist-info → rapidtide-3.1.3.dist-info/licenses}/LICENSE +0 -0
rapidtide/stats.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
  #
4
- # Copyright 2016-2024 Blaise Frederick
4
+ # Copyright 2016-2025 Blaise Frederick
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -17,9 +17,13 @@
17
17
  #
18
18
  #
19
19
  import warnings
20
+ from typing import Any, Callable, Optional, Tuple, Union
20
21
 
21
22
  import matplotlib.pyplot as plt
22
23
  import numpy as np
24
+ from numpy.typing import ArrayLike, NDArray
25
+
26
+ from rapidtide.decorators import conditionaljit, conditionaljit2
23
27
 
24
28
  with warnings.catch_warnings():
25
29
  warnings.simplefilter("ignore")
@@ -32,6 +36,7 @@ with warnings.catch_warnings():
32
36
 
33
37
  import scipy as sp
34
38
  from scipy.stats import johnsonsb, kurtosis, kurtosistest, skew, skewtest
39
+ from statsmodels.robust import mad
35
40
 
36
41
  import rapidtide.fit as tide_fit
37
42
  import rapidtide.io as tide_io
@@ -44,80 +49,55 @@ if pyfftwpresent:
44
49
  # ---------------------------------------- Global constants -------------------------------------------
45
50
  defaultbutterorder = 6
46
51
  MAXLINES = 10000000
47
- donotbeaggressive = True
48
-
49
- # ----------------------------------------- Conditional imports ---------------------------------------
50
- try:
51
- from memory_profiler import profile
52
-
53
- memprofilerexists = True
54
- except ImportError:
55
- memprofilerexists = False
56
-
57
- try:
58
- from numba import jit
59
- except ImportError:
60
- donotusenumba = True
61
- else:
62
- donotusenumba = False
63
-
64
-
65
- def disablenumba():
66
- global donotusenumba
67
- donotusenumba = True
68
-
69
-
70
- def conditionaljit():
71
- def resdec(f):
72
- if donotusenumba:
73
- return f
74
- return jit(f, nopython=True)
75
-
76
- return resdec
77
-
78
-
79
- def conditionaljit2():
80
- def resdec(f):
81
- if donotusenumba or donotbeaggressive:
82
- return f
83
- return jit(f, nopython=True)
84
-
85
- return resdec
86
52
 
87
53
 
88
54
  # --------------------------- probability functions -------------------------------------------------
89
- def printthresholds(pcts, thepercentiles, labeltext):
90
- """
55
+ def printthresholds(pcts: ArrayLike, thepercentiles: ArrayLike, labeltext: str) -> None:
56
+ """Print significance thresholds with formatted output.
91
57
 
92
58
  Parameters
93
59
  ----------
94
- pcts
95
- thepercentiles
96
- labeltext
97
-
98
- Returns
99
- -------
100
-
60
+ pcts : array-like
61
+ Percentile threshold values
62
+ thepercentiles : array-like
63
+ Percentile levels (0-1)
64
+ labeltext : str
65
+ Label to print before thresholds
101
66
  """
102
67
  print(labeltext)
103
68
  for i in range(0, len(pcts)):
104
69
  print(f"\tp <{1.0 - thepercentiles[i]:.3f}: {pcts[i]:.3f}")
105
70
 
106
71
 
107
- def fitgausspdf(thehist, histlen, thedata, displayplots=False, nozero=False, debug=False):
108
- """
72
+ def fitgausspdf(
73
+ thehist: Tuple,
74
+ histlen: int,
75
+ thedata: NDArray,
76
+ displayplots: bool = False,
77
+ nozero: bool = False,
78
+ debug: bool = False,
79
+ ) -> NDArray:
80
+ """Fit a Gaussian probability density function to histogram data.
109
81
 
110
82
  Parameters
111
83
  ----------
112
- thehist
113
- histlen
114
- thedata
115
- displayplots
116
- nozero
84
+ thehist : tuple
85
+ Histogram tuple from np.histogram containing (counts, bin_edges)
86
+ histlen : int
87
+ Length of histogram
88
+ thedata : array-like
89
+ Original data used to create histogram
90
+ displayplots : bool, optional
91
+ If True, display fit visualization. Default: False
92
+ nozero : bool, optional
93
+ If True, ignore zero values. Default: False
94
+ debug : bool, optional
95
+ Enable debug output. Default: False
117
96
 
118
97
  Returns
119
98
  -------
120
-
99
+ array-like
100
+ Array containing (peakheight, peakloc, peakwidth, zeroterm)
121
101
  """
122
102
  thestore = np.zeros((2, histlen), dtype="float64")
123
103
  thestore[0, :] = thehist[1][:-1]
@@ -177,20 +157,35 @@ def fitgausspdf(thehist, histlen, thedata, displayplots=False, nozero=False, deb
177
157
  return np.append(params, np.array([zeroterm]))
178
158
 
179
159
 
180
- def fitjsbpdf(thehist, histlen, thedata, displayplots=False, nozero=False, debug=False):
181
- """
160
+ def fitjsbpdf(
161
+ thehist: Tuple,
162
+ histlen: int,
163
+ thedata: NDArray,
164
+ displayplots: bool = False,
165
+ nozero: bool = False,
166
+ debug: bool = False,
167
+ ) -> NDArray:
168
+ """Fit a Johnson SB probability density function to histogram data.
182
169
 
183
170
  Parameters
184
171
  ----------
185
- thehist
186
- histlen
187
- thedata
188
- displayplots
189
- nozero
172
+ thehist : tuple
173
+ Histogram tuple from np.histogram containing (counts, bin_edges)
174
+ histlen : int
175
+ Length of histogram
176
+ thedata : array-like
177
+ Original data used to create histogram
178
+ displayplots : bool, optional
179
+ If True, display fit visualization. Default: False
180
+ nozero : bool, optional
181
+ If True, ignore zero values. Default: False
182
+ debug : bool, optional
183
+ Enable debug output. Default: False
190
184
 
191
185
  Returns
192
186
  -------
193
-
187
+ array-like
188
+ Array containing (a, b, loc, scale, zeroterm) parameters of Johnson SB fit
194
189
  """
195
190
  thestore = np.zeros((2, histlen), dtype="float64")
196
191
  thestore[0, :] = thehist[1][:-1]
@@ -229,54 +224,70 @@ def fitjsbpdf(thehist, histlen, thedata, displayplots=False, nozero=False, debug
229
224
  return np.append(params, np.array([zeroterm]))
230
225
 
231
226
 
232
- def getjohnsonppf(percentile, params, zeroterm):
233
- """
227
+ def getjohnsonppf(percentile: float, params: ArrayLike, zeroterm: float) -> None:
228
+ """Get percent point function (inverse CDF) for Johnson SB distribution.
229
+
230
+ Note: This function is incomplete and only initializes variables.
234
231
 
235
232
  Parameters
236
233
  ----------
237
- percentile
238
- params
239
- zeroterm
240
-
241
- Returns
242
- -------
243
-
234
+ percentile : float
235
+ Percentile value (0-1)
236
+ params : array-like
237
+ Johnson SB distribution parameters (a, b, loc, scale)
238
+ zeroterm : float
239
+ Zero term correction factor
244
240
  """
245
241
  johnsonfunc = johnsonsb(params[0], params[1], params[2], params[3])
246
242
  corrfac = 1.0 - zeroterm
247
243
 
248
244
 
249
245
  def sigFromDistributionData(
250
- vallist,
251
- histlen,
252
- thepercentiles,
253
- similaritymetric="correlation",
254
- displayplots=False,
255
- twotail=False,
256
- nozero=False,
257
- dosighistfit=True,
258
- debug=False,
259
- ):
260
- """
246
+ vallist: NDArray,
247
+ histlen: int,
248
+ thepercentiles: ArrayLike,
249
+ similaritymetric: str = "correlation",
250
+ displayplots: bool = False,
251
+ twotail: bool = False,
252
+ nozero: bool = False,
253
+ dosighistfit: bool = True,
254
+ debug: bool = False,
255
+ ) -> Tuple[Optional[list], Optional[list], Optional[NDArray]]:
256
+ """Calculate significance thresholds from distribution data.
257
+
258
+ Fits a probability distribution to data and calculates percentile thresholds
259
+ for significance testing.
261
260
 
262
261
  Parameters
263
262
  ----------
264
- vallist
265
- histlen
266
- thepercentiles
267
- displayplots
268
- twotail
269
- nozero
270
- dosighistfit
263
+ vallist : array-like
264
+ List of similarity/correlation values
265
+ histlen : int
266
+ Length of histogram
267
+ thepercentiles : array-like
268
+ Percentile values to compute (0-1)
269
+ similaritymetric : str, optional
270
+ Type of similarity metric ("correlation" or "mutualinfo"). Default: "correlation"
271
+ displayplots : bool, optional
272
+ If True, display diagnostic plots. Default: False
273
+ twotail : bool, optional
274
+ If True, calculate two-tailed thresholds. Default: False
275
+ nozero : bool, optional
276
+ If True, exclude zero values. Default: False
277
+ dosighistfit : bool, optional
278
+ If True, fit distribution to data. Default: True
279
+ debug : bool, optional
280
+ Enable debug output. Default: False
271
281
 
272
282
  Returns
273
283
  -------
274
-
284
+ tuple
285
+ (pcts_data, pcts_fit, histfit) - percentiles from data, fitted distribution, and fit parameters
275
286
  """
276
287
  # check to make sure there are nonzero values first
277
288
  if len(np.where(vallist != 0.0)[0]) == 0:
278
289
  print("no nonzero values - skipping percentile calculation")
279
- return None, 0, 0
290
+ return None, None, None
280
291
  thehistogram, peakheight, peakloc, peakwidth, centerofmass, peakpercentile = makehistogram(
281
292
  np.abs(vallist), histlen, therange=[0.0, 1.0]
282
293
  )
@@ -307,40 +318,122 @@ def sigFromDistributionData(
307
318
  pcts_fit = getfracvalsfromfit(histfit, thepercentiles)
308
319
  return pcts_data, pcts_fit, histfit
309
320
  else:
310
- return pcts_data, 0, 0
321
+ pcts_fit = []
322
+ for i in len(pcts_data):
323
+ pcts_fit.append(None)
324
+ return pcts_data, pcts_fit, None
311
325
 
312
326
 
313
- def rfromp(fitfile, thepercentiles):
314
- """
327
+ global neglogpfromr_interpolator, minrforneglogp, maxrforneglogp
328
+ neglogpfromr_interpolator = None
329
+ minrforneglogp = None
330
+ maxrforneglogp = None
331
+
332
+
333
+ def neglog10pfromr(
334
+ rval: float,
335
+ histfit: ArrayLike,
336
+ lutlen: int = 3000,
337
+ initialize: bool = False,
338
+ neglogpmin: float = 0.0,
339
+ neglogpmax: float = 3.0,
340
+ debug: bool = False,
341
+ ) -> float:
342
+ """Convert correlation value to negative log10 p-value using histogram fit.
315
343
 
316
344
  Parameters
317
345
  ----------
318
- fitfile
319
- thepercentiles
346
+ rval : float
347
+ Correlation value to convert
348
+ histfit : array-like
349
+ Histogram fit parameters from fitjsbpdf
350
+ lutlen : int, optional
351
+ Length of lookup table. Default: 3000
352
+ initialize : bool, optional
353
+ Force reinitialization of interpolator. Default: False
354
+ neglogpmin : float, optional
355
+ Minimum negative log10 p-value. Default: 0.0
356
+ neglogpmax : float, optional
357
+ Maximum negative log10 p-value. Default: 3.0
358
+ debug : bool, optional
359
+ Enable debug output. Default: False
320
360
 
321
361
  Returns
322
362
  -------
363
+ float
364
+ Negative log10 p-value corresponding to the input correlation value
365
+ """
366
+ global neglogpfromr_interpolator, minrforneglogp, maxrforneglogp
367
+ if neglogpfromr_interpolator is None or initialize:
368
+ neglogparray = np.linspace(neglogpmin, neglogpmax, lutlen, endpoint=True)
369
+ pvals = pow(10.0, -neglogparray)
370
+ percentile_list = (1.0 - pvals).tolist()
371
+ rforneglogp = np.asarray(getfracvalsfromfit(histfit, percentile_list), dtype=float)
372
+ minrforneglogp = rforneglogp[0]
373
+ maxrforneglogp = rforneglogp[-1]
374
+ if debug:
375
+ print("START NEGLOGPFROMR DEBUG")
376
+ print("neglogp\tpval\tpct\trfornlp")
377
+ for i in range(lutlen):
378
+ print(f"{neglogparray[i]}\t{pvals[i]}\t{percentile_list[i]}\t{rforneglogp[i]}")
379
+ print("END NEGLOGPFROMR DEBUG")
380
+ neglogpfromr_interpolator = sp.interpolate.UnivariateSpline(
381
+ rforneglogp, neglogparray, k=3, s=0
382
+ )
383
+ if rval > maxrforneglogp:
384
+ return np.float64(neglogpmax)
385
+ elif rval < minrforneglogp:
386
+ return np.float64(neglogpmin)
387
+ else:
388
+ return np.float64(neglogpfromr_interpolator(np.asarray([rval], dtype=float))[0])
389
+
390
+
391
+ def rfromp(fitfile: str, thepercentiles: ArrayLike) -> NDArray:
392
+ """Get correlation values from p-values using a saved distribution fit.
323
393
 
394
+ Parameters
395
+ ----------
396
+ fitfile : str
397
+ Path to file containing distribution fit parameters
398
+ thepercentiles : array-like
399
+ Percentile values to calculate (0-1)
400
+
401
+ Returns
402
+ -------
403
+ array-like
404
+ Correlation values corresponding to the percentiles
324
405
  """
325
406
  thefit = np.array(tide_io.readvecs(fitfile)[0]).astype("float64")
326
407
  print(f"thefit = {thefit}")
327
408
  return getfracvalsfromfit(thefit, thepercentiles)
328
409
 
329
410
 
330
- def tfromr(r, nsamps, dfcorrfac=1.0, oversampfactor=1.0, returnp=False):
331
- """
411
+ def tfromr(
412
+ r: float,
413
+ nsamps: int,
414
+ dfcorrfac: float = 1.0,
415
+ oversampfactor: float = 1.0,
416
+ returnp: bool = False,
417
+ ) -> Union[float, Tuple[float, float]]:
418
+ """Convert correlation to t-statistic.
332
419
 
333
420
  Parameters
334
421
  ----------
335
- r
336
- nsamps
337
- dfcorrfac
338
- oversampfactor
339
- returnp
422
+ r : float
423
+ Correlation coefficient
424
+ nsamps : int
425
+ Number of samples
426
+ dfcorrfac : float, optional
427
+ Degrees of freedom correction factor. Default: 1.0
428
+ oversampfactor : float, optional
429
+ Oversampling factor for DOF adjustment. Default: 1.0
430
+ returnp : bool, optional
431
+ If True, also return p-value. Default: False
340
432
 
341
433
  Returns
342
434
  -------
343
-
435
+ float or tuple
436
+ T-statistic, or (t-statistic, p-value) if returnp=True
344
437
  """
345
438
  if r >= 1.0:
346
439
  tval = float("inf")
@@ -355,7 +448,21 @@ def tfromr(r, nsamps, dfcorrfac=1.0, oversampfactor=1.0, returnp=False):
355
448
  return tval
356
449
 
357
450
 
358
- def pfromz(z, twotailed=True):
451
+ def pfromz(z: float, twotailed: bool = True) -> float:
452
+ """Calculate p-value from z-score.
453
+
454
+ Parameters
455
+ ----------
456
+ z : float
457
+ Z-score value
458
+ twotailed : bool, optional
459
+ If True, calculate two-tailed p-value. Default: True
460
+
461
+ Returns
462
+ -------
463
+ float
464
+ P-value corresponding to the z-score
465
+ """
359
466
  # importing packages
360
467
  import scipy.stats
361
468
 
@@ -366,20 +473,32 @@ def pfromz(z, twotailed=True):
366
473
  return scipy.stats.norm.sf(abs(z))
367
474
 
368
475
 
369
- def zfromr(r, nsamps, dfcorrfac=1.0, oversampfactor=1.0, returnp=False):
370
- """
476
+ def zfromr(
477
+ r: float,
478
+ nsamps: int,
479
+ dfcorrfac: float = 1.0,
480
+ oversampfactor: float = 1.0,
481
+ returnp: bool = False,
482
+ ) -> Union[float, Tuple[float, float]]:
483
+ """Convert correlation to z-statistic.
371
484
 
372
485
  Parameters
373
486
  ----------
374
- r
375
- nsamps
376
- dfcorrfac
377
- oversampfactor
378
- returnp
487
+ r : float
488
+ Correlation coefficient
489
+ nsamps : int
490
+ Number of samples
491
+ dfcorrfac : float, optional
492
+ Degrees of freedom correction factor. Default: 1.0
493
+ oversampfactor : float, optional
494
+ Oversampling factor for DOF adjustment. Default: 1.0
495
+ returnp : bool, optional
496
+ If True, also return p-value. Default: False
379
497
 
380
498
  Returns
381
499
  -------
382
-
500
+ float or tuple
501
+ Z-statistic, or (z-statistic, p-value) if returnp=True
383
502
  """
384
503
  if r >= 1.0:
385
504
  zval = float("inf")
@@ -394,29 +513,79 @@ def zfromr(r, nsamps, dfcorrfac=1.0, oversampfactor=1.0, returnp=False):
394
513
  return zval
395
514
 
396
515
 
397
- def zofcorrdiff(r1, r2, n1, n2):
516
+ def zofcorrdiff(r1: float, r2: float, n1: int, n2: int) -> float:
517
+ """Calculate z-statistic for the difference between two correlations.
518
+
519
+ Parameters
520
+ ----------
521
+ r1 : float
522
+ First correlation coefficient
523
+ r2 : float
524
+ Second correlation coefficient
525
+ n1 : int
526
+ Sample size for first correlation
527
+ n2 : int
528
+ Sample size for second correlation
529
+
530
+ Returns
531
+ -------
532
+ float
533
+ Z-statistic for the difference between the two correlations
534
+ """
398
535
  return (fisher(r1) - fisher(r2)) / stderrofdiff(n1, n2)
399
536
 
400
537
 
401
- def stderrofdiff(n1, n2):
402
- return np.sqrt(1.0 / (n1 - 3) + 1.0 / (n2 - 3))
538
+ def stderrofdiff(n1: int, n2: int) -> float:
539
+ """Calculate standard error of difference between two Fisher-transformed correlations.
403
540
 
541
+ Parameters
542
+ ----------
543
+ n1 : int
544
+ Sample size for first correlation
545
+ n2 : int
546
+ Sample size for second correlation
404
547
 
405
- def fisher(r):
548
+ Returns
549
+ -------
550
+ float
551
+ Standard error of the difference
406
552
  """
553
+ return np.sqrt(1.0 / (n1 - 3) + 1.0 / (n2 - 3))
554
+
555
+
556
+ def fisher(r: float) -> float:
557
+ """Apply Fisher's r-to-z transformation to correlation coefficient.
407
558
 
408
559
  Parameters
409
560
  ----------
410
- r
561
+ r : float
562
+ Correlation coefficient
411
563
 
412
564
  Returns
413
565
  -------
414
-
566
+ float
567
+ Fisher-transformed z-value
415
568
  """
416
569
  return 0.5 * np.log((1 + r) / (1 - r))
417
570
 
418
571
 
419
- def permute_phase(time_series):
572
+ def permute_phase(time_series: NDArray) -> NDArray:
573
+ """Generate phase-randomized surrogate time series.
574
+
575
+ Creates a surrogate time series with the same power spectrum as the input
576
+ but with randomized phases. Useful for generating null distributions in
577
+ time series analysis.
578
+
579
+ Parameters
580
+ ----------
581
+ time_series : array-like
582
+ Input time series
583
+
584
+ Returns
585
+ -------
586
+ array-like
587
+ Phase-randomized surrogate time series with same length as input
588
+ """
420
589
  # Compute the Fourier transform of the time series
421
590
  freq_domain = np.fft.rfft(time_series)
422
591
 
@@ -430,37 +599,71 @@ def permute_phase(time_series):
430
599
  return permuted_time_series
431
600
 
432
601
 
433
- def skewnessstats(timecourse):
434
- """
602
+ def skewnessstats(timecourse: NDArray) -> Tuple[float, float, float]:
603
+ """Calculate skewness and statistical test for timecourse.
435
604
 
436
605
  Parameters
437
606
  ----------
438
- timecourse: array
439
- The timecourse to test
440
-
441
- :return:
607
+ timecourse : array-like
608
+ Input time series
442
609
 
610
+ Returns
611
+ -------
612
+ tuple
613
+ (skewness, z-statistic, p-value) from skewness test
443
614
  """
444
615
  testres = skewtest(timecourse)
445
616
  return skew(timecourse), testres[0], testres[1]
446
617
 
447
618
 
448
- def kurtosisstats(timecourse):
449
- """
619
+ def kurtosisstats(timecourse: NDArray) -> Tuple[float, float, float]:
620
+ """Calculate kurtosis and statistical test for timecourse.
450
621
 
451
622
  Parameters
452
623
  ----------
453
- timecourse: array
454
- The timecourse to test
455
-
456
- :return:
624
+ timecourse : array-like
625
+ Input time series
457
626
 
627
+ Returns
628
+ -------
629
+ tuple
630
+ (kurtosis, z-statistic, p-value) from kurtosis test
458
631
  """
459
632
  testres = kurtosistest(timecourse)
460
633
  return kurtosis(timecourse), testres[0], testres[1]
461
634
 
462
635
 
463
- def fast_ICC_rep_anova(Y, nocache=False, debug=False):
636
+ def fmristats(
637
+ fmridata: NDArray,
638
+ ) -> Tuple[NDArray, NDArray, NDArray, NDArray, NDArray, NDArray, NDArray, NDArray]:
639
+ """Calculate comprehensive statistics for fMRI data along time axis.
640
+
641
+ Parameters
642
+ ----------
643
+ fmridata : ndarray
644
+ 2D array where rows are voxels and columns are timepoints
645
+
646
+ Returns
647
+ -------
648
+ tuple
649
+ (min, max, mean, std, median, mad, skew, kurtosis) - each as 1D array
650
+ with length equal to number of voxels, calculated along timepoints
651
+ """
652
+ return (
653
+ np.min(fmridata, axis=1),
654
+ np.max(fmridata, axis=1),
655
+ np.mean(fmridata, axis=1),
656
+ np.std(fmridata, axis=1),
657
+ np.median(fmridata, axis=1),
658
+ mad(fmridata, axis=1),
659
+ skew(fmridata, axis=1),
660
+ kurtosis(fmridata, axis=1),
661
+ )
662
+
663
+
664
+ def fast_ICC_rep_anova(
665
+ Y: NDArray, nocache: bool = False, debug: bool = False
666
+ ) -> Tuple[float, float, float, float, int, int]:
464
667
  """
465
668
  the data Y are entered as a 'table' ie subjects are in rows and repeated
466
669
  measures in columns
@@ -547,26 +750,34 @@ def fast_ICC_rep_anova(Y, nocache=False, debug=False):
547
750
 
548
751
  # --------------------------- histogram functions -------------------------------------------------
549
752
  def gethistprops(
550
- indata,
551
- histlen,
552
- refine=False,
553
- therange=None,
554
- pickleft=False,
555
- peakthresh=0.33,
556
- ):
557
- """
753
+ indata: NDArray,
754
+ histlen: int,
755
+ refine: bool = False,
756
+ therange: Optional[Tuple[float, float]] = None,
757
+ pickleft: bool = False,
758
+ peakthresh: float = 0.33,
759
+ ) -> Tuple[float, float, float]:
760
+ """Extract histogram peak properties from data.
558
761
 
559
762
  Parameters
560
763
  ----------
561
- indata
562
- histlen
563
- refine
564
- therange
565
- pickleftpeak
764
+ indata : array-like
765
+ Input data array
766
+ histlen : int
767
+ Number of histogram bins
768
+ refine : bool, optional
769
+ If True, refine peak estimates using Gaussian fit. Default: False
770
+ therange : tuple, optional
771
+ (min, max) range for histogram. If None, use data range. Default: None
772
+ pickleft : bool, optional
773
+ If True, pick leftmost peak above threshold. Default: False
774
+ peakthresh : float, optional
775
+ Threshold for peak detection (fraction of max). Default: 0.33
566
776
 
567
777
  Returns
568
778
  -------
569
-
779
+ tuple
780
+ (peakloc, peakheight, peakwidth) - peak location, height, and width
570
781
  """
571
782
  thestore = np.zeros((2, histlen), dtype="float64")
572
783
  if therange is None:
@@ -582,7 +793,7 @@ def gethistprops(
582
793
  i = 1
583
794
  started = False
584
795
  finished = False
585
- while i < len(thestore[1, :] - 2) and not finished:
796
+ while i < len(thestore[1, :] - 3) and not finished:
586
797
  if thestore[1, i] > peakthresh * overallmax:
587
798
  started = True
588
799
  if thestore[1, i] > thestore[1, peakindex]:
@@ -608,13 +819,35 @@ def gethistprops(
608
819
 
609
820
 
610
821
  def prochistogram(
611
- thehist,
612
- refine=False,
613
- pickleft=False,
614
- peakthresh=0.33,
615
- ignorefirstpoint=False,
616
- debug=False,
617
- ):
822
+ thehist: Tuple,
823
+ refine: bool = False,
824
+ pickleft: bool = False,
825
+ peakthresh: float = 0.33,
826
+ ignorefirstpoint: bool = False,
827
+ debug: bool = False,
828
+ ) -> Tuple[float, float, float, float]:
829
+ """Process histogram data to extract peak properties.
830
+
831
+ Parameters
832
+ ----------
833
+ thehist : tuple
834
+ Histogram tuple from np.histogram containing (counts, bin_edges)
835
+ refine : bool, optional
836
+ If True, refine peak estimates using Gaussian fit. Default: False
837
+ pickleft : bool, optional
838
+ If True, pick leftmost peak above threshold. Default: False
839
+ peakthresh : float, optional
840
+ Threshold for peak detection (fraction of max). Default: 0.33
841
+ ignorefirstpoint : bool, optional
842
+ If True, ignore first histogram bin. Default: False
843
+ debug : bool, optional
844
+ Enable debug output. Default: False
845
+
846
+ Returns
847
+ -------
848
+ tuple
849
+ (peakheight, peakloc, peakwidth, centerofmass) - peak properties
850
+ """
618
851
  thestore = np.zeros((2, len(thehist[0])), dtype="float64")
619
852
  histlen = len(thehist[1])
620
853
  thestore[0, :] = (thehist[1][1:] + thehist[1][0:-1]) / 2.0
@@ -666,7 +899,23 @@ def prochistogram(
666
899
  return peakheight, peakloc, peakwidth, centerofmass
667
900
 
668
901
 
669
- def percentilefromloc(indata, peakloc, nozero=False):
902
+ def percentilefromloc(indata: NDArray, peakloc: float, nozero: bool = False) -> float:
903
+ """Calculate the percentile corresponding to a given value location.
904
+
905
+ Parameters
906
+ ----------
907
+ indata : array-like
908
+ Input data array
909
+ peakloc : float
910
+ Value location to find percentile for
911
+ nozero : bool, optional
912
+ If True, exclude zero values from calculation. Default: False
913
+
914
+ Returns
915
+ -------
916
+ float
917
+ Percentile (0-100) corresponding to the given value location
918
+ """
670
919
  order = indata.argsort()
671
920
  orderedvalues = indata[order]
672
921
  if nozero:
@@ -677,31 +926,46 @@ def percentilefromloc(indata, peakloc, nozero=False):
677
926
 
678
927
 
679
928
  def makehistogram(
680
- indata,
681
- histlen,
682
- binsize=None,
683
- therange=None,
684
- pickleft=False,
685
- peakthresh=0.33,
686
- refine=False,
687
- normalize=False,
688
- ignorefirstpoint=False,
689
- debug=False,
690
- ):
691
- """
929
+ indata: NDArray,
930
+ histlen: Optional[int],
931
+ binsize: Optional[float] = None,
932
+ therange: Optional[Tuple[float, float]] = None,
933
+ pickleft: bool = False,
934
+ peakthresh: float = 0.33,
935
+ refine: bool = False,
936
+ normalize: bool = False,
937
+ ignorefirstpoint: bool = False,
938
+ debug: bool = False,
939
+ ) -> Tuple[Tuple, float, float, float, float, float]:
940
+ """Create histogram and extract peak properties from data.
692
941
 
693
942
  Parameters
694
943
  ----------
695
- indata
696
- histlen
697
- binsize
698
- therange
699
- refine
700
- normalize
944
+ indata : array-like
945
+ Input data array
946
+ histlen : int or None
947
+ Number of histogram bins. If None, binsize must be specified
948
+ binsize : float, optional
949
+ Bin size for histogram. If specified, overrides histlen. Default: None
950
+ therange : tuple, optional
951
+ (min, max) range for histogram. If None, use data range. Default: None
952
+ pickleft : bool, optional
953
+ If True, pick leftmost peak above threshold. Default: False
954
+ peakthresh : float, optional
955
+ Threshold for peak detection (fraction of max). Default: 0.33
956
+ refine : bool, optional
957
+ If True, refine peak estimates using Gaussian fit. Default: False
958
+ normalize : bool, optional
959
+ If True, normalize histogram to unit area. Default: False
960
+ ignorefirstpoint : bool, optional
961
+ If True, ignore first histogram bin. Default: False
962
+ debug : bool, optional
963
+ Enable debug output. Default: False
701
964
 
702
965
  Returns
703
966
  -------
704
-
967
+ tuple
968
+ (histogram, peakheight, peakloc, peakwidth, centerofmass, peakpercentile)
705
969
  """
706
970
  if therange is None:
707
971
  therange = [indata.min(), indata.max()]
@@ -731,7 +995,27 @@ def makehistogram(
731
995
  return thehist, peakheight, peakloc, peakwidth, centerofmass, peakpercentile
732
996
 
733
997
 
734
- def echoloc(indata, histlen, startoffset=5.0):
998
+ def echoloc(indata: NDArray, histlen: int, startoffset: float = 5.0) -> Tuple[float, float]:
999
+ """Detect and analyze echo peak in histogram data.
1000
+
1001
+ Identifies a secondary (echo) peak in histogram data that occurs after
1002
+ the primary peak, useful for analyzing echo patterns in imaging data.
1003
+
1004
+ Parameters
1005
+ ----------
1006
+ indata : array-like
1007
+ Input data array
1008
+ histlen : int
1009
+ Number of histogram bins
1010
+ startoffset : float, optional
1011
+ Offset from primary peak to start echo search. Default: 5.0
1012
+
1013
+ Returns
1014
+ -------
1015
+ tuple
1016
+ (echo_lag, echo_ratio) where echo_lag is the distance between primary
1017
+ and echo peaks, and echo_ratio is the ratio of echo to primary peak areas
1018
+ """
735
1019
  thehist, peakheight, peakloc, peakwidth, centerofmass, peakpercentile = makehistogram(
736
1020
  indata, histlen, refine=True
737
1021
  )
@@ -760,43 +1044,56 @@ def echoloc(indata, histlen, startoffset=5.0):
760
1044
 
761
1045
 
762
1046
  def makeandsavehistogram(
763
- indata,
764
- histlen,
765
- endtrim,
766
- outname,
767
- binsize=None,
768
- saveimfile=False,
769
- displaytitle="histogram",
770
- displayplots=False,
771
- refine=False,
772
- therange=None,
773
- normalize=False,
774
- dictvarname=None,
775
- thedict=None,
776
- append=False,
777
- debug=False,
778
- ):
779
- """
1047
+ indata: NDArray,
1048
+ histlen: int,
1049
+ endtrim: int,
1050
+ outname: str,
1051
+ binsize: Optional[float] = None,
1052
+ saveimfile: bool = False,
1053
+ displaytitle: str = "histogram",
1054
+ displayplots: bool = False,
1055
+ refine: bool = False,
1056
+ therange: Optional[Tuple[float, float]] = None,
1057
+ normalize: bool = False,
1058
+ dictvarname: Optional[str] = None,
1059
+ thedict: Optional[dict] = None,
1060
+ append: bool = False,
1061
+ debug: bool = False,
1062
+ ) -> None:
1063
+ """Create histogram, extract properties, and save results to file.
780
1064
 
781
1065
  Parameters
782
1066
  ----------
783
- indata
784
- histlen
785
- endtrim
786
- outname
787
- displaytitle
788
- displayplots
789
- refine
790
- therange
791
- normalize
792
- dictvarname
793
- thedict
794
- append
795
- debug
796
-
797
- Returns
798
- -------
799
-
1067
+ indata : array-like
1068
+ Input data array
1069
+ histlen : int
1070
+ Number of histogram bins
1071
+ endtrim : int
1072
+ Number of bins to trim from end when plotting
1073
+ outname : str
1074
+ Output file path (without extension)
1075
+ binsize : float, optional
1076
+ Bin size for histogram. If specified, overrides histlen. Default: None
1077
+ saveimfile : bool, optional
1078
+ Unused parameter. Default: False
1079
+ displaytitle : str, optional
1080
+ Title for display plots. Default: "histogram"
1081
+ displayplots : bool, optional
1082
+ If True, display histogram plot. Default: False
1083
+ refine : bool, optional
1084
+ If True, refine peak estimates using Gaussian fit. Default: False
1085
+ therange : tuple, optional
1086
+ (min, max) range for histogram. If None, use data range. Default: None
1087
+ normalize : bool, optional
1088
+ If True, normalize histogram to unit area. Default: False
1089
+ dictvarname : str, optional
1090
+ Variable name for dictionary storage. If None, use outname. Default: None
1091
+ thedict : dict, optional
1092
+ Dictionary to store results in. If None, write to file. Default: None
1093
+ append : bool, optional
1094
+ If True, append to existing file. Default: False
1095
+ debug : bool, optional
1096
+ Enable debug output. Default: False
800
1097
  """
801
1098
  thehist, peakheight, peakloc, peakwidth, centerofmass, peakpercentile = makehistogram(
802
1099
  indata,
@@ -878,18 +1175,22 @@ def makeandsavehistogram(
878
1175
  plt.show()
879
1176
 
880
1177
 
881
- def symmetrize(a, antisymmetric=False, zerodiagonal=False):
882
- """
1178
+ def symmetrize(a: NDArray, antisymmetric: bool = False, zerodiagonal: bool = False) -> NDArray:
1179
+ """Symmetrize a matrix.
883
1180
 
884
1181
  Parameters
885
1182
  ----------
886
- a
887
- antisymmetric
888
- zerodiagonal
1183
+ a : ndarray
1184
+ Input matrix
1185
+ antisymmetric : bool, optional
1186
+ If True, create antisymmetric matrix (a - a.T) / 2. Default: False
1187
+ zerodiagonal : bool, optional
1188
+ If True, set diagonal elements to zero. Default: False
889
1189
 
890
1190
  Returns
891
1191
  -------
892
-
1192
+ ndarray
1193
+ Symmetrized matrix
893
1194
  """
894
1195
  if antisymmetric:
895
1196
  intermediate = (a - a.T) / 2.0
@@ -901,19 +1202,24 @@ def symmetrize(a, antisymmetric=False, zerodiagonal=False):
901
1202
  return intermediate
902
1203
 
903
1204
 
904
- def makepmask(rvals, pval, sighistfit, onesided=True):
905
- """
1205
+ def makepmask(rvals: NDArray, pval: float, sighistfit: NDArray, onesided: bool = True) -> NDArray:
1206
+ """Create significance mask from p-value threshold and distribution fit.
906
1207
 
907
1208
  Parameters
908
1209
  ----------
909
- rvals
910
- pval
911
- sighistfit
912
- onesided
1210
+ rvals : array-like
1211
+ Array of correlation or similarity values
1212
+ pval : float
1213
+ P-value threshold (0-1)
1214
+ sighistfit : array-like
1215
+ Distribution fit parameters from fitjsbpdf
1216
+ onesided : bool, optional
1217
+ If True, use one-sided test. If False, use two-sided test. Default: True
913
1218
 
914
1219
  Returns
915
1220
  -------
916
-
1221
+ ndarray
1222
+ Binary mask (int16) with 1 for significant values, 0 otherwise
917
1223
  """
918
1224
  if onesided:
919
1225
  return np.where(
@@ -928,35 +1234,49 @@ def makepmask(rvals, pval, sighistfit, onesided=True):
928
1234
 
929
1235
 
930
1236
  # Find the image intensity value which thefrac of the non-zero voxels in the image exceed
931
- def getfracval(datamat, thefrac, nozero=False):
932
- """
1237
+ def getfracval(datamat: NDArray, thefrac: float, nozero: bool = False) -> float:
1238
+ """Get data value at a specific fractional position in sorted data.
933
1239
 
934
1240
  Parameters
935
1241
  ----------
936
- datamat
937
- thefrac
1242
+ datamat : array-like
1243
+ Input data array
1244
+ thefrac : float
1245
+ Fractional position (0-1) to find value at
1246
+ nozero : bool, optional
1247
+ If True, exclude zero values. Default: False
938
1248
 
939
1249
  Returns
940
1250
  -------
941
-
1251
+ float
1252
+ Value at the specified fractional position
942
1253
  """
943
1254
  return getfracvals(datamat, [thefrac], nozero=nozero)[0]
944
1255
 
945
1256
 
946
- def getfracvals(datamat, thefracs, nozero=False, debug=False):
947
- """
1257
+ def getfracvals(
1258
+ datamat: NDArray, thefracs: ArrayLike, nozero: bool = False, debug: bool = False
1259
+ ) -> list:
1260
+ """Get data values at multiple fractional positions in sorted data.
1261
+
1262
+ Finds the intensity values that correspond to specified fractional positions
1263
+ when data is sorted in ascending order. Useful for percentile calculations.
948
1264
 
949
1265
  Parameters
950
1266
  ----------
951
- datamat
952
- thefracs
953
- displayplots
954
- nozero
955
- debug
1267
+ datamat : array-like
1268
+ Input data array
1269
+ thefracs : array-like
1270
+ List of fractional positions (0-1) to find values at
1271
+ nozero : bool, optional
1272
+ If True, exclude zero values. Default: False
1273
+ debug : bool, optional
1274
+ Enable debug output. Default: False
956
1275
 
957
1276
  Returns
958
1277
  -------
959
-
1278
+ list
1279
+ Values at the specified fractional positions
960
1280
  """
961
1281
  thevals = []
962
1282
 
@@ -984,17 +1304,23 @@ def getfracvals(datamat, thefracs, nozero=False, debug=False):
984
1304
  return thevals
985
1305
 
986
1306
 
987
- def getfracvalsfromfit(histfit, thefracs):
988
- """
1307
+ def getfracvalsfromfit(histfit: ArrayLike, thefracs: ArrayLike) -> NDArray:
1308
+ """Get data values at fractional positions from a Johnson SB distribution fit.
1309
+
1310
+ Uses the fitted Johnson SB distribution to calculate values corresponding
1311
+ to specified percentiles.
989
1312
 
990
1313
  Parameters
991
1314
  ----------
992
- histfit
993
- thefracs
1315
+ histfit : array-like
1316
+ Johnson SB distribution fit parameters (a, b, loc, scale, zeroterm) from fitjsbpdf
1317
+ thefracs : array-like
1318
+ List of fractional positions/percentiles (0-1) to calculate values for
994
1319
 
995
1320
  Returns
996
1321
  -------
997
-
1322
+ array-like
1323
+ Values corresponding to the specified percentiles from the fitted distribution
998
1324
  """
999
1325
  # print('entering getfracvalsfromfit: histfit=',histfit, ' thefracs=', thefracs)
1000
1326
  thedist = johnsonsb(histfit[0], histfit[1], histfit[2], histfit[3])
@@ -1002,7 +1328,13 @@ def getfracvalsfromfit(histfit, thefracs):
1002
1328
  return thevals
1003
1329
 
1004
1330
 
1005
- def makemask(image, threshpct=25.0, verbose=False, nozero=False, noneg=False):
1331
+ def makemask(
1332
+ image: NDArray,
1333
+ threshpct: float = 25.0,
1334
+ verbose: bool = False,
1335
+ nozero: bool = False,
1336
+ noneg: bool = False,
1337
+ ) -> NDArray:
1006
1338
  """
1007
1339
 
1008
1340
  Parameters
@@ -1036,13 +1368,13 @@ def makemask(image, threshpct=25.0, verbose=False, nozero=False, noneg=False):
1036
1368
  print(
1037
1369
  f"fracval: {pctthresh:.2f}",
1038
1370
  f"threshpct: {threshpct:.2f}",
1039
- f"mask threshhold: {threshval:.2f}",
1371
+ f"mask threshold: {threshval:.2f}",
1040
1372
  )
1041
1373
  themask = np.where(image > threshval, np.int16(1), np.int16(0))
1042
1374
  return themask
1043
1375
 
1044
1376
 
1045
- def getmasksize(themask):
1377
+ def getmasksize(themask: NDArray) -> int:
1046
1378
  """
1047
1379
 
1048
1380
  Parameters