Possible to call rule directly
This commit is contained in:
+97
-19
@@ -55,6 +55,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
label_convert = {
|
||||
"turb_rms": "$f_{rms}$",
|
||||
"beta": "$\\beta$",
|
||||
"beta_cool": "$\\beta_{c}$",
|
||||
"dens0": "$n_0$",
|
||||
"sfr_avg_window": "window",
|
||||
"comp_frac": "$\\zeta$",
|
||||
@@ -286,6 +287,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
title=None,
|
||||
nml_key=None,
|
||||
put_time=True,
|
||||
time_unit=cst.Myr,
|
||||
cmap="plasma",
|
||||
norm="log",
|
||||
autoscale=True,
|
||||
@@ -330,7 +332,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
if put_time:
|
||||
time = self.save.root._v_attrs.time * self.comp.info["unit_time"]
|
||||
time_str = "time = {:.6g} Myr".format(time.express(cst.Myr))
|
||||
time_str = "time = {:.6g} {}".format(
|
||||
time.express(time_unit), time_unit.latex
|
||||
)
|
||||
if len(title) > 0:
|
||||
title = title + " | " + time_str
|
||||
else:
|
||||
@@ -423,19 +427,51 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if not label is None:
|
||||
P.ylabel(label)
|
||||
|
||||
def _plot_hist(self, name, ax_los="z", label=None, ylog=False):
|
||||
def _plot_hist(
|
||||
self,
|
||||
name,
|
||||
ax_los,
|
||||
run,
|
||||
label=None,
|
||||
unit=None,
|
||||
unit_coeff=1.0,
|
||||
title=None,
|
||||
nml_key=None,
|
||||
put_time=True,
|
||||
time_unit=cst.Myr,
|
||||
ylog=False,
|
||||
**kwargs
|
||||
):
|
||||
|
||||
pdf = self.save.get_node("/hist/" + name + "_" + ax_los)
|
||||
values, centers = pdf.read()
|
||||
node = self.save.get_node("/hist/" + name + "_" + ax_los)
|
||||
|
||||
label, unit_old, unit = self._ax_label_unit(node, label, unit, unit_coeff)
|
||||
values, centers = node.read() * unit_old.express(unit)
|
||||
width = centers[1] - centers[0]
|
||||
P.bar(centers, values, width, log=ylog)
|
||||
|
||||
P.bar(centers, values, width, log=ylog, **kwargs)
|
||||
P.grid()
|
||||
|
||||
title = self._label_run(run, node, title, nml_key)
|
||||
|
||||
if put_time:
|
||||
time = self.save.root._v_attrs.time * self.comp.info["unit_time"]
|
||||
time_str = "time = {:.6g} {}".format(
|
||||
time.express(time_unit), time_unit.latex
|
||||
)
|
||||
if len(title) > 0:
|
||||
title = title + " | " + time_str
|
||||
else:
|
||||
title = time_str
|
||||
|
||||
P.title(title)
|
||||
|
||||
if not label is None:
|
||||
P.xlabel(label)
|
||||
|
||||
if "/hist/fit_" + name + "_" + ax_los in self.save:
|
||||
slope = pdf.attrs.slope
|
||||
origin = pdf.attrs.origin
|
||||
slope = node.attrs.slope
|
||||
origin = node.attrs.origin
|
||||
P.plot(
|
||||
centers,
|
||||
10 ** (slope * centers + origin),
|
||||
@@ -481,6 +517,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if node_y._v_attrs.CLASS == "ARRAY":
|
||||
x = node_x.read() * xunit_old.express(xunit)
|
||||
y = node_y.read() * yunit_old.express(yunit)
|
||||
mask = np.isfinite(y)
|
||||
x, y = x[mask], y[mask]
|
||||
if smooth > 0:
|
||||
y = gaussian_filter1d(y, sigma=smooth)
|
||||
yerr = None
|
||||
@@ -488,6 +526,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
elif "mean" in node_y:
|
||||
x = node_x.read() * xunit_old.express(xunit)
|
||||
y = node_y.mean.read() * yunit_old.express(yunit)
|
||||
mask = np.isfinite(y)
|
||||
x, y = x[mask], y[mask]
|
||||
if smooth > 0:
|
||||
y = gaussian_filter1d(y, sigma=smooth)
|
||||
yerr = node_y.std.read() * yunit_old.express(yunit)
|
||||
@@ -500,6 +540,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
x_run, y_run = node_x[run], node_y[run]
|
||||
x = x_run.read() * xunit_old.express(xunit)
|
||||
y = y_run.read() * yunit_old.express(yunit)
|
||||
mask = np.isfinite(y)
|
||||
x, y = x[mask], y[mask]
|
||||
if smooth > 0:
|
||||
y = gaussian_filter1d(y, sigma=smooth)
|
||||
label_run = self._label_run(run, y_run, label, nml_key)
|
||||
@@ -507,16 +549,25 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
P.legend()
|
||||
|
||||
if linearfit:
|
||||
_overlay_linearfit(x, y, yerr)
|
||||
self._overlay_linearfit(x, y, yerr)
|
||||
|
||||
def _overlay_linearfit(x, y, yerr=None):
|
||||
def _overlay_linearfit(self, x, y, yerr=None, fit_order=1):
|
||||
if yerr is None:
|
||||
(a, b, rho, _, stderr) = linregress(x, y)
|
||||
(a, b, rho, _map_rule, stderr) = linregress(x, y)
|
||||
self._log(
|
||||
"Linear fit y = {} x + {} with R^2 = {} and error is {}".format(
|
||||
a, b, rho, stderr
|
||||
)
|
||||
)
|
||||
else:
|
||||
c = polyfit(x, y, 1, w=[1.0 / ty for ty in yerr], full=False)
|
||||
fit = polyfit(x, y, 1, w=[1.0 / ty for ty in yerr], full=True)
|
||||
c = fit[0]
|
||||
residual = fit[1][0][0]
|
||||
b, a = c[0], c[1]
|
||||
|
||||
P.plot(x, a * y + b, "--", linewidth=1.5)
|
||||
self._log(
|
||||
"Linear fit y = {} x + {} with residual {}".format(a, b, residual)
|
||||
)
|
||||
P.plot(x, a * x + b, "--", linewidth=1.5)
|
||||
|
||||
def overlay_kennicutt(self, n0, step):
|
||||
P.grid(False)
|
||||
@@ -638,7 +689,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
label="{}/avg({})".format(name, name),
|
||||
),
|
||||
"Probability density function of {} fluctuations".format(name),
|
||||
dependencies=["pdf_" + name],
|
||||
dependencies=["fit_pdf_" + name],
|
||||
)
|
||||
|
||||
self.rules.update(
|
||||
@@ -647,12 +698,14 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/comp/beta",
|
||||
"/comp/avg_pdf_slope_coldens",
|
||||
linearfit=True,
|
||||
"/comp/nml_cloud_params/beta_cool",
|
||||
"/comp/avg_time_pdf_slope_coldens",
|
||||
),
|
||||
kind="comp",
|
||||
dependencies=["beta", "avg_pdf_slope_coldens"],
|
||||
dependencies={
|
||||
"nml": "cloud_params/beta_cool",
|
||||
"avg_time_pdf_slope_coldens": None,
|
||||
},
|
||||
),
|
||||
"sink_mass": PlotRule(
|
||||
self,
|
||||
@@ -703,6 +756,17 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
kind="series",
|
||||
dependencies=["rms_from_log"],
|
||||
),
|
||||
"turb_energy": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
"/series/rms_from_log/turb_energy",
|
||||
xunit=cst.Myr,
|
||||
),
|
||||
kind="series",
|
||||
dependencies=["rms_from_log"],
|
||||
),
|
||||
"sigma": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
@@ -713,15 +777,29 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.km_s,
|
||||
),
|
||||
kind="comp",
|
||||
kind="series",
|
||||
dependencies=["time_sigma"],
|
||||
),
|
||||
"max_fluct_coldens": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/time",
|
||||
"/series/time_max_fluct_coldens_z",
|
||||
ylabel="$\\max(\Sigma/\overline{\Sigma})$",
|
||||
xunit=cst.Myr,
|
||||
),
|
||||
kind="series",
|
||||
dependencies={"time_max_fluct_coldens": "z"},
|
||||
),
|
||||
"plot": PlotRule(
|
||||
self, lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="comp"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
super(Plotter, self).def_rules()
|
||||
|
||||
|
||||
class InteractiveGUI:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user