Skip to content

Commit b5a3500

Browse files
committed
corrected stimulus normalization | corrected data masking
1 parent f1c85fe commit b5a3500

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

code/python/cni_toolbox/pRF.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,24 @@ def import_stimulus(self):
206206

207207
self.stimulus = np.zeros((self.h_stimulus,
208208
self.w_stimulus,
209-
self.n_samples + self.l_hrf))
209+
self.n_samples))
210210

211211
for f in files:
212212
number = int(''.join([str(s) for s in f if s.isdigit()]))
213213
img = cv2.imread(f)
214214
self.stimulus[:, :, number] = img[:, :, 0]
215215

216-
mn = np.min(self.stimulus[:, :, ::self.n_samples])
216+
mn = np.min(self.stimulus)
217217
mx = np.max(self.stimulus)
218218
self.stimulus = (self.stimulus - mn) / (mx - mn)
219219

220-
221220
self.stimulus = np.reshape(self.stimulus,
222221
(self.h_stimulus * self.w_stimulus,
223-
self.n_samples + self.l_hrf))
222+
self.n_samples))
224223

224+
self.stimulus = np.hstack((self.stimulus,
225+
np.zeros((self.h_stimulus * self.w_stimulus, self.l_hrf))))
226+
225227
def create_timecourses(self, max_radius = 10.0, n_xy = 30,
226228
min_slope = 0.1, max_slope = 1.2,
227229
n_slope = 10):
@@ -318,16 +320,17 @@ def mapping(self, data, threshold = 100, mask = []):
318320
self.n_total))
319321

320322
mean_signal = np.mean(data, axis = 0)
321-
data = zscore(data, axis = 0)
323+
322324

323325
if np.size(mask)==0:
324326
mask = mean_signal >= threshold
325327

326328
mask = np.reshape(mask,self.n_total)
327329
voxel_index = np.where(mask)[0]
330+
data = zscore(data[:, mask], axis = 0)
328331
n_voxels = voxel_index.size
329-
330-
mag_d = np.sqrt(np.sum(data[:, mask]**2, axis = 0))
332+
333+
mag_d = np.sqrt(np.sum(data**2, axis = 0))
331334

332335

333336
results = {'corr_fit': np.zeros(self.n_total),
@@ -347,7 +350,7 @@ def mapping(self, data, threshold = 100, mask = []):
347350
for m in range(n_voxels):
348351
v = voxel_index[m]
349352

350-
CS = np.matmul(tc, data[:, v]) / (mag_tc * mag_d[m])
353+
CS = np.matmul(tc, data[:, m]) / (mag_tc * mag_d[m])
351354
idx_remove = (CS == np.Inf)| (CS == np.NaN);
352355
CS[idx_remove] = 0
353356

@@ -380,7 +383,7 @@ def mapping(self, data, threshold = 100, mask = []):
380383
tc = tc[:, 0:self.n_samples]
381384
mag_tc = np.sqrt(np.sum(tc**2, axis = 1))
382385

383-
CS = np.matmul(tc, data[:, v]) / (mag_tc * mag_d[m])
386+
CS = np.matmul(tc, data[:, m]) / (mag_tc * mag_d[m])
384387
idx_remove = (CS == np.Inf) | (CS == np.NaN)
385388
CS[idx_remove] = 0
386389

@@ -414,4 +417,4 @@ def mapping(self, data, threshold = 100, mask = []):
414417

415418
return results
416419

417-
420+

0 commit comments

Comments
 (0)