Add rules to compute $\alpha$
This commit is contained in:
+234
-66
@@ -78,6 +78,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"coldens0": "$\Sigma_0$",
|
||||
"sfr_avg_window": "window",
|
||||
"bx_bound": "$B_0$",
|
||||
"levelmax": "$l_{\max}$",
|
||||
"levelmin": "$l_{\min}$",
|
||||
"comp_frac": "$1 - \\zeta$",
|
||||
}
|
||||
|
||||
# Conversion table from namelist values (from amses config file) into LaTex strings
|
||||
@@ -96,7 +99,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
pp_params=None,
|
||||
selector=None,
|
||||
tag=None,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
|
||||
"""
|
||||
@@ -147,7 +150,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
Check if the dependency belongs to the plotter object or to another one (comp, pp, ..)
|
||||
"""
|
||||
if dep in self.comp.rules:
|
||||
done = self.comp.process(dep, dep_arg, overwrite, overwrite)
|
||||
done = self.comp.process(
|
||||
dep, dep_arg, overwrite, overwrite_dep=self.overwrite_dep
|
||||
)
|
||||
self.just_done.extend(done)
|
||||
else:
|
||||
super(Plotter, self)._not_self_dep(name, dep, dep_arg, overwrite, **kwargs)
|
||||
@@ -171,10 +176,10 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
ax=None,
|
||||
movie=False,
|
||||
from_cells=False,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Generic method to process a rule, with its dependencies
|
||||
Open storage and figure if needed before processing a rule
|
||||
"""
|
||||
if not arg is None:
|
||||
name_full = name + "_" + str(arg)
|
||||
@@ -217,7 +222,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
overwrite,
|
||||
ax=ax[i],
|
||||
run=run,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
except TypeError as e:
|
||||
if str(e) in [
|
||||
@@ -234,7 +239,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
overwrite,
|
||||
ax=ax,
|
||||
run=run,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
elif ax is None:
|
||||
fig = P.figure()
|
||||
@@ -246,7 +251,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
overwrite,
|
||||
ax=P.gca(),
|
||||
run=run,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
else:
|
||||
raise
|
||||
@@ -414,7 +419,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
norm="log",
|
||||
put_cbar=True,
|
||||
autoscale=True,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Plot data on a map
|
||||
@@ -477,39 +482,81 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
P.title(title)
|
||||
|
||||
for i, plot_overlay in enumerate(overlays):
|
||||
try:
|
||||
plot_overlay(ax_los, **overlays_kwargs[i])
|
||||
except:
|
||||
plot_overlay(ax_los)
|
||||
if plot_overlay in self.overlays:
|
||||
plot_overlay = self.overlays[plot_overlay]
|
||||
|
||||
def _overlay_levels(self, ax_los):
|
||||
try:
|
||||
plot_overlay(ax_los, im_extent, **overlays_kwargs[i])
|
||||
except:
|
||||
plot_overlay(ax_los, im_extent)
|
||||
|
||||
def _overlay_contour(
|
||||
self,
|
||||
ax_los,
|
||||
im_extent,
|
||||
map_name,
|
||||
log=False,
|
||||
lvl_array=None,
|
||||
lw=None,
|
||||
lvl_th=None,
|
||||
lvl_max_lbl=np.inf,
|
||||
lbl_fmt="%g",
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Add an overlay : contour of other map
|
||||
"""
|
||||
map_contour = self.save.get_node("/maps/{}_{}".format(map_name, ax_los)).read()
|
||||
if log:
|
||||
map_contour = np.log10(map_contour)
|
||||
# Computing linewidths
|
||||
mask_fin = np.isfinite(map_contour)
|
||||
if lvl_array is None:
|
||||
lvl_array = np.arange(
|
||||
np.min(map_contour[mask_fin]), np.max(map_contour[mask_fin]) + 1
|
||||
)
|
||||
|
||||
if lw is None:
|
||||
lw = np.ones(lvl_array.size) * 2
|
||||
if lvl_th:
|
||||
lw[lvl_array >= lvl_th] = lw[lvl_array >= lvl_th] ** (
|
||||
lvl_th - lvl_array[lvl_array >= lvl_th]
|
||||
)
|
||||
lw[lvl_array < lvl_th] = 1.0
|
||||
|
||||
cont = P.contour(
|
||||
map_contour,
|
||||
extent=im_extent,
|
||||
origin="lower",
|
||||
linewidths=lw,
|
||||
levels=lvl_array,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
P.clabel(
|
||||
cont,
|
||||
lvl_array[lvl_array < lvl_max_lbl],
|
||||
inline=1,
|
||||
fontsize=8.0,
|
||||
fmt=lbl_fmt,
|
||||
)
|
||||
|
||||
def _overlay_levels(self, ax_los, im_extent, **kwargs):
|
||||
"""
|
||||
Add an overlay : AMR levels
|
||||
"""
|
||||
map_level = self.save.get_node("/maps/{}_{}".format("levels", ax_los)).read()
|
||||
# Computing linewidths
|
||||
levels_ar = np.arange(np.min(map_level), np.max(map_level) + 1)
|
||||
lw = np.ones(levels_ar.size) * 2
|
||||
lvl_th = 8 # Level threeshold for reducing linewidths
|
||||
lw[levels_ar >= lvl_th] = lw[levels_ar >= lvl_th] ** (
|
||||
lvl_th - levels_ar[levels_ar >= lvl_th]
|
||||
return self._overlay_contour(
|
||||
ax_los,
|
||||
im_extent,
|
||||
"levels",
|
||||
lbl_fmt="%1d",
|
||||
lvl_th=8,
|
||||
lvl_max_lbl=11,
|
||||
**kwargs,
|
||||
)
|
||||
lw[levels_ar < lvl_th] = 1.0
|
||||
|
||||
cont = P.contour(
|
||||
map_level,
|
||||
extent=self.save.root.maps._v_attrs.im_extent,
|
||||
origin="lower",
|
||||
colors="grey",
|
||||
linewidths=lw,
|
||||
levels=levels_ar,
|
||||
)
|
||||
cont.levels = cont.levels + 1
|
||||
|
||||
P.clabel(cont, cont.levels[cont.levels < 11], inline=1, fontsize=8.0, fmt="%1d")
|
||||
|
||||
def _overlay_speed(
|
||||
self, ax_los, unit=cst.km_s, unit_coeff=1.0, key_v=None, **kwargs
|
||||
self, ax_los, im_extent, unit=cst.km_s, unit_coeff=1.0, key_v=None, **kwargs
|
||||
):
|
||||
"""
|
||||
Add an overlay : velocity vector field
|
||||
@@ -532,6 +579,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
) # take only a subset of velocities
|
||||
map_vv_red = dmap_vv[::vel_red, ::vel_red] * unit_old.express(unit)
|
||||
|
||||
# TODO : redo this with im_extent
|
||||
|
||||
nh = map_vh_red.shape[0]
|
||||
nv = map_vv_red.shape[1]
|
||||
vec_h = (
|
||||
@@ -559,7 +608,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
coordinates="figure",
|
||||
)
|
||||
|
||||
def _overlay_B(self, ax_los, **kwargs):
|
||||
def _overlay_B(self, ax_los, im_extent, **kwargs):
|
||||
"""
|
||||
Add an overlay : magnetic streamlines
|
||||
"""
|
||||
@@ -569,6 +618,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dmap_Bh = dmap_Bh_node.read()
|
||||
dmap_Bv = self.save.get_node("/maps/B_v_{}".format(ax_los)).read()
|
||||
|
||||
# TODO : redo this with im_extent
|
||||
|
||||
vel_red = self.pp_params.plot.vel_red
|
||||
radius = self.save.root.maps._v_attrs.radius
|
||||
center = self.save.root.maps._v_attrs.center
|
||||
@@ -590,14 +641,33 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
P.streamplot(hh, vv, map_Bh_red, map_Bv_red)
|
||||
|
||||
def _plot_radial(self, name, ax_los, label=None, xlog=False, ylog=False):
|
||||
def _plot_radial(
|
||||
self,
|
||||
name,
|
||||
ax_los,
|
||||
run,
|
||||
ylabel=None,
|
||||
xlog=False,
|
||||
ylog=False,
|
||||
ytransform=None,
|
||||
title=None,
|
||||
nml_key=None,
|
||||
put_title=True,
|
||||
put_time=True,
|
||||
time_unit=cst.Myr,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Plot a radial profile (for disks, OUTDATED)
|
||||
"""
|
||||
|
||||
radial_bins = self.save.get_node("/radial/radial_bins_" + ax_los).read()
|
||||
bin_centers = 0.5 * (radial_bins[1:] + radial_bins[:-1])
|
||||
mean_bin = self.save.get_node("/radial/{}_{}".format(name, ax_los)).read()
|
||||
node = self.save.get_node("/radial/{}_{}".format(name, ax_los))
|
||||
mean_bin = node.read()
|
||||
|
||||
if ytransform is not None:
|
||||
mean_bin = ytransform(mean_bin)
|
||||
|
||||
P.grid()
|
||||
P.xlabel(r"$r$")
|
||||
@@ -606,20 +676,37 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
P.xscale("log")
|
||||
if ylog:
|
||||
P.yscale("log")
|
||||
P.plot(bin_centers, mean_bin)
|
||||
P.plot(bin_centers, mean_bin, **kwargs)
|
||||
|
||||
if not label is None:
|
||||
P.ylabel(label)
|
||||
if not ylabel is None:
|
||||
P.ylabel(ylabel)
|
||||
|
||||
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
|
||||
|
||||
P.title(title)
|
||||
|
||||
def _plot_hist(
|
||||
self,
|
||||
name,
|
||||
ax_los,
|
||||
run,
|
||||
ax_los=None,
|
||||
run=None,
|
||||
group="/hist/",
|
||||
label=None,
|
||||
xlabel=None,
|
||||
unit=None,
|
||||
unit_coeff=1.0,
|
||||
ytransform=None,
|
||||
label=None,
|
||||
title=None,
|
||||
nml_key=None,
|
||||
put_time=True,
|
||||
@@ -633,7 +720,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
nml_color=None,
|
||||
fit=None,
|
||||
fitlabel=None,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Plot an histogram (PDF, etc ...)
|
||||
@@ -649,7 +736,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
except:
|
||||
xlog = False
|
||||
|
||||
label, unit_old, unit = self._ax_label_unit(node, label, unit, unit_coeff)
|
||||
xlabel, unit_old, unit = self._ax_label_unit(node, label, unit, unit_coeff)
|
||||
|
||||
if "mean" in node:
|
||||
index = node["runs"].read().index(run)
|
||||
@@ -662,6 +749,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
else:
|
||||
centers = centers * unit_old.express(unit)
|
||||
|
||||
if ytransform is not None:
|
||||
values = ytransform(values)
|
||||
|
||||
title = self._label_run(run, node, title, nml_key)
|
||||
|
||||
if put_time:
|
||||
@@ -686,19 +776,22 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
except:
|
||||
color = colors(nml)
|
||||
|
||||
if label == None:
|
||||
label = title
|
||||
|
||||
if kind == "bar":
|
||||
width = centers[1] - centers[0]
|
||||
P.bar(centers, values, width, log=ylog, color=color, label=title, **kwargs)
|
||||
P.bar(centers, values, width, log=ylog, color=color, label=label, **kwargs)
|
||||
elif kind == "step":
|
||||
if ylog:
|
||||
P.yscale("log")
|
||||
P.step(centers, values, where="mid", color=color, label=title, **kwargs)
|
||||
P.step(centers, values, where="mid", color=color, label=label, **kwargs)
|
||||
else:
|
||||
raise ValueError("kind must be 'bar' or 'step'")
|
||||
P.grid()
|
||||
|
||||
if not label is None:
|
||||
P.xlabel(label)
|
||||
P.xlabel(xlabel)
|
||||
if not ylabel is None:
|
||||
P.ylabel(ylabel)
|
||||
|
||||
@@ -749,7 +842,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
legend=None,
|
||||
subname_x=None,
|
||||
subname_y=None,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Generic plot routine, with name_x and name_y two path in the hdf5 file
|
||||
@@ -991,7 +1084,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
def def_rules(self):
|
||||
"""
|
||||
That is where rules are defined
|
||||
This is where rules are defined
|
||||
"""
|
||||
self.rules = {
|
||||
# Generic rules
|
||||
@@ -1000,13 +1093,69 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
),
|
||||
"coldens": PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "coldens", label=r"$\Sigma$", unit=cst.coldens),
|
||||
partial(
|
||||
self._plot_map,
|
||||
"coldens",
|
||||
label=r"$\Sigma$",
|
||||
# unit=cst.coldens
|
||||
),
|
||||
"Column density map",
|
||||
dependencies=["coldens", "speed_h", "speed_v"],
|
||||
dependencies=["coldens"],
|
||||
),
|
||||
"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"],
|
||||
),
|
||||
"vphi": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"vphi",
|
||||
label=r"$v_\phi$",
|
||||
# unit=cst.km_s
|
||||
),
|
||||
"Azimuthal speed",
|
||||
dependencies=["vphi"],
|
||||
),
|
||||
"vr": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"vr",
|
||||
label=r"$v_r$",
|
||||
# unit=cst.km_s
|
||||
),
|
||||
"Radial speed",
|
||||
dependencies=["vr"],
|
||||
),
|
||||
"P_avg": PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "P_avg", label=r"$P$"),
|
||||
"Pressure (average)",
|
||||
dependencies=["P_avg"],
|
||||
),
|
||||
"rho_avg": PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "rho_avg", label=r"$\rho$"),
|
||||
"Density (average)",
|
||||
dependencies=["rho_avg"],
|
||||
),
|
||||
"rho": PlotRule(
|
||||
self,
|
||||
partial(self._plot_map, "rho", label=r"$\rho$", unit=cst.Msun_pc3),
|
||||
partial(
|
||||
self._plot_map,
|
||||
"rho",
|
||||
label=r"$\rho$",
|
||||
# unit=cst.Msun_pc3
|
||||
),
|
||||
"Density slice at s = 0, with s = x, y or z.",
|
||||
dependencies=["rho"],
|
||||
),
|
||||
@@ -1058,18 +1207,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"Density slice with magnetic field and velocity overlay",
|
||||
dependencies=["rho", "B_h", "B_v", "speed_h", "speed_v"],
|
||||
),
|
||||
"B_int_B_vel": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map,
|
||||
"B_int",
|
||||
label="B",
|
||||
unit=cst.T,
|
||||
overlays=[self._overlay_B, self._overlay_speed],
|
||||
),
|
||||
"Magnetic slice with magnetic field and velocity overlay",
|
||||
dependencies=["B_int", "B_h", "B_v", "speed_h", "speed_v"],
|
||||
),
|
||||
"jeans_ratio": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
@@ -1303,7 +1440,19 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
),
|
||||
}
|
||||
|
||||
averageables = ["coldens", "rho", "T", "Q"]
|
||||
averageables = [
|
||||
"coldens",
|
||||
"rho",
|
||||
"T",
|
||||
"Q",
|
||||
"vr",
|
||||
"vphi",
|
||||
"rho_avg",
|
||||
"P_avg",
|
||||
"T_avg",
|
||||
"alpha_disk",
|
||||
"alpha_grav",
|
||||
]
|
||||
for name in averageables:
|
||||
self.rules["rad_" + name] = PlotRule(
|
||||
self,
|
||||
@@ -1331,6 +1480,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"Fluctuation of {}".format(name),
|
||||
dependencies=["fluct_" + name],
|
||||
)
|
||||
|
||||
self.rules["pdf_" + name] = PlotRule(
|
||||
self,
|
||||
partial(
|
||||
@@ -1343,4 +1493,22 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dependencies=["fit_pdf_" + name],
|
||||
)
|
||||
|
||||
for name_bin in averageables:
|
||||
if name_bin is not name:
|
||||
group = "mbb_{}_{}".format(name, name_bin)
|
||||
self.rules["mbb_" + name + "_" + name_bin] = PlotRule(
|
||||
self,
|
||||
partial(self._plot_hist, group, ylabel=r"$\alpha$"),
|
||||
"Mean of {} by bins of {}".format(name, name_bin),
|
||||
dependencies=[group],
|
||||
)
|
||||
|
||||
# Dict of overlays
|
||||
self.overlays = {
|
||||
"B": self._overlay_B,
|
||||
"speed": self._overlay_speed,
|
||||
"levels": self._overlay_levels,
|
||||
"contour": self._overlay_contour,
|
||||
}
|
||||
|
||||
super(Plotter, self).def_rules()
|
||||
|
||||
Reference in New Issue
Block a user