@@ -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 ]))
0 commit comments