Skip to content

Commit a0a4296

Browse files
authored
Merge pull request #365 from int-brain-lab/bb_passive_fix
fix brainbox passive code for case when no spikes during passive period
2 parents b3a86bf + 755f444 commit a0a4296

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

brainbox/task/passive.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ def get_rf_map_over_depth(rf_map_times, rf_map_pos, rf_stim_frames, spike_times,
115115
stim_on_times = rf_map_times[stim_frame[0]]
116116
stim_intervals = np.c_[stim_on_times - pre_stim, stim_on_times + post_stim]
117117

118-
idx_intervals = np.searchsorted(times, stim_intervals)
119-
120-
stim_trials = np.zeros((depths.shape[0], n_bins, idx_intervals.shape[0]))
121-
for i, on in enumerate(idx_intervals):
122-
stim_trials[:, :, i] = binned_array[:, on[0]:on[1]]
123-
avg_stim_trials = np.mean(stim_trials, axis=2)
118+
out_intervals = stim_intervals[:, 1] > times[-1]
119+
idx_intervals = np.searchsorted(times, stim_intervals)[np.invert(out_intervals)]
120+
121+
# Case when no spikes during the passive period
122+
if idx_intervals.shape[0] == 0:
123+
avg_stim_trials = np.zeros((depths.shape[0], n_bins))
124+
else:
125+
stim_trials = np.zeros((depths.shape[0], n_bins, idx_intervals.shape[0]))
126+
for i, on in enumerate(idx_intervals):
127+
stim_trials[:, :, i] = binned_array[:, on[0]:on[1]]
128+
avg_stim_trials = np.mean(stim_trials, axis=2)
124129

125130
_rf_map[:, x_pos, y_pos, :] = avg_stim_trials
126131

@@ -197,8 +202,10 @@ def get_stim_aligned_activity(stim_events, spike_times, spike_depths, z_score_fl
197202

198203
stim_intervals = np.c_[stim_times - pre_stim, stim_times + post_stim]
199204
base_intervals = np.c_[stim_times - base_stim, stim_times - pre_stim]
200-
idx_stim = np.searchsorted(times, stim_intervals)
201-
idx_base = np.searchsorted(times, base_intervals)
205+
out_intervals = stim_intervals[:, 1] > times[-1]
206+
207+
idx_stim = np.searchsorted(times, stim_intervals)[np.invert(out_intervals)]
208+
idx_base = np.searchsorted(times, base_intervals)[np.invert(out_intervals)]
202209

203210
stim_trials = np.zeros((depths.shape[0], n_bins, idx_stim.shape[0]))
204211
noise_trials = np.zeros((depths.shape[0], n_bins_base, idx_stim.shape[0]))

ibllib/pipes/ephys_alignment.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def __init__(self, xyz_picks, chn_depths=None, track_prev=None,
3535
self.xyz_samples = histology.interpolate_along_track(self.xyz_track,
3636
self.sampling_trk -
3737
self.sampling_trk[0])
38+
# ensure none of the track is outside the y or x lim of atlas
39+
xlim = np.bitwise_and(self.xyz_samples[:, 0] > self.brain_atlas.bc.xlim[0],
40+
self.xyz_samples[:, 0] < self.brain_atlas.bc.xlim[1])
41+
ylim = np.bitwise_and(self.xyz_samples[:, 1] < self.brain_atlas.bc.ylim[0],
42+
self.xyz_samples[:, 1] > self.brain_atlas.bc.ylim[1])
43+
rem = np.bitwise_and(xlim, ylim)
44+
self.xyz_samples = self.xyz_samples[rem]
3845

3946
self.region, self.region_label, self.region_colour, self.region_id\
4047
= self.get_histology_regions(self.xyz_samples, self.sampling_trk, self.brain_atlas)

0 commit comments

Comments
 (0)