less verbose
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
from scipy.integrate import solve_ivp
|
from scipy.integrate import solve_ivp
|
||||||
from plotter import U
|
from plotter import U
|
||||||
import select_runs
|
import select_snapshot
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -280,6 +280,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
self.def_rules()
|
self.def_rules()
|
||||||
|
|
||||||
# Generate astrophysix's simulations object
|
# Generate astrophysix's simulations object
|
||||||
|
if self.params.astrophysix.generate:
|
||||||
self.gen_simus()
|
self.gen_simus()
|
||||||
|
|
||||||
# Initialize pointers
|
# Initialize pointers
|
||||||
@@ -456,17 +457,18 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
run=run,
|
run=run,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save in astrophysix format
|
|
||||||
df = rule.datafile(name, arg)
|
|
||||||
df[filetype] = plot_filename
|
|
||||||
if movie:
|
if movie:
|
||||||
filenames[run].append(plot_filename)
|
filenames[run].append(plot_filename)
|
||||||
|
|
||||||
|
# Save in astrophysix format
|
||||||
|
if self.params.astrophysix.generate:
|
||||||
|
df = rule.datafile(name, arg)
|
||||||
|
df[filetype] = plot_filename
|
||||||
|
|
||||||
if plot_info is not None:
|
if plot_info is not None:
|
||||||
df.plot_info = plot_info
|
df.plot_info = plot_info
|
||||||
if num is not None:
|
if num is not None:
|
||||||
snap = self.snaps[run][num].snapshot
|
snap = self.snaps[run][num].snapshot
|
||||||
|
|
||||||
if overwrite and df.name in snap.datafiles:
|
if overwrite and df.name in snap.datafiles:
|
||||||
del snap.datafiles[df.name]
|
del snap.datafiles[df.name]
|
||||||
elif df.name not in snap.datafiles:
|
elif df.name not in snap.datafiles:
|
||||||
@@ -474,7 +476,6 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
|
|
||||||
if snap not in self.simulations[run].snapshots:
|
if snap not in self.simulations[run].snapshots:
|
||||||
self.simulations[run].snapshots.add(snap)
|
self.simulations[run].snapshots.add(snap)
|
||||||
|
|
||||||
datafiles.append(df)
|
datafiles.append(df)
|
||||||
|
|
||||||
if movie:
|
if movie:
|
||||||
@@ -857,6 +858,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
plt.xlim(xlim)
|
plt.xlim(xlim)
|
||||||
plt.ylim(ylim)
|
plt.ylim(ylim)
|
||||||
|
|
||||||
|
if self.params.astrophysics.generate:
|
||||||
return PlotInfo(
|
return PlotInfo(
|
||||||
plot_type=PlotType.IMAGE,
|
plot_type=PlotType.IMAGE,
|
||||||
xaxis_values=np.linspace(im_extent[0], im_extent[1], dmap.shape[0] + 1),
|
xaxis_values=np.linspace(im_extent[0], im_extent[1], dmap.shape[0] + 1),
|
||||||
@@ -1201,6 +1203,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# returns PlotInfo (for Galactica)
|
# returns PlotInfo (for Galactica)
|
||||||
|
if self.params.astrophysics.generate:
|
||||||
edges = np.append(centers - width / 2.0, centers[-1] + width / 2.0)
|
edges = np.append(centers - width / 2.0, centers[-1] + width / 2.0)
|
||||||
return PlotInfo(
|
return PlotInfo(
|
||||||
plot_type=PlotType.HISTOGRAM,
|
plot_type=PlotType.HISTOGRAM,
|
||||||
@@ -1822,21 +1825,18 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
def generic_rule(name):
|
def generic_rule(name):
|
||||||
|
|
||||||
self.rules["slice_" + name] = PlotRule(
|
self.rules["slice_" + name] = PlotRule(
|
||||||
self,
|
|
||||||
partial(self._plot_map, "slice_" + name),
|
partial(self._plot_map, "slice_" + name),
|
||||||
"{} slice".format(name),
|
"{} slice".format(name),
|
||||||
dependencies=["slice_" + name],
|
dependencies=["slice_" + name],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.rules[name + "_mwavg"] = PlotRule(
|
self.rules[name + "_mwavg"] = PlotRule(
|
||||||
self,
|
|
||||||
partial(self._plot_map, name + "_mwavg"),
|
partial(self._plot_map, name + "_mwavg"),
|
||||||
"Ax mass-weighted averaged {}".format(name),
|
"Ax mass-weighted averaged {}".format(name),
|
||||||
dependencies=[name + "_mwavg"],
|
dependencies=[name + "_mwavg"],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.rules[name + "_avg"] = PlotRule(
|
self.rules[name + "_avg"] = PlotRule(
|
||||||
self,
|
|
||||||
partial(self._plot_map, name + "_avg"),
|
partial(self._plot_map, name + "_avg"),
|
||||||
"Ax averaged {}".format(name),
|
"Ax averaged {}".format(name),
|
||||||
dependencies=[name + "_avg"],
|
dependencies=[name + "_avg"],
|
||||||
|
|||||||
@@ -390,6 +390,7 @@ class SnapshotProcessor(HDF5Container):
|
|||||||
coeff=factor)
|
coeff=factor)
|
||||||
|
|
||||||
time_in_right_unit = self.time * self.info["unit_time"].express(unit_time)
|
time_in_right_unit = self.time * self.info["unit_time"].express(unit_time)
|
||||||
|
if self.params.astrophysix.generate:
|
||||||
self.snapshot = Snapshot(
|
self.snapshot = Snapshot(
|
||||||
name=str(self.num),
|
name=str(self.num),
|
||||||
description="",
|
description="",
|
||||||
@@ -488,6 +489,8 @@ class SnapshotProcessor(HDF5Container):
|
|||||||
self.open()
|
self.open()
|
||||||
if "/maps" not in self.save:
|
if "/maps" not in self.save:
|
||||||
self.save.create_group("/", "maps", "2D maps")
|
self.save.create_group("/", "maps", "2D maps")
|
||||||
|
if "/datasets" not in self.save:
|
||||||
|
self.save.create_group("/", "datasets", "Complex datasets")
|
||||||
self.save.root.maps._v_attrs.center = center
|
self.save.root.maps._v_attrs.center = center
|
||||||
self.save.root.maps._v_attrs.radius = self._radius
|
self.save.root.maps._v_attrs.radius = self._radius
|
||||||
self.save.root.maps._v_attrs.im_extent = im_extent
|
self.save.root.maps._v_attrs.im_extent = im_extent
|
||||||
|
|||||||
+57
-22
@@ -131,7 +131,7 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
super(StudyProcessor, self)._save_data(name_full, data, description, unit)
|
super(StudyProcessor, self)._save_data(name_full, data, description, unit)
|
||||||
self.save.get_node(name_full)._v_attrs.nums = self.nums
|
self.save.get_node(name_full)._v_attrs.nums = self.nums
|
||||||
|
|
||||||
def _time_series(self, getter, arg=None):
|
def time_series(self, getter, arg=None):
|
||||||
series = {}
|
series = {}
|
||||||
for run in self.runs:
|
for run in self.runs:
|
||||||
series[run] = []
|
series[run] = []
|
||||||
@@ -140,17 +140,47 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
series[run] = np.array(series[run], dtype=float)
|
series[run] = np.array(series[run], dtype=float)
|
||||||
return series
|
return series
|
||||||
|
|
||||||
def _compare(self, getter, use_num=True):
|
def compare(self, getter, use_num=True, select=None):
|
||||||
prop = []
|
|
||||||
for i, run in enumerate(self.runs):
|
if select is None:
|
||||||
|
runs = self.runs
|
||||||
|
else:
|
||||||
|
runs, _ = self.selector.select(**select)
|
||||||
|
|
||||||
|
prop = {}
|
||||||
|
for i, run in enumerate(runs):
|
||||||
if use_num:
|
if use_num:
|
||||||
num = self.nums[run][0]
|
num = self.nums[run][0]
|
||||||
prop.append(getter(run, num))
|
prop[run] = getter(run, num)
|
||||||
else:
|
else:
|
||||||
prop.append(getter(run))
|
prop[run] = getter(run)
|
||||||
return np.array(prop)
|
return np.array(list(prop.keys()))
|
||||||
|
|
||||||
def _time_avg(self, name, start=None, end=None, span=None, group="/series"):
|
def time_avg(self, name, start=None, end=None, span=None, unit_time=U.Myr, group="/series", select=None):
|
||||||
|
"""Do the time average and quantiles of a time series
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
name : str
|
||||||
|
name of the array to average
|
||||||
|
start : float, optional
|
||||||
|
The average is taken between start and end or start + span, by default None
|
||||||
|
end : float, optional
|
||||||
|
The average is taken between start and end or end - span, by default None
|
||||||
|
span : _type_, optional
|
||||||
|
length of the averaging period (overrrided if both start and end are set), by default None
|
||||||
|
unit_time : _type_, optional
|
||||||
|
Time unit to use, by default U.Myr
|
||||||
|
group : str, optional
|
||||||
|
group of the data to average, by default "/series"
|
||||||
|
select : dict, optional
|
||||||
|
arguments to selector, by default None
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
time average and quantiles
|
||||||
|
"""
|
||||||
serie0 = self.save.get_node(group + "/" + name + "/" + self.runs[0]).read()
|
serie0 = self.save.get_node(group + "/" + name + "/" + self.runs[0]).read()
|
||||||
if len(serie0.shape) > 1:
|
if len(serie0.shape) > 1:
|
||||||
shape = [len(self.runs)] + list(serie0.shape[1:])
|
shape = [len(self.runs)] + list(serie0.shape[1:])
|
||||||
@@ -166,11 +196,16 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
q16 = np.zeros(shape)
|
q16 = np.zeros(shape)
|
||||||
q84 = np.zeros(shape)
|
q84 = np.zeros(shape)
|
||||||
|
|
||||||
for i, run in enumerate(self.runs):
|
if select is None:
|
||||||
serie = self.save.get_node(group + "/" + name + "/" + run).read()
|
runs = self.runs
|
||||||
time = self.save.get_node(group + "/time/" + run).read()
|
else:
|
||||||
|
runs, _ = self.selector.select(**select)
|
||||||
|
|
||||||
|
for i, run in enumerate(runs):
|
||||||
|
serie = self.get_value(group + "/" + name + "/" + run)
|
||||||
|
time = self.get_value(group + "/time/" + run, unit=unit_time)
|
||||||
if len(serie.shape) <= 1:
|
if len(serie.shape) <= 1:
|
||||||
mask = abs(serie) != np.inf
|
mask = np.isfinite(serie)
|
||||||
|
|
||||||
if not ((start, end, span) == (None, None, None)):
|
if not ((start, end, span) == (None, None, None)):
|
||||||
start_r, end_r = start, end
|
start_r, end_r = start, end
|
||||||
@@ -202,7 +237,7 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
v_max[i],
|
v_max[i],
|
||||||
) = np.percentile(serie, [0, 2.5, 16, 50, 84, 97.5, 100], axis=0)
|
) = np.percentile(serie, [0, 2.5, 16, 50, 84, 97.5, 100], axis=0)
|
||||||
return {
|
return {
|
||||||
"runs": self.runs,
|
"runs": np.array(runs),
|
||||||
"mean": mean,
|
"mean": mean,
|
||||||
"std": std,
|
"std": std,
|
||||||
"median": median,
|
"median": median,
|
||||||
@@ -591,7 +626,7 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
|
|
||||||
self.rules[name] = Rule(
|
self.rules[name] = Rule(
|
||||||
partial(
|
partial(
|
||||||
self._time_series,
|
self.time_series,
|
||||||
partial(
|
partial(
|
||||||
self.get_global, glob_group + "/" + glob_name, unload_cells=True
|
self.get_global, glob_group + "/" + glob_name, unload_cells=True
|
||||||
),
|
),
|
||||||
@@ -635,9 +670,9 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
|
|
||||||
def fn(arg=None, **kwargs):
|
def fn(arg=None, **kwargs):
|
||||||
if arg is None:
|
if arg is None:
|
||||||
return self._time_avg(src_name, group=group_src, **kwargs)
|
return self.time_avg(src_name, group=group_src, **kwargs)
|
||||||
else:
|
else:
|
||||||
return self._time_avg(
|
return self.time_avg(
|
||||||
src_name + "_" + str(arg), group=group_src, **kwargs
|
src_name + "_" + str(arg), group=group_src, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -790,7 +825,7 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
# Read from outputs
|
# Read from outputs
|
||||||
"time": Rule(
|
"time": Rule(
|
||||||
partial(
|
partial(
|
||||||
self._time_series, partial(self.get_global, "/globals/time_num")
|
self.time_series, partial(self.get_global, "/globals/time_num")
|
||||||
),
|
),
|
||||||
group="/series",
|
group="/series",
|
||||||
unit="unit_time",
|
unit="unit_time",
|
||||||
@@ -798,28 +833,28 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
),
|
),
|
||||||
"time_rho_prof": Rule(
|
"time_rho_prof": Rule(
|
||||||
partial(
|
partial(
|
||||||
self._time_series, partial(self.get_snap_value, "/profile/rho_prof")
|
self.time_series, partial(self.get_snap_value, "/profile/rho_prof")
|
||||||
),
|
),
|
||||||
group="/series",
|
group="/series",
|
||||||
dependencies={"time": None, "rho_prof": "__parent__"},
|
dependencies={"time": None, "rho_prof": "__parent__"},
|
||||||
),
|
),
|
||||||
"time_coldens_pdf": Rule(
|
"time_coldens_pdf": Rule(
|
||||||
partial(
|
partial(
|
||||||
self._time_series, partial(self.get_snap_value, "/hist/pdf_coldens")
|
self.time_series, partial(self.get_snap_value, "/hist/pdf_coldens")
|
||||||
),
|
),
|
||||||
group="/series",
|
group="/series",
|
||||||
dependencies={"time": None, "pdf_coldens": "__parent__"},
|
dependencies={"time": None, "pdf_coldens": "__parent__"},
|
||||||
),
|
),
|
||||||
"time_rho_pdf": Rule(
|
"time_rho_pdf": Rule(
|
||||||
partial(
|
partial(
|
||||||
self._time_series, partial(self.get_snap_value, "/hist/rho_pdf")
|
self.time_series, partial(self.get_snap_value, "/hist/rho_pdf")
|
||||||
),
|
),
|
||||||
group="/series",
|
group="/series",
|
||||||
dependencies={"time": None},
|
dependencies={"time": None},
|
||||||
),
|
),
|
||||||
"time_pdf_slope_coldens": Rule(
|
"time_pdf_slope_coldens": Rule(
|
||||||
partial(
|
partial(
|
||||||
self._time_series,
|
self.time_series,
|
||||||
partial(
|
partial(
|
||||||
self.get_attr,
|
self.get_attr,
|
||||||
"slope",
|
"slope",
|
||||||
@@ -839,7 +874,7 @@ class StudyProcessor(Aggregator, HDF5Container):
|
|||||||
),
|
),
|
||||||
# namelist
|
# namelist
|
||||||
"nml": Rule(
|
"nml": Rule(
|
||||||
lambda nml_key: self._compare(
|
lambda nml_key: self.compare(
|
||||||
partial(self.get_nml, nml_key), use_num=False
|
partial(self.get_nml, nml_key), use_num=False
|
||||||
),
|
),
|
||||||
group="/comp",
|
group="/comp",
|
||||||
|
|||||||
Reference in New Issue
Block a user