rapidtide 3.0a14__py3-none-any.whl → 3.0.1__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 (231) hide show
  1. rapidtide/Colortables.py +1 -1
  2. rapidtide/DerivativeDelay.py +1 -1
  3. rapidtide/OrthoImageItem.py +1 -1
  4. rapidtide/RapidtideDataset.py +3 -1
  5. rapidtide/RegressorRefiner.py +1 -1
  6. rapidtide/calcandfitcorrpairs.py +1 -1
  7. rapidtide/calccoherence.py +1 -1
  8. rapidtide/calcnullsimfunc.py +1 -1
  9. rapidtide/calcsimfunc.py +1 -1
  10. rapidtide/correlate.py +1 -1
  11. rapidtide/data/examples/src/test_findmaxlag.py +1 -1
  12. rapidtide/data/examples/src/testfmri +3 -2
  13. rapidtide/data/examples/src/testfuncs +1 -1
  14. rapidtide/data/examples/src/testhappy +12 -1
  15. rapidtide/data/examples/src/testmodels +33 -0
  16. rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/loss.png +0 -0
  17. rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/loss.txt +1 -0
  18. rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/model.keras +0 -0
  19. rapidtide/data/models/model_cnn_w064_l13_fn20_fl08/model_meta.json +167 -0
  20. rapidtide/data/models/model_revised_tf2/model.keras +0 -0
  21. rapidtide/data/models/{model_serdar → model_revised_tf2}/model_meta.json +1 -1
  22. rapidtide/data/models/model_serdar2_tf2/model.keras +0 -0
  23. rapidtide/data/models/{model_serdar2 → model_serdar2_tf2}/model_meta.json +1 -1
  24. rapidtide/data/models/model_serdar_tf2/model.keras +0 -0
  25. rapidtide/data/models/{model_revised → model_serdar_tf2}/model_meta.json +1 -1
  26. rapidtide/dlfilter.py +325 -241
  27. rapidtide/externaltools.py +1 -1
  28. rapidtide/fMRIData_class.py +1 -1
  29. rapidtide/filter.py +1 -8
  30. rapidtide/fit.py +1 -8
  31. rapidtide/happy_supportfuncs.py +30 -1
  32. rapidtide/helper_classes.py +1 -1
  33. rapidtide/io.py +1 -1
  34. rapidtide/linfitfiltpass.py +1 -1
  35. rapidtide/makelaggedtcs.py +1 -1
  36. rapidtide/maskutil.py +1 -1
  37. rapidtide/miscmath.py +1 -8
  38. rapidtide/multiproc.py +1 -1
  39. rapidtide/patchmatch.py +1 -1
  40. rapidtide/peakeval.py +1 -1
  41. rapidtide/qualitycheck.py +1 -1
  42. rapidtide/refinedelay.py +1 -3
  43. rapidtide/refineregressor.py +1 -1
  44. rapidtide/resample.py +1 -1
  45. rapidtide/scripts/adjustoffset.py +1 -1
  46. rapidtide/scripts/aligntcs.py +1 -1
  47. rapidtide/scripts/applydlfilter.py +1 -1
  48. rapidtide/scripts/atlasaverage.py +1 -1
  49. rapidtide/scripts/atlastool.py +1 -1
  50. rapidtide/scripts/calcicc.py +1 -1
  51. rapidtide/scripts/calctexticc.py +1 -1
  52. rapidtide/scripts/calcttest.py +1 -1
  53. rapidtide/scripts/ccorrica.py +1 -1
  54. rapidtide/scripts/delayvar.py +2 -2
  55. rapidtide/scripts/diffrois.py +1 -1
  56. rapidtide/scripts/endtidalproc.py +1 -1
  57. rapidtide/scripts/fdica.py +1 -1
  58. rapidtide/scripts/filtnifti.py +1 -1
  59. rapidtide/scripts/filttc.py +1 -1
  60. rapidtide/scripts/fingerprint.py +1 -1
  61. rapidtide/scripts/fixtr.py +1 -1
  62. rapidtide/scripts/gmscalc.py +1 -1
  63. rapidtide/scripts/happy.py +1 -1
  64. rapidtide/scripts/happy2std.py +1 -1
  65. rapidtide/scripts/happywarp.py +1 -1
  66. rapidtide/scripts/histnifti.py +1 -1
  67. rapidtide/scripts/histtc.py +1 -1
  68. rapidtide/scripts/linfitfilt.py +1 -1
  69. rapidtide/scripts/localflow.py +1 -1
  70. rapidtide/scripts/mergequality.py +1 -1
  71. rapidtide/scripts/pairproc.py +1 -1
  72. rapidtide/scripts/pairwisemergenifti.py +1 -1
  73. rapidtide/scripts/physiofreq.py +1 -1
  74. rapidtide/scripts/pixelcomp.py +1 -1
  75. rapidtide/scripts/plethquality.py +1 -1
  76. rapidtide/scripts/polyfitim.py +1 -1
  77. rapidtide/scripts/proj2flow.py +1 -1
  78. rapidtide/scripts/rankimage.py +1 -1
  79. rapidtide/scripts/rapidtide.py +1 -1
  80. rapidtide/scripts/rapidtide2std.py +1 -1
  81. rapidtide/scripts/resamplenifti.py +1 -1
  82. rapidtide/scripts/resampletc.py +1 -1
  83. rapidtide/scripts/retrolagtcs.py +1 -1
  84. rapidtide/scripts/retroregress.py +1 -1
  85. rapidtide/scripts/roisummarize.py +1 -1
  86. rapidtide/scripts/runqualitycheck.py +1 -1
  87. rapidtide/scripts/showarbcorr.py +1 -1
  88. rapidtide/scripts/showhist.py +1 -1
  89. rapidtide/scripts/showstxcorr.py +1 -1
  90. rapidtide/scripts/showtc.py +1 -1
  91. rapidtide/scripts/showxcorr_legacy.py +1 -1
  92. rapidtide/scripts/showxcorrx.py +1 -1
  93. rapidtide/scripts/showxy.py +1 -1
  94. rapidtide/scripts/simdata.py +1 -1
  95. rapidtide/scripts/spatialdecomp.py +1 -1
  96. rapidtide/scripts/spatialfit.py +1 -1
  97. rapidtide/scripts/spatialmi.py +1 -1
  98. rapidtide/scripts/spectrogram.py +1 -1
  99. rapidtide/scripts/stupidramtricks.py +1 -1
  100. rapidtide/scripts/synthASL.py +1 -1
  101. rapidtide/scripts/tcfrom2col.py +1 -1
  102. rapidtide/scripts/tcfrom3col.py +1 -1
  103. rapidtide/scripts/temporaldecomp.py +1 -1
  104. rapidtide/scripts/testhrv.py +1 -1
  105. rapidtide/scripts/threeD.py +1 -1
  106. rapidtide/scripts/tidepool.py +1 -1
  107. rapidtide/scripts/variabilityizer.py +1 -1
  108. rapidtide/simfuncfit.py +1 -1
  109. rapidtide/stats.py +1 -8
  110. rapidtide/tests/cleanposttest +1 -1
  111. rapidtide/tests/resethappytargets +1 -1
  112. rapidtide/tests/resetrapidtidetargets +1 -1
  113. rapidtide/tests/resettargets +1 -1
  114. rapidtide/tests/runlocaltest +1 -1
  115. rapidtide/tests/showkernels +1 -1
  116. rapidtide/tests/test_aliasedcorrelate.py +1 -1
  117. rapidtide/tests/test_aligntcs.py +1 -1
  118. rapidtide/tests/test_calcicc.py +1 -1
  119. rapidtide/tests/test_congrid.py +1 -1
  120. rapidtide/tests/test_correlate.py +1 -1
  121. rapidtide/tests/test_corrpass.py +1 -1
  122. rapidtide/tests/test_delayestimation.py +1 -1
  123. rapidtide/tests/test_doresample.py +1 -1
  124. rapidtide/tests/test_fastresampler.py +1 -1
  125. rapidtide/tests/test_findmaxlag.py +1 -1
  126. rapidtide/tests/test_fullrunhappy_v1.py +2 -2
  127. rapidtide/tests/test_fullrunhappy_v2.py +2 -2
  128. rapidtide/tests/test_fullrunhappy_v3.py +2 -2
  129. rapidtide/tests/test_fullrunhappy_v4.py +2 -2
  130. rapidtide/tests/test_fullrunhappy_v5.py +1 -3
  131. rapidtide/tests/test_fullrunrapidtide_v1.py +1 -1
  132. rapidtide/tests/test_fullrunrapidtide_v2.py +3 -1
  133. rapidtide/tests/test_fullrunrapidtide_v3.py +1 -1
  134. rapidtide/tests/test_fullrunrapidtide_v4.py +1 -1
  135. rapidtide/tests/test_fullrunrapidtide_v5.py +1 -1
  136. rapidtide/tests/test_fullrunrapidtide_v6.py +1 -1
  137. rapidtide/tests/test_io.py +1 -1
  138. rapidtide/tests/test_linfitfiltpass.py +1 -1
  139. rapidtide/tests/test_mi.py +1 -1
  140. rapidtide/tests/test_miscmath.py +1 -1
  141. rapidtide/tests/test_motionregress.py +1 -1
  142. rapidtide/tests/test_nullcorr.py +1 -1
  143. rapidtide/tests/test_padvec.py +1 -1
  144. rapidtide/tests/test_phaseanalysis.py +1 -1
  145. rapidtide/tests/test_rapidtideparser.py +1 -1
  146. rapidtide/tests/test_refinedelay.py +1 -2
  147. rapidtide/tests/test_runmisc.py +1 -1
  148. rapidtide/tests/test_sharedmem.py +1 -1
  149. rapidtide/tests/test_simulate.py +1 -1
  150. rapidtide/tests/test_stcorrelate.py +1 -1
  151. rapidtide/tests/test_timeshift.py +1 -1
  152. rapidtide/tests/test_valtoindex.py +1 -1
  153. rapidtide/tests/test_zRapidtideDataset.py +1 -1
  154. rapidtide/tests/utils.py +1 -1
  155. rapidtide/transformerdlfilter.py +2 -4
  156. rapidtide/util.py +37 -14
  157. rapidtide/voxelData.py +278 -0
  158. rapidtide/wiener.py +1 -1
  159. rapidtide/wiener2.py +1 -1
  160. rapidtide/workflows/adjustoffset.py +1 -1
  161. rapidtide/workflows/aligntcs.py +1 -1
  162. rapidtide/workflows/applydlfilter.py +20 -65
  163. rapidtide/workflows/atlasaverage.py +1 -1
  164. rapidtide/workflows/atlastool.py +1 -1
  165. rapidtide/workflows/calctexticc.py +1 -1
  166. rapidtide/workflows/ccorrica.py +1 -1
  167. rapidtide/workflows/cleanregressor.py +243 -0
  168. rapidtide/workflows/delayestimation.py +488 -0
  169. rapidtide/workflows/delayvar.py +1 -1
  170. rapidtide/workflows/diffrois.py +1 -1
  171. rapidtide/workflows/endtidalproc.py +1 -1
  172. rapidtide/workflows/fdica.py +1 -1
  173. rapidtide/workflows/filtnifti.py +1 -1
  174. rapidtide/workflows/filttc.py +1 -1
  175. rapidtide/workflows/fixtr.py +1 -1
  176. rapidtide/workflows/gmscalc.py +1 -1
  177. rapidtide/workflows/happy.py +49 -3
  178. rapidtide/workflows/happy2std.py +1 -1
  179. rapidtide/workflows/happy_parser.py +30 -6
  180. rapidtide/workflows/histnifti.py +1 -1
  181. rapidtide/workflows/histtc.py +1 -1
  182. rapidtide/workflows/linfitfilt.py +1 -1
  183. rapidtide/workflows/localflow.py +1 -1
  184. rapidtide/workflows/mergequality.py +1 -1
  185. rapidtide/workflows/niftidecomp.py +1 -1
  186. rapidtide/workflows/niftistats.py +1 -1
  187. rapidtide/workflows/pairproc.py +1 -1
  188. rapidtide/workflows/pairwisemergenifti.py +1 -1
  189. rapidtide/workflows/parser_funcs.py +1 -1
  190. rapidtide/workflows/physiofreq.py +1 -1
  191. rapidtide/workflows/pixelcomp.py +1 -1
  192. rapidtide/workflows/plethquality.py +1 -1
  193. rapidtide/workflows/polyfitim.py +1 -1
  194. rapidtide/workflows/proj2flow.py +1 -1
  195. rapidtide/workflows/rankimage.py +1 -1
  196. rapidtide/workflows/rapidtide.py +163 -679
  197. rapidtide/workflows/rapidtide2std.py +1 -1
  198. rapidtide/workflows/rapidtide_parser.py +1 -98
  199. rapidtide/workflows/regressfrommaps.py +4 -48
  200. rapidtide/workflows/resamplenifti.py +1 -1
  201. rapidtide/workflows/resampletc.py +1 -1
  202. rapidtide/workflows/retrolagtcs.py +1 -1
  203. rapidtide/workflows/retroregress.py +1 -1
  204. rapidtide/workflows/roisummarize.py +1 -1
  205. rapidtide/workflows/runqualitycheck.py +1 -1
  206. rapidtide/workflows/showarbcorr.py +1 -1
  207. rapidtide/workflows/showhist.py +1 -1
  208. rapidtide/workflows/showstxcorr.py +1 -1
  209. rapidtide/workflows/showtc.py +1 -1
  210. rapidtide/workflows/showxcorrx.py +1 -1
  211. rapidtide/workflows/showxy.py +1 -1
  212. rapidtide/workflows/simdata.py +1 -1
  213. rapidtide/workflows/spatialfit.py +1 -1
  214. rapidtide/workflows/spatialmi.py +1 -1
  215. rapidtide/workflows/spectrogram.py +1 -1
  216. rapidtide/workflows/synthASL.py +1 -1
  217. rapidtide/workflows/tcfrom2col.py +1 -1
  218. rapidtide/workflows/tcfrom3col.py +1 -1
  219. rapidtide/workflows/tidepool.py +2 -1
  220. rapidtide/workflows/utils.py +1 -1
  221. rapidtide/workflows/variabilityizer.py +1 -1
  222. {rapidtide-3.0a14.dist-info → rapidtide-3.0.1.dist-info}/METADATA +7 -9
  223. rapidtide-3.0.1.dist-info/RECORD +353 -0
  224. {rapidtide-3.0a14.dist-info → rapidtide-3.0.1.dist-info}/WHEEL +1 -1
  225. rapidtide/data/models/model_revised/model.h5 +0 -0
  226. rapidtide/data/models/model_serdar/model.h5 +0 -0
  227. rapidtide/data/models/model_serdar2/model.h5 +0 -0
  228. rapidtide-3.0a14.dist-info/RECORD +0 -345
  229. {rapidtide-3.0a14.dist-info → rapidtide-3.0.1.dist-info}/entry_points.txt +0 -0
  230. {rapidtide-3.0a14.dist-info → rapidtide-3.0.1.dist-info}/licenses/LICENSE +0 -0
  231. {rapidtide-3.0a14.dist-info → rapidtide-3.0.1.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
  #
4
- # Copyright 2016-2024 Blaise Frederick
4
+ # Copyright 2016-2025 Blaise Frederick
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -51,7 +51,9 @@ 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
+ import rapidtide.voxelData as tide_voxelData
54
55
  import rapidtide.wiener as tide_wiener
56
+ import rapidtide.workflows.cleanregressor as tide_cleanregressor
55
57
  import rapidtide.workflows.regressfrommaps as tide_regressfrommaps
56
58
  from rapidtide.tests.utils import mse
57
59
 
@@ -64,32 +66,11 @@ try:
64
66
  except ImportError:
65
67
  mklexists = False
66
68
 
67
- try:
68
- from memory_profiler import profile
69
-
70
- memprofilerexists = True
71
- except ImportError:
72
- memprofilerexists = False
73
-
74
69
  LGR = logging.getLogger("GENERAL")
75
70
  ErrorLGR = logging.getLogger("ERROR")
76
71
  TimingLGR = logging.getLogger("TIMING")
77
72
 
78
73
 
79
- def conditionalprofile():
80
- def resdec(f):
81
- if memprofilerexists:
82
- return profile(f)
83
- return f
84
-
85
- return resdec
86
-
87
-
88
- @conditionalprofile()
89
- def memcheckpoint(message):
90
- LGR.info(message)
91
-
92
-
93
74
  def getglobalsignal(
94
75
  indata, optiondict, includemask=None, excludemask=None, pcacomponents=0.8, debug=False
95
76
  ):
@@ -159,14 +140,6 @@ def getglobalsignal(
159
140
  return tide_math.stdnormalize(globalmean), themask
160
141
 
161
142
 
162
- def addmemprofiling(thefunc, memprofile, themessage):
163
- tide_util.logmem(themessage)
164
- if memprofile:
165
- return profile(thefunc, precision=2)
166
- else:
167
- return thefunc
168
-
169
-
170
143
  def checkforzeromean(thedataset):
171
144
  themean = np.mean(thedataset, axis=1)
172
145
  thestd = np.std(thedataset, axis=1)
@@ -216,21 +189,6 @@ def echocancel(thetimecourse, echooffset, thetimestep, outputname, padtimepoints
216
189
  return outputtimecourse, echofit, echoR2
217
190
 
218
191
 
219
- def disablemkl(numprocs, debug=False):
220
- if mklexists:
221
- if numprocs > 1:
222
- if debug:
223
- print("disablemkl: setting threads to 1")
224
- mkl.set_num_threads(1)
225
-
226
-
227
- def enablemkl(numthreads, debug=False):
228
- if mklexists:
229
- if debug:
230
- print(f"enablemkl: setting threads to {numthreads}")
231
- mkl.set_num_threads(numthreads)
232
-
233
-
234
192
  def rapidtide_main(argparsingfunc):
235
193
  threaddebug = False
236
194
  optiondict, theprefilter = argparsingfunc
@@ -249,7 +207,7 @@ def rapidtide_main(argparsingfunc):
249
207
  optiondict["Description"] = (
250
208
  "A detailed dump of all internal variables in the program. Useful for debugging and data provenance."
251
209
  )
252
- fmrifilename = optiondict["in_file"]
210
+ inputdatafilename = optiondict["in_file"]
253
211
  outputname = optiondict["outputname"]
254
212
  regressorfilename = optiondict["regressorfile"]
255
213
 
@@ -392,7 +350,7 @@ def rapidtide_main(argparsingfunc):
392
350
  mklmaxthreads = mkl.get_max_threads()
393
351
  if not (1 <= optiondict["mklthreads"] <= mklmaxthreads):
394
352
  optiondict["mklthreads"] = mklmaxthreads
395
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
353
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
396
354
  LGR.info(f"using {optiondict['mklthreads']} MKL threads")
397
355
 
398
356
  # Generate MemoryLGR output file with column names
@@ -401,77 +359,30 @@ def rapidtide_main(argparsingfunc):
401
359
  ####################################################
402
360
  # Read data
403
361
  ####################################################
404
- # open the fmri datafile
405
- tide_util.logmem("before reading in fmri data")
406
- if tide_io.checkiftext(fmrifilename):
407
- LGR.debug("input file is text - all I/O will be to text files")
408
- optiondict["textio"] = True
409
- if optiondict["gausssigma"] > 0.0:
410
- optiondict["gausssigma"] = 0.0
411
- LGR.info("gaussian spatial filter disabled for text input files")
412
- else:
362
+ # read the fmri datafile
363
+ tide_util.logmem("before reading in input data")
364
+ theinputdata = tide_voxelData.VoxelData(inputdatafilename, timestep=optiondict["realtr"])
365
+ if optiondict["debug"]:
366
+ theinputdata.summarize()
367
+ nim = theinputdata.nim
368
+ nim_hdr = theinputdata.nim_hdr
369
+ nim_affine = theinputdata.nim_affine
370
+ xsize, ysize, numslices, timepoints = theinputdata.getdims()
371
+ thesizes = theinputdata.thesizes
372
+ xdim, ydim, slicethickness, fmritr = theinputdata.getsizes()
373
+ numspatiallocs = theinputdata.numspatiallocs
374
+ nativespaceshape = theinputdata.nativespaceshape
375
+ cifti_hdr = theinputdata.cifti_hdr
376
+ fmritr = theinputdata.timestep
377
+ if theinputdata.filetype == "cifti":
378
+ fileiscifti = True
413
379
  optiondict["textio"] = False
414
-
415
- if optiondict["textio"]:
416
- nim_data = tide_io.readvecs(fmrifilename)
417
- nim_hdr = None
418
- nim_affine = None
419
- theshape = np.shape(nim_data)
420
- xsize = theshape[0]
421
- ysize = 1
422
- numslices = 1
380
+ elif theinputdata.filetype == "text":
423
381
  fileiscifti = False
424
- timepoints = theshape[1]
425
- thesizes = [0, int(xsize), 1, 1, int(timepoints)]
426
- numspatiallocs = int(xsize)
427
- nativespaceshape = xsize
428
- cifti_hdr = None
429
- else:
430
- fileiscifti = tide_io.checkifcifti(fmrifilename)
431
- if fileiscifti:
432
- LGR.debug("input file is CIFTI")
433
- (
434
- dummy,
435
- cifti_hdr,
436
- nim_data,
437
- nim_hdr,
438
- thedims,
439
- thesizes,
440
- dummy,
441
- ) = tide_io.readfromcifti(fmrifilename)
442
- nim_affine = None
443
- optiondict["isgrayordinate"] = True
444
- timepoints = nim_data.shape[1]
445
- numspatiallocs = nim_data.shape[0]
446
- LGR.debug(f"cifti file has {timepoints} timepoints, {numspatiallocs} numspatiallocs")
447
- nativespaceshape = (1, 1, 1, 1, numspatiallocs)
448
- else:
449
- LGR.debug("input file is NIFTI")
450
- nim, nim_data, nim_hdr, thedims, thesizes = tide_io.readfromnifti(fmrifilename)
451
- nim_affine = nim.affine
452
- optiondict["isgrayordinate"] = False
453
- xsize, ysize, numslices, timepoints = tide_io.parseniftidims(thedims)
454
- numspatiallocs = int(xsize) * int(ysize) * int(numslices)
455
- cifti_hdr = None
456
- nativespaceshape = (xsize, ysize, numslices)
457
- xdim, ydim, slicethickness, dummy = tide_io.parseniftisizes(thesizes)
458
-
459
- # correct some fields if necessary
460
- if fileiscifti:
461
- fmritr = 0.72 # this is wrong and is a hack until I can parse CIFTI XML
382
+ optiondict["textio"] = True
462
383
  else:
463
- if optiondict["textio"]:
464
- if optiondict["realtr"] <= 0.0:
465
- raise ValueError(
466
- "for text file data input, you must use the -t option to set the timestep"
467
- )
468
- else:
469
- if nim_hdr.get_xyzt_units()[1] == "msec":
470
- fmritr = thesizes[4] / 1000.0
471
- else:
472
- fmritr = thesizes[4]
473
- if optiondict["realtr"] > 0.0:
474
- fmritr = optiondict["realtr"]
384
+ fileiscifti = False
385
+ optiondict["textio"] = False
475
386
 
476
387
  # check to see if we need to adjust the oversample factor
477
388
  if optiondict["oversampfactor"] < 0:
@@ -498,6 +409,8 @@ def rapidtide_main(argparsingfunc):
498
409
  raise ValueError(
499
410
  f"magnitude of lagmax exceeds {(validend - validstart + 1) * fmritr / 2.0} - invalid"
500
411
  )
412
+ # trim the fmri data to the limits
413
+ theinputdata.setvalidtimes(validstart, validend)
501
414
 
502
415
  # determine the valid timepoints
503
416
  validtimepoints = validend - validstart + 1
@@ -551,60 +464,21 @@ def rapidtide_main(argparsingfunc):
551
464
  whitemask = anatomicmasks[2]
552
465
 
553
466
  # do spatial filtering if requested
554
- if fileiscifti:
555
- optiondict["gausssigma"] = 0.0
556
- if optiondict["gausssigma"] < 0.0 and not optiondict["textio"]:
557
- # set gausssigma automatically
558
- optiondict["gausssigma"] = np.mean([xdim, ydim, slicethickness]) / 2.0
467
+ optiondict["gausssigma"] = theinputdata.smooth(
468
+ optiondict["gausssigma"],
469
+ brainmask=brainmask,
470
+ graymask=graymask,
471
+ whitemask=whitemask,
472
+ premask=optiondict["premask"],
473
+ premasktissueonly=optiondict["premasktissueonly"],
474
+ showprogressbar=optiondict["showprogressbar"],
475
+ )
559
476
  if optiondict["gausssigma"] > 0.0:
560
- # premask data if requested
561
- if optiondict["premask"]:
562
- if optiondict["premasktissueonly"]:
563
- if (graymask is not None) and (whitemask is not None):
564
- multmask = graymask + whitemask
565
- else:
566
- raise ValueError(
567
- "ERROR: graymask and whitemask must be defined to use premasktissueonly - exiting"
568
- )
569
- else:
570
- if brainmask is not None:
571
- multmask = brainmask
572
- else:
573
- raise ValueError("ERROR: brainmask must be defined to use premask - exiting")
574
- LGR.info(f"premasking timepoints {validstart} to {validend}")
575
- for i in tqdm(
576
- range(validstart, validend + 1),
577
- desc="Timepoint",
578
- unit="timepoints",
579
- disable=(not optiondict["showprogressbar"]),
580
- ):
581
- nim_data[:, :, :, i] *= multmask
582
-
583
- # this is where you'd slice time correct
584
- # but we don't anymore
585
-
586
- # now apply the filter
587
- LGR.info(
588
- f"applying gaussian spatial filter to timepoints {validstart} "
589
- f"to {validend} with sigma={optiondict['gausssigma']}"
590
- )
591
- for i in tqdm(
592
- range(validstart, validend + 1),
593
- desc="Timepoint",
594
- unit="timepoints",
595
- disable=(not optiondict["showprogressbar"]),
596
- ):
597
- nim_data[:, :, :, i] = tide_filt.ssmooth(
598
- xdim,
599
- ydim,
600
- slicethickness,
601
- optiondict["gausssigma"],
602
- nim_data[:, :, :, i],
603
- )
604
477
  TimingLGR.info("End 3D smoothing")
605
478
 
606
479
  # reshape the data and trim to a time range, if specified. Check for special case of no trimming to save RAM
607
- fmri_data = nim_data.reshape((numspatiallocs, timepoints))[:, validstart : validend + 1]
480
+ fmri_data = theinputdata.voxelbytime()
481
+ print(f"{fmri_data.shape=}")
608
482
 
609
483
  # detect zero mean data
610
484
  if not optiondict["dataiszeromean"]:
@@ -719,9 +593,9 @@ def rapidtide_main(argparsingfunc):
719
593
  else:
720
594
  # check to see if the data has been demeaned
721
595
  if fileiscifti or optiondict["textio"]:
722
- corrmask = np.uint(nim_data[:, 0] * 0 + 1)
596
+ corrmask = np.uint(theinputdata.voxelbytime()[:, 0] * 0 + 1)
723
597
  else:
724
- if optiondict["dataiszeromean"]:
598
+ if not optiondict["dataiszeromean"]:
725
599
  LGR.verbose("generating correlation mask from mean image")
726
600
  corrmask = np.uint16(tide_mask.makeepimask(nim).dataobj.reshape(numspatiallocs))
727
601
  else:
@@ -779,7 +653,8 @@ def rapidtide_main(argparsingfunc):
779
653
  np.savetxt(f"{outputname}_validvoxels.txt", validvoxels)
780
654
  numvalidspatiallocs = np.shape(validvoxels)[0]
781
655
  LGR.debug(f"validvoxels shape = {numvalidspatiallocs}")
782
- fmri_data_valid = fmri_data[validvoxels, :] + 0.0
656
+ theinputdata.setvalidvoxels(validvoxels)
657
+ fmri_data_valid = theinputdata.getvalidvoxels() + 0.0
783
658
  LGR.verbose(
784
659
  f"original size = {np.shape(fmri_data)}, trimmed size = {np.shape(fmri_data_valid)}"
785
660
  )
@@ -824,10 +699,7 @@ def rapidtide_main(argparsingfunc):
824
699
  if optiondict["sharedmem"]:
825
700
  LGR.info("moving fmri data to shared memory")
826
701
  TimingLGR.verbose("Start moving fmri_data to shared memory")
827
- numpy2shared_func = addmemprofiling(
828
- tide_util.numpy2shared, optiondict["memprofile"], "before fmri data move"
829
- )
830
- fmri_data_valid, fmri_data_valid_shm = numpy2shared_func(
702
+ fmri_data_valid, fmri_data_valid_shm = tide_util.numpy2shared(
831
703
  fmri_data_valid, rt_floatset, name=f"fmri_data_valid_{optiondict['pid']}"
832
704
  )
833
705
  TimingLGR.verbose("End moving fmri_data to shared memory")
@@ -859,7 +731,7 @@ def rapidtide_main(argparsingfunc):
859
731
  else:
860
732
  doconfounds = False
861
733
 
862
- # now actually do the filtering
734
+ # now actually do the confound filtering
863
735
  if domotion or doconfounds:
864
736
  LGR.info("Doing confound filtering")
865
737
  TimingLGR.verbose("Confound filtering start")
@@ -885,7 +757,14 @@ def rapidtide_main(argparsingfunc):
885
757
  append=False,
886
758
  )
887
759
 
888
- disablemkl(optiondict["nprocs_confoundregress"], debug=threaddebug)
760
+ if optiondict["focaldebug"]:
761
+ print(f"{mergedregressors.shape=}")
762
+ print(f"{mergedregressorlabels}")
763
+ print(f"{fmri_data_valid.shape=}")
764
+ print(f"{fmritr=}")
765
+ print(f"{validstart=}")
766
+ print(f"{validend=}")
767
+ tide_util.disablemkl(optiondict["nprocs_confoundregress"], debug=threaddebug)
889
768
  (
890
769
  mergedregressors,
891
770
  mergedregressorlabels,
@@ -902,7 +781,7 @@ def rapidtide_main(argparsingfunc):
902
781
  orthogonalize=optiondict["orthogonalize"],
903
782
  showprogressbar=optiondict["showprogressbar"],
904
783
  )
905
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
784
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
906
785
  if confoundr2 is None:
907
786
  print("There are no nonzero confound regressors - exiting")
908
787
  sys.exit()
@@ -961,8 +840,6 @@ def rapidtide_main(argparsingfunc):
961
840
  },
962
841
  append=False,
963
842
  )
964
- if optiondict["memprofile"]:
965
- memcheckpoint("...done")
966
843
  tide_util.logmem("after confound sLFO filter")
967
844
 
968
845
  if optiondict["saveconfoundfiltered"]:
@@ -1008,11 +885,11 @@ def rapidtide_main(argparsingfunc):
1008
885
  # get rid of memory we aren't using
1009
886
  tide_util.logmem("before purging full sized fmri data")
1010
887
  meanvalue = np.mean(
1011
- nim_data.reshape((numspatiallocs, timepoints))[:, validstart : validend + 1],
888
+ theinputdata.voxelbytime(),
1012
889
  axis=1,
1013
890
  )
1014
891
  stddevvalue = np.std(
1015
- nim_data.reshape((numspatiallocs, timepoints))[:, validstart : validend + 1],
892
+ theinputdata.voxelbytime(),
1016
893
  axis=1,
1017
894
  )
1018
895
  covvalue = np.where(meanvalue > 0.0, stddevvalue / meanvalue, 0.0)
@@ -1035,8 +912,7 @@ def rapidtide_main(argparsingfunc):
1035
912
  )
