def overlay_spikes(self, spikes, clusters, channels): first_sample = self.ctrl.model.t0 / self.ctrl.model.si last_sample = first_sample + self.ctrl.model.ns ifirst, ilast = np.searchsorted(spikes['samples'], [first_sample, last_sample]) tspi = spikes['samples'][ifirst:ilast].astype( np.float64) * self.ctrl.model.si xspi = channels['rawInd'][clusters['channels'][spikes['clusters'] [ifirst:ilast]]] n_side_by_side = int(self.ctrl.model.ntr / 384) print(n_side_by_side) if n_side_by_side > 1: addx = (np.zeros([1, xspi.size]) + np.array( [self.ctrl.model.ntr * r for r in range(n_side_by_side)])[:, np.newaxis]).flatten() xspi = np.tile(xspi, n_side_by_side) + addx yspi = np.tile(tspi, n_side_by_side) if self.ctrl.model.taxis == 1: self.ctrl.add_scatter(xspi, tspi) else: self.ctrl.add_scatter(tspi, xspi) sc = self.layers['default']['layer'] sc.setSize(8) sc.setSymbol('x') # sc.setPen(pg.mkPen((0, 255, 0, 155), width=1)) rgbs = [ list((rgb * 255).astype(np.uint8)) for rgb in color_cycle(spikes['clusters'][ifirst:ilast]) ] sc.setBrush([pg.mkBrush(rgb) for rgb in rgbs]) sc.setPen([pg.mkPen(rgb) for rgb in rgbs]) return sc # sc.setData(x=xspi, y=tspi, brush=pg.mkBrush((255, 0, 0))) def callback(sc, points, evt): NTR = 12 NS = 128 qxy = self.imageItem_seismic.mapFromScene(evt.scenePos()) # tr, _, _, s, _ = self.ctrl.cursor2timetraceamp(qxy) itr, itime = self.ctrl.cursor2ind(qxy) print(itr, itime) h = self.ctrl.model.header x = self.ctrl.model.data trsel = np.arange(np.max([0, itr - NTR]), np.min([self.ctrl.model.ntr, itr + NTR])) ordre = np.lexsort((h['x'][trsel], h['y'][trsel])) trsel = trsel[ordre] w = x[trsel, int(itime) - NS:int(itime) + NS] wiggle(-w.T * 10000, fs=1 / self.ctrl.model.si, t0=(itime - NS) * self.ctrl.model.si) # hw = {k:h[k][trsel] for k in h} # s.sigMouseClicked.disconnect() sc.sigClicked.connect(callback)
def plot_valve_times(passiveValve_intervals, ax=None): if ax is None: f, ax = plt.subplots(1, 1) # Update the plot vertical_lines( passiveValve_intervals[:, 0], ymin=2, ymax=3, color=color_cycle(3), ax=ax, label="ValveOn_times", ) vertical_lines( passiveValve_intervals[:, 1], ymin=2, ymax=3, color=color_cycle(4), ax=ax, label="ValveOff_times", ) ax.legend()
def plot_gabor_times(passiveGabor_df, ax=None): if ax is None: f, ax = plt.subplots(1, 1) # Update plot vertical_lines( passiveGabor_df["start"].values, ymin=0, ymax=1, color=color_cycle(1), ax=ax, label="GaborOn_times", ) vertical_lines( passiveGabor_df["stop"].values, ymin=0, ymax=1, color=color_cycle(2), ax=ax, label="GaborOff_times", ) ax.legend()
def plot_rfmapping(times_interp_RF, ax=None): if ax is None: f, ax = plt.subplots(1, 1) vertical_lines(times_interp_RF, ymin=0, ymax=1, color=color_cycle(9), ax=ax, label="RFframe_times") ax.legend()
def plot_passive_periods(passivePeriods_df, ax=None): if ax is None: f, ax = plt.subplots(1, 1) # Update plot vertical_lines( np.r_[passivePeriods_df.loc['start'], passivePeriods_df.loc['stop']], ymin=-1, ymax=4, color=color_cycle(0), ax=ax, label="spacers", ) ax.legend()
def plot_audio_times(passiveTone_intervals, passiveNoise_intervals, ax=None): if ax is None: f, ax = plt.subplots(1, 1) # Look at it vertical_lines( passiveTone_intervals[:, 0], ymin=1, ymax=2, color=color_cycle(5), ax=ax, label="toneOn_times", ) vertical_lines( passiveTone_intervals[:, 1], ymin=1, ymax=2, color=color_cycle(6), ax=ax, label="toneOff_times", ) vertical_lines( passiveNoise_intervals[:, 0], ymin=1, ymax=2, color=color_cycle(7), ax=ax, label="noiseOn_times", ) vertical_lines( passiveNoise_intervals[:, 1], ymin=1, ymax=2, color=color_cycle(8), ax=ax, label="noiseOff_times", ) ax.legend()
def plot_stims_times(passiveStims_df, ax=None): if ax is None: f, ax = plt.subplots(1, 1) # Look at it vertical_lines( passiveStims_df["valveOn"].values, ymin=2, ymax=3, color=color_cycle(3), ax=ax, label="ValveOn_times", ) vertical_lines( passiveStims_df["valveOff"].values, ymin=2, ymax=3, color=color_cycle(4), ax=ax, label="ValveOff_times", ) ax.legend() vertical_lines( passiveStims_df["toneOn"].values, ymin=1, ymax=2, color=color_cycle(5), ax=ax, label="toneOn_times", ) vertical_lines( passiveStims_df["toneOff"].values, ymin=1, ymax=2, color=color_cycle(6), ax=ax, label="toneOff_times", ) vertical_lines( passiveStims_df["noiseOn"].values, ymin=1, ymax=2, color=color_cycle(7), ax=ax, label="noiseOn_times", ) vertical_lines( passiveStims_df["noiseOff"].values, ymin=1, ymax=2, color=color_cycle(8), ax=ax, label="noiseOff_times", ) ax.legend()
gb_diff_ts = np.diff(t_gabor[0::2]) pearson_r = np.corrcoef(np.diff(gabor_fixtures), gb_diff_ts)[1, 0] assert pearson_r > 0.95 DEBUG_PLOTS = True if DEBUG_PLOTS: # plots for debug t0 = np.median(t_valve_open - valve_fixtures) from ibllib.plots import squares, vertical_lines, color_cycle import matplotlib.pyplot as plt pl, ax = plt.subplots(2, 1) for i, lab in enumerate(['frame2ttl', 'audio', 'bpod']): sy = ephys_fpga._get_sync_fronts(sync, sync_map[lab], tmin=t_start_passive) squares(sy['times'], sy['polarities'], yrange=[0.1 + i, 0.9 + i], color='k', ax=ax[0]) vertical_lines(np.r_[t_start_passive, t_starts, t_ends], ymin=-1, ymax=4, color=color_cycle(0), ax=ax[0], label='spacers') vertical_lines(gabor_fixtures + t0, ymin=-1, ymax=4, color=color_cycle(1), ax=ax[0], label='fixtures gabor') vertical_lines(t_valve_open, ymin=-1, ymax=4, color=color_cycle(2), ax=ax[0], label='valve') vertical_lines(valve_fixtures + t0, ymin=-1, ymax=4, color=color_cycle(2), ax=ax[0], linestyle='--', label='fixtures valve') ax[0].legend() ax[1].plot([0, 3], [0, 3], linewidth=2.0) # plt.plot(diff_delays, gb_diff_ts, '.') plt.xlabel('saved delays diff [s]') plt.ylabel('measured times diff [s]') # scatter plot plt.scatter(np.diff(gabor_fixtures), gb_diff_ts,
si=1 / sr.fs, h=h, t0=t0, title='destr_', taxis=0) # Example 5: overlay the spikes on the existing easyqc instances from ibllib.plots import color_cycle ss = {} symbols = 'x+o' eqcsort = {} for i, sorter in enumerate(SORTERS): alf_path = SORT_PATH.joinpath(sorter, pid, 'alf') ss[sorter] = {} for k in ['spikes', 'clusters', 'channels']: ss[sorter][k] = alf.io.load_object(alf_path, k) col = (np.array(color_cycle(i)) * 255).astype(np.uint8) eqcsort[sorter] = viewseis(destripe.T, si=1 / sr.fs, h=h, t0=t0, title=sorter, taxis=0) _, _, _ = overlay_spikes(eqcsort[sorter], ss[sorter]['spikes'], ss[sorter]['clusters'], ss[sorter]['channels'], label=sorter, symbol=symbols[i]) _, _, _ = overlay_spikes(eqc_dest_, ss[sorter]['spikes'], ss[sorter]['clusters'],