rapidtide 3.0a12__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/{Refiner.py → RegressorRefiner.py} +1 -1
- 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 +1 -0
- rapidtide/data/examples/src/testglmfilt +8 -6
- rapidtide/data/examples/src/testhappy +1 -1
- rapidtide/data/examples/src/testnewrefine +11 -11
- rapidtide/data/examples/src/testnoiseamp +2 -2
- 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} +21 -19
- rapidtide/refinedelay.py +96 -58
- 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_alt_qt6.py +172 -45
- rapidtide/tidepoolTemplate_big_qt6.py +196 -53
- rapidtide/tidepoolTemplate_qt6.py +150 -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/rapidtide.py +235 -171
- rapidtide/workflows/rapidtide_parser.py +103 -86
- rapidtide/workflows/{glmfrommaps.py → regressfrommaps.py} +28 -26
- rapidtide/workflows/retrolagtcs.py +12 -12
- rapidtide/workflows/{retroglm.py → retroregress.py} +158 -141
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/METADATA +3 -2
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/RECORD +61 -56
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/WHEEL +1 -1
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/entry_points.txt +3 -2
- rapidtide/data/examples/src/testoutputsize +0 -45
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info/licenses}/LICENSE +0 -0
- {rapidtide-3.0a12.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,13 +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
|
|
60
|
-
|
|
61
|
+
DEFAULT_REFINEREGRESSDERIVS = 1
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
def _get_parser():
|
|
@@ -65,8 +66,8 @@ def _get_parser():
|
|
|
65
66
|
Argument parser for glmfilt
|
|
66
67
|
"""
|
|
67
68
|
parser = argparse.ArgumentParser(
|
|
68
|
-
prog="
|
|
69
|
-
description="Do the rapidtide
|
|
69
|
+
prog="retroregress",
|
|
70
|
+
description="Do the rapidtide sLFO filtering using the maps generated from a previous analysis.",
|
|
70
71
|
allow_abbrev=False,
|
|
71
72
|
)
|
|
72
73
|
|
|
@@ -89,15 +90,15 @@ def _get_parser():
|
|
|
89
90
|
default=None,
|
|
90
91
|
)
|
|
91
92
|
parser.add_argument(
|
|
92
|
-
"--
|
|
93
|
-
dest="
|
|
93
|
+
"--regressderivs",
|
|
94
|
+
dest="regressderivs",
|
|
94
95
|
action="store",
|
|
95
96
|
type=lambda x: pf.is_int(parser, x, minval=0),
|
|
96
97
|
metavar="NDERIVS",
|
|
97
98
|
help=(
|
|
98
|
-
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}"
|
|
99
100
|
),
|
|
100
|
-
default=
|
|
101
|
+
default=DEFAULT_REGRESSIONFILTDERIVS,
|
|
101
102
|
)
|
|
102
103
|
parser.add_argument(
|
|
103
104
|
"--nprocs",
|
|
@@ -129,7 +130,7 @@ def _get_parser():
|
|
|
129
130
|
choices=["min", "less", "normal", "more", "max"],
|
|
130
131
|
help=(
|
|
131
132
|
"The level of file output produced. 'min' produces only absolutely essential files, 'less' adds in "
|
|
132
|
-
"the
|
|
133
|
+
"the sLFO filtered data (rather than just filter efficacy metrics), 'normal' saves what you "
|
|
133
134
|
"would typically want around for interactive data exploration, "
|
|
134
135
|
"'more' adds files that are sometimes useful, and 'max' outputs anything you might possibly want. "
|
|
135
136
|
"Selecting 'max' will produce ~3x your input datafile size as output. "
|
|
@@ -171,7 +172,7 @@ def _get_parser():
|
|
|
171
172
|
"--nofilterwithrefineddelay",
|
|
172
173
|
dest="filterwithrefineddelay",
|
|
173
174
|
action="store_false",
|
|
174
|
-
help=("Do not use the refined delay in
|
|
175
|
+
help=("Do not use the refined delay in sLFO filter."),
|
|
175
176
|
default=True,
|
|
176
177
|
)
|
|
177
178
|
parser.add_argument(
|
|
@@ -218,22 +219,22 @@ def _get_parser():
|
|
|
218
219
|
"Experimental options (not fully tested, or not tested at all, may not work). Beware!"
|
|
219
220
|
)
|
|
220
221
|
experimental.add_argument(
|
|
221
|
-
"--
|
|
222
|
-
dest="
|
|
222
|
+
"--refineregressderivs",
|
|
223
|
+
dest="refineregressderivs",
|
|
223
224
|
action="store",
|
|
224
225
|
type=lambda x: pf.is_int(parser, x, minval=1),
|
|
225
226
|
metavar="NDERIVS",
|
|
226
227
|
help=(
|
|
227
228
|
f"When doing GLM for delay refinement, include derivatives up to NDERIVS order. Must be 1 or more. "
|
|
228
|
-
f"Default is {
|
|
229
|
+
f"Default is {DEFAULT_REFINEREGRESSDERIVS}"
|
|
229
230
|
),
|
|
230
|
-
default=
|
|
231
|
+
default=DEFAULT_REFINEREGRESSDERIVS,
|
|
231
232
|
)
|
|
232
233
|
|
|
233
234
|
return parser
|
|
234
235
|
|
|
235
236
|
|
|
236
|
-
def
|
|
237
|
+
def retroregress(args):
|
|
237
238
|
# get the pid of the parent process
|
|
238
239
|
args.pid = os.getpid()
|
|
239
240
|
|
|
@@ -258,7 +259,7 @@ def retroglm(args):
|
|
|
258
259
|
debug=args.debug,
|
|
259
260
|
)
|
|
260
261
|
TimingLGR.info("Start")
|
|
261
|
-
LGR.info(f"starting
|
|
262
|
+
LGR.info(f"starting retroregress")
|
|
262
263
|
|
|
263
264
|
# set some global values
|
|
264
265
|
args.mindelay = DEFAULT_REFINEDELAYMINDELAY
|
|
@@ -266,30 +267,30 @@ def retroglm(args):
|
|
|
266
267
|
args.numpoints = DEFAULT_REFINEDELAYNUMPOINTS
|
|
267
268
|
|
|
268
269
|
if args.outputlevel == "min":
|
|
269
|
-
args.
|
|
270
|
-
args.
|
|
270
|
+
args.saveminimumsLFOfiltfiles = False
|
|
271
|
+
args.savenormalsLFOfiltfiles = False
|
|
271
272
|
args.savemovingsignal = False
|
|
272
|
-
args.
|
|
273
|
+
args.saveallsLFOfiltfiles = False
|
|
273
274
|
elif args.outputlevel == "less":
|
|
274
|
-
args.
|
|
275
|
-
args.
|
|
275
|
+
args.saveminimumsLFOfiltfiles = True
|
|
276
|
+
args.savenormalsLFOfiltfiles = False
|
|
276
277
|
args.savemovingsignal = False
|
|
277
|
-
args.
|
|
278
|
+
args.saveallsLFOfiltfiles = False
|
|
278
279
|
elif args.outputlevel == "normal":
|
|
279
|
-
args.
|
|
280
|
-
args.
|
|
280
|
+
args.saveminimumsLFOfiltfiles = True
|
|
281
|
+
args.savenormalsLFOfiltfiles = True
|
|
281
282
|
args.savemovingsignal = False
|
|
282
|
-
args.
|
|
283
|
+
args.saveallsLFOfiltfiles = False
|
|
283
284
|
elif args.outputlevel == "more":
|
|
284
|
-
args.
|
|
285
|
-
args.
|
|
285
|
+
args.saveminimumsLFOfiltfiles = True
|
|
286
|
+
args.savenormalsLFOfiltfiles = True
|
|
286
287
|
args.savemovingsignal = True
|
|
287
|
-
args.
|
|
288
|
+
args.saveallsLFOfiltfiles = False
|
|
288
289
|
elif args.outputlevel == "max":
|
|
289
|
-
args.
|
|
290
|
-
args.
|
|
290
|
+
args.saveminimumsLFOfiltfiles = True
|
|
291
|
+
args.savenormalsLFOfiltfiles = True
|
|
291
292
|
args.savemovingsignal = True
|
|
292
|
-
args.
|
|
293
|
+
args.saveallsLFOfiltfiles = True
|
|
293
294
|
else:
|
|
294
295
|
print(f"illegal output level {args['outputlevel']}")
|
|
295
296
|
sys.exit()
|
|
@@ -304,12 +305,25 @@ def retroglm(args):
|
|
|
304
305
|
else:
|
|
305
306
|
usesharedmem = True
|
|
306
307
|
|
|
307
|
-
# read the runoptions file
|
|
308
|
+
# read the runoptions file, update if necessary
|
|
308
309
|
print("reading runoptions")
|
|
309
310
|
runoptionsfile = f"{args.datafileroot}_desc-runoptions_info"
|
|
310
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
|
+
|
|
311
325
|
try:
|
|
312
|
-
|
|
326
|
+
candoretroregress = therunoptions["retroregresscompatible"]
|
|
313
327
|
except KeyError:
|
|
314
328
|
print(
|
|
315
329
|
f"based on {runoptionsfile}, this rapidtide dataset does not support retrospective GLM calculation"
|
|
@@ -330,7 +344,7 @@ def retroglm(args):
|
|
|
330
344
|
else:
|
|
331
345
|
rt_outfloattype = "float32"
|
|
332
346
|
rt_outfloatset = np.float32
|
|
333
|
-
therunoptions["
|
|
347
|
+
therunoptions["saveminimumsLFOfiltfiles"] = args.saveminimumsLFOfiltfiles
|
|
334
348
|
|
|
335
349
|
# read the fmri input files
|
|
336
350
|
print("reading fmrifile")
|
|
@@ -363,7 +377,7 @@ def retroglm(args):
|
|
|
363
377
|
if not tide_io.checkspacematch(fmri_header, procmask_header):
|
|
364
378
|
raise ValueError("procmask dimensions do not match fmri dimensions")
|
|
365
379
|
procmask_spacebytime = procmask.reshape((numspatiallocs))
|
|
366
|
-
if args.debug
|
|
380
|
+
if args.debug:
|
|
367
381
|
print(f"{procmask_spacebytime.shape=}")
|
|
368
382
|
print(f"{tide_stats.getmasksize(procmask_spacebytime)=}")
|
|
369
383
|
|
|
@@ -380,7 +394,7 @@ def retroglm(args):
|
|
|
380
394
|
if not tide_io.checkspacematch(fmri_header, corrmask_header):
|
|
381
395
|
raise ValueError("corrmask dimensions do not match fmri dimensions")
|
|
382
396
|
corrmask_spacebytime = corrmask.reshape((numspatiallocs))
|
|
383
|
-
if args.debug
|
|
397
|
+
if args.debug:
|
|
384
398
|
print(f"{corrmask_spacebytime.shape=}")
|
|
385
399
|
print(f"{tide_stats.getmasksize(corrmask_spacebytime)=}")
|
|
386
400
|
|
|
@@ -442,19 +456,19 @@ def retroglm(args):
|
|
|
442
456
|
print("figuring out valid voxels")
|
|
443
457
|
validvoxels = np.where(procmask_spacebytime > 0)[0]
|
|
444
458
|
numvalidspatiallocs = np.shape(validvoxels)[0]
|
|
445
|
-
if args.debug
|
|
459
|
+
if args.debug:
|
|
446
460
|
print(f"{numvalidspatiallocs=}")
|
|
447
461
|
internalvalidspaceshape = numvalidspatiallocs
|
|
448
462
|
if args.refinedelay:
|
|
449
|
-
derivaxissize = np.max([args.
|
|
463
|
+
derivaxissize = np.max([args.refineregressderivs + 1, args.regressderivs + 1])
|
|
450
464
|
else:
|
|
451
|
-
derivaxissize = args.
|
|
465
|
+
derivaxissize = args.regressderivs + 1
|
|
452
466
|
internalvalidspaceshapederivs = (
|
|
453
467
|
internalvalidspaceshape,
|
|
454
468
|
derivaxissize,
|
|
455
469
|
)
|
|
456
470
|
internalvalidfmrishape = (numvalidspatiallocs, np.shape(initial_fmri_x)[0])
|
|
457
|
-
if args.debug
|
|
471
|
+
if args.debug:
|
|
458
472
|
print(f"validvoxels shape = {numvalidspatiallocs}")
|
|
459
473
|
print(f"internalvalidfmrishape shape = {internalvalidfmrishape}")
|
|
460
474
|
|
|
@@ -470,7 +484,9 @@ def retroglm(args):
|
|
|
470
484
|
if usesharedmem:
|
|
471
485
|
if args.debug:
|
|
472
486
|
print("allocating shared memory")
|
|
473
|
-
|
|
487
|
+
sLFOfitmean, sLFOfitmean_shm = tide_util.allocshared(
|
|
488
|
+
internalvalidspaceshape, rt_outfloatset
|
|
489
|
+
)
|
|
474
490
|
rvalue, rvalue_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
|
|
475
491
|
r2value, r2value_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
|
|
476
492
|
fitNorm, fitNorm_shm = tide_util.allocshared(internalvalidspaceshapederivs, rt_outfloatset)
|
|
@@ -488,7 +504,7 @@ def retroglm(args):
|
|
|
488
504
|
else:
|
|
489
505
|
if args.debug:
|
|
490
506
|
print("allocating memory")
|
|
491
|
-
|
|
507
|
+
sLFOfitmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
492
508
|
rvalue = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
493
509
|
r2value = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
494
510
|
fitNorm = np.zeros(internalvalidspaceshapederivs, dtype=rt_outfloattype)
|
|
@@ -499,7 +515,7 @@ def retroglm(args):
|
|
|
499
515
|
ramlocation = "locally"
|
|
500
516
|
|
|
501
517
|
totalbytes = (
|
|
502
|
-
|
|
518
|
+
sLFOfitmean.nbytes
|
|
503
519
|
+ rvalue.nbytes
|
|
504
520
|
+ r2value.nbytes
|
|
505
521
|
+ fitNorm.nbytes
|
|
@@ -518,13 +534,13 @@ def retroglm(args):
|
|
|
518
534
|
print(f"{outputname=}")
|
|
519
535
|
oversamptr = fmritr / oversampfactor
|
|
520
536
|
try:
|
|
521
|
-
threshval = therunoptions["
|
|
537
|
+
threshval = therunoptions["regressfiltthreshval"]
|
|
522
538
|
except KeyError:
|
|
523
539
|
threshval = 0.0
|
|
524
|
-
therunoptions["
|
|
540
|
+
therunoptions["regressfiltthreshval"] = threshval
|
|
525
541
|
mode = "glm"
|
|
526
542
|
|
|
527
|
-
if args.debug
|
|
543
|
+
if args.debug:
|
|
528
544
|
print(f"{validvoxels.shape=}")
|
|
529
545
|
np.savetxt(f"{outputname}_validvoxels.txt", validvoxels)
|
|
530
546
|
|
|
@@ -556,7 +572,7 @@ def retroglm(args):
|
|
|
556
572
|
"inputdata",
|
|
557
573
|
"bold",
|
|
558
574
|
None,
|
|
559
|
-
"fMRI data that will be subjected to
|
|
575
|
+
"fMRI data that will be subjected to sLFO filtering",
|
|
560
576
|
),
|
|
561
577
|
]
|
|
562
578
|
tide_io.savemaplist(
|
|
@@ -583,7 +599,7 @@ def retroglm(args):
|
|
|
583
599
|
args.delayoffsetgausssigma = np.mean([xdim, ydim, slicedim]) / 2.0
|
|
584
600
|
|
|
585
601
|
TimingLGR.info("Refinement calibration start")
|
|
586
|
-
|
|
602
|
+
regressderivratios, regressrvalues = tide_refinedelay.getderivratios(
|
|
587
603
|
fmri_data_valid,
|
|
588
604
|
validvoxels,
|
|
589
605
|
initial_fmri_x,
|
|
@@ -593,25 +609,25 @@ def retroglm(args):
|
|
|
593
609
|
mode,
|
|
594
610
|
outputname,
|
|
595
611
|
oversamptr,
|
|
596
|
-
|
|
612
|
+
sLFOfitmean,
|
|
597
613
|
rvalue,
|
|
598
614
|
r2value,
|
|
599
|
-
fitNorm[:, : (args.
|
|
600
|
-
fitcoeff[:, : (args.
|
|
615
|
+
fitNorm[:, : (args.refineregressderivs + 1)],
|
|
616
|
+
fitcoeff[:, : (args.refineregressderivs + 1)],
|
|
601
617
|
movingsignal,
|
|
602
618
|
lagtc,
|
|
603
619
|
filtereddata,
|
|
604
620
|
LGR,
|
|
605
621
|
TimingLGR,
|
|
606
622
|
therunoptions,
|
|
607
|
-
|
|
623
|
+
regressderivs=args.refineregressderivs,
|
|
608
624
|
debug=args.debug,
|
|
609
625
|
)
|
|
610
626
|
|
|
611
|
-
if args.
|
|
612
|
-
|
|
627
|
+
if args.refineregressderivs == 1:
|
|
628
|
+
medfiltregressderivratios, filteredregressderivratios, delayoffsetMAD = (
|
|
613
629
|
tide_refinedelay.filterderivratios(
|
|
614
|
-
|
|
630
|
+
regressderivratios,
|
|
615
631
|
(xsize, ysize, numslices),
|
|
616
632
|
validvoxels,
|
|
617
633
|
(xdim, ydim, slicedim),
|
|
@@ -639,49 +655,51 @@ def retroglm(args):
|
|
|
639
655
|
|
|
640
656
|
# now calculate the delay offsets
|
|
641
657
|
TimingLGR.info("Calculating delay offsets")
|
|
642
|
-
delayoffset = np.zeros_like(
|
|
643
|
-
if args.
|
|
644
|
-
print(f"calculating delayoffsets for {
|
|
645
|
-
for i in range(
|
|
646
|
-
delayoffset[i] = tide_refinedelay.ratiotodelay(
|
|
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])
|
|
647
663
|
"""delayoffset[i] = tide_refinedelay.coffstodelay(
|
|
648
|
-
np.asarray([
|
|
664
|
+
np.asarray([filteredregressderivratios[i]]),
|
|
649
665
|
mindelay=args.mindelay,
|
|
650
666
|
maxdelay=args.maxdelay,
|
|
651
667
|
)"""
|
|
652
668
|
|
|
653
|
-
refinedvoxelstoreport =
|
|
669
|
+
refinedvoxelstoreport = filteredregressderivratios.shape[0]
|
|
654
670
|
else:
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
delayoffsetMAD = np.zeros(args.
|
|
658
|
-
for i in range(args.
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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,
|
|
672
690
|
)
|
|
673
691
|
|
|
674
692
|
# now calculate the delay offsets
|
|
675
|
-
delayoffset = np.zeros_like(
|
|
693
|
+
delayoffset = np.zeros_like(filteredregressderivratios[0, :])
|
|
676
694
|
if args.debug:
|
|
677
|
-
print(f"calculating delayoffsets for {
|
|
678
|
-
for i in range(
|
|
695
|
+
print(f"calculating delayoffsets for {filteredregressderivratios.shape[1]} voxels")
|
|
696
|
+
for i in range(filteredregressderivratios.shape[1]):
|
|
679
697
|
delayoffset[i] = tide_refinedelay.coffstodelay(
|
|
680
|
-
|
|
698
|
+
filteredregressderivratios[:, i],
|
|
681
699
|
mindelay=args.mindelay,
|
|
682
700
|
maxdelay=args.maxdelay,
|
|
683
701
|
)
|
|
684
|
-
refinedvoxelstoreport =
|
|
702
|
+
refinedvoxelstoreport = filteredregressderivratios.shape[1]
|
|
685
703
|
|
|
686
704
|
namesuffix = "_desc-delayoffset_hist"
|
|
687
705
|
tide_stats.makeandsavehistogram(
|
|
@@ -706,16 +724,15 @@ def retroglm(args):
|
|
|
706
724
|
# Delay refinement end
|
|
707
725
|
####################################################
|
|
708
726
|
|
|
709
|
-
# initialrawvariance = tide_math.imagevariance(fmri_data_valid, None, 1.0 / fmritr)
|
|
710
727
|
initialvariance = tide_math.imagevariance(fmri_data_valid, theprefilter, 1.0 / fmritr)
|
|
711
728
|
|
|
712
|
-
print("calling
|
|
713
|
-
TimingLGR.info("Starting
|
|
729
|
+
print("calling regressfrommaps")
|
|
730
|
+
TimingLGR.info("Starting sLFO filtering")
|
|
714
731
|
if args.refinedelay and args.filterwithrefineddelay:
|
|
715
732
|
lagstouse_valid = lagtimesrefined_valid
|
|
716
733
|
else:
|
|
717
734
|
lagstouse_valid = lagtimes_valid
|
|
718
|
-
|
|
735
|
+
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
719
736
|
fmri_data_valid,
|
|
720
737
|
validvoxels,
|
|
721
738
|
initial_fmri_x,
|
|
@@ -725,29 +742,29 @@ def retroglm(args):
|
|
|
725
742
|
mode,
|
|
726
743
|
outputname,
|
|
727
744
|
oversamptr,
|
|
728
|
-
|
|
745
|
+
sLFOfitmean,
|
|
729
746
|
rvalue,
|
|
730
747
|
r2value,
|
|
731
|
-
fitNorm[:, : args.
|
|
732
|
-
fitcoeff[:, : args.
|
|
748
|
+
fitNorm[:, : args.regressderivs + 1],
|
|
749
|
+
fitcoeff[:, : args.regressderivs + 1],
|
|
733
750
|
movingsignal,
|
|
734
751
|
lagtc,
|
|
735
752
|
filtereddata,
|
|
736
753
|
LGR,
|
|
737
754
|
TimingLGR,
|
|
738
755
|
threshval,
|
|
739
|
-
args.
|
|
756
|
+
args.saveminimumsLFOfiltfiles,
|
|
740
757
|
nprocs_makelaggedtcs=args.nprocs,
|
|
741
|
-
|
|
742
|
-
|
|
758
|
+
nprocs_regressionfilt=args.nprocs,
|
|
759
|
+
regressderivs=args.regressderivs,
|
|
743
760
|
showprogressbar=args.showprogressbar,
|
|
744
761
|
debug=args.debug,
|
|
745
762
|
)
|
|
746
|
-
print(f"filtered {
|
|
763
|
+
print(f"filtered {voxelsprocessed_regressionfilt} voxels")
|
|
747
764
|
TimingLGR.info(
|
|
748
|
-
"
|
|
765
|
+
"sLFO filtering done",
|
|
749
766
|
{
|
|
750
|
-
"message2":
|
|
767
|
+
"message2": voxelsprocessed_regressionfilt,
|
|
751
768
|
"message3": "voxels",
|
|
752
769
|
},
|
|
753
770
|
)
|
|
@@ -810,7 +827,7 @@ def retroglm(args):
|
|
|
810
827
|
# "Change in total variance after filtering, in percent",
|
|
811
828
|
# ),
|
|
812
829
|
]
|
|
813
|
-
if args.
|
|
830
|
+
if args.saveminimumsLFOfiltfiles:
|
|
814
831
|
maplist += [
|
|
815
832
|
(
|
|
816
833
|
r2value,
|
|
@@ -820,10 +837,10 @@ def retroglm(args):
|
|
|
820
837
|
"Squared R value of the GLM fit (proportion of variance explained)",
|
|
821
838
|
),
|
|
822
839
|
]
|
|
823
|
-
if args.
|
|
840
|
+
if args.savenormalsLFOfiltfiles:
|
|
824
841
|
maplist += [
|
|
825
|
-
(
|
|
826
|
-
(
|
|
842
|
+
(rvalue, "lfofilterR", "map", None, "R value of the GLM fit"),
|
|
843
|
+
(sLFOfitmean, "lfofilterMean", "map", None, "Intercept from GLM fit"),
|
|
827
844
|
]
|
|
828
845
|
else:
|
|
829
846
|
maplist = [
|
|
@@ -831,7 +848,7 @@ def retroglm(args):
|
|
|
831
848
|
(finalvariance, "lfofilterInbandVarianceAfter", "map", None),
|
|
832
849
|
(varchange, "CVRVariance", "map", None),
|
|
833
850
|
]
|
|
834
|
-
if args.
|
|
851
|
+
if args.savenormalsLFOfiltfiles:
|
|
835
852
|
maplist += [
|
|
836
853
|
(rvalue, "CVRR", "map", None),
|
|
837
854
|
(r2value, "CVRR2", "map", None),
|
|
@@ -851,13 +868,13 @@ def retroglm(args):
|
|
|
851
868
|
(corrmask_valid, "corrfitREAD", "mask", None, "Correlation mask used for calculation"),
|
|
852
869
|
(procmask_valid, "processedREAD", "mask", None, "Processed mask used for calculation"),
|
|
853
870
|
]
|
|
854
|
-
if args.
|
|
855
|
-
if args.
|
|
871
|
+
if args.savenormalsLFOfiltfiles:
|
|
872
|
+
if args.regressderivs > 0 or args.refinedelay:
|
|
856
873
|
maplist += [
|
|
857
874
|
(fitcoeff[:, 0], "lfofilterCoeff", "map", None, "Fit coefficient"),
|
|
858
875
|
(fitNorm[:, 0], "lfofilterNorm", "map", None, "Normalized fit coefficient"),
|
|
859
876
|
]
|
|
860
|
-
for thederiv in range(1, args.
|
|
877
|
+
for thederiv in range(1, args.regressderivs + 1):
|
|
861
878
|
maplist += [
|
|
862
879
|
(
|
|
863
880
|
fitcoeff[:, thederiv],
|
|
@@ -881,53 +898,53 @@ def retroglm(args):
|
|
|
881
898
|
]
|
|
882
899
|
|
|
883
900
|
if args.refinedelay:
|
|
884
|
-
if args.
|
|
885
|
-
for i in range(args.
|
|
901
|
+
if args.refineregressderivs > 1:
|
|
902
|
+
for i in range(args.refineregressderivs):
|
|
886
903
|
maplist += [
|
|
887
904
|
(
|
|
888
|
-
|
|
889
|
-
f"
|
|
905
|
+
regressderivratios[i, :],
|
|
906
|
+
f"regressderivratios_{i}",
|
|
890
907
|
"map",
|
|
891
908
|
None,
|
|
892
909
|
f"Ratio of derivative {i+1} of delayed sLFO to the delayed sLFO",
|
|
893
910
|
),
|
|
894
911
|
(
|
|
895
|
-
|
|
896
|
-
f"
|
|
912
|
+
medfiltregressderivratios[i, :],
|
|
913
|
+
f"medfiltregressderivratios_{i}",
|
|
897
914
|
"map",
|
|
898
915
|
None,
|
|
899
|
-
f"Median filtered version of the
|
|
916
|
+
f"Median filtered version of the regressderivratios_{i} map",
|
|
900
917
|
),
|
|
901
918
|
(
|
|
902
|
-
|
|
903
|
-
f"
|
|
919
|
+
filteredregressderivratios[i, :],
|
|
920
|
+
f"filteredregressderivratios_{i}",
|
|
904
921
|
"map",
|
|
905
922
|
None,
|
|
906
|
-
f"
|
|
923
|
+
f"regressderivratios_{i}, with outliers patched using median filtered data",
|
|
907
924
|
),
|
|
908
925
|
]
|
|
909
926
|
else:
|
|
910
927
|
maplist += [
|
|
911
928
|
(
|
|
912
|
-
|
|
913
|
-
"
|
|
929
|
+
regressderivratios,
|
|
930
|
+
"regressderivratios",
|
|
914
931
|
"map",
|
|
915
932
|
None,
|
|
916
933
|
"Ratio of the first derivative of delayed sLFO to the delayed sLFO",
|
|
917
934
|
),
|
|
918
935
|
(
|
|
919
|
-
|
|
920
|
-
"
|
|
936
|
+
medfiltregressderivratios,
|
|
937
|
+
"medfiltregressderivratios",
|
|
921
938
|
"map",
|
|
922
939
|
None,
|
|
923
|
-
"Median filtered version of the
|
|
940
|
+
"Median filtered version of the regressderivratios map",
|
|
924
941
|
),
|
|
925
942
|
(
|
|
926
|
-
|
|
927
|
-
"
|
|
943
|
+
filteredregressderivratios,
|
|
944
|
+
"filteredregressderivratios",
|
|
928
945
|
"map",
|
|
929
946
|
None,
|
|
930
|
-
"
|
|
947
|
+
"regressderivratios, with outliers patched using median filtered data",
|
|
931
948
|
),
|
|
932
949
|
]
|
|
933
950
|
maplist += [
|
|
@@ -961,7 +978,7 @@ def retroglm(args):
|
|
|
961
978
|
# write the 4D maps
|
|
962
979
|
theheader = copy.deepcopy(fmri_header)
|
|
963
980
|
maplist = []
|
|
964
|
-
if args.
|
|
981
|
+
if args.saveminimumsLFOfiltfiles:
|
|
965
982
|
maplist = [
|
|
966
983
|
(
|
|
967
984
|
filtereddata,
|
|
@@ -982,8 +999,8 @@ def retroglm(args):
|
|
|
982
999
|
)
|
|
983
1000
|
]
|
|
984
1001
|
|
|
985
|
-
if args.
|
|
986
|
-
if args.
|
|
1002
|
+
if args.saveallsLFOfiltfiles:
|
|
1003
|
+
if args.regressderivs > 0:
|
|
987
1004
|
if args.debug:
|
|
988
1005
|
print("going down the multiple EV path")
|
|
989
1006
|
print(f"{regressorset[:, :, 0].shape=}")
|
|
@@ -996,7 +1013,7 @@ def retroglm(args):
|
|
|
996
1013
|
"Shifted sLFO regressor to filter",
|
|
997
1014
|
),
|
|
998
1015
|
]
|
|
999
|
-
for thederiv in range(1, args.
|
|
1016
|
+
for thederiv in range(1, args.regressderivs + 1):
|
|
1000
1017
|
if args.debug:
|
|
1001
1018
|
print(f"{regressorset[:, :, thederiv].shape=}")
|
|
1002
1019
|
maplist += [
|
|
@@ -1058,7 +1075,7 @@ def retroglm(args):
|
|
|
1058
1075
|
)
|
|
1059
1076
|
TimingLGR.info("Filtering for maxcorralt calculation complete")
|
|
1060
1077
|
TimingLGR.info("GLM for maxcorralt calculation start")
|
|
1061
|
-
|
|
1078
|
+
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
1062
1079
|
fmri_data_valid,
|
|
1063
1080
|
validvoxels,
|
|
1064
1081
|
initial_fmri_x,
|
|
@@ -1068,28 +1085,28 @@ def retroglm(args):
|
|
|
1068
1085
|
mode,
|
|
1069
1086
|
outputname,
|
|
1070
1087
|
oversamptr,
|
|
1071
|
-
|
|
1088
|
+
sLFOfitmean,
|
|
1072
1089
|
rvalue,
|
|
1073
1090
|
r2value,
|
|
1074
|
-
fitNorm[:, : args.
|
|
1075
|
-
fitcoeff[:, : args.
|
|
1091
|
+
fitNorm[:, : args.regressderivs + 1],
|
|
1092
|
+
fitcoeff[:, : args.regressderivs + 1],
|
|
1076
1093
|
movingsignal,
|
|
1077
1094
|
lagtc,
|
|
1078
1095
|
filtereddata,
|
|
1079
1096
|
LGR,
|
|
1080
1097
|
TimingLGR,
|
|
1081
1098
|
threshval,
|
|
1082
|
-
args.
|
|
1099
|
+
args.saveminimumsLFOfiltfiles,
|
|
1083
1100
|
nprocs_makelaggedtcs=args.nprocs,
|
|
1084
|
-
|
|
1085
|
-
|
|
1101
|
+
nprocs_regressionfilt=args.nprocs,
|
|
1102
|
+
regressderivs=args.regressderivs,
|
|
1086
1103
|
showprogressbar=args.showprogressbar,
|
|
1087
1104
|
debug=args.debug,
|
|
1088
1105
|
)
|
|
1089
1106
|
TimingLGR.info(
|
|
1090
1107
|
"GLM for maxcorralt calculation done",
|
|
1091
1108
|
{
|
|
1092
|
-
"message2":
|
|
1109
|
+
"message2": voxelsprocessed_regressionfilt,
|
|
1093
1110
|
"message3": "voxels",
|
|
1094
1111
|
},
|
|
1095
1112
|
)
|
|
@@ -1144,15 +1161,15 @@ def retroglm(args):
|
|
|
1144
1161
|
# read the runoptions file
|
|
1145
1162
|
print("writing runoptions")
|
|
1146
1163
|
if args.refinedelay:
|
|
1147
|
-
therunoptions["
|
|
1148
|
-
therunoptions["
|
|
1164
|
+
therunoptions["retroregress_delayoffsetMAD"] = delayoffsetMAD
|
|
1165
|
+
therunoptions["retroregress_runtime"] = time.strftime(
|
|
1149
1166
|
"%a, %d %b %Y %H:%M:%S %Z", time.localtime(time.time())
|
|
1150
1167
|
)
|
|
1151
1168
|
|
|
1152
1169
|
# clean up shared memory
|
|
1153
1170
|
if usesharedmem:
|
|
1154
1171
|
TimingLGR.info("Shared memory cleanup start")
|
|
1155
|
-
tide_util.cleanup_shm(
|
|
1172
|
+
tide_util.cleanup_shm(sLFOfitmean_shm)
|
|
1156
1173
|
tide_util.cleanup_shm(rvalue_shm)
|
|
1157
1174
|
tide_util.cleanup_shm(r2value_shm)
|
|
1158
1175
|
tide_util.cleanup_shm(fitNorm_shm)
|
|
@@ -1160,7 +1177,7 @@ def retroglm(args):
|
|
|
1160
1177
|
tide_util.cleanup_shm(movingsignal_shm)
|
|
1161
1178
|
tide_util.cleanup_shm(lagtc_shm)
|
|
1162
1179
|
tide_util.cleanup_shm(filtereddata_shm)
|
|
1163
|
-
|
|
1180
|
+
TimingLGR.info("Shared memory cleanup complete")
|
|
1164
1181
|
|
|
1165
1182
|
# shut down logging
|
|
1166
1183
|
TimingLGR.info("Done")
|
|
@@ -1195,7 +1212,7 @@ def retroglm(args):
|
|
|
1195
1212
|
|
|
1196
1213
|
def process_args(inputargs=None):
|
|
1197
1214
|
"""
|
|
1198
|
-
Compile arguments for
|
|
1215
|
+
Compile arguments for retroregress workflow.
|
|
1199
1216
|
"""
|
|
1200
1217
|
args, argstowrite = pf.setargs(_get_parser, inputargs=inputargs)
|
|
1201
1218
|
return args
|