1036
913
 
1037
914
  # get rid of more memory we aren't using
1038
- del fmri_data
1039
- del nim_data
915
+ theinputdata.unload()
1040
916
  uncollected = gc.collect()
1041
917
  if uncollected != 0:
1042
918
  print(f"garbage collected - unable to collect {uncollected} objects")
@@ -1149,59 +1025,6 @@ def rapidtide_main(argparsingfunc):
1149
1025
  LGR.verbose(f"the timepoint spacing is {1.0 / inputfreq}")
1150
1026
  LGR.verbose(f"the input timecourse start time is {inputstarttime}")
1151
1027
 
1152
- # if there is an externally specified noise regressor, read it in here
1153
- if optiondict["noisetimecoursespec"] is not None:
1154
- noisetimecoursespec = optiondict["noisetimecoursespec"]
1155
- LGR.info(f"using externally supplied noise regressor {noisetimecoursespec}")
1156
- (
1157
- filenoisefreq,
1158
- filenoisestarttime,
1159
- dummy,
1160
- noisevec,
1161
- dummy,
1162
- dummy,
1163
- ) = tide_io.readvectorsfromtextfile(optiondict["noisetimecoursespec"], onecol=True)
1164
- if optiondict["noiseinvert"]:
1165
- noisevec = noisevec * -1.0
1166
- noisefreq = optiondict["noisefreq"]
1167
- noisestarttime = optiondict["noisestarttime"]
1168
- if noisefreq is None:
1169
- if filenoisefreq is not None:
1170
- noisefreq = filenoisefreq
1171
- else:
1172
- noisefreq = 1.0 / fmritr
1173
- LGR.warning(f"no regressor frequency specified - defaulting to {noisefreq} (1/tr)")
1174
- if noisestarttime is None:
1175
- if filenoisestarttime is not None:
1176
- noisestarttime = filenoisestarttime
1177
- else:
1178
- LGR.warning("no regressor start time specified - defaulting to 0.0")
1179
- noisestarttime = 0.0
1180
- noiseperiod = 1.0 / noisefreq
1181
- numnoise = len(noisevec)
1182
- optiondict["noisefreq"] = noisefreq
1183
- optiondict["noisestarttime"] = noisestarttime
1184
- LGR.debug(
1185
- "Noise timecourse start time, end time, and step: {:.3f}, {:.3f}, {:.3f}".format(
1186
- -noisestarttime, noisestarttime + numnoise * noiseperiod, noiseperiod
1187
- )
1188
- )
1189
- noise_x = np.arange(0.0, numnoise) * noiseperiod - noisestarttime
1190
- noise_y = noisevec[0:numnoise] - np.mean(noisevec[0:numnoise])
1191
- # write out the noise regressor as read
1192
- tide_io.writebidstsv(
1193
- f"{outputname}_desc-initialnoiseregressor_timeseries",
1194
- noise_y,
1195
- noisefreq,
1196
- starttime=-noisestarttime,
1197
- columns=["prefilt"],
1198
- append=False,
1199
- )
1200
- LGR.verbose("noise vector")
1201
- LGR.verbose(f"length: {len(noisevec)}")
1202
- LGR.verbose(f"noise freq: {noisefreq}")
1203
- LGR.verbose(f"noise start time: {noisestarttime:.3f}")
1204
-
1205
1028
  # generate the time axes
