def plot(idx, params, label): landscape = cl.__dict__[params['landscape']['mode']]( nrow, params['landscape'].get('specs', {})) gids, ts = protocol.get_or_simulate(simulation, params) ii = ts > recstart clusters, sequences = seq.identify_vectors(ts[ii], gids[ii] - 1, nrow, ncol, steps=steps, width=width, td=td, eps=eps) das = [] t, x, y, c, a, s = sequences for cid in np.unique(c): cidx = c == cid da = np.diff(a[cidx]) das.extend(da[~np.isnan(da)]) nclu = [] for i in range(0, 9000, 100): q = (t >= (i + 500)) * (t < (i + 1500)) nclu.append((np.unique(c[q]).size)) nclusters.append(nclu) ax1 = pl.subplot2grid((gridy, gridx), (0, idx)) plot_landscape_map(ax1, landscape) ax1.set_title(label) ax2 = pl.subplot2grid((gridy, gridx), (1, idx)) plot_rate_map(ax2, gids[ii]) plot_speed(s[~np.isnan(s)], label.split('\n')[-1]) plot_direction_changing(das, label.split('\n')[-1]) return ax1, ax2
'size': 4 } }, { 'mode': 'Perlin_uniform', 'specs': { 'size': 4 } }, ] simulation = 'sequence_EI_networks' params = protocol.get_parameters(simulation).as_dict() params.update({'landscape': landscapes[-1]}) gids, ts = protocol.get_or_simulate(simulation, params) nrow = ncol = params['nrowE'] npop = nrow * ncol offset = 1 idx = gids - offset < npop gids, ts = gids[idx], ts[idx] ts_bins = np.arange(500., 2500., 10.) h = np.histogram2d(ts, gids - offset, bins=[ts_bins, range(npop + 1)])[0] hh = h.reshape(-1, nrow, ncol) fig, ax = pl.subplots(1) a = ai.animate_image(ax, hh, vmin=0, vmax=np.max(hh)) date = datetime.datetime.now()
def plot_clustered_activity(axes, simulation, nrow, ncol, ts_bins, eps, td, center, hanning_width): title = ' '.join(simulation.split('_')[1:]) gids, ts = protocol.get_or_simulate(simulation) npop = nrow * ncol idx = ((gids - 1) < (nrow * ncol)) * (ts > wuptime) gids, ts = gids[idx], ts[idx] nclusters, clusters = dbscan.detect_wrap(ts, gids - 1, nrow, ncol, td, eps) clustersize = np.bincount(clusters + 1) ax = axes[0] ax.clear() steps = 10 for i in range(nclusters): if clustersize[i] < 100: continue idx = (clusters == i) ax.plot(ts[idx][::steps] / 1000., gids[idx][::steps], '.', ms=2) ax.text(0.04, 0.95, title, verticalalignment='top', horizontalalignment='left', transform=ax.transAxes, fontsize=8, bbox={ 'facecolor': 'white', 'pad': 3 }) yfmt = mpl.ticker.ScalarFormatter() yfmt.set_powerlimits((0, 2)) ax.yaxis.set_major_formatter(yfmt) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.locator_params(nbins=3) ax.set_ylabel('Neuron') c = np.hanning(hanning_width) cx, cy = center g = np.unique(gids) - 1 n = 10 gx = g[((cx + n) > g // nrow) * (g // nrow > (cx - n)) * ((cy + n) > g % nrow) * (g % nrow > (cy - n))] idx = np.in1d(gids - 1, gx) tsc, gidsc = ts[idx], gids[idx] h = np.histogram2d(tsc, gidsc - 1, bins=[ts_bins, range(nrow * ncol + 1)])[0] gidx = np.sum(h, 0) != 0 h = h[:, gidx] hh = np.array([np.convolve(hi, c, mode='valid') for hi in h.T]).T spike_sort = np.argsort(np.argmax(hh, 0)) hh1 = hh[:, spike_sort] g = np.unique(gids) np.random.shuffle(g) idx = np.in1d(gids, g[:400]) tsc, gidsc = ts[idx], gids[idx] h = np.histogram2d(tsc, gidsc - 1, bins=[ts_bins, range(nrow * ncol + 1)])[0] gidx = np.sum(h, 0) != 0 h = h[:, gidx] hh = np.array([np.convolve(hi, c, mode='valid') for hi in h.T]).T spike_sort = np.argsort(np.argmax(hh, 0)) hh2 = hh[:, spike_sort] ax = axes[1] ax.clear() ax.matshow(hh1.T, aspect='auto', origin='bottom', cmap='binary', extent=[0, ts_bins[-1] / 1000., 0, hh1.shape[1]]) ax.yaxis.set_major_formatter(yfmt) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.xaxis.set_ticks_position('bottom') ax.locator_params(nbins=3) ax = axes[2] ax.clear() ax.matshow(hh2.T, aspect='auto', origin='bottom', cmap='binary', extent=[0, ts_bins[-1] / 1000., 0, hh1.shape[1]]) ax.yaxis.set_major_formatter(yfmt) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.xaxis.set_ticks_position('bottom') ax.locator_params(nbins=3)