diff --git a/test.py b/test.py index d2a452f..c52428e 100644 --- a/test.py +++ b/test.py @@ -22,29 +22,42 @@ from matplotlib import gridspec from plottools.axes import labelaxes_params -def demo(): - """ Run a demonstration of the axes module. - """ - - def afigure(): - fig = plt.figure() - gs = gridspec.GridSpec(2, 3, width_ratios=[5, 1.5, 2.4]) - gs.update(left=0.075, bottom=0.14, right=0.985, top=0.9, wspace=0.6, hspace=0.6) - ax1 = fig.add_subplot(gs[:, 0]) - ax2 = fig.add_subplot(gs[0, 1:]) - ax3 = fig.add_subplot(gs[1, 1]) - ax4 = fig.add_subplot(gs[1, 2]) - for ax in [ax1, ax2, ax3, ax4]: - ax.set_xlabel('xlabel') - ax.set_ylabel('ylabel') - return fig, (ax1, ax2, ax3, ax4) - - labelaxes_params(xoffs='auto', yoffs=-1, labels='A', font=dict(fontweight='bold')) - - fig, axs = afigure() - # axs[0].text(0.5, 0.5, 'fig.label_axes()', transform=axs[0].transAxes, ha='center') - # axs[0].text(0.0, 0.0, 'X', transform=fig.transFigure, ha='left', va='bottom') - fig.label_axes() - plt.show() - -demo() \ No newline at end of file + + + +# sp = self.spikes(index) +# binary = np.zeros(t.shape) +# spike_indices = ((sp - t[0]) / dt).astype(int) +# binary[spike_indices[(spike_indices >= 0) & (spike_indices < len(binary))]] = 1 +# g = gaussian_kernel(kernel_width, dt) +# rate = np.convolve(binary, g, mode='same') + +fit = ModelFit("results/final_2/2012-07-12-ag-invivo-1/start_parameter_4_err_6.11/") +model = fit.get_model() + +base_stim = SinusoidalStepStimulus(fit.get_cell_data().get_eod_frequency(), 0, 0) +time_list = [] +freq_list = [] +con_freq_list = [] +duration = 10 +step = model.get_sampling_interval() +g = gaussian_kernel(0.005, step) +for i in range(20): + print(i) + v1, spikes = model.simulate(base_stim, duration) + + binary = np.zeros(int(np.rint(duration / step))) + for s in spikes: + binary[int(np.rint(s/step))] = 1 + rate = np.convolve(binary, g, mode='same') + con_freq_list.append(rate) + + time, freq = hF.calculate_time_and_frequency_trace(spikes, model.get_sampling_interval()) + time_list.append(time) + freq_list.append(freq) +rates = np.array(con_freq_list) +mean_rate = np.mean(rates, axis=0) +mean_time, mean_freq = hF.calculate_mean_of_frequency_traces(time_list, freq_list, model.get_sampling_interval()) +plt.plot(np.arange(0, 10, step), mean_rate, alpha=0.5) +plt.plot(mean_time, mean_freq, alpha=0.5) +plt.show() \ No newline at end of file