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.
- cloud/gmscalc-HCPYA +1 -1
- cloud/mount-and-run +2 -0
- cloud/rapidtide-HCPYA +3 -3
- rapidtide/Colortables.py +538 -38
- rapidtide/OrthoImageItem.py +1094 -51
- rapidtide/RapidtideDataset.py +1709 -114
- rapidtide/__init__.py +0 -8
- rapidtide/_version.py +4 -4
- rapidtide/calccoherence.py +242 -97
- rapidtide/calcnullsimfunc.py +240 -140
- rapidtide/calcsimfunc.py +314 -129
- rapidtide/correlate.py +1211 -389
- rapidtide/data/examples/src/testLD +56 -0
- rapidtide/data/examples/src/test_findmaxlag.py +2 -2
- rapidtide/data/examples/src/test_mlregressallt.py +32 -17
- rapidtide/data/examples/src/testalign +1 -1
- rapidtide/data/examples/src/testatlasaverage +35 -7
- rapidtide/data/examples/src/testboth +21 -0
- rapidtide/data/examples/src/testcifti +11 -0
- rapidtide/data/examples/src/testdelayvar +13 -0
- rapidtide/data/examples/src/testdlfilt +25 -0
- rapidtide/data/examples/src/testfft +35 -0
- rapidtide/data/examples/src/testfileorfloat +37 -0
- rapidtide/data/examples/src/testfmri +94 -27
- rapidtide/data/examples/src/testfuncs +3 -3
- rapidtide/data/examples/src/testglmfilt +8 -6
- rapidtide/data/examples/src/testhappy +84 -51
- rapidtide/data/examples/src/testinitdelay +19 -0
- rapidtide/data/examples/src/testmodels +33 -0
- rapidtide/data/examples/src/testnewrefine +26 -0
- rapidtide/data/examples/src/testnoiseamp +21 -0
- rapidtide/data/examples/src/testppgproc +17 -0
- rapidtide/data/examples/src/testrefineonly +22 -0
- rapidtide/data/examples/src/testretro +26 -13
- rapidtide/data/examples/src/testretrolagtcs +16 -0
- rapidtide/data/examples/src/testrolloff +11 -0
- rapidtide/data/examples/src/testsimdata +45 -28
- rapidtide/data/models/model_cnn_pytorch/loss.png +0 -0
- rapidtide/data/models/model_cnn_pytorch/loss.txt +1 -0
- rapidtide/data/models/model_cnn_pytorch/model.pth +0 -0
- rapidtide/data/models/model_cnn_pytorch/model_meta.json +68 -0
- rapidtide/data/models/model_cnn_pytorch_fulldata/loss.png +0 -0
- rapidtide/data/models/model_cnn_pytorch_fulldata/loss.txt +1 -0
- rapidtide/data/models/model_cnn_pytorch_fulldata/model.pth +0 -0
- rapidtide/data/models/model_cnn_pytorch_fulldata/model_meta.json +80 -0
- rapidtide/data/models/model_cnnbp_pytorch_fullldata/loss.png +0 -0
- rapidtide/data/models/model_cnnbp_pytorch_fullldata/loss.txt +1 -0
- rapidtide/data/models/model_cnnbp_pytorch_fullldata/model.pth +0 -0
- rapidtide/data/models/model_cnnbp_pytorch_fullldata/model_meta.json +138 -0
- rapidtide/data/models/model_cnnfft_pytorch_fulldata/loss.png +0 -0
- rapidtide/data/models/model_cnnfft_pytorch_fulldata/loss.txt +1 -0
- rapidtide/data/models/model_cnnfft_pytorch_fulldata/model.pth +0 -0
- rapidtide/data/models/model_cnnfft_pytorch_fulldata/model_meta.json +128 -0
- rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/loss.png +0 -0
- rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/loss.txt +1 -0
- rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/model.pth +0 -0
- rapidtide/data/models/model_ppgattention_pytorch_w128_fulldata/model_meta.json +49 -0
- rapidtide/data/models/model_revised_tf2/model.keras +0 -0
- rapidtide/data/models/{model_serdar → model_revised_tf2}/model_meta.json +1 -1
- rapidtide/data/models/model_serdar2_tf2/model.keras +0 -0
- rapidtide/data/models/{model_serdar2 → model_serdar2_tf2}/model_meta.json +1 -1
- rapidtide/data/models/model_serdar_tf2/model.keras +0 -0
- rapidtide/data/models/{model_revised → model_serdar_tf2}/model_meta.json +1 -1
- rapidtide/data/reference/HCP1200v2_MTT_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_binmask_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_csf_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_gray_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_graylaghist.json +7 -0
- rapidtide/data/reference/HCP1200v2_graylaghist.tsv.gz +0 -0
- rapidtide/data/reference/HCP1200v2_laghist.json +7 -0
- rapidtide/data/reference/HCP1200v2_laghist.tsv.gz +0 -0
- rapidtide/data/reference/HCP1200v2_mask_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_maxcorr_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_maxtime_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_maxwidth_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_negmask_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_timepercentile_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_white_2mm.nii.gz +0 -0
- rapidtide/data/reference/HCP1200v2_whitelaghist.json +7 -0
- rapidtide/data/reference/HCP1200v2_whitelaghist.tsv.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1-seg2.xml +131 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1-seg2_regions.txt +60 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1-seg2_space-MNI152NLin6Asym_2mm.nii.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm.nii.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm_mask.nii.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin6Asym_2mm_mask.nii.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL2_space-MNI152NLin6Asym_2mm_mask.nii.gz +0 -0
- rapidtide/data/reference/MNI152_T1_1mm_Brain_FAST_seg.nii.gz +0 -0
- rapidtide/data/reference/MNI152_T1_1mm_Brain_Mask.nii.gz +0 -0
- rapidtide/data/reference/MNI152_T1_2mm_Brain_FAST_seg.nii.gz +0 -0
- rapidtide/data/reference/MNI152_T1_2mm_Brain_Mask.nii.gz +0 -0
- rapidtide/decorators.py +91 -0
- rapidtide/dlfilter.py +2553 -414
- rapidtide/dlfiltertorch.py +5201 -0
- rapidtide/externaltools.py +328 -13
- rapidtide/fMRIData_class.py +178 -0
- rapidtide/ffttools.py +168 -0
- rapidtide/filter.py +2704 -1462
- rapidtide/fit.py +2361 -579
- rapidtide/genericmultiproc.py +197 -0
- rapidtide/happy_supportfuncs.py +3255 -548
- rapidtide/helper_classes.py +590 -1181
- rapidtide/io.py +2569 -468
- rapidtide/linfitfiltpass.py +784 -0
- rapidtide/makelaggedtcs.py +267 -97
- rapidtide/maskutil.py +555 -25
- rapidtide/miscmath.py +867 -137
- rapidtide/multiproc.py +217 -44
- rapidtide/patchmatch.py +752 -0
- rapidtide/peakeval.py +32 -32
- rapidtide/ppgproc.py +2205 -0
- rapidtide/qualitycheck.py +353 -40
- rapidtide/refinedelay.py +854 -0
- rapidtide/refineregressor.py +939 -0
- rapidtide/resample.py +725 -204
- rapidtide/scripts/__init__.py +1 -0
- rapidtide/scripts/{adjustoffset → adjustoffset.py} +7 -2
- rapidtide/scripts/{aligntcs → aligntcs.py} +7 -2
- rapidtide/scripts/{applydlfilter → applydlfilter.py} +7 -2
- rapidtide/scripts/applyppgproc.py +28 -0
- rapidtide/scripts/{atlasaverage → atlasaverage.py} +7 -2
- rapidtide/scripts/{atlastool → atlastool.py} +7 -2
- rapidtide/scripts/{calcicc → calcicc.py} +7 -2
- rapidtide/scripts/{calctexticc → calctexticc.py} +7 -2
- rapidtide/scripts/{calcttest → calcttest.py} +7 -2
- rapidtide/scripts/{ccorrica → ccorrica.py} +7 -2
- rapidtide/scripts/delayvar.py +28 -0
- rapidtide/scripts/{diffrois → diffrois.py} +7 -2
- rapidtide/scripts/{endtidalproc → endtidalproc.py} +7 -2
- rapidtide/scripts/{fdica → fdica.py} +7 -2
- rapidtide/scripts/{filtnifti → filtnifti.py} +7 -2
- rapidtide/scripts/{filttc → filttc.py} +7 -2
- rapidtide/scripts/{fingerprint → fingerprint.py} +20 -16
- rapidtide/scripts/{fixtr → fixtr.py} +7 -2
- rapidtide/scripts/{gmscalc → gmscalc.py} +7 -2
- rapidtide/scripts/{happy → happy.py} +7 -2
- rapidtide/scripts/{happy2std → happy2std.py} +7 -2
- rapidtide/scripts/{happywarp → happywarp.py} +8 -4
- rapidtide/scripts/{histnifti → histnifti.py} +7 -2
- rapidtide/scripts/{histtc → histtc.py} +7 -2
- rapidtide/scripts/{glmfilt → linfitfilt.py} +7 -4
- rapidtide/scripts/{localflow → localflow.py} +7 -2
- rapidtide/scripts/{mergequality → mergequality.py} +7 -2
- rapidtide/scripts/{pairproc → pairproc.py} +7 -2
- rapidtide/scripts/{pairwisemergenifti → pairwisemergenifti.py} +7 -2
- rapidtide/scripts/{physiofreq → physiofreq.py} +7 -2
- rapidtide/scripts/{pixelcomp → pixelcomp.py} +7 -2
- rapidtide/scripts/{plethquality → plethquality.py} +7 -2
- rapidtide/scripts/{polyfitim → polyfitim.py} +7 -2
- rapidtide/scripts/{proj2flow → proj2flow.py} +7 -2
- rapidtide/scripts/{rankimage → rankimage.py} +7 -2
- rapidtide/scripts/{rapidtide → rapidtide.py} +7 -2
- rapidtide/scripts/{rapidtide2std → rapidtide2std.py} +7 -2
- rapidtide/scripts/{resamplenifti → resamplenifti.py} +7 -2
- rapidtide/scripts/{resampletc → resampletc.py} +7 -2
- rapidtide/scripts/retrolagtcs.py +28 -0
- rapidtide/scripts/retroregress.py +28 -0
- rapidtide/scripts/{roisummarize → roisummarize.py} +7 -2
- rapidtide/scripts/{runqualitycheck → runqualitycheck.py} +7 -2
- rapidtide/scripts/{showarbcorr → showarbcorr.py} +7 -2
- rapidtide/scripts/{showhist → showhist.py} +7 -2
- rapidtide/scripts/{showstxcorr → showstxcorr.py} +7 -2
- rapidtide/scripts/{showtc → showtc.py} +7 -2
- rapidtide/scripts/{showxcorr_legacy → showxcorr_legacy.py} +8 -8
- rapidtide/scripts/{showxcorrx → showxcorrx.py} +7 -2
- rapidtide/scripts/{showxy → showxy.py} +7 -2
- rapidtide/scripts/{simdata → simdata.py} +7 -2
- rapidtide/scripts/{spatialdecomp → spatialdecomp.py} +7 -2
- rapidtide/scripts/{spatialfit → spatialfit.py} +7 -2
- rapidtide/scripts/{spatialmi → spatialmi.py} +7 -2
- rapidtide/scripts/{spectrogram → spectrogram.py} +7 -2
- rapidtide/scripts/stupidramtricks.py +238 -0
- rapidtide/scripts/{synthASL → synthASL.py} +7 -2
- rapidtide/scripts/{tcfrom2col → tcfrom2col.py} +7 -2
- rapidtide/scripts/{tcfrom3col → tcfrom3col.py} +7 -2
- rapidtide/scripts/{temporaldecomp → temporaldecomp.py} +7 -2
- rapidtide/scripts/{testhrv → testhrv.py} +1 -1
- rapidtide/scripts/{threeD → threeD.py} +7 -2
- rapidtide/scripts/{tidepool → tidepool.py} +7 -2
- rapidtide/scripts/{variabilityizer → variabilityizer.py} +7 -2
- rapidtide/simFuncClasses.py +2113 -0
- rapidtide/simfuncfit.py +312 -108
- rapidtide/stats.py +579 -247
- rapidtide/tests/.coveragerc +27 -6
- rapidtide-2.9.5.data/scripts/fdica → rapidtide/tests/cleanposttest +4 -6
- rapidtide/tests/happycomp +9 -0
- rapidtide/tests/resethappytargets +1 -1
- rapidtide/tests/resetrapidtidetargets +1 -1
- rapidtide/tests/resettargets +1 -1
- rapidtide/tests/runlocaltest +3 -3
- rapidtide/tests/showkernels +1 -1
- rapidtide/tests/test_aliasedcorrelate.py +4 -4
- rapidtide/tests/test_aligntcs.py +1 -1
- rapidtide/tests/test_calcicc.py +1 -1
- rapidtide/tests/test_cleanregressor.py +184 -0
- rapidtide/tests/test_congrid.py +70 -81
- rapidtide/tests/test_correlate.py +1 -1
- rapidtide/tests/test_corrpass.py +4 -4
- rapidtide/tests/test_delayestimation.py +54 -59
- rapidtide/tests/test_dlfiltertorch.py +437 -0
- rapidtide/tests/test_doresample.py +2 -2
- rapidtide/tests/test_externaltools.py +69 -0
- rapidtide/tests/test_fastresampler.py +9 -5
- rapidtide/tests/test_filter.py +96 -57
- rapidtide/tests/test_findmaxlag.py +50 -19
- rapidtide/tests/test_fullrunhappy_v1.py +15 -10
- rapidtide/tests/test_fullrunhappy_v2.py +19 -13
- rapidtide/tests/test_fullrunhappy_v3.py +28 -13
- rapidtide/tests/test_fullrunhappy_v4.py +30 -11
- rapidtide/tests/test_fullrunhappy_v5.py +62 -0
- rapidtide/tests/test_fullrunrapidtide_v1.py +61 -7
- rapidtide/tests/test_fullrunrapidtide_v2.py +27 -15
- rapidtide/tests/test_fullrunrapidtide_v3.py +28 -8
- rapidtide/tests/test_fullrunrapidtide_v4.py +16 -8
- rapidtide/tests/test_fullrunrapidtide_v5.py +15 -6
- rapidtide/tests/test_fullrunrapidtide_v6.py +142 -0
- rapidtide/tests/test_fullrunrapidtide_v7.py +114 -0
- rapidtide/tests/test_fullrunrapidtide_v8.py +66 -0
- rapidtide/tests/test_getparsers.py +158 -0
- rapidtide/tests/test_io.py +59 -18
- rapidtide/tests/{test_glmpass.py → test_linfitfiltpass.py} +10 -10
- rapidtide/tests/test_mi.py +1 -1
- rapidtide/tests/test_miscmath.py +1 -1
- rapidtide/tests/test_motionregress.py +5 -5
- rapidtide/tests/test_nullcorr.py +6 -9
- rapidtide/tests/test_padvec.py +216 -0
- rapidtide/tests/test_parserfuncs.py +101 -0
- rapidtide/tests/test_phaseanalysis.py +1 -1
- rapidtide/tests/test_rapidtideparser.py +59 -53
- rapidtide/tests/test_refinedelay.py +296 -0
- rapidtide/tests/test_runmisc.py +5 -5
- rapidtide/tests/test_sharedmem.py +60 -0
- rapidtide/tests/test_simroundtrip.py +132 -0
- rapidtide/tests/test_simulate.py +1 -1
- rapidtide/tests/test_stcorrelate.py +4 -2
- rapidtide/tests/test_timeshift.py +2 -2
- rapidtide/tests/test_valtoindex.py +1 -1
- rapidtide/tests/test_zRapidtideDataset.py +5 -3
- rapidtide/tests/utils.py +10 -9
- rapidtide/tidepoolTemplate.py +88 -70
- rapidtide/tidepoolTemplate.ui +60 -46
- rapidtide/tidepoolTemplate_alt.py +88 -53
- rapidtide/tidepoolTemplate_alt.ui +62 -52
- rapidtide/tidepoolTemplate_alt_qt6.py +921 -0
- rapidtide/tidepoolTemplate_big.py +1125 -0
- rapidtide/tidepoolTemplate_big.ui +2386 -0
- rapidtide/tidepoolTemplate_big_qt6.py +1129 -0
- rapidtide/tidepoolTemplate_qt6.py +793 -0
- rapidtide/util.py +1389 -148
- rapidtide/voxelData.py +1048 -0
- rapidtide/wiener.py +138 -25
- rapidtide/wiener2.py +114 -8
- rapidtide/workflows/adjustoffset.py +107 -5
- rapidtide/workflows/aligntcs.py +86 -3
- rapidtide/workflows/applydlfilter.py +231 -89
- rapidtide/workflows/applyppgproc.py +540 -0
- rapidtide/workflows/atlasaverage.py +309 -48
- rapidtide/workflows/atlastool.py +130 -9
- rapidtide/workflows/calcSimFuncMap.py +490 -0
- rapidtide/workflows/calctexticc.py +202 -10
- rapidtide/workflows/ccorrica.py +123 -15
- rapidtide/workflows/cleanregressor.py +415 -0
- rapidtide/workflows/delayvar.py +1268 -0
- rapidtide/workflows/diffrois.py +84 -6
- rapidtide/workflows/endtidalproc.py +149 -9
- rapidtide/workflows/fdica.py +197 -17
- rapidtide/workflows/filtnifti.py +71 -4
- rapidtide/workflows/filttc.py +76 -5
- rapidtide/workflows/fitSimFuncMap.py +578 -0
- rapidtide/workflows/fixtr.py +74 -4
- rapidtide/workflows/gmscalc.py +116 -6
- rapidtide/workflows/happy.py +1242 -480
- rapidtide/workflows/happy2std.py +145 -13
- rapidtide/workflows/happy_parser.py +277 -59
- rapidtide/workflows/histnifti.py +120 -4
- rapidtide/workflows/histtc.py +85 -4
- rapidtide/workflows/{glmfilt.py → linfitfilt.py} +128 -14
- rapidtide/workflows/localflow.py +329 -29
- rapidtide/workflows/mergequality.py +80 -4
- rapidtide/workflows/niftidecomp.py +323 -19
- rapidtide/workflows/niftistats.py +178 -8
- rapidtide/workflows/pairproc.py +99 -5
- rapidtide/workflows/pairwisemergenifti.py +86 -3
- rapidtide/workflows/parser_funcs.py +1488 -56
- rapidtide/workflows/physiofreq.py +139 -12
- rapidtide/workflows/pixelcomp.py +211 -9
- rapidtide/workflows/plethquality.py +105 -23
- rapidtide/workflows/polyfitim.py +159 -19
- rapidtide/workflows/proj2flow.py +76 -3
- rapidtide/workflows/rankimage.py +115 -8
- rapidtide/workflows/rapidtide.py +1833 -1919
- rapidtide/workflows/rapidtide2std.py +101 -3
- rapidtide/workflows/rapidtide_parser.py +607 -372
- rapidtide/workflows/refineDelayMap.py +249 -0
- rapidtide/workflows/refineRegressor.py +1215 -0
- rapidtide/workflows/regressfrommaps.py +308 -0
- rapidtide/workflows/resamplenifti.py +86 -4
- rapidtide/workflows/resampletc.py +92 -4
- rapidtide/workflows/retrolagtcs.py +442 -0
- rapidtide/workflows/retroregress.py +1501 -0
- rapidtide/workflows/roisummarize.py +176 -7
- rapidtide/workflows/runqualitycheck.py +72 -7
- rapidtide/workflows/showarbcorr.py +172 -16
- rapidtide/workflows/showhist.py +87 -3
- rapidtide/workflows/showstxcorr.py +161 -4
- rapidtide/workflows/showtc.py +172 -10
- rapidtide/workflows/showxcorrx.py +250 -62
- rapidtide/workflows/showxy.py +186 -16
- rapidtide/workflows/simdata.py +418 -112
- rapidtide/workflows/spatialfit.py +83 -8
- rapidtide/workflows/spatialmi.py +252 -29
- rapidtide/workflows/spectrogram.py +306 -33
- rapidtide/workflows/synthASL.py +157 -6
- rapidtide/workflows/tcfrom2col.py +77 -3
- rapidtide/workflows/tcfrom3col.py +75 -3
- rapidtide/workflows/tidepool.py +3829 -666
- rapidtide/workflows/utils.py +45 -19
- rapidtide/workflows/utils_doc.py +293 -0
- rapidtide/workflows/variabilityizer.py +118 -5
- {rapidtide-2.9.5.dist-info → rapidtide-3.1.3.dist-info}/METADATA +30 -223
- rapidtide-3.1.3.dist-info/RECORD +393 -0
- {rapidtide-2.9.5.dist-info → rapidtide-3.1.3.dist-info}/WHEEL +1 -1
- rapidtide-3.1.3.dist-info/entry_points.txt +65 -0
- rapidtide-3.1.3.dist-info/top_level.txt +2 -0
- rapidtide/calcandfitcorrpairs.py +0 -262
- rapidtide/data/examples/src/testoutputsize +0 -45
- rapidtide/data/models/model_revised/model.h5 +0 -0
- rapidtide/data/models/model_serdar/model.h5 +0 -0
- rapidtide/data/models/model_serdar2/model.h5 +0 -0
- rapidtide/data/reference/ASPECTS_nlin_asym_09c_2mm.nii.gz +0 -0
- rapidtide/data/reference/ASPECTS_nlin_asym_09c_2mm_mask.nii.gz +0 -0
- rapidtide/data/reference/ATTbasedFlowTerritories_split_nlin_asym_09c_2mm.nii.gz +0 -0
- rapidtide/data/reference/ATTbasedFlowTerritories_split_nlin_asym_09c_2mm_mask.nii.gz +0 -0
- rapidtide/data/reference/HCP1200_binmask_2mm_2009c_asym.nii.gz +0 -0
- rapidtide/data/reference/HCP1200_lag_2mm_2009c_asym.nii.gz +0 -0
- rapidtide/data/reference/HCP1200_mask_2mm_2009c_asym.nii.gz +0 -0
- rapidtide/data/reference/HCP1200_negmask_2mm_2009c_asym.nii.gz +0 -0
- rapidtide/data/reference/HCP1200_sigma_2mm_2009c_asym.nii.gz +0 -0
- rapidtide/data/reference/HCP1200_strength_2mm_2009c_asym.nii.gz +0 -0
- rapidtide/glmpass.py +0 -434
- rapidtide/refine_factored.py +0 -641
- rapidtide/scripts/retroglm +0 -23
- rapidtide/workflows/glmfrommaps.py +0 -202
- rapidtide/workflows/retroglm.py +0 -643
- rapidtide-2.9.5.data/scripts/adjustoffset +0 -23
- rapidtide-2.9.5.data/scripts/aligntcs +0 -23
- rapidtide-2.9.5.data/scripts/applydlfilter +0 -23
- rapidtide-2.9.5.data/scripts/atlasaverage +0 -23
- rapidtide-2.9.5.data/scripts/atlastool +0 -23
- rapidtide-2.9.5.data/scripts/calcicc +0 -22
- rapidtide-2.9.5.data/scripts/calctexticc +0 -23
- rapidtide-2.9.5.data/scripts/calcttest +0 -22
- rapidtide-2.9.5.data/scripts/ccorrica +0 -23
- rapidtide-2.9.5.data/scripts/diffrois +0 -23
- rapidtide-2.9.5.data/scripts/endtidalproc +0 -23
- rapidtide-2.9.5.data/scripts/filtnifti +0 -23
- rapidtide-2.9.5.data/scripts/filttc +0 -23
- rapidtide-2.9.5.data/scripts/fingerprint +0 -593
- rapidtide-2.9.5.data/scripts/fixtr +0 -23
- rapidtide-2.9.5.data/scripts/glmfilt +0 -24
- rapidtide-2.9.5.data/scripts/gmscalc +0 -22
- rapidtide-2.9.5.data/scripts/happy +0 -25
- rapidtide-2.9.5.data/scripts/happy2std +0 -23
- rapidtide-2.9.5.data/scripts/happywarp +0 -350
- rapidtide-2.9.5.data/scripts/histnifti +0 -23
- rapidtide-2.9.5.data/scripts/histtc +0 -23
- rapidtide-2.9.5.data/scripts/localflow +0 -23
- rapidtide-2.9.5.data/scripts/mergequality +0 -23
- rapidtide-2.9.5.data/scripts/pairproc +0 -23
- rapidtide-2.9.5.data/scripts/pairwisemergenifti +0 -23
- rapidtide-2.9.5.data/scripts/physiofreq +0 -23
- rapidtide-2.9.5.data/scripts/pixelcomp +0 -23
- rapidtide-2.9.5.data/scripts/plethquality +0 -23
- rapidtide-2.9.5.data/scripts/polyfitim +0 -23
- rapidtide-2.9.5.data/scripts/proj2flow +0 -23
- rapidtide-2.9.5.data/scripts/rankimage +0 -23
- rapidtide-2.9.5.data/scripts/rapidtide +0 -23
- rapidtide-2.9.5.data/scripts/rapidtide2std +0 -23
- rapidtide-2.9.5.data/scripts/resamplenifti +0 -23
- rapidtide-2.9.5.data/scripts/resampletc +0 -23
- rapidtide-2.9.5.data/scripts/retroglm +0 -23
- rapidtide-2.9.5.data/scripts/roisummarize +0 -23
- rapidtide-2.9.5.data/scripts/runqualitycheck +0 -23
- rapidtide-2.9.5.data/scripts/showarbcorr +0 -23
- rapidtide-2.9.5.data/scripts/showhist +0 -23
- rapidtide-2.9.5.data/scripts/showstxcorr +0 -23
- rapidtide-2.9.5.data/scripts/showtc +0 -23
- rapidtide-2.9.5.data/scripts/showxcorr_legacy +0 -536
- rapidtide-2.9.5.data/scripts/showxcorrx +0 -23
- rapidtide-2.9.5.data/scripts/showxy +0 -23
- rapidtide-2.9.5.data/scripts/simdata +0 -23
- rapidtide-2.9.5.data/scripts/spatialdecomp +0 -23
- rapidtide-2.9.5.data/scripts/spatialfit +0 -23
- rapidtide-2.9.5.data/scripts/spatialmi +0 -23
- rapidtide-2.9.5.data/scripts/spectrogram +0 -23
- rapidtide-2.9.5.data/scripts/synthASL +0 -23
- rapidtide-2.9.5.data/scripts/tcfrom2col +0 -23
- rapidtide-2.9.5.data/scripts/tcfrom3col +0 -23
- rapidtide-2.9.5.data/scripts/temporaldecomp +0 -23
- rapidtide-2.9.5.data/scripts/threeD +0 -236
- rapidtide-2.9.5.data/scripts/tidepool +0 -23
- rapidtide-2.9.5.data/scripts/variabilityizer +0 -23
- rapidtide-2.9.5.dist-info/RECORD +0 -357
- rapidtide-2.9.5.dist-info/top_level.txt +0 -86
- {rapidtide-2.9.5.dist-info → rapidtide-3.1.3.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,1215 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2016-2025 Blaise Frederick
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
#
|
|
19
|
+
import sys
|
|
20
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
from numpy.typing import NDArray
|
|
24
|
+
|
|
25
|
+
import rapidtide.fit as tide_fit
|
|
26
|
+
import rapidtide.io as tide_io
|
|
27
|
+
import rapidtide.miscmath as tide_math
|
|
28
|
+
import rapidtide.refineregressor as tide_refineregressor
|
|
29
|
+
import rapidtide.resample as tide_resample
|
|
30
|
+
import rapidtide.stats as tide_stats
|
|
31
|
+
import rapidtide.util as tide_util
|
|
32
|
+
from rapidtide.tests.utils import mse
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
A class to implement regressor refinement
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RegressorRefiner:
|
|
40
|
+
|
|
41
|
+
refinemaskvoxels = None
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
internalvalidfmrishape: Any,
|
|
46
|
+
internalvalidpaddedfmrishape: Any,
|
|
47
|
+
pid: Any,
|
|
48
|
+
outputname: Any,
|
|
49
|
+
initial_fmri_x: Any,
|
|
50
|
+
paddedinitial_fmri_x: Any,
|
|
51
|
+
os_fmri_x: Any,
|
|
52
|
+
sharedmem: bool = False,
|
|
53
|
+
offsettime: float = 0.0,
|
|
54
|
+
ampthresh: float = 0.3,
|
|
55
|
+
lagminthresh: float = 0.25,
|
|
56
|
+
lagmaxthresh: float = 3.0,
|
|
57
|
+
sigmathresh: float = 1000.0,
|
|
58
|
+
cleanrefined: bool = False,
|
|
59
|
+
bipolar: bool = False,
|
|
60
|
+
fixdelay: bool = False,
|
|
61
|
+
includemask: Optional[Any] = None,
|
|
62
|
+
excludemask: Optional[Any] = None,
|
|
63
|
+
LGR: Optional[Any] = None,
|
|
64
|
+
nprocs: int = 1,
|
|
65
|
+
detrendorder: int = 1,
|
|
66
|
+
alwaysmultiproc: bool = False,
|
|
67
|
+
showprogressbar: bool = True,
|
|
68
|
+
chunksize: int = 50000,
|
|
69
|
+
padtrs: int = 10,
|
|
70
|
+
refineprenorm: str = "var",
|
|
71
|
+
refineweighting: Optional[Any] = None,
|
|
72
|
+
refinetype: str = "pca",
|
|
73
|
+
pcacomponents: float = 0.8,
|
|
74
|
+
dodispersioncalc: bool = False,
|
|
75
|
+
dispersioncalc_lower: float = -5.0,
|
|
76
|
+
dispersioncalc_upper: float = 5.0,
|
|
77
|
+
dispersioncalc_step: float = 0.5,
|
|
78
|
+
windowfunc: str = "hamming",
|
|
79
|
+
passes: int = 3,
|
|
80
|
+
maxpasses: int = 15,
|
|
81
|
+
convergencethresh: Optional[Any] = None,
|
|
82
|
+
interptype: str = "univariate",
|
|
83
|
+
usetmask: bool = False,
|
|
84
|
+
tmask_y: Optional[Any] = None,
|
|
85
|
+
tmaskos_y: Optional[Any] = None,
|
|
86
|
+
fastresamplerpadtime: float = 45.0,
|
|
87
|
+
prewhitenregressor: bool = False,
|
|
88
|
+
prewhitenlags: int = 10,
|
|
89
|
+
debug: bool = False,
|
|
90
|
+
rt_floattype: np.dtype = np.float64,
|
|
91
|
+
) -> None:
|
|
92
|
+
"""
|
|
93
|
+
Initialize the object with configuration parameters for fMRI data processing.
|
|
94
|
+
|
|
95
|
+
This constructor sets up internal attributes and performs initial setup tasks such as
|
|
96
|
+
allocating memory and applying masks based on provided parameters.
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
----------
|
|
100
|
+
internalvalidfmrishape : Any
|
|
101
|
+
Shape of the internal valid fMRI data.
|
|
102
|
+
internalvalidpaddedfmrishape : Any
|
|
103
|
+
Shape of the padded internal valid fMRI data.
|
|
104
|
+
pid : Any
|
|
105
|
+
Process identifier used for memory allocation.
|
|
106
|
+
outputname : Any
|
|
107
|
+
Name of the output file or dataset.
|
|
108
|
+
initial_fmri_x : Any
|
|
109
|
+
Initial fMRI data array.
|
|
110
|
+
paddedinitial_fmri_x : Any
|
|
111
|
+
Padded version of the initial fMRI data.
|
|
112
|
+
os_fmri_x : Any
|
|
113
|
+
Oversampled fMRI data array.
|
|
114
|
+
sharedmem : bool, optional
|
|
115
|
+
Whether to use shared memory for processing (default is False).
|
|
116
|
+
offsettime : float, optional
|
|
117
|
+
Time offset in seconds (default is 0.0).
|
|
118
|
+
ampthresh : float, optional
|
|
119
|
+
Amplitude threshold for filtering (default is 0.3).
|
|
120
|
+
lagminthresh : float, optional
|
|
121
|
+
Minimum lag threshold for correlation analysis (default is 0.25).
|
|
122
|
+
lagmaxthresh : float, optional
|
|
123
|
+
Maximum lag threshold for correlation analysis (default is 3.0).
|
|
124
|
+
sigmathresh : float, optional
|
|
125
|
+
Significance threshold for statistical tests (default is 1000.0).
|
|
126
|
+
cleanrefined : bool, optional
|
|
127
|
+
Whether to apply refined cleaning steps (default is False).
|
|
128
|
+
bipolar : bool, optional
|
|
129
|
+
Whether to use bipolar filtering (default is False).
|
|
130
|
+
fixdelay : bool, optional
|
|
131
|
+
Whether to fix delay in the processing pipeline (default is False).
|
|
132
|
+
includemask : Optional[Any], optional
|
|
133
|
+
Mask to include specific regions (default is None).
|
|
134
|
+
excludemask : Optional[Any], optional
|
|
135
|
+
Mask to exclude specific regions (default is None).
|
|
136
|
+
LGR : Optional[Any], optional
|
|
137
|
+
Logarithmic gradient or related parameter (default is None).
|
|
138
|
+
nprocs : int, optional
|
|
139
|
+
Number of processes to use (default is 1).
|
|
140
|
+
detrendorder : int, optional
|
|
141
|
+
Order of detrending polynomial (default is 1).
|
|
142
|
+
alwaysmultiproc : bool, optional
|
|
143
|
+
Force multiprocessing even for small tasks (default is False).
|
|
144
|
+
showprogressbar : bool, optional
|
|
145
|
+
Show progress bar during processing (default is True).
|
|
146
|
+
chunksize : int, optional
|
|
147
|
+
Size of data chunks for processing (default is 50000).
|
|
148
|
+
padtrs : int, optional
|
|
149
|
+
Number of TRs to pad (default is 10).
|
|
150
|
+
refineprenorm : str, optional
|
|
151
|
+
Pre-normalization method for refinement ("var", "mean", etc.) (default is "var").
|
|
152
|
+
refineweighting : Optional[Any], optional
|
|
153
|
+
Weighting scheme for refinement (default is None).
|
|
154
|
+
refinetype : str, optional
|
|
155
|
+
Type of refinement to perform ("pca", "ica", etc.) (default is "pca").
|
|
156
|
+
pcacomponents : float, optional
|
|
157
|
+
Fraction of PCA components to retain (default is 0.8).
|
|
158
|
+
dodispersioncalc : bool, optional
|
|
159
|
+
Whether to perform dispersion calculation (default is False).
|
|
160
|
+
dispersioncalc_lower : float, optional
|
|
161
|
+
Lower bound for dispersion calculation (default is -5.0).
|
|
162
|
+
dispersioncalc_upper : float, optional
|
|
163
|
+
Upper bound for dispersion calculation (default is 5.0).
|
|
164
|
+
dispersioncalc_step : float, optional
|
|
165
|
+
Step size for dispersion calculation (default is 0.5).
|
|
166
|
+
windowfunc : str, optional
|
|
167
|
+
Window function used in spectral analysis (default is "hamming").
|
|
168
|
+
passes : int, optional
|
|
169
|
+
Number of filter passes (default is 3).
|
|
170
|
+
maxpasses : int, optional
|
|
171
|
+
Maximum allowed number of passes (default is 15).
|
|
172
|
+
convergencethresh : Optional[Any], optional
|
|
173
|
+
Convergence threshold for iterative algorithms (default is None).
|
|
174
|
+
interptype : str, optional
|
|
175
|
+
Interpolation type for resampling ("univariate", "multivariate") (default is "univariate").
|
|
176
|
+
usetmask : bool, optional
|
|
177
|
+
Whether to use temporal mask (default is False).
|
|
178
|
+
tmask_y : Optional[Any], optional
|
|
179
|
+
Temporal mask for y-axis (default is None).
|
|
180
|
+
tmaskos_y : Optional[Any], optional
|
|
181
|
+
Oversampled temporal mask for y-axis (default is None).
|
|
182
|
+
fastresamplerpadtime : float, optional
|
|
183
|
+
Padding time for fast resampling (default is 45.0).
|
|
184
|
+
prewhitenregressor : bool, optional
|
|
185
|
+
Apply pre-whitening to regressors (default is False).
|
|
186
|
+
prewhitenlags : int, optional
|
|
187
|
+
Number of lags for pre-whitening (default is 10).
|
|
188
|
+
debug : bool, optional
|
|
189
|
+
Enable debug mode (default is False).
|
|
190
|
+
rt_floattype : np.dtype, optional
|
|
191
|
+
Rapidtide floating-point data type (default is np.float64).
|
|
192
|
+
|
|
193
|
+
Returns
|
|
194
|
+
-------
|
|
195
|
+
None
|
|
196
|
+
This method initializes the object and does not return any value.
|
|
197
|
+
|
|
198
|
+
Notes
|
|
199
|
+
-----
|
|
200
|
+
- The function internally calls `setmasks` and `_allocatemem` to initialize
|
|
201
|
+
masks and allocate memory respectively.
|
|
202
|
+
- The parameters are stored as instance attributes for use in subsequent processing steps.
|
|
203
|
+
|
|
204
|
+
Examples
|
|
205
|
+
--------
|
|
206
|
+
>>> obj = MyClass(
|
|
207
|
+
... internalvalidfmrishape=(64, 64, 30),
|
|
208
|
+
... internalvalidpaddedfmrishape=(64, 64, 35),
|
|
209
|
+
... pid=12345,
|
|
210
|
+
... outputname="output.nii",
|
|
211
|
+
... initial_fmri_x=np.random.rand(64, 64, 30),
|
|
212
|
+
... paddedinitial_fmri_x=np.random.rand(64, 64, 35),
|
|
213
|
+
... os_fmri_x=np.random.rand(64, 64, 60),
|
|
214
|
+
... sharedmem=True,
|
|
215
|
+
... offsettime=0.5,
|
|
216
|
+
... ampthresh=0.5,
|
|
217
|
+
... lagminthresh=0.3,
|
|
218
|
+
... lagmaxthresh=2.0,
|
|
219
|
+
... sigmathresh=500.0,
|
|
220
|
+
... cleanrefined=True,
|
|
221
|
+
... bipolar=False,
|
|
222
|
+
... fixdelay=False,
|
|
223
|
+
... includemask=None,
|
|
224
|
+
... excludemask=None,
|
|
225
|
+
... LGR=None,
|
|
226
|
+
... nprocs=4,
|
|
227
|
+
... detrendorder=2,
|
|
228
|
+
... alwaysmultiproc=False,
|
|
229
|
+
... showprogressbar=True,
|
|
230
|
+
... chunksize=10000,
|
|
231
|
+
... padtrs=5,
|
|
232
|
+
... refineprenorm="mean",
|
|
233
|
+
... refineweighting=None,
|
|
234
|
+
... refinetype="pca",
|
|
235
|
+
... pcacomponents=0.9,
|
|
236
|
+
... dodispersioncalc=True,
|
|
237
|
+
... dispersioncalc_lower=-4.0,
|
|
238
|
+
... dispersioncalc_upper=4.0,
|
|
239
|
+
... dispersioncalc_step=0.25,
|
|
240
|
+
... windowfunc="hann",
|
|
241
|
+
... passes=2,
|
|
242
|
+
... maxpasses=10,
|
|
243
|
+
... convergencethresh=None,
|
|
244
|
+
... interptype="multivariate",
|
|
245
|
+
... usetmask=True,
|
|
246
|
+
... tmask_y=np.ones((64, 64)),
|
|
247
|
+
... tmaskos_y=np.ones((64, 64)),
|
|
248
|
+
... fastresamplerpadtime=30.0,
|
|
249
|
+
... prewhitenregressor=True,
|
|
250
|
+
... prewhitenlags=5,
|
|
251
|
+
... debug=False,
|
|
252
|
+
... rt_floattype=np.float32,
|
|
253
|
+
... )
|
|
254
|
+
"""
|
|
255
|
+
self.internalvalidfmrishape = internalvalidfmrishape
|
|
256
|
+
self.internalvalidpaddedfmrishape = internalvalidpaddedfmrishape
|
|
257
|
+
self.sharedmem = sharedmem
|
|
258
|
+
self.outputname = outputname
|
|
259
|
+
self.initial_fmri_x = initial_fmri_x
|
|
260
|
+
self.paddedinitial_fmri_x = paddedinitial_fmri_x
|
|
261
|
+
self.os_fmri_x = os_fmri_x
|
|
262
|
+
|
|
263
|
+
self.offsettime = offsettime
|
|
264
|
+
self.ampthresh = ampthresh
|
|
265
|
+
self.lagminthresh = lagminthresh
|
|
266
|
+
self.lagmaxthresh = lagmaxthresh
|
|
267
|
+
self.sigmathresh = sigmathresh
|
|
268
|
+
self.cleanrefined = cleanrefined
|
|
269
|
+
self.bipolar = bipolar
|
|
270
|
+
self.fixdelay = fixdelay
|
|
271
|
+
self.LGR = LGR
|
|
272
|
+
self.nprocs = nprocs
|
|
273
|
+
self.detrendorder = detrendorder
|
|
274
|
+
self.alwaysmultiproc = alwaysmultiproc
|
|
275
|
+
self.showprogressbar = showprogressbar
|
|
276
|
+
self.chunksize = chunksize
|
|
277
|
+
self.padtrs = padtrs
|
|
278
|
+
self.refineprenorm = refineprenorm
|
|
279
|
+
self.refineweighting = refineweighting
|
|
280
|
+
self.refinetype = refinetype
|
|
281
|
+
self.pcacomponents = pcacomponents
|
|
282
|
+
self.dodispersioncalc = dodispersioncalc
|
|
283
|
+
self.dispersioncalc_lower = dispersioncalc_lower
|
|
284
|
+
self.dispersioncalc_upper = dispersioncalc_upper
|
|
285
|
+
self.dispersioncalc_step = dispersioncalc_step
|
|
286
|
+
self.windowfunc = windowfunc
|
|
287
|
+
self.passes = passes
|
|
288
|
+
self.maxpasses = maxpasses
|
|
289
|
+
self.convergencethresh = convergencethresh
|
|
290
|
+
self.interptype = interptype
|
|
291
|
+
self.usetmask = usetmask
|
|
292
|
+
self.tmask_y = tmask_y
|
|
293
|
+
self.tmaskos_y = tmaskos_y
|
|
294
|
+
self.fastresamplerpadtime = fastresamplerpadtime
|
|
295
|
+
self.prewhitenregressor = prewhitenregressor
|
|
296
|
+
self.prewhitenlags = prewhitenlags
|
|
297
|
+
self.debug = debug
|
|
298
|
+
self.rt_floattype = rt_floattype
|
|
299
|
+
|
|
300
|
+
self.setmasks(includemask, excludemask)
|
|
301
|
+
self.totalrefinementbytes = self._allocatemem(pid)
|
|
302
|
+
|
|
303
|
+
def setmasks(self, includemask: Any, excludemask: Any) -> None:
|
|
304
|
+
"""
|
|
305
|
+
Set the include and exclude masks for the object.
|
|
306
|
+
|
|
307
|
+
Parameters
|
|
308
|
+
----------
|
|
309
|
+
includemask : Any
|
|
310
|
+
The mask to be used for including elements. Type and structure depends
|
|
311
|
+
on the specific implementation and usage context.
|
|
312
|
+
excludemask : Any
|
|
313
|
+
The mask to be used for excluding elements. Type and structure depends
|
|
314
|
+
on the specific implementation and usage context.
|
|
315
|
+
|
|
316
|
+
Returns
|
|
317
|
+
-------
|
|
318
|
+
None
|
|
319
|
+
This method does not return any value.
|
|
320
|
+
|
|
321
|
+
Notes
|
|
322
|
+
-----
|
|
323
|
+
This method assigns the provided masks to instance attributes `includemask`
|
|
324
|
+
and `excludemask`. The masks are typically used for filtering or selection
|
|
325
|
+
operations in data processing workflows.
|
|
326
|
+
|
|
327
|
+
Examples
|
|
328
|
+
--------
|
|
329
|
+
>>> obj = MyClass()
|
|
330
|
+
>>> obj.setmasks([1, 0, 1], [0, 1, 0])
|
|
331
|
+
>>> print(obj.includemask)
|
|
332
|
+
[1, 0, 1]
|
|
333
|
+
>>> print(obj.excludemask)
|
|
334
|
+
[0, 1, 0]
|
|
335
|
+
"""
|
|
336
|
+
self.includemask = includemask
|
|
337
|
+
self.excludemask = excludemask
|
|
338
|
+
|
|
339
|
+
def _allocatemem(self, pid: Any) -> int:
|
|
340
|
+
"""
|
|
341
|
+
Allocate memory for refinement arrays using shared memory if specified.
|
|
342
|
+
|
|
343
|
+
This function allocates four arrays used in the refinement process:
|
|
344
|
+
`shiftedtcs`, `weights`, `paddedshiftedtcs`, and `paddedweights`. These
|
|
345
|
+
arrays are allocated with shapes determined by `internalvalidfmrishape` and
|
|
346
|
+
`internalvalidpaddedfmrishape`, using the specified data type and memory
|
|
347
|
+
sharing settings.
|
|
348
|
+
|
|
349
|
+
Parameters
|
|
350
|
+
----------
|
|
351
|
+
pid : Any
|
|
352
|
+
Process identifier used to name shared memory segments.
|
|
353
|
+
|
|
354
|
+
Returns
|
|
355
|
+
-------
|
|
356
|
+
int
|
|
357
|
+
Total number of bytes allocated for the refinement arrays.
|
|
358
|
+
|
|
359
|
+
Notes
|
|
360
|
+
-----
|
|
361
|
+
If `sharedmem` is True, the arrays are allocated in shared memory; otherwise,
|
|
362
|
+
they are allocated locally. The function prints information about the
|
|
363
|
+
allocation size and location, and logs memory usage after allocation.
|
|
364
|
+
|
|
365
|
+
Examples
|
|
366
|
+
--------
|
|
367
|
+
>>> self._allocatemem(pid=1234)
|
|
368
|
+
allocated 10.500 MB in shared memory for refinement
|
|
369
|
+
11010048
|
|
370
|
+
"""
|
|
371
|
+
self.shiftedtcs, self.shiftedtcs_shm = tide_util.allocarray(
|
|
372
|
+
self.internalvalidfmrishape,
|
|
373
|
+
self.rt_floattype,
|
|
374
|
+
shared=self.sharedmem,
|
|
375
|
+
name=f"shiftedtcs_{pid}",
|
|
376
|
+
)
|
|
377
|
+
self.weights, self.weights_shm = tide_util.allocarray(
|
|
378
|
+
self.internalvalidfmrishape,
|
|
379
|
+
self.rt_floattype,
|
|
380
|
+
shared=self.sharedmem,
|
|
381
|
+
name=f"weights_{pid}",
|
|
382
|
+
)
|
|
383
|
+
self.paddedshiftedtcs, self.paddedshiftedtcs_shm = tide_util.allocarray(
|
|
384
|
+
self.internalvalidpaddedfmrishape,
|
|
385
|
+
self.rt_floattype,
|
|
386
|
+
shared=self.sharedmem,
|
|
387
|
+
name=f"paddedshiftedtcs_{pid}",
|
|
388
|
+
)
|
|
389
|
+
self.paddedweights, self.paddedweights_shm = tide_util.allocarray(
|
|
390
|
+
self.internalvalidpaddedfmrishape,
|
|
391
|
+
self.rt_floattype,
|
|
392
|
+
shared=self.sharedmem,
|
|
393
|
+
name=f"paddedweights_{pid}",
|
|
394
|
+
)
|
|
395
|
+
if self.sharedmem:
|
|
396
|
+
ramlocation = "in shared memory"
|
|
397
|
+
else:
|
|
398
|
+
ramlocation = "locally"
|
|
399
|
+
totalrefinementbytes = (
|
|
400
|
+
self.shiftedtcs.nbytes
|
|
401
|
+
+ self.weights.nbytes
|
|
402
|
+
+ self.paddedshiftedtcs.nbytes
|
|
403
|
+
+ self.paddedweights.nbytes
|
|
404
|
+
)
|
|
405
|
+
thesize, theunit = tide_util.format_bytes(totalrefinementbytes)
|
|
406
|
+
print(f"allocated {thesize:.3f} {theunit} {ramlocation} for refinement")
|
|
407
|
+
tide_util.logmem("after refinement array allocation")
|
|
408
|
+
return totalrefinementbytes
|
|
409
|
+
|
|
410
|
+
def cleanup(self) -> None:
|
|
411
|
+
"""
|
|
412
|
+
Clean up memory resources by deleting internal attributes and shared memory segments.
|
|
413
|
+
|
|
414
|
+
This method removes all internal arrays and their corresponding shared memory segments
|
|
415
|
+
when shared memory is being used. It's designed to free up memory resources that were
|
|
416
|
+
allocated during processing.
|
|
417
|
+
|
|
418
|
+
Returns
|
|
419
|
+
-------
|
|
420
|
+
None
|
|
421
|
+
This method does not return any value.
|
|
422
|
+
|
|
423
|
+
Notes
|
|
424
|
+
-----
|
|
425
|
+
- Deletes the following internal attributes: paddedshiftedtcs, paddedweights,
|
|
426
|
+
shiftedtcs, weights
|
|
427
|
+
- If shared memory is enabled (sharedmem=True), also cleans up the corresponding
|
|
428
|
+
shared memory segments using tide_util.cleanup_shm()
|
|
429
|
+
- This method should be called when the object is no longer needed to prevent
|
|
430
|
+
memory leaks
|
|
431
|
+
|
|
432
|
+
Examples
|
|
433
|
+
--------
|
|
434
|
+
>>> obj = MyClass()
|
|
435
|
+
>>> obj.cleanup()
|
|
436
|
+
>>> # All internal memory resources are now freed
|
|
437
|
+
"""
|
|
438
|
+
del self.paddedshiftedtcs
|
|
439
|
+
del self.paddedweights
|
|
440
|
+
del self.shiftedtcs
|
|
441
|
+
del self.weights
|
|
442
|
+
if self.sharedmem:
|
|
443
|
+
tide_util.cleanup_shm(self.paddedshiftedtcs_shm)
|
|
444
|
+
tide_util.cleanup_shm(self.paddedweights_shm)
|
|
445
|
+
tide_util.cleanup_shm(self.shiftedtcs_shm)
|
|
446
|
+
tide_util.cleanup_shm(self.weights_shm)
|
|
447
|
+
|
|
448
|
+
def makemask(self, lagstrengths: Any, lagtimes: Any, lagsigma: Any, fitmask: Any) -> bool:
|
|
449
|
+
"""
|
|
450
|
+
Create a refinement mask based on lag strength, lag time, and sigma thresholds.
|
|
451
|
+
|
|
452
|
+
This function generates a mask for refining regressor parameters by evaluating
|
|
453
|
+
the quality of lag estimates against specified thresholds. The mask determines
|
|
454
|
+
which voxels should be included in the refinement process based on their
|
|
455
|
+
lag strength, lag time, and sigma values.
|
|
456
|
+
|
|
457
|
+
Parameters
|
|
458
|
+
----------
|
|
459
|
+
lagstrengths : array-like
|
|
460
|
+
Array containing lag strength values for each voxel
|
|
461
|
+
lagtimes : array-like
|
|
462
|
+
Array containing lag time values for each voxel
|
|
463
|
+
lagsigma : array-like
|
|
464
|
+
Array containing sigma values for each voxel
|
|
465
|
+
fitmask : array-like
|
|
466
|
+
Boolean mask indicating which voxels to consider for fitting
|
|
467
|
+
|
|
468
|
+
Returns
|
|
469
|
+
-------
|
|
470
|
+
bool
|
|
471
|
+
True if voxels are included in the refine mask, False if no voxels
|
|
472
|
+
meet the refinement criteria
|
|
473
|
+
|
|
474
|
+
Notes
|
|
475
|
+
-----
|
|
476
|
+
The function uses internal threshold parameters to determine which voxels
|
|
477
|
+
should be included in the refinement process. These include:
|
|
478
|
+
|
|
479
|
+
- ampthresh: amplitude threshold
|
|
480
|
+
- lagminthresh: minimum lag threshold
|
|
481
|
+
- lagmaxthresh: maximum lag threshold
|
|
482
|
+
- sigmathresh: sigma threshold
|
|
483
|
+
|
|
484
|
+
If no voxels meet the criteria, a critical log message is generated and
|
|
485
|
+
the function returns False.
|
|
486
|
+
|
|
487
|
+
Examples
|
|
488
|
+
--------
|
|
489
|
+
>>> # Assuming self is an instance of a class with the required attributes
|
|
490
|
+
>>> result = self.makemask(lagstrengths, lagtimes, lagsigma, fitmask)
|
|
491
|
+
>>> if result:
|
|
492
|
+
... print("Refinement mask created successfully")
|
|
493
|
+
... else:
|
|
494
|
+
... print("No voxels in refine mask")
|
|
495
|
+
"""
|
|
496
|
+
# create the refinement mask
|
|
497
|
+
(
|
|
498
|
+
self.refinemaskvoxels,
|
|
499
|
+
self.refinemask,
|
|
500
|
+
self.locationfails,
|
|
501
|
+
self.ampfails,
|
|
502
|
+
self.lagfails,
|
|
503
|
+
self.sigmafails,
|
|
504
|
+
self.numinmask,
|
|
505
|
+
) = tide_refineregressor.makerefinemask(
|
|
506
|
+
lagstrengths,
|
|
507
|
+
lagtimes,
|
|
508
|
+
lagsigma,
|
|
509
|
+
fitmask,
|
|
510
|
+
offsettime=self.offsettime,
|
|
511
|
+
ampthresh=self.ampthresh,
|
|
512
|
+
lagminthresh=self.lagminthresh,
|
|
513
|
+
lagmaxthresh=self.lagmaxthresh,
|
|
514
|
+
sigmathresh=self.sigmathresh,
|
|
515
|
+
cleanrefined=self.cleanrefined,
|
|
516
|
+
bipolar=self.bipolar,
|
|
517
|
+
includemask=self.includemask,
|
|
518
|
+
excludemask=self.excludemask,
|
|
519
|
+
fixdelay=self.fixdelay,
|
|
520
|
+
debug=self.debug,
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
if self.numinmask == 0:
|
|
524
|
+
self.LGR.critical("No voxels in refine mask - adjust thresholds or external masks")
|
|
525
|
+
return False
|
|
526
|
+
else:
|
|
527
|
+
return True
|
|
528
|
+
|
|
529
|
+
def getrefinemask(self) -> NDArray:
|
|
530
|
+
"""
|
|
531
|
+
Return the refinement mask.
|
|
532
|
+
|
|
533
|
+
Returns
|
|
534
|
+
-------
|
|
535
|
+
NDArray
|
|
536
|
+
The refinement mask stored in the instance.
|
|
537
|
+
|
|
538
|
+
Notes
|
|
539
|
+
-----
|
|
540
|
+
This method provides access to the refinement mask attribute. The refinement
|
|
541
|
+
mask is typically used in computational physics or data analysis workflows
|
|
542
|
+
to identify regions of interest or apply specific processing to certain data
|
|
543
|
+
points.
|
|
544
|
+
|
|
545
|
+
Examples
|
|
546
|
+
--------
|
|
547
|
+
>>> mask = obj.getrefinemask()
|
|
548
|
+
>>> print(mask)
|
|
549
|
+
[True, False, True, False]
|
|
550
|
+
"""
|
|
551
|
+
return self.refinemask
|
|
552
|
+
|
|
553
|
+
def getpaddedshiftedtcs(self) -> NDArray:
|
|
554
|
+
"""
|
|
555
|
+
Return the padded and shifted time-course data.
|
|
556
|
+
|
|
557
|
+
This method retrieves the pre-computed padded and shifted time-course data
|
|
558
|
+
that has been processed for analysis. The data is typically used in
|
|
559
|
+
time-series analysis or signal processing applications where temporal
|
|
560
|
+
alignment and padding are required.
|
|
561
|
+
|
|
562
|
+
Returns
|
|
563
|
+
-------
|
|
564
|
+
NDArray
|
|
565
|
+
The padded and shifted time-course data stored in the instance variable
|
|
566
|
+
`paddedshiftedtcs`. The exact format depends on the data processing
|
|
567
|
+
pipeline that generated this data.
|
|
568
|
+
|
|
569
|
+
Notes
|
|
570
|
+
-----
|
|
571
|
+
This method serves as a simple getter function for the `paddedshiftedtcs`
|
|
572
|
+
attribute. The actual computation of padded and shifted time-course data
|
|
573
|
+
should be performed prior to calling this method.
|
|
574
|
+
|
|
575
|
+
Examples
|
|
576
|
+
--------
|
|
577
|
+
>>> processor = TimeCourseProcessor()
|
|
578
|
+
>>> processor.compute_padded_shifted_tcs()
|
|
579
|
+
>>> result = processor.getpaddedshiftedtcs()
|
|
580
|
+
>>> print(result.shape)
|
|
581
|
+
(1000, 50)
|
|
582
|
+
"""
|
|
583
|
+
return self.paddedshiftedtcs
|
|
584
|
+
|
|
585
|
+
def alignvoxels(self, fmri_data_valid: Any, fmritr: Any, lagtimes: Any) -> int:
|
|
586
|
+
"""
|
|
587
|
+
Align timecourses to prepare for refinement.
|
|
588
|
+
|
|
589
|
+
This function aligns voxel timecourses for further refinement processing by
|
|
590
|
+
coordinating the alignment of fMRI data with specified lag times and processing
|
|
591
|
+
parameters.
|
|
592
|
+
|
|
593
|
+
Parameters
|
|
594
|
+
----------
|
|
595
|
+
fmri_data_valid : Any
|
|
596
|
+
Valid fMRI data to be aligned
|
|
597
|
+
fmritr : Any
|
|
598
|
+
fMRI temporal resolution information
|
|
599
|
+
lagtimes : Any
|
|
600
|
+
Lag times to be used for alignment
|
|
601
|
+
|
|
602
|
+
Returns
|
|
603
|
+
-------
|
|
604
|
+
int
|
|
605
|
+
Returns the number of voxels processed
|
|
606
|
+
|
|
607
|
+
Notes
|
|
608
|
+
-----
|
|
609
|
+
The function utilizes the `tide_refineregressor.alignvoxels` function internally
|
|
610
|
+
and passes all relevant processing parameters including multiprocessing settings,
|
|
611
|
+
detrending options, and padding parameters.
|
|
612
|
+
|
|
613
|
+
Examples
|
|
614
|
+
--------
|
|
615
|
+
>>> alignvoxels(fmri_data_valid, fmritr, lagtimes)
|
|
616
|
+
>>> # Function processes data and updates internal state
|
|
617
|
+
"""
|
|
618
|
+
# align timecourses to prepare for refinement
|
|
619
|
+
self.LGR.info("aligning timecourses")
|
|
620
|
+
voxelsprocessed_rra = tide_refineregressor.alignvoxels(
|
|
621
|
+
fmri_data_valid,
|
|
622
|
+
fmritr,
|
|
623
|
+
self.shiftedtcs,
|
|
624
|
+
self.weights,
|
|
625
|
+
self.paddedshiftedtcs,
|
|
626
|
+
self.paddedweights,
|
|
627
|
+
lagtimes,
|
|
628
|
+
self.refinemask,
|
|
629
|
+
nprocs=self.nprocs,
|
|
630
|
+
detrendorder=self.detrendorder,
|
|
631
|
+
offsettime=self.offsettime,
|
|
632
|
+
alwaysmultiproc=self.alwaysmultiproc,
|
|
633
|
+
showprogressbar=self.showprogressbar,
|
|
634
|
+
chunksize=self.chunksize,
|
|
635
|
+
padtrs=self.padtrs,
|
|
636
|
+
rt_floattype=self.rt_floattype,
|
|
637
|
+
)
|
|
638
|
+
return voxelsprocessed_rra
|
|
639
|
+
# self.LGR.info(f"align complete: {voxelsprocessed_rra=}")
|
|
640
|
+
|
|
641
|
+
def prenormalize(self, lagtimes: Any, lagstrengths: Any, R2: Any) -> None:
|
|
642
|
+
"""
|
|
643
|
+
Pre-normalize time series data for refinement regression.
|
|
644
|
+
|
|
645
|
+
This function applies pre-normalization to the padded and shifted time series
|
|
646
|
+
data using the specified lag times, lag strengths, and R2 values. The
|
|
647
|
+
normalization is performed through the underlying tide_refineregressor.prenorm
|
|
648
|
+
function with the appropriate internal parameters.
|
|
649
|
+
|
|
650
|
+
Parameters
|
|
651
|
+
----------
|
|
652
|
+
lagtimes : Any
|
|
653
|
+
Array or list of lag times to be used in the pre-normalization process.
|
|
654
|
+
lagstrengths : Any
|
|
655
|
+
Array or list of lag strengths corresponding to the lag times.
|
|
656
|
+
R2 : Any
|
|
657
|
+
Array or list of R2 values used for the pre-normalization calculation.
|
|
658
|
+
|
|
659
|
+
Returns
|
|
660
|
+
-------
|
|
661
|
+
None
|
|
662
|
+
This function does not return any value. It modifies internal attributes
|
|
663
|
+
in-place.
|
|
664
|
+
|
|
665
|
+
Notes
|
|
666
|
+
-----
|
|
667
|
+
The function internally uses:
|
|
668
|
+
- self.paddedshiftedtcs: padded and shifted time series data
|
|
669
|
+
- self.refinemask: refinement mask for the normalization process
|
|
670
|
+
- self.lagmaxthresh: maximum lag threshold
|
|
671
|
+
- self.refineprenorm: refinement pre-normalization parameters
|
|
672
|
+
- self.refineweighting: refinement weighting parameters
|
|
673
|
+
|
|
674
|
+
Examples
|
|
675
|
+
--------
|
|
676
|
+
>>> prenormalize(lagtimes=[1, 2, 3], lagstrengths=[0.5, 0.3, 0.8], R2=[0.9, 0.85, 0.92])
|
|
677
|
+
"""
|
|
678
|
+
tide_refineregressor.prenorm(
|
|
679
|
+
self.paddedshiftedtcs,
|
|
680
|
+
self.refinemask,
|
|
681
|
+
lagtimes,
|
|
682
|
+
self.lagmaxthresh,
|
|
683
|
+
lagstrengths,
|
|
684
|
+
R2,
|
|
685
|
+
self.refineprenorm,
|
|
686
|
+
self.refineweighting,
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
def refine(
|
|
690
|
+
self,
|
|
691
|
+
theprefilter: Any,
|
|
692
|
+
fmritr: Any,
|
|
693
|
+
thepass: Any,
|
|
694
|
+
lagstrengths: Any,
|
|
695
|
+
lagtimes: Any,
|
|
696
|
+
previousnormoutputdata: Any,
|
|
697
|
+
corrmasksize: Any,
|
|
698
|
+
) -> Tuple[int, dict, NDArray, NDArray, NDArray, bool, Optional[str], Any]:
|
|
699
|
+
"""
|
|
700
|
+
Refine the regressor by iteratively applying filtering and resampling operations.
|
|
701
|
+
|
|
702
|
+
This method performs iterative refinement of a regressor using a series of
|
|
703
|
+
filtering, resampling, and normalization steps. It tracks convergence and
|
|
704
|
+
updates internal state variables accordingly.
|
|
705
|
+
|
|
706
|
+
Parameters
|
|
707
|
+
----------
|
|
708
|
+
theprefilter : Any
|
|
709
|
+
The prefilter to be applied to the data.
|
|
710
|
+
fmritr : Any
|
|
711
|
+
The fMRI temporal resolution (TR).
|
|
712
|
+
thepass : Any
|
|
713
|
+
The current pass number in the refinement process.
|
|
714
|
+
lagstrengths : Any
|
|
715
|
+
The lag strengths used in the refinement.
|
|
716
|
+
lagtimes : Any
|
|
717
|
+
The lag times used in the refinement.
|
|
718
|
+
previousnormoutputdata : Any
|
|
719
|
+
The normalized output data from the previous pass.
|
|
720
|
+
corrmasksize : Any
|
|
721
|
+
The size of the correlation mask.
|
|
722
|
+
|
|
723
|
+
Returns
|
|
724
|
+
-------
|
|
725
|
+
tuple
|
|
726
|
+
A tuple containing:
|
|
727
|
+
- voxelsprocessed_rr : int
|
|
728
|
+
Number of voxels processed in this pass.
|
|
729
|
+
- outputdict : dict
|
|
730
|
+
Dictionary of output statistics for this pass.
|
|
731
|
+
- previousnormoutputdata : NDArray
|
|
732
|
+
Updated normalized output data for the next pass.
|
|
733
|
+
- resampref_y : NDArray
|
|
734
|
+
Resampled refined regressor at oversampled frequency.
|
|
735
|
+
- resampnonosref_y : NDArray
|
|
736
|
+
Resampled refined regressor at original frequency.
|
|
737
|
+
- stoprefining : bool
|
|
738
|
+
Flag indicating whether refinement should stop.
|
|
739
|
+
- refinestopreason : str or None
|
|
740
|
+
Reason for stopping refinement.
|
|
741
|
+
- genlagtc : FastResampler
|
|
742
|
+
Generator for lag time courses.
|
|
743
|
+
|
|
744
|
+
Notes
|
|
745
|
+
-----
|
|
746
|
+
This function modifies internal attributes of the class, such as `paddedoutputdata`,
|
|
747
|
+
`locationfails`, `ampfails`, `lagfails`, and `sigmafails`. It also writes output
|
|
748
|
+
files using `tide_io.writebidstsv`.
|
|
749
|
+
|
|
750
|
+
Examples
|
|
751
|
+
--------
|
|
752
|
+
>>> refine(prefilter, fmritr, 1, lagstrengths, lagtimes, prev_data, mask_size)
|
|
753
|
+
"""
|
|
754
|
+
(
|
|
755
|
+
voxelsprocessed_rr,
|
|
756
|
+
self.paddedoutputdata,
|
|
757
|
+
) = tide_refineregressor.dorefine(
|
|
758
|
+
self.paddedshiftedtcs,
|
|
759
|
+
self.refinemask,
|
|
760
|
+
self.weights,
|
|
761
|
+
theprefilter,
|
|
762
|
+
fmritr,
|
|
763
|
+
thepass,
|
|
764
|
+
lagstrengths,
|
|
765
|
+
lagtimes,
|
|
766
|
+
self.refinetype,
|
|
767
|
+
1.0 / fmritr,
|
|
768
|
+
self.outputname,
|
|
769
|
+
detrendorder=self.detrendorder,
|
|
770
|
+
pcacomponents=self.pcacomponents,
|
|
771
|
+
dodispersioncalc=self.dodispersioncalc,
|
|
772
|
+
dispersioncalc_lower=self.dispersioncalc_lower,
|
|
773
|
+
dispersioncalc_upper=self.dispersioncalc_upper,
|
|
774
|
+
dispersioncalc_step=self.dispersioncalc_step,
|
|
775
|
+
windowfunc=self.windowfunc,
|
|
776
|
+
cleanrefined=self.cleanrefined,
|
|
777
|
+
bipolar=self.bipolar,
|
|
778
|
+
rt_floattype=self.rt_floattype,
|
|
779
|
+
)
|
|
780
|
+
outputdict = {}
|
|
781
|
+
outputdict["refinemasksize_pass" + str(thepass)] = voxelsprocessed_rr
|
|
782
|
+
outputdict["refinemaskpct_pass" + str(thepass)] = 100.0 * voxelsprocessed_rr / corrmasksize
|
|
783
|
+
outputdict["refinelocationfails_pass" + str(thepass)] = self.locationfails
|
|
784
|
+
outputdict["refineampfails_pass" + str(thepass)] = self.ampfails
|
|
785
|
+
outputdict["refinelagfails_pass" + str(thepass)] = self.lagfails
|
|
786
|
+
outputdict["refinesigmafails_pass" + str(thepass)] = self.sigmafails
|
|
787
|
+
|
|
788
|
+
if self.prewhitenregressor:
|
|
789
|
+
self.paddedoutputdata = tide_fit.prewhiten(
|
|
790
|
+
self.paddedoutputdata, self.prewhitenlags, debug=self.debug
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
fmrifreq = 1.0 / fmritr
|
|
794
|
+
if voxelsprocessed_rr > 0:
|
|
795
|
+
paddednormoutputdata = tide_math.stdnormalize(
|
|
796
|
+
theprefilter.apply(fmrifreq, self.paddedoutputdata)
|
|
797
|
+
)
|
|
798
|
+
outputdata = self.paddedoutputdata[self.padtrs : -self.padtrs]
|
|
799
|
+
normoutputdata = tide_math.stdnormalize(theprefilter.apply(fmrifreq, outputdata))
|
|
800
|
+
normunfilteredoutputdata = tide_math.stdnormalize(outputdata)
|
|
801
|
+
tide_io.writebidstsv(
|
|
802
|
+
f"{self.outputname}_desc-refinedmovingregressor_timeseries",
|
|
803
|
+
normunfilteredoutputdata,
|
|
804
|
+
fmrifreq,
|
|
805
|
+
columns=["unfiltered_pass" + str(thepass)],
|
|
806
|
+
extraheaderinfo={
|
|
807
|
+
"Description": "The raw and filtered probe regressor produced by the refinement procedure, at the time resolution of the data"
|
|
808
|
+
},
|
|
809
|
+
append=(thepass > 1),
|
|
810
|
+
)
|
|
811
|
+
tide_io.writebidstsv(
|
|
812
|
+
f"{self.outputname}_desc-refinedmovingregressor_timeseries",
|
|
813
|
+
normoutputdata,
|
|
814
|
+
fmrifreq,
|
|
815
|
+
columns=["filtered_pass" + str(thepass)],
|
|
816
|
+
extraheaderinfo={
|
|
817
|
+
"Description": "The raw and filtered probe regressor produced by the refinement procedure, at the time resolution of the data"
|
|
818
|
+
},
|
|
819
|
+
append=True,
|
|
820
|
+
)
|
|
821
|
+
|
|
822
|
+
# check for convergence
|
|
823
|
+
regressormse = mse(normoutputdata, previousnormoutputdata)
|
|
824
|
+
outputdict["regressormse_pass" + str(thepass).zfill(2)] = regressormse
|
|
825
|
+
self.LGR.info(f"regressor difference at end of pass {thepass:d} is {regressormse:.6f}")
|
|
826
|
+
if self.convergencethresh is not None:
|
|
827
|
+
if thepass >= self.maxpasses:
|
|
828
|
+
self.LGR.info("refinement ended (maxpasses reached)")
|
|
829
|
+
stoprefining = True
|
|
830
|
+
refinestopreason = "maxpassesreached"
|
|
831
|
+
elif regressormse < self.convergencethresh:
|
|
832
|
+
self.LGR.info("refinement ended (refinement has converged")
|
|
833
|
+
stoprefining = True
|
|
834
|
+
refinestopreason = "convergence"
|
|
835
|
+
else:
|
|
836
|
+
stoprefining = False
|
|
837
|
+
elif thepass >= self.passes:
|
|
838
|
+
stoprefining = True
|
|
839
|
+
refinestopreason = "passesreached"
|
|
840
|
+
else:
|
|
841
|
+
stoprefining = False
|
|
842
|
+
refinestopreason = None
|
|
843
|
+
outputdict["refinestopreason"] = refinestopreason
|
|
844
|
+
|
|
845
|
+
if self.detrendorder > 0:
|
|
846
|
+
resampnonosref_y = tide_fit.detrend(
|
|
847
|
+
tide_resample.doresample(
|
|
848
|
+
self.paddedinitial_fmri_x,
|
|
849
|
+
paddednormoutputdata,
|
|
850
|
+
self.initial_fmri_x,
|
|
851
|
+
method=self.interptype,
|
|
852
|
+
),
|
|
853
|
+
order=self.detrendorder,
|
|
854
|
+
demean=True,
|
|
855
|
+
)
|
|
856
|
+
resampref_y = tide_fit.detrend(
|
|
857
|
+
tide_resample.doresample(
|
|
858
|
+
self.paddedinitial_fmri_x,
|
|
859
|
+
paddednormoutputdata,
|
|
860
|
+
self.os_fmri_x,
|
|
861
|
+
method=self.interptype,
|
|
862
|
+
),
|
|
863
|
+
order=self.detrendorder,
|
|
864
|
+
demean=True,
|
|
865
|
+
)
|
|
866
|
+
else:
|
|
867
|
+
resampnonosref_y = tide_resample.doresample(
|
|
868
|
+
self.paddedinitial_fmri_x,
|
|
869
|
+
paddednormoutputdata,
|
|
870
|
+
self.initial_fmri_x,
|
|
871
|
+
method=self.interptype,
|
|
872
|
+
)
|
|
873
|
+
resampref_y = tide_resample.doresample(
|
|
874
|
+
self.paddedinitial_fmri_x,
|
|
875
|
+
paddednormoutputdata,
|
|
876
|
+
self.os_fmri_x,
|
|
877
|
+
method=self.interptype,
|
|
878
|
+
)
|
|
879
|
+
if self.usetmask:
|
|
880
|
+
resampnonosref_y *= self.tmask_y
|
|
881
|
+
thefit, R2val = tide_fit.mlregress(self.tmask_y, resampnonosref_y)
|
|
882
|
+
resampnonosref_y -= thefit[0, 1] * self.tmask_y
|
|
883
|
+
resampref_y *= self.tmaskos_y
|
|
884
|
+
thefit, R2val = tide_fit.mlregress(self.tmaskos_y, resampref_y)
|
|
885
|
+
resampref_y -= thefit[0, 1] * self.tmaskos_y
|
|
886
|
+
|
|
887
|
+
# reinitialize genlagtc for resampling
|
|
888
|
+
previousnormoutputdata = np.zeros_like(normoutputdata)
|
|
889
|
+
genlagtc = tide_resample.FastResampler(
|
|
890
|
+
self.paddedinitial_fmri_x,
|
|
891
|
+
paddednormoutputdata,
|
|
892
|
+
padtime=self.fastresamplerpadtime,
|
|
893
|
+
)
|
|
894
|
+
genlagtc.save(f"{self.outputname}_desc-lagtcgenerator_timeseries")
|
|
895
|
+
if self.debug:
|
|
896
|
+
genlagtc.info()
|
|
897
|
+
(
|
|
898
|
+
outputdict[f"kurtosis_reference_pass{thepass + 1}"],
|
|
899
|
+
outputdict[f"kurtosisz_reference_pass{thepass + 1}"],
|
|
900
|
+
outputdict[f"kurtosisp_reference_pass{thepass + 1}"],
|
|
901
|
+
) = tide_stats.kurtosisstats(resampref_y)
|
|
902
|
+
(
|
|
903
|
+
outputdict[f"skewness_reference_pass{thepass + 1}"],
|
|
904
|
+
outputdict[f"skewnessz_reference_pass{thepass + 1}"],
|
|
905
|
+
outputdict[f"skewnessp_reference_pass{thepass + 1}"],
|
|
906
|
+
) = tide_stats.skewnessstats(resampref_y)
|
|
907
|
+
if not stoprefining:
|
|
908
|
+
tide_io.writebidstsv(
|
|
909
|
+
f"{self.outputname}_desc-movingregressor_timeseries",
|
|
910
|
+
tide_math.stdnormalize(resampnonosref_y),
|
|
911
|
+
1.0 / fmritr,
|
|
912
|
+
columns=["pass" + str(thepass + 1)],
|
|
913
|
+
extraheaderinfo={
|
|
914
|
+
"Description": "The probe regressor used in each pass, at the time resolution of the data"
|
|
915
|
+
},
|
|
916
|
+
append=True,
|
|
917
|
+
)
|
|
918
|
+
oversampfreq = 1.0 / (self.os_fmri_x[1] - self.os_fmri_x[0])
|
|
919
|
+
tide_io.writebidstsv(
|
|
920
|
+
f"{self.outputname}_desc-oversampledmovingregressor_timeseries",
|
|
921
|
+
tide_math.stdnormalize(resampref_y),
|
|
922
|
+
oversampfreq,
|
|
923
|
+
columns=["pass" + str(thepass + 1)],
|
|
924
|
+
extraheaderinfo={
|
|
925
|
+
"Description": "The probe regressor used in each pass, at the time resolution used for calculating the similarity function"
|
|
926
|
+
},
|
|
927
|
+
append=True,
|
|
928
|
+
)
|
|
929
|
+
else:
|
|
930
|
+
self.LGR.warning(f"refinement failed - terminating at end of pass {thepass}")
|
|
931
|
+
stoprefining = True
|
|
932
|
+
refinestopreason = "emptymask"
|
|
933
|
+
|
|
934
|
+
return (
|
|
935
|
+
voxelsprocessed_rr,
|
|
936
|
+
outputdict,
|
|
937
|
+
previousnormoutputdata,
|
|
938
|
+
resampref_y,
|
|
939
|
+
resampnonosref_y,
|
|
940
|
+
stoprefining,
|
|
941
|
+
refinestopreason,
|
|
942
|
+
genlagtc,
|
|
943
|
+
)
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
def refineRegressor(
|
|
947
|
+
LGR: Any,
|
|
948
|
+
TimingLGR: Any,
|
|
949
|
+
thepass: Any,
|
|
950
|
+
optiondict: Any,
|
|
951
|
+
fitmask: NDArray,
|
|
952
|
+
internaloffsetincludemask_valid: NDArray,
|
|
953
|
+
internaloffsetexcludemask_valid: NDArray,
|
|
954
|
+
internalrefineincludemask_valid: NDArray,
|
|
955
|
+
internalrefineexcludemask_valid: NDArray,
|
|
956
|
+
internaldespeckleincludemask: NDArray,
|
|
957
|
+
validvoxels: NDArray,
|
|
958
|
+
theRegressorRefiner: Any,
|
|
959
|
+
lagtimes: NDArray,
|
|
960
|
+
lagstrengths: NDArray,
|
|
961
|
+
lagsigma: NDArray,
|
|
962
|
+
fmri_data_valid: NDArray,
|
|
963
|
+
fmritr: float,
|
|
964
|
+
R2: Any,
|
|
965
|
+
theprefilter: Any,
|
|
966
|
+
previousnormoutputdata: Any,
|
|
967
|
+
theinputdata: Any,
|
|
968
|
+
numpadtrs: Any,
|
|
969
|
+
outputname: Any,
|
|
970
|
+
nativefmrishape: Any,
|
|
971
|
+
bidsbasedict: Any,
|
|
972
|
+
rt_floattype: np.dtype = np.dtype(np.float64),
|
|
973
|
+
debug: bool = False,
|
|
974
|
+
) -> Tuple[NDArray, NDArray, bool, str, Any]:
|
|
975
|
+
"""
|
|
976
|
+
Refine the regressor by adjusting masks, aligning timecourses, and performing refinement steps.
|
|
977
|
+
|
|
978
|
+
This function performs regressor refinement during a specified pass, including:
|
|
979
|
+
- Updating offset time based on lag properties
|
|
980
|
+
- Managing masks for refinement and despeckling
|
|
981
|
+
- Aligning timecourses
|
|
982
|
+
- Pre-normalizing data
|
|
983
|
+
- Executing the refinement step using a regressor refiner object
|
|
984
|
+
|
|
985
|
+
Parameters
|
|
986
|
+
----------
|
|
987
|
+
LGR : logging.Logger
|
|
988
|
+
Logger instance for general logging.
|
|
989
|
+
TimingLGR : logging.Logger
|
|
990
|
+
Logger instance for timing-related messages.
|
|
991
|
+
thepass : int
|
|
992
|
+
Current pass number in the refinement process.
|
|
993
|
+
optiondict : dict
|
|
994
|
+
Dictionary containing various options and settings for the refinement process.
|
|
995
|
+
fitmask : array_like
|
|
996
|
+
Boolean mask indicating voxels to be considered in fitting.
|
|
997
|
+
internaloffsetincludemask_valid : array_like or None
|
|
998
|
+
Mask for including voxels in offset calculation.
|
|
999
|
+
internaloffsetexcludemask_valid : array_like or None
|
|
1000
|
+
Mask for excluding voxels from offset calculation.
|
|
1001
|
+
internalrefineincludemask_valid : array_like or None
|
|
1002
|
+
Mask for including voxels in refinement.
|
|
1003
|
+
internalrefineexcludemask_valid : array_like or None
|
|
1004
|
+
Mask for excluding voxels from refinement.
|
|
1005
|
+
internaldespeckleincludemask : array_like
|
|
1006
|
+
Mask for including voxels in despeckling.
|
|
1007
|
+
validvoxels : array_like
|
|
1008
|
+
Indices of valid voxels.
|
|
1009
|
+
theRegressorRefiner : object
|
|
1010
|
+
Regressor refiner object with methods for mask setting, masking, alignment, etc.
|
|
1011
|
+
lagtimes : array_like
|
|
1012
|
+
Array of lag times.
|
|
1013
|
+
lagstrengths : array_like
|
|
1014
|
+
Array of lag strengths.
|
|
1015
|
+
lagsigma : array_like
|
|
1016
|
+
Array of lag sigma values.
|
|
1017
|
+
fmri_data_valid : array_like
|
|
1018
|
+
Valid fMRI data.
|
|
1019
|
+
fmritr : float
|
|
1020
|
+
fMRI repetition time.
|
|
1021
|
+
R2 : array_like
|
|
1022
|
+
R2 values.
|
|
1023
|
+
theprefilter : object
|
|
1024
|
+
Filter object used for preprocessing.
|
|
1025
|
+
previousnormoutputdata : array_like
|
|
1026
|
+
Previously normalized output data.
|
|
1027
|
+
theinputdata : object
|
|
1028
|
+
Input data object (e.g., Nifti1Image).
|
|
1029
|
+
numpadtrs : int
|
|
1030
|
+
Number of padded timepoints.
|
|
1031
|
+
outputname : str
|
|
1032
|
+
Base name for output files.
|
|
1033
|
+
nativefmrishape : tuple
|
|
1034
|
+
Shape of the native fMRI data.
|
|
1035
|
+
bidsbasedict : dict
|
|
1036
|
+
Dictionary for BIDS metadata.
|
|
1037
|
+
rt_floattype : numpy.dtype, optional
|
|
1038
|
+
Data type for floating-point operations, default is np.float64.
|
|
1039
|
+
debug : bool, optional
|
|
1040
|
+
Enable debug mode, default is False.
|
|
1041
|
+
|
|
1042
|
+
Returns
|
|
1043
|
+
-------
|
|
1044
|
+
tuple
|
|
1045
|
+
A tuple containing:
|
|
1046
|
+
- resampref_y : NDArray
|
|
1047
|
+
Resampled refined y values.
|
|
1048
|
+
- resampnonosref_y : NDArray
|
|
1049
|
+
Resampled non-oscillatory refined y values.
|
|
1050
|
+
- stoprefining : bool
|
|
1051
|
+
Flag indicating whether refinement should stop.
|
|
1052
|
+
- refinestopreason : str
|
|
1053
|
+
Reason for stopping refinement.
|
|
1054
|
+
- genlagtc : array_like
|
|
1055
|
+
Generated lag timecourses.
|
|
1056
|
+
|
|
1057
|
+
Notes
|
|
1058
|
+
-----
|
|
1059
|
+
- This function modifies `optiondict` in-place, updating offset times and other parameters.
|
|
1060
|
+
- The function uses `theRegressorRefiner` to perform various refinement steps including:
|
|
1061
|
+
`setmasks`, `makemask`, `alignvoxels`, `prenormalize`, and `refine`.
|
|
1062
|
+
- If `refinedespeckled` is False and `despeckle_passes` > 0, the exclude mask for refinement
|
|
1063
|
+
is adjusted to include voxels being despeckled.
|
|
1064
|
+
- The function may exit early if no voxels qualify for refinement.
|
|
1065
|
+
|
|
1066
|
+
Examples
|
|
1067
|
+
--------
|
|
1068
|
+
>>> refineRegressor(
|
|
1069
|
+
... LGR, TimingLGR, 1, optiondict, fitmask, offset_incl, offset_excl,
|
|
1070
|
+
... refine_incl, refine_excl, despeckle_incl, valid_voxels, refiner,
|
|
1071
|
+
... lagtimes, lagstrengths, lagsigma, fmri_data, fmritr, R2, prefilter,
|
|
1072
|
+
... prev_norm_data, input_data, numpadtrs, output_name, native_shape,
|
|
1073
|
+
... bids_dict, debug=True
|
|
1074
|
+
... )
|
|
1075
|
+
"""
|
|
1076
|
+
LGR.info(f"\n\nRegressor refinement, pass {thepass}")
|
|
1077
|
+
TimingLGR.info(f"Regressor refinement start, pass {thepass}")
|
|
1078
|
+
if optiondict["refineoffset"]:
|
|
1079
|
+
# check that we won't end up excluding all voxels from offset calculation before accepting mask
|
|
1080
|
+
offsetmask = np.uint16(fitmask)
|
|
1081
|
+
if internaloffsetincludemask_valid is not None:
|
|
1082
|
+
offsetmask[np.where(internaloffsetincludemask_valid == 0)] = np.uint16(0)
|
|
1083
|
+
if internaloffsetexcludemask_valid is not None:
|
|
1084
|
+
offsetmask[np.where(internaloffsetexcludemask_valid != 0.0)] = np.uint16(0)
|
|
1085
|
+
if tide_stats.getmasksize(offsetmask) == 0:
|
|
1086
|
+
LGR.warning(
|
|
1087
|
+
"NB: cannot exclude voxels from offset calculation mask - including for this pass"
|
|
1088
|
+
)
|
|
1089
|
+
offsetmask = fitmask + 0
|
|
1090
|
+
|
|
1091
|
+
peaklag, dummy, dummy = tide_stats.gethistprops(
|
|
1092
|
+
lagtimes[np.where(offsetmask > 0)],
|
|
1093
|
+
optiondict["histlen"],
|
|
1094
|
+
pickleft=optiondict["pickleft"],
|
|
1095
|
+
peakthresh=optiondict["pickleftthresh"],
|
|
1096
|
+
)
|
|
1097
|
+
optiondict["offsettime"] = peaklag
|
|
1098
|
+
optiondict["offsettime_total"] += peaklag
|
|
1099
|
+
optiondict[f"offsettime_pass{thepass}"] = optiondict["offsettime"]
|
|
1100
|
+
optiondict[f"offsettime_total_pass{thepass}"] = optiondict["offsettime_total"]
|
|
1101
|
+
LGR.info(
|
|
1102
|
+
f"offset time set to {optiondict['offsettime']:.3f}, "
|
|
1103
|
+
f"total is {optiondict['offsettime_total']:.3f}"
|
|
1104
|
+
)
|
|
1105
|
+
|
|
1106
|
+
if optiondict["refinedespeckled"] or (optiondict["despeckle_passes"] == 0):
|
|
1107
|
+
# if refinedespeckled is true, or there is no despeckling, masks are unaffected
|
|
1108
|
+
thisinternalrefineexcludemask_valid = internalrefineexcludemask_valid
|
|
1109
|
+
else:
|
|
1110
|
+
# if refinedespeckled is false and there is despeckling, need to make a proper mask
|
|
1111
|
+
if internalrefineexcludemask_valid is None:
|
|
1112
|
+
# if there is currently no exclude mask, set exclude mask = despeckle mask
|
|
1113
|
+
thisinternalrefineexcludemask_valid = np.where(
|
|
1114
|
+
internaldespeckleincludemask[validvoxels] == 0.0, 0, 1
|
|
1115
|
+
)
|
|
1116
|
+
else:
|
|
1117
|
+
# if there is a current exclude mask, add any voxels that are being despeckled
|
|
1118
|
+
thisinternalrefineexcludemask_valid = np.where(
|
|
1119
|
+
internalrefineexcludemask_valid > 0, 1, 0
|
|
1120
|
+
)
|
|
1121
|
+
thisinternalrefineexcludemask_valid[
|
|
1122
|
+
np.where(internaldespeckleincludemask[validvoxels] != 0.0)
|
|
1123
|
+
] = 1
|
|
1124
|
+
|
|
1125
|
+
# now check that we won't end up excluding all voxels from refinement before accepting mask
|
|
1126
|
+
overallmask = np.uint16(fitmask)
|
|
1127
|
+
if internalrefineincludemask_valid is not None:
|
|
1128
|
+
overallmask[np.where(internalrefineincludemask_valid == 0)] = np.uint16(0)
|
|
1129
|
+
if thisinternalrefineexcludemask_valid is not None:
|
|
1130
|
+
overallmask[np.where(thisinternalrefineexcludemask_valid != 0.0)] = np.uint16(0)
|
|
1131
|
+
if tide_stats.getmasksize(overallmask) == 0:
|
|
1132
|
+
LGR.warning(
|
|
1133
|
+
"NB: cannot exclude despeckled voxels from refinement - including for this pass"
|
|
1134
|
+
)
|
|
1135
|
+
thisinternalrefineexcludemask_valid = internalrefineexcludemask_valid
|
|
1136
|
+
theRegressorRefiner.setmasks(
|
|
1137
|
+
internalrefineincludemask_valid, thisinternalrefineexcludemask_valid
|
|
1138
|
+
)
|
|
1139
|
+
|
|
1140
|
+
# regenerate regressor for next pass
|
|
1141
|
+
# create the refinement mask
|
|
1142
|
+
LGR.info("making refine mask")
|
|
1143
|
+
createdmask = theRegressorRefiner.makemask(lagstrengths, lagtimes, lagsigma, fitmask)
|
|
1144
|
+
print(f"Refine mask has {theRegressorRefiner.refinemaskvoxels} voxels")
|
|
1145
|
+
if not createdmask:
|
|
1146
|
+
print("no voxels qualify for refinement - exiting")
|
|
1147
|
+
sys.exit()
|
|
1148
|
+
|
|
1149
|
+
# align timecourses to prepare for refinement
|
|
1150
|
+
LGR.info("aligning timecourses")
|
|
1151
|
+
tide_util.disablemkl(optiondict["nprocs_refine"], debug=optiondict["threaddebug"])
|
|
1152
|
+
voxelsprocessed_rra = theRegressorRefiner.alignvoxels(fmri_data_valid, fmritr, lagtimes)
|
|
1153
|
+
tide_util.enablemkl(optiondict["mklthreads"], debug=optiondict["threaddebug"])
|
|
1154
|
+
LGR.info(f"align complete: {voxelsprocessed_rra=}")
|
|
1155
|
+
|
|
1156
|
+
# prenormalize
|
|
1157
|
+
LGR.info("prenormalizing timecourses")
|
|
1158
|
+
theRegressorRefiner.prenormalize(lagtimes, lagstrengths, R2)
|
|
1159
|
+
|
|
1160
|
+
# now doing the refinement
|
|
1161
|
+
(
|
|
1162
|
+
voxelsprocessed_rr,
|
|
1163
|
+
outputdict,
|
|
1164
|
+
previousnormoutputdata,
|
|
1165
|
+
resampref_y,
|
|
1166
|
+
resampnonosref_y,
|
|
1167
|
+
stoprefining,
|
|
1168
|
+
refinestopreason,
|
|
1169
|
+
genlagtc,
|
|
1170
|
+
) = theRegressorRefiner.refine(
|
|
1171
|
+
theprefilter,
|
|
1172
|
+
fmritr,
|
|
1173
|
+
thepass,
|
|
1174
|
+
lagstrengths,
|
|
1175
|
+
lagtimes,
|
|
1176
|
+
previousnormoutputdata,
|
|
1177
|
+
optiondict["corrmasksize"],
|
|
1178
|
+
)
|
|
1179
|
+
TimingLGR.info(
|
|
1180
|
+
f"Regressor refinement end, pass {thepass}",
|
|
1181
|
+
{
|
|
1182
|
+
"message2": voxelsprocessed_rr,
|
|
1183
|
+
"message3": "voxels",
|
|
1184
|
+
},
|
|
1185
|
+
)
|
|
1186
|
+
for key, value in outputdict.items():
|
|
1187
|
+
optiondict[key] = value
|
|
1188
|
+
|
|
1189
|
+
# Save shifted timecourses for César
|
|
1190
|
+
if optiondict["saveintermediatemaps"] and optiondict["savelagregressors"]:
|
|
1191
|
+
theheader = theinputdata.copyheader()
|
|
1192
|
+
bidspasssuffix = f"_intermediatedata-pass{thepass}"
|
|
1193
|
+
maplist = [
|
|
1194
|
+
(
|
|
1195
|
+
(theRegressorRefiner.getpaddedshiftedtcs())[:, numpadtrs:-numpadtrs],
|
|
1196
|
+
"shiftedtcs",
|
|
1197
|
+
"bold",
|
|
1198
|
+
None,
|
|
1199
|
+
"The filtered input fMRI data, in voxels used for refinement, time shifted by the negated delay in every voxel so that the moving blood component is aligned.",
|
|
1200
|
+
),
|
|
1201
|
+
]
|
|
1202
|
+
tide_io.savemaplist(
|
|
1203
|
+
f"{outputname}{bidspasssuffix}",
|
|
1204
|
+
maplist,
|
|
1205
|
+
validvoxels,
|
|
1206
|
+
nativefmrishape,
|
|
1207
|
+
theheader,
|
|
1208
|
+
bidsbasedict,
|
|
1209
|
+
filetype=theinputdata.filetype,
|
|
1210
|
+
rt_floattype=rt_floattype,
|
|
1211
|
+
cifti_hdr=theinputdata.cifti_hdr,
|
|
1212
|
+
debug=debug,
|
|
1213
|
+
)
|
|
1214
|
+
|
|
1215
|
+
return resampref_y, resampnonosref_y, stoprefining, refinestopreason, genlagtc
|