rapidtide 3.0a12__py3-none-any.whl → 3.0a14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. cloud/gmscalc-HCPYA +1 -1
  2. cloud/rapidtide-HCPYA +3 -3
  3. rapidtide/Colortables.py +10 -10
  4. rapidtide/DerivativeDelay.py +213 -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 +14 -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} +23 -19
  25. rapidtide/makelaggedtcs.py +8 -5
  26. rapidtide/multiproc.py +8 -11
  27. rapidtide/refinedelay.py +234 -109
  28. rapidtide/resample.py +3 -0
  29. rapidtide/scripts/{retroglm.py → delayvar.py} +2 -2
  30. rapidtide/scripts/{glmfilt.py → linfitfilt.py} +2 -2
  31. rapidtide/scripts/retroregress.py +28 -0
  32. rapidtide/scripts/stupidramtricks.py +9 -7
  33. rapidtide/simfuncfit.py +1 -1
  34. rapidtide/tests/cleanposttest +21 -0
  35. rapidtide/tests/test_delayestimation.py +3 -3
  36. rapidtide/tests/test_fastresampler.py +1 -2
  37. rapidtide/tests/test_fullrunhappy_v1.py +14 -6
  38. rapidtide/tests/test_fullrunhappy_v2.py +17 -9
  39. rapidtide/tests/test_fullrunhappy_v3.py +16 -8
  40. rapidtide/tests/test_fullrunhappy_v4.py +16 -8
  41. rapidtide/tests/test_fullrunhappy_v5.py +14 -6
  42. rapidtide/tests/test_fullrunrapidtide_v1.py +20 -12
  43. rapidtide/tests/test_fullrunrapidtide_v2.py +21 -13
  44. rapidtide/tests/test_fullrunrapidtide_v3.py +15 -7
  45. rapidtide/tests/test_fullrunrapidtide_v4.py +14 -7
  46. rapidtide/tests/test_fullrunrapidtide_v5.py +13 -5
  47. rapidtide/tests/test_fullrunrapidtide_v6.py +34 -26
  48. rapidtide/tests/{test_glmpass.py → test_linfitfiltpass.py} +9 -9
  49. rapidtide/tests/test_motionregress.py +3 -3
  50. rapidtide/tests/test_refinedelay.py +14 -12
  51. rapidtide/tidepoolTemplate_alt_qt6.py +172 -45
  52. rapidtide/tidepoolTemplate_big_qt6.py +196 -53
  53. rapidtide/tidepoolTemplate_qt6.py +150 -39
  54. rapidtide/workflows/atlasaverage.py +40 -12
  55. rapidtide/workflows/delayvar.py +1136 -0
  56. rapidtide/workflows/happy.py +37 -11
  57. rapidtide/workflows/happy_parser.py +4 -4
  58. rapidtide/workflows/{glmfilt.py → linfitfilt.py} +4 -4
  59. rapidtide/workflows/rapidtide.py +246 -178
  60. rapidtide/workflows/rapidtide_parser.py +116 -101
  61. rapidtide/workflows/{glmfrommaps.py → regressfrommaps.py} +30 -26
  62. rapidtide/workflows/retrolagtcs.py +13 -12
  63. rapidtide/workflows/{retroglm.py → retroregress.py} +182 -141
  64. {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/METADATA +3 -2
  65. {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/RECORD +69 -64
  66. {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/WHEEL +1 -1
  67. {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/entry_points.txt +3 -2
  68. rapidtide/data/examples/src/testoutputsize +0 -45
  69. {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info/licenses}/LICENSE +0 -0
  70. {rapidtide-3.0a12.dist-info → rapidtide-3.0a14.dist-info}/top_level.txt +0 -0
rapidtide/refinedelay.py CHANGED
@@ -24,9 +24,9 @@ from statsmodels.robust import mad
24
24
 
25
25
  import rapidtide.filter as tide_filt
26
26
  import rapidtide.io as tide_io
27
- import rapidtide.workflows.glmfrommaps as tide_glmfrommaps
27
+ import rapidtide.workflows.regressfrommaps as tide_regressfrommaps
28
28
 
29
- global ratiotooffsetfunc, maplimits
29
+ global ratiotooffsetfunc, funcoffsets, maplimits
30
30
 
31
31
 
32
32
  def smooth(y, box_pts):
@@ -40,33 +40,39 @@ def trainratiotooffset(
40
40
  timeaxis,
41
41
  outputname,
42
42
  outputlevel,
43
+ trainlagmin=0.0,
44
+ trainlagmax=0.0,
45
+ trainlagstep=0.5,
43
46
  mindelay=-3.0,
44
47
  maxdelay=3.0,
45
48
  numpoints=501,
46
49
  smoothpts=3,
47
50
  edgepad=5,
48
- glmderivs=1,
51
+ regressderivs=1,
52
+ LGR=None,
53
+ TimingLGR=None,
54
+ verbose=False,
49
55
  debug=False,
50
56
  ):
51
- global ratiotooffsetfunc, maplimits
57
+ global ratiotooffsetfunc, funcoffsets, maplimits
52
58
 
53
59
  if debug:
54
60
  print("ratiotooffsetfunc:")
55
61
  lagtcgenerator.info(prefix="\t")
56
62
  print("\ttimeaxis:", timeaxis)
57
63
  print("\toutputname:", outputname)
64
+ print("\ttrainlagmin:", trainlagmin)
65
+ print("\ttrainlagmax:", trainlagmax)
66
+ print("\ttrainlagstep:", trainlagstep)
58
67
  print("\tmindelay:", mindelay)
59
68
  print("\tmaxdelay:", maxdelay)
60
69
  print("\tsmoothpts:", smoothpts)
61
70
  print("\tedgepad:", edgepad)
62
- print("\tglmderivs:", glmderivs)
71
+ print("\tregressderivs:", regressderivs)
63
72
  print("\tlagtcgenerator:", lagtcgenerator)
73
+
64
74
  # make a delay map
65
75
  delaystep = (maxdelay - mindelay) / (numpoints - 1)
66
- if debug:
67
- print(f"{delaystep=}")
68
- print(f"{mindelay=}")
69
- print(f"{maxdelay=}")
70
76
  lagtimes = np.linspace(
71
77
  mindelay - edgepad * delaystep,
72
78
  maxdelay + edgepad * delaystep,
@@ -76,18 +82,16 @@ def trainratiotooffset(
76
82
  if debug:
77
83
  print(f"{mindelay=}")
78
84
  print(f"{maxdelay=}")
85
+ print(f"{delaystep=}")
79
86
  print("lagtimes=", lagtimes)
80
87
 
81
- # now make synthetic fMRI data
88
+ # set up for getratioderivs call
89
+ rt_floattype = "float64"
82
90
  internalvalidfmrishape = (numpoints + 2 * edgepad, timeaxis.shape[0])
83
91
  fmridata = np.zeros(internalvalidfmrishape, dtype=float)
84
92
  fmrimask = np.ones(numpoints + 2 * edgepad, dtype=float)
85
93
  validvoxels = np.where(fmrimask > 0)[0]
86
- for i in range(numpoints + 2 * edgepad):
87
- fmridata[i, :] = lagtcgenerator.yfromx(timeaxis - lagtimes[i])
88
-
89
- rt_floattype = "float64"
90
- glmmean = np.zeros(numpoints + 2 * edgepad, dtype=rt_floattype)
94
+ sLFOfitmean = np.zeros(numpoints + 2 * edgepad, dtype=rt_floattype)
91
95
  rvalue = np.zeros(numpoints + 2 * edgepad, dtype=rt_floattype)
92
96
  r2value = np.zeros(numpoints + 2 * edgepad, dtype=rt_floattype)
93
97
  fitNorm = np.zeros((numpoints + 2 * edgepad, 2), dtype=rt_floattype)
@@ -97,10 +101,10 @@ def trainratiotooffset(
97
101
  filtereddata = np.zeros(internalvalidfmrishape, dtype=rt_floattype)
98
102
  sampletime = timeaxis[1] - timeaxis[0]
99
103
  optiondict = {
100
- "glmthreshval": 0.0,
101
- "saveminimumglmfiles": False,
104
+ "regressfiltthreshval": 0.0,
105
+ "saveminimumsLFOfiltfiles": False,
102
106
  "nprocs_makelaggedtcs": 1,
103
- "nprocs_glm": 1,
107
+ "nprocs_regressionfilt": 1,
104
108
  "mp_chunksize": 1000,
105
109
  "showprogressbar": False,
106
110
  "alwaysmultiproc": False,
@@ -110,96 +114,204 @@ def trainratiotooffset(
110
114
  "textio": False,
111
115
  }
112
116
 
113
- glmderivratios = getderivratios(
114
- fmridata,
115
- validvoxels,
116
- timeaxis,
117
- 0.0 * lagtimes,
118
- fmrimask,
119
- lagtcgenerator,
120
- "glm",
121
- "refinedelaytest",
122
- sampletime,
123
- glmmean,
124
- rvalue,
125
- r2value,
126
- fitNorm[:, :2],
127
- fitcoeff[:, :2],
128
- movingsignal,
129
- lagtc,
130
- filtereddata,
131
- None,
132
- None,
133
- optiondict,
134
- glmderivs=glmderivs,
135
- debug=debug,
136
- )
137
- if debug:
138
- print("before trimming")
139
- print(f"{glmderivratios.shape=}")
140
- print(f"{lagtimes.shape=}")
141
- if glmderivs == 1:
142
- smoothglmderivratios = tide_filt.unpadvec(
143
- smooth(tide_filt.padvec(glmderivratios, padlen=20, padtype="constant"), smoothpts),
144
- padlen=20,
117
+ if trainlagmax - trainlagmin > 0.0:
118
+ numnegoffsets = np.max((-int(np.round(trainlagmin / trainlagstep, 0)), 1))
119
+ numposoffsets = np.max((int(np.round(trainlagmax / trainlagstep, 0)), 1))
120
+ numoffsets = numnegoffsets + 1 + numposoffsets
121
+ trainoffsets = (
122
+ np.linspace(0, (numoffsets - 1) * trainlagstep, numoffsets, endpoint=True)
123
+ - numnegoffsets * trainlagstep
145
124
  )
146
- glmderivratios = glmderivratios[edgepad:-edgepad]
147
- smoothglmderivratios = smoothglmderivratios[edgepad:-edgepad]
148
125
  else:
149
- smoothglmderivratios = np.zeros_like(glmderivratios)
150
- for i in range(glmderivs):
151
- smoothglmderivratios[i, :] = tide_filt.unpadvec(
126
+ trainoffsets = np.array([0.0], dtype=float)
127
+ numoffsets = 1
128
+ if debug:
129
+ print("trainoffsets:", trainoffsets)
130
+ allsmoothregressderivratios = np.zeros(
131
+ (numpoints + 2 * edgepad, numoffsets), dtype=rt_floattype
132
+ )
133
+ theEVs = np.zeros((numoffsets, timeaxis.shape[0]), dtype=float)
134
+
135
+ if verbose and (LGR is not None):
136
+ thisLGR = LGR
137
+ thisTimingLGR = TimingLGR
138
+ else:
139
+ thisLGR = None
140
+ thisTimingLGR = None
141
+
142
+ for whichoffset in range(numoffsets):
143
+ thisoffset = trainoffsets[whichoffset]
144
+
145
+ # now make synthetic fMRI data
146
+ for i in range(numpoints + 2 * edgepad):
147
+ fmridata[i, :] = lagtcgenerator.yfromx(timeaxis - lagtimes[i] + thisoffset)
148
+
149
+ theEVs[whichoffset, :] = lagtcgenerator.yfromx(timeaxis + thisoffset)
150
+
151
+ regressderivratios, regressrvalues = getderivratios(
152
+ fmridata,
153
+ validvoxels,
154
+ timeaxis + thisoffset,
155
+ 0.0 * lagtimes,
156
+ fmrimask,
157
+ lagtcgenerator,
158
+ "glm",
159
+ "refinedelaytest",
160
+ sampletime,
161
+ sLFOfitmean,
162
+ rvalue,
163
+ r2value,
164
+ fitNorm[:, :2],
165
+ fitcoeff[:, :2],
166
+ movingsignal,
167
+ lagtc,
168
+ filtereddata,
169
+ thisLGR,
170
+ thisTimingLGR,
171
+ optiondict,
172
+ regressderivs=regressderivs,
173
+ debug=debug,
174
+ )
175
+ if debug:
176
+ print("before trimming")
177
+ print(f"{regressderivratios.shape=}")
178
+ print(f"{lagtimes.shape=}")
179
+ if regressderivs == 1:
180
+ smoothregressderivratios = tide_filt.unpadvec(
152
181
  smooth(
153
- tide_filt.padvec(glmderivratios[i, :], padlen=20, padtype="constant"),
154
- smoothpts,
182
+ tide_filt.padvec(regressderivratios, padlen=20, padtype="constant"), smoothpts
155
183
  ),
156
184
  padlen=20,
157
185
  )
158
- glmderivratios = glmderivratios[:, edgepad:-edgepad]
159
- smoothglmderivratios = smoothglmderivratios[:, edgepad:-edgepad]
186
+ # regressderivratios = regressderivratios[edgepad:-edgepad]
187
+ allsmoothregressderivratios[:, whichoffset] = smoothregressderivratios + 0.0
188
+ else:
189
+ smoothregressderivratios = np.zeros_like(regressderivratios)
190
+ for i in range(regressderivs):
191
+ allsmoothregressderivratios[i, :] = tide_filt.unpadvec(
192
+ smooth(
193
+ tide_filt.padvec(regressderivratios[i, :], padlen=20, padtype="constant"),
194
+ smoothpts,
195
+ ),
196
+ padlen=20,
197
+ )
198
+ # regressderivratios = regressderivratios[:, edgepad:-edgepad]
199
+ allsmoothregressderivratios = smoothregressderivratios + 0.0
200
+
201
+ allsmoothregressderivratios = allsmoothregressderivratios[edgepad:-edgepad, :]
160
202
  lagtimes = lagtimes[edgepad:-edgepad]
161
203
  if debug:
162
204
  print("after trimming")
163
- print(f"{glmderivratios.shape=}")
164
- print(f"{smoothglmderivratios.shape=}")
205
+ print(f"{regressderivratios.shape=}")
206
+ print(f"{allsmoothregressderivratios.shape=}")
165
207
  print(f"{lagtimes.shape=}")
166
208
 
167
- # make sure the mapping function is legal
168
- xaxis = smoothglmderivratios[::-1]
169
- yaxis = lagtimes[::-1]
170
- midpoint = int(len(xaxis) // 2)
171
- lowerlim = midpoint + 0
172
- while (lowerlim > 1) and xaxis[lowerlim] > xaxis[lowerlim - 1]:
173
- lowerlim -= 1
174
- upperlim = midpoint + 0
175
- while (upperlim < len(xaxis) - 2) and xaxis[upperlim] < xaxis[upperlim + 1]:
176
- upperlim += 1
177
- xaxis = xaxis[lowerlim : upperlim + 1]
178
- yaxis = yaxis[lowerlim : upperlim + 1]
179
- ratiotooffsetfunc = CubicSpline(xaxis, yaxis)
209
+ # find the minimum legal limits of the mapping function
210
+ highestlowerlim = 0
211
+ lowestupperlim = numpoints
212
+ for whichoffset in range(numoffsets):
213
+ xaxis = allsmoothregressderivratios[::-1, whichoffset]
214
+ midpoint = int(len(xaxis) // 2)
215
+ lowerlim = midpoint + 0
216
+ while (lowerlim > 1) and xaxis[lowerlim] > xaxis[lowerlim - 1]:
217
+ lowerlim -= 1
218
+ upperlim = midpoint + 0
219
+ while (upperlim < len(xaxis) - 2) and xaxis[upperlim] < xaxis[upperlim + 1]:
220
+ upperlim += 1
221
+ if lowerlim > highestlowerlim:
222
+ highestlowerlim = lowerlim
223
+ if upperlim < lowestupperlim:
224
+ lowestupperlim = upperlim
225
+
226
+ ratiotooffsetfunc = []
227
+ funcoffsets = []
228
+ for whichoffset in range(numoffsets):
229
+ xaxis = allsmoothregressderivratios[::-1, whichoffset]
230
+ yaxis = lagtimes[::-1]
231
+ xaxis = xaxis[highestlowerlim : lowestupperlim + 1]
232
+ yaxis = yaxis[highestlowerlim : lowestupperlim + 1]
233
+ ratiotooffsetfunc.append(CubicSpline(xaxis, yaxis))
234
+ funcoffsets.append(trainoffsets[whichoffset] + 0.0)
180
235
  maplimits = (xaxis[0], xaxis[-1])
181
236
 
182
237
  if outputlevel != "min":
183
238
  resampaxis = np.linspace(xaxis[0], xaxis[-1], num=len(xaxis), endpoint=True)
239
+ outputfuncs = np.zeros((resampaxis.size, numoffsets), dtype=float)
240
+ colnames = []
241
+ for whichoffset in range(numoffsets):
242
+ colnames.append(f"{funcoffsets[whichoffset]}")
243
+ outputfuncs[:, whichoffset] = ratiotooffsetfunc[whichoffset](resampaxis)
244
+ if debug:
245
+ print(f"{colnames=}")
246
+ print(f"{outputfuncs.shape=}")
184
247
  tide_io.writebidstsv(
185
248
  f"{outputname}_desc-ratiotodelayfunc_timeseries",
186
- ratiotooffsetfunc(resampaxis),
249
+ np.transpose(outputfuncs),
187
250
  1.0 / (resampaxis[1] - resampaxis[0]),
188
251
  starttime=resampaxis[0],
189
- columns=["delay"],
190
- extraheaderinfo={"Description": "The function mapping derivative ratio to delay"},
252
+ columns=colnames,
253
+ extraheaderinfo={
254
+ "Description": "The function mapping derivative ratio to delay",
255
+ "minratio": f"{resampaxis[0]}",
256
+ "maxratio": f"{resampaxis[-1]}",
257
+ },
258
+ xaxislabel="coefficientratio",
259
+ yaxislabel="time",
191
260
  append=False,
192
261
  )
262
+ if numoffsets > 1:
263
+ print(f"{theEVs.shape=}, {numoffsets=}, {(numoffsets>1)=}")
264
+ tide_io.writebidstsv(
265
+ f"{outputname}_desc-trainratioEV_timeseries",
266
+ theEVs,
267
+ 1.0 / (timeaxis[1] - timeaxis[0]),
268
+ starttime=timeaxis[0],
269
+ columns=colnames,
270
+ extraheaderinfo={"Description": f"EVs used for each offset"},
271
+ append=False,
272
+ )
273
+
193
274
 
275
+ def ratiotodelay(theratio, offset=0.0, debug=False):
276
+ global ratiotooffsetfunc, funcoffsets, maplimits
277
+
278
+ # find the closest calculated offset
279
+ closestindex = 0
280
+ for offsetindex in range(1, len(funcoffsets)):
281
+ if np.fabs(funcoffsets[offsetindex] - offset) < np.fabs(
282
+ funcoffsets[closestindex] - offset
283
+ ):
284
+ closestindex = offsetindex
285
+ closestoffset = funcoffsets[closestindex]
286
+ distance = np.fabs(funcoffsets[closestindex] - offset)
287
+ """if (maplimits[0] < theratio < maplimits[1]) and (
288
+ distance < (funcoffsets[1] - funcoffsets[0]) / 2
289
+ ):
290
+ return (
291
+ ratiotooffsetfunc[closestindex](theratio) + (offset - closestoffset),
292
+ closestoffset,
293
+ )
294
+ else:
295
+ return (
296
+ 0.0,
297
+ closestoffset,
298
+ )"""
194
299
 
195
- def ratiotodelay(theratio):
196
- global ratiotooffsetfunc, maplimits
197
300
  if theratio < maplimits[0]:
198
- return ratiotooffsetfunc(maplimits[0])
301
+ return (
302
+ ratiotooffsetfunc[closestindex](maplimits[0]) + (offset - closestoffset),
303
+ closestoffset,
304
+ )
199
305
  elif theratio > maplimits[1]:
200
- return ratiotooffsetfunc(maplimits[1])
306
+ return (
307
+ ratiotooffsetfunc[closestindex](maplimits[1]),
308
+ closestoffset,
309
+ )
201
310
  else:
202
- return ratiotooffsetfunc(theratio)
311
+ return (
312
+ ratiotooffsetfunc[closestindex](theratio),
313
+ closestoffset,
314
+ )
203
315
 
204
316
 
205
317
  def coffstodelay(thecoffs, mindelay=-3.0, maxdelay=3.0, debug=False):
@@ -240,7 +352,7 @@ def getderivratios(
240
352
  mode,
241
353
  outputname,
242
354
  oversamptr,
243
- glmmean,
355
+ sLFOfitmean,
244
356
  rvalue,
245
357
  r2value,
246
358
  fitNorm,
@@ -251,25 +363,34 @@ def getderivratios(
251
363
  LGR,
252
364
  TimingLGR,
253
365
  optiondict,
254
- glmderivs=1,
366
+ regressderivs=1,
367
+ starttr=None,
368
+ endtr=None,
255
369
  debug=False,
256
370
  ):
371
+ if starttr is None:
372
+ starttr = 0
373
+ if endtr is None:
374
+ endtr = fmri_data_valid.shape[1]
257
375
  if debug:
258
376
  print("getderivratios")
259
377
  print(f"{fitNorm.shape=}")
260
378
  print(f"{fitcoeff.shape=}")
261
- print(f"{glmderivs=}")
262
- voxelsprocessed_glm, regressorset, evset = tide_glmfrommaps.glmfrommaps(
263
- fmri_data_valid,
379
+ print(f"{regressderivs=}")
380
+ print(f"{starttr=}")
381
+ print(f"{endtr=}")
382
+
383
+ voxelsprocessed_regressionfilt, regressorset, evset = tide_regressfrommaps.regressfrommaps(
384
+ fmri_data_valid[:, starttr:endtr],
264
385
  validvoxels,
265
- initial_fmri_x,
386
+ initial_fmri_x[starttr:endtr],
266
387
  lagtimes,
267
388
  fitmask,
268
389
  genlagtc,
269
390
  mode,
270
391
  outputname,
271
392
  oversamptr,
272
- glmmean,
393
+ sLFOfitmean,
273
394
  rvalue,
274
395
  r2value,
275
396
  fitNorm,
@@ -279,11 +400,11 @@ def getderivratios(
279
400
  filtereddata,
280
401
  LGR,
281
402
  TimingLGR,
282
- optiondict["glmthreshval"],
283
- optiondict["saveminimumglmfiles"],
403
+ optiondict["regressfiltthreshval"],
404
+ False,
284
405
  nprocs_makelaggedtcs=optiondict["nprocs_makelaggedtcs"],
285
- nprocs_glm=optiondict["nprocs_glm"],
286
- glmderivs=glmderivs,
406
+ nprocs_regressionfilt=optiondict["nprocs_regressionfilt"],
407
+ regressderivs=regressderivs,
287
408
  mp_chunksize=optiondict["mp_chunksize"],
288
409
  showprogressbar=optiondict["showprogressbar"],
289
410
  alwaysmultiproc=optiondict["alwaysmultiproc"],
@@ -292,19 +413,19 @@ def getderivratios(
292
413
  )
293
414
 
294
415
  # calculate the ratio of the first derivative to the main regressor
295
- if glmderivs == 1:
296
- glmderivratios = np.nan_to_num(fitcoeff[:, 1] / fitcoeff[:, 0])
416
+ if regressderivs == 1:
417
+ regressderivratios = np.nan_to_num(fitcoeff[:, 1] / fitcoeff[:, 0])
297
418
  else:
298
419
  numvoxels = fitcoeff.shape[0]
299
- glmderivratios = np.zeros((glmderivs, numvoxels), dtype=np.float64)
300
- for i in range(glmderivs):
301
- glmderivratios[i, :] = np.nan_to_num(fitcoeff[:, i + 1] / fitcoeff[:, 0])
420
+ regressderivratios = np.zeros((regressderivs, numvoxels), dtype=np.float64)
421
+ for i in range(regressderivs):
422
+ regressderivratios[i, :] = np.nan_to_num(fitcoeff[:, i + 1] / fitcoeff[:, 0])
302
423
 
303
- return glmderivratios
424
+ return regressderivratios, rvalue
304
425
 
305
426
 
306
427
  def filterderivratios(
307
- glmderivratios,
428
+ regressderivratios,
308
429
  nativespaceshape,
309
430
  validvoxels,
310
431
  thedims,
@@ -313,6 +434,7 @@ def filterderivratios(
313
434
  fileiscifti=False,
314
435
  textio=False,
315
436
  rt_floattype="float64",
437
+ verbose=True,
316
438
  debug=False,
317
439
  ):
318
440
 
@@ -323,32 +445,35 @@ def filterderivratios(
323
445
  print(f"\t{nativespaceshape=}")
324
446
 
325
447
  # filter the ratio to find weird values
326
- themad = mad(glmderivratios).astype(np.float64)
327
- print(f"MAD of GLM derivative ratios = {themad}")
448
+ themad = mad(regressderivratios).astype(np.float64)
449
+ if verbose:
450
+ print(f"MAD of regression fit derivative ratios = {themad}")
328
451
  outmaparray, internalspaceshape = tide_io.makedestarray(
329
452
  nativespaceshape,
330
453
  textio=textio,
331
454
  fileiscifti=fileiscifti,
332
455
  rt_floattype=rt_floattype,
333
456
  )
334
- mappedglmderivratios = tide_io.populatemap(
335
- glmderivratios,
457
+ mappedregressderivratios = tide_io.populatemap(
458
+ regressderivratios,
336
459
  internalspaceshape,
337
460
  validvoxels,
338
461
  outmaparray,
339
462
  debug=debug,
340
463
  )
341
464
  if textio or fileiscifti:
342
- medfilt = glmderivratios
343
- filteredarray = glmderivratios
465
+ medfilt = regressderivratios
466
+ filteredarray = regressderivratios
344
467
  else:
345
468
  if debug:
346
- print(f"{glmderivratios.shape=}, {mappedglmderivratios.shape=}")
469
+ print(f"{regressderivratios.shape=}, {mappedregressderivratios.shape=}")
347
470
  medfilt = median_filter(
348
- mappedglmderivratios.reshape(nativespaceshape), size=(3, 3, 3)
471
+ mappedregressderivratios.reshape(nativespaceshape), size=(3, 3, 3)
349
472
  ).reshape(internalspaceshape)[validvoxels]
350
473
  filteredarray = np.where(
351
- np.fabs(glmderivratios - medfilt) > patchthresh * themad, medfilt, glmderivratios
474
+ np.fabs(regressderivratios - medfilt) > patchthresh * themad,
475
+ medfilt,
476
+ regressderivratios,
352
477
  )
353
478
  if gausssigma > 0:
354
479
  mappedfilteredarray = tide_io.populatemap(
rapidtide/resample.py CHANGED
@@ -328,6 +328,9 @@ class FastResampler:
328
328
  pl.legend(("input", "hires"))
329
329
  pl.show()
330
330
 
331
+ def getdata(self):
332
+ return self.timeaxis, self.timecourse, self.hires_x, self.hires_y, 1.0 / self.initstep
333
+
331
334
  def info(self, prefix=""):
332
335
  print(f"{prefix}{self.timeaxis=}")
333
336
  print(f"{prefix}{self.timecourse=}")
@@ -17,11 +17,11 @@
17
17
  #
18
18
  #
19
19
  import rapidtide.workflows.parser_funcs as pf
20
- import rapidtide.workflows.retroglm as theworkflow
20
+ import rapidtide.workflows.delayvar as theworkflow
21
21
 
22
22
 
23
23
  def entrypoint():
24
- pf.generic_init(theworkflow._get_parser, theworkflow.retroglm)
24
+ pf.generic_init(theworkflow._get_parser, theworkflow.delayvar)
25
25
 
26
26
 
27
27
  if __name__ == "__main__":
@@ -16,11 +16,11 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  #
19
- import rapidtide.workflows.glmfilt as glmfilt_workflow
19
+ import rapidtide.workflows.linfitfilt as linfitfilt_workflow
20
20
 
21
21
 
22
22
  def entrypoint():
23
- glmfilt_workflow.main()
23
+ linfitfilt_workflow.main()
24
24
 
25
25
 
26
26
  if __name__ == "__main__":
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2016-2024 Blaise Frederick
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ #
19
+ import rapidtide.workflows.parser_funcs as pf
20
+ import rapidtide.workflows.retroregress as theworkflow
21
+
22
+
23
+ def entrypoint():
24
+ pf.generic_init(theworkflow._get_parser, theworkflow.retroregress)
25
+
26
+
27
+ if __name__ == "__main__":
28
+ entrypoint()
@@ -29,7 +29,7 @@ import rapidtide.workflows.parser_funcs as pf
29
29
 
30
30
  def _get_parser():
31
31
  """
32
- Argument parser for glmfilt
32
+ Argument parser for stupidramtricks
33
33
  """
34
34
  parser = argparse.ArgumentParser(
35
35
  prog="stupidramtricks",
@@ -141,7 +141,9 @@ def stupidramtricks(args):
141
141
  fmridata, fmridata_shm = tide_util.numpy2shared(
142
142
  fmridata, rt_floatset, name=f"fmridata_{args.pid}"
143
143
  )
144
- glmmean, glmmean_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
144
+ sLFOfitmean, sLFOfitmean_shm = tide_util.allocshared(
145
+ internalvalidspaceshape, rt_outfloatset
146
+ )
145
147
  rvalue, rvalue_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
146
148
  r2value, r2value_shm = tide_util.allocshared(internalvalidspaceshape, rt_outfloatset)
147
149
  fitNorm, fitNorm_shm = tide_util.allocshared(internalvalidspaceshapederivs, rt_outfloatset)
@@ -160,7 +162,7 @@ def stupidramtricks(args):
160
162
  else:
161
163
  if args.debug:
162
164
  print("allocating memory")
163
- glmmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
165
+ sLFOfitmean = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
164
166
  rvalue = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
165
167
  r2value = np.zeros(internalvalidspaceshape, dtype=rt_outfloattype)
166
168
  fitNorm = np.zeros(internalvalidspaceshapederivs, dtype=rt_outfloattype)
@@ -172,7 +174,7 @@ def stupidramtricks(args):
172
174
 
173
175
  totalbytes = (
174
176
  fmridata.nbytes
175
- + glmmean.nbytes
177
+ + sLFOfitmean.nbytes
176
178
  + rvalue.nbytes
177
179
  + r2value.nbytes
178
180
  + fitNorm.nbytes
@@ -185,7 +187,7 @@ def stupidramtricks(args):
185
187
  thesize, theunit = tide_util.format_bytes(totalbytes)
186
188
  print(f"allocated {thesize:.3f} {theunit} {location}")
187
189
 
188
- """glmderivratios = tide_refinedelay.getderivratios(
190
+ """regressderivratios, regressrvalues = tide_refinedelay.getderivratios(
189
191
  fmri_data_valid,
190
192
  validvoxels,
191
193
  initial_fmri_x,
@@ -195,7 +197,7 @@ def stupidramtricks(args):
195
197
  mode,
196
198
  outputname,
197
199
  oversamptr,
198
- glmmean,
200
+ sLFOfitmean,
199
201
  rvalue,
200
202
  r2value,
201
203
  fitNorm[:, :2],
@@ -212,7 +214,7 @@ def stupidramtricks(args):
212
214
  # clean up shared memory
213
215
  if args.usesharedmem:
214
216
  tide_util.cleanup_shm(fmridata_shm)
215
- tide_util.cleanup_shm(glmmean_shm)
217
+ tide_util.cleanup_shm(sLFOfitmean_shm)
216
218
  tide_util.cleanup_shm(rvalue_shm)
217
219
  tide_util.cleanup_shm(r2value_shm)
218
220
  tide_util.cleanup_shm(fitNorm_shm)
rapidtide/simfuncfit.py CHANGED
@@ -43,7 +43,7 @@ def onesimfuncfit(
43
43
  ):
44
44
  if initiallag is not None:
45
45
  thefitter.setguess(True, maxguess=initiallag)
46
- thefitter.setrange(-despeckle_thresh/2.0, despeckle_thresh/2.0)
46
+ thefitter.setrange(-despeckle_thresh / 2.0, despeckle_thresh / 2.0)
47
47
  else:
48
48
  thefitter.setguess(False)
49
49
 
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright 2016-2021 Blaise Frederick
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ #
18
+
19
+ rm tmp/*
20
+ rm testdata/*
21
+ rm .coveragerc.*