update
This commit is contained in:
+28
-14
@@ -122,10 +122,10 @@ class Comparator(Aggregator, HDF5Container):
|
||||
def _time_series(self, getter, arg=None):
|
||||
series = {}
|
||||
for run in self.runs:
|
||||
series[run] = np.zeros(len(self.nums[run]))
|
||||
series[run] = []
|
||||
for i, num in enumerate(self.nums[run]):
|
||||
series[run][i] = getter(run, num, arg=arg)
|
||||
return series
|
||||
series[run].apend(getter(run, num, arg=arg))
|
||||
return np.array(series)
|
||||
|
||||
def _comp(self, getter, use_num=True):
|
||||
prop = np.zeros(len(self.runs))
|
||||
@@ -137,9 +137,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
prop[i] = getter(run)
|
||||
return prop
|
||||
|
||||
def _time_avg(
|
||||
self, name, start=None, end=None, span=None, ergodic=False, group="/series"
|
||||
):
|
||||
def _time_avg(self, name, start=None, end=None, span=None, group="/series"):
|
||||
mean = np.zeros(len(self.runs))
|
||||
median = np.zeros(len(self.runs))
|
||||
std = np.zeros(len(self.runs))
|
||||
@@ -169,15 +167,11 @@ class Comparator(Aggregator, HDF5Container):
|
||||
|
||||
mask = mask & (time >= start_r) & (time <= end_r) & np.isfinite(serie)
|
||||
|
||||
mean[i] = np.mean(serie[mask])
|
||||
std[i] = np.std(serie[mask])
|
||||
mean[i] = np.mean(serie[mask], axis=0)
|
||||
std[i] = np.std(serie[mask], axis=0)
|
||||
v_min[i], q025[i], median[i], q975[i], v_max[i] = np.percentile(
|
||||
serie[mask], [0, 2.5, 50, 97.5, 100]
|
||||
serie[mask], [0, 2.5, 50, 97.5, 100], axis=0
|
||||
)
|
||||
if ergodic: # If the process is ergodic ...
|
||||
std[i] = std[i] / np.sqrt(len(serie[mask]))
|
||||
else:
|
||||
std[i] = std[i]
|
||||
return {
|
||||
"runs": self.runs,
|
||||
"mean": mean,
|
||||
@@ -195,6 +189,12 @@ class Comparator(Aggregator, HDF5Container):
|
||||
node_name = node_name + "_" + str(arg)
|
||||
return pp.get_attribute(node_name, attr_name)
|
||||
|
||||
def get_pp_value(self, name, run, num, arg=None):
|
||||
pp = self.pp[run][num]
|
||||
if not arg is None:
|
||||
name = name + "_" + str(arg)
|
||||
return pp.get_value(name)
|
||||
|
||||
def get_global(self, node_name, run, num, arg=None, unload_cells=False):
|
||||
if not arg is None:
|
||||
node_name = node_name + "_" + str(arg)
|
||||
@@ -509,6 +509,14 @@ class Comparator(Aggregator, HDF5Container):
|
||||
unit="unit_time",
|
||||
dependencies=["time_num"],
|
||||
),
|
||||
"time_rho_prof": Rule(
|
||||
self,
|
||||
partial(
|
||||
self._time_series, partial(self.get_pp_value, "/profile/rho_prof")
|
||||
),
|
||||
group="/series",
|
||||
dependencies={"time": None, "rho_prof": "__parent__"},
|
||||
),
|
||||
"time_pdf_slope_coldens": Rule(
|
||||
self,
|
||||
partial(
|
||||
@@ -535,7 +543,13 @@ class Comparator(Aggregator, HDF5Container):
|
||||
self._gen_rule_time_global("mwa_sigma", "time_sigma", unit="unit_velocity")
|
||||
self._gen_rule_time_global("max_fluct_coldens")
|
||||
|
||||
for name in ["issfr", "time_sigma", "time_pdf_slope_coldens", "turb_power"]:
|
||||
for name in [
|
||||
"issfr",
|
||||
"time_sigma",
|
||||
"time_pdf_slope_coldens",
|
||||
"turb_power",
|
||||
"time_rho_prof",
|
||||
]:
|
||||
self._gen_rule_avg(name)
|
||||
|
||||
self._gen_rule_avg("sinks_from_log", "mass_sink")
|
||||
|
||||
+43
-17
@@ -129,6 +129,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if rule.kind == "classic":
|
||||
try:
|
||||
runs = kwargs.pop("runs")
|
||||
if isinstance(runs, RunSelector):
|
||||
runs = runs.runs
|
||||
except KeyError:
|
||||
runs = self.runs
|
||||
|
||||
@@ -150,7 +152,12 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
run=run,
|
||||
**kwargs
|
||||
)
|
||||
except TypeError:
|
||||
except TypeError as e:
|
||||
if (
|
||||
str(e)
|
||||
!= "'LocatableAxes' object does not support indexing"
|
||||
):
|
||||
raise
|
||||
self._plot_rule(
|
||||
rule,
|
||||
save,
|
||||
@@ -207,7 +214,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
tag_name = "_" + tag_name
|
||||
|
||||
if not run is None and not num is None:
|
||||
fmt = "{out}/{run}/{name}{tag}_{run}_{num:05}_{ext}"
|
||||
fmt = "{out}/{run}/{name}{tag}_{run}_{num:05}{ext}"
|
||||
elif not run is None:
|
||||
fmt = "{out}/{run}/{name}{tag}_{run}{ext}"
|
||||
else:
|
||||
@@ -300,6 +307,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
overlays=[],
|
||||
overlays_kwargs=[],
|
||||
title=None,
|
||||
put_title=True,
|
||||
nml_key=None,
|
||||
put_time=True,
|
||||
time_unit=cst.Myr,
|
||||
@@ -352,19 +360,20 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if not label is None:
|
||||
cbar.set_label(label)
|
||||
|
||||
title = self._label_run(run, node, title, nml_key)
|
||||
if put_title:
|
||||
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 = self.pp_params.plot.time_fmt.format(
|
||||
time.express(time_unit), time_unit.latex
|
||||
)
|
||||
if len(title) > 0:
|
||||
title = title + " | " + time_str
|
||||
else:
|
||||
title = time_str
|
||||
if put_time:
|
||||
time = self.save.root._v_attrs.time * self.comp.info["unit_time"]
|
||||
time_str = self.pp_params.plot.time_fmt.format(
|
||||
time.express(time_unit), time_unit.latex
|
||||
)
|
||||
if len(title) > 0:
|
||||
title = title + " | " + time_str
|
||||
else:
|
||||
title = time_str
|
||||
|
||||
P.title(title)
|
||||
P.title(title)
|
||||
|
||||
for i, plot_overlay in enumerate(overlays):
|
||||
try:
|
||||
@@ -470,6 +479,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
xlog=None,
|
||||
ylog=False,
|
||||
kind="bar",
|
||||
color=None,
|
||||
colors=None,
|
||||
nml_color=None,
|
||||
**kwargs
|
||||
@@ -505,8 +515,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
P.title(title)
|
||||
|
||||
color = None
|
||||
if not colors is None:
|
||||
if color is None and not colors is None:
|
||||
if nml_color is None:
|
||||
color = colors[run]
|
||||
else:
|
||||
@@ -547,6 +556,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self,
|
||||
name_x,
|
||||
name_y,
|
||||
node_arg=None,
|
||||
xlabel=None,
|
||||
ylabel=None,
|
||||
label=None,
|
||||
@@ -558,14 +568,19 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
fitlabel=None,
|
||||
smooth=0,
|
||||
nml_key=None,
|
||||
run=None,
|
||||
runs=None,
|
||||
yerr_kind="std",
|
||||
sigma_err=2.0,
|
||||
grid=True,
|
||||
colors=None,
|
||||
nml_color=None,
|
||||
**kwargs
|
||||
):
|
||||
|
||||
if not node_arg is None:
|
||||
name_x, name_y = name_x + "_" + node_arg, name_y + "_" + node_arg
|
||||
|
||||
node_x = self.save.get_node(name_x)
|
||||
node_y = self.save.get_node(name_y)
|
||||
|
||||
@@ -578,7 +593,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
P.xlabel(xlabel)
|
||||
P.ylabel(ylabel)
|
||||
P.grid()
|
||||
|
||||
if grid:
|
||||
P.grid()
|
||||
|
||||
yerr = None
|
||||
if node_y._v_attrs.CLASS == "ARRAY":
|
||||
@@ -588,7 +605,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
x, y = x[mask], y[mask]
|
||||
if smooth > 0:
|
||||
y = gaussian_filter1d(y, sigma=smooth)
|
||||
(base_line,) = P.plot(x, y, "*", **kwargs)
|
||||
if not run is None:
|
||||
label = self._label_run(run, node_y, label, nml_key)
|
||||
(base_line,) = P.plot(x, y, label=label, **kwargs)
|
||||
elif "mean" in node_y:
|
||||
x = node_x.read() * xunit_old.express(xunit)
|
||||
y = node_y.mean.read() * yunit_old.express(yunit)
|
||||
@@ -616,6 +635,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
yerr_min[mask],
|
||||
yerr_max[mask],
|
||||
)
|
||||
if not run is None:
|
||||
label = self._label_run(run, node_y, label, nml_key)
|
||||
base_line, _, _ = P.errorbar(
|
||||
x, y, yerr=[y - yerr_min, yerr_max - y], label=label, **kwargs
|
||||
)
|
||||
@@ -806,6 +827,11 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"P_pdf": PlotRule(
|
||||
self, partial(self._plot_hist, "P_pdf"), "P-PDF", dependencies=["P_pdf"]
|
||||
),
|
||||
"rho_prof": PlotRule(
|
||||
self,
|
||||
partial(self._plot, "/profile/axis", "/profile/rho_prof"),
|
||||
dependencies=["axis", "rho_prof"],
|
||||
),
|
||||
}
|
||||
|
||||
averageables = ["coldens", "rho", "T", "Q"]
|
||||
|
||||
+51
-1
@@ -1,5 +1,5 @@
|
||||
# coding: utf-8
|
||||
|
||||
import pandas as pd
|
||||
from baseprocessor import *
|
||||
|
||||
mass_func = lambda dset: dset["rho"] * dset["dx"] ** 3 # Mass function
|
||||
@@ -141,6 +141,7 @@ class PostProcessor(HDF5Container):
|
||||
for key in cells_pymses.fields:
|
||||
self.cells[key] = cells_pymses[key]
|
||||
self.cells["dx"] = cells_pymses.get_sizes()
|
||||
self.cells["pos"] = cells_pymses.points
|
||||
|
||||
if self.pp_params.process.save_cells:
|
||||
cells_hdf5 = tables.open_file(self.cells_filename, mode="w")
|
||||
@@ -195,6 +196,7 @@ class PostProcessor(HDF5Container):
|
||||
):
|
||||
"""
|
||||
Map of the average of a quantity (given by getter) along an axis (ax_los)
|
||||
Return 2D array
|
||||
"""
|
||||
if mass_weighted:
|
||||
|
||||
@@ -216,6 +218,38 @@ class PostProcessor(HDF5Container):
|
||||
datamap = rt.process(self._cam[ax_los], surf_qty=surf_qty)
|
||||
return datamap.map.T
|
||||
|
||||
def _get_axis(self, axis):
|
||||
|
||||
if isinstance(axis, str):
|
||||
axis = self._ax_nb[axis]
|
||||
|
||||
self.load_cells()
|
||||
return np.sort(np.unique(self.cells["pos"][:, axis]))
|
||||
|
||||
def _plane_avg_uniform(
|
||||
self, getter, axis, unit=cst.none, mass_weighted=True, surf_qty=False
|
||||
):
|
||||
"""
|
||||
Profile of the average of a quantity (given by getter) perpendicular to an axis
|
||||
WARNING : This version only works on an uniform grid, need of a box version for AMR
|
||||
"""
|
||||
self.load_cells()
|
||||
if isinstance(axis, str):
|
||||
axis = self._ax_nb[axis]
|
||||
axis_data = self.cells["pos"][:, axis]
|
||||
value = getter(self.cells)
|
||||
|
||||
df = pd.DataFrame({"axis": axis_data})
|
||||
if mass_weighted:
|
||||
mass = mass_func(self.cells)
|
||||
tot_mass = np.sum(mass)
|
||||
df["value"] = value * mass / tot_mass
|
||||
else:
|
||||
df["value"] = value
|
||||
|
||||
df.sort_values("axis", inplace=True)
|
||||
return df.groupby("axis").mean().values[:, 0]
|
||||
|
||||
def _vol_avg(self, getter, mass_weighted=True):
|
||||
self.load_cells()
|
||||
value = getter(self.cells)
|
||||
@@ -685,6 +719,22 @@ class PostProcessor(HDF5Container):
|
||||
"/hist",
|
||||
unit=self.info["unit_pressure"],
|
||||
),
|
||||
# Profiles
|
||||
"axis": Rule(
|
||||
self,
|
||||
partial(self._get_axis),
|
||||
"Axis",
|
||||
"/profile",
|
||||
unit=self.info["unit_length"],
|
||||
),
|
||||
"rho_prof": Rule(
|
||||
self,
|
||||
partial(self._plane_avg_uniform, partial(simple_getter, "rho")),
|
||||
"Rho profile",
|
||||
"/profile",
|
||||
unit=self.info["unit_density"],
|
||||
dependencies=["axis"],
|
||||
),
|
||||
# globals
|
||||
"time_num": Rule(
|
||||
self,
|
||||
|
||||
+1547
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user