rapidtide 3.0a12__py3-none-any.whl → 3.0a14__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 +213 -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 +14 -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} +23 -19
- rapidtide/makelaggedtcs.py +8 -5
- rapidtide/multiproc.py +8 -11
- rapidtide/refinedelay.py +234 -109
- 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 +14 -6
- rapidtide/tests/test_fullrunhappy_v2.py +17 -9
- rapidtide/tests/test_fullrunhappy_v3.py +16 -8
- rapidtide/tests/test_fullrunhappy_v4.py +16 -8
- rapidtide/tests/test_fullrunhappy_v5.py +14 -6
- rapidtide/tests/test_fullrunrapidtide_v1.py +20 -12
- rapidtide/tests/test_fullrunrapidtide_v2.py +21 -13
- rapidtide/tests/test_fullrunrapidtide_v3.py +15 -7
- rapidtide/tests/test_fullrunrapidtide_v4.py +14 -7
- rapidtide/tests/test_fullrunrapidtide_v5.py +13 -5
- rapidtide/tests/test_fullrunrapidtide_v6.py +34 -26
- rapidtide/tests/{test_glmpass.py → test_linfitfiltpass.py} +9 -9
- rapidtide/tests/test_motionregress.py +3 -3
- rapidtide/tests/test_refinedelay.py +14 -12
- rapidtide/tidepoolTemplate_alt_qt6.py +172 -45
- rapidtide/tidepoolTemplate_big_qt6.py +196 -53
- rapidtide/tidepoolTemplate_qt6.py +150 -39
- rapidtide/workflows/atlasaverage.py +40 -12
- rapidtide/workflows/delayvar.py +1136 -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 +246 -178
- rapidtide/workflows/rapidtide_parser.py +116 -101
- rapidtide/workflows/{glmfrommaps.py → regressfrommaps.py} +30 -26
- rapidtide/workflows/retrolagtcs.py +13 -12
- rapidtide/workflows/{retroglm.py → retroregress.py} +182 -141
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/METADATA +3 -2
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/RECORD +69 -64
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/WHEEL +1 -1
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/entry_points.txt +3 -2
- rapidtide/data/examples/src/testoutputsize +0 -45
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info/licenses}/LICENSE +0 -0
- {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.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,35 +267,57 @@ 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()
|
|
296
297
|
|
|
298
|
+
# save the raw and formatted command lines
|
|
299
|
+
argstowrite = sys.argv
|
|
297
300
|
thecommandline = " ".join(sys.argv[1:])
|
|
301
|
+
tide_io.writevec([thecommandline], f"{outputname}_retrocommandline.txt")
|
|
302
|
+
formattedcommandline = []
|
|
303
|
+
for thetoken in argstowrite[0:3]:
|
|
304
|
+
formattedcommandline.append(thetoken)
|
|
305
|
+
for thetoken in argstowrite[3:]:
|
|
306
|
+
if thetoken[0:2] == "--":
|
|
307
|
+
formattedcommandline.append(thetoken)
|
|
308
|
+
else:
|
|
309
|
+
formattedcommandline[-1] += " " + thetoken
|
|
310
|
+
for i in range(len(formattedcommandline)):
|
|
311
|
+
if i > 0:
|
|
312
|
+
prefix = " "
|
|
313
|
+
else:
|
|
314
|
+
prefix = ""
|
|
315
|
+
if i < len(formattedcommandline) - 1:
|
|
316
|
+
suffix = " \\"
|
|
317
|
+
else:
|
|
318
|
+
suffix = ""
|
|
319
|
+
formattedcommandline[i] = prefix + formattedcommandline[i] + suffix
|
|
320
|
+
tide_io.writevec(formattedcommandline, f"{outputname}_retroformattedcommandline.txt")
|
|
298
321
|
|
|
299
322
|
if args.nprocs < 1:
|
|
300
323
|
args.nprocs = tide_multiproc.maxcpus()
|
|
@@ -304,12 +327,25 @@ def retroglm(args):
|
|
|
304
327
|
else:
|
|
305
328
|
usesharedmem = True
|
|
306
329
|
|
|
307
|
-
# read the runoptions file
|
|
330
|
+
# read the runoptions file, update if necessary
|
|
308
331
|
print("reading runoptions")
|
|
309
332
|
runoptionsfile = f"{args.datafileroot}_desc-runoptions_info"
|
|
310
333
|
therunoptions = tide_io.readoptionsfile(runoptionsfile)
|
|
334
|
+
sublist = (
|
|
335
|
+
("retroglmcompatible", "retroregresscompatible"),
|
|
336
|
+
("glmthreshval", "regressfiltthreshval"),
|
|
337
|
+
)
|
|
338
|
+
therunoptions["singleproc_regressionfilt"] = False
|
|
339
|
+
therunoptions["nprocs_regressionfilt"] = args.nprocs
|
|
340
|
+
for subpair in sublist:
|
|
341
|
+
try:
|
|
342
|
+
therunoptions[subpair[1]] = therunoptions[subpair[0]]
|
|
343
|
+
print(f"substituting {subpair[1]} for {subpair[0]} in runoptions")
|
|
344
|
+
except KeyError:
|
|
345
|
+
pass
|
|
346
|
+
|
|
311
347
|
try:
|
|
312
|
-
|
|
348
|
+
candoretroregress = therunoptions["retroregresscompatible"]
|
|
313
349
|
except KeyError:
|
|
314
350
|
print(
|
|
315
351
|
f"based on {runoptionsfile}, this rapidtide dataset does not support retrospective GLM calculation"
|
|
@@ -330,7 +366,7 @@ def retroglm(args):
|
|
|
330
366
|
else:
|
|
331
367
|
rt_outfloattype = "float32"
|
|
332
368
|
rt_outfloatset = np.float32
|
|
333
|
-
therunoptions["
|
|
369
|
+
therunoptions["saveminimumsLFOfiltfiles"] = args.saveminimumsLFOfiltfiles
|
|
334
370
|
|
|
335
371
|
# read the fmri input files
|
|
336
372
|
print("reading fmrifile")
|
|
@@ -363,7 +399,7 @@ def retroglm(args):
|
|
|
363
399
|
if not tide_io.checkspacematch(fmri_header, procmask_header):
|
|
364
400
|
raise ValueError("procmask dimensions do not match fmri dimensions")
|
|
365
401
|
procmask_spacebytime = procmask.reshape((numspatiallocs))
|
|
366
|
-
if args.debug
|
|
402
|
+
if args.debug:
|
|
367
403
|
print(f"{procmask_spacebytime.shape=}")
|
|
368
404
|
print(f"{tide_stats.getmasksize(procmask_spacebytime)=}")
|
|
369
405
|
|
|
@@ -380,7 +416,7 @@ def retroglm(args):
|
|
|
380
416
|
if not tide_io.checkspacematch(fmri_header, corrmask_header):
|
|
381
417
|
raise ValueError("corrmask dimensions do not match fmri dimensions")
|
|
382
418
|
corrmask_spacebytime = corrmask.reshape((numspatiallocs))
|
|
383
|
-
if args.debug
|
|
419
|
+
if args.debug:
|
|
384
420
|
print(f"{corrmask_spacebytime.shape=}")
|
|
385
421
|
print(f"{tide_stats.getmasksize(corrmask_spacebytime)=}")
|
|
386
422
|
|
|
@@ -442,19 +478,19 @@ def retroglm(args):
|
|
|
442
478
|
print("figuring out valid voxels")
|
|
443
479
|
validvoxels = np.where(procmask_spacebytime > 0)[0]
|
|
444
480
|
numvalidspatiallocs = np.shape(validvoxels)[0]
|
|
445
|
-
if args.debug
|
|
481
|
+
if args.debug:
|
|
446
482
|
print(f"{numvalidspatiallocs=}")
|
|
447
483
|
internalvalidspaceshape = numvalidspatiallocs
|
|
448
484
|
if args.refinedelay:
|
|
449
|
-
derivaxissize = np.max([args.
|
|
485
|
+
derivaxissize = np.max([args.refineregressderivs + 1, args.regressderivs + 1])
|
|
450
486
|
else:
|
|
451
|
-
derivaxissize = args.
|
|
487
|
+
derivaxissize = args.regressderivs + 1
|
|
452
488
|
internalvalidspaceshapederivs = (
|
|
453
489
|
internalvalidspaceshape,
|
|
454
490
|
derivaxissize,
|
|
455
491
|
)
|
|
456
492
|
internalvalidfmrishape = (numvalidspatiallocs, np.shape(initial_fmri_x)[0])
|
|
457
|
-
if args.debug
|
|
493
|
+
if args.debug:
|
|
458
494
|
print(f"validvoxels shape = {numvalidspatiallocs}")
|
|
459
495
|
print(f"internalvalidfmrishape shape = {internalvalidfmrishape}")
|
|
460
496
|
|
|
@@ -470,7 +506,9 @@ def retroglm(args):
|
|
|
470
506
|
if usesharedmem:
|
|
471
507
|
if args.debug:
|
|
472
508
|
print("allocating shared memory")
|
|
473
|
-
|
|
509
|
+
sLFOfitmean, sLFOfitmean_shm = tide_util.allocshared(
|
|
510
|
+
internalvalidspaceshape, rt_outfloatset
|
|
511
|
+
)
|
|
474
512
|
rvalue, rvalue_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
|
|
475
513
|
r2value, r2value_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
|
|
476
514
|
fitNorm, fitNorm_shm = tide_util.allocshared(internalvalidspaceshapederivs, rt_outfloatset)
|
|
@@ -488,7 +526,7 @@ def retroglm(args):
|
|
|
488
526
|
else:
|
|
489
527
|
if args.debug:
|
|
490
528
|
print("allocating memory")
|
|
491
|
-
|
|
529
|
+
sLFOfitmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
492
530
|
rvalue = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
493
531
|
r2value = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
|
|
494
532
|
fitNorm = np.zeros(internalvalidspaceshapederivs, dtype=rt_outfloattype)
|
|
@@ -499,7 +537,7 @@ def retroglm(args):
|
|
|
499
537
|
ramlocation = "locally"
|
|
500
538
|
|
|
501
539
|
totalbytes = (
|
|
502
|
-
|
|
540
|
+
sLFOfitmean.nbytes
|
|
503
541
|
+ rvalue.nbytes
|
|
504
542
|
+ r2value.nbytes
|
|
505
543
|
+ fitNorm.nbytes
|
|
@@ -518,13 +556,13 @@ def retroglm(args):
|
|
|
518
556
|
print(f"{outputname=}")
|
|
519
557
|
oversamptr = fmritr / oversampfactor
|
|
520
558
|
try:
|
|
521
|
-
threshval = therunoptions["
|
|
559
|
+
threshval = therunoptions["regressfiltthreshval"]
|
|
522
560
|
except KeyError:
|
|
523
561
|
threshval = 0.0
|
|
524
|
-
therunoptions["
|
|
562
|
+
therunoptions["regressfiltthreshval"] = threshval
|
|
525
563
|
mode = "glm"
|
|
526
564
|
|
|
527
|
-
if args.debug
|
|
565
|
+
if args.debug:
|
|
528
566
|
print(f"{validvoxels.shape=}")
|
|
529
567
|
np.savetxt(f"{outputname}_validvoxels.txt", validvoxels)
|
|
530
568
|
|
|
@@ -556,7 +594,7 @@ def retroglm(args):
|
|
|
556
594
|
"inputdata",
|
|
557
595
|
"bold",
|
|
558
596
|
None,
|
|
559
|
-
"fMRI data that will be subjected to
|
|
597
|
+
"fMRI data that will be subjected to sLFO filtering",
|
|
560
598
|
),
|
|
561
599
|
]
|
|
562
600
|
tide_io.savemaplist(
|
|
@@ -583,7 +621,7 @@ def retroglm(args):
|
|
|
583
621
|
args.delayoffsetgausssigma = np.mean([xdim, ydim, slicedim]) / 2.0
|
|
584
622
|
|
|
585
623
|
TimingLGR.info("Refinement calibration start")
|
|
586
|
-
|
|
624
|
+
regressderivratios, regressrvalues = tide_refinedelay.getderivratios(
|
|
587
625
|
fmri_data_valid,
|
|
588
626
|
validvoxels,
|
|
589
627
|
initial_fmri_x,
|
|
@@ -593,25 +631,25 @@ def retroglm(args):
|
|
|
593
631
|
mode,
|
|
594
632
|
outputname,
|
|
595
633
|
oversamptr,
|
|
596
|
-
|
|
634
|
+
sLFOfitmean,
|
|
597
635
|
rvalue,
|
|
598
636
|
r2value,
|
|
599
|
-
fitNorm[:, : (args.
|
|
600
|
-
fitcoeff[:, : (args.
|
|
637
|
+
fitNorm[:, : (args.refineregressderivs + 1)],
|
|
638
|
+
fitcoeff[:, : (args.refineregressderivs + 1)],
|
|
601
639
|
movingsignal,
|
|
602
640
|
lagtc,
|
|
603
641
|
filtereddata,
|
|
604
642
|
LGR,
|
|
605
643
|
TimingLGR,
|
|
606
644
|
therunoptions,
|
|
607
|
-
|
|
645
|
+
regressderivs=args.refineregressderivs,
|
|
608
646
|
debug=args.debug,
|
|
609
647
|
)
|
|
610
648
|
|
|
611
|
-
if args.
|
|
612
|
-
|
|
649
|
+
if args.refineregressderivs == 1:
|
|
650
|
+
medfiltregressderivratios, filteredregressderivratios, delayoffsetMAD = (
|
|
613
651
|
tide_refinedelay.filterderivratios(
|
|
614
|
-
|
|
652
|
+
regressderivratios,
|
|
615
653
|
(xsize, ysize, numslices),
|
|
616
654
|
validvoxels,
|
|
617
655
|
(xdim, ydim, slicedim),
|
|
@@ -639,49 +677,53 @@ def retroglm(args):
|
|
|
639
677
|
|
|
640
678
|
# now calculate the delay offsets
|
|
641
679
|
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(
|
|
680
|
+
delayoffset = np.zeros_like(filteredregressderivratios)
|
|
681
|
+
if args.debug:
|
|
682
|
+
print(f"calculating delayoffsets for {filteredregressderivratios.shape[0]} voxels")
|
|
683
|
+
for i in range(filteredregressderivratios.shape[0]):
|
|
684
|
+
delayoffset[i], closestoffset = tide_refinedelay.ratiotodelay(
|
|
685
|
+
filteredregressderivratios[i]
|
|
686
|
+
)
|
|
647
687
|
"""delayoffset[i] = tide_refinedelay.coffstodelay(
|
|
648
|
-
np.asarray([
|
|
688
|
+
np.asarray([filteredregressderivratios[i]]),
|
|
649
689
|
mindelay=args.mindelay,
|
|
650
690
|
maxdelay=args.maxdelay,
|
|
651
691
|
)"""
|
|
652
692
|
|
|
653
|
-
refinedvoxelstoreport =
|
|
693
|
+
refinedvoxelstoreport = filteredregressderivratios.shape[0]
|
|
654
694
|
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
|
-
|
|
695
|
+
medfiltregressderivratios = np.zeros_like(regressderivratios)
|
|
696
|
+
filteredregressderivratios = np.zeros_like(regressderivratios)
|
|
697
|
+
delayoffsetMAD = np.zeros(args.refineregressderivs, dtype=float)
|
|
698
|
+
for i in range(args.refineregressderivs):
|
|
699
|
+
(
|
|
700
|
+
medfiltregressderivratios[i, :],
|
|
701
|
+
filteredregressderivratios[i, :],
|
|
702
|
+
delayoffsetMAD[i],
|
|
703
|
+
) = tide_refinedelay.filterderivratios(
|
|
704
|
+
regressderivratios[i, :],
|
|
705
|
+
(xsize, ysize, numslices),
|
|
706
|
+
validvoxels,
|
|
707
|
+
(xdim, ydim, slicedim),
|
|
708
|
+
gausssigma=args.delayoffsetgausssigma,
|
|
709
|
+
patchthresh=args.delaypatchthresh,
|
|
710
|
+
fileiscifti=False,
|
|
711
|
+
textio=False,
|
|
712
|
+
rt_floattype=rt_floattype,
|
|
713
|
+
debug=args.debug,
|
|
672
714
|
)
|
|
673
715
|
|
|
674
716
|
# now calculate the delay offsets
|
|
675
|
-
delayoffset = np.zeros_like(
|
|
717
|
+
delayoffset = np.zeros_like(filteredregressderivratios[0, :])
|
|
676
718
|
if args.debug:
|
|
677
|
-
print(f"calculating delayoffsets for {
|
|
678
|
-
for i in range(
|
|
719
|
+
print(f"calculating delayoffsets for {filteredregressderivratios.shape[1]} voxels")
|
|
720
|
+
for i in range(filteredregressderivratios.shape[1]):
|
|
679
721
|
delayoffset[i] = tide_refinedelay.coffstodelay(
|
|
680
|
-
|
|
722
|
+
filteredregressderivratios[:, i],
|
|
681
723
|
mindelay=args.mindelay,
|
|
682
724
|
maxdelay=args.maxdelay,
|
|
683
725
|
)
|
|
684
|
-
refinedvoxelstoreport =
|
|
726
|
+
refinedvoxelstoreport = filteredregressderivratios.shape[1]
|
|
685
727
|
|
|
686
728
|
namesuffix = "_desc-delayoffset_hist"
|
|
687
729
|
tide_stats.makeandsavehistogram(
|
|
@@ -706,16 +748,15 @@ def retroglm(args):
|
|
|
706
748
|
# Delay refinement end
|
|
707
749
|
####################################################
|
|
708
750
|
|
|
709
|
-
# initialrawvariance = tide_math.imagevariance(fmri_data_valid, None, 1.0 / fmritr)
|
|
710
751
|
initialvariance = tide_math.imagevariance(fmri_data_valid, theprefilter, 1.0 / fmritr)
|
|
711
752
|
|
|
712
|
-
print("calling
|
|
713
|
-
TimingLGR.info("Starting
|
|
753
|
+
print("calling regressfrommaps")
|
|
754
|
+
TimingLGR.info("Starting sLFO filtering")
|
|
714
755
|
if args.refinedelay and args.filterwithrefineddelay:
|
|
715
756
|
lagstouse_valid = lagtimesrefined_valid
|
|
716
757
|
else:
|
|
717
758
|
lagstouse_valid = lagtimes_valid
|
|
718
|
-
|
|
759
|
+
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
719
760
|
fmri_data_valid,
|
|
720
761
|
validvoxels,
|
|
721
762
|
initial_fmri_x,
|
|
@@ -725,29 +766,29 @@ def retroglm(args):
|
|
|
725
766
|
mode,
|
|
726
767
|
outputname,
|
|
727
768
|
oversamptr,
|
|
728
|
-
|
|
769
|
+
sLFOfitmean,
|
|
729
770
|
rvalue,
|
|
730
771
|
r2value,
|
|
731
|
-
fitNorm[:, : args.
|
|
732
|
-
fitcoeff[:, : args.
|
|
772
|
+
fitNorm[:, : args.regressderivs + 1],
|
|
773
|
+
fitcoeff[:, : args.regressderivs + 1],
|
|
733
774
|
movingsignal,
|
|
734
775
|
lagtc,
|
|
735
776
|
filtereddata,
|
|
736
777
|
LGR,
|
|
737
778
|
TimingLGR,
|
|
738
779
|
threshval,
|
|
739
|
-
args.
|
|
780
|
+
args.saveminimumsLFOfiltfiles,
|
|
740
781
|
nprocs_makelaggedtcs=args.nprocs,
|
|
741
|
-
|
|
742
|
-
|
|
782
|
+
nprocs_regressionfilt=args.nprocs,
|
|
783
|
+
regressderivs=args.regressderivs,
|
|
743
784
|
showprogressbar=args.showprogressbar,
|
|
744
785
|
debug=args.debug,
|
|
745
786
|
)
|
|
746
|
-
print(f"filtered {
|
|
787
|
+
print(f"filtered {voxelsprocessed_regressionfilt} voxels")
|
|
747
788
|
TimingLGR.info(
|
|
748
|
-
"
|
|
789
|
+
"sLFO filtering done",
|
|
749
790
|
{
|
|
750
|
-
"message2":
|
|
791
|
+
"message2": voxelsprocessed_regressionfilt,
|
|
751
792
|
"message3": "voxels",
|
|
752
793
|
},
|
|
753
794
|
)
|
|
@@ -810,7 +851,7 @@ def retroglm(args):
|
|
|
810
851
|
# "Change in total variance after filtering, in percent",
|
|
811
852
|
# ),
|
|
812
853
|
]
|
|
813
|
-
if args.
|
|
854
|
+
if args.saveminimumsLFOfiltfiles:
|
|
814
855
|
maplist += [
|
|
815
856
|
(
|
|
816
857
|
r2value,
|
|
@@ -820,10 +861,10 @@ def retroglm(args):
|
|
|
820
861
|
"Squared R value of the GLM fit (proportion of variance explained)",
|
|
821
862
|
),
|
|
822
863
|
]
|
|
823
|
-
if args.
|
|
864
|
+
if args.savenormalsLFOfiltfiles:
|
|
824
865
|
maplist += [
|
|
825
|
-
(
|
|
826
|
-
(
|
|
866
|
+
(rvalue, "lfofilterR", "map", None, "R value of the GLM fit"),
|
|
867
|
+
(sLFOfitmean, "lfofilterMean", "map", None, "Intercept from GLM fit"),
|
|
827
868
|
]
|
|
828
869
|
else:
|
|
829
870
|
maplist = [
|
|
@@ -831,7 +872,7 @@ def retroglm(args):
|
|
|
831
872
|
(finalvariance, "lfofilterInbandVarianceAfter", "map", None),
|
|
832
873
|
(varchange, "CVRVariance", "map", None),
|
|
833
874
|
]
|
|
834
|
-
if args.
|
|
875
|
+
if args.savenormalsLFOfiltfiles:
|
|
835
876
|
maplist += [
|
|
836
877
|
(rvalue, "CVRR", "map", None),
|
|
837
878
|
(r2value, "CVRR2", "map", None),
|
|
@@ -851,13 +892,13 @@ def retroglm(args):
|
|
|
851
892
|
(corrmask_valid, "corrfitREAD", "mask", None, "Correlation mask used for calculation"),
|
|
852
893
|
(procmask_valid, "processedREAD", "mask", None, "Processed mask used for calculation"),
|
|
853
894
|
]
|
|
854
|
-
if args.
|
|
855
|
-
if args.
|
|
895
|
+
if args.savenormalsLFOfiltfiles:
|
|
896
|
+
if args.regressderivs > 0 or args.refinedelay:
|
|
856
897
|
maplist += [
|
|
857
898
|
(fitcoeff[:, 0], "lfofilterCoeff", "map", None, "Fit coefficient"),
|
|
858
899
|
(fitNorm[:, 0], "lfofilterNorm", "map", None, "Normalized fit coefficient"),
|
|
859
900
|
]
|
|
860
|
-
for thederiv in range(1, args.
|
|
901
|
+
for thederiv in range(1, args.regressderivs + 1):
|
|
861
902
|
maplist += [
|
|
862
903
|
(
|
|
863
904
|
fitcoeff[:, thederiv],
|
|
@@ -881,53 +922,53 @@ def retroglm(args):
|
|
|
881
922
|
]
|
|
882
923
|
|
|
883
924
|
if args.refinedelay:
|
|
884
|
-
if args.
|
|
885
|
-
for i in range(args.
|
|
925
|
+
if args.refineregressderivs > 1:
|
|
926
|
+
for i in range(args.refineregressderivs):
|
|
886
927
|
maplist += [
|
|
887
928
|
(
|
|
888
|
-
|
|
889
|
-
f"
|
|
929
|
+
regressderivratios[i, :],
|
|
930
|
+
f"regressderivratios_{i}",
|
|
890
931
|
"map",
|
|
891
932
|
None,
|
|
892
933
|
f"Ratio of derivative {i+1} of delayed sLFO to the delayed sLFO",
|
|
893
934
|
),
|
|
894
935
|
(
|
|
895
|
-
|
|
896
|
-
f"
|
|
936
|
+
medfiltregressderivratios[i, :],
|
|
937
|
+
f"medfiltregressderivratios_{i}",
|
|
897
938
|
"map",
|
|
898
939
|
None,
|
|
899
|
-
f"Median filtered version of the
|
|
940
|
+
f"Median filtered version of the regressderivratios_{i} map",
|
|
900
941
|
),
|
|
901
942
|
(
|
|
902
|
-
|
|
903
|
-
f"
|
|
943
|
+
filteredregressderivratios[i, :],
|
|
944
|
+
f"filteredregressderivratios_{i}",
|
|
904
945
|
"map",
|
|
905
946
|
None,
|
|
906
|
-
f"
|
|
947
|
+
f"regressderivratios_{i}, with outliers patched using median filtered data",
|
|
907
948
|
),
|
|
908
949
|
]
|
|
909
950
|
else:
|
|
910
951
|
maplist += [
|
|
911
952
|
(
|
|
912
|
-
|
|
913
|
-
"
|
|
953
|
+
regressderivratios,
|
|
954
|
+
"regressderivratios",
|
|
914
955
|
"map",
|
|
915
956
|
None,
|
|
916
957
|
"Ratio of the first derivative of delayed sLFO to the delayed sLFO",
|
|
917
958
|
),
|
|
918
959
|
(
|
|
919
|
-
|
|
920
|
-
"
|
|
960
|
+
medfiltregressderivratios,
|
|
961
|
+
"medfiltregressderivratios",
|
|
921
962
|
"map",
|
|
922
963
|
None,
|
|
923
|
-
"Median filtered version of the
|
|
964
|
+
"Median filtered version of the regressderivratios map",
|
|
924
965
|
),
|
|
925
966
|
(
|
|
926
|
-
|
|
927
|
-
"
|
|
967
|
+
filteredregressderivratios,
|
|
968
|
+
"filteredregressderivratios",
|
|
928
969
|
"map",
|
|
929
970
|
None,
|
|
930
|
-
"
|
|
971
|
+
"regressderivratios, with outliers patched using median filtered data",
|
|
931
972
|
),
|
|
932
973
|
]
|
|
933
974
|
maplist += [
|
|
@@ -961,7 +1002,7 @@ def retroglm(args):
|
|
|
961
1002
|
# write the 4D maps
|
|
962
1003
|
theheader = copy.deepcopy(fmri_header)
|
|
963
1004
|
maplist = []
|
|
964
|
-
if args.
|
|
1005
|
+
if args.saveminimumsLFOfiltfiles:
|
|
965
1006
|
maplist = [
|
|
966
1007
|
(
|
|
967
1008
|
filtereddata,
|
|
@@ -982,8 +1023,8 @@ def retroglm(args):
|
|
|
982
1023
|
)
|
|
983
1024
|
]
|
|
984
1025
|
|
|
985
|
-
if args.
|
|
986
|
-
if args.
|
|
1026
|
+
if args.saveallsLFOfiltfiles:
|
|
1027
|
+
if args.regressderivs > 0:
|
|
987
1028
|
if args.debug:
|
|
988
1029
|
print("going down the multiple EV path")
|
|
989
1030
|
print(f"{regressorset[:, :, 0].shape=}")
|
|
@@ -996,7 +1037,7 @@ def retroglm(args):
|
|
|
996
1037
|
"Shifted sLFO regressor to filter",
|
|
997
1038
|
),
|
|
998
1039
|
]
|
|
999
|
-
for thederiv in range(1, args.
|
|
1040
|
+
for thederiv in range(1, args.regressderivs + 1):
|
|
1000
1041
|
if args.debug:
|
|
1001
1042
|
print(f"{regressorset[:, :, thederiv].shape=}")
|
|
1002
1043
|
maplist += [
|
|
@@ -1058,7 +1099,7 @@ def retroglm(args):
|
|
|
1058
1099
|
)
|
|
1059
1100
|
TimingLGR.info("Filtering for maxcorralt calculation complete")
|
|
1060
1101
|
TimingLGR.info("GLM for maxcorralt calculation start")
|
|
1061
|
-
|
|
1102
|
+
voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
|
|
1062
1103
|
fmri_data_valid,
|
|
1063
1104
|
validvoxels,
|
|
1064
1105
|
initial_fmri_x,
|
|
@@ -1068,28 +1109,28 @@ def retroglm(args):
|
|
|
1068
1109
|
mode,
|
|
1069
1110
|
outputname,
|
|
1070
1111
|
oversamptr,
|
|
1071
|
-
|
|
1112
|
+
sLFOfitmean,
|
|
1072
1113
|
rvalue,
|
|
1073
1114
|
r2value,
|
|
1074
|
-
fitNorm[:, : args.
|
|
1075
|
-
fitcoeff[:, : args.
|
|
1115
|
+
fitNorm[:, : args.regressderivs + 1],
|
|
1116
|
+
fitcoeff[:, : args.regressderivs + 1],
|
|
1076
1117
|
movingsignal,
|
|
1077
1118
|
lagtc,
|
|
1078
1119
|
filtereddata,
|
|
1079
1120
|
LGR,
|
|
1080
1121
|
TimingLGR,
|
|
1081
1122
|
threshval,
|
|
1082
|
-
args.
|
|
1123
|
+
args.saveminimumsLFOfiltfiles,
|
|
1083
1124
|
nprocs_makelaggedtcs=args.nprocs,
|
|
1084
|
-
|
|
1085
|
-
|
|
1125
|
+
nprocs_regressionfilt=args.nprocs,
|
|
1126
|
+
regressderivs=args.regressderivs,
|
|
1086
1127
|
showprogressbar=args.showprogressbar,
|
|
1087
1128
|
debug=args.debug,
|
|
1088
1129
|
)
|
|
1089
1130
|
TimingLGR.info(
|
|
1090
1131
|
"GLM for maxcorralt calculation done",
|
|
1091
1132
|
{
|
|
1092
|
-
"message2":
|
|
1133
|
+
"message2": voxelsprocessed_regressionfilt,
|
|
1093
1134
|
"message3": "voxels",
|
|
1094
1135
|
},
|
|
1095
1136
|
)
|
|
@@ -1144,15 +1185,15 @@ def retroglm(args):
|
|
|
1144
1185
|
# read the runoptions file
|
|
1145
1186
|
print("writing runoptions")
|
|
1146
1187
|
if args.refinedelay:
|
|
1147
|
-
therunoptions["
|
|
1148
|
-
therunoptions["
|
|
1188
|
+
therunoptions["retroregress_delayoffsetMAD"] = delayoffsetMAD
|
|
1189
|
+
therunoptions["retroregress_runtime"] = time.strftime(
|
|
1149
1190
|
"%a, %d %b %Y %H:%M:%S %Z", time.localtime(time.time())
|
|
1150
1191
|
)
|
|
1151
1192
|
|
|
1152
1193
|
# clean up shared memory
|
|
1153
1194
|
if usesharedmem:
|
|
1154
1195
|
TimingLGR.info("Shared memory cleanup start")
|
|
1155
|
-
tide_util.cleanup_shm(
|
|
1196
|
+
tide_util.cleanup_shm(sLFOfitmean_shm)
|
|
1156
1197
|
tide_util.cleanup_shm(rvalue_shm)
|
|
1157
1198
|
tide_util.cleanup_shm(r2value_shm)
|
|
1158
1199
|
tide_util.cleanup_shm(fitNorm_shm)
|
|
@@ -1160,7 +1201,7 @@ def retroglm(args):
|
|
|
1160
1201
|
tide_util.cleanup_shm(movingsignal_shm)
|
|
1161
1202
|
tide_util.cleanup_shm(lagtc_shm)
|
|
1162
1203
|
tide_util.cleanup_shm(filtereddata_shm)
|
|
1163
|
-
|
|
1204
|
+
TimingLGR.info("Shared memory cleanup complete")
|
|
1164
1205
|
|
|
1165
1206
|
# shut down logging
|
|
1166
1207
|
TimingLGR.info("Done")
|
|
@@ -1195,7 +1236,7 @@ def retroglm(args):
|
|
|
1195
1236
|
|
|
1196
1237
|
def process_args(inputargs=None):
|
|
1197
1238
|
"""
|
|
1198
|
-
Compile arguments for
|
|
1239
|
+
Compile arguments for retroregress workflow.
|
|
1199
1240
|
"""
|
|
1200
1241
|
args, argstowrite = pf.setargs(_get_parser, inputargs=inputargs)
|
|
1201
1242
|
return args
|