rapidtide 3.0a13__py3-none-any.whl → 3.0a15__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.
- rapidtide/Colortables.py +1 -1
- rapidtide/DerivativeDelay.py +4 -2
- rapidtide/OrthoImageItem.py +1 -1
- rapidtide/RapidtideDataset.py +3 -1
- rapidtide/RegressorRefiner.py +1 -1
- rapidtide/calcandfitcorrpairs.py +1 -1
- rapidtide/calccoherence.py +1 -1
- rapidtide/calcnullsimfunc.py +1 -1
- rapidtide/calcsimfunc.py +1 -1
- rapidtide/correlate.py +1 -1
- rapidtide/data/examples/src/test_findmaxlag.py +1 -1
- rapidtide/data/examples/src/testdelayvar +2 -1
- rapidtide/data/examples/src/testfmri +3 -2
- rapidtide/data/examples/src/testfuncs +1 -1
- rapidtide/data/examples/src/testhappy +12 -1
- rapidtide/data/examples/src/testmodels +33 -0
- rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/loss.png +0 -0
- rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/loss.txt +1 -0
- rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/model.keras +0 -0
- rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/model_meta.json +167 -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/dlfilter.py +325 -241
- rapidtide/externaltools.py +1 -1
- rapidtide/fMRIData_class.py +1 -1
- rapidtide/filter.py +1 -8
- rapidtide/fit.py +1 -8
- rapidtide/happy_supportfuncs.py +30 -1
- rapidtide/helper_classes.py +1 -1
- rapidtide/io.py +1 -1
- rapidtide/linfitfiltpass.py +3 -1
- rapidtide/makelaggedtcs.py +9 -6
- rapidtide/maskutil.py +1 -1
- rapidtide/miscmath.py +1 -8
- rapidtide/multiproc.py +9 -12
- rapidtide/patchmatch.py +1 -1
- rapidtide/peakeval.py +1 -1
- rapidtide/qualitycheck.py +1 -1
- rapidtide/refinedelay.py +174 -89
- rapidtide/refineregressor.py +1 -1
- rapidtide/resample.py +1 -1
- rapidtide/scripts/adjustoffset.py +1 -1
- rapidtide/scripts/aligntcs.py +1 -1
- rapidtide/scripts/applydlfilter.py +1 -1
- rapidtide/scripts/atlasaverage.py +1 -1
- rapidtide/scripts/atlastool.py +1 -1
- rapidtide/scripts/calcicc.py +1 -1
- rapidtide/scripts/calctexticc.py +1 -1
- rapidtide/scripts/calcttest.py +1 -1
- rapidtide/scripts/ccorrica.py +1 -1
- rapidtide/scripts/delayvar.py +2 -2
- rapidtide/scripts/diffrois.py +1 -1
- rapidtide/scripts/endtidalproc.py +1 -1
- rapidtide/scripts/fdica.py +1 -1
- rapidtide/scripts/filtnifti.py +1 -1
- rapidtide/scripts/filttc.py +1 -1
- rapidtide/scripts/fingerprint.py +1 -1
- rapidtide/scripts/fixtr.py +1 -1
- rapidtide/scripts/gmscalc.py +1 -1
- rapidtide/scripts/happy.py +1 -1
- rapidtide/scripts/happy2std.py +1 -1
- rapidtide/scripts/happywarp.py +1 -1
- rapidtide/scripts/histnifti.py +1 -1
- rapidtide/scripts/histtc.py +1 -1
- rapidtide/scripts/linfitfilt.py +1 -1
- rapidtide/scripts/localflow.py +1 -1
- rapidtide/scripts/mergequality.py +1 -1
- rapidtide/scripts/pairproc.py +1 -1
- rapidtide/scripts/pairwisemergenifti.py +1 -1
- rapidtide/scripts/physiofreq.py +1 -1
- rapidtide/scripts/pixelcomp.py +1 -1
- rapidtide/scripts/plethquality.py +1 -1
- rapidtide/scripts/polyfitim.py +1 -1
- rapidtide/scripts/proj2flow.py +1 -1
- rapidtide/scripts/rankimage.py +1 -1
- rapidtide/scripts/rapidtide.py +1 -1
- rapidtide/scripts/rapidtide2std.py +1 -1
- rapidtide/scripts/resamplenifti.py +1 -1
- rapidtide/scripts/resampletc.py +1 -1
- rapidtide/scripts/retrolagtcs.py +1 -1
- rapidtide/scripts/retroregress.py +1 -1
- rapidtide/scripts/roisummarize.py +1 -1
- rapidtide/scripts/runqualitycheck.py +1 -1
- rapidtide/scripts/showarbcorr.py +1 -1
- rapidtide/scripts/showhist.py +1 -1
- rapidtide/scripts/showstxcorr.py +1 -1
- rapidtide/scripts/showtc.py +1 -1
- rapidtide/scripts/showxcorr_legacy.py +1 -1
- rapidtide/scripts/showxcorrx.py +1 -1
- rapidtide/scripts/showxy.py +1 -1
- rapidtide/scripts/simdata.py +1 -1
- rapidtide/scripts/spatialdecomp.py +1 -1
- rapidtide/scripts/spatialfit.py +1 -1
- rapidtide/scripts/spatialmi.py +1 -1
- rapidtide/scripts/spectrogram.py +1 -1
- rapidtide/scripts/stupidramtricks.py +1 -1
- rapidtide/scripts/synthASL.py +1 -1
- rapidtide/scripts/tcfrom2col.py +1 -1
- rapidtide/scripts/tcfrom3col.py +1 -1
- rapidtide/scripts/temporaldecomp.py +1 -1
- rapidtide/scripts/testhrv.py +1 -1
- rapidtide/scripts/threeD.py +1 -1
- rapidtide/scripts/tidepool.py +1 -1
- rapidtide/scripts/variabilityizer.py +1 -1
- rapidtide/simfuncfit.py +1 -1
- rapidtide/stats.py +1 -8
- rapidtide/tests/cleanposttest +1 -1
- rapidtide/tests/resethappytargets +1 -1
- rapidtide/tests/resetrapidtidetargets +1 -1
- rapidtide/tests/resettargets +1 -1
- rapidtide/tests/runlocaltest +1 -1
- rapidtide/tests/showkernels +1 -1
- rapidtide/tests/test_aliasedcorrelate.py +1 -1
- rapidtide/tests/test_aligntcs.py +1 -1
- rapidtide/tests/test_calcicc.py +1 -1
- rapidtide/tests/test_congrid.py +1 -1
- rapidtide/tests/test_correlate.py +1 -1
- rapidtide/tests/test_corrpass.py +1 -1
- rapidtide/tests/test_delayestimation.py +1 -1
- rapidtide/tests/test_doresample.py +1 -1
- rapidtide/tests/test_fastresampler.py +1 -1
- rapidtide/tests/test_findmaxlag.py +1 -1
- rapidtide/tests/test_fullrunhappy_v1.py +15 -7
- rapidtide/tests/test_fullrunhappy_v2.py +18 -10
- rapidtide/tests/test_fullrunhappy_v3.py +18 -10
- rapidtide/tests/test_fullrunhappy_v4.py +18 -10
- rapidtide/tests/test_fullrunhappy_v5.py +15 -9
- rapidtide/tests/test_fullrunrapidtide_v1.py +19 -11
- rapidtide/tests/test_fullrunrapidtide_v2.py +24 -14
- rapidtide/tests/test_fullrunrapidtide_v3.py +15 -7
- rapidtide/tests/test_fullrunrapidtide_v4.py +15 -8
- rapidtide/tests/test_fullrunrapidtide_v5.py +13 -5
- rapidtide/tests/test_fullrunrapidtide_v6.py +24 -16
- rapidtide/tests/test_io.py +1 -1
- rapidtide/tests/test_linfitfiltpass.py +1 -1
- rapidtide/tests/test_mi.py +1 -1
- rapidtide/tests/test_miscmath.py +1 -1
- rapidtide/tests/test_motionregress.py +1 -1
- rapidtide/tests/test_nullcorr.py +1 -1
- rapidtide/tests/test_padvec.py +1 -1
- rapidtide/tests/test_phaseanalysis.py +1 -1
- rapidtide/tests/test_rapidtideparser.py +1 -1
- rapidtide/tests/test_refinedelay.py +4 -3
- rapidtide/tests/test_runmisc.py +1 -1
- rapidtide/tests/test_sharedmem.py +1 -1
- rapidtide/tests/test_simulate.py +1 -1
- rapidtide/tests/test_stcorrelate.py +1 -1
- rapidtide/tests/test_timeshift.py +1 -1
- rapidtide/tests/test_valtoindex.py +1 -1
- rapidtide/tests/test_zRapidtideDataset.py +1 -1
- rapidtide/tests/utils.py +1 -1
- rapidtide/transformerdlfilter.py +2 -4
- rapidtide/util.py +37 -14
- rapidtide/voxelData.py +278 -0
- rapidtide/wiener.py +1 -1
- rapidtide/wiener2.py +1 -1
- rapidtide/workflows/adjustoffset.py +1 -1
- rapidtide/workflows/aligntcs.py +1 -1
- rapidtide/workflows/applydlfilter.py +20 -65
- rapidtide/workflows/atlasaverage.py +41 -13
- rapidtide/workflows/atlastool.py +1 -1
- rapidtide/workflows/calctexticc.py +1 -1
- rapidtide/workflows/ccorrica.py +1 -1
- rapidtide/workflows/cleanregressor.py +243 -0
- rapidtide/workflows/delayestimation.py +488 -0
- rapidtide/workflows/delayvar.py +122 -34
- rapidtide/workflows/diffrois.py +1 -1
- rapidtide/workflows/endtidalproc.py +1 -1
- rapidtide/workflows/fdica.py +1 -1
- rapidtide/workflows/filtnifti.py +1 -1
- rapidtide/workflows/filttc.py +1 -1
- rapidtide/workflows/fixtr.py +1 -1
- rapidtide/workflows/gmscalc.py +1 -1
- rapidtide/workflows/happy.py +49 -3
- rapidtide/workflows/happy2std.py +1 -1
- rapidtide/workflows/happy_parser.py +30 -6
- rapidtide/workflows/histnifti.py +1 -1
- rapidtide/workflows/histtc.py +1 -1
- rapidtide/workflows/linfitfilt.py +1 -1
- rapidtide/workflows/localflow.py +1 -1
- rapidtide/workflows/mergequality.py +1 -1
- rapidtide/workflows/niftidecomp.py +1 -1
- rapidtide/workflows/niftistats.py +1 -1
- rapidtide/workflows/pairproc.py +1 -1
- rapidtide/workflows/pairwisemergenifti.py +1 -1
- rapidtide/workflows/parser_funcs.py +1 -1
- rapidtide/workflows/physiofreq.py +1 -1
- rapidtide/workflows/pixelcomp.py +1 -1
- rapidtide/workflows/plethquality.py +1 -1
- rapidtide/workflows/polyfitim.py +1 -1
- rapidtide/workflows/proj2flow.py +1 -1
- rapidtide/workflows/rankimage.py +1 -1
- rapidtide/workflows/rapidtide.py +174 -686
- rapidtide/workflows/rapidtide2std.py +1 -1
- rapidtide/workflows/rapidtide_parser.py +14 -113
- rapidtide/workflows/regressfrommaps.py +6 -48
- rapidtide/workflows/resamplenifti.py +1 -1
- rapidtide/workflows/resampletc.py +1 -1
- rapidtide/workflows/retrolagtcs.py +2 -1
- rapidtide/workflows/retroregress.py +26 -2
- rapidtide/workflows/roisummarize.py +1 -1
- rapidtide/workflows/runqualitycheck.py +1 -1
- rapidtide/workflows/showarbcorr.py +1 -1
- rapidtide/workflows/showhist.py +1 -1
- rapidtide/workflows/showstxcorr.py +1 -1
- rapidtide/workflows/showtc.py +1 -1
- rapidtide/workflows/showxcorrx.py +1 -1
- rapidtide/workflows/showxy.py +1 -1
- rapidtide/workflows/simdata.py +1 -1
- rapidtide/workflows/spatialfit.py +1 -1
- rapidtide/workflows/spatialmi.py +1 -1
- rapidtide/workflows/spectrogram.py +1 -1
- rapidtide/workflows/synthASL.py +1 -1
- rapidtide/workflows/tcfrom2col.py +1 -1
- rapidtide/workflows/tcfrom3col.py +1 -1
- rapidtide/workflows/tidepool.py +2 -1
- rapidtide/workflows/utils.py +1 -1
- rapidtide/workflows/variabilityizer.py +1 -1
- {rapidtide-3.0a13.dist-info → rapidtide-3.0a15.dist-info}/METADATA +1 -1
- rapidtide-3.0a15.dist-info/RECORD +353 -0
- {rapidtide-3.0a13.dist-info → rapidtide-3.0a15.dist-info}/WHEEL +1 -1
- 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-3.0a13.dist-info/RECORD +0 -345
- {rapidtide-3.0a13.dist-info → rapidtide-3.0a15.dist-info}/entry_points.txt +0 -0
- {rapidtide-3.0a13.dist-info → rapidtide-3.0a15.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0a13.dist-info → rapidtide-3.0a15.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,488 @@
|
|
|
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 argparse
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
from scipy.stats import skew
|
|
24
|
+
|
|
25
|
+
import rapidtide.io as tide_io
|
|
26
|
+
import rapidtide.workflows.parser_funcs as pf
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
import mkl
|
|
30
|
+
|
|
31
|
+
mklexists = True
|
|
32
|
+
except ImportError:
|
|
33
|
+
mklexists = False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def disablemkl(numprocs, debug=False):
|
|
37
|
+
if mklexists:
|
|
38
|
+
if numprocs > 1:
|
|
39
|
+
if debug:
|
|
40
|
+
print("disablemkl: setting threads to 1")
|
|
41
|
+
mkl.set_num_threads(1)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def enablemkl(numthreads, debug=False):
|
|
45
|
+
if mklexists:
|
|
46
|
+
if debug:
|
|
47
|
+
print(f"enablemkl: setting threads to {numthreads}")
|
|
48
|
+
mkl.set_num_threads(numthreads)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def estimateDelay(voxeldata, datatimeaxis, osdatatimeaxis, theMutualInformationator, thepass):
|
|
52
|
+
# Step 1 - Correlation step
|
|
53
|
+
if optiondict["similaritymetric"] == "mutualinfo":
|
|
54
|
+
similaritytype = "Mutual information"
|
|
55
|
+
elif optiondict["similaritymetric"] == "correlation":
|
|
56
|
+
similaritytype = "Correlation"
|
|
57
|
+
else:
|
|
58
|
+
similaritytype = "MI enhanced correlation"
|
|
59
|
+
LGR.info(f"\n\n{similaritytype} calculation, pass {thepass}")
|
|
60
|
+
TimingLGR.info(f"{similaritytype} calculation start, pass {thepass}")
|
|
61
|
+
|
|
62
|
+
disablemkl(optiondict["nprocs_calcsimilarity"], debug=threaddebug)
|
|
63
|
+
if optiondict["similaritymetric"] == "mutualinfo":
|
|
64
|
+
theMutualInformationator.setlimits(lagmininpts, lagmaxinpts)
|
|
65
|
+
(
|
|
66
|
+
voxelsprocessed_cp,
|
|
67
|
+
theglobalmaxlist,
|
|
68
|
+
trimmedcorrscale,
|
|
69
|
+
) = tide_calcsimfunc.correlationpass(
|
|
70
|
+
voxeldata,
|
|
71
|
+
cleaned_referencetc,
|
|
72
|
+
theMutualInformationator,
|
|
73
|
+
datatimeaxis,
|
|
74
|
+
osdatatimeaxis,
|
|
75
|
+
lagmininpts,
|
|
76
|
+
lagmaxinpts,
|
|
77
|
+
corrout,
|
|
78
|
+
meanval,
|
|
79
|
+
nprocs=optiondict["nprocs_calcsimilarity"],
|
|
80
|
+
alwaysmultiproc=optiondict["alwaysmultiproc"],
|
|
81
|
+
oversampfactor=optiondict["oversampfactor"],
|
|
82
|
+
interptype=optiondict["interptype"],
|
|
83
|
+
showprogressbar=optiondict["showprogressbar"],
|
|
84
|
+
chunksize=optiondict["mp_chunksize"],
|
|
85
|
+
rt_floatset=rt_floatset,
|
|
86
|
+
rt_floattype=rt_floattype,
|
|
87
|
+
)
|
|
88
|
+
else:
|
|
89
|
+
(
|
|
90
|
+
voxelsprocessed_cp,
|
|
91
|
+
theglobalmaxlist,
|
|
92
|
+
trimmedcorrscale,
|
|
93
|
+
) = tide_calcsimfunc.correlationpass(
|
|
94
|
+
voxeldata,
|
|
95
|
+
cleaned_referencetc,
|
|
96
|
+
theCorrelator,
|
|
97
|
+
datatimeaxis,
|
|
98
|
+
osdatatimeaxis,
|
|
99
|
+
lagmininpts,
|
|
100
|
+
lagmaxinpts,
|
|
101
|
+
corrout,
|
|
102
|
+
meanval,
|
|
103
|
+
nprocs=optiondict["nprocs_calcsimilarity"],
|
|
104
|
+
alwaysmultiproc=optiondict["alwaysmultiproc"],
|
|
105
|
+
oversampfactor=optiondict["oversampfactor"],
|
|
106
|
+
interptype=optiondict["interptype"],
|
|
107
|
+
showprogressbar=optiondict["showprogressbar"],
|
|
108
|
+
chunksize=optiondict["mp_chunksize"],
|
|
109
|
+
rt_floatset=rt_floatset,
|
|
110
|
+
rt_floattype=rt_floattype,
|
|
111
|
+
)
|
|
112
|
+
enablemkl(optiondict["mklthreads"], debug=threaddebug)
|
|
113
|
+
|
|
114
|
+
for i in range(len(theglobalmaxlist)):
|
|
115
|
+
theglobalmaxlist[i] = corrscale[theglobalmaxlist[i]] - optiondict["simcalcoffset"]
|
|
116
|
+
namesuffix = "_desc-globallag_hist"
|
|
117
|
+
tide_stats.makeandsavehistogram(
|
|
118
|
+
np.asarray(theglobalmaxlist),
|
|
119
|
+
len(corrscale),
|
|
120
|
+
0,
|
|
121
|
+
outputname + namesuffix,
|
|
122
|
+
displaytitle="Histogram of lag times from global lag calculation",
|
|
123
|
+
therange=(corrscale[0], corrscale[-1]),
|
|
124
|
+
refine=False,
|
|
125
|
+
dictvarname="globallaghist_pass" + str(thepass),
|
|
126
|
+
append=(optiondict["echocancel"] or (thepass > 1)),
|
|
127
|
+
thedict=optiondict,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
if optiondict["checkpoint"]:
|
|
131
|
+
outcorrarray[:, :] = 0.0
|
|
132
|
+
outcorrarray[validvoxels, :] = corrout[:, :]
|
|
133
|
+
if optiondict["textio"]:
|
|
134
|
+
tide_io.writenpvecs(
|
|
135
|
+
outcorrarray.reshape(nativecorrshape),
|
|
136
|
+
f"{outputname}_corrout_prefit_pass" + str(thepass) + ".txt",
|
|
137
|
+
)
|
|
138
|
+
else:
|
|
139
|
+
savename = f"{outputname}_desc-corroutprefit_pass-" + str(thepass)
|
|
140
|
+
tide_io.savetonifti(outcorrarray.reshape(nativecorrshape), theheader, savename)
|
|
141
|
+
|
|
142
|
+
TimingLGR.info(
|
|
143
|
+
f"{similaritytype} calculation end, pass {thepass}",
|
|
144
|
+
{
|
|
145
|
+
"message2": voxelsprocessed_cp,
|
|
146
|
+
"message3": "voxels",
|
|
147
|
+
},
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Step 1b. Do a peak prefit
|
|
151
|
+
if optiondict["similaritymetric"] == "hybrid":
|
|
152
|
+
LGR.info(f"\n\nPeak prefit calculation, pass {thepass}")
|
|
153
|
+
TimingLGR.info(f"Peak prefit calculation start, pass {thepass}")
|
|
154
|
+
|
|
155
|
+
disablemkl(optiondict["nprocs_peakeval"], debug=threaddebug)
|
|
156
|
+
voxelsprocessed_pe, thepeakdict = tide_peakeval.peakevalpass(
|
|
157
|
+
voxeldata,
|
|
158
|
+
cleaned_referencetc,
|
|
159
|
+
datatimeaxis,
|
|
160
|
+
osdatatimeaxis,
|
|
161
|
+
theMutualInformationator,
|
|
162
|
+
trimmedcorrscale,
|
|
163
|
+
corrout,
|
|
164
|
+
nprocs=optiondict["nprocs_peakeval"],
|
|
165
|
+
alwaysmultiproc=optiondict["alwaysmultiproc"],
|
|
166
|
+
bipolar=optiondict["bipolar"],
|
|
167
|
+
oversampfactor=optiondict["oversampfactor"],
|
|
168
|
+
interptype=optiondict["interptype"],
|
|
169
|
+
showprogressbar=optiondict["showprogressbar"],
|
|
170
|
+
chunksize=optiondict["mp_chunksize"],
|
|
171
|
+
rt_floatset=rt_floatset,
|
|
172
|
+
rt_floattype=rt_floattype,
|
|
173
|
+
)
|
|
174
|
+
enablemkl(optiondict["mklthreads"], debug=threaddebug)
|
|
175
|
+
|
|
176
|
+
TimingLGR.info(
|
|
177
|
+
f"Peak prefit end, pass {thepass}",
|
|
178
|
+
{
|
|
179
|
+
"message2": voxelsprocessed_pe,
|
|
180
|
+
"message3": "voxels",
|
|
181
|
+
},
|
|
182
|
+
)
|
|
183
|
+
mipeaks = lagtimes * 0.0
|
|
184
|
+
for i in range(numvalidspatiallocs):
|
|
185
|
+
if len(thepeakdict[str(i)]) > 0:
|
|
186
|
+
mipeaks[i] = thepeakdict[str(i)][0][0]
|
|
187
|
+
else:
|
|
188
|
+
thepeakdict = None
|
|
189
|
+
|
|
190
|
+
# Step 2 - similarity function fitting and time lag estimation
|
|
191
|
+
# write out the current version of the run options
|
|
192
|
+
optiondict["currentstage"] = f"presimfuncfit_pass{thepass}"
|
|
193
|
+
tide_io.writedicttojson(optiondict, f"{outputname}_desc-runoptions_info.json")
|
|
194
|
+
LGR.info(f"\n\nTime lag estimation pass {thepass}")
|
|
195
|
+
TimingLGR.info(f"Time lag estimation start, pass {thepass}")
|
|
196
|
+
|
|
197
|
+
theFitter.setfunctype(optiondict["similaritymetric"])
|
|
198
|
+
theFitter.setcorrtimeaxis(trimmedcorrscale)
|
|
199
|
+
|
|
200
|
+
# use initial lags if this is a hybrid fit
|
|
201
|
+
if optiondict["similaritymetric"] == "hybrid" and thepeakdict is not None:
|
|
202
|
+
initlags = mipeaks
|
|
203
|
+
else:
|
|
204
|
+
initlags = None
|
|
205
|
+
|
|
206
|
+
disablemkl(optiondict["nprocs_fitcorr"], debug=threaddebug)
|
|
207
|
+
voxelsprocessed_fc = tide_simfuncfit.fitcorr(
|
|
208
|
+
trimmedcorrscale,
|
|
209
|
+
theFitter,
|
|
210
|
+
corrout,
|
|
211
|
+
fitmask,
|
|
212
|
+
failreason,
|
|
213
|
+
lagtimes,
|
|
214
|
+
lagstrengths,
|
|
215
|
+
lagsigma,
|
|
216
|
+
gaussout,
|
|
217
|
+
windowout,
|
|
218
|
+
R2,
|
|
219
|
+
despeckling=False,
|
|
220
|
+
peakdict=thepeakdict,
|
|
221
|
+
nprocs=optiondict["nprocs_fitcorr"],
|
|
222
|
+
alwaysmultiproc=optiondict["alwaysmultiproc"],
|
|
223
|
+
fixdelay=optiondict["fixdelay"],
|
|
224
|
+
initialdelayvalue=theinitialdelay,
|
|
225
|
+
showprogressbar=optiondict["showprogressbar"],
|
|
226
|
+
chunksize=optiondict["mp_chunksize"],
|
|
227
|
+
despeckle_thresh=optiondict["despeckle_thresh"],
|
|
228
|
+
initiallags=initlags,
|
|
229
|
+
rt_floatset=rt_floatset,
|
|
230
|
+
rt_floattype=rt_floattype,
|
|
231
|
+
)
|
|
232
|
+
enablemkl(optiondict["mklthreads"], debug=threaddebug)
|
|
233
|
+
|
|
234
|
+
TimingLGR.info(
|
|
235
|
+
f"Time lag estimation end, pass {thepass}",
|
|
236
|
+
{
|
|
237
|
+
"message2": voxelsprocessed_fc,
|
|
238
|
+
"message3": "voxels",
|
|
239
|
+
},
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
# Step 2b - Correlation time despeckle
|
|
243
|
+
if optiondict["despeckle_passes"] > 0:
|
|
244
|
+
LGR.info(f"\n\n{similaritytype} despeckling pass {thepass}")
|
|
245
|
+
LGR.info(f"\tUsing despeckle_thresh = {optiondict['despeckle_thresh']:.3f}")
|
|
246
|
+
TimingLGR.info(f"{similaritytype} despeckle start, pass {thepass}")
|
|
247
|
+
|
|
248
|
+
# find lags that are very different from their neighbors, and refit starting at the median lag for the point
|
|
249
|
+
voxelsprocessed_fc_ds = 0
|
|
250
|
+
despecklingdone = False
|
|
251
|
+
lastnumdespeckled = 1000000
|
|
252
|
+
for despecklepass in range(optiondict["despeckle_passes"]):
|
|
253
|
+
LGR.info(f"\n\n{similaritytype} despeckling subpass {despecklepass + 1}")
|
|
254
|
+
outmaparray *= 0.0
|
|
255
|
+
outmaparray[validvoxels] = eval("lagtimes")[:]
|
|
256
|
+
|
|
257
|
+
# find voxels to despeckle
|
|
258
|
+
medianlags = ndimage.median_filter(outmaparray.reshape(nativespaceshape), 3).reshape(
|
|
259
|
+
numspatiallocs
|
|
260
|
+
)
|
|
261
|
+
# voxels that we're happy with have initlags set to -1000000.0
|
|
262
|
+
initlags = np.where(
|
|
263
|
+
np.abs(outmaparray - medianlags) > optiondict["despeckle_thresh"],
|
|
264
|
+
medianlags,
|
|
265
|
+
-1000000.0,
|
|
266
|
+
)[validvoxels]
|
|
267
|
+
|
|
268
|
+
if len(initlags) > 0:
|
|
269
|
+
numdespeckled = len(np.where(initlags != -1000000.0)[0])
|
|
270
|
+
if lastnumdespeckled > numdespeckled > 0:
|
|
271
|
+
lastnumdespeckled = numdespeckled
|
|
272
|
+
disablemkl(optiondict["nprocs_fitcorr"], debug=threaddebug)
|
|
273
|
+
voxelsprocessed_thispass = tide_simfuncfit.fitcorr(
|
|
274
|
+
trimmedcorrscale,
|
|
275
|
+
theFitter,
|
|
276
|
+
corrout,
|
|
277
|
+
fitmask,
|
|
278
|
+
failreason,
|
|
279
|
+
lagtimes,
|
|
280
|
+
lagstrengths,
|
|
281
|
+
lagsigma,
|
|
282
|
+
gaussout,
|
|
283
|
+
windowout,
|
|
284
|
+
R2,
|
|
285
|
+
despeckling=True,
|
|
286
|
+
peakdict=thepeakdict,
|
|
287
|
+
nprocs=optiondict["nprocs_fitcorr"],
|
|
288
|
+
alwaysmultiproc=optiondict["alwaysmultiproc"],
|
|
289
|
+
fixdelay=optiondict["fixdelay"],
|
|
290
|
+
initialdelayvalue=theinitialdelay,
|
|
291
|
+
showprogressbar=optiondict["showprogressbar"],
|
|
292
|
+
chunksize=optiondict["mp_chunksize"],
|
|
293
|
+
despeckle_thresh=optiondict["despeckle_thresh"],
|
|
294
|
+
initiallags=initlags,
|
|
295
|
+
rt_floatset=rt_floatset,
|
|
296
|
+
rt_floattype=rt_floattype,
|
|
297
|
+
)
|
|
298
|
+
enablemkl(optiondict["mklthreads"], debug=threaddebug)
|
|
299
|
+
|
|
300
|
+
voxelsprocessed_fc_ds += voxelsprocessed_thispass
|
|
301
|
+
optiondict[
|
|
302
|
+
"despecklemasksize_pass" + str(thepass) + "_d" + str(despecklepass + 1)
|
|
303
|
+
] = voxelsprocessed_thispass
|
|
304
|
+
optiondict[
|
|
305
|
+
"despecklemaskpct_pass" + str(thepass) + "_d" + str(despecklepass + 1)
|
|
306
|
+
] = (100.0 * voxelsprocessed_thispass / optiondict["corrmasksize"])
|
|
307
|
+
else:
|
|
308
|
+
despecklingdone = True
|
|
309
|
+
else:
|
|
310
|
+
despecklingdone = True
|
|
311
|
+
if despecklingdone:
|
|
312
|
+
LGR.info("Nothing left to do! Terminating despeckling")
|
|
313
|
+
break
|
|
314
|
+
|
|
315
|
+
internaldespeckleincludemask = np.where(
|
|
316
|
+
np.abs(outmaparray - medianlags) > optiondict["despeckle_thresh"],
|
|
317
|
+
medianlags,
|
|
318
|
+
0.0,
|
|
319
|
+
)
|
|
320
|
+
if optiondict["savedespecklemasks"] and (optiondict["despeckle_passes"] > 0):
|
|
321
|
+
despecklesavemask = np.where(internaldespeckleincludemask[validvoxels] == 0.0, 0, 1)
|
|
322
|
+
if thepass == optiondict["passes"]:
|
|
323
|
+
if not optiondict["textio"]:
|
|
324
|
+
if fileiscifti:
|
|
325
|
+
timeindex = theheader["dim"][0] - 1
|
|
326
|
+
spaceindex = theheader["dim"][0]
|
|
327
|
+
theheader["dim"][timeindex] = 1
|
|
328
|
+
theheader["dim"][spaceindex] = numspatiallocs
|
|
329
|
+
else:
|
|
330
|
+
theheader["dim"][0] = 3
|
|
331
|
+
theheader["dim"][4] = 1
|
|
332
|
+
theheader["pixdim"][4] = 1.0
|
|
333
|
+
masklist = [
|
|
334
|
+
(
|
|
335
|
+
despecklesavemask,
|
|
336
|
+
"despeckle",
|
|
337
|
+
"mask",
|
|
338
|
+
None,
|
|
339
|
+
"Voxels that underwent despeckling in the final pass",
|
|
340
|
+
)
|
|
341
|
+
]
|
|
342
|
+
tide_io.savemaplist(
|
|
343
|
+
outputname,
|
|
344
|
+
masklist,
|
|
345
|
+
validvoxels,
|
|
346
|
+
nativespaceshape,
|
|
347
|
+
theheader,
|
|
348
|
+
bidsbasedict,
|
|
349
|
+
textio=optiondict["textio"],
|
|
350
|
+
fileiscifti=fileiscifti,
|
|
351
|
+
rt_floattype=rt_floattype,
|
|
352
|
+
cifti_hdr=cifti_hdr,
|
|
353
|
+
)
|
|
354
|
+
LGR.info(
|
|
355
|
+
f"\n\n{voxelsprocessed_fc_ds} voxels despeckled in "
|
|
356
|
+
f"{optiondict['despeckle_passes']} passes"
|
|
357
|
+
)
|
|
358
|
+
TimingLGR.info(
|
|
359
|
+
f"{similaritytype} despeckle end, pass {thepass}",
|
|
360
|
+
{
|
|
361
|
+
"message2": voxelsprocessed_fc_ds,
|
|
362
|
+
"message3": "voxels",
|
|
363
|
+
},
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
# Step 2c - patch shifting
|
|
367
|
+
if optiondict["patchshift"]:
|
|
368
|
+
outmaparray *= 0.0
|
|
369
|
+
outmaparray[validvoxels] = eval("lagtimes")[:]
|
|
370
|
+
# new method
|
|
371
|
+
masklist = [
|
|
372
|
+
(
|
|
373
|
+
outmaparray[validvoxels],
|
|
374
|
+
f"lagtimes_prepatch_pass{thepass}",
|
|
375
|
+
"map",
|
|
376
|
+
None,
|
|
377
|
+
f"Input lagtimes map prior to patch map generation pass {thepass}",
|
|
378
|
+
),
|
|
379
|
+
]
|
|
380
|
+
tide_io.savemaplist(
|
|
381
|
+
outputname,
|
|
382
|
+
masklist,
|
|
383
|
+
validvoxels,
|
|
384
|
+
nativespaceshape,
|
|
385
|
+
theheader,
|
|
386
|
+
bidsbasedict,
|
|
387
|
+
textio=optiondict["textio"],
|
|
388
|
+
fileiscifti=fileiscifti,
|
|
389
|
+
rt_floattype=rt_floattype,
|
|
390
|
+
cifti_hdr=cifti_hdr,
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
# create list of anomalous 3D regions that don't match surroundings
|
|
394
|
+
if nim_affine is not None:
|
|
395
|
+
# make an atlas of anomalous patches - each patch shares the same integer value
|
|
396
|
+
step1 = tide_patch.calc_DoG(
|
|
397
|
+
outmaparray.reshape(nativespaceshape).copy(),
|
|
398
|
+
nim_affine,
|
|
399
|
+
thesizes,
|
|
400
|
+
fwhm=optiondict["patchfwhm"],
|
|
401
|
+
ratioopt=False,
|
|
402
|
+
debug=True,
|
|
403
|
+
)
|
|
404
|
+
masklist = [
|
|
405
|
+
(
|
|
406
|
+
step1.reshape(internalspaceshape)[validvoxels],
|
|
407
|
+
f"DoG_pass{thepass}",
|
|
408
|
+
"map",
|
|
409
|
+
None,
|
|
410
|
+
f"DoG map for pass {thepass}",
|
|
411
|
+
),
|
|
412
|
+
]
|
|
413
|
+
tide_io.savemaplist(
|
|
414
|
+
outputname,
|
|
415
|
+
masklist,
|
|
416
|
+
validvoxels,
|
|
417
|
+
nativespaceshape,
|
|
418
|
+
theheader,
|
|
419
|
+
bidsbasedict,
|
|
420
|
+
textio=optiondict["textio"],
|
|
421
|
+
fileiscifti=fileiscifti,
|
|
422
|
+
rt_floattype=rt_floattype,
|
|
423
|
+
cifti_hdr=cifti_hdr,
|
|
424
|
+
)
|
|
425
|
+
step2 = tide_patch.invertedflood3D(
|
|
426
|
+
step1,
|
|
427
|
+
1,
|
|
428
|
+
)
|
|
429
|
+
masklist = [
|
|
430
|
+
(
|
|
431
|
+
step2.reshape(internalspaceshape)[validvoxels],
|
|
432
|
+
f"invertflood_pass{thepass}",
|
|
433
|
+
"map",
|
|
434
|
+
None,
|
|
435
|
+
f"Inverted flood map for pass {thepass}",
|
|
436
|
+
),
|
|
437
|
+
]
|
|
438
|
+
tide_io.savemaplist(
|
|
439
|
+
outputname,
|
|
440
|
+
masklist,
|
|
441
|
+
validvoxels,
|
|
442
|
+
nativespaceshape,
|
|
443
|
+
theheader,
|
|
444
|
+
bidsbasedict,
|
|
445
|
+
textio=optiondict["textio"],
|
|
446
|
+
fileiscifti=fileiscifti,
|
|
447
|
+
rt_floattype=rt_floattype,
|
|
448
|
+
cifti_hdr=cifti_hdr,
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
patchmap = tide_patch.separateclusters(
|
|
452
|
+
step2,
|
|
453
|
+
sizethresh=optiondict["patchminsize"],
|
|
454
|
+
debug=True,
|
|
455
|
+
)
|
|
456
|
+
# patchmap = tide_patch.getclusters(
|
|
457
|
+
# outmaparray.reshape(nativespaceshape),
|
|
458
|
+
# nim_affine,
|
|
459
|
+
# thesizes,
|
|
460
|
+
# fwhm=optiondict["patchfwhm"],
|
|
461
|
+
# ratioopt=True,
|
|
462
|
+
# sizethresh=optiondict["patchminsize"],
|
|
463
|
+
# debug=True,
|
|
464
|
+
# )
|
|
465
|
+
masklist = [
|
|
466
|
+
(
|
|
467
|
+
patchmap[validvoxels],
|
|
468
|
+
f"patch_pass{thepass}",
|
|
469
|
+
"map",
|
|
470
|
+
None,
|
|
471
|
+
f"Patch map for despeckling pass {thepass}",
|
|
472
|
+
),
|
|
473
|
+
]
|
|
474
|
+
tide_io.savemaplist(
|
|
475
|
+
outputname,
|
|
476
|
+
masklist,
|
|
477
|
+
validvoxels,
|
|
478
|
+
nativespaceshape,
|
|
479
|
+
theheader,
|
|
480
|
+
bidsbasedict,
|
|
481
|
+
textio=optiondict["textio"],
|
|
482
|
+
fileiscifti=fileiscifti,
|
|
483
|
+
rt_floattype=rt_floattype,
|
|
484
|
+
cifti_hdr=cifti_hdr,
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
# now shift the patches to align with the majority of the image
|
|
488
|
+
tide_patch.interppatch(lagtimes, patchmap[validvoxels])
|