rapidtide 3.0.2__py3-none-any.whl → 3.0.4__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/RapidtideDataset.py +2 -0
- rapidtide/_version.py +20 -682
- rapidtide/calcsimfunc.py +3 -0
- rapidtide/correlate.py +18 -1
- rapidtide/data/examples/src/testfmri +7 -4
- rapidtide/data/examples/src/testretro +10 -4
- rapidtide/helper_classes.py +4 -4
- rapidtide/io.py +8 -1
- rapidtide/maskutil.py +144 -0
- rapidtide/tests/test_cleanregressor.py +185 -0
- rapidtide/tests/test_fullrunrapidtide_v1.py +2 -0
- rapidtide/tests/test_fullrunrapidtide_v7.py +114 -0
- rapidtide/tests/test_getparsers.py +140 -0
- rapidtide/tests/test_io.py +58 -13
- rapidtide/tests/test_parserfuncs.py +70 -0
- rapidtide/tests/test_zRapidtideDataset.py +2 -0
- rapidtide/voxelData.py +1 -0
- rapidtide/workflows/cleanregressor.py +43 -6
- rapidtide/workflows/rapidtide.py +247 -108
- rapidtide/workflows/rapidtide2std.py +2 -0
- rapidtide/workflows/rapidtide_parser.py +115 -66
- rapidtide/workflows/retroregress.py +192 -43
- rapidtide/workflows/tidepool.py +6 -0
- {rapidtide-3.0.2.dist-info → rapidtide-3.0.4.dist-info}/METADATA +1 -1
- {rapidtide-3.0.2.dist-info → rapidtide-3.0.4.dist-info}/RECORD +29 -25
- {rapidtide-3.0.2.dist-info → rapidtide-3.0.4.dist-info}/WHEEL +1 -1
- {rapidtide-3.0.2.dist-info → rapidtide-3.0.4.dist-info}/entry_points.txt +0 -0
- {rapidtide-3.0.2.dist-info → rapidtide-3.0.4.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.2.dist-info → rapidtide-3.0.4.dist-info}/top_level.txt +0 -0
rapidtide/workflows/rapidtide.py
CHANGED
|
@@ -71,75 +71,6 @@ ErrorLGR = logging.getLogger("ERROR")
|
|
|
71
71
|
TimingLGR = logging.getLogger("TIMING")
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
def getglobalsignal(
|
|
75
|
-
indata, optiondict, includemask=None, excludemask=None, pcacomponents=0.8, debug=False
|
|
76
|
-
):
|
|
77
|
-
# Start with all voxels
|
|
78
|
-
themask = indata[:, 0] * 0 + 1
|
|
79
|
-
|
|
80
|
-
# modify the mask if needed
|
|
81
|
-
if includemask is not None:
|
|
82
|
-
themask = themask * includemask
|
|
83
|
-
if excludemask is not None:
|
|
84
|
-
themask = themask * (1 - excludemask)
|
|
85
|
-
|
|
86
|
-
# combine all the voxels using one of the three methods
|
|
87
|
-
global rt_floatset, rt_floattype
|
|
88
|
-
globalmean = rt_floatset(indata[0, :])
|
|
89
|
-
thesize = np.shape(themask)
|
|
90
|
-
numvoxelsused = int(np.sum(np.where(themask > 0.0, 1, 0)))
|
|
91
|
-
selectedvoxels = indata[np.where(themask > 0.0), :][0]
|
|
92
|
-
if debug:
|
|
93
|
-
print(f"getglobalsignal: {selectedvoxels.shape=}")
|
|
94
|
-
LGR.info(f"constructing global mean signal using {optiondict['globalsignalmethod']}")
|
|
95
|
-
if optiondict["globalsignalmethod"] == "sum":
|
|
96
|
-
globalmean = np.mean(selectedvoxels, axis=0)
|
|
97
|
-
globalmean -= np.mean(globalmean)
|
|
98
|
-
elif optiondict["globalsignalmethod"] == "meanscale":
|
|
99
|
-
themean = np.mean(indata, axis=1)
|
|
100
|
-
for vox in range(0, thesize[0]):
|
|
101
|
-
if themask[vox] > 0.0:
|
|
102
|
-
if themean[vox] != 0.0:
|
|
103
|
-
globalmean += indata[vox, :] / themean[vox] - 1.0
|
|
104
|
-
elif optiondict["globalsignalmethod"] == "pca":
|
|
105
|
-
themean = np.mean(indata, axis=1)
|
|
106
|
-
thevar = np.var(indata, axis=1)
|
|
107
|
-
scaledvoxels = selectedvoxels * 0.0
|
|
108
|
-
for vox in range(0, selectedvoxels.shape[0]):
|
|
109
|
-
scaledvoxels[vox, :] = selectedvoxels[vox, :] - themean[vox]
|
|
110
|
-
if thevar[vox] > 0.0:
|
|
111
|
-
scaledvoxels[vox, :] = selectedvoxels[vox, :] / thevar[vox]
|
|
112
|
-
try:
|
|
113
|
-
thefit = PCA(n_components=pcacomponents).fit(np.transpose(scaledvoxels))
|
|
114
|
-
except ValueError:
|
|
115
|
-
if pcacomponents == "mle":
|
|
116
|
-
LGR.warning("mle estimation failed - falling back to pcacomponents=0.8")
|
|
117
|
-
thefit = PCA(n_components=0.8).fit(np.transpose(scaledvoxels))
|
|
118
|
-
else:
|
|
119
|
-
raise ValueError("unhandled math exception in PCA refinement - exiting")
|
|
120
|
-
|
|
121
|
-
varex = 100.0 * np.cumsum(thefit.explained_variance_ratio_)[len(thefit.components_) - 1]
|
|
122
|
-
thetransform = thefit.transform(np.transpose(scaledvoxels))
|
|
123
|
-
if debug:
|
|
124
|
-
print(f"getglobalsignal: {thetransform.shape=}")
|
|
125
|
-
globalmean = np.mean(thetransform, axis=0)
|
|
126
|
-
globalmean -= np.mean(globalmean)
|
|
127
|
-
if debug:
|
|
128
|
-
print(f"getglobalsignal: {varex=}")
|
|
129
|
-
LGR.info(
|
|
130
|
-
f"Using {len(thefit.components_)} component(s), accounting for "
|
|
131
|
-
f"{varex:.2f}% of the variance"
|
|
132
|
-
)
|
|
133
|
-
elif optiondict["globalsignalmethod"] == "random":
|
|
134
|
-
globalmean = np.random.standard_normal(size=len(globalmean))
|
|
135
|
-
else:
|
|
136
|
-
raise ValueError(f"illegal globalsignalmethod: {optiondict['globalsignalmethod']}")
|
|
137
|
-
LGR.info(f"used {numvoxelsused} voxels to calculate global mean signal")
|
|
138
|
-
if debug:
|
|
139
|
-
print(f"getglobalsignal: {globalmean=}")
|
|
140
|
-
return tide_math.stdnormalize(globalmean), themask
|
|
141
|
-
|
|
142
|
-
|
|
143
74
|
def checkforzeromean(thedataset):
|
|
144
75
|
themean = np.mean(thedataset, axis=1)
|
|
145
76
|
thestd = np.std(thedataset, axis=1)
|
|
@@ -437,6 +368,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
437
368
|
["brainmaskincludename", "brainmaskincludevals", "brainmask"],
|
|
438
369
|
["graymatterincludename", "graymatterincludevals", "graymattermask"],
|
|
439
370
|
["whitematterincludename", "whitematterincludevals", "whitemattermask"],
|
|
371
|
+
["csfincludename", "csfincludevals", "csfmask"],
|
|
440
372
|
]
|
|
441
373
|
anatomicmasks = []
|
|
442
374
|
for thisanatomic in anatomiclist:
|
|
@@ -450,6 +382,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
450
382
|
valslist=optiondict[thisanatomic[1]],
|
|
451
383
|
maskname=thisanatomic[2],
|
|
452
384
|
tolerance=optiondict["spatialtolerance"],
|
|
385
|
+
debug=optiondict["focaldebug"],
|
|
453
386
|
)
|
|
454
387
|
)
|
|
455
388
|
anatomicmasks[-1] = np.uint16(np.where(anatomicmasks[-1] > 0.1, 1, 0))
|
|
@@ -459,6 +392,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
459
392
|
brainmask = anatomicmasks[0]
|
|
460
393
|
graymask = anatomicmasks[1]
|
|
461
394
|
whitemask = anatomicmasks[2]
|
|
395
|
+
csfmask = anatomicmasks[3]
|
|
462
396
|
|
|
463
397
|
# do spatial filtering if requested
|
|
464
398
|
optiondict["gausssigma"] = theinputdata.smooth(
|
|
@@ -489,7 +423,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
489
423
|
)
|
|
490
424
|
optiondict["refineprenorm"] = "None"
|
|
491
425
|
|
|
492
|
-
# reformat the
|
|
426
|
+
# reformat the anatomic masks, if they exist
|
|
493
427
|
if brainmask is None:
|
|
494
428
|
invbrainmask = None
|
|
495
429
|
|
|
@@ -503,22 +437,25 @@ def rapidtide_main(argparsingfunc):
|
|
|
503
437
|
# read in the optional masks
|
|
504
438
|
tide_util.logmem("before setting masks")
|
|
505
439
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
440
|
+
internalinitregressorincludemask, internalinitregressorexcludemask, dummy = (
|
|
441
|
+
tide_mask.getmaskset(
|
|
442
|
+
"global mean",
|
|
443
|
+
optiondict["initregressorincludename"],
|
|
444
|
+
optiondict["initregressorincludevals"],
|
|
445
|
+
optiondict["initregressorexcludename"],
|
|
446
|
+
optiondict["initregressorexcludevals"],
|
|
447
|
+
theinputdata.nim_hdr,
|
|
448
|
+
numspatiallocs,
|
|
449
|
+
istext=(theinputdata.filetype == "text"),
|
|
450
|
+
tolerance=optiondict["spatialtolerance"],
|
|
451
|
+
debug=optiondict["focaldebug"],
|
|
452
|
+
)
|
|
516
453
|
)
|
|
517
454
|
if internalinvbrainmask is not None:
|
|
518
|
-
if
|
|
519
|
-
|
|
455
|
+
if internalinitregressorexcludemask is not None:
|
|
456
|
+
internalinitregressorexcludemask *= internalinvbrainmask
|
|
520
457
|
else:
|
|
521
|
-
|
|
458
|
+
internalinitregressorexcludemask = internalinvbrainmask
|
|
522
459
|
|
|
523
460
|
internalrefineincludemask, internalrefineexcludemask, dummy = tide_mask.getmaskset(
|
|
524
461
|
"refine",
|
|
@@ -530,6 +467,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
530
467
|
numspatiallocs,
|
|
531
468
|
istext=(theinputdata.filetype == "text"),
|
|
532
469
|
tolerance=optiondict["spatialtolerance"],
|
|
470
|
+
debug=optiondict["focaldebug"],
|
|
533
471
|
)
|
|
534
472
|
if internalinvbrainmask is not None:
|
|
535
473
|
if internalrefineexcludemask is not None:
|
|
@@ -547,6 +485,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
547
485
|
numspatiallocs,
|
|
548
486
|
istext=(theinputdata.filetype == "text"),
|
|
549
487
|
tolerance=optiondict["spatialtolerance"],
|
|
488
|
+
debug=optiondict["focaldebug"],
|
|
550
489
|
)
|
|
551
490
|
if internalinvbrainmask is not None:
|
|
552
491
|
if internaloffsetexcludemask is not None:
|
|
@@ -568,6 +507,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
568
507
|
valslist=optiondict["corrmaskincludevals"],
|
|
569
508
|
maskname="correlation",
|
|
570
509
|
tolerance=optiondict["spatialtolerance"],
|
|
510
|
+
debug=optiondict["focaldebug"],
|
|
571
511
|
)
|
|
572
512
|
|
|
573
513
|
corrmask = np.uint16(np.where(thecorrmask > 0, 1, 0).reshape(numspatiallocs))
|
|
@@ -604,8 +544,8 @@ def rapidtide_main(argparsingfunc):
|
|
|
604
544
|
np.std(fmri_data, axis=1), threshpct=optiondict["corrmaskthreshpct"]
|
|
605
545
|
)
|
|
606
546
|
)
|
|
607
|
-
|
|
608
|
-
|
|
547
|
+
if internalbrainmask is not None:
|
|
548
|
+
corrmask = internalbrainmask
|
|
609
549
|
if tide_stats.getmasksize(corrmask) == 0:
|
|
610
550
|
raise ValueError("ERROR: there are no voxels in the correlation mask - exiting")
|
|
611
551
|
|
|
@@ -710,7 +650,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
710
650
|
),
|
|
711
651
|
labels=["xtrans", "ytrans", "ztrans", "xrot", "yrot", "zrot"],
|
|
712
652
|
deriv=optiondict["mot_deriv"],
|
|
713
|
-
order=
|
|
653
|
+
order=optiondict["mot_power"],
|
|
714
654
|
)
|
|
715
655
|
domotion = True
|
|
716
656
|
else:
|
|
@@ -753,7 +693,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
753
693
|
append=False,
|
|
754
694
|
)
|
|
755
695
|
|
|
756
|
-
if optiondict["
|
|
696
|
+
if optiondict["debug"]:
|
|
757
697
|
print(f"{mergedregressors.shape=}")
|
|
758
698
|
print(f"{mergedregressorlabels}")
|
|
759
699
|
print(f"{fmri_data_valid.shape=}")
|
|
@@ -880,15 +820,86 @@ def rapidtide_main(argparsingfunc):
|
|
|
880
820
|
meanfreq = 1.0 / fmritr
|
|
881
821
|
meanperiod = 1.0 * fmritr
|
|
882
822
|
meanstarttime = 0.0
|
|
883
|
-
meanvec, meanmask =
|
|
823
|
+
meanvec, meanmask = tide_mask.saveregionaltimeseries(
|
|
824
|
+
"initial regressor",
|
|
825
|
+
"startregressormask",
|
|
884
826
|
fmri_data,
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
827
|
+
internalinitregressorincludemask,
|
|
828
|
+
meanfreq,
|
|
829
|
+
outputname,
|
|
830
|
+
initfile=True,
|
|
831
|
+
signalgenmethod=optiondict["initregressorsignalmethod"],
|
|
832
|
+
pcacomponents=optiondict["initregressorpcacomponents"],
|
|
833
|
+
excludemask=internalinitregressorexcludemask,
|
|
834
|
+
filedesc="regionalprefilter",
|
|
835
|
+
suffix="",
|
|
836
|
+
debug=optiondict["debug"],
|
|
890
837
|
)
|
|
891
838
|
|
|
839
|
+
if brainmask is not None:
|
|
840
|
+
brainvec, dummy = tide_mask.saveregionaltimeseries(
|
|
841
|
+
"whole brain",
|
|
842
|
+
"brain",
|
|
843
|
+
fmri_data,
|
|
844
|
+
internalbrainmask,
|
|
845
|
+
meanfreq,
|
|
846
|
+
outputname,
|
|
847
|
+
filedesc="regionalprefilter",
|
|
848
|
+
suffix="",
|
|
849
|
+
debug=optiondict["debug"],
|
|
850
|
+
)
|
|
851
|
+
|
|
852
|
+
if graymask is None:
|
|
853
|
+
internalgraymask = None
|
|
854
|
+
else:
|
|
855
|
+
internalgraymask = graymask.reshape((numspatiallocs))
|
|
856
|
+
grayvec, dummy = tide_mask.saveregionaltimeseries(
|
|
857
|
+
"gray matter",
|
|
858
|
+
"GM",
|
|
859
|
+
fmri_data,
|
|
860
|
+
internalgraymask,
|
|
861
|
+
meanfreq,
|
|
862
|
+
outputname,
|
|
863
|
+
excludemask=internalinvbrainmask,
|
|
864
|
+
filedesc="regionalprefilter",
|
|
865
|
+
suffix="",
|
|
866
|
+
debug=optiondict["debug"],
|
|
867
|
+
)
|
|
868
|
+
|
|
869
|
+
if whitemask is None:
|
|
870
|
+
internalwhitemask = None
|
|
871
|
+
else:
|
|
872
|
+
internalwhitemask = whitemask.reshape((numspatiallocs))
|
|
873
|
+
whitevec, dummy = tide_mask.saveregionaltimeseries(
|
|
874
|
+
"white matter",
|
|
875
|
+
"WM",
|
|
876
|
+
fmri_data,
|
|
877
|
+
internalwhitemask,
|
|
878
|
+
meanfreq,
|
|
879
|
+
outputname,
|
|
880
|
+
excludemask=internalinvbrainmask,
|
|
881
|
+
filedesc="regionalprefilter",
|
|
882
|
+
suffix="",
|
|
883
|
+
debug=optiondict["debug"],
|
|
884
|
+
)
|
|
885
|
+
|
|
886
|
+
if csfmask is None:
|
|
887
|
+
internalcsfmask = None
|
|
888
|
+
else:
|
|
889
|
+
internalcsfmask = csfmask.reshape((numspatiallocs))
|
|
890
|
+
csfvec, dummy = tide_mask.saveregionaltimeseries(
|
|
891
|
+
"CSF",
|
|
892
|
+
"CSF",
|
|
893
|
+
fmri_data,
|
|
894
|
+
internalcsfmask,
|
|
895
|
+
meanfreq,
|
|
896
|
+
outputname,
|
|
897
|
+
excludemask=internalinvbrainmask,
|
|
898
|
+
filedesc="regionalprefilter",
|
|
899
|
+
suffix="",
|
|
900
|
+
debug=optiondict["debug"],
|
|
901
|
+
)
|
|
902
|
+
|
|
892
903
|
# get rid of more memory we aren't using
|
|
893
904
|
theinputdata.unload()
|
|
894
905
|
uncollected = gc.collect()
|
|
@@ -903,12 +914,12 @@ def rapidtide_main(argparsingfunc):
|
|
|
903
914
|
TimingLGR.info("Start of reference prep")
|
|
904
915
|
if regressorfilename is None:
|
|
905
916
|
LGR.info("no regressor file specified - will use the global mean regressor")
|
|
906
|
-
optiondict["
|
|
917
|
+
optiondict["useinitregressorref"] = True
|
|
907
918
|
else:
|
|
908
|
-
optiondict["
|
|
919
|
+
optiondict["useinitregressorref"] = False
|
|
909
920
|
|
|
910
921
|
# now set the regressor that we'll use
|
|
911
|
-
if optiondict["
|
|
922
|
+
if optiondict["useinitregressorref"]:
|
|
912
923
|
LGR.verbose("using global mean as probe regressor")
|
|
913
924
|
inputfreq = meanfreq
|
|
914
925
|
inputperiod = meanperiod
|
|
@@ -917,7 +928,9 @@ def rapidtide_main(argparsingfunc):
|
|
|
917
928
|
|
|
918
929
|
# save the meanmask
|
|
919
930
|
theheader = theinputdata.copyheader(numtimepoints=1)
|
|
920
|
-
masklist = [
|
|
931
|
+
masklist = [
|
|
932
|
+
(meanmask, "initregressor", "mask", None, "Voxels used to calculate initial regressor")
|
|
933
|
+
]
|
|
921
934
|
tide_io.savemaplist(
|
|
922
935
|
outputname,
|
|
923
936
|
masklist,
|
|
@@ -968,7 +981,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
968
981
|
LGR.verbose(f"input freq: {inputfreq}")
|
|
969
982
|
LGR.verbose(f"input start time: {inputstarttime:.3f}")
|
|
970
983
|
|
|
971
|
-
if not optiondict["
|
|
984
|
+
if not optiondict["useinitregressorref"]:
|
|
972
985
|
globalcorrx, globalcorry, dummy, dummy = tide_corr.arbcorr(
|
|
973
986
|
meanvec, meanfreq, inputvec, inputfreq, start2=(inputstarttime)
|
|
974
987
|
)
|
|
@@ -1253,6 +1266,10 @@ def rapidtide_main(argparsingfunc):
|
|
|
1253
1266
|
corrpadding=optiondict["corrpadding"],
|
|
1254
1267
|
debug=optiondict["debug"],
|
|
1255
1268
|
)
|
|
1269
|
+
if optiondict["focaldebug"]:
|
|
1270
|
+
print(
|
|
1271
|
+
f"calling setreftc during initialization with length {optiondict['oversampfactor'] * validtimepoints}"
|
|
1272
|
+
)
|
|
1256
1273
|
theCorrelator.setreftc(
|
|
1257
1274
|
np.zeros((optiondict["oversampfactor"] * validtimepoints), dtype=np.float64)
|
|
1258
1275
|
)
|
|
@@ -1452,7 +1469,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
1452
1469
|
# prepare for regressor refinement, if we're doing it
|
|
1453
1470
|
if (
|
|
1454
1471
|
optiondict["passes"] > 1
|
|
1455
|
-
or optiondict["
|
|
1472
|
+
or optiondict["initregressorpreselect"]
|
|
1456
1473
|
or optiondict["dofinalrefine"]
|
|
1457
1474
|
or optiondict["convergencethresh"] is not None
|
|
1458
1475
|
):
|
|
@@ -1667,6 +1684,10 @@ def rapidtide_main(argparsingfunc):
|
|
|
1667
1684
|
rt_floattype=rt_floattype,
|
|
1668
1685
|
rt_floatset=rt_floatset,
|
|
1669
1686
|
)
|
|
1687
|
+
if optiondict["focaldebug"]:
|
|
1688
|
+
print(
|
|
1689
|
+
f"after cleanregressor: {len(referencetc)=}, {len(cleaned_referencetc)=}, {osvalidsimcalcstart=}, {osvalidsimcalcend=}, {lagmininpts=}, {lagmaxinpts=}"
|
|
1690
|
+
)
|
|
1670
1691
|
|
|
1671
1692
|
# Step 0 - estimate significance
|
|
1672
1693
|
if optiondict["numestreps"] > 0:
|
|
@@ -1694,6 +1715,10 @@ def rapidtide_main(argparsingfunc):
|
|
|
1694
1715
|
f"{outputname}_options_pregetnull_pass" + str(thepass) + ".json",
|
|
1695
1716
|
)
|
|
1696
1717
|
theCorrelator.setlimits(lagmininpts, lagmaxinpts)
|
|
1718
|
+
if optiondict["focaldebug"]:
|
|
1719
|
+
print(
|
|
1720
|
+
f"calling setreftc prior to significance estimation with length {len(cleaned_resampref_y)}"
|
|
1721
|
+
)
|
|
1697
1722
|
theCorrelator.setreftc(cleaned_resampref_y)
|
|
1698
1723
|
theMutualInformationator.setlimits(lagmininpts, lagmaxinpts)
|
|
1699
1724
|
theMutualInformationator.setreftc(cleaned_resampref_y)
|
|
@@ -1861,6 +1886,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
1861
1886
|
chunksize=optiondict["mp_chunksize"],
|
|
1862
1887
|
rt_floatset=rt_floatset,
|
|
1863
1888
|
rt_floattype=rt_floattype,
|
|
1889
|
+
debug=optiondict["focaldebug"],
|
|
1864
1890
|
)
|
|
1865
1891
|
else:
|
|
1866
1892
|
(
|
|
@@ -1885,6 +1911,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
1885
1911
|
chunksize=optiondict["mp_chunksize"],
|
|
1886
1912
|
rt_floatset=rt_floatset,
|
|
1887
1913
|
rt_floattype=rt_floattype,
|
|
1914
|
+
debug=optiondict["focaldebug"],
|
|
1888
1915
|
)
|
|
1889
1916
|
tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
|
|
1890
1917
|
|
|
@@ -2303,7 +2330,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
2303
2330
|
if (
|
|
2304
2331
|
thepass < optiondict["passes"]
|
|
2305
2332
|
or optiondict["convergencethresh"] is not None
|
|
2306
|
-
or optiondict["
|
|
2333
|
+
or optiondict["initregressorpreselect"]
|
|
2307
2334
|
or optiondict["dofinalrefine"]
|
|
2308
2335
|
):
|
|
2309
2336
|
LGR.info(f"\n\nRegressor refinement, pass {thepass}")
|
|
@@ -2319,7 +2346,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
2319
2346
|
LGR.warning(
|
|
2320
2347
|
"NB: cannot exclude voxels from offset calculation mask - including for this pass"
|
|
2321
2348
|
)
|
|
2322
|
-
offsetmask = fitmask
|
|
2349
|
+
offsetmask = fitmask + 0
|
|
2323
2350
|
|
|
2324
2351
|
peaklag, dummy, dummy = tide_stats.gethistprops(
|
|
2325
2352
|
lagtimes[np.where(offsetmask > 0)],
|
|
@@ -2420,7 +2447,34 @@ def rapidtide_main(argparsingfunc):
|
|
|
2420
2447
|
)
|
|
2421
2448
|
for key, value in outputdict.items():
|
|
2422
2449
|
optiondict[key] = value
|
|
2423
|
-
|
|
2450
|
+
|
|
2451
|
+
# Save shifted timecourses for César
|
|
2452
|
+
if optiondict["saveintermediatemaps"] and optiondict["savelagregressors"]:
|
|
2453
|
+
theheader = theinputdata.copyheader()
|
|
2454
|
+
bidspasssuffix = f"_intermediatedata-pass{thepass}"
|
|
2455
|
+
maplist = [
|
|
2456
|
+
(
|
|
2457
|
+
(theRegressorRefiner.getpaddedshiftedtcs())[:, numpadtrs:-numpadtrs],
|
|
2458
|
+
"shiftedtcs",
|
|
2459
|
+
"bold",
|
|
2460
|
+
None,
|
|
2461
|
+
"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.",
|
|
2462
|
+
),
|
|
2463
|
+
]
|
|
2464
|
+
tide_io.savemaplist(
|
|
2465
|
+
f"{outputname}{bidspasssuffix}",
|
|
2466
|
+
maplist,
|
|
2467
|
+
validvoxels,
|
|
2468
|
+
nativefmrishape,
|
|
2469
|
+
theheader,
|
|
2470
|
+
bidsbasedict,
|
|
2471
|
+
filetype=theinputdata.filetype,
|
|
2472
|
+
rt_floattype=rt_floattype,
|
|
2473
|
+
cifti_hdr=theinputdata.cifti_hdr,
|
|
2474
|
+
debug=True,
|
|
2475
|
+
)
|
|
2476
|
+
# We are done with refinement.
|
|
2477
|
+
# End of main pass loop
|
|
2424
2478
|
|
|
2425
2479
|
if optiondict["convergencethresh"] is None:
|
|
2426
2480
|
optiondict["actual_passes"] = optiondict["passes"]
|
|
@@ -2974,6 +3028,79 @@ def rapidtide_main(argparsingfunc):
|
|
|
2974
3028
|
"message3": "voxels",
|
|
2975
3029
|
},
|
|
2976
3030
|
)
|
|
3031
|
+
if internalinitregressorincludemask is not None:
|
|
3032
|
+
thisincludemask = internalinitregressorincludemask[validvoxels]
|
|
3033
|
+
else:
|
|
3034
|
+
thisincludemask = None
|
|
3035
|
+
if internalinitregressorexcludemask is not None:
|
|
3036
|
+
thisexcludemask = internalinitregressorexcludemask[validvoxels]
|
|
3037
|
+
else:
|
|
3038
|
+
thisexcludemask = None
|
|
3039
|
+
|
|
3040
|
+
meanvec, meanmask = tide_mask.saveregionaltimeseries(
|
|
3041
|
+
"initial regressor",
|
|
3042
|
+
"startregressormask",
|
|
3043
|
+
filtereddata,
|
|
3044
|
+
thisincludemask,
|
|
3045
|
+
meanfreq,
|
|
3046
|
+
outputname,
|
|
3047
|
+
initfile=True,
|
|
3048
|
+
excludemask=thisexcludemask,
|
|
3049
|
+
filedesc="regionalpostfilter",
|
|
3050
|
+
suffix="",
|
|
3051
|
+
debug=optiondict["debug"],
|
|
3052
|
+
)
|
|
3053
|
+
if brainmask is not None:
|
|
3054
|
+
brainvec, dummy = tide_mask.saveregionaltimeseries(
|
|
3055
|
+
"whole brain",
|
|
3056
|
+
"brain",
|
|
3057
|
+
filtereddata,
|
|
3058
|
+
internalbrainmask[validvoxels],
|
|
3059
|
+
meanfreq,
|
|
3060
|
+
outputname,
|
|
3061
|
+
filedesc="regionalpostfilter",
|
|
3062
|
+
suffix="",
|
|
3063
|
+
debug=optiondict["debug"],
|
|
3064
|
+
)
|
|
3065
|
+
if graymask is not None:
|
|
3066
|
+
grayvec, dummy = tide_mask.saveregionaltimeseries(
|
|
3067
|
+
"gray matter",
|
|
3068
|
+
"GM",
|
|
3069
|
+
filtereddata,
|
|
3070
|
+
internalgraymask[validvoxels],
|
|
3071
|
+
meanfreq,
|
|
3072
|
+
outputname,
|
|
3073
|
+
excludemask=internalinvbrainmask[validvoxels],
|
|
3074
|
+
filedesc="regionalpostfilter",
|
|
3075
|
+
suffix="",
|
|
3076
|
+
debug=optiondict["debug"],
|
|
3077
|
+
)
|
|
3078
|
+
if whitemask is not None:
|
|
3079
|
+
whitevec, dummy = tide_mask.saveregionaltimeseries(
|
|
3080
|
+
"white matter",
|
|
3081
|
+
"WM",
|
|
3082
|
+
filtereddata,
|
|
3083
|
+
internalwhitemask[validvoxels],
|
|
3084
|
+
meanfreq,
|
|
3085
|
+
outputname,
|
|
3086
|
+
excludemask=internalinvbrainmask[validvoxels],
|
|
3087
|
+
filedesc="regionalpostfilter",
|
|
3088
|
+
suffix="",
|
|
3089
|
+
debug=optiondict["debug"],
|
|
3090
|
+
)
|
|
3091
|
+
if csfmask is not None:
|
|
3092
|
+
grayvec, dummy = tide_mask.saveregionaltimeseries(
|
|
3093
|
+
"CSF",
|
|
3094
|
+
"CSF",
|
|
3095
|
+
filtereddata,
|
|
3096
|
+
internalcsfmask[validvoxels],
|
|
3097
|
+
meanfreq,
|
|
3098
|
+
outputname,
|
|
3099
|
+
excludemask=internalinvbrainmask[validvoxels],
|
|
3100
|
+
filedesc="regionalpostfilter",
|
|
3101
|
+
suffix="",
|
|
3102
|
+
debug=optiondict["debug"],
|
|
3103
|
+
)
|
|
2977
3104
|
tide_util.logmem("after sLFO filter")
|
|
2978
3105
|
LGR.info("")
|
|
2979
3106
|
else:
|
|
@@ -3336,7 +3463,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
3336
3463
|
cifti_hdr=theinputdata.cifti_hdr,
|
|
3337
3464
|
)
|
|
3338
3465
|
|
|
3339
|
-
if optiondict["refinedelay"]
|
|
3466
|
+
if optiondict["refinedelay"]:
|
|
3340
3467
|
# filter the fmri data to the lfo band
|
|
3341
3468
|
print("filtering fmri_data to sLFO band")
|
|
3342
3469
|
for i in range(fmri_data_valid.shape[0]):
|
|
@@ -3377,7 +3504,13 @@ def rapidtide_main(argparsingfunc):
|
|
|
3377
3504
|
)
|
|
3378
3505
|
|
|
3379
3506
|
maplist = [
|
|
3380
|
-
(
|
|
3507
|
+
(
|
|
3508
|
+
rvalue,
|
|
3509
|
+
"maxcorrrefined",
|
|
3510
|
+
"map",
|
|
3511
|
+
None,
|
|
3512
|
+
"R value of the inband sLFO fit, with sign",
|
|
3513
|
+
),
|
|
3381
3514
|
]
|
|
3382
3515
|
|
|
3383
3516
|
tide_io.savemaplist(
|
|
@@ -3423,6 +3556,8 @@ def rapidtide_main(argparsingfunc):
|
|
|
3423
3556
|
maplist.append((graymask, "GM", "mask", None, "Gray matter mask"))
|
|
3424
3557
|
if whitemask is not None:
|
|
3425
3558
|
maplist.append((whitemask, "WM", "mask", None, "White matter mask"))
|
|
3559
|
+
if csfmask is not None:
|
|
3560
|
+
maplist.append((csfmask, "CSF", "mask", None, "CSF mask"))
|
|
3426
3561
|
tide_io.savemaplist(
|
|
3427
3562
|
outputname,
|
|
3428
3563
|
maplist,
|
|
@@ -3474,15 +3609,15 @@ def rapidtide_main(argparsingfunc):
|
|
|
3474
3609
|
)
|
|
3475
3610
|
del masklist
|
|
3476
3611
|
|
|
3477
|
-
if (optiondict["passes"] > 1 or optiondict["
|
|
3612
|
+
if (optiondict["passes"] > 1 or optiondict["initregressorpreselect"]) and optiondict[
|
|
3478
3613
|
"refinestopreason"
|
|
3479
3614
|
] != "emptymask":
|
|
3480
3615
|
refinemask = theRegressorRefiner.getrefinemask()
|
|
3481
|
-
if optiondict["
|
|
3616
|
+
if optiondict["initregressorpreselect"]:
|
|
3482
3617
|
masklist = [
|
|
3483
3618
|
(
|
|
3484
3619
|
refinemask,
|
|
3485
|
-
"
|
|
3620
|
+
"initregressorpreselect",
|
|
3486
3621
|
"mask",
|
|
3487
3622
|
None,
|
|
3488
3623
|
"I really don't know what this file is for",
|
|
@@ -3511,7 +3646,11 @@ def rapidtide_main(argparsingfunc):
|
|
|
3511
3646
|
del fitmask
|
|
3512
3647
|
|
|
3513
3648
|
# now do the 4D maps of the similarity function and friends
|
|
3514
|
-
theheader = theinputdata.copyheader(
|
|
3649
|
+
theheader = theinputdata.copyheader(
|
|
3650
|
+
numtimepoints=np.shape(outcorrarray)[1],
|
|
3651
|
+
tr=corrtr,
|
|
3652
|
+
toffset=(corrscale[corrorigin - lagmininpts]),
|
|
3653
|
+
)
|
|
3515
3654
|
if (
|
|
3516
3655
|
optiondict["savecorrout"]
|
|
3517
3656
|
or (optiondict["outputlevel"] != "min")
|
|
@@ -187,8 +187,10 @@ def rapidtide2std(args):
|
|
|
187
187
|
|
|
188
188
|
thefmrimaps = [
|
|
189
189
|
"desc-maxtime_map",
|
|
190
|
+
"desc-maxtimerefined_map",
|
|
190
191
|
"desc-timepercentile_map",
|
|
191
192
|
"desc-maxcorr_map",
|
|
193
|
+
"desc-maxcorrrefined_map",
|
|
192
194
|
"desc-maxwidth_map",
|
|
193
195
|
"desc-MTT_map",
|
|
194
196
|
"desc-corrfit_mask",
|