def results(output_dir="results", analysed_results_dir="obj"): output_dir = os.path.join(output_dir, analysed_results_dir) if os.path.isdir(output_dir): shutil.rmtree(output_dir) os.makedirs(output_dir) os.makedirs(os.path.join(output_dir, "figures")) sizes = load_obj("sizes", analysed_results_dir) nrParticlesInHalos = load_obj("nrParticlesInHalos", analysed_results_dir) nrHalos = load_obj("nrHalosnrHalos", analysed_results_dir) percentageInHalos = load_obj("percentageInHalos", analysed_results_dir) nrParticles = load_obj("nrParticles", analysed_results_dir) for key in sizes: f = open(os.path.join(output_dir, key + ".txt"), "w") f.write(" Mean stderror\n") f.write("nrParticles: {} {}\n".format( np.mean(nrParticles[key]), scipy.stats.sem(nrParticles[key]))) f.write("nrHalos: {} {}\n".format( np.mean(nrHalos[key]), scipy.stats.sem(nrHalos[key]))) f.write("nrParticlesInHalos: {} {}\n".format( np.mean(nrParticlesInHalos[key]), scipy.stats.sem(nrParticlesInHalos[key]))) f.write("percentageInHalos: {} {}\n".format( np.mean(percentageInHalos[key]), scipy.stats.sem(percentageInHalos[key]))) f.close() # Plotting all data for key in sizes: c = 0 i = 0 t_max = 0 t_min = 10000 data_max = 0 data_min = 10000 legend = [] nr_hues = len(sizes[key]) for data in sizes[key]: t = range(1, len(data) + 1) prettyPlot(data, t, "Cumulative cluster size", "Cluster size", "Nr of clusters", color=c, nr_hues=nr_hues, new_figure=False) if max(data) > data_max: data_max = max(data) if min(data) < data_min: data_min = min(data) if max(t) > t_max: t_max = max(t) if min(t) < t_min: t_min = min(t) legend.append("Datasett {}".format(i)) i += 1 c += 1 plt.yscale('log') plt.xscale('log') plt.ylim([t_min, t_max]) plt.xlim([data_min, data_max]) plt.legend(legend) plt.savefig(os.path.join(output_dir, "figures", key + ".png")) # plt.clf() plt.close() #Calculate and plot mean values for key in sizes: size, mean, bins, width = calculateMean(sizes[key]) cumsumAll = np.cumsum(mean[:, ::-1], 1)[:, ::-1] cumsum = np.mean(cumsumAll, 0) sumstd = scipy.stats.sem(cumsumAll, 0) # prettyPlot(size, std, "Cumulative cluster size, mean", "nr cells, mean", "nr of cluster with number of cells > nrParticles", color=2) # prettyPlot(size, cumsum, "Cumulative cluster size, mean", "nr cells, mean", "nr of cluster with number of cells > nrParticles", color=0, new_figure=False) # plt.legend(["Mean", "Standard deviation"]) max_sizes = [] for size in sizes[key]: max_sizes.append(max(size)) max_size = max(max_sizes) bins = (bins / max_size) * 100 width = (width / max_size) * 100 ax = prettyBar(cumsum, index=bins[:-1], color=0, nr_hues=2, error=sumstd, width=width, linewidth=2) ax.set_xticks(bins - width / 2) ax.set_xticklabels(np.round(bins, 0).astype(int), fontsize=14, rotation=0) plt.yscale('log') plt.ylabel("Nr of clusters") plt.xlabel("Cluster size [\% of max cluster size {}]".format(max_size), fontsize=16) plt.title("Cumulative cluster size, mean") plt.savefig(os.path.join(output_dir, "figures", key + "mean.png")) plt.close() # Calculate fractionalDifference between H and V pattern = re.compile(r"(.*)(H)$") for keyH in sizes: result = pattern.search(keyH) if result is not None: keyV = re.sub(pattern, r"\1V", keyH) if keyV in sizes: data_max = 0 data_min = 100000 for data in sizes[keyH]: if max(data) > data_max: data_max = max(data) if min(data) < data_min: data_min = min(data) for data in sizes[keyV]: if max(data) > data_max: data_max = max(data) if min(data) < data_min: data_min = min(data) bins = np.linspace(data_min, data_max, nr_bins) # plot cumulative cluster size H and V from same animal in the same plot t_max = 0 t_min = 10000 nr_hues = 2 prettyPlot([data_min - 1], [t_min - 1], "Cumulative cluster size", "Cluster size", "Nr of clusters", color=0, nr_hues=nr_hues, new_figure=False) prettyPlot([data_min - 1], [t_min - 1], "Cumulative cluster size", "Cluster size", "Nr of clusters", color=1, nr_hues=nr_hues, new_figure=False) plt.legend(["V", "H"]) for data in sizes[keyV]: t = range(1, len(data) + 1) prettyPlot(data, t, "Cumulative cluster size", "Cluster size", "Nr of clusters", color=0, nr_hues=nr_hues, new_figure=False) if max(t) > t_max: t_max = max(t) if min(t) < t_min: t_min = min(t) i += 1 for data in sizes[keyH]: t = range(1, len(data) + 1) prettyPlot(data, t, "Cumulative cluster size", "Cluster size", "Nr of clusters", color=1, nr_hues=nr_hues, new_figure=False) if max(t) > t_max: t_max = max(t) if min(t) < t_min: t_min = min(t) i += 1 plt.yscale('log') plt.xscale('log') plt.ylim([t_min, t_max]) plt.xlim([data_min, data_max]) plt.savefig( os.path.join(output_dir, "figures", keyH[:-1] + "combined.png")) plt.close() meanH = [] for data in sizes[keyH]: meanH.append(np.histogram(data, bins=bins)[0]) meanH = np.array(meanH) meanV = [] for data in sizes[keyV]: meanV.append(np.histogram(data, bins=bins)[0]) meanV = np.array(meanV) width = bins[1] - bins[0] cumsumAllH = np.cumsum(meanH[:, ::-1], 1)[:, ::-1] cumsumAllV = np.cumsum(meanV[:, ::-1], 1)[:, ::-1] cumsumH = np.mean(cumsumAllH, 0) cumsumV = np.mean(cumsumAllV, 0) sumstdV = np.std(cumsumAllV, 0) sumstdH = np.std(cumsumAllH, 0) diff = 1 - cumsumH / cumsumV.astype(float) stddiff = diff * np.sqrt(sumstdV**2 / cumsumV**2 + sumstdH**2 / cumsumH**2) #plot two mean values against each other bins = (bins / data_max) * 100 width = bins[1] - bins[0] ax = prettyBar(cumsumV, index=bins[:-1], color=0, nr_hues=2, error=sumstdV, width=width, linewidth=2) ax = prettyBar(cumsumH, index=bins[:-1], color=4, nr_hues=6, error=sumstdH, width=width, linewidth=2, new_figure=False, alpha=0.6, error_kw=dict(ecolor=get_colormap()[4], lw=2, capsize=10, capthick=2)) ax.set_xticks(bins - width / 2) ax.set_xticklabels(np.round(bins, 0).astype(int), fontsize=14, rotation=0) plt.yscale('log') plt.legend(["V", "H"]) plt.ylabel("Nr of clusters") plt.xlabel("Cluster size [\% of max cluster size {}]".format( data_max), fontsize=16) plt.title("Cumulative cluster size, mean") plt.savefig( os.path.join(output_dir, "figures", keyH[:-1] + "compare.png")) plt.close() # Plot fractional difference width = bins[1] - bins[0] ax = prettyBar(diff, index=bins[:-1], color=0, nr_hues=2, error=stddiff, width=width, linewidth=2) ax.set_xticks(bins - width / 2) ax.set_xticklabels(np.round(bins, 0).astype(int), fontsize=14, rotation=0) plt.ylabel("Fractional difference nr of cluster") plt.xlabel("Cluster size [\% of max cluster size {}]".format( data_max), fontsize=16) plt.title("Fractional difference, (V-H)/V") # prettyPlot(size, diff, "Fractional difference, (V-H)/V", "CLuster size", "Fractional difference nr of cluster", color=0) plt.savefig( os.path.join(output_dir, "figures", keyH[:-1] + "difference.png")) plt.close()
width = 0.2 distance = 0.5 xlabels = ["Mean", "Variance", "$P_5$", "$P_{95}$"] xticks = [0, width, distance + width, distance + 2 * width] values = [ data["nr_spikes"].mean, data["nr_spikes"].variance, data["nr_spikes"].percentile_5, data["nr_spikes"].percentile_95 ] ylabel = data.get_labels("nr_spikes")[0] ax = prettyBar(values, index=xticks, xlabels=xlabels, ylabel=ylabel.capitalize(), palette=get_colormap_tableu20(), style="seaborn-white") plt.savefig("nr_spikes.png") xlabels = [ r"Potassium conductance $\bar{g}_\mathrm{K}$", r"Sodium conductance $\bar{g}_\mathrm{Na}$", r"Leak conductance $\bar{g}_\mathrm{l}$" ] xticks = [0, width + 0.1, 2 * (width + 0.1)] values = [ data["nr_spikes"].mean, data["nr_spikes"].variance,
def test_prettyPlotFalseNewFigure2(self): prettyBar(self.values, new_figure=False) plt.close()
def test_PrettyBarLabels(self): prettyBar(self.values, xlabels=self.labels) plt.close()
def test_PrettyBarError(self): prettyBar(self.values, self.error) plt.close()
def test_PrettyBar(self): prettyBar(self.values) plt.close()