rapidtide 3.0a11__py3-none-any.whl → 3.0a13__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/rapidtide-HCPYA +3 -3
- rapidtide/Colortables.py +10 -10
- rapidtide/DerivativeDelay.py +211 -0
- rapidtide/RegressorRefiner.py +464 -0
- rapidtide/__init__.py +2 -1
- rapidtide/_version.py +1 -1
- rapidtide/data/examples/src/test_mlregressallt.py +32 -17
- rapidtide/data/examples/src/testalign +1 -1
- rapidtide/data/examples/src/testboth +1 -1
- rapidtide/data/examples/src/testcifti +11 -0
- rapidtide/data/examples/src/testdelayvar +13 -0
- rapidtide/data/examples/src/testfmri +3 -124
- rapidtide/data/examples/src/testglmfilt +8 -6
- rapidtide/data/examples/src/testhappy +1 -1
- rapidtide/data/examples/src/testinitdelay +19 -0
- rapidtide/data/examples/src/testnewrefine +49 -0
- rapidtide/data/examples/src/testnoiseamp +2 -2
- rapidtide/data/examples/src/testrefineonly +22 -0
- rapidtide/data/examples/src/testretro +16 -7
- rapidtide/data/examples/src/testretrolagtcs +1 -1
- rapidtide/dlfilter.py +0 -1
- rapidtide/fit.py +41 -9
- rapidtide/happy_supportfuncs.py +5 -0
- rapidtide/io.py +13 -2
- rapidtide/{glmpass.py → linfitfiltpass.py} +29 -20
- rapidtide/refinedelay.py +133 -55
- rapidtide/refineregressor.py +38 -24
- rapidtide/resample.py +3 -0
- rapidtide/scripts/{retroglm.py → delayvar.py} +2 -2
- rapidtide/scripts/{glmfilt.py → linfitfilt.py} +2 -2
- rapidtide/scripts/retroregress.py +28 -0
- rapidtide/scripts/stupidramtricks.py +9 -7
- rapidtide/simfuncfit.py +1 -1
- rapidtide/tests/cleanposttest +21 -0
- rapidtide/tests/test_delayestimation.py +3 -3
- rapidtide/tests/test_fastresampler.py +1 -2
- rapidtide/tests/test_fullrunhappy_v1.py +1 -1
- rapidtide/tests/test_fullrunhappy_v2.py +1 -1
- rapidtide/tests/test_fullrunrapidtide_v1.py +2 -2
- rapidtide/tests/test_fullrunrapidtide_v3.py +1 -1
- rapidtide/tests/test_fullrunrapidtide_v5.py +1 -1
- rapidtide/tests/test_fullrunrapidtide_v6.py +11 -11
- rapidtide/tests/{test_glmpass.py → test_linfitfiltpass.py} +9 -9
- rapidtide/tests/test_motionregress.py +3 -3
- rapidtide/tests/test_refinedelay.py +12 -12
- rapidtide/tidepoolTemplate.py +1 -0
- rapidtide/tidepoolTemplate.ui +1 -0
- rapidtide/tidepoolTemplate_alt.py +5 -4
- rapidtide/tidepoolTemplate_alt.ui +3 -2
- rapidtide/tidepoolTemplate_alt_qt6.py +177 -49
- rapidtide/tidepoolTemplate_big.py +1 -0
- rapidtide/tidepoolTemplate_big.ui +1 -0
- rapidtide/tidepoolTemplate_big_qt6.py +197 -53
- rapidtide/tidepoolTemplate_qt6.py +151 -39
- rapidtide/workflows/delayvar.py +1048 -0
- rapidtide/workflows/happy.py +37 -11
- rapidtide/workflows/happy_parser.py +4 -4
- rapidtide/workflows/{glmfilt.py → linfitfilt.py} +4 -4
- rapidtide/workflows/parser_funcs.py +10 -2
- rapidtide/workflows/rapidtide.py +388 -452
- rapidtide/workflows/rapidtide_parser.py +129 -90
- rapidtide/workflows/{glmfrommaps.py → regressfrommaps.py} +28 -26
- rapidtide/workflows/retrolagtcs.py +12 -12
- rapidtide/workflows/{retroglm.py → retroregress.py} +243 -141
- rapidtide/workflows/tidepool.py +2 -2
- {rapidtide-3.0a11.dist-info → rapidtide-3.0a13.dist-info}/METADATA +3 -2
- {rapidtide-3.0a11.dist-info → rapidtide-3.0a13.dist-info}/RECORD +72 -63
- {rapidtide-3.0a11.dist-info → rapidtide-3.0a13.dist-info}/WHEEL +1 -1
- {rapidtide-3.0a11.dist-info → rapidtide-3.0a13.dist-info}/entry_points.txt +3 -2
- rapidtide/data/examples/src/testoutputsize +0 -45
- {rapidtide-3.0a11.dist-info → rapidtide-3.0a13.dist-info/licenses}/LICENSE +0 -0
- {rapidtide-3.0a11.dist-info → rapidtide-3.0a13.dist-info}/top_level.txt +0 -0
|
@@ -34,9 +34,10 @@ import rapidtide.refinedelay as tide_refinedelay
|
|
|
34
34
|
import rapidtide.resample as tide_resample
|
|
35
35
|
import rapidtide.stats as tide_stats
|
|
36
36
|
import rapidtide.util as tide_util
|
|
37
|
-
import rapidtide.workflows.glmfrommaps as tide_glmfrommaps
|
|
38
37
|
import rapidtide.workflows.parser_funcs as pf
|
|
38
|
+
import rapidtide.workflows.regressfrommaps as tide_regressfrommaps
|
|
39
39
|
|
|
40
|
+
from .rapidtide_parser import DEFAULT_REGRESSIONFILTDERIVS
|
|
40
41
|
from .utils import setup_logger
|
|
41
42
|
|
|
42
43
|
|
|
@@ -51,12 +52,13 @@ LGR = logging.getLogger(__name__)
|
|
|
51
52
|
ErrorLGR = logging.getLogger("ERROR")
|
|
52
53
|
TimingLGR = logging.getLogger("TIMING")
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
DEFAULT_REGRESSIONFILTDERIVS = 0
|
|
55
56
|
DEFAULT_PATCHTHRESH = 3.0
|
|
56
57
|
DEFAULT_REFINEDELAYMINDELAY = -5.0
|
|
57
58
|
DEFAULT_REFINEDELAYMAXDELAY = 5.0
|
|
58
59
|
DEFAULT_REFINEDELAYNUMPOINTS = 501
|
|
59
60
|
DEFAULT_DELAYOFFSETSPATIALFILT = -1
|
|
61
|
+
DEFAULT_REFINEREGRESSDERIVS = 1
|
|
60
62
|
|
|
61
63
|
|
|
62
64
|
def _get_parser():
|
|
@@ -64,8 +66,8 @@ def _get_parser():
|
|
|
64
66
|
Argument parser for glmfilt
|
|
65
67
|
"""
|
|
66
68
|
parser = argparse.ArgumentParser(
|
|
67
|
-
prog="
|
|
68
|
-
description="Do the rapidtide
|
|
69
|
+
prog="retroregress",
|
|
70
|
+
description="Do the rapidtide sLFO filtering using the maps generated from a previous analysis.",
|
|
69
71
|
allow_abbrev=False,
|
|
70
72
|
)
|
|
71
73
|
|
|
@@ -88,15 +90,15 @@ def _get_parser():
|
|
|
88
90
|
default=None,
|
|
89
91
|
)
|
|
90
92
|
parser.add_argument(
|
|
91
|
-
"--
|
|
92
|
-
dest="
|
|
93
|
+
"--regressderivs",
|
|
94
|
+
dest="regressderivs",
|
|
93
95
|
action="store",
|
|
94
|
-
type=
|
|
96
|
+
type=lambda x: pf.is_int(parser, x, minval=0),
|
|
95
97
|
metavar="NDERIVS",
|
|
96
98
|
help=(
|
|
97
|
-
f"When doing final GLM, include derivatives up to NDERIVS order. Default is {
|
|
99
|
+
f"When doing final GLM, include derivatives up to NDERIVS order. Default is {DEFAULT_REGRESSIONFILTDERIVS}"
|
|
98
100
|
),
|
|
99
|
-
default=
|
|
101
|
+
default=DEFAULT_REGRESSIONFILTDERIVS,
|
|
100
102
|
)
|
|
101
103
|
parser.add_argument(
|
|
102
104
|
"--nprocs",
|
|
@@ -115,7 +117,7 @@ def _get_parser():
|
|
|
115
117
|
"--numskip",
|
|
116
118
|
dest="numskip",
|
|
117
119
|
action="store",
|
|
118
|
-
type=
|
|
120
|
+
type=lambda x: pf.is_int(parser, x, minval=0),
|
|
119
121
|
metavar="NUMSKIP",
|
|
120
122
|
help=("Skip NUMSKIP points at the beginning of the fmri file."),
|
|
121
123
|
default=0,
|
|
@@ -128,7 +130,7 @@ def _get_parser():
|
|
|
128
130
|
choices=["min", "less", "normal", "more", "max"],
|
|
129
131
|
help=(
|
|
130
132
|
"The level of file output produced. 'min' produces only absolutely essential files, 'less' adds in "
|
|
131
|
-
"the
|
|
133
|
+
"the sLFO filtered data (rather than just filter efficacy metrics), 'normal' saves what you "
|
|
132
134
|
"would typically want around for interactive data exploration, "
|
|
133
135
|
"'more' adds files that are sometimes useful, and 'max' outputs anything you might possibly want. "
|
|
134
136
|
"Selecting 'max' will produce ~3x your input datafile size as output. "
|
|
@@ -170,7 +172,7 @@ def _get_parser():
|
|
|
170
172
|
"--nofilterwithrefineddelay",
|
|
171
173
|
dest="filterwithrefineddelay",
|
|
172
174
|
action="store_false",
|
|
173
|
-
help=("Do not use the refined delay in
|
|
175
|
+
help=("Do not use the refined delay in sLFO filter."),
|
|
174
176
|
default=True,
|
|
175
177
|
)
|
|
176
178
|
parser.add_argument(
|
|
@@ -213,11 +215,26 @@ def _get_parser():
|
|
|
213
215
|
help=("Output lots of helpful information on a limited subset of operations."),
|
|
214
216
|
default=False,
|
|
215
217
|
)
|
|
218
|
+
experimental = parser.add_argument_group(
|
|
219
|
+
"Experimental options (not fully tested, or not tested at all, may not work). Beware!"
|
|
220
|
+
)
|
|
221
|
+
experimental.add_argument(
|
|
222
|
+
"--refineregressderivs",
|
|
223
|
+
dest="refineregressderivs",
|
|
224
|
+
action="store",
|
|
225
|
+
type=lambda x: pf.is_int(parser, x, minval=1),
|
|
226
|
+
metavar="NDERIVS",
|
|
227
|
+
help=(
|
|
228
|
+
f"When doing GLM for delay refinement, include derivatives up to NDERIVS order. Must be 1 or more. "
|
|
229
|
+
f"Default is {DEFAULT_REFINEREGRESSDERIVS}"
|
|
230
|
+
),
|
|
231
|
+
default=DEFAULT_REFINEREGRESSDERIVS,
|
|
232
|
+
)
|
|
216
233
|
|
|
217
234
|
return parser
|
|
218
235
|
|
|
219
236
|
|
|
220
|
-
def
|
|
237
|
+
def retroregress(args):
|
|
221
238
|
# get the pid of the parent process
|
|
222
239
|
args.pid = os.getpid()
|
|
223
240
|
|
|
@@ -242,7 +259,7 @@ def retroglm(args):
|
|
|
242
259
|
debug=args.debug,
|
|
243
260
|
)
|
|
244
261
|
TimingLGR.info("Start")
|
|
245
|
-
LGR.info(f"starting
|
|
262
|
+
LGR.info(f"starting retroregress")
|
|
246
263
|
|
|
247
264
|
# set some global values
|
|
248
265
|
args.mindelay = DEFAULT_REFINEDELAYMINDELAY
|
|
@@ -250,30 +267,30 @@ def retroglm(args):
|
|
|
250
267
|
args.numpoints = DEFAULT_REFINEDELAYNUMPOINTS
|
|
251
268
|
|
|
252
269
|
if args.outputlevel == "min":
|
|
253
|
-
args.
|
|
254
|
-
args.
|
|
270
|
+
args.saveminimumsLFOfiltfiles = False
|
|
271
|
+
args.savenormalsLFOfiltfiles = False
|
|
255
272
|
args.savemovingsignal = False
|
|
256
|
-
args.
|
|
273
|
+
args.saveallsLFOfiltfiles = False
|
|
257
274
|
elif args.outputlevel == "less":
|
|
258
|
-
args.
|
|
259
|
-
args.
|
|
275
|
+
args.saveminimumsLFOfiltfiles = True
|
|
276
|
+
args.savenormalsLFOfiltfiles = False
|
|
260
277
|
args.savemovingsignal = False
|
|
261
|
-
args.
|
|
278
|
+
args.saveallsLFOfiltfiles = False
|
|
262
279
|
elif args.outputlevel == "normal":
|
|
263
|
-
args.
|
|
264
|
-
args.
|
|
280
|
+
args.saveminimumsLFOfiltfiles = True
|
|
281
|
+
args.savenormalsLFOfiltfiles = True
|
|
265
282
|
args.savemovingsignal = False
|
|
266
|
-
args.
|
|
283
|
+
args.saveallsLFOfiltfiles = False
|
|
267
284
|
elif args.outputlevel == "more":
|
|
268
|
-
args.
|
|
269
|
-
args.
|
|
285
|
+
args.saveminimumsLFOfiltfiles = True
|
|
286
|
+
args.savenormalsLFOfiltfiles = True
|
|
270
287
|
args.savemovingsignal = True
|
|
271
|
-
args.
|
|
288
|
+
args.saveallsLFOfiltfiles = False
|
|
272
289
|
elif args.outputlevel == "max":
|
|
273
|
-
args.
|
|
274
|
-
args.
|
|
290
|
+
args.saveminimumsLFOfiltfiles = True
|
|
291
|
+
args.savenormalsLFOfiltfiles = True
|
|
275
292
|
args.savemovingsignal = True
|
|
276
|
-
args.
|
|
293
|
+
args.saveallsLFOfiltfiles = True
|
|
277
294
|
else:
|
|
278
295
|
print(f"illegal output level {args['outputlevel']}")
|
|
279
296
|
sys.exit()
|
|
@@ -288,12 +305,25 @@ def retroglm(args):
|
|
|
288
305
|
else:
|
|
289
306
|
usesharedmem = True
|
|
290
307
|
|
|
291
|
-
# read the runoptions file
|
|
308
|
+
# read the runoptions file, update if necessary
|
|
292
309
|
print("reading runoptions")
|
|
293
310
|
runoptionsfile = f"{args.datafileroot}_desc-runoptions_info"
|
|
294
311
|
therunoptions = tide_io.readoptionsfile(runoptionsfile)
|
|
312
|
+
sublist = (
|
|
313
|
+
("retroglmcompatible", "retroregresscompatible"),
|
|
314
|
+
("glmthreshval", "regressfiltthreshval"),
|
|
315
|
+
)
|
|
316
|
+
therunoptions["singleproc_regressionfilt"] = False
|
|
317
|
+
therunoptions["nprocs_regressionfilt"] = args.nprocs
|
|
318
|
+
for subpair in sublist:
|
|
319
|
+
try:
|
|
320
|
+
therunoptions[subpair[1]] = therunoptions[subpair[0]]
|
|
321
|
+
print(f"substituting {subpair[1]} for {subpair[0]} in runoptions")
|
|
322
|
+
except KeyError:
|
|
323
|
+
pass
|
|
324
|
+
|
|
295
325
|
try:
|
|
296
|
-
|
|
326
|
+
candoretroregress = therunoptions["retroregresscompatible"]
|
|
297
327
|
except KeyError:
|
|
298
328
|
print(
|
|
299
329
|
f"based on {runoptionsfile}, this rapidtide dataset does not support retrospective GLM calculation"
|
|
@@ -314,7 +344,7 @@ def retroglm(args):
|
|
|
314
344
|
else:
|
|
315
345
|
rt_outfloattype = "float32"
|
|
316
346
|
rt_outfloatset = np.float32
|
|
317
|
-
therunoptions["
|
|
347
|
+
therunoptions["saveminimumsLFOfiltfiles"] = args.saveminimumsLFOfiltfiles
|
|
318
348
|
|
|
319
349
|
# read the fmri input files
|
|
320
350
|
print("reading fmrifile")
|
|
@@ -347,7 +377,7 @@ def retroglm(args):
|
|
|
347
377
|
if not tide_io.checkspacematch(fmri_header, procmask_header):
|
|
348
378
|
raise ValueError("procmask dimensions do not match fmri dimensions")
|
|
349
379
|
procmask_spacebytime = procmask.reshape((numspatiallocs))
|
|
350
|
-
if args.debug
|
|
380
|
+
if args.debug:
|
|
351
381
|
print(f"{procmask_spacebytime.shape=}")
|
|
352
382
|
print(f"{tide_stats.getmasksize(procmask_spacebytime)=}")
|
|
353
383
|
|
|
@@ -364,7 +394,7 @@ def retroglm(args):
|
|
|
364
394
|
if not tide_io.checkspacematch(fmri_header, corrmask_header):
|
|
365
395
|
raise ValueError("corrmask dimensions do not match fmri dimensions")
|
|
366
396
|
corrmask_spacebytime = corrmask.reshape((numspatiallocs))
|
|
367
|
-
if args.debug
|
|
397
|
+
if args.debug:
|
|
368
398
|
print(f"{corrmask_spacebytime.shape=}")
|
|
369
399
|
print(f"{tide_stats.getmasksize(corrmask_spacebytime)=}")
|
|
370
400
|
|
|
@@ -426,19 +456,19 @@ def retroglm(args):
|
|
|
426
456
|
print("figuring out valid voxels")
|
|
427
457
|
validvoxels = np.where(procmask_spacebytime > 0)[0]
|
|
428
458
|
numvalidspatiallocs = np.shape(validvoxels)[0]
|
|
429
|
-
if args.debug
|
|
459
|
+
if args.debug:
|
|
430
460
|
print(f"{numvalidspatiallocs=}")
|
|
431
461
|
internalvalidspaceshape = numvalidspatiallocs
|
|
432
462
|
if args.refinedelay:
|
|
433
|
-
derivaxissize = np.max([
|
|
463
|
+
derivaxissize = np.max([args.refineregressderivs + 1, args.regressderivs + 1])
|
|
434
464
|
else:
|
|
435
|
-
derivaxissize = args.
|
|
465
|
+
derivaxissize = args.regressderivs + 1
|
|
436
466
|
internalvalidspaceshapederivs = (
|
|
437
467
|
internalvalidspaceshape,
|
|
438
468
|
derivaxissize,
|
|
439
469
|
)
|
|
440
470
|
internalvalidfmrishape = (numvalidspatiallocs, np.shape(initial_fmri_x)[0])
|
|
441
|
-
if args.debug
|
|
471
|
+
if args.debug:
|
|
442
472
|
print(f"validvoxels shape = {numvalidspatiallocs}")
|
|
443
473
|
print(f"internalvalidfmrishape shape = {internalvalidfmrishape}")
|
|
444
474
|
|
|
@@ -454,7 +484,9 @@ def retroglm(args):
|
|
|
454
484
|
if usesharedmem:
|
|
455
485
|
if args.debug:
|
|
456
486
|
print("allocating shared memory")
|
|
457
|
-
|
|
487
|
+
sLFOfitmean, sLFOfitmean_shm = tide_util.allocshared(
|
|
488
|
+
internalvalidspaceshape, rt_outfloatset
|
|
489
|
+
)
|
|
458
490
|
rvalue, rvalue_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
|
|
459
491
|
r2value, r2value_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
|
|
460
492
|
fitNorm, fitNorm_shm = tide_util.allocshared(internalvalidspaceshapederivs, rt_outfloatset)
|
|
@@ -472,7 +504,7 @@ def retroglm(args):
|
|
|
472
504
|
else:
|
|
473
505
|
if args.debug:
|
|
474
506
|
print("allocating memory")
|
|
475
|
-
|
|
507
|
+
sLFOfitmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
476
508
|
rvalue = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
477
509
|
r2value = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
478
510
|
fitNorm = np.zeros(internalvalidspaceshapederivs, dtype=rt_outfloattype)
|
|
@@ -483,7 +515,7 @@ def retroglm(args):
|
|
|
483
515
|
ramlocation = "locally"
|
|
484
516
|
|
|
485
517
|
totalbytes = (
|
|
486
|
-
|
|
518
|
+
sLFOfitmean.nbytes
|
|
487
519
|
+ rvalue.nbytes
|
|
488
520
|
+ r2value.nbytes
|
|
489
521
|
+ fitNorm.nbytes
|
|
@@ -502,12 +534,13 @@ def retroglm(args):
|
|
|
502
534
|
print(f"{outputname=}")
|
|
503
535
|
oversamptr = fmritr / oversampfactor
|
|
504
536
|
try:
|
|
505
|
-
threshval = therunoptions["
|
|
537
|
+
threshval = therunoptions["regressfiltthreshval"]
|
|
506
538
|
except KeyError:
|
|
507
539
|
threshval = 0.0
|
|
540
|
+
therunoptions["regressfiltthreshval"] = threshval
|
|
508
541
|
mode = "glm"
|
|
509
542
|
|
|
510
|
-
if args.debug
|
|
543
|
+
if args.debug:
|
|
511
544
|
print(f"{validvoxels.shape=}")
|
|
512
545
|
np.savetxt(f"{outputname}_validvoxels.txt", validvoxels)
|
|
513
546
|
|
|
@@ -539,7 +572,7 @@ def retroglm(args):
|
|
|
539
572
|
"inputdata",
|
|
540
573
|
"bold",
|
|
541
574
|
None,
|
|
542
|
-
"fMRI data that will be subjected to
|
|
575
|
+
"fMRI data that will be subjected to sLFO filtering",
|
|
543
576
|
),
|
|
544
577
|
]
|
|
545
578
|
tide_io.savemaplist(
|
|
@@ -566,7 +599,7 @@ def retroglm(args):
|
|
|
566
599
|
args.delayoffsetgausssigma = np.mean([xdim, ydim, slicedim]) / 2.0
|
|
567
600
|
|
|
568
601
|
TimingLGR.info("Refinement calibration start")
|
|
569
|
-
|
|
602
|
+
regressderivratios, regressrvalues = tide_refinedelay.getderivratios(
|
|
570
603
|
fmri_data_valid,
|
|
571
604
|
validvoxels,
|
|
572
605
|
initial_fmri_x,
|
|
@@ -576,57 +609,99 @@ def retroglm(args):
|
|
|
576
609
|
mode,
|
|
577
610
|
outputname,
|
|
578
611
|
oversamptr,
|
|
579
|
-
|
|
612
|
+
sLFOfitmean,
|
|
580
613
|
rvalue,
|
|
581
614
|
r2value,
|
|
582
|
-
fitNorm[:, :
|
|
583
|
-
fitcoeff[:, :
|
|
615
|
+
fitNorm[:, : (args.refineregressderivs + 1)],
|
|
616
|
+
fitcoeff[:, : (args.refineregressderivs + 1)],
|
|
584
617
|
movingsignal,
|
|
585
618
|
lagtc,
|
|
586
619
|
filtereddata,
|
|
587
620
|
LGR,
|
|
588
621
|
TimingLGR,
|
|
589
622
|
therunoptions,
|
|
623
|
+
regressderivs=args.refineregressderivs,
|
|
590
624
|
debug=args.debug,
|
|
591
625
|
)
|
|
592
626
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
627
|
+
if args.refineregressderivs == 1:
|
|
628
|
+
medfiltregressderivratios, filteredregressderivratios, delayoffsetMAD = (
|
|
629
|
+
tide_refinedelay.filterderivratios(
|
|
630
|
+
regressderivratios,
|
|
631
|
+
(xsize, ysize, numslices),
|
|
632
|
+
validvoxels,
|
|
633
|
+
(xdim, ydim, slicedim),
|
|
634
|
+
gausssigma=args.delayoffsetgausssigma,
|
|
635
|
+
patchthresh=args.delaypatchthresh,
|
|
636
|
+
fileiscifti=False,
|
|
637
|
+
textio=False,
|
|
638
|
+
rt_floattype=rt_floattype,
|
|
639
|
+
debug=args.debug,
|
|
640
|
+
)
|
|
641
|
+
)
|
|
642
|
+
|
|
643
|
+
# find the mapping of glm ratios to delays
|
|
644
|
+
tide_refinedelay.trainratiotooffset(
|
|
645
|
+
genlagtc,
|
|
646
|
+
initial_fmri_x,
|
|
647
|
+
outputname,
|
|
648
|
+
args.outputlevel,
|
|
649
|
+
mindelay=args.mindelay,
|
|
650
|
+
maxdelay=args.maxdelay,
|
|
651
|
+
numpoints=args.numpoints,
|
|
604
652
|
debug=args.debug,
|
|
605
653
|
)
|
|
606
|
-
|
|
654
|
+
TimingLGR.info("Refinement calibration end")
|
|
607
655
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
656
|
+
# now calculate the delay offsets
|
|
657
|
+
TimingLGR.info("Calculating delay offsets")
|
|
658
|
+
delayoffset = np.zeros_like(filteredregressderivratios)
|
|
659
|
+
if args.debug:
|
|
660
|
+
print(f"calculating delayoffsets for {filteredregressderivratios.shape[0]} voxels")
|
|
661
|
+
for i in range(filteredregressderivratios.shape[0]):
|
|
662
|
+
delayoffset[i] = tide_refinedelay.ratiotodelay(filteredregressderivratios[i])
|
|
663
|
+
"""delayoffset[i] = tide_refinedelay.coffstodelay(
|
|
664
|
+
np.asarray([filteredregressderivratios[i]]),
|
|
665
|
+
mindelay=args.mindelay,
|
|
666
|
+
maxdelay=args.maxdelay,
|
|
667
|
+
)"""
|
|
668
|
+
|
|
669
|
+
refinedvoxelstoreport = filteredregressderivratios.shape[0]
|
|
670
|
+
else:
|
|
671
|
+
medfiltregressderivratios = np.zeros_like(regressderivratios)
|
|
672
|
+
filteredregressderivratios = np.zeros_like(regressderivratios)
|
|
673
|
+
delayoffsetMAD = np.zeros(args.refineregressderivs, dtype=float)
|
|
674
|
+
for i in range(args.refineregressderivs):
|
|
675
|
+
(
|
|
676
|
+
medfiltregressderivratios[i, :],
|
|
677
|
+
filteredregressderivratios[i, :],
|
|
678
|
+
delayoffsetMAD[i],
|
|
679
|
+
) = tide_refinedelay.filterderivratios(
|
|
680
|
+
regressderivratios[i, :],
|
|
681
|
+
(xsize, ysize, numslices),
|
|
682
|
+
validvoxels,
|
|
683
|
+
(xdim, ydim, slicedim),
|
|
684
|
+
gausssigma=args.delayoffsetgausssigma,
|
|
685
|
+
patchthresh=args.delaypatchthresh,
|
|
686
|
+
fileiscifti=False,
|
|
687
|
+
textio=False,
|
|
688
|
+
rt_floattype=rt_floattype,
|
|
689
|
+
debug=args.debug,
|
|
690
|
+
)
|
|
691
|
+
|
|
692
|
+
# now calculate the delay offsets
|
|
693
|
+
delayoffset = np.zeros_like(filteredregressderivratios[0, :])
|
|
694
|
+
if args.debug:
|
|
695
|
+
print(f"calculating delayoffsets for {filteredregressderivratios.shape[1]} voxels")
|
|
696
|
+
for i in range(filteredregressderivratios.shape[1]):
|
|
697
|
+
delayoffset[i] = tide_refinedelay.coffstodelay(
|
|
698
|
+
filteredregressderivratios[:, i],
|
|
699
|
+
mindelay=args.mindelay,
|
|
700
|
+
maxdelay=args.maxdelay,
|
|
701
|
+
)
|
|
702
|
+
refinedvoxelstoreport = filteredregressderivratios.shape[1]
|
|
629
703
|
|
|
704
|
+
namesuffix = "_desc-delayoffset_hist"
|
|
630
705
|
tide_stats.makeandsavehistogram(
|
|
631
706
|
delayoffset,
|
|
632
707
|
therunoptions["histlen"],
|
|
@@ -641,7 +716,7 @@ def retroglm(args):
|
|
|
641
716
|
TimingLGR.info(
|
|
642
717
|
"Delay offset calculation done",
|
|
643
718
|
{
|
|
644
|
-
"message2":
|
|
719
|
+
"message2": refinedvoxelstoreport,
|
|
645
720
|
"message3": "voxels",
|
|
646
721
|
},
|
|
647
722
|
)
|
|
@@ -649,16 +724,15 @@ def retroglm(args):
|
|
|
649
724
|
# Delay refinement end
|
|
650
725
|
####################################################
|
|
651
726
|
|
|
652
|
-
# initialrawvariance = tide_math.imagevariance(fmri_data_valid, None, 1.0 / fmritr)
|
|
653
727
|
initialvariance = tide_math.imagevariance(fmri_data_valid, theprefilter, 1.0 / fmritr)
|
|
654
728
|
|
|
655
|
-
print("calling
|
|
656
|
-
TimingLGR.info("Starting
|
|
729
|
+
print("calling regressfrommaps")
|
|
730
|
+
TimingLGR.info("Starting sLFO filtering")
|
|
657
731
|
if args.refinedelay and args.filterwithrefineddelay:
|
|
658
732
|
lagstouse_valid = lagtimesrefined_valid
|
|
659
733
|
else:
|
|
660
734
|
lagstouse_valid = lagtimes_valid
|
|
661
|
-
|
|
735
|
+
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
662
736
|
fmri_data_valid,
|
|
663
737
|
validvoxels,
|
|
664
738
|
initial_fmri_x,
|
|
@@ -668,29 +742,29 @@ def retroglm(args):
|
|
|
668
742
|
mode,
|
|
669
743
|
outputname,
|
|
670
744
|
oversamptr,
|
|
671
|
-
|
|
745
|
+
sLFOfitmean,
|
|
672
746
|
rvalue,
|
|
673
747
|
r2value,
|
|
674
|
-
fitNorm[:, : args.
|
|
675
|
-
fitcoeff[:, : args.
|
|
748
|
+
fitNorm[:, : args.regressderivs + 1],
|
|
749
|
+
fitcoeff[:, : args.regressderivs + 1],
|
|
676
750
|
movingsignal,
|
|
677
751
|
lagtc,
|
|
678
752
|
filtereddata,
|
|
679
753
|
LGR,
|
|
680
754
|
TimingLGR,
|
|
681
755
|
threshval,
|
|
682
|
-
args.
|
|
756
|
+
args.saveminimumsLFOfiltfiles,
|
|
683
757
|
nprocs_makelaggedtcs=args.nprocs,
|
|
684
|
-
|
|
685
|
-
|
|
758
|
+
nprocs_regressionfilt=args.nprocs,
|
|
759
|
+
regressderivs=args.regressderivs,
|
|
686
760
|
showprogressbar=args.showprogressbar,
|
|
687
761
|
debug=args.debug,
|
|
688
762
|
)
|
|
689
|
-
print(f"filtered {
|
|
763
|
+
print(f"filtered {voxelsprocessed_regressionfilt} voxels")
|
|
690
764
|
TimingLGR.info(
|
|
691
|
-
"
|
|
765
|
+
"sLFO filtering done",
|
|
692
766
|
{
|
|
693
|
-
"message2":
|
|
767
|
+
"message2": voxelsprocessed_regressionfilt,
|
|
694
768
|
"message3": "voxels",
|
|
695
769
|
},
|
|
696
770
|
)
|
|
@@ -753,7 +827,7 @@ def retroglm(args):
|
|
|
753
827
|
# "Change in total variance after filtering, in percent",
|
|
754
828
|
# ),
|
|
755
829
|
]
|
|
756
|
-
if args.
|
|
830
|
+
if args.saveminimumsLFOfiltfiles:
|
|
757
831
|
maplist += [
|
|
758
832
|
(
|
|
759
833
|
r2value,
|
|
@@ -763,10 +837,10 @@ def retroglm(args):
|
|
|
763
837
|
"Squared R value of the GLM fit (proportion of variance explained)",
|
|
764
838
|
),
|
|
765
839
|
]
|
|
766
|
-
if args.
|
|
840
|
+
if args.savenormalsLFOfiltfiles:
|
|
767
841
|
maplist += [
|
|
768
|
-
(
|
|
769
|
-
(
|
|
842
|
+
(rvalue, "lfofilterR", "map", None, "R value of the GLM fit"),
|
|
843
|
+
(sLFOfitmean, "lfofilterMean", "map", None, "Intercept from GLM fit"),
|
|
770
844
|
]
|
|
771
845
|
else:
|
|
772
846
|
maplist = [
|
|
@@ -774,7 +848,7 @@ def retroglm(args):
|
|
|
774
848
|
(finalvariance, "lfofilterInbandVarianceAfter", "map", None),
|
|
775
849
|
(varchange, "CVRVariance", "map", None),
|
|
776
850
|
]
|
|
777
|
-
if args.
|
|
851
|
+
if args.savenormalsLFOfiltfiles:
|
|
778
852
|
maplist += [
|
|
779
853
|
(rvalue, "CVRR", "map", None),
|
|
780
854
|
(r2value, "CVRR2", "map", None),
|
|
@@ -794,13 +868,13 @@ def retroglm(args):
|
|
|
794
868
|
(corrmask_valid, "corrfitREAD", "mask", None, "Correlation mask used for calculation"),
|
|
795
869
|
(procmask_valid, "processedREAD", "mask", None, "Processed mask used for calculation"),
|
|
796
870
|
]
|
|
797
|
-
if args.
|
|
798
|
-
if args.
|
|
871
|
+
if args.savenormalsLFOfiltfiles:
|
|
872
|
+
if args.regressderivs > 0 or args.refinedelay:
|
|
799
873
|
maplist += [
|
|
800
874
|
(fitcoeff[:, 0], "lfofilterCoeff", "map", None, "Fit coefficient"),
|
|
801
875
|
(fitNorm[:, 0], "lfofilterNorm", "map", None, "Normalized fit coefficient"),
|
|
802
876
|
]
|
|
803
|
-
for thederiv in range(1, args.
|
|
877
|
+
for thederiv in range(1, args.regressderivs + 1):
|
|
804
878
|
maplist += [
|
|
805
879
|
(
|
|
806
880
|
fitcoeff[:, thederiv],
|
|
@@ -824,28 +898,56 @@ def retroglm(args):
|
|
|
824
898
|
]
|
|
825
899
|
|
|
826
900
|
if args.refinedelay:
|
|
901
|
+
if args.refineregressderivs > 1:
|
|
902
|
+
for i in range(args.refineregressderivs):
|
|
903
|
+
maplist += [
|
|
904
|
+
(
|
|
905
|
+
regressderivratios[i, :],
|
|
906
|
+
f"regressderivratios_{i}",
|
|
907
|
+
"map",
|
|
908
|
+
None,
|
|
909
|
+
f"Ratio of derivative {i+1} of delayed sLFO to the delayed sLFO",
|
|
910
|
+
),
|
|
911
|
+
(
|
|
912
|
+
medfiltregressderivratios[i, :],
|
|
913
|
+
f"medfiltregressderivratios_{i}",
|
|
914
|
+
"map",
|
|
915
|
+
None,
|
|
916
|
+
f"Median filtered version of the regressderivratios_{i} map",
|
|
917
|
+
),
|
|
918
|
+
(
|
|
919
|
+
filteredregressderivratios[i, :],
|
|
920
|
+
f"filteredregressderivratios_{i}",
|
|
921
|
+
"map",
|
|
922
|
+
None,
|
|
923
|
+
f"regressderivratios_{i}, with outliers patched using median filtered data",
|
|
924
|
+
),
|
|
925
|
+
]
|
|
926
|
+
else:
|
|
927
|
+
maplist += [
|
|
928
|
+
(
|
|
929
|
+
regressderivratios,
|
|
930
|
+
"regressderivratios",
|
|
931
|
+
"map",
|
|
932
|
+
None,
|
|
933
|
+
"Ratio of the first derivative of delayed sLFO to the delayed sLFO",
|
|
934
|
+
),
|
|
935
|
+
(
|
|
936
|
+
medfiltregressderivratios,
|
|
937
|
+
"medfiltregressderivratios",
|
|
938
|
+
"map",
|
|
939
|
+
None,
|
|
940
|
+
"Median filtered version of the regressderivratios map",
|
|
941
|
+
),
|
|
942
|
+
(
|
|
943
|
+
filteredregressderivratios,
|
|
944
|
+
"filteredregressderivratios",
|
|
945
|
+
"map",
|
|
946
|
+
None,
|
|
947
|
+
"regressderivratios, with outliers patched using median filtered data",
|
|
948
|
+
),
|
|
949
|
+
]
|
|
827
950
|
maplist += [
|
|
828
|
-
(
|
|
829
|
-
glmderivratios,
|
|
830
|
-
"glmderivratios",
|
|
831
|
-
"map",
|
|
832
|
-
None,
|
|
833
|
-
"Ratio of the first derivative of delayed sLFO to the delayed sLFO",
|
|
834
|
-
),
|
|
835
|
-
(
|
|
836
|
-
medfiltglmderivratios,
|
|
837
|
-
"medfiltglmderivratios",
|
|
838
|
-
"map",
|
|
839
|
-
None,
|
|
840
|
-
"Median filtered version of the glmderivratios map",
|
|
841
|
-
),
|
|
842
|
-
(
|
|
843
|
-
filteredglmderivratios,
|
|
844
|
-
"filteredglmderivratios",
|
|
845
|
-
"map",
|
|
846
|
-
None,
|
|
847
|
-
"glmderivratios, with outliers patched using median filtered data",
|
|
848
|
-
),
|
|
849
951
|
(
|
|
850
952
|
delayoffset,
|
|
851
953
|
"delayoffset",
|
|
@@ -876,7 +978,7 @@ def retroglm(args):
|
|
|
876
978
|
# write the 4D maps
|
|
877
979
|
theheader = copy.deepcopy(fmri_header)
|
|
878
980
|
maplist = []
|
|
879
|
-
if args.
|
|
981
|
+
if args.saveminimumsLFOfiltfiles:
|
|
880
982
|
maplist = [
|
|
881
983
|
(
|
|
882
984
|
filtereddata,
|
|
@@ -897,8 +999,8 @@ def retroglm(args):
|
|
|
897
999
|
)
|
|
898
1000
|
]
|
|
899
1001
|
|
|
900
|
-
if args.
|
|
901
|
-
if args.
|
|
1002
|
+
if args.saveallsLFOfiltfiles:
|
|
1003
|
+
if args.regressderivs > 0:
|
|
902
1004
|
if args.debug:
|
|
903
1005
|
print("going down the multiple EV path")
|
|
904
1006
|
print(f"{regressorset[:, :, 0].shape=}")
|
|
@@ -911,7 +1013,7 @@ def retroglm(args):
|
|
|
911
1013
|
"Shifted sLFO regressor to filter",
|
|
912
1014
|
),
|
|
913
1015
|
]
|
|
914
|
-
for thederiv in range(1, args.
|
|
1016
|
+
for thederiv in range(1, args.regressderivs + 1):
|
|
915
1017
|
if args.debug:
|
|
916
1018
|
print(f"{regressorset[:, :, thederiv].shape=}")
|
|
917
1019
|
maplist += [
|
|
@@ -973,7 +1075,7 @@ def retroglm(args):
|
|
|
973
1075
|
)
|
|
974
1076
|
TimingLGR.info("Filtering for maxcorralt calculation complete")
|
|
975
1077
|
TimingLGR.info("GLM for maxcorralt calculation start")
|
|
976
|
-
|
|
1078
|
+
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
977
1079
|
fmri_data_valid,
|
|
978
1080
|
validvoxels,
|
|
979
1081
|
initial_fmri_x,
|
|
@@ -983,28 +1085,28 @@ def retroglm(args):
|
|
|
983
1085
|
mode,
|
|
984
1086
|
outputname,
|
|
985
1087
|
oversamptr,
|
|
986
|
-
|
|
1088
|
+
sLFOfitmean,
|
|
987
1089
|
rvalue,
|
|
988
1090
|
r2value,
|
|
989
|
-
fitNorm[:, : args.
|
|
990
|
-
fitcoeff[:, : args.
|
|
1091
|
+
fitNorm[:, : args.regressderivs + 1],
|
|
1092
|
+
fitcoeff[:, : args.regressderivs + 1],
|
|
991
1093
|
movingsignal,
|
|
992
1094
|
lagtc,
|
|
993
1095
|
filtereddata,
|
|
994
1096
|
LGR,
|
|
995
1097
|
TimingLGR,
|
|
996
1098
|
threshval,
|
|
997
|
-
args.
|
|
1099
|
+
args.saveminimumsLFOfiltfiles,
|
|
998
1100
|
nprocs_makelaggedtcs=args.nprocs,
|
|
999
|
-
|
|
1000
|
-
|
|
1101
|
+
nprocs_regressionfilt=args.nprocs,
|
|
1102
|
+
regressderivs=args.regressderivs,
|
|
1001
1103
|
showprogressbar=args.showprogressbar,
|
|
1002
1104
|
debug=args.debug,
|
|
1003
1105
|
)
|
|
1004
1106
|
TimingLGR.info(
|
|
1005
1107
|
"GLM for maxcorralt calculation done",
|
|
1006
1108
|
{
|
|
1007
|
-
"message2":
|
|
1109
|
+
"message2": voxelsprocessed_regressionfilt,
|
|
1008
1110
|
"message3": "voxels",
|
|
1009
1111
|
},
|
|
1010
1112
|
)
|
|
@@ -1059,15 +1161,15 @@ def retroglm(args):
|
|
|
1059
1161
|
# read the runoptions file
|
|
1060
1162
|
print("writing runoptions")
|
|
1061
1163
|
if args.refinedelay:
|
|
1062
|
-
therunoptions["
|
|
1063
|
-
therunoptions["
|
|
1164
|
+
therunoptions["retroregress_delayoffsetMAD"] = delayoffsetMAD
|
|
1165
|
+
therunoptions["retroregress_runtime"] = time.strftime(
|
|
1064
1166
|
"%a, %d %b %Y %H:%M:%S %Z", time.localtime(time.time())
|
|
1065
1167
|
)
|
|
1066
1168
|
|
|
1067
1169
|
# clean up shared memory
|
|
1068
1170
|
if usesharedmem:
|
|
1069
1171
|
TimingLGR.info("Shared memory cleanup start")
|
|
1070
|
-
tide_util.cleanup_shm(
|
|
1172
|
+
tide_util.cleanup_shm(sLFOfitmean_shm)
|
|
1071
1173
|
tide_util.cleanup_shm(rvalue_shm)
|
|
1072
1174
|
tide_util.cleanup_shm(r2value_shm)
|
|
1073
1175
|
tide_util.cleanup_shm(fitNorm_shm)
|
|
@@ -1075,7 +1177,7 @@ def retroglm(args):
|
|
|
1075
1177
|
tide_util.cleanup_shm(movingsignal_shm)
|
|
1076
1178
|
tide_util.cleanup_shm(lagtc_shm)
|
|
1077
1179
|
tide_util.cleanup_shm(filtereddata_shm)
|
|
1078
|
-
|
|
1180
|
+
TimingLGR.info("Shared memory cleanup complete")
|
|
1079
1181
|
|
|
1080
1182
|
# shut down logging
|
|
1081
1183
|
TimingLGR.info("Done")
|
|
@@ -1110,7 +1212,7 @@ def retroglm(args):
|
|
|
1110
1212
|
|
|
1111
1213
|
def process_args(inputargs=None):
|
|
1112
1214
|
"""
|
|
1113
|
-
Compile arguments for
|
|
1215
|
+
Compile arguments for retroregress workflow.
|
|
1114
1216
|
"""
|
|
1115
1217
|
args, argstowrite = pf.setargs(_get_parser, inputargs=inputargs)
|
|
1116
1218
|
return args
|