1206
1029
  fmrifreq = 1.0 / fmritr
1207
1030
  optiondict["fmrifreq"] = fmrifreq
@@ -1278,8 +1101,6 @@ def rapidtide_main(argparsingfunc):
1278
1101
  reference_y = -np.gradient(reference_y_classfilter)
1279
1102
  else:
1280
1103
  reference_y = reference_y_classfilter
1281
- if optiondict["noisetimecoursespec"] is not None:
1282
- noise_y = theprefilter.apply(noisefreq, noise_y)
1283
1104
 
1284
1105
  # write out the reference regressor used
1285
1106
  tide_io.writebidstsv(
@@ -1306,26 +1127,6 @@ def rapidtide_main(argparsingfunc):
1306
1127
  debug=optiondict["debug"],
1307
1128
  )
1308
1129
  reference_y = rt_floatset(reference_y_filt.real)
1309
- if optiondict["noisetimecoursespec"] is not None:
1310
- noise_y_filt = tide_filt.dolptrapfftfilt(
1311
- noisefreq,
1312
- 0.25 * fmrifreq,
1313
- 0.5 * fmrifreq,
1314
- noise_y,
1315
- padlen=int(noisefreq * optiondict["padseconds"]),
1316
- debug=optiondict["debug"],
1317
- )
1318
- noise_y = rt_floatset(noise_y_filt.real)
1319
-
1320
- # write out the noise regressor after filtering
1321
- tide_io.writebidstsv(
1322
- f"{outputname}_desc-initialnoiseregressor_timeseries",
1323
- noise_y,
1324
- noisefreq,
1325
- starttime=-noisestarttime,
1326
- columns=["postfilt"],
1327
- append=True,
1328
- )
1329
1130
 
