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.
Files changed (62) hide show
  1. cloud/gmscalc-HCPYA +1 -1
  2. cloud/rapidtide-HCPYA +3 -3
  3. rapidtide/Colortables.py +10 -10
  4. rapidtide/DerivativeDelay.py +211 -0
  5. rapidtide/{Refiner.py → RegressorRefiner.py} +1 -1
  6. rapidtide/__init__.py +2 -1
  7. rapidtide/_version.py +1 -1
  8. rapidtide/data/examples/src/test_mlregressallt.py +32 -17
  9. rapidtide/data/examples/src/testalign +1 -1
  10. rapidtide/data/examples/src/testboth +1 -1
  11. rapidtide/data/examples/src/testcifti +11 -0
  12. rapidtide/data/examples/src/testdelayvar +13 -0
  13. rapidtide/data/examples/src/testfmri +1 -0
  14. rapidtide/data/examples/src/testglmfilt +8 -6
  15. rapidtide/data/examples/src/testhappy +1 -1
  16. rapidtide/data/examples/src/testnewrefine +11 -11
  17. rapidtide/data/examples/src/testnoiseamp +2 -2
  18. rapidtide/data/examples/src/testretro +16 -7
  19. rapidtide/data/examples/src/testretrolagtcs +1 -1
  20. rapidtide/dlfilter.py +0 -1
  21. rapidtide/fit.py +41 -9
  22. rapidtide/happy_supportfuncs.py +5 -0
  23. rapidtide/io.py +13 -2
  24. rapidtide/{glmpass.py → linfitfiltpass.py} +21 -19
  25. rapidtide/refinedelay.py +96 -58
  26. rapidtide/resample.py +3 -0
  27. rapidtide/scripts/{retroglm.py → delayvar.py} +2 -2
  28. rapidtide/scripts/{glmfilt.py → linfitfilt.py} +2 -2
  29. rapidtide/scripts/retroregress.py +28 -0
  30. rapidtide/scripts/stupidramtricks.py +9 -7
  31. rapidtide/simfuncfit.py +1 -1
  32. rapidtide/tests/cleanposttest +21 -0
  33. rapidtide/tests/test_delayestimation.py +3 -3
  34. rapidtide/tests/test_fastresampler.py +1 -2
  35. rapidtide/tests/test_fullrunhappy_v1.py +1 -1
  36. rapidtide/tests/test_fullrunhappy_v2.py +1 -1
  37. rapidtide/tests/test_fullrunrapidtide_v1.py +2 -2
  38. rapidtide/tests/test_fullrunrapidtide_v3.py +1 -1
  39. rapidtide/tests/test_fullrunrapidtide_v5.py +1 -1
  40. rapidtide/tests/test_fullrunrapidtide_v6.py +11 -11
  41. rapidtide/tests/{test_glmpass.py → test_linfitfiltpass.py} +9 -9
  42. rapidtide/tests/test_motionregress.py +3 -3
  43. rapidtide/tests/test_refinedelay.py +12 -12
  44. rapidtide/tidepoolTemplate_alt_qt6.py +172 -45
  45. rapidtide/tidepoolTemplate_big_qt6.py +196 -53
  46. rapidtide/tidepoolTemplate_qt6.py +150 -39
  47. rapidtide/workflows/delayvar.py +1048 -0
  48. rapidtide/workflows/happy.py +37 -11
  49. rapidtide/workflows/happy_parser.py +4 -4
  50. rapidtide/workflows/{glmfilt.py → linfitfilt.py} +4 -4
  51. rapidtide/workflows/rapidtide.py +235 -171
  52. rapidtide/workflows/rapidtide_parser.py +103 -86
  53. rapidtide/workflows/{glmfrommaps.py → regressfrommaps.py} +28 -26
  54. rapidtide/workflows/retrolagtcs.py +12 -12
  55. rapidtide/workflows/{retroglm.py → retroregress.py} +158 -141
  56. {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/METADATA +3 -2
  57. {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/RECORD +61 -56
  58. {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/WHEEL +1 -1
  59. {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/entry_points.txt +3 -2
  60. rapidtide/data/examples/src/testoutputsize +0 -45
  61. {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info/licenses}/LICENSE +0 -0
  62. {rapidtide-3.0a12.dist-info → rapidtide-3.0a13.dist-info}/top_level.txt +0 -0
@@ -37,22 +37,22 @@ import rapidtide.calcsimfunc as tide_calcsimfunc
37
37
  import rapidtide.correlate as tide_corr
38
38
  import rapidtide.filter as tide_filt
39
39
  import rapidtide.fit as tide_fit
40
- import rapidtide.glmpass as tide_glmpass
41
40
  import rapidtide.helper_classes as tide_classes
42
41
  import rapidtide.io as tide_io
42
+ import rapidtide.linfitfiltpass as tide_linfitfiltpass
43
43
  import rapidtide.maskutil as tide_mask
44
44
  import rapidtide.miscmath as tide_math
45
45
  import rapidtide.multiproc as tide_multiproc
46
46
  import rapidtide.patchmatch as tide_patch
47
47
  import rapidtide.peakeval as tide_peakeval
48
48
  import rapidtide.refinedelay as tide_refinedelay
49
- import rapidtide.Refiner as tide_refiner
49
+ import rapidtide.RegressorRefiner as tide_regrefiner
50
50
  import rapidtide.resample as tide_resample
51
51
  import rapidtide.simfuncfit as tide_simfuncfit
52
52
  import rapidtide.stats as tide_stats
53
53
  import rapidtide.util as tide_util
54
54
  import rapidtide.wiener as tide_wiener
55
- import rapidtide.workflows.glmfrommaps as tide_glmfrommaps
55
+ import rapidtide.workflows.regressfrommaps as tide_regressfrommaps
56
56
  from rapidtide.tests.utils import mse
57
57
 
58
58
  from .utils import setup_logger
@@ -382,10 +382,10 @@ def rapidtide_main(argparsingfunc):
382
382
  else:
383
383
  optiondict["nprocs_makelaggedtcs"] = optiondict["nprocs"]
384
384
 
385
- if optiondict["singleproc_glm"]:
386
- optiondict["nprocs_glm"] = 1
385
+ if optiondict["singleproc_regressionfilt"]:
386
+ optiondict["nprocs_regressionfilt"] = 1
387
387
  else:
388
- optiondict["nprocs_glm"] = optiondict["nprocs"]
388
+ optiondict["nprocs_regressionfilt"] = optiondict["nprocs"]
389
389
 
390
390
  # set the number of MKL threads to use
391
391
  if mklexists:
@@ -889,7 +889,7 @@ def rapidtide_main(argparsingfunc):
889
889
  mergedregressorlabels,
890
890
  fmri_data_valid,
891
891
  confoundr2,
892
- ) = tide_glmpass.confoundregress(
892
+ ) = tide_linfitfiltpass.confoundregress(
893
893
  mergedregressors,
894
894
  mergedregressorlabels,
895
895
  fmri_data_valid,
@@ -961,7 +961,7 @@ def rapidtide_main(argparsingfunc):
961
961
  )
962
962
  if optiondict["memprofile"]:
963
963
  memcheckpoint("...done")
964
- tide_util.logmem("after confound glm filter")
964
+ tide_util.logmem("after confound sLFO filter")
965
965
 
966
966
  if optiondict["saveconfoundfiltered"]:
967
967
  if not optiondict["textio"]:
@@ -1736,7 +1736,7 @@ def rapidtide_main(argparsingfunc):
1736
1736
  or optiondict["convergencethresh"] is not None
1737
1737
  ):
1738
1738
  # we will be doing regressor refinement, so set that up
1739
- theRegressorRefiner = tide_refiner.Refiner(
1739
+ theRegressorRefiner = tide_regrefiner.RegressorRefiner(
1740
1740
  internalvalidfmrishape,
1741
1741
  internalvalidpaddedfmrishape,
1742
1742
  optiondict["pid"],
@@ -1948,7 +1948,7 @@ def rapidtide_main(argparsingfunc):
1948
1948
  )
1949
1949
 
1950
1950
  # regress out
1951
- resampref_y, datatoremove, R, dummy = tide_fit.glmfilt(
1951
+ resampref_y, datatoremove, R, dummy = tide_fit.linfitfilt(
1952
1952
  resampref_y, shiftednoise, debug=True
1953
1953
  )
1954
1954
 
@@ -3155,20 +3155,20 @@ def rapidtide_main(argparsingfunc):
3155
3155
  tide_util.cleanup_shm(wpeak_shm)
3156
3156
 
3157
3157
  ####################################################
3158
- # GLM filtering start
3158
+ # Linear regression filtering start
3159
3159
  ####################################################
3160
- # Post refinement step 1 - GLM fitting, either to remove moving signal, or to calculate delayed CVR
3160
+ # Post refinement step 1 - regression fitting, either to remove moving signal, or to calculate delayed CVR
3161
3161
  # write out the current version of the run options
3162
- optiondict["currentstage"] = "preglm"
3162
+ optiondict["currentstage"] = "presLFOfit"
3163
3163
  tide_io.writedicttojson(optiondict, f"{outputname}_desc-runoptions_info.json")
3164
- if optiondict["doglmfilt"] or optiondict["docvrmap"] or optiondict["refinedelay"]:
3165
- if optiondict["doglmfilt"]:
3164
+ if optiondict["dolinfitfilt"] or optiondict["docvrmap"] or optiondict["refinedelay"]:
3165
+ if optiondict["dolinfitfilt"]:
3166
3166
  if optiondict["refinedelay"]:
3167
- TimingLGR.info("Setting up for delay refinement and GLM filtering")
3168
- LGR.info("\n\nDelay refinement and GLM filtering setup")
3167
+ TimingLGR.info("Setting up for delay refinement and sLFO filtering")
3168
+ LGR.info("\n\nDelay refinement and sLFO filtering setup")
3169
3169
  else:
3170
- TimingLGR.info("Setting up for GLM filtering")
3171
- LGR.info("\n\nGLM filtering setup")
3170
+ TimingLGR.info("Setting up for sLFO filtering")
3171
+ LGR.info("\n\nsLFO filtering setup")
3172
3172
  elif optiondict["docvrmap"]:
3173
3173
  if optiondict["refinedelay"]:
3174
3174
  TimingLGR.info("Setting up for delay refinement and CVR map generation")
@@ -3181,14 +3181,16 @@ def rapidtide_main(argparsingfunc):
3181
3181
  LGR.info("\n\nDelay refinement setup")
3182
3182
  if (
3183
3183
  (optiondict["gausssigma"] > 0.0)
3184
- or (optiondict["glmsourcefile"] is not None)
3184
+ or (optiondict["denoisesourcefile"] is not None)
3185
3185
  or optiondict["docvrmap"]
3186
3186
  ):
3187
- if optiondict["glmsourcefile"] is not None:
3188
- LGR.info(f"reading in {optiondict['glmsourcefile']} for GLM filter, please wait")
3189
- sourcename = optiondict["glmsourcefile"]
3187
+ if optiondict["denoisesourcefile"] is not None:
3188
+ LGR.info(
3189
+ f"reading in {optiondict['denoisesourcefile']} for sLFO filter, please wait"
3190
+ )
3191
+ sourcename = optiondict["denoisesourcefile"]
3190
3192
  else:
3191
- LGR.info(f"rereading {fmrifilename} for GLM filter, please wait")
3193
+ LGR.info(f"rereading {fmrifilename} for sLFO filter, please wait")
3192
3194
  sourcename = fmrifilename
3193
3195
  if fileiscifti:
3194
3196
  LGR.info("input file is CIFTI")
@@ -3235,28 +3237,30 @@ def rapidtide_main(argparsingfunc):
3235
3237
  numpy2shared_func = addmemprofiling(
3236
3238
  tide_util.numpy2shared,
3237
3239
  optiondict["memprofile"],
3238
- "before movetoshared (glm)",
3240
+ "before movetoshared (sLFO filter)",
3239
3241
  )
3240
3242
  fmri_data_valid, fmri_data_valid_shm = numpy2shared_func(
3241
- fmri_data_valid, rt_floatset, name=f"fmri_data_valid_glm_{optiondict['pid']}"
3243
+ fmri_data_valid,
3244
+ rt_floatset,
3245
+ name=f"fmri_data_valid_regressionfilt_{optiondict['pid']}",
3242
3246
  )
3243
3247
  TimingLGR.info("End moving fmri_data to shared memory")
3244
3248
  del nim_data
3245
3249
 
3246
- # now allocate the arrays needed for GLM filtering
3250
+ # now allocate the arrays needed for sLFO filtering
3247
3251
  if optiondict["refinedelay"]:
3248
3252
  derivaxissize = np.max(
3249
- [optiondict["refineglmderivs"] + 1, optiondict["glmderivs"] + 1]
3253
+ [optiondict["refineregressderivs"] + 1, optiondict["regressderivs"] + 1]
3250
3254
  )
3251
3255
  else:
3252
- derivaxissize = optiondict["glmderivs"] + 1
3256
+ derivaxissize = optiondict["regressderivs"] + 1
3253
3257
  internalvalidspaceshapederivs = (
3254
3258
  internalvalidspaceshape,
3255
3259
  derivaxissize,
3256
3260
  )
3257
3261
  if optiondict["sharedmem"]:
3258
- glmmean, glmmean_shm = tide_util.allocshared(
3259
- internalvalidspaceshape, rt_outfloatset, name=f"glmmean_{optiondict['pid']}"
3262
+ sLFOfitmean, sLFOfitmean_shm = tide_util.allocshared(
3263
+ internalvalidspaceshape, rt_outfloatset, name=f"sLFOfitmean_{optiondict['pid']}"
3260
3264
  )
3261
3265
  rvalue, rvalue_shm = tide_util.allocshared(
3262
3266
  internalvalidspaceshape, rt_outfloatset, name=f"rvalue_{optiondict['pid']}"
@@ -3281,7 +3285,7 @@ def rapidtide_main(argparsingfunc):
3281
3285
  )
3282
3286
  ramlocation = "in shared memory"
3283
3287
  else:
3284
- glmmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
3288
+ sLFOfitmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
3285
3289
  rvalue = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
3286
3290
  r2value = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
3287
3291
  fitNorm = np.zeros(internalvalidspaceshapederivs, dtype=rt_outfloattype)
@@ -3291,8 +3295,8 @@ def rapidtide_main(argparsingfunc):
3291
3295
  filtereddata = np.zeros(internalvalidfmrishape, dtype=rt_outfloattype)
3292
3296
  ramlocation = "locally"
3293
3297
 
3294
- optiondict["totalglmbytes"] = (
3295
- glmmean.nbytes
3298
+ optiondict["totalsLFOfilterbytes"] = (
3299
+ sLFOfitmean.nbytes
3296
3300
  + rvalue.nbytes
3297
3301
  + r2value.nbytes
3298
3302
  + fitNorm.nbytes
@@ -3301,25 +3305,25 @@ def rapidtide_main(argparsingfunc):
3301
3305
  + lagtc.nbytes
3302
3306
  + filtereddata.nbytes
3303
3307
  )
3304
- thesize, theunit = tide_util.format_bytes(optiondict["totalglmbytes"])
3305
- print(f"allocated {thesize:.3f} {theunit} {ramlocation} for glm/delay refinement")
3308
+ thesize, theunit = tide_util.format_bytes(optiondict["totalsLFOfilterbytes"])
3309
+ print(f"allocated {thesize:.3f} {theunit} {ramlocation} for sLFO filter/delay refinement")
3306
3310
 
3307
3311
  if optiondict["memprofile"]:
3308
- if optiondict["doglmfilt"]:
3309
- memcheckpoint("about to start glm noise removal...")
3312
+ if optiondict["dolinfitfilt"]:
3313
+ memcheckpoint("about to start sLFO noise removal...")
3310
3314
  else:
3311
3315
  memcheckpoint("about to start CVR magnitude estimation...")
3312
- tide_util.logmem("before glm")
3316
+ tide_util.logmem("before sLFO filter")
3313
3317
 
3314
- if optiondict["doglmfilt"]:
3318
+ if optiondict["dolinfitfilt"]:
3315
3319
  mode = "glm"
3316
- optiondict["glmthreshval"] = threshval
3320
+ optiondict["regressfiltthreshval"] = threshval
3317
3321
  else:
3318
3322
  # set the threshval to zero
3319
3323
  mode = "cvrmap"
3320
- optiondict["glmthreshval"] = 0.0
3324
+ optiondict["regressfiltthreshval"] = 0.0
3321
3325
  if optiondict["debug"]:
3322
- # dump the fmri input file going to glm
3326
+ # dump the fmri input file going to sLFO filter
3323
3327
  if not optiondict["textio"]:
3324
3328
  theheader = copy.deepcopy(nim_hdr)
3325
3329
  if fileiscifti:
@@ -3340,7 +3344,7 @@ def rapidtide_main(argparsingfunc):
3340
3344
  "datatofilter",
3341
3345
  "bold",
3342
3346
  None,
3343
- "fMRI data that will be subjected to GLM filtering",
3347
+ "fMRI data that will be subjected to sLFO filtering",
3344
3348
  ),
3345
3349
  ]
3346
3350
  tide_io.savemaplist(
@@ -3356,7 +3360,7 @@ def rapidtide_main(argparsingfunc):
3356
3360
  cifti_hdr=cifti_hdr,
3357
3361
  )
3358
3362
 
3359
- # refine the delay value prior to calculating the GLM
3363
+ # refine the delay value prior to calculating the sLFO filter
3360
3364
  if optiondict["refinedelay"]:
3361
3365
  TimingLGR.info("Delay refinement start")
3362
3366
  LGR.info("\n\nDelay refinement")
@@ -3364,7 +3368,7 @@ def rapidtide_main(argparsingfunc):
3364
3368
  # set gausssigma automatically
3365
3369
  optiondict["delayoffsetgausssigma"] = np.mean([xdim, ydim, slicethickness]) / 2.0
3366
3370
 
3367
- glmderivratios = tide_refinedelay.getderivratios(
3371
+ regressderivratios, regressrvalues = tide_refinedelay.getderivratios(
3368
3372
  fmri_data_valid,
3369
3373
  validvoxels,
3370
3374
  initial_fmri_x,
@@ -3374,25 +3378,25 @@ def rapidtide_main(argparsingfunc):
3374
3378
  mode,
3375
3379
  outputname,
3376
3380
  oversamptr,
3377
- glmmean,
3381
+ sLFOfitmean,
3378
3382
  rvalue,
3379
3383
  r2value,
3380
- fitNorm[:, : (optiondict["refineglmderivs"] + 1)],
3381
- fitcoeff[:, : (optiondict["refineglmderivs"] + 1)],
3384
+ fitNorm[:, : (optiondict["refineregressderivs"] + 1)],
3385
+ fitcoeff[:, : (optiondict["refineregressderivs"] + 1)],
3382
3386
  movingsignal,
3383
3387
  lagtc,
3384
3388
  filtereddata,
3385
3389
  LGR,
3386
3390
  TimingLGR,
3387
3391
  optiondict,
3388
- glmderivs=optiondict["refineglmderivs"],
3392
+ regressderivs=optiondict["refineregressderivs"],
3389
3393
  debug=optiondict["debug"],
3390
3394
  )
3391
3395
 
3392
- if optiondict["refineglmderivs"] == 1:
3393
- medfiltglmderivratios, filteredglmderivratios, delayoffsetMAD = (
3396
+ if optiondict["refineregressderivs"] == 1:
3397
+ medfiltregressderivratios, filteredregressderivratios, delayoffsetMAD = (
3394
3398
  tide_refinedelay.filterderivratios(
3395
- glmderivratios,
3399
+ regressderivratios,
3396
3400
  nativespaceshape,
3397
3401
  validvoxels,
3398
3402
  (xdim, ydim, slicethickness),
@@ -3406,7 +3410,7 @@ def rapidtide_main(argparsingfunc):
3406
3410
  )
3407
3411
  optiondict["delayoffsetMAD"] = delayoffsetMAD
3408
3412
 
3409
- # find the mapping of glm ratios to delays
3413
+ # find the mapping of derivative ratios to delays
3410
3414
  tide_refinedelay.trainratiotooffset(
3411
3415
  genlagtc,
3412
3416
  initial_fmri_x,
@@ -3419,25 +3423,27 @@ def rapidtide_main(argparsingfunc):
3419
3423
  )
3420
3424
 
3421
3425
  # now calculate the delay offsets
3422
- delayoffset = np.zeros_like(filteredglmderivratios)
3426
+ delayoffset = np.zeros_like(filteredregressderivratios)
3423
3427
  if optiondict["debug"]:
3424
- print(f"calculating delayoffsets for {filteredglmderivratios.shape[0]} voxels")
3425
- for i in range(filteredglmderivratios.shape[0]):
3426
- delayoffset[i] = tide_refinedelay.ratiotodelay(filteredglmderivratios[i])
3428
+ print(
3429
+ f"calculating delayoffsets for {filteredregressderivratios.shape[0]} voxels"
3430
+ )
3431
+ for i in range(filteredregressderivratios.shape[0]):
3432
+ delayoffset[i] = tide_refinedelay.ratiotodelay(filteredregressderivratios[i])
3427
3433
  else:
3428
- medfiltglmderivratios = np.zeros_like(glmderivratios)
3429
- filteredglmderivratios = np.zeros_like(glmderivratios)
3430
- delayoffsetMAD = np.zeros(optiondict["refineglmderivs"], dtype=float)
3431
- for i in range(args.refineglmderivs):
3434
+ medfiltregressderivratios = np.zeros_like(regressderivratios)
3435
+ filteredregressderivratios = np.zeros_like(regressderivratios)
3436
+ delayoffsetMAD = np.zeros(optiondict["refineregressderivs"], dtype=float)
3437
+ for i in range(optiondict["refineregressderivs"]):
3432
3438
  (
3433
- medfiltglmderivratios[i, :],
3434
- filteredglmderivratios[i, :],
3439
+ medfiltregressderivratios[i, :],
3440
+ filteredregressderivratios[i, :],
3435
3441
  delayoffsetMAD[i],
3436
3442
  ) = tide_refinedelay.filterderivratios(
3437
- glmderivratios[i, :],
3443
+ regressderivratios[i, :],
3438
3444
  (xsize, ysize, numslices),
3439
3445
  validvoxels,
3440
- (xdim, ydim, slicedim),
3446
+ (xdim, ydim, slicethickness),
3441
3447
  gausssigma=optiondict["delayoffsetgausssigma"],
3442
3448
  patchthresh=optiondict["delaypatchthresh"],
3443
3449
  fileiscifti=False,
@@ -3448,24 +3454,26 @@ def rapidtide_main(argparsingfunc):
3448
3454
  optiondict[f"delayoffsetMAD_{i + 1}"] = delayoffsetMAD[i]
3449
3455
 
3450
3456
  # now calculate the delay offsets
3451
- delayoffset = np.zeros_like(filteredglmderivratios[0, :])
3457
+ delayoffset = np.zeros_like(filteredregressderivratios[0, :])
3452
3458
  if optiondict["debug"]:
3453
- print(f"calculating delayoffsets for {filteredglmderivratios.shape[1]} voxels")
3454
- for i in range(filteredglmderivratios.shape[1]):
3459
+ print(
3460
+ f"calculating delayoffsets for {filteredregressderivratios.shape[1]} voxels"
3461
+ )
3462
+ for i in range(filteredregressderivratios.shape[1]):
3455
3463
  delayoffset[i] = tide_refinedelay.coffstodelay(
3456
- filteredglmderivratios[:, i],
3464
+ filteredregressderivratios[:, i],
3457
3465
  mindelay=optiondict["mindelay"],
3458
3466
  maxdelay=optiondict["maxdelay"],
3459
3467
  )
3460
3468
 
3461
3469
  namesuffix = "_desc-delayoffset_hist"
3462
- if optiondict["doglmfilt"]:
3470
+ if optiondict["dolinfitfilt"]:
3463
3471
  tide_stats.makeandsavehistogram(
3464
3472
  delayoffset[np.where(fitmask > 0)],
3465
3473
  optiondict["histlen"],
3466
3474
  1,
3467
3475
  outputname + namesuffix,
3468
- displaytitle="Histogram of delay offsets calculated from GLM",
3476
+ displaytitle="Histogram of delay offsets calculated from regression coefficients",
3469
3477
  dictvarname="delayoffsethist",
3470
3478
  thedict=optiondict,
3471
3479
  )
@@ -3475,11 +3483,11 @@ def rapidtide_main(argparsingfunc):
3475
3483
  # Delay refinement end
3476
3484
  ####################################################
3477
3485
 
3478
- # now calculate the GLM or CVR map
3479
- if optiondict["doglmfilt"] or optiondict["docvrmap"]:
3480
- if optiondict["doglmfilt"]:
3481
- TimingLGR.info("GLM filtering start")
3482
- LGR.info("\n\nGLM filtering")
3486
+ # now calculate the sLFO filter or CVR map
3487
+ if optiondict["dolinfitfilt"] or optiondict["docvrmap"]:
3488
+ if optiondict["dolinfitfilt"]:
3489
+ TimingLGR.info("sLFO filtering start")
3490
+ LGR.info("\n\nsLFO filtering")
3483
3491
  else:
3484
3492
  TimingLGR.info("CVR map generation")
3485
3493
  LGR.info("\n\nCVR mapping")
@@ -3488,46 +3496,48 @@ def rapidtide_main(argparsingfunc):
3488
3496
  # initialrawvariance = tide_math.imagevariance(fmri_data_valid, None, 1.0 / fmritr)
3489
3497
  initialvariance = tide_math.imagevariance(fmri_data_valid, theprefilter, 1.0 / fmritr)
3490
3498
 
3491
- # now calculate the GLM
3499
+ # now calculate the sLFO filter
3492
3500
  if optiondict["refinedelay"] and optiondict["filterwithrefineddelay"]:
3493
3501
  lagstouse = lagtimesrefined
3494
3502
  else:
3495
3503
  lagstouse = lagtimes
3496
- voxelsprocessed_glm, regressorset, evset = tide_glmfrommaps.glmfrommaps(
3497
- fmri_data_valid,
3498
- validvoxels,
3499
- initial_fmri_x,
3500
- lagstouse,
3501
- fitmask,
3502
- genlagtc,
3503
- mode,
3504
- outputname,
3505
- oversamptr,
3506
- glmmean,
3507
- rvalue,
3508
- r2value,
3509
- fitNorm[:, : optiondict["glmderivs"] + 1],
3510
- fitcoeff[:, : optiondict["glmderivs"] + 1],
3511
- movingsignal,
3512
- lagtc,
3513
- filtereddata,
3514
- LGR,
3515
- TimingLGR,
3516
- optiondict["glmthreshval"],
3517
- optiondict["saveminimumglmfiles"],
3518
- nprocs_makelaggedtcs=optiondict["nprocs_makelaggedtcs"],
3519
- nprocs_glm=optiondict["nprocs_glm"],
3520
- glmderivs=optiondict["glmderivs"],
3521
- mp_chunksize=optiondict["mp_chunksize"],
3522
- showprogressbar=optiondict["showprogressbar"],
3523
- alwaysmultiproc=optiondict["alwaysmultiproc"],
3524
- memprofile=optiondict["memprofile"],
3525
- debug=optiondict["debug"],
3504
+ voxelsprocessed_regressionfilt, regressorset, evset = (
3505
+ tide_regressfrommaps.regressfrommaps(
3506
+ fmri_data_valid,
3507
+ validvoxels,
3508
+ initial_fmri_x,
3509
+ lagstouse,
3510
+ fitmask,
3511
+ genlagtc,
3512
+ mode,
3513
+ outputname,
3514
+ oversamptr,
3515
+ sLFOfitmean,
3516
+ rvalue,
3517
+ r2value,
3518
+ fitNorm[:, : optiondict["regressderivs"] + 1],
3519
+ fitcoeff[:, : optiondict["regressderivs"] + 1],
3520
+ movingsignal,
3521
+ lagtc,
3522
+ filtereddata,
3523
+ LGR,
3524
+ TimingLGR,
3525
+ optiondict["regressfiltthreshval"],
3526
+ optiondict["saveminimumsLFOfiltfiles"],
3527
+ nprocs_makelaggedtcs=optiondict["nprocs_makelaggedtcs"],
3528
+ nprocs_regressionfilt=optiondict["nprocs_regressionfilt"],
3529
+ regressderivs=optiondict["regressderivs"],
3530
+ mp_chunksize=optiondict["mp_chunksize"],
3531
+ showprogressbar=optiondict["showprogressbar"],
3532
+ alwaysmultiproc=optiondict["alwaysmultiproc"],
3533
+ memprofile=optiondict["memprofile"],
3534
+ debug=optiondict["debug"],
3535
+ )
3526
3536
  )
3527
3537
 
3528
3538
  evcolnames = ["base"]
3529
- if optiondict["glmderivs"] > 0:
3530
- for i in range(1, optiondict["glmderivs"] + 1):
3539
+ if optiondict["regressderivs"] > 0:
3540
+ for i in range(1, optiondict["regressderivs"] + 1):
3531
3541
  evcolnames.append(f"deriv_{str(i)}")
3532
3542
 
3533
3543
  tide_io.writebidstsv(
@@ -3535,7 +3545,7 @@ def rapidtide_main(argparsingfunc):
3535
3545
  np.transpose(evset),
3536
3546
  1.0 / fmritr,
3537
3547
  columns=evcolnames,
3538
- extraheaderinfo={"Description": "GLM regressor set"},
3548
+ extraheaderinfo={"Description": "sLFO filter regressor set"},
3539
3549
  append=False,
3540
3550
  )
3541
3551
 
@@ -3547,30 +3557,20 @@ def rapidtide_main(argparsingfunc):
3547
3557
  varchange = initialvariance * 0.0
3548
3558
  varchange[divlocs] = 100.0 * (finalvariance[divlocs] / initialvariance[divlocs] - 1.0)
3549
3559
 
3550
- """divlocs = np.where(finalrawvariance > 0.0)
3551
- rawvarchange = initialrawvariance * 0.0
3552
- rawvarchange[divlocs] = 100.0 * (
3553
- finalrawvariance[divlocs] / initialvariance[divlocs] - 1.0
3554
- )"""
3555
-
3556
- del fmri_data_valid
3557
- if optiondict["sharedmem"]:
3558
- tide_util.cleanup_shm(fmri_data_valid_shm)
3559
-
3560
3560
  LGR.info("End filtering operation")
3561
3561
  TimingLGR.info(
3562
- "GLM filtering end",
3562
+ "sLFO filtering end",
3563
3563
  {
3564
- "message2": voxelsprocessed_glm,
3564
+ "message2": voxelsprocessed_regressionfilt,
3565
3565
  "message3": "voxels",
3566
3566
  },
3567
3567
  )
3568
3568
  if optiondict["memprofile"]:
3569
3569
  memcheckpoint("...done")
3570
- tide_util.logmem("after glm filter")
3570
+ tide_util.logmem("after sLFO filter")
3571
3571
  LGR.info("")
3572
3572
  ####################################################
3573
- # GLM filtering end
3573
+ # sLFO filtering end
3574
3574
  ####################################################
3575
3575
 
3576
3576
  # Post refinement step 2 - make and save interesting histograms
@@ -3608,24 +3608,24 @@ def rapidtide_main(argparsingfunc):
3608
3608
  thedict=optiondict,
3609
3609
  )
3610
3610
  namesuffix = "_desc-lfofilterR2_hist"
3611
- if optiondict["doglmfilt"]:
3611
+ if optiondict["dolinfitfilt"]:
3612
3612
  tide_stats.makeandsavehistogram(
3613
3613
  r2value[np.where(fitmask > 0)],
3614
3614
  optiondict["histlen"],
3615
3615
  1,
3616
3616
  outputname + namesuffix,
3617
- displaytitle="Histogram of GLM filter R2 values",
3617
+ displaytitle="Histogram of sLFO filter R2 values",
3618
3618
  dictvarname="R2hist",
3619
3619
  thedict=optiondict,
3620
3620
  )
3621
3621
  namesuffix = "_desc-lfofilterInbandVarianceChange_hist"
3622
- if optiondict["doglmfilt"]:
3622
+ if optiondict["dolinfitfilt"]:
3623
3623
  tide_stats.makeandsavehistogram(
3624
3624
  varchange[np.where(fitmask > 0)],
3625
3625
  optiondict["histlen"],
3626
3626
  1,
3627
3627
  outputname + namesuffix,
3628
- displaytitle="Histogram of percent of inband variance removed by GLM filter",
3628
+ displaytitle="Histogram of percent of inband variance removed by sLFO filter",
3629
3629
  dictvarname="varchangehist",
3630
3630
  thedict=optiondict,
3631
3631
  )
@@ -3714,56 +3714,55 @@ def rapidtide_main(argparsingfunc):
3714
3714
  "second",
3715
3715
  "Lag time in seconds, refined",
3716
3716
  ),
3717
- (np.fabs(rvalue), "maxcorralt", "map", None, "R value of the GLM fit, with sign"),
3718
3717
  ]
3719
3718
  if (optiondict["outputlevel"] != "min") and (optiondict["outputlevel"] != "less"):
3720
- if optiondict["refineglmderivs"] > 1:
3721
- for i in range(optiondict["refineglmderivs"]):
3719
+ if optiondict["refineregressderivs"] > 1:
3720
+ for i in range(optiondict["refineregressderivs"]):
3722
3721
  savelist += [
3723
3722
  (
3724
- glmderivratios[i, :],
3725
- f"glmderivratios_{i}",
3723
+ regressderivratios[i, :],
3724
+ f"regressderivratios_{i}",
3726
3725
  "map",
3727
3726
  None,
3728
3727
  f"Ratio of derivative {i + 1} of delayed sLFO to the delayed sLFO",
3729
3728
  ),
3730
3729
  (
3731
- medfiltglmderivratios[i, :],
3732
- f"medfiltglmderivratios_{i}",
3730
+ medfiltregressderivratios[i, :],
3731
+ f"medfiltregressderivratios_{i}",
3733
3732
  "map",
3734
3733
  None,
3735
- f"Median filtered version of the glmderivratios_{i} map",
3734
+ f"Median filtered version of the regressderivratios_{i} map",
3736
3735
  ),
3737
3736
  (
3738
- filteredglmderivratios[i, :],
3739
- f"filteredglmderivratios_{i}",
3737
+ filteredregressderivratios[i, :],
3738
+ f"filteredregressderivratios_{i}",
3740
3739
  "map",
3741
3740
  None,
3742
- f"glmderivratios_{i}, with outliers patched using median filtered data",
3741
+ f"regressderivratios_{i}, with outliers patched using median filtered data",
3743
3742
  ),
3744
3743
  ]
3745
3744
  else:
3746
3745
  savelist += [
3747
3746
  (
3748
- glmderivratios,
3749
- "glmderivratios",
3747
+ regressderivratios,
3748
+ "regressderivratios",
3750
3749
  "map",
3751
3750
  None,
3752
3751
  "Ratio of the first derivative of delayed sLFO to the delayed sLFO",
3753
3752
  ),
3754
3753
  (
3755
- medfiltglmderivratios,
3756
- "medfiltglmderivratios",
3754
+ medfiltregressderivratios,
3755
+ "medfiltregressderivratios",
3757
3756
  "map",
3758
3757
  None,
3759
- "Median filtered version of the glmderivratios map",
3758
+ "Median filtered version of the regressderivratios map",
3760
3759
  ),
3761
3760
  (
3762
- filteredglmderivratios,
3763
- "filteredglmderivratios",
3761
+ filteredregressderivratios,
3762
+ "filteredregressderivratios",
3764
3763
  "map",
3765
3764
  None,
3766
- "glmderivratios, with outliers patched using median filtered data",
3765
+ "regressderivratios, with outliers patched using median filtered data",
3767
3766
  ),
3768
3767
  ]
3769
3768
  if optiondict["calccoherence"]:
@@ -3803,8 +3802,8 @@ def rapidtide_main(argparsingfunc):
3803
3802
  tide_util.cleanup_shm(coherencepeakfreq_shm)
3804
3803
 
3805
3804
  # write the optional 3D maps that need to be remapped
3806
- if optiondict["doglmfilt"] or optiondict["docvrmap"]:
3807
- if optiondict["doglmfilt"]:
3805
+ if optiondict["dolinfitfilt"] or optiondict["docvrmap"]:
3806
+ if optiondict["dolinfitfilt"]:
3808
3807
  maplist = [
3809
3808
  (
3810
3809
  initialvariance,
@@ -3828,22 +3827,22 @@ def rapidtide_main(argparsingfunc):
3828
3827
  "Change in inband variance after filtering, in percent",
3829
3828
  ),
3830
3829
  ]
3831
- if optiondict["saveminimumglmfiles"]:
3830
+ if optiondict["saveminimumsLFOfiltfiles"]:
3832
3831
  maplist += [
3833
3832
  (
3834
3833
  r2value,
3835
3834
  "lfofilterR2",
3836
3835
  "map",
3837
3836
  None,
3838
- "Squared R value of the GLM fit (proportion of variance explained)",
3837
+ "Squared R value of the sLFO fit (proportion of variance explained)",
3839
3838
  ),
3840
3839
  ]
3841
- if optiondict["savenormalglmfiles"]:
3840
+ if optiondict["savenormalsLFOfiltfiles"]:
3842
3841
  maplist += [
3843
- (np.fabs(rvalue), "lfofilterR", "map", None, "R value of the GLM fit"),
3844
- (glmmean, "lfofilterMean", "map", None, "Intercept from GLM fit"),
3842
+ (rvalue, "lfofilterR", "map", None, "R value of the sLFO fit"),
3843
+ (sLFOfitmean, "lfofilterMean", "map", None, "Intercept from sLFO fit"),
3845
3844
  ]
3846
- if optiondict["glmderivs"] > 0:
3845
+ if optiondict["regressderivs"] > 0:
3847
3846
  maplist += [
3848
3847
  (fitcoeff[:, 0], "lfofilterCoeff", "map", None, "Fit coefficient"),
3849
3848
  (
@@ -3854,7 +3853,7 @@ def rapidtide_main(argparsingfunc):
3854
3853
  "Normalized fit coefficient",
3855
3854
  ),
3856
3855
  ]
3857
- for thederiv in range(1, optiondict["glmderivs"] + 1):
3856
+ for thederiv in range(1, optiondict["regressderivs"] + 1):
3858
3857
  maplist += [
3859
3858
  (
3860
3859
  fitcoeff[:, thederiv],
@@ -3874,14 +3873,14 @@ def rapidtide_main(argparsingfunc):
3874
3873
  else:
3875
3874
  maplist += [
3876
3875
  (
3877
- fitcoeff[:, : optiondict["glmderivs"] + 1],
3876
+ fitcoeff[:, : optiondict["regressderivs"] + 1],
3878
3877
  "lfofilterCoeff",
3879
3878
  "map",
3880
3879
  None,
3881
3880
  "Fit coefficient",
3882
3881
  ),
3883
3882
  (
3884
- fitNorm[:, : optiondict["glmderivs"] + 1],
3883
+ fitNorm[:, : optiondict["regressderivs"] + 1],
3885
3884
  "lfofilterNorm",
3886
3885
  "map",
3887
3886
  None,
@@ -3912,15 +3911,15 @@ def rapidtide_main(argparsingfunc):
3912
3911
  "Percentage of inband variance attributable to CVR regressor",
3913
3912
  ),
3914
3913
  ]
3915
- if optiondict["savenormalglmfiles"]:
3914
+ if optiondict["savenormalsLFOfiltfiles"]:
3916
3915
  maplist = [
3917
- (rvalue, "CVRR", "map", None, "R value of the GLM fit"),
3916
+ (rvalue, "CVRR", "map", None, "R value of the sLFO fit"),
3918
3917
  (
3919
3918
  r2value,
3920
3919
  "CVRR2",
3921
3920
  "map",
3922
3921
  None,
3923
- "Squared R value of the GLM fit (proportion of variance explained)",
3922
+ "Squared R value of the sLFO fit (proportion of variance explained)",
3924
3923
  ),
3925
3924
  (
3926
3925
  fitcoeff,
@@ -3943,7 +3942,70 @@ def rapidtide_main(argparsingfunc):
3943
3942
  rt_floattype=rt_floattype,
3944
3943
  cifti_hdr=cifti_hdr,
3945
3944
  )
3946
- del glmmean
3945
+
3946
+ if optiondict["refinedelay"] and False:
3947
+ # filter the fmri data to the lfo band
3948
+ print("filtering fmri_data to sLFO band")
3949
+ for i in range(fmri_data_valid.shape[0]):
3950
+ fmri_data_valid[i, :] = theprefilter.apply(
3951
+ optiondict["fmrifreq"], fmri_data_valid[i, :]
3952
+ )
3953
+
3954
+ print("rerunning sLFO fit to get filtered R value")
3955
+ dummy, dummy, dummy = tide_regressfrommaps.regressfrommaps(
3956
+ fmri_data_valid,
3957
+ validvoxels,
3958
+ initial_fmri_x,
3959
+ lagstouse,
3960
+ fitmask,
3961
+ genlagtc,
3962
+ mode,
3963
+ outputname,
3964
+ oversamptr,
3965
+ sLFOfitmean,
3966
+ rvalue,
3967
+ r2value,
3968
+ fitNorm[:, : optiondict["regressderivs"] + 1],
3969
+ fitcoeff[:, : optiondict["regressderivs"] + 1],
3970
+ movingsignal,
3971
+ lagtc,
3972
+ filtereddata,
3973
+ LGR,
3974
+ TimingLGR,
3975
+ optiondict["regressfiltthreshval"],
3976
+ optiondict["saveminimumsLFOfiltfiles"],
3977
+ nprocs_makelaggedtcs=optiondict["nprocs_makelaggedtcs"],
3978
+ nprocs_regressionfilt=optiondict["nprocs_regressionfilt"],
3979
+ regressderivs=optiondict["regressderivs"],
3980
+ mp_chunksize=optiondict["mp_chunksize"],
3981
+ showprogressbar=optiondict["showprogressbar"],
3982
+ alwaysmultiproc=optiondict["alwaysmultiproc"],
3983
+ memprofile=optiondict["memprofile"],
3984
+ debug=optiondict["debug"],
3985
+ )
3986
+
3987
+ maplist = [
3988
+ (rvalue, "maxcorralt", "map", None, "R value of the inband sLFO fit, with sign"),
3989
+ ]
3990
+
3991
+ tide_io.savemaplist(
3992
+ outputname,
3993
+ maplist,
3994
+ validvoxels,
3995
+ nativespaceshape,
3996
+ theheader,
3997
+ bidsbasedict,
3998
+ textio=optiondict["textio"],
3999
+ fileiscifti=fileiscifti,
4000
+ rt_floattype=rt_floattype,
4001
+ cifti_hdr=cifti_hdr,
4002
+ )
4003
+
4004
+ del fmri_data_valid
4005
+ if optiondict["sharedmem"]:
4006
+ tide_util.cleanup_shm(fmri_data_valid_shm)
4007
+
4008
+ del sLFOfitmean
3947
4009
  del rvalue
3948
4010
  del r2value
3949
4011
  del fitcoeff
@@ -3952,7 +4014,7 @@ def rapidtide_main(argparsingfunc):
3952
4014
  del finalvariance
3953
4015
  del varchange
3954
4016
  if optiondict["sharedmem"]:
3955
- tide_util.cleanup_shm(glmmean_shm)
4017
+ tide_util.cleanup_shm(sLFOfitmean_shm)
3956
4018
  tide_util.cleanup_shm(rvalue_shm)
3957
4019
  tide_util.cleanup_shm(r2value_shm)
3958
4020
  tide_util.cleanup_shm(fitcoeff_shm)
@@ -4133,8 +4195,10 @@ def rapidtide_main(argparsingfunc):
4133
4195
  cifti_hdr = None
4134
4196
 
4135
4197
  maplist = []
4136
- if optiondict["saveallglmfiles"] and (optiondict["doglmfilt"] or optiondict["docvrmap"]):
4137
- if optiondict["glmderivs"] > 0:
4198
+ if optiondict["saveallsLFOfiltfiles"] and (
4199
+ optiondict["dolinfitfilt"] or optiondict["docvrmap"]
4200
+ ):
4201
+ if optiondict["regressderivs"] > 0:
4138
4202
  maplist += [
4139
4203
  (
4140
4204
  regressorset[:, :, 0],
@@ -4144,7 +4208,7 @@ def rapidtide_main(argparsingfunc):
4144
4208
  "Shifted sLFO regressor to filter",
4145
4209
  ),
4146
4210
  ]
4147
- for thederiv in range(1, optiondict["glmderivs"] + 1):
4211
+ for thederiv in range(1, optiondict["regressderivs"] + 1):
4148
4212
  maplist += [
4149
4213
  (
4150
4214
  regressorset[:, :, thederiv],
@@ -4159,7 +4223,7 @@ def rapidtide_main(argparsingfunc):
4159
4223
  (regressorset, "lfofilterEV", "bold", None, "Shifted sLFO regressor to filter"),
4160
4224
  ]
4161
4225
 
4162
- if optiondict["passes"] > 1:
4226
+ if (optiondict["passes"] > 1) or optiondict["dofinalrefine"]:
4163
4227
  if optiondict["savelagregressors"]:
4164
4228
  maplist += [
4165
4229
  (
@@ -4171,8 +4235,8 @@ def rapidtide_main(argparsingfunc):
4171
4235
  ),
4172
4236
  ]
4173
4237
 
4174
- if optiondict["doglmfilt"]:
4175
- if optiondict["saveminimumglmfiles"]:
4238
+ if optiondict["dolinfitfilt"]:
4239
+ if optiondict["saveminimumsLFOfiltfiles"]:
4176
4240
  maplist += [
4177
4241
  (
4178
4242
  filtereddata,
@@ -4232,7 +4296,7 @@ def rapidtide_main(argparsingfunc):
4232
4296
  # clean up
4233
4297
  if optiondict["passes"] > 1:
4234
4298
  theRegressorRefiner.cleanup()
4235
- if optiondict["doglmfilt"]:
4299
+ if optiondict["dolinfitfilt"]:
4236
4300
  del lagtc
4237
4301
  del filtereddata
4238
4302
  del movingsignal