Add possibility to launch an external rule
+ some plotter improvements + some namelist improvements + add datacube extraction
This commit is contained in:
+42
-64
@@ -155,8 +155,7 @@ def line_integral_convolution(ax, map_h, map_v, extent, **kwargs):
|
||||
|
||||
class PlotRule(Rule):
|
||||
"""
|
||||
The rule class, speficic to plot.
|
||||
Add an extra method, plot, that take the reference to an open hdf5 file (from pytables)
|
||||
The rule class, specific to plot.
|
||||
"""
|
||||
|
||||
def datafile(self, name, arg):
|
||||
@@ -197,10 +196,16 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"comp_frac": "$\chi$",
|
||||
}
|
||||
|
||||
# Conversion table from namelist values (from amses config file) into LaTex strings
|
||||
value_convert = {
|
||||
# Conversion table from namelist values (from ramses config file) into LaTex strings
|
||||
value_str = {
|
||||
"sfr_avg_window": lambda x: "${:g}$ Myr".format(80 * x),
|
||||
"Bx": lambda x: "${:g}$ $\\mu G$".format(7.6189439 * x),
|
||||
"Bx": lambda x: "${:.1f}$ $\\mu G$".format(7.6189439 * x),
|
||||
}
|
||||
|
||||
# Conversion table from namelist values (from ramses config file) into suitanle units
|
||||
value_convert = {
|
||||
"sfr_avg_window": lambda x: 80 * x, # Myr
|
||||
"Bx": lambda x: x * 7.6189439,
|
||||
}
|
||||
|
||||
def __init__(
|
||||
@@ -560,11 +565,16 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
prop_label = self.label_convert[prop_name]
|
||||
else:
|
||||
prop_label = prop_name
|
||||
prop_value = self.study.get_nml(nml_key, run)
|
||||
if prop_name in self.value_convert:
|
||||
try:
|
||||
prop_value = self.study.get_nml(nml_key, run)
|
||||
except KeyError:
|
||||
return ""
|
||||
if prop_name in self.value_str:
|
||||
prop_value_str = self.value_str[prop_name](prop_value)
|
||||
elif prop_name in self.value_convert:
|
||||
prop_value_str = self.value_convert[prop_name](prop_value)
|
||||
elif type(prop_value) in [int, float]:
|
||||
prop_value_str = convert_exp(prop_value, digits=5)
|
||||
prop_value_str = convert_exp(prop_value, digits=4)
|
||||
else:
|
||||
prop_value_str = str(prop_value)
|
||||
return r"{} = {}".format(prop_label, prop_value_str)
|
||||
@@ -584,7 +594,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
elif nml_key is not None:
|
||||
if not type(nml_key) == list:
|
||||
nml_key = [nml_key]
|
||||
label_run = ", ".join(map(get_label_nml, nml_key))
|
||||
lbl_list = map(get_label_nml, nml_key) # get namelist value
|
||||
lbl_list = filter(lambda x: len(x) > 0, lbl_list) # Remove void labels
|
||||
label_run = ", ".join(lbl_list)
|
||||
|
||||
if label is not None:
|
||||
label_run = label + " (" + label_run + ")"
|
||||
@@ -667,6 +679,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
colorbar=True,
|
||||
embeded=False,
|
||||
text_embeded=None,
|
||||
text_kwargs={},
|
||||
colorbar_embeded=None,
|
||||
axes_indicator=None,
|
||||
overtext_color="w",
|
||||
@@ -814,10 +827,11 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if text_embeded:
|
||||
ax.text(
|
||||
x=0.05,
|
||||
y=0.95,
|
||||
y=0.91,
|
||||
s=title,
|
||||
color=overtext_color,
|
||||
transform=ax.transAxes,
|
||||
**text_kwargs
|
||||
)
|
||||
else:
|
||||
plt.title(title)
|
||||
@@ -1021,7 +1035,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
c = c(data)[mask]
|
||||
|
||||
# Scatter plot
|
||||
plt.scatter(part_h, part_v, s=s, c=c, **kwargs)
|
||||
scatter = plt.scatter(part_h, part_v, s=s, c=c, **kwargs)
|
||||
|
||||
def _overlay_vector(
|
||||
self,
|
||||
@@ -1143,11 +1157,13 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
).express(unit_time)
|
||||
color = colors(time)
|
||||
else:
|
||||
nml = self.study.get_nml(nml_color, run)
|
||||
nml_value = self.study.get_nml(nml_color, run)
|
||||
if os.path.basename(nml_color) in self.value_convert:
|
||||
nml_value = self.value_convert[ os.path.basename(nml_color)](nml_value)
|
||||
try:
|
||||
color = colors[nml]
|
||||
color = colors[nml_value]
|
||||
except TypeError:
|
||||
color = colors(nml)
|
||||
color = colors(nml_value)
|
||||
|
||||
# Actual plot
|
||||
if kind == "bar":
|
||||
@@ -1209,6 +1225,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
label=None,
|
||||
xunit=None,
|
||||
yunit=None,
|
||||
put_units=True,
|
||||
xunit_coeff=1.0,
|
||||
yunit_coeff=1.0,
|
||||
xtransform=None,
|
||||
@@ -1255,10 +1272,10 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
# Find proper labels
|
||||
xlabel, xunit_old, xunit = self._ax_label_unit(
|
||||
name_x, xlabel, xunit, xunit_coeff
|
||||
name_x, xlabel, xunit, xunit_coeff, put_units=put_units,
|
||||
)
|
||||
ylabel, yunit_old, yunit = self._ax_label_unit(
|
||||
name_y, ylabel, yunit, yunit_coeff
|
||||
name_y, ylabel, yunit, yunit_coeff, put_units=put_units,
|
||||
)
|
||||
|
||||
# If relevent, get time
|
||||
@@ -1350,11 +1367,13 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
).express(unit_time)
|
||||
color = colors(time)
|
||||
else:
|
||||
nml = self.study.get_nml(nml_color, run)
|
||||
nml_value = self.study.get_nml(nml_color, run)
|
||||
if os.path.basename(nml_color) in self.value_convert:
|
||||
nml_value = self.value_convert[os.path.basename(nml_color)](nml_value)
|
||||
try:
|
||||
color = colors[nml]
|
||||
color = colors[nml_value]
|
||||
except TypeError:
|
||||
color = colors(nml)
|
||||
color = colors(nml_value)
|
||||
if yerr is None or yerr_kind is None:
|
||||
(base_line,) = plt.plot(x, y, label=label, color=color, **kwargs)
|
||||
else:
|
||||
@@ -1469,7 +1488,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
else:
|
||||
name_rule = name_y + "_" + name_x
|
||||
self.rules[name_rule] = PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/" + logrule + "/" + name_x,
|
||||
@@ -1485,20 +1503,15 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
This is where rules are defined
|
||||
"""
|
||||
self.rules = {
|
||||
"plot": PlotRule(
|
||||
self, lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="comp"
|
||||
"plot": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="comp"
|
||||
),
|
||||
"plot_run": PlotRule(
|
||||
self, lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="run"
|
||||
"plot_run": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="run"
|
||||
),
|
||||
"plot_snapshot": PlotRule(
|
||||
self, lambda arg, **kwargs: self._plot(*arg, **kwargs)
|
||||
"plot_snapshot": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs)
|
||||
),
|
||||
"plot_map": PlotRule(
|
||||
self, lambda mapname, **kwargs: self._plot_map(mapname, **kwargs)
|
||||
"plot_map": PlotRule(lambda mapname, **kwargs: self._plot_map(mapname, **kwargs)
|
||||
),
|
||||
"coldens": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"coldens",
|
||||
@@ -1509,7 +1522,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["coldens"],
|
||||
),
|
||||
"slice_T": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"T",
|
||||
@@ -1519,19 +1531,16 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["T"],
|
||||
),
|
||||
"alpha_disk": PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "alpha_disk", label=r"$\alpha$"),
|
||||
"Map of the Shakura&Sunaev alpha parameter for disks",
|
||||
dependencies=["alpha_disk"],
|
||||
),
|
||||
"alpha_grav": PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "alpha_grav", label=r"$\alpha_g$"),
|
||||
"Map of the grav Shakura&Sunaev alpha parameter for disks",
|
||||
dependencies=["alpha_grav"],
|
||||
),
|
||||
"coldens_l": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"coldens",
|
||||
@@ -1543,7 +1552,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["coldens", "levels"],
|
||||
),
|
||||
"slice_rho_v": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"slice_rho",
|
||||
@@ -1555,7 +1563,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["slice_rho"],
|
||||
),
|
||||
"jeans_ratio": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"jeans_ratio",
|
||||
@@ -1568,7 +1575,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["jeans_ratio", "levels"],
|
||||
),
|
||||
"Q": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"Q",
|
||||
@@ -1581,25 +1587,21 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["Q"],
|
||||
),
|
||||
"rho_pdf": PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, "rho_pdf"),
|
||||
"$\rho$-PDF",
|
||||
dependencies=["rho_pdf"],
|
||||
),
|
||||
"rho_pdf_mw": PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, "rho_pdf_mw"),
|
||||
"Mass weighted $\rho$-PDF",
|
||||
dependencies=["rho_pdf_mw"],
|
||||
),
|
||||
"cos_pdf": PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, "cos_pdf"),
|
||||
"cos-PDF",
|
||||
dependencies=["cos_pdf", "mwa_speed"],
|
||||
),
|
||||
"avg_coldens_pdf": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_hist,
|
||||
"avg_time_coldens_pdf_z",
|
||||
@@ -1612,19 +1614,16 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies={"avg_time_coldens_pdf": "z"},
|
||||
),
|
||||
"T_pdf": PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, "T_pdf"),
|
||||
"T-PDF on a 2D slice",
|
||||
dependencies=["T_pdf"],
|
||||
),
|
||||
"P_pdf": PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, "P_pdf"),
|
||||
"P-PDF on a 2D slice ",
|
||||
dependencies=["P_pdf"],
|
||||
),
|
||||
"Brho": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/datasets/Brho/rho",
|
||||
@@ -1636,7 +1635,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["Brho"],
|
||||
),
|
||||
"Ek_Eb_rho": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/datasets/Ek_Eb_rho/rho",
|
||||
@@ -1648,14 +1646,12 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["Ek_Eb_rho", "mwa_speed"],
|
||||
),
|
||||
"rho_prof": PlotRule(
|
||||
self,
|
||||
partial(self._plot, "/profile/axis", "/profile/rho_prof"),
|
||||
"Density profile",
|
||||
dependencies=["axis", "rho_prof"],
|
||||
),
|
||||
"pspec": PlotRule(self, self._pspec, dependencies={"pspec": None}),
|
||||
"sbeta": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/comp/nml_cloud_params/beta_cool",
|
||||
@@ -1669,7 +1665,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
},
|
||||
),
|
||||
"sbeta_onavg": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/comp/sbeta_onavg/beta",
|
||||
@@ -1681,7 +1676,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["sbeta_onavg"],
|
||||
),
|
||||
"sink_mass": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/sinks_from_log/time",
|
||||
@@ -1694,7 +1688,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["sinks_from_log"],
|
||||
),
|
||||
"ssm": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/sinks_from_log/time",
|
||||
@@ -1707,7 +1700,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["ssm"],
|
||||
),
|
||||
"assfr": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/sfr_from_log/time",
|
||||
@@ -1720,7 +1712,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["sfr_from_log"],
|
||||
),
|
||||
"issfr": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/sinks_from_log/time",
|
||||
@@ -1733,7 +1724,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["issfr"],
|
||||
),
|
||||
"turb_rms": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
@@ -1745,7 +1735,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["rms_from_log"],
|
||||
),
|
||||
"turb_energy": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
@@ -1757,7 +1746,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["rms_from_log"],
|
||||
),
|
||||
"turb_power": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
@@ -1769,7 +1757,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["turb_power"],
|
||||
),
|
||||
"sigma": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/time",
|
||||
@@ -1783,7 +1770,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["time_sigma"],
|
||||
),
|
||||
"mwa_B_int": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/time",
|
||||
@@ -1796,7 +1782,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["time_mwa_B_int"],
|
||||
),
|
||||
"mass": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/time",
|
||||
@@ -1809,7 +1794,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["time_mass"],
|
||||
),
|
||||
"max_fluct_coldens": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/series/time",
|
||||
@@ -1879,7 +1863,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
for name in averageables:
|
||||
self.rules["rad_" + name] = PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/radial/radial_centers",
|
||||
@@ -1890,7 +1873,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
|
||||
self.rules["dispersion_rad_" + name] = PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot,
|
||||
"/radial/radial_centers",
|
||||
@@ -1901,28 +1883,24 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
|
||||
self.rules["avg_map_" + name] = PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "avg_map_" + name),
|
||||
"Map of the radial average of {}".format(name),
|
||||
dependencies=["avg_map_" + name],
|
||||
)
|
||||
|
||||
self.rules["mwavg_map_" + name] = PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "mwavg_map_" + name),
|
||||
"Map of the mass weighted radial average of {}".format(name),
|
||||
dependencies=["avg_map_" + name],
|
||||
)
|
||||
|
||||
self.rules["fluct_" + name] = PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "fluct_" + name, cmap="RdBu_r"),
|
||||
"Fluctuation of {}".format(name),
|
||||
dependencies=["fluct_" + name],
|
||||
)
|
||||
|
||||
self.rules["pdf_" + name] = PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, "pdf_" + name, ylog=True),
|
||||
"Probability density function of {} fluctuations".format(name),
|
||||
dependencies=["pdf_" + name],
|
||||
|
||||
Reference in New Issue
Block a user