rapidtide 3.0.6__py3-none-any.whl → 3.0.7__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.
- rapidtide/RapidtideDataset.py +17 -0
- rapidtide/_version.py +3 -3
- rapidtide/correlate.py +25 -6
- rapidtide/data/examples/src/testfmri +15 -0
- rapidtide/data/examples/src/testhappy +56 -60
- rapidtide/data/examples/src/testsimdata +45 -28
- rapidtide/happy_supportfuncs.py +599 -107
- rapidtide/resample.py +24 -14
- rapidtide/tests/test_congrid.py +68 -79
- rapidtide/voxelData.py +17 -3
- rapidtide/workflows/cleanregressor.py +3 -2
- rapidtide/workflows/happy.py +59 -2
- rapidtide/workflows/happy_parser.py +36 -0
- rapidtide/workflows/rapidtide.py +16 -5
- rapidtide/workflows/rapidtide_parser.py +7 -0
- rapidtide/workflows/showarbcorr.py +19 -6
- rapidtide/workflows/simdata.py +149 -65
- {rapidtide-3.0.6.dist-info → rapidtide-3.0.7.dist-info}/METADATA +1 -1
- {rapidtide-3.0.6.dist-info → rapidtide-3.0.7.dist-info}/RECORD +23 -23
- {rapidtide-3.0.6.dist-info → rapidtide-3.0.7.dist-info}/WHEEL +1 -1
- {rapidtide-3.0.6.dist-info → rapidtide-3.0.7.dist-info}/entry_points.txt +0 -0
- {rapidtide-3.0.6.dist-info → rapidtide-3.0.7.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.6.dist-info → rapidtide-3.0.7.dist-info}/top_level.txt +0 -0
rapidtide/resample.py
CHANGED
|
@@ -124,7 +124,17 @@ congridyvals["kernel"] = "kaiser"
|
|
|
124
124
|
congridyvals["width"] = 3.0
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
def congrid(
|
|
127
|
+
def congrid(
|
|
128
|
+
xaxis,
|
|
129
|
+
loc,
|
|
130
|
+
val,
|
|
131
|
+
width,
|
|
132
|
+
kernel="kaiser",
|
|
133
|
+
cache=True,
|
|
134
|
+
cyclic=True,
|
|
135
|
+
debug=False,
|
|
136
|
+
onlykeynotices=True,
|
|
137
|
+
):
|
|
128
138
|
"""
|
|
129
139
|
Perform a convolution gridding operation with a Kaiser-Bessel or Gaussian kernel of width 'width'. Grid
|
|
130
140
|
parameters are cached for performance.
|
|
@@ -164,10 +174,10 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
|
|
|
164
174
|
|
|
165
175
|
if (congridyvals["kernel"] != kernel) or (congridyvals["width"] != width):
|
|
166
176
|
if congridyvals["kernel"] != kernel:
|
|
167
|
-
if debug:
|
|
177
|
+
if debug and not onlykeynotices:
|
|
168
178
|
print(congridyvals["kernel"], "!=", kernel)
|
|
169
179
|
if congridyvals["width"] != width:
|
|
170
|
-
if debug:
|
|
180
|
+
if debug and not onlykeynotices:
|
|
171
181
|
print(congridyvals["width"], "!=", width)
|
|
172
182
|
if debug:
|
|
173
183
|
print("(re)initializing congridyvals")
|
|
@@ -191,7 +201,7 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
|
|
|
191
201
|
|
|
192
202
|
# find the closest grid point to the target location, calculate relative offsets from this point
|
|
193
203
|
center = tide_util.valtoindex(xaxis, loc)
|
|
194
|
-
offset = np.fmod(np.round((loc - xaxis[center]) / xstep,
|
|
204
|
+
offset = np.fmod(np.round((loc - xaxis[center]) / xstep, 4), 1.0) # will vary from -0.5 to 0.5
|
|
195
205
|
if cyclic:
|
|
196
206
|
if center == len(xaxis) - 1 and offset > 0.5:
|
|
197
207
|
center = 0
|
|
@@ -224,12 +234,13 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
|
|
|
224
234
|
)
|
|
225
235
|
+ offset
|
|
226
236
|
)
|
|
227
|
-
|
|
228
|
-
|
|
237
|
+
yvals = tide_fit.gauss_eval(xvals, np.array([1.0, 0.0, width]))
|
|
238
|
+
if cache:
|
|
239
|
+
congridyvals[offsetkey] = 1.0 * yvals
|
|
229
240
|
startpt = int(center - widthinpts // 2)
|
|
230
241
|
indices = range(startpt, startpt + widthinpts)
|
|
231
242
|
indices = np.remainder(indices, len(xaxis))
|
|
232
|
-
if debug:
|
|
243
|
+
if debug and not onlykeynotices:
|
|
233
244
|
print("center, offset, indices, yvals", center, offset, indices, yvals)
|
|
234
245
|
return val * yvals, yvals, indices
|
|
235
246
|
else:
|
|
@@ -245,19 +256,18 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
|
|
|
245
256
|
xvals = indices - center + offset
|
|
246
257
|
if kernel == "gauss":
|
|
247
258
|
sigma = optsigma[kernelindex]
|
|
248
|
-
|
|
259
|
+
yvals = tide_fit.gauss_eval(xvals, np.array([1.0, 0.0, sigma]))
|
|
249
260
|
elif kernel == "kaiser":
|
|
250
261
|
beta = optbeta[kernelindex]
|
|
251
|
-
|
|
252
|
-
xvals, np.array([beta, width / 2.0])
|
|
253
|
-
)
|
|
262
|
+
yvals = tide_fit.kaiserbessel_eval(xvals, np.array([beta, width / 2.0]))
|
|
254
263
|
else:
|
|
255
264
|
print("illegal kernel value in congrid - exiting")
|
|
256
265
|
sys.exit()
|
|
257
|
-
|
|
258
|
-
|
|
266
|
+
if cache:
|
|
267
|
+
congridyvals[offsetkey] = 1.0 * yvals
|
|
268
|
+
if debug and not onlykeynotices:
|
|
259
269
|
print("xvals, yvals", xvals, yvals)
|
|
260
|
-
if debug:
|
|
270
|
+
if debug and not onlykeynotices:
|
|
261
271
|
print("center, offset, indices, yvals", center, offset, indices, yvals)
|
|
262
272
|
return val * yvals, yvals, indices
|
|
263
273
|
|
rapidtide/tests/test_congrid.py
CHANGED
|
@@ -21,6 +21,7 @@ import matplotlib.pyplot as plt
|
|
|
21
21
|
import numpy as np
|
|
22
22
|
|
|
23
23
|
from rapidtide.resample import congrid
|
|
24
|
+
from rapidtide.happy_supportfuncs import preloadcongrid
|
|
24
25
|
from rapidtide.tests.utils import mse
|
|
25
26
|
|
|
26
27
|
|
|
@@ -74,86 +75,74 @@ def test_congrid(debug=False, displayplots=False):
|
|
|
74
75
|
weights = np.zeros((gridlen), dtype=float)
|
|
75
76
|
griddeddata = np.zeros((gridlen), dtype=float)
|
|
76
77
|
|
|
77
|
-
for
|
|
78
|
-
for
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
outputlines.append(
|
|
143
|
-
" ".join(
|
|
144
|
-
[
|
|
145
|
-
"mse for",
|
|
146
|
-
str(cycles),
|
|
147
|
-
"cycles:",
|
|
148
|
-
gridkernel,
|
|
149
|
-
str(congridbins),
|
|
150
|
-
":",
|
|
151
|
-
str(themse),
|
|
152
|
-
]
|
|
78
|
+
for prefill in [True, False]:
|
|
79
|
+
for gridkernel in kernellist:
|
|
80
|
+
for congridbins in binslist:
|
|
81
|
+
print("about to grid")
|
|
82
|
+
|
|
83
|
+
# reinitialize grid outputs
|
|
84
|
+
weights *= 0.0
|
|
85
|
+
griddeddata *= 0.0
|
|
86
|
+
|
|
87
|
+
if prefill:
|
|
88
|
+
preloadcongrid(
|
|
89
|
+
gridaxis, congridbins, gridkernel=gridkernel, cyclic=True, debug=False
|
|
90
|
+
)
|
|
91
|
+
for i in range(numsamples):
|
|
92
|
+
thevals, theweights, theindices = congrid(
|
|
93
|
+
gridaxis,
|
|
94
|
+
testvals[i],
|
|
95
|
+
funcvalue2(testvals[i], frequency=cycles),
|
|
96
|
+
congridbins,
|
|
97
|
+
kernel=gridkernel,
|
|
98
|
+
debug=False,
|
|
99
|
+
)
|
|
100
|
+
for i in range(len(theindices)):
|
|
101
|
+
weights[theindices[i]] += theweights[i]
|
|
102
|
+
griddeddata[theindices[i]] += thevals[i]
|
|
103
|
+
|
|
104
|
+
griddeddata = np.where(weights > 0.0, griddeddata / weights, 0.0)
|
|
105
|
+
|
|
106
|
+
target = np.float64(gridaxis * 0.0)
|
|
107
|
+
for i in range(len(gridaxis)):
|
|
108
|
+
target[i] = funcvalue2(gridaxis[i], frequency=cycles)
|
|
109
|
+
|
|
110
|
+
print("gridding done")
|
|
111
|
+
print("debug:", debug)
|
|
112
|
+
|
|
113
|
+
# plot if we are doing that
|
|
114
|
+
if displayplots:
|
|
115
|
+
offset = 0.0
|
|
116
|
+
legend = []
|
|
117
|
+
plt.plot(sourceaxis, timecoursein)
|
|
118
|
+
legend.append("Original")
|
|
119
|
+
# offset += 1.0
|
|
120
|
+
plt.plot(gridaxis, target + offset)
|
|
121
|
+
legend.append("Target")
|
|
122
|
+
# offset += 1.0
|
|
123
|
+
plt.plot(gridaxis, griddeddata + offset)
|
|
124
|
+
legend.append("Gridded")
|
|
125
|
+
plt.plot(gridaxis, weights)
|
|
126
|
+
legend.append("Weights")
|
|
127
|
+
plt.legend(legend)
|
|
128
|
+
plt.show()
|
|
129
|
+
|
|
130
|
+
# do the tests
|
|
131
|
+
msethresh = 6.0e-2
|
|
132
|
+
themse = mse(target, griddeddata)
|
|
133
|
+
if debug:
|
|
134
|
+
if themse >= msethresh:
|
|
135
|
+
extra = "FAIL"
|
|
136
|
+
else:
|
|
137
|
+
extra = ""
|
|
138
|
+
print(
|
|
139
|
+
f"mse for {cycles} cycles: {prefill=}, {gridkernel} {congridbins}: {themse} {extra}"
|
|
140
|
+
)
|
|
141
|
+
outputlines.append(
|
|
142
|
+
f"mse for {cycles} cycles: {prefill=}, {gridkernel} {congridbins}: {themse}"
|
|
153
143
|
)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
assert themse < msethresh
|
|
144
|
+
if not debug:
|
|
145
|
+
assert themse < msethresh
|
|
157
146
|
if debug:
|
|
158
147
|
for theline in outputlines:
|
|
159
148
|
print(theline)
|
rapidtide/voxelData.py
CHANGED
|
@@ -100,6 +100,7 @@ class VoxelData:
|
|
|
100
100
|
ysize = None
|
|
101
101
|
numslices = None
|
|
102
102
|
timepoints = None
|
|
103
|
+
dimensions = None
|
|
103
104
|
realtimepoints = None
|
|
104
105
|
xdim = None
|
|
105
106
|
ydim = None
|
|
@@ -160,6 +161,10 @@ class VoxelData:
|
|
|
160
161
|
self.xsize, self.ysize, self.numslices, self.timepoints = tide_io.parseniftidims(
|
|
161
162
|
self.thedims
|
|
162
163
|
)
|
|
164
|
+
if self.timepoints == 1:
|
|
165
|
+
self.dimensions = 3
|
|
166
|
+
else:
|
|
167
|
+
self.dimensions = 4
|
|
163
168
|
self.numslicelocs = int(self.xsize) * int(self.ysize)
|
|
164
169
|
self.numspatiallocs = int(self.xsize) * int(self.ysize) * int(self.numslices)
|
|
165
170
|
self.cifti_hdr = None
|
|
@@ -283,15 +288,24 @@ class VoxelData:
|
|
|
283
288
|
if not self.resident:
|
|
284
289
|
self.load()
|
|
285
290
|
if self.filetype == "nifti":
|
|
286
|
-
|
|
291
|
+
if self.dimensions == 4 or self.filetype == "cifti" or self.filetype == "text":
|
|
292
|
+
return self.nim_data[:, :, :, self.validstart : self.validend + 1]
|
|
293
|
+
else:
|
|
294
|
+
return self.nim_data[:, :, :]
|
|
287
295
|
else:
|
|
288
296
|
return self.nim_data[:, self.validstart : self.validend + 1]
|
|
289
297
|
|
|
290
298
|
def byvoxel(self):
|
|
291
|
-
|
|
299
|
+
if self.dimensions == 4 or self.filetype == "cifti" or self.filetype == "text":
|
|
300
|
+
return self.byvoltrimmed().reshape(self.numspatiallocs, -1)
|
|
301
|
+
else:
|
|
302
|
+
return self.byvoltrimmed().reshape(self.numspatiallocs)
|
|
292
303
|
|
|
293
304
|
def byslice(self):
|
|
294
|
-
|
|
305
|
+
if self.dimensions == 4 or self.filetype == "cifti" or self.filetype == "text":
|
|
306
|
+
return self.byvoltrimmed().reshape(self.numslicelocs, self.numslices, -1)
|
|
307
|
+
else:
|
|
308
|
+
return self.byvoltrimmed().reshape(self.numslicelocs, self.numslices)
|
|
295
309
|
|
|
296
310
|
def validdata(self):
|
|
297
311
|
if self.validvoxels is None:
|
|
@@ -103,8 +103,9 @@ def cleanregressor(
|
|
|
103
103
|
theCorrelator.setlimits(acmininpts, acmaxinpts)
|
|
104
104
|
# theCorrelator.setlimits(lagmininpts, lagmaxinpts)
|
|
105
105
|
print("check_autocorrelation:", acmininpts, acmaxinpts, lagmininpts, lagmaxinpts)
|
|
106
|
-
thexcorr, accheckcorrscale,
|
|
107
|
-
resampref_y[osvalidsimcalcstart : osvalidsimcalcend + 1]
|
|
106
|
+
thexcorr, accheckcorrscale, theglobalmax = theCorrelator.run(
|
|
107
|
+
resampref_y[osvalidsimcalcstart : osvalidsimcalcend + 1],
|
|
108
|
+
trim=False,
|
|
108
109
|
)
|
|
109
110
|
theFitter.setcorrtimeaxis(accheckcorrscale)
|
|
110
111
|
(
|
rapidtide/workflows/happy.py
CHANGED
|
@@ -24,7 +24,7 @@ import warnings
|
|
|
24
24
|
from pathlib import Path
|
|
25
25
|
|
|
26
26
|
import numpy as np
|
|
27
|
-
from
|
|
27
|
+
from scipy.stats import pearsonr
|
|
28
28
|
|
|
29
29
|
import rapidtide.correlate as tide_corr
|
|
30
30
|
import rapidtide.filter as tide_filt
|
|
@@ -315,8 +315,10 @@ def happy_main(argparsingfunc):
|
|
|
315
315
|
time,
|
|
316
316
|
timings,
|
|
317
317
|
LGR=None,
|
|
318
|
+
mpcode=args.mpdetrend,
|
|
318
319
|
nprocs=args.nprocs,
|
|
319
320
|
showprogressbar=args.showprogressbar,
|
|
321
|
+
debug=args.debug,
|
|
320
322
|
)
|
|
321
323
|
normdata_byslice = normdata.reshape((xsize * ysize, numslices, timepoints))
|
|
322
324
|
|
|
@@ -1243,7 +1245,9 @@ def happy_main(argparsingfunc):
|
|
|
1243
1245
|
demeandata_byslice = demeandata.reshape((xsize * ysize, numslices, timepoints))
|
|
1244
1246
|
means_byslice = means.reshape((xsize * ysize, numslices))
|
|
1245
1247
|
|
|
1246
|
-
timings.append(
|
|
1248
|
+
timings.append(
|
|
1249
|
+
["Phase projection to image prep started" + passstring, time.time(), None, None]
|
|
1250
|
+
)
|
|
1247
1251
|
print("Starting phase projection")
|
|
1248
1252
|
proctrs = range(timepoints) # proctrs is the list of all fmri trs to be projected
|
|
1249
1253
|
procpoints = range(
|
|
@@ -1257,6 +1261,14 @@ def happy_main(argparsingfunc):
|
|
|
1257
1261
|
proctrs = np.where(censortrs < 1)[0]
|
|
1258
1262
|
procpoints = np.where(censorpoints < 1)[0]
|
|
1259
1263
|
|
|
1264
|
+
# preload congrid
|
|
1265
|
+
if args.preloadcongrid:
|
|
1266
|
+
print("Preloading congrid values...")
|
|
1267
|
+
happy_support.preloadcongrid(
|
|
1268
|
+
outphases, args.congridbins, gridkernel=args.gridkernel, cyclic=True, debug=False
|
|
1269
|
+
)
|
|
1270
|
+
print("done")
|
|
1271
|
+
|
|
1260
1272
|
# do phase averaging
|
|
1261
1273
|
app_bypoint, weights_bypoint = happy_support.cardiaccycleaverage(
|
|
1262
1274
|
instantaneous_cardiacphase,
|
|
@@ -1266,6 +1278,7 @@ def happy_main(argparsingfunc):
|
|
|
1266
1278
|
args.congridbins,
|
|
1267
1279
|
args.gridkernel,
|
|
1268
1280
|
args.centric,
|
|
1281
|
+
cache=args.congridcache,
|
|
1269
1282
|
cyclic=True,
|
|
1270
1283
|
)
|
|
1271
1284
|
if thispass == numpasses - 1:
|
|
@@ -1358,9 +1371,53 @@ def happy_main(argparsingfunc):
|
|
|
1358
1371
|
debug=args.debug,
|
|
1359
1372
|
)
|
|
1360
1373
|
|
|
1374
|
+
timings.append(
|
|
1375
|
+
["Phase projection to image prep ended" + passstring, time.time(), None, None]
|
|
1376
|
+
)
|
|
1361
1377
|
if not args.verbose:
|
|
1362
1378
|
print("Setting up for phase projection...")
|
|
1363
1379
|
|
|
1380
|
+
# make a vessel map using Wright's method
|
|
1381
|
+
if args.wrightiterations > 0:
|
|
1382
|
+
timings.append(
|
|
1383
|
+
[
|
|
1384
|
+
"Wright mask generation started" + passstring,
|
|
1385
|
+
time.time(),
|
|
1386
|
+
None,
|
|
1387
|
+
None,
|
|
1388
|
+
]
|
|
1389
|
+
)
|
|
1390
|
+
wrightcorrs = happy_support.wrightmap(
|
|
1391
|
+
input_data,
|
|
1392
|
+
demeandata_byslice,
|
|
1393
|
+
rawapp_byslice,
|
|
1394
|
+
projmask_byslice,
|
|
1395
|
+
outphases,
|
|
1396
|
+
cardphasevals,
|
|
1397
|
+
proctrs,
|
|
1398
|
+
args.congridbins,
|
|
1399
|
+
args.gridkernel,
|
|
1400
|
+
args.destpoints,
|
|
1401
|
+
iterations=args.wrightiterations,
|
|
1402
|
+
nprocs=args.nprocs,
|
|
1403
|
+
verbose=False,
|
|
1404
|
+
debug=args.debug,
|
|
1405
|
+
)
|
|
1406
|
+
|
|
1407
|
+
theheader = input_data.copyheader(numtimepoints=1)
|
|
1408
|
+
wrightfilename = f"{outputroot}_desc-wrightcorrspass{thispass + 1}_map"
|
|
1409
|
+
tide_io.writedicttojson(bidsbasedict, wrightfilename + ".json")
|
|
1410
|
+
tide_io.savetonifti(wrightcorrs, theheader, wrightfilename)
|
|
1411
|
+
timings.append(
|
|
1412
|
+
[
|
|
1413
|
+
"Wright mask generation completed" + passstring,
|
|
1414
|
+
time.time(),
|
|
1415
|
+
None,
|
|
1416
|
+
None,
|
|
1417
|
+
]
|
|
1418
|
+
)
|
|
1419
|
+
|
|
1420
|
+
timings.append(["Phase projection to image started" + passstring, time.time(), None, None])
|
|
1364
1421
|
# make a lowpass filter for the projected data. Limit frequency to 3 cycles per 2pi (1/6th Fs)
|
|
1365
1422
|
phaseFs = 1.0 / phasestep
|
|
1366
1423
|
phaseFc = phaseFs / 6.0
|
|
@@ -593,6 +593,14 @@ def _get_parser():
|
|
|
593
593
|
help="Will disable showing progress bars (helpful if stdout is going to a file). ",
|
|
594
594
|
default=True,
|
|
595
595
|
)
|
|
596
|
+
misc_opts.add_argument(
|
|
597
|
+
"--wrightiterations",
|
|
598
|
+
dest="wrightiterations",
|
|
599
|
+
action="store",
|
|
600
|
+
type=lambda x: pf.is_int(parser, x),
|
|
601
|
+
help="Number of iterations for calculating Wright map. Set to 0 to disable.",
|
|
602
|
+
default=0,
|
|
603
|
+
)
|
|
596
604
|
pf.addtagopts(
|
|
597
605
|
misc_opts,
|
|
598
606
|
helptext="Additional key, value pairs to add to the info json file (useful for tracking analyses).",
|
|
@@ -692,6 +700,34 @@ def _get_parser():
|
|
|
692
700
|
help="Decrease the number of intermediate output files. ",
|
|
693
701
|
default=0,
|
|
694
702
|
)
|
|
703
|
+
debug_opts.add_argument(
|
|
704
|
+
"--nompdetrend",
|
|
705
|
+
dest="mpdetrend",
|
|
706
|
+
action="store_false",
|
|
707
|
+
help="Disable multiproc detrending.",
|
|
708
|
+
default=True,
|
|
709
|
+
)
|
|
710
|
+
debug_opts.add_argument(
|
|
711
|
+
"--nompphaseproject",
|
|
712
|
+
dest="mpphaseproject",
|
|
713
|
+
action="store_false",
|
|
714
|
+
help="Disable multiproc phase projection.",
|
|
715
|
+
default=True,
|
|
716
|
+
)
|
|
717
|
+
debug_opts.add_argument(
|
|
718
|
+
"--noprefillcongrid",
|
|
719
|
+
dest="preloadcongrid",
|
|
720
|
+
action="store_false",
|
|
721
|
+
help="Don't prefill the congrid value cache.",
|
|
722
|
+
default=True,
|
|
723
|
+
)
|
|
724
|
+
debug_opts.add_argument(
|
|
725
|
+
"--nocongridcache",
|
|
726
|
+
dest="congridcache",
|
|
727
|
+
action="store_false",
|
|
728
|
+
help="Disable the congrid value cache completely.",
|
|
729
|
+
default=True,
|
|
730
|
+
)
|
|
695
731
|
|
|
696
732
|
return parser
|
|
697
733
|
|
rapidtide/workflows/rapidtide.py
CHANGED
|
@@ -28,7 +28,6 @@ import numpy as np
|
|
|
28
28
|
from scipy import ndimage
|
|
29
29
|
from scipy.stats import rankdata
|
|
30
30
|
|
|
31
|
-
|
|
32
31
|
import rapidtide.calccoherence as tide_calccoherence
|
|
33
32
|
import rapidtide.calcnullsimfunc as tide_nullsimfunc
|
|
34
33
|
import rapidtide.calcsimfunc as tide_calcsimfunc
|
|
@@ -392,6 +391,11 @@ def rapidtide_main(argparsingfunc):
|
|
|
392
391
|
csfmask = anatomicmasks[3]
|
|
393
392
|
|
|
394
393
|
# do spatial filtering if requested
|
|
394
|
+
if theinputdata.filetype == "nifti":
|
|
395
|
+
unfiltmeanvalue = np.mean(
|
|
396
|
+
theinputdata.byvoxel(),
|
|
397
|
+
axis=1,
|
|
398
|
+
)
|
|
395
399
|
optiondict["gausssigma"] = theinputdata.smooth(
|
|
396
400
|
optiondict["gausssigma"],
|
|
397
401
|
brainmask=brainmask,
|
|
@@ -2652,6 +2656,9 @@ def rapidtide_main(argparsingfunc):
|
|
|
2652
2656
|
optiondict["currentstage"] = "presLFOfit"
|
|
2653
2657
|
tide_io.writedicttojson(optiondict, f"{outputname}_desc-runoptions_info.json")
|
|
2654
2658
|
if optiondict["dolinfitfilt"] or optiondict["docvrmap"] or optiondict["refinedelay"]:
|
|
2659
|
+
sLFOfiltmask = fitmask + 0.0
|
|
2660
|
+
if optiondict["nosLFOfiltmask"]:
|
|
2661
|
+
sLFOfiltmask = sLFOfiltmask * 0.0 + 1.0
|
|
2655
2662
|
if optiondict["dolinfitfilt"]:
|
|
2656
2663
|
if optiondict["refinedelay"]:
|
|
2657
2664
|
TimingLGR.info("Setting up for delay refinement and sLFO filtering")
|
|
@@ -2831,7 +2838,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
2831
2838
|
validvoxels,
|
|
2832
2839
|
initial_fmri_x,
|
|
2833
2840
|
lagtimes,
|
|
2834
|
-
|
|
2841
|
+
sLFOfiltmask,
|
|
2835
2842
|
genlagtc,
|
|
2836
2843
|
mode,
|
|
2837
2844
|
outputname,
|
|
@@ -2927,7 +2934,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
2927
2934
|
namesuffix = "_desc-delayoffset_hist"
|
|
2928
2935
|
if optiondict["dolinfitfilt"]:
|
|
2929
2936
|
tide_stats.makeandsavehistogram(
|
|
2930
|
-
delayoffset[np.where(
|
|
2937
|
+
delayoffset[np.where(sLFOfiltmask > 0)],
|
|
2931
2938
|
optiondict["histlen"],
|
|
2932
2939
|
1,
|
|
2933
2940
|
outputname + namesuffix,
|
|
@@ -2965,7 +2972,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
2965
2972
|
validvoxels,
|
|
2966
2973
|
initial_fmri_x,
|
|
2967
2974
|
lagstouse,
|
|
2968
|
-
|
|
2975
|
+
sLFOfiltmask,
|
|
2969
2976
|
genlagtc,
|
|
2970
2977
|
mode,
|
|
2971
2978
|
outputname,
|
|
@@ -3471,7 +3478,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
3471
3478
|
validvoxels,
|
|
3472
3479
|
initial_fmri_x,
|
|
3473
3480
|
lagstouse,
|
|
3474
|
-
|
|
3481
|
+
sLFOfiltmask,
|
|
3475
3482
|
genlagtc,
|
|
3476
3483
|
mode,
|
|
3477
3484
|
outputname,
|
|
@@ -3539,7 +3546,10 @@ def rapidtide_main(argparsingfunc):
|
|
|
3539
3546
|
tide_util.cleanup_shm(fitNorm_shm)
|
|
3540
3547
|
|
|
3541
3548
|
# write the 3D maps that don't need to be remapped
|
|
3549
|
+
if theinputdata.filetype != "nifti":
|
|
3550
|
+
unfiltmeanvalue = meanvalue
|
|
3542
3551
|
maplist = [
|
|
3552
|
+
(unfiltmeanvalue, "unfiltmean", "map", None, "Voxelwise mean of fmri data before smoothing"),
|
|
3543
3553
|
(meanvalue, "mean", "map", None, "Voxelwise mean of fmri data"),
|
|
3544
3554
|
(stddevvalue, "std", "map", None, "Voxelwise standard deviation of fmri data"),
|
|
3545
3555
|
(covvalue, "CoV", "map", None, "Voxelwise coefficient of variation of fmri data"),
|
|
@@ -3564,6 +3574,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
3564
3574
|
cifti_hdr=theinputdata.cifti_hdr,
|
|
3565
3575
|
)
|
|
3566
3576
|
del meanvalue
|
|
3577
|
+
del unfiltmeanvalue
|
|
3567
3578
|
|
|
3568
3579
|
if optiondict["numestreps"] > 0:
|
|
3569
3580
|
masklist = []
|
|
@@ -1462,6 +1462,13 @@ def _get_parser():
|
|
|
1462
1462
|
help=("Do regressor refinement on the final pass."),
|
|
1463
1463
|
default=False,
|
|
1464
1464
|
)
|
|
1465
|
+
experimental.add_argument(
|
|
1466
|
+
"--nosLFOfiltmask",
|
|
1467
|
+
dest="nosLFOfiltmask",
|
|
1468
|
+
action="store_true",
|
|
1469
|
+
help=("Don't spatially limit sLFO filter to fit voxels."),
|
|
1470
|
+
default=False,
|
|
1471
|
+
)
|
|
1465
1472
|
experimental.add_argument(
|
|
1466
1473
|
"--territorymap",
|
|
1467
1474
|
dest="territorymap",
|
|
@@ -297,6 +297,8 @@ def showarbcorr(args):
|
|
|
297
297
|
sys.exit()
|
|
298
298
|
if starttime1 == None:
|
|
299
299
|
starttime1 = 0.0
|
|
300
|
+
endtime1 = starttime1 + len(inputdata1) / Fs1
|
|
301
|
+
print(f"inputdata1 goes from {starttime1} to {endtime1}")
|
|
300
302
|
|
|
301
303
|
if args.samplerate2 is not None:
|
|
302
304
|
Fs2 = args.samplerate2
|
|
@@ -305,9 +307,19 @@ def showarbcorr(args):
|
|
|
305
307
|
sys.exit()
|
|
306
308
|
if starttime2 == None:
|
|
307
309
|
starttime2 = 0.0
|
|
310
|
+
endtime2 = starttime2 + len(inputdata2) / Fs2
|
|
311
|
+
print(f"inputdata2 goes from {starttime2} to {endtime2}")
|
|
308
312
|
|
|
309
|
-
|
|
310
|
-
|
|
313
|
+
matchedinput1, matchedinput2, commonFs = tide_corr.matchsamplerates(
|
|
314
|
+
inputdata1,
|
|
315
|
+
Fs1,
|
|
316
|
+
inputdata2,
|
|
317
|
+
Fs2,
|
|
318
|
+
method="univariate",
|
|
319
|
+
debug=args.debug,
|
|
320
|
+
)
|
|
321
|
+
trimdata1 = matchedinput1
|
|
322
|
+
trimdata2 = matchedinput2
|
|
311
323
|
|
|
312
324
|
if args.trimdata:
|
|
313
325
|
minlen = np.min([len(trimdata1), len(trimdata2)])
|
|
@@ -324,12 +336,12 @@ def showarbcorr(args):
|
|
|
324
336
|
if args.verbose:
|
|
325
337
|
print("filtering to ", theprefilter.gettype(), " band")
|
|
326
338
|
filtereddata1 = tide_math.corrnormalize(
|
|
327
|
-
theprefilter.apply(
|
|
339
|
+
theprefilter.apply(commonFs, trimdata1),
|
|
328
340
|
detrendorder=args.detrendorder,
|
|
329
341
|
windowfunc=args.windowfunc,
|
|
330
342
|
)
|
|
331
343
|
filtereddata2 = tide_math.corrnormalize(
|
|
332
|
-
theprefilter.apply(
|
|
344
|
+
theprefilter.apply(commonFs, trimdata2),
|
|
333
345
|
detrendorder=args.detrendorder,
|
|
334
346
|
windowfunc=args.windowfunc,
|
|
335
347
|
)
|
|
@@ -341,9 +353,9 @@ def showarbcorr(args):
|
|
|
341
353
|
print(f"{Fs1=}, {Fs2=}, {starttime1=}, {starttime2=}, {args.windowfunc=}")
|
|
342
354
|
xcorr_x, thexcorr, corrFs, zeroloc = tide_corr.arbcorr(
|
|
343
355
|
filtereddata1,
|
|
344
|
-
|
|
356
|
+
commonFs,
|
|
345
357
|
filtereddata2,
|
|
346
|
-
|
|
358
|
+
commonFs,
|
|
347
359
|
start1=starttime1,
|
|
348
360
|
start2=starttime2,
|
|
349
361
|
windowfunc=args.windowfunc,
|
|
@@ -375,6 +387,7 @@ def showarbcorr(args):
|
|
|
375
387
|
thexcorr_trim = thexcorr[lowerlim:upperlim]
|
|
376
388
|
print("trimmed Correlator lengths (x, y):", len(xcorr_x_trim), len(thexcorr_trim))
|
|
377
389
|
|
|
390
|
+
print(f"{len(filtereddata1)=}, {len(filtereddata2)=}")
|
|
378
391
|
thepxcorr = pearsonr(filtereddata1, filtereddata2)
|
|
379
392
|
|
|
380
393
|
# initialize the correlation fitter
|