1330
1131
  warnings.filterwarnings("ignore", "Casting*")
1331
1132
 
@@ -1359,22 +1160,6 @@ def rapidtide_main(argparsingfunc):
1359
1160
  order=optiondict["detrendorder"],
1360
1161
  demean=optiondict["dodemean"],
1361
1162
  )
1362
- if optiondict["noisetimecoursespec"] is not None:
1363
- if optiondict["detrendorder"] > 0:
1364
- resampnoise_y = tide_fit.detrend(
1365
- tide_resample.doresample(
1366
- noise_x,
1367
- noise_y,
1368
- os_fmri_x,
1369
- padlen=int(oversampfreq * optiondict["padseconds"]),
1370
- padtype="zero",
1371
- method=optiondict["interptype"],
1372
- debug=optiondict["debug"],
1373
- ),
1374
- order=optiondict["detrendorder"],
1375
- demean=optiondict["dodemean"],
1376
- )
1377
-
1378
1163
  else:
1379
1164
  resampnonosref_y = tide_resample.doresample(
1380
1165
  reference_x,
@@ -1390,15 +1175,6 @@ def rapidtide_main(argparsingfunc):
1390
1175
  padlen=int(oversampfreq * optiondict["padseconds"]),
1391
1176
  method=optiondict["interptype"],
1392
1177
  )
1393
- if optiondict["noisetimecoursespec"] is not None:
1394
- resampnoise_y = tide_resample.doresample(
1395
- noise_x,
1396
- noise_y,
1397
- os_fmri_x,
1398
- padlen=int(oversampfreq * optiondict["padseconds"]),
1399
- padtype="zero",
1400
- method=optiondict["interptype"],
1401
- )
1402
1178
 
1403
1179
  LGR.debug(
1404
1180
  f"{len(os_fmri_x)} "
@@ -1460,22 +1236,6 @@ def rapidtide_main(argparsingfunc):
1460
1236
  else:
1461
1237
  tmaskos_y = None
1462
1238
 
1463
- if optiondict["noisetimecoursespec"] is not None:
1464
- tide_io.writebidstsv(
1465
- f"{outputname}_desc-noiseregressor_timeseries",
1466
- tide_math.stdnormalize(resampnonosref_y),
1467
- 1.0 / fmritr,
1468
- columns=["resampled"],
1469
- append=False,
1470
- )
1471
- tide_io.writebidstsv(
1472
- f"{outputname}_desc-oversamplednoiseregressor_timeseries",
1473
- tide_math.stdnormalize(resampref_y),
1474
- oversampfreq,
1475
- columns=["oversampled"],
1476
- append=False,
1477
- )
1478
-
1479
1239
  (
1480
1240
  optiondict["kurtosis_reference_pass1"],
1481
1241
  optiondict["kurtosisz_reference_pass1"],
@@ -1666,7 +1426,7 @@ def rapidtide_main(argparsingfunc):
1666
1426
  print(f"allocated {thesize:.3f} {theunit} {ramlocation} for correlation")
1667
1427
  tide_util.logmem("after correlation array allocation")
1668
1428
 
1669
- # if there is a fixed delay map, read it in
1429
+ # if there is an initial delay map, read it in
1670
1430
  if optiondict["initialdelayvalue"] is not None:
1671
1431
  try:
1672
1432
  theinitialdelay = float(optiondict["initialdelayvalue"])
@@ -1701,9 +1461,10 @@ def rapidtide_main(argparsingfunc):
1701
1461
  + 30.0
1702
1462
  + np.abs(optiondict["offsettime"])
1703
1463
  )
1704
- LGR.info(f"setting up fast resampling with padtime = {optiondict['fastresamplerpadtime']}")
1705
1464
  numpadtrs = int(optiondict["fastresamplerpadtime"] // fmritr)
1706
1465
  optiondict["fastresamplerpadtime"] = fmritr * numpadtrs
1466
+ LGR.info(f"setting up fast resampling with padtime = {optiondict['fastresamplerpadtime']}")
1467
+
1707
1468
  genlagtc = tide_resample.FastResampler(
1708
1469
  reference_x, reference_y, padtime=optiondict["fastresamplerpadtime"]
1709
1470
  )
@@ -1731,13 +1492,14 @@ def rapidtide_main(argparsingfunc):
1731
1492
  2 * numpadtrs + np.shape(initial_fmri_x)[0],
1732
1493
  )
1733
1494
 
1495
+ # prepare for regressor refinement, if we're doing it
1734
1496
  if (
1735
1497
  optiondict["passes"] > 1
1736
1498
  or optiondict["globalpreselect"]
1737
1499
  or optiondict["dofinalrefine"]
1738
1500
  or optiondict["convergencethresh"] is not None
1739
1501
  ):
1740
- # we will be doing regressor refinement, so set that up
1502
+ # we will be doing regressor refinement, so configure the refiner
1741
1503
  theRegressorRefiner = tide_regrefiner.RegressorRefiner(
1742
1504
  internalvalidfmrishape,
1743
1505
  internalvalidpaddedfmrishape,
@@ -1778,8 +1540,6 @@ def rapidtide_main(argparsingfunc):
1778
1540
  debug=optiondict["debug"],
1779
1541
  )
1780
1542
 
1781
- outfmriarray = np.zeros(internalfmrishape, dtype=rt_floattype)
1782
-
1783
1543
  # cycle over all voxels
1784
1544
  refine = True
1785
1545
  LGR.verbose(f"refine is set to {refine}")
@@ -1789,7 +1549,7 @@ def rapidtide_main(argparsingfunc):
1789
1549
  LGR.verbose(f"edgebufferfrac set to {optiondict['edgebufferfrac']}")
1790
1550
 
1791
1551
  # initialize the correlation fitter
1792
- thefitter = tide_classes.SimilarityFunctionFitter(
1552
+ theFitter = tide_classes.SimilarityFunctionFitter(
1793
1553
  lagmod=optiondict["lagmod"],
1794
1554
  lthreshval=optiondict["lthreshval"],
1795
1555
  uthreshval=optiondict["uthreshval"],
@@ -1810,11 +1570,6 @@ def rapidtide_main(argparsingfunc):
1810
1570
  if optiondict["echocancel"]:
1811
1571
  LGR.info("\n\nEcho cancellation")
1812
1572
  TimingLGR.info("Echo cancellation start")
1813
- calcsimilaritypass_func = addmemprofiling(
1814
- tide_calcsimfunc.correlationpass,
1815
- optiondict["memprofile"],
1816
- "before correlationpass",
1817
- )
1818
1573
 
1819
1574
  referencetc = tide_math.corrnormalize(
1820
1575
  resampref_y[osvalidsimcalcstart : osvalidsimcalcend + 1],
@@ -1822,12 +1577,12 @@ def rapidtide_main(argparsingfunc):
1822
1577
  windowfunc=optiondict["windowfunc"],
1823
1578
  )
1824
1579
 
1825
- disablemkl(optiondict["nprocs_calcsimilarity"], debug=threaddebug)
1580
+ tide_util.disablemkl(optiondict["nprocs_calcsimilarity"], debug=threaddebug)
1826
1581
  (
1827
1582
  voxelsprocessed_echo,
1828
1583
  theglobalmaxlist,
1829
1584
  trimmedcorrscale,
1830
- ) = calcsimilaritypass_func(
1585
+ ) = tide_calcsimfunc.correlationpass(
1831
1586
  fmri_data_valid[:, validsimcalcstart : validsimcalcend + 1],
1832
1587
  referencetc,
1833
1588
  theCorrelator,
@@ -1846,7 +1601,7 @@ def rapidtide_main(argparsingfunc):
1846
1601
  rt_floatset=rt_floatset,
1847
1602
  rt_floattype=rt_floattype,
1848
1603
  )
1849
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
1604
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
1850
1605
 
1851
1606
  for i in range(len(theglobalmaxlist)):
1852
1607
  theglobalmaxlist[i] = corrscale[theglobalmaxlist[i]] - optiondict["simcalcoffset"]
@@ -1915,237 +1670,51 @@ def rapidtide_main(argparsingfunc):
1915
1670
  )
1916
1671
 
1917
1672
  # Step -1 - check the regressor for periodic components in the passband
1918
- dolagmod = True
1919
- doreferencenotch = True
1920
- if optiondict["respdelete"]:
1921
- resptracker = tide_classes.FrequencyTracker(nperseg=64)
1922
- thetimes, thefreqs = resptracker.track(resampref_y, 1.0 / oversamptr)
1923
- tide_io.writevec(thefreqs, f"{outputname}_peakfreaks_pass{thepass}.txt")
1924
- resampref_y = resptracker.clean(resampref_y, 1.0 / oversamptr, thetimes, thefreqs)
1925
- tide_io.writevec(resampref_y, f"{outputname}_respfilt_pass{thepass}.txt")
1926
- referencetc = tide_math.corrnormalize(
1927
- resampref_y[osvalidsimcalcstart : osvalidsimcalcend + 1],
1928
- detrendorder=optiondict["detrendorder"],
1929
- windowfunc=optiondict["windowfunc"],
1930
- )
1931
- if optiondict["noisetimecoursespec"] is not None:
1932
- # align the noise signal with referencetc
1933
- (
1934
- shiftednoise,
1935
- optiondict[f"noisedelay_pass{thepass}"],
1936
- optiondict[f"noisecorr_pass{thepass}"],
1937
- dummy,
1938
- ) = tide_corr.aligntcwithref(
1939
- resampref_y,
1940
- resampnoise_y,
1941
- oversampfreq,
1942
- zerooutbadfit=False,
1943
- verbose=True,
1944
- )
1945
- LGR.info(
1946
- "Maximum correlation amplitude with noise regressor is "
1947
- + str(optiondict[f"noisecorr_pass{thepass}"])
1948
- + " at "
1949
- + str(optiondict[f"noisedelay_pass{thepass}"])
1950
- )
1951
-
1952
- # regress out
1953
- resampref_y, datatoremove, R, dummy = tide_fit.linfitfilt(
1954
- resampref_y, shiftednoise, debug=True
1955
- )
1956
-
1957
- # save
1958
- tide_io.writebidstsv(
1959
- f"{outputname}_desc-regressornoiseremoval_timeseries",
1960
- shiftednoise,
1961
- 1.0 / oversamptr,
1962
- starttime=0.0,
1963
- columns=[f"shiftednoise_pass{thepass}"],
1964
- append=(thepass > 1),
1965
- )
1966
- tide_io.writebidstsv(
1967
- f"{outputname}_desc-regressornoiseremoval_timeseries",
1968
- datatoremove,
1969
- 1.0 / oversamptr,
1970
- starttime=0.0,
1971
- columns=[f"removed_pass{thepass}"],
1972
- append=True,
1973
- )
1974
- tide_io.writebidstsv(
1975
- f"{outputname}_desc-regressornoiseremoval_timeseries",
1976
- resampref_y,
1977
- 1.0 / oversamptr,
1978
- starttime=0.0,
1979
- columns=[f"filtered_pass{thepass}"],
1980
- append=True,
1981
- )
1982
-
1983
- if optiondict["check_autocorrelation"]:
1984
- LGR.info("checking reference regressor autocorrelation properties")
1985
- optiondict["lagmod"] = 1000.0
1986
- lagindpad = np.max((lagmininpts, lagmaxinpts))
1987
- acmininpts = lagindpad
1988
- acmaxinpts = lagindpad
1989
- theCorrelator.setreftc(referencetc)
1990
- theCorrelator.setlimits(acmininpts, acmaxinpts)
1991
- # theCorrelator.setlimits(lagmininpts, lagmaxinpts)
1992
- print("check_autocorrelation:", acmininpts, acmaxinpts, lagmininpts, lagmaxinpts)
1993
- thexcorr, accheckcorrscale, dummy = theCorrelator.run(
1994
- resampref_y[osvalidsimcalcstart : osvalidsimcalcend + 1]
1995
- )
1996
- thefitter.setcorrtimeaxis(accheckcorrscale)
1997
- (
1998
- dummy,
1999
- dummy,
2000
- dummy,
2001
- acwidth,
2002
- dummy,
2003
- dummy,
2004
- dummy,
2005
- dummy,
2006
- ) = tide_simfuncfit.onesimfuncfit(
2007
- thexcorr,
2008
- thefitter,
2009
- despeckle_thresh=optiondict["despeckle_thresh"],
2010
- lthreshval=optiondict["lthreshval"],
2011
- fixdelay=optiondict["fixdelay"],
2012
- rt_floatset=rt_floatset,
2013
- rt_floattype=rt_floattype,
2014
- )
2015
- tide_io.writebidstsv(
2016
- f"{outputname}_desc-autocorr_timeseries",
2017
- thexcorr,
2018
- 1.0 / (accheckcorrscale[1] - accheckcorrscale[0]),
2019
- starttime=accheckcorrscale[0],
2020
- extraheaderinfo={
2021
- "Description": "Autocorrelation of the probe regressor for each pass"
2022
- },
2023
- columns=[f"pass{thepass}"],
2024
- append=(thepass > 1),
2025
- )
2026
- thelagthresh = np.max((abs(optiondict["lagmin"]), abs(optiondict["lagmax"])))
2027
- theampthresh = 0.1
2028
- LGR.info(
2029
- f"searching for sidelobes with amplitude > {theampthresh} "
2030
- f"with abs(lag) < {thelagthresh} s"
2031
- )
2032
- sidelobetime, sidelobeamp = tide_corr.check_autocorrelation(
2033
- accheckcorrscale,
2034
- thexcorr,
2035
- acampthresh=theampthresh,
2036
- aclagthresh=thelagthresh,
2037
- detrendorder=optiondict["detrendorder"],
2038
- )
2039
- optiondict["acwidth"] = acwidth + 0.0
2040
- optiondict["absmaxsigma"] = acwidth * 10.0
2041
- passsuffix = "_pass" + str(thepass)
2042
- if sidelobetime is not None:
2043
- optiondict["acsidelobelag" + passsuffix] = sidelobetime
2044
- optiondict["despeckle_thresh"] = np.max(
2045
- [optiondict["despeckle_thresh"], sidelobetime / 2.0]
2046
- )
2047
- optiondict["acsidelobeamp" + passsuffix] = sidelobeamp
2048
- LGR.warning(
2049
- f"\n\nWARNING: check_autocorrelation found bad sidelobe at {sidelobetime} "
2050
- f"seconds ({1.0 / sidelobetime} Hz)..."
2051
- )
2052
- # bidsify
2053
- """tide_io.writebidstsv(
2054
- f"{outputname}_desc-movingregressor_timeseries",
2055
- tide_math.stdnormalize(resampnonosref_y),
2056
- 1.0 / fmritr,
2057
- columns=["pass1"],
2058
- append=False,
2059
- )"""
2060
- tide_io.writenpvecs(
2061
- np.array([sidelobetime]),
2062
- f"{outputname}_autocorr_sidelobetime" + passsuffix + ".txt",
2063
- )
2064
- if optiondict["fix_autocorrelation"]:
2065
- LGR.info("Removing sidelobe")
2066
- if dolagmod:
2067
- LGR.info("subjecting lag times to modulus")
2068
- optiondict["lagmod"] = sidelobetime / 2.0
2069
- if doreferencenotch:
2070
- LGR.info("removing spectral component at sidelobe frequency")
2071
- acstopfreq = 1.0 / sidelobetime
2072
- acfixfilter = tide_filt.NoncausalFilter(
2073
- debug=optiondict["debug"],
2074
- )
2075
- acfixfilter.settype("arb_stop")
2076
- acfixfilter.setfreqs(
2077
- acstopfreq * 0.9,
2078
- acstopfreq * 0.95,
2079
- acstopfreq * 1.05,
2080
- acstopfreq * 1.1,
2081
- )
2082
- cleaned_resampref_y = tide_math.corrnormalize(
2083
- acfixfilter.apply(1.0 / oversamptr, resampref_y),
2084
- windowfunc="None",
2085
- detrendorder=optiondict["detrendorder"],
2086
- )
2087
- cleaned_referencetc = tide_math.corrnormalize(
2088
- cleaned_resampref_y,
2089
- detrendorder=optiondict["detrendorder"],
2090
- windowfunc=optiondict["windowfunc"],
2091
- )
2092
- cleaned_nonosreferencetc = tide_math.stdnormalize(
2093
- acfixfilter.apply(fmrifreq, resampnonosref_y)
2094
- )
2095
- tide_io.writebidstsv(
2096
- f"{outputname}_desc-cleanedreferencefmrires_info",
2097
- cleaned_nonosreferencetc,
2098
- fmrifreq,
2099
- columns=[f"pass{thepass}"],
2100
- append=(thepass > 1),
2101
- )
2102
- tide_io.writebidstsv(
2103
- f"{outputname}_desc-cleanedreference_info",
2104
- cleaned_referencetc,
2105
- 1.0 / oversamptr,
2106
- columns=[f"pass{thepass}"],
2107
- append=(thepass > 1),
2108
- )
2109
- tide_io.writebidstsv(
2110
- f"{outputname}_desc-cleanedresamprefy_info",
2111
- cleaned_resampref_y,
2112
- 1.0 / oversamptr,
2113
- columns=[f"pass{thepass}"],
2114
- append=(thepass > 1),
2115
- )
2116
- else:
2117
- cleaned_resampref_y = 1.0 * tide_math.corrnormalize(
2118
- resampref_y,
2119
- windowfunc="None",
2120
- detrendorder=optiondict["detrendorder"],
2121
- )
2122
- cleaned_referencetc = 1.0 * referencetc
2123
- cleaned_nonosreferencetc = 1.0 * resampnonosref_y
2124
- else:
2125
- LGR.info("no sidelobes found in range")
2126
- cleaned_resampref_y = 1.0 * tide_math.corrnormalize(
2127
- resampref_y,
2128
- windowfunc="None",
2129
- detrendorder=optiondict["detrendorder"],
2130
- )
2131
- cleaned_referencetc = 1.0 * referencetc
2132
- cleaned_nonosreferencetc = 1.0 * resampnonosref_y
2133
- else:
2134
- cleaned_resampref_y = 1.0 * tide_math.corrnormalize(
2135
- resampref_y, windowfunc="None", detrendorder=optiondict["detrendorder"]
2136
- )
2137
- cleaned_referencetc = 1.0 * referencetc
2138
- cleaned_nonosreferencetc = 1.0 * resampnonosref_y
1673
+ passsuffix = "_pass" + str(thepass)
1674
+ (
1675
+ cleaned_resampref_y,
1676
+ cleaned_referencetc,
1677
+ cleaned_nonosreferencetc,
1678
+ optiondict["despeckle_thresh"],
1679
+ optiondict["acsidelobeamp" + passsuffix],
1680
+ optiondict["acsidelobelag" + passsuffix],
1681
+ optiondict["lagmod"],
1682
+ optiondict["acwidth"],
1683
+ optiondict["absmaxsigma"],
1684
+ ) = tide_cleanregressor.cleanregressor(
1685
+ outputname,
1686
+ thepass,
1687
+ referencetc,
1688
+ resampref_y,
1689
+ resampnonosref_y,
1690
+ fmrifreq,
1691
+ oversampfreq,
1692
+ osvalidsimcalcstart,
1693
+ osvalidsimcalcend,
1694
+ lagmininpts,
1695
+ lagmaxinpts,
1696
+ theFitter,
1697
+ theCorrelator,
1698
+ optiondict["lagmin"],
1699
+ optiondict["lagmax"],
1700
+ LGR=LGR,
1701
+ check_autocorrelation=optiondict["check_autocorrelation"],
1702
+ fix_autocorrelation=optiondict["fix_autocorrelation"],
1703
+ despeckle_thresh=optiondict["despeckle_thresh"],
1704
+ lthreshval=optiondict["lthreshval"],
1705
+ fixdelay=optiondict["fixdelay"],
1706
+ detrendorder=optiondict["detrendorder"],
1707
+ windowfunc=optiondict["windowfunc"],
1708
+ respdelete=optiondict["respdelete"],
1709
+ debug=optiondict["debug"],
1710
+ rt_floattype=rt_floattype,
1711
+ rt_floatset=rt_floatset,
1712
+ )
2139
1713
 
2140
1714
  # Step 0 - estimate significance
2141
1715
  if optiondict["numestreps"] > 0:
2142
1716
  TimingLGR.info(f"Significance estimation start, pass {thepass}")
2143
1717
  LGR.info(f"\n\nSignificance estimation, pass {thepass}")
2144
- getNullDistributionData_func = addmemprofiling(
2145
- tide_nullsimfunc.getNullDistributionDatax,
2146
- optiondict["memprofile"],
2147
- "before getnulldistristributiondata",
2148
- )
2149
1718
  if optiondict["checkpoint"]:
2150
1719
  # bidsify
2151
1720
  """tide_io.writebidstsv(
@@ -2172,19 +1741,19 @@ def rapidtide_main(argparsingfunc):
2172
1741
  theMutualInformationator.setlimits(lagmininpts, lagmaxinpts)
2173
1742
  theMutualInformationator.setreftc(cleaned_resampref_y)
2174
1743
  dummy, trimmedcorrscale, dummy = theCorrelator.getfunction()
2175
- thefitter.setcorrtimeaxis(trimmedcorrscale)
1744
+ theFitter.setcorrtimeaxis(trimmedcorrscale)
2176
1745
 
2177
1746
  # parallel path for mutual information
2178
1747
  if optiondict["similaritymetric"] == "mutualinfo":
2179
1748
  theSimFunc = theMutualInformationator
2180
1749
  else:
2181
1750
  theSimFunc = theCorrelator
2182
- disablemkl(optiondict["nprocs_getNullDist"], debug=threaddebug)
2183
- simdistdata = getNullDistributionData_func(
1751
+ tide_util.disablemkl(optiondict["nprocs_getNullDist"], debug=threaddebug)
1752
+ simdistdata = tide_nullsimfunc.getNullDistributionDatax(
2184
1753
  cleaned_resampref_y,
2185
1754
  oversampfreq,
2186
1755
  theSimFunc,
2187
- thefitter,
1756
+ theFitter,
2188
1757
  numestreps=optiondict["numestreps"],
2189
1758
  nprocs=optiondict["nprocs_getNullDist"],
2190
1759
  alwaysmultiproc=optiondict["alwaysmultiproc"],
@@ -2195,7 +1764,7 @@ def rapidtide_main(argparsingfunc):
2195
1764
  rt_floatset=np.float64,
2196
1765
  rt_floattype="float64",
2197
1766
  )
2198
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
1767
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2199
1768
 
2200
1769
  tide_io.writebidstsv(
2201
1770
  f"{outputname}_desc-simdistdata_info",
@@ -2286,11 +1855,20 @@ def rapidtide_main(argparsingfunc):
2286
1855
  "message3": "repetitions",
2287
1856
  },
2288
1857
  )
2289
-
2290
1858
  # write out the current version of the run options
2291
1859
  optiondict["currentstage"] = f"precorrelation_pass{thepass}"
2292
1860
  tide_io.writedicttojson(optiondict, f"{outputname}_desc-runoptions_info.json")
2293
1861
 
1862
+ # tide_delayestimate.estimateDelay(
1863
+ # fmri_data_valid[:, validsimcalcstart : validsimcalcend + 1],
1864
+ # initial_fmri_x[validsimcalcstart : validsimcalcend + 1],
1865
+ # os_fmri_x[osvalidsimcalcstart : osvalidsimcalcend + 1],
1866
+ # theMutualInformationator,
1867
+ # thepass,
1868
+ # )
1869
+ ########################
1870
+ # Delay estimation start
1871
+ ########################
2294
1872
  # Step 1 - Correlation step
2295
1873
  if optiondict["similaritymetric"] == "mutualinfo":
2296
1874
  similaritytype = "Mutual information"
@@ -2300,20 +1878,15 @@ def rapidtide_main(argparsingfunc):
2300
1878
  similaritytype = "MI enhanced correlation"
2301
1879
  LGR.info(f"\n\n{similaritytype} calculation, pass {thepass}")
2302
1880
  TimingLGR.info(f"{similaritytype} calculation start, pass {thepass}")
2303
- calcsimilaritypass_func = addmemprofiling(
2304
- tide_calcsimfunc.correlationpass,
2305
- optiondict["memprofile"],
2306
- "before correlationpass",
2307
- )
2308
1881
 
2309
- disablemkl(optiondict["nprocs_calcsimilarity"], debug=threaddebug)
1882
+ tide_util.disablemkl(optiondict["nprocs_calcsimilarity"], debug=threaddebug)
2310
1883
  if optiondict["similaritymetric"] == "mutualinfo":
2311
1884
  theMutualInformationator.setlimits(lagmininpts, lagmaxinpts)
2312
1885
  (
2313
1886
  voxelsprocessed_cp,
2314
1887
  theglobalmaxlist,
2315
1888
  trimmedcorrscale,
2316
- ) = calcsimilaritypass_func(
1889
+ ) = tide_calcsimfunc.correlationpass(
2317
1890
  fmri_data_valid[:, validsimcalcstart : validsimcalcend + 1],
2318
1891
  cleaned_referencetc,
2319
1892
  theMutualInformationator,
@@ -2337,7 +1910,7 @@ def rapidtide_main(argparsingfunc):
2337
1910
  voxelsprocessed_cp,
2338
1911
  theglobalmaxlist,
2339
1912
  trimmedcorrscale,
2340
- ) = calcsimilaritypass_func(
1913
+ ) = tide_calcsimfunc.correlationpass(
2341
1914
  fmri_data_valid[:, validsimcalcstart : validsimcalcend + 1],
2342
1915
  cleaned_referencetc,
2343
1916
  theCorrelator,
@@ -2356,7 +1929,7 @@ def rapidtide_main(argparsingfunc):
2356
1929
  rt_floatset=rt_floatset,
2357
1930
  rt_floattype=rt_floattype,
2358
1931
  )
2359
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
1932
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2360
1933
 
2361
1934
  for i in range(len(theglobalmaxlist)):
2362
1935
  theglobalmaxlist[i] = corrscale[theglobalmaxlist[i]] - optiondict["simcalcoffset"]
@@ -2398,14 +1971,9 @@ def rapidtide_main(argparsingfunc):
2398
1971
  if optiondict["similaritymetric"] == "hybrid":
2399
1972
  LGR.info(f"\n\nPeak prefit calculation, pass {thepass}")
2400
1973
  TimingLGR.info(f"Peak prefit calculation start, pass {thepass}")
2401
- peakevalpass_func = addmemprofiling(
2402
- tide_peakeval.peakevalpass,
2403
- optiondict["memprofile"],
2404
- "before peakevalpass",
2405
- )
2406
1974
 
2407
- disablemkl(optiondict["nprocs_peakeval"], debug=threaddebug)
2408
- voxelsprocessed_pe, thepeakdict = peakevalpass_func(
1975
+ tide_util.disablemkl(optiondict["nprocs_peakeval"], debug=threaddebug)
1976
+ voxelsprocessed_pe, thepeakdict = tide_peakeval.peakevalpass(
2409
1977
  fmri_data_valid[:, validsimcalcstart : validsimcalcend + 1],
2410
1978
  cleaned_referencetc,
2411
1979
  initial_fmri_x[validsimcalcstart : validsimcalcend + 1],
@@ -2423,7 +1991,7 @@ def rapidtide_main(argparsingfunc):
2423
1991
  rt_floatset=rt_floatset,
2424
1992
  rt_floattype=rt_floattype,
2425
1993
  )
2426
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
1994
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2427
1995
 
2428
1996
  TimingLGR.info(
2429
1997
  f"Peak prefit end, pass {thepass}",
@@ -2445,11 +2013,9 @@ def rapidtide_main(argparsingfunc):
2445
2013
  tide_io.writedicttojson(optiondict, f"{outputname}_desc-runoptions_info.json")
2446
2014
  LGR.info(f"\n\nTime lag estimation pass {thepass}")
2447
2015
  TimingLGR.info(f"Time lag estimation start, pass {thepass}")
2448
- fitcorr_func = addmemprofiling(
2449
- tide_simfuncfit.fitcorr, optiondict["memprofile"], "before fitcorr"
2450
- )
2451
- thefitter.setfunctype(optiondict["similaritymetric"])
2452
- thefitter.setcorrtimeaxis(trimmedcorrscale)
2016
+
2017
+ theFitter.setfunctype(optiondict["similaritymetric"])
2018
+ theFitter.setcorrtimeaxis(trimmedcorrscale)
2453
2019
 
2454
2020
  # use initial lags if this is a hybrid fit
2455
2021
  if optiondict["similaritymetric"] == "hybrid" and thepeakdict is not None:
@@ -2457,10 +2023,10 @@ def rapidtide_main(argparsingfunc):
2457
2023
  else:
2458
2024
  initlags = None
2459
2025
 
2460
- disablemkl(optiondict["nprocs_fitcorr"], debug=threaddebug)
2461
- voxelsprocessed_fc = fitcorr_func(
2026
+ tide_util.disablemkl(optiondict["nprocs_fitcorr"], debug=threaddebug)
2027
+ voxelsprocessed_fc = tide_simfuncfit.fitcorr(
2462
2028
  trimmedcorrscale,
2463
- thefitter,
2029
+ theFitter,
2464
2030
  corrout,
2465
2031
  fitmask,
2466
2032
  failreason,
@@ -2483,7 +2049,7 @@ def rapidtide_main(argparsingfunc):
2483
2049
  rt_floatset=rt_floatset,
2484
2050
  rt_floattype=rt_floattype,
2485
2051
  )
2486
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
2052
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2487
2053
 
2488
2054
  TimingLGR.info(
2489
2055
  f"Time lag estimation end, pass {thepass}",
@@ -2523,10 +2089,10 @@ def rapidtide_main(argparsingfunc):
2523
2089
  numdespeckled = len(np.where(initlags != -1000000.0)[0])
2524
2090
  if lastnumdespeckled > numdespeckled > 0:
2525
2091
  lastnumdespeckled = numdespeckled
2526
- disablemkl(optiondict["nprocs_fitcorr"], debug=threaddebug)
2527
- voxelsprocessed_thispass = fitcorr_func(
2092
+ tide_util.disablemkl(optiondict["nprocs_fitcorr"], debug=threaddebug)
2093
+ voxelsprocessed_thispass = tide_simfuncfit.fitcorr(
2528
2094
  trimmedcorrscale,
2529
- thefitter,
2095
+ theFitter,
2530
2096
  corrout,
2531
2097
  fitmask,
2532
2098
  failreason,
@@ -2549,7 +2115,7 @@ def rapidtide_main(argparsingfunc):
2549
2115
  rt_floatset=rt_floatset,
2550
2116
  rt_floattype=rt_floattype,
2551
2117
  )
2552
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
2118
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2553
2119
 
2554
2120
  voxelsprocessed_fc_ds += voxelsprocessed_thispass
2555
2121
  optiondict[
@@ -2742,6 +2308,9 @@ def rapidtide_main(argparsingfunc):
2742
2308
 
2743
2309
  # now shift the patches to align with the majority of the image
2744
2310
  tide_patch.interppatch(lagtimes, patchmap[validvoxels])
2311
+ ########################
2312
+ # Delay estimation end
2313
+ ########################
2745
2314
 
2746
2315
  # Step 2d - make a rank order map
2747
2316
  timepercentile = (
@@ -2871,11 +2440,11 @@ def rapidtide_main(argparsingfunc):
2871
2440
 
2872
2441
  # align timecourses to prepare for refinement
2873
2442
  LGR.info("aligning timecourses")
2874
- disablemkl(optiondict["nprocs_refine"], debug=threaddebug)
2443
+ tide_util.disablemkl(optiondict["nprocs_refine"], debug=threaddebug)
2875
2444
  voxelsprocessed_rra = theRegressorRefiner.alignvoxels(
2876
2445
  fmri_data_valid, fmritr, lagtimes
2877
2446
  )
2878
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
2447
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2879
2448
  LGR.info(f"align complete: {voxelsprocessed_rra=}")
2880
2449
 
2881
2450
  # prenormalize
@@ -2910,57 +2479,6 @@ def rapidtide_main(argparsingfunc):
2910
2479
  )
2911
2480
  for key, value in outputdict.items():
2912
2481
  optiondict[key] = value
2913
-
2914
- """if optiondict["saveintermediatemaps"]:
2915
- if not optiondict["textio"]:
2916
- theheader = copy.deepcopy(nim_hdr)
2917
- if fileiscifti:
2918
- timeindex = theheader["dim"][0] - 1
2919
- spaceindex = theheader["dim"][0]
2920
- theheader["dim"][timeindex] = 1
2921
- theheader["dim"][spaceindex] = numspatiallocs
2922
- else:
2923
- theheader["dim"][0] = 3
2924
- theheader["dim"][4] = 1
2925
- theheader["pixdim"][4] = 1.0
2926
- bidspasssuffix = f"_intermediatedata-pass{thepass}"
2927
- maplist = [
2928
- (fitmask, "corrfit", "mask", None, "Voxels where correlation value was fit"),
2929
- (
2930
- failreason,
2931
- "corrfitfailreason",
2932
- "info",
2933
- None,
2934
- "Result codes for correlation fit",
2935
- ),
2936
- ]
2937
- if optiondict["savedespecklemasks"] and (optiondict["despeckle_passes"] > 0):
2938
- maplist.append(
2939
- (
2940
- despecklesavemask,
2941
- "despecklemask",
2942
- "map",
2943
- None,
2944
- "Voxels that underwent despeckling",
2945
- )
2946
- )
2947
- if thepass < optiondict["passes"]:
2948
- maplist.append(
2949
- (refinemask, "refinemask", "map", None, "Voxels used for regressor refinement")
2950
- )
2951
- tide_io.savemaplist(
2952
- f"{outputname}{bidspasssuffix}",
2953
- maplist,
2954
- validvoxels,
2955
- nativespaceshape,
2956
- theheader,
2957
- bidsbasedict,
2958
- textio=optiondict["textio"],
2959
- fileiscifti=fileiscifti,
2960
- rt_floattype=rt_floattype,
2961
- cifti_hdr=cifti_hdr,
2962
- )"""
2963
-
2964
2482
  # We are done with refinement.
2965
2483
 
2966
2484
  if optiondict["convergencethresh"] is None:
@@ -3047,13 +2565,8 @@ def rapidtide_main(argparsingfunc):
3047
2565
  thesize, theunit = tide_util.format_bytes(optiondict["totalcoherencebytes"])
3048
2566
  print(f"allocated {thesize:.3f} {theunit} {ramlocation} for coherence calculation")
3049
2567
 
3050
- coherencepass_func = addmemprofiling(
3051
- tide_calccoherence.coherencepass,
3052
- optiondict["memprofile"],
3053
- "before coherencepass",
3054
- )
3055
- disablemkl(1, debug=threaddebug)
3056
- voxelsprocessed_coherence = coherencepass_func(
2568
+ tide_util.disablemkl(1, debug=threaddebug)
2569
+ voxelsprocessed_coherence = tide_calccoherence.coherencepass(
3057
2570
  fmri_data_valid,
3058
2571
  theCoherer,
3059
2572
  coherencefunc,
@@ -3067,7 +2580,7 @@ def rapidtide_main(argparsingfunc):
3067
2580
  rt_floatset=rt_floatset,
3068
2581
  rt_floattype=rt_floattype,
3069
2582
  )
3070
- enablemkl(optiondict["mklthreads"], debug=threaddebug)
2583
+ tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
3071
2584
 
3072
2585
  # save the results of the calculations
3073
2586
  if not optiondict["textio"]:
@@ -3127,12 +2640,7 @@ def rapidtide_main(argparsingfunc):
3127
2640
  thesize, theunit = tide_util.format_bytes(optiondict["totalwienerbytes"])
3128
2641
  print(f"allocated {thesize:.3f} {theunit} {ramlocation} for wiener deconvolution")
3129
2642
 
3130
- wienerpass_func = addmemprofiling(
3131
- tide_wiener.wienerpass,
3132
- optiondict["memprofile"],
3133
- "before wienerpass",
3134
- )
3135
- voxelsprocessed_wiener = wienerpass_func(
2643
+ voxelsprocessed_wiener = tide_wiener.wienerpass(
3136
2644
  numspatiallocs,
3137
2645
  fmri_data_valid,
3138
2646
  threshval,
@@ -3191,29 +2699,11 @@ def rapidtide_main(argparsingfunc):
3191
2699
  f"reading in {optiondict['denoisesourcefile']} for sLFO filter, please wait"
3192
2700
  )
3193
2701
  sourcename = optiondict["denoisesourcefile"]
3194
- else:
3195
- LGR.info(f"rereading {fmrifilename} for sLFO filter, please wait")
3196
- sourcename = fmrifilename
3197
- if fileiscifti:
3198
- LGR.info("input file is CIFTI")
3199
- (
3200
- dummy,
3201
- cifti_hdr,
3202
- nim_data,
3203
- nim_hdr,
3204
- thedims,
3205
- thesizes,
3206
- dummy,
3207
- ) = tide_io.readfromcifti(sourcename)
3208
- else:
3209
- if optiondict["textio"]:
3210
- nim_data = tide_io.readvecs(sourcename)
3211
- else:
3212
- nim, nim_data, nim_hdr, thedims, thesizes = tide_io.readfromnifti(sourcename)
2702
+ theinputdata = tide_voxelData.VoxelData(sourcename, timestep=optiondict["realtr"])
2703
+ theinputdata.setvalidtimes(validstart, validend)
2704
+ theinputdata.setvalidvoxels(validvoxels)
3213
2705
 
3214
- fmri_data_valid = (
3215
- nim_data.reshape((numspatiallocs, timepoints))[:, validstart : validend + 1]
3216
- )[validvoxels, :] + 0.0
2706
+ fmri_data_valid = theinputdata.getvalidvoxels() + 0.0
3217
2707
 
3218
2708
  if optiondict["docvrmap"]:
3219
2709
  # percent normalize the fmri data
@@ -3236,18 +2726,13 @@ def rapidtide_main(argparsingfunc):
3236
2726
  tide_util.cleanup_shm(fmri_data_valid_shm)
3237
2727
  LGR.info("moving fmri data to shared memory")
3238
2728
  TimingLGR.info("Start moving fmri_data to shared memory")
3239
- numpy2shared_func = addmemprofiling(
3240
- tide_util.numpy2shared,
3241
- optiondict["memprofile"],
3242
- "before movetoshared (sLFO filter)",
3243
- )
3244
- fmri_data_valid, fmri_data_valid_shm = numpy2shared_func(
2729
+ fmri_data_valid, fmri_data_valid_shm = tide_util.numpy2shared(
3245
2730
  fmri_data_valid,
3246
2731
  rt_floatset,
3247
2732
  name=f"fmri_data_valid_regressionfilt_{optiondict['pid']}",
3248
2733
  )
3249
2734
  TimingLGR.info("End moving fmri_data to shared memory")
3250
- del nim_data
2735
+ theinputdata.unload()
3251
2736
 
3252
2737
  # now allocate the arrays needed for sLFO filtering
3253
2738
  if optiondict["refinedelay"]:
@@ -3309,12 +2794,6 @@ def rapidtide_main(argparsingfunc):
3309
2794
  )
3310
2795
  thesize, theunit = tide_util.format_bytes(optiondict["totalsLFOfilterbytes"])
3311
2796
  print(f"allocated {thesize:.3f} {theunit} {ramlocation} for sLFO filter/delay refinement")
3312
-
3313
- if optiondict["memprofile"]:
3314
- if optiondict["dolinfitfilt"]:
3315
- memcheckpoint("about to start sLFO noise removal...")
3316
- else:
3317
- memcheckpoint("about to start CVR magnitude estimation...")
3318
2797
  tide_util.logmem("before sLFO filter")
3319
2798
 
3320
2799
  if optiondict["dolinfitfilt"]:
@@ -3324,9 +2803,11 @@ def rapidtide_main(argparsingfunc):
3324
2803
  # set the threshval to zero
3325
2804
  mode = "cvrmap"
3326
2805
  optiondict["regressfiltthreshval"] = 0.0
2806
+
3327
2807
  if optiondict["debug"]:
3328
2808
  # dump the fmri input file going to sLFO filter
3329
2809
  if not optiondict["textio"]:
2810
+ outfmriarray = np.zeros(internalfmrishape, dtype=rt_floattype)
3330
2811
  theheader = copy.deepcopy(nim_hdr)
3331
2812
  if fileiscifti:
3332
2813
  timeindex = theheader["dim"][0] - 1
@@ -3339,6 +2820,7 @@ def rapidtide_main(argparsingfunc):
3339
2820
  else:
3340
2821
  theheader = None
3341
2822
  cifti_hdr = None
2823
+ outfmriarray = None
3342
2824
 
3343
2825
  maplist = [
3344
2826
  (
@@ -3361,6 +2843,8 @@ def rapidtide_main(argparsingfunc):
3361
2843
  rt_floattype=rt_floattype,
3362
2844
  cifti_hdr=cifti_hdr,
3363
2845
  )
2846
+ else:
2847
+ outfmriarray = None
3364
2848
 
3365
2849
  # refine the delay value prior to calculating the sLFO filter
3366
2850
  if optiondict["refinedelay"]:
@@ -3534,7 +3018,6 @@ def rapidtide_main(argparsingfunc):
3534
3018
  mp_chunksize=optiondict["mp_chunksize"],
3535
3019
  showprogressbar=optiondict["showprogressbar"],
3536
3020
  alwaysmultiproc=optiondict["alwaysmultiproc"],
3537
- memprofile=optiondict["memprofile"],
3538
3021
  debug=optiondict["debug"],
3539
3022
  )
3540
3023
  )
@@ -3569,10 +3052,10 @@ def rapidtide_main(argparsingfunc):
3569
3052
  "message3": "voxels",
3570
3053
  },
3571
3054
  )
3572
- if optiondict["memprofile"]:
3573
- memcheckpoint("...done")
3574
3055
  tide_util.logmem("after sLFO filter")
3575
3056
  LGR.info("")
3057
+ else:
3058
+ outfmriarray = None
3576
3059
  ####################################################
3577
3060
  # sLFO filtering end
3578
3061
  ####################################################
@@ -3984,7 +3467,6 @@ def rapidtide_main(argparsingfunc):
3984
3467
  mp_chunksize=optiondict["mp_chunksize"],
3985
3468
  showprogressbar=optiondict["showprogressbar"],
3986
3469
  alwaysmultiproc=optiondict["alwaysmultiproc"],
3987
- memprofile=optiondict["memprofile"],
3988
3470
  debug=optiondict["debug"],
3989
3471
  )
3990
3472
 
@@ -4184,6 +3666,8 @@ def rapidtide_main(argparsingfunc):
4184
3666
  tide_util.cleanup_shm(outcorrarray_shm)
4185
3667
 
4186
3668
  # now save all the files that are of the same length as the input data file and masked
3669
+ if outfmriarray is None:
3670
+ outfmriarray = np.zeros(internalfmrishape, dtype=rt_floattype)
4187
3671
  if not optiondict["textio"]:
4188
3672
  theheader = copy.deepcopy(nim_hdr)
4189
3673
  if fileiscifti: