Huge refactoring
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import matplotlib as mpl
|
||||
import numpy as np
|
||||
from functools import partial
|
||||
import matplotlib.patches as patches
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.lines import Line2D
|
||||
@@ -8,14 +10,14 @@ from matplotlib.widgets import (
|
||||
CheckButtons,
|
||||
LassoSelector,
|
||||
PolygonSelector,
|
||||
RadioButtons,
|
||||
Slider,
|
||||
SpanSelector,
|
||||
)
|
||||
from scipy.stats import linregress
|
||||
from skimage.draw import line
|
||||
|
||||
from postprocessor import *
|
||||
from snapshotprocessor import SnapshotProcessor
|
||||
from params import default_params
|
||||
|
||||
|
||||
class DraggablePoint:
|
||||
@@ -184,42 +186,6 @@ class DraggableLine:
|
||||
self.list_points[1].line.remove()
|
||||
|
||||
|
||||
class FitterTool:
|
||||
"""
|
||||
Flexible fitter tool
|
||||
"""
|
||||
|
||||
def __init__(self, ax, bounds=None):
|
||||
self.ax = ax
|
||||
self.bounds = bounds
|
||||
self.bounds_selector = SpanSelector(
|
||||
self.ax, self.onselect, "horizontal", useblit=True, span_stays=True
|
||||
)
|
||||
self.fitline = DraggableLine(self, self.ax_gamma, [0, 0], [1, 0.3], 0.05)
|
||||
|
||||
if update_map and self.gamma_3d_button.get_status()[1]:
|
||||
lr = linregress(rho[rho > -4], cs[rho > -4])
|
||||
(a, b, r, _, _) = lr
|
||||
self.line_gamma.clear()
|
||||
del self.line_gamma
|
||||
rhomin, rhomax = np.min(rho), np.max(rho)
|
||||
self.line_gamma = DraggableLine(
|
||||
self,
|
||||
self.ax_gamma,
|
||||
[rhomin, a * rhomin + b],
|
||||
[rhomax, a * rhomax + b],
|
||||
0.05,
|
||||
)
|
||||
print("Gamma linregress : {}".format(lr))
|
||||
else:
|
||||
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)
|
||||
|
||||
def onselect(self, vmin, vmax):
|
||||
self.bounds = (vmin, vmax)
|
||||
|
||||
|
||||
class InteractiveGUI:
|
||||
"""
|
||||
This is a matplotlib interactive session to restrain analysis to a specific area
|
||||
@@ -245,7 +211,7 @@ class InteractiveGUI:
|
||||
self.fcs = np.copy(self.fcs_map)
|
||||
self.fmap[np.logical_not(self.mask)] = np.nan
|
||||
|
||||
## Map
|
||||
# Map
|
||||
plt.sca(self.ax_fluct)
|
||||
if first:
|
||||
self.im = plt.imshow(
|
||||
@@ -262,7 +228,7 @@ class InteractiveGUI:
|
||||
else:
|
||||
self.im.set_data(self.fmap)
|
||||
|
||||
## Gamma
|
||||
# Gamma
|
||||
plt.sca(self.ax_gamma)
|
||||
|
||||
if self.gamma_3d_button.get_status()[0]:
|
||||
@@ -317,7 +283,7 @@ class InteractiveGUI:
|
||||
|
||||
self.ax_gamma.set_title("$\Gamma$ = {:.3g}".format(self.get_gamma(a)))
|
||||
|
||||
## PDF
|
||||
# PDF
|
||||
if first or update_map:
|
||||
plt.sca(self.ax_pdf)
|
||||
nb_cells = np.sum(self.mask_flat)
|
||||
@@ -325,7 +291,7 @@ class InteractiveGUI:
|
||||
self.std_nb_cells = nb_cells
|
||||
values, self.edges = np.histogram(
|
||||
np.log10(self.fmap.flatten()[self.mask_flat]),
|
||||
self.pp.pp_params.pdf.nb_bin,
|
||||
self.pp.params.pdf.nb_bin,
|
||||
weights=np.ones(nb_cells) / self.std_nb_cells,
|
||||
)
|
||||
edges = self.edges
|
||||
@@ -340,8 +306,8 @@ class InteractiveGUI:
|
||||
|
||||
centers = 0.5 * (edges[1:] + edges[:-1])
|
||||
mask_fit = (
|
||||
(centers > self.pp.pp_params.pdf.xmin_fit)
|
||||
& (centers < self.pp.pp_params.pdf.xmax_fit)
|
||||
(centers > self.pp.params.pdf.xmin_fit)
|
||||
& (centers < self.pp.params.pdf.xmax_fit)
|
||||
& (values > 0)
|
||||
)
|
||||
(a, b, r, _, _) = linregress(centers[mask_fit], np.log10(values[mask_fit]))
|
||||
@@ -364,21 +330,21 @@ class InteractiveGUI:
|
||||
self.fit.set_label(r"a = {:.3g}, $R^2$ = {:.3g}".format(a, r ** 2))
|
||||
plt.legend()
|
||||
|
||||
### PROFILE
|
||||
# PROFILE
|
||||
plt.sca(self.ax_profile)
|
||||
lps = self.line_profile.list_points
|
||||
xa, ya, xb, yb = lps[0].x, lps[0].y, lps[1].x, lps[1].y
|
||||
coor_pix = list(
|
||||
np.asarray(
|
||||
(np.array([xa, ya, xb, yb]) * self.pp.pp_params.pymses.zoom + 0.5)
|
||||
(np.array([xa, ya, xb, yb]) * self.pp.params.pymses.zoom + 0.5)
|
||||
* self.shape[0],
|
||||
dtype=int,
|
||||
)
|
||||
)
|
||||
xpp, ypp = line(*coor_pix)
|
||||
rho_prof = self.rho_map[ypp, xpp]
|
||||
xp = ((xpp / float(self.shape[0])) - 0.5) / self.pp.pp_params.pymses.zoom
|
||||
yp = ((ypp / float(self.shape[1])) - 0.5) / self.pp.pp_params.pymses.zoom
|
||||
xp = ((xpp / float(self.shape[0])) - 0.5) / self.pp.params.pymses.zoom
|
||||
yp = ((ypp / float(self.shape[1])) - 0.5) / self.pp.params.pymses.zoom
|
||||
print(xp, yp, xpp, ypp)
|
||||
x = np.sqrt(np.abs((xp - xa) * (xb - xa) + (yp - ya) * (yb - ya)))
|
||||
x = x - float(x[0])
|
||||
@@ -482,27 +448,27 @@ class InteractiveGUI:
|
||||
self.fit_prof_vmax = vmax
|
||||
self.draw()
|
||||
|
||||
def __init__(self, num, path="./", pp_params=None, datamap_key="fluct_coldens_z"):
|
||||
def __init__(self, num, path="./", params=None, datamap_key="fluct_coldens_z"):
|
||||
"""
|
||||
Interactive plotting
|
||||
|
||||
"""
|
||||
if pp_params is None:
|
||||
pp_params = default_params()
|
||||
pp_params.input.nml_filename = "disk.nml"
|
||||
pp_params.out.interactive = True
|
||||
pp_params.pymses.map_size = 4096
|
||||
pp_params.pymses.zoom = 4
|
||||
if params is None:
|
||||
params = default_params()
|
||||
params.input.nml_filename = "disk.nml"
|
||||
params.out.interactive = True
|
||||
params.pymses.map_size = 4096
|
||||
params.pymses.zoom = 4
|
||||
|
||||
pp_params.pymses.variables = ["rho", "vel", "P"]
|
||||
params.pymses.variables = ["rho", "vel", "P"]
|
||||
|
||||
pp_params.disk.enable = True
|
||||
pp_params.disk.nb_bin = 200
|
||||
pp_params.pdf.nb_bin = 100
|
||||
params.disk.enable = True
|
||||
params.disk.nb_bin = 200
|
||||
params.pdf.nb_bin = 100
|
||||
|
||||
self.fig = plt.figure(figsize=(10, 8))
|
||||
|
||||
self.pp = PostProcessor(path, num, pp_params=pp_params, tag="interactive")
|
||||
self.pp = SnapshotProcessor(path, num, params=params, tag="interactive")
|
||||
self.pp.pdf_coldens("z")
|
||||
self.pp.pdf_rho("z")
|
||||
self.pp.pdf_T("z")
|
||||
@@ -523,8 +489,8 @@ class InteractiveGUI:
|
||||
self.rr = np.sqrt(self.xx ** 2 + self.yy ** 2)
|
||||
self.rhocs = np.column_stack((self.frho_map.flatten(), self.fcs_map.flatten()))
|
||||
|
||||
self.rmin = self.pp.pp_params.disk.rmin_pdf / 2.0
|
||||
self.rmax = self.pp.pp_params.disk.rmax_pdf / 2.0
|
||||
self.rmin = self.pp.params.disk.rmin_pdf / 2.0
|
||||
self.rmax = self.pp.params.disk.rmax_pdf / 2.0
|
||||
self.mask = (self.rr >= self.rmin) & (self.rr <= self.rmax)
|
||||
self.mask_flat = self.mask.flatten()
|
||||
|
||||
@@ -553,11 +519,11 @@ class InteractiveGUI:
|
||||
|
||||
ax_rmax = plt.axes([0.05, 0.07, 0.15, 0.02])
|
||||
self.srmax = Slider(
|
||||
ax_rmax, r"$r_{max}$", 0, 0.7 / pp_params.pymses.zoom, valinit=self.rmax
|
||||
ax_rmax, r"$r_{max}$", 0, 0.7 / params.pymses.zoom, valinit=self.rmax
|
||||
)
|
||||
ax_rmin = plt.axes([0.05, 0.03, 0.15, 0.02])
|
||||
self.srmin = Slider(
|
||||
ax_rmin, r"$r_{min}$", 0, 0.7 / pp_params.pymses.zoom, valinit=self.rmin
|
||||
ax_rmin, r"$r_{min}$", 0, 0.7 / params.pymses.zoom, valinit=self.rmin
|
||||
)
|
||||
ax_lasso = plt.axes([0.6, 0.07, 0.19, 0.02])
|
||||
ax_poly = plt.axes([0.8, 0.07, 0.19, 0.02])
|
||||
|
||||
Reference in New Issue
Block a user