diff --git a/gui.py b/gui.py index 17fdef0..be37745 100644 --- a/gui.py +++ b/gui.py @@ -1,6 +1,7 @@ import matplotlib as mpl import matplotlib.pyplot as plt -from matplotlib.widgets import Slider, Button, RadioButtons, LassoSelector, SpanSelector +from matplotlib.widgets import Slider, Button, RadioButtons, LassoSelector +from matplotlib.widgets import SpanSelector, PolygonSelector, CheckButtons import matplotlib.patches as patches from matplotlib.lines import Line2D from matplotlib.path import Path @@ -219,22 +220,35 @@ class InteractiveGUI: plt.sca(self.ax_gamma) # (a, b, r, _, _) = linregress(self.frho_map[self.mask], self.fcs_map[self.mask]) + if self.full_gamma_button.get_status()[0]: + rho = np.log10(self.pp.cells["rho"]) + cs = np.log10(np.sqrt(self.pp.cells["P"])) + mask_fin = np.isfinite(rho) & np.isfinite(cs) + rho, cs = rho[mask_fin], cs[mask_fin] + plt.xlabel(r"$\log(\rho)$") + plt.ylabel(r"$\log(P)$") + self.get_gamma = lambda a: a + else: + rho = self.frho_map[self.mask] + cs = self.fcs_map[self.mask] + plt.xlabel(r"$\log(\rho / \bar{\rho})$") + plt.ylabel(r"$\log(c_s / \bar{c_s})$") + self.get_gamma = lambda a: 2 * a + 1 + if first: _, _, _, self.gamma_hist = plt.hist2d( - self.frho_map[self.mask], - self.fcs_map[self.mask], + rho, + cs, bins=100, norm=mpl.colors.LogNorm(), cmap=plt.get_cmap("plasma"), ) - plt.xlabel(r"$\log(\rho / \bar{\rho})$") - plt.ylabel(r"$\log(c_s / \bar{c_s})$") # cbar = plt.colorbar() else: self.gamma_hist.remove() _, _, _, self.gamma_hist = plt.hist2d( - self.frho_map[self.mask], - self.fcs_map[self.mask], + rho, + cs, bins=100, norm=mpl.colors.LogNorm(), cmap=plt.get_cmap("plasma"), @@ -244,7 +258,8 @@ class InteractiveGUI: lps = self.line_gamma.list_points xa, ya, xb, yb = lps[0].x, lps[0].y, lps[1].x, lps[1].y a = (yb - ya) / (xb - xa) - self.ax_gamma.set_title("$\Gamma$ = {:.3g}".format(2 * a + 1)) + + self.ax_gamma.set_title("$\Gamma$ = {:.3g}".format(self.get_gamma(a))) ## PDF if first or update_map: @@ -313,9 +328,24 @@ class InteractiveGUI: print("Warning in linregress : {}".format(e)) a, b, r = np.nan, np.nan, np.nan + xv, yv = float(xa) / self.shape[0], float(ya) / self.shape[1] + mask_vert = (xv >= self.pp.cells["pos"][:, 0]) & ( + xv < self.pp.cells["pos"][:, 0] + self.pp.cells["dx"] + ) + mask_vert = ( + mask_vert + & (yv >= self.pp.cells["pos"][:, 1]) + & (yv < self.pp.cells["pos"][:, 1] + self.pp.cells["dx"]) + ) + rho_vert = np.log10(self.pp.cells["rho"][mask_vert]) + z_vert = self.pp.cells["pos"][mask_vert][:, 2] - 0.5 + sorter = np.argsort(z_vert) + rho_vert = rho_vert[sorter] + z_vert = z_vert[sorter] + if first: (self.prof,) = plt.semilogx(x, rho_prof) - plt.xlim([None, None]) + (self.prof_z,) = plt.semilogx(z_vert, rho_vert) plt.title("Profil") (self.fit_prof,) = plt.plot( x[mask_fit_prof], @@ -328,7 +358,7 @@ class InteractiveGUI: self.ax_profile.set_ylabel(r"$\log(\rho)$") else: self.prof.set_data(x, rho_prof) - plt.xlim([None, None]) + self.prof_z.set_data(z_vert, rho_vert) self.fit_prof.set_data(x[mask_fit_prof], a * np.log10(x[mask_fit_prof]) + b) self.fit_prof.set_label(r"a = {:.3g}, $R^2$ = {:.3g}".format(a, r ** 2)) @@ -346,15 +376,15 @@ class InteractiveGUI: self.mask = self.mask_flat.reshape(self.shape) self.draw() - def clicked_select(self, val): + def clicked_select(self, val, selector, button): if not self.lasso: - self.lasso = LassoSelector( + self.lasso = selector( self.ax_fluct, partial(self.onselect, select_data=self.points) ) - self.lasso_gamma = LassoSelector( + self.lasso_gamma = selector( self.ax_gamma, partial(self.onselect, select_data=self.rhocs) ) - self.lasso_button.color = "0.55" + button.color = "0.55" else: self.unselect_lasso() @@ -362,6 +392,7 @@ class InteractiveGUI: self.lasso = False self.lasso_gamma = False self.lasso_button.color = "0.85" + self.poly_button.color = "0.85" def clicked_reset(self, val): self.mask = (self.rr > self.rmin) & (self.rr < self.rmax) @@ -399,6 +430,7 @@ class InteractiveGUI: self.pp.pdf_coldens("z") self.pp.pdf_rho("z") self.pp.pdf_T("z") + self.pp.load_cells() self.datamap = self.pp.get_value("/maps/" + datamap_key) self.frho_map = np.log10(self.pp.get_value("/maps/fluct_rho_z")) self.T_map = self.pp.get_value("/maps/T_z") @@ -435,17 +467,30 @@ class InteractiveGUI: self.mask = (self.rr > self.rmin) & (self.rr < self.rmax) self.mask_flat = self.mask.flatten() - ax_rmax = plt.axes([0.1, 0.03, 0.4, 0.02]) + ax_rmax = plt.axes([0.3, 0.03, 0.15, 0.02]) self.srmax = Slider(ax_rmax, r"$r_{max}$", 0, 0.5, valinit=self.rmax) - ax_rmin = plt.axes([0.1, 0.07, 0.4, 0.02]) + ax_rmin = plt.axes([0.05, 0.03, 0.15, 0.02]) self.srmin = Slider(ax_rmin, r"$r_{min}$", 0, 0.5, valinit=self.rmin) - ax_lasso = plt.axes([0.6, 0.07, 0.2, 0.02]) + ax_lasso = plt.axes([0.6, 0.07, 0.19, 0.02]) + ax_poly = plt.axes([0.8, 0.07, 0.19, 0.02]) + ax_full_gamma = plt.axes([0.1, 0.07, 0.19, 0.02]) + self.full_gamma_button = CheckButtons(ax_full_gamma, ["Full $\Gamma$"], [True]) self.lasso = False self.lasso_gamma = False - self.lasso_button = Button(ax_lasso, "Select region") - self.lasso_button.on_clicked(self.clicked_select) + self.lasso_button = Button(ax_lasso, "Lasso selector") + self.poly_button = Button(ax_poly, "Polygon selector") + self.lasso_button.on_clicked( + partial( + self.clicked_select, selector=LassoSelector, button=self.lasso_button + ) + ) + self.poly_button.on_clicked( + partial( + self.clicked_select, selector=PolygonSelector, button=self.poly_button + ) + ) - ax_reset = plt.axes([0.6, 0.03, 0.2, 0.02]) + ax_reset = plt.axes([0.6, 0.03, 0.19, 0.02]) self.reset_button = Button(ax_reset, "Reset") self.reset_button.on_clicked(self.clicked_reset) diff --git a/plotter.py b/plotter.py index 042f6b1..5130f82 100644 --- a/plotter.py +++ b/plotter.py @@ -118,7 +118,15 @@ class Plotter(Aggregator, BaseProcessor): ) def _process_rule( - self, name, rule, arg, overwrite=False, ax=None, movie=False, **kwargs + self, + name, + rule, + arg, + overwrite=False, + ax=None, + movie=False, + from_cells=False, + **kwargs ): if not arg is None: name_full = name + "_" + str(arg) @@ -143,7 +151,12 @@ class Plotter(Aggregator, BaseProcessor): for num in nums: plot_filename = self._find_filename(name_full, run, num) - if rule.kind == "classic": + if from_cells or rule.kind == "cells": + if not os.exists(self.pp[run][num].cells_filename): + self.pp[run][num].load_cells() + self.pp[run][num].unload_cells() + save = tables.open_file(self.pp[run][num].cells_filename) + elif rule.kind == "classic": save = tables.open_file(self.pp[run][num].filename) else: save = tables.open_file(self.comp.filename, "r")