[refactoring] removed star imports, renamed cst in U
and applied flake8 guidelines
This commit is contained in:
+142
-126
@@ -9,9 +9,7 @@ This is the plotter module.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
import matplotlib as mpl
|
||||
import numpy as np
|
||||
import tables
|
||||
@@ -27,10 +25,24 @@ if os.environ.get("DISPLAY", "") == "":
|
||||
mpl.use("Agg")
|
||||
import datetime
|
||||
|
||||
import pylab as P
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import pspec_read
|
||||
from comparator import *
|
||||
from baseprocessor import Rule, BaseProcessor
|
||||
from aggregator import Aggregator
|
||||
from comparator import Comparator
|
||||
from run_selector import RunSelector
|
||||
from units import U, unit_str, convert_exp
|
||||
|
||||
|
||||
from astrophysix.simdm.results import GenericResult
|
||||
from astrophysix.simdm.experiment import (
|
||||
ParameterSetting,
|
||||
ParameterVisibility,
|
||||
Simulation,
|
||||
)
|
||||
from ramses_astrophysix import ramses
|
||||
|
||||
|
||||
filetype_from_ext = {ext: ft for ft in FileType for ext in ft.extension_list}
|
||||
|
||||
@@ -88,19 +100,18 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"beta": "$\\beta$",
|
||||
"beta_cool": "$\\beta$",
|
||||
"dens0": "$n_0$",
|
||||
"coldens0": "$\Sigma_0$",
|
||||
"coldens0": "$\\Sigma_0$",
|
||||
"sfr_avg_window": "window",
|
||||
"bx_bound": "$B_0$",
|
||||
"levelmax": "$l_{\max}$",
|
||||
"levelmin": "$l_{\min}$",
|
||||
"levelmax": "$l_{\\max}$",
|
||||
"levelmin": "$l_{\\min}$",
|
||||
"comp_frac": "$1 - \\zeta$",
|
||||
}
|
||||
|
||||
# Conversion table from namelist values (from amses config file) into LaTex strings
|
||||
value_convert = {
|
||||
"sfr_avg_window": lambda x: "${:g}$ Myr".format(80 * x),
|
||||
#'comp_frac' : lambda x: "${:g}$".format(1 - x),
|
||||
"bx_bound": lambda x: "${:g}$ $\mu G$".format(5.267501272979475 * x),
|
||||
"bx_bound": lambda x: "${:g}$ $\\mu G$".format(5.267501272979475 * x),
|
||||
}
|
||||
|
||||
def __init__(
|
||||
@@ -112,7 +123,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
pp_params=None,
|
||||
selector=None,
|
||||
tag=None,
|
||||
unit_time=cst.year,
|
||||
unit_time=U.year,
|
||||
**kwargs,
|
||||
):
|
||||
|
||||
@@ -124,10 +135,12 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
path : path to the main folder of the simulations (ex '~/simus/myproject')
|
||||
in_runs : list of the runs to consider (ex ['run1', 'run2'])
|
||||
in_nums : list or dict of the outputs numbers to consider (ex [3, 5] or {'run1' : [3, 5], 'run2' : [4, 6])
|
||||
in_nums : list or dict of the outputs numbers to consider (ex [3, 5]
|
||||
or {'run1' : [3, 5], 'run2' : [4, 6])
|
||||
path_out : Path where the plot will be saved. By default set to `path`
|
||||
pp_params : Parameters for postprocessing. See pp_params module.
|
||||
selector : Existing instance of RunSelector, that selects runs and outputs. If set, in_runs and in_nums will be ignored
|
||||
selector : Existing instance of RunSelector, that selects runs and outputs. If set, in_runs and
|
||||
in_nums will be ignored
|
||||
tag : string to add in the output and data files.
|
||||
kwargs : Keyword arguments for RunSelector.
|
||||
"""
|
||||
@@ -216,7 +229,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
dep, dep_arg, overwrite, overwrite_dep=self.overwrite_dep
|
||||
)
|
||||
if result is not None:
|
||||
self.just_done.append(done)
|
||||
self.just_done.append(result)
|
||||
else:
|
||||
super(Plotter, self)._not_self_dep(name, dep, dep_arg, overwrite, **kwargs)
|
||||
|
||||
@@ -238,7 +251,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"""
|
||||
|
||||
# Set full name according to argument
|
||||
if not arg is None:
|
||||
if arg is not None:
|
||||
name_full = (
|
||||
name
|
||||
+ "_"
|
||||
@@ -286,7 +299,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
real_ax = ax[i]
|
||||
except TypeError as e:
|
||||
if ax is None:
|
||||
fig, real_ax = P.subplots(1, 1)
|
||||
fig, real_ax = plt.subplots(1, 1)
|
||||
elif not_array_error(e):
|
||||
real_ax = ax
|
||||
else:
|
||||
@@ -341,15 +354,15 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"""
|
||||
Once all dependencies are met, actually process the rule
|
||||
"""
|
||||
P.sca(ax)
|
||||
plt.sca(ax)
|
||||
if self._needs_computation(overwrite, plot_filename):
|
||||
plot_info = rule.plot(save, arg, **kwargs)
|
||||
|
||||
if not self.pp_params.out.interactive:
|
||||
P.tight_layout(pad=1)
|
||||
plt.tight_layout(pad=1)
|
||||
|
||||
if self.pp_params.out.save:
|
||||
P.savefig(plot_filename)
|
||||
plt.savefig(plot_filename)
|
||||
self._log("{} plotted".format(plot_filename), "SUCCESS")
|
||||
else:
|
||||
self._log(
|
||||
@@ -357,7 +370,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
|
||||
if not self.pp_params.out.interactive:
|
||||
P.close()
|
||||
plt.close()
|
||||
return plot_info
|
||||
else:
|
||||
self._log("Plot {} is already done, skipping...".format(plot_filename))
|
||||
@@ -372,9 +385,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if not self.pp_params.out.tag == "":
|
||||
tag_name = "_" + tag_name
|
||||
|
||||
if not run is None and not num is None:
|
||||
if run is not None and num is not None:
|
||||
fmt = "{out}/{run}/{name}{tag}_{run}_{num:05}{ext}"
|
||||
elif not run is None:
|
||||
elif run is not None:
|
||||
fmt = "{out}/{run}/{name}{tag}_{run}{ext}"
|
||||
else:
|
||||
fmt = "{out}/{name}{tag}{ext}"
|
||||
@@ -382,7 +395,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
fmt = self.pp_params.out.fmt
|
||||
|
||||
nml = None
|
||||
if not run is None:
|
||||
if run is not None:
|
||||
nml = self.comp.namelist[run]
|
||||
|
||||
return fmt.format(
|
||||
@@ -423,12 +436,12 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
label_run = r"{}".format(self.save.root._v_attrs.attrs[run].label)
|
||||
else:
|
||||
label_run = run
|
||||
elif not nml_key is None:
|
||||
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))
|
||||
|
||||
if not label is None:
|
||||
if label is not None:
|
||||
label_run = label + " (" + label_run + ")"
|
||||
else:
|
||||
label_run = label
|
||||
@@ -451,7 +464,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if "unit" in node._v_attrs:
|
||||
unit_old = node._v_attrs.unit
|
||||
else:
|
||||
unit_old = cst.none
|
||||
unit_old = U.none
|
||||
|
||||
if unit is None:
|
||||
unit = unit_old
|
||||
@@ -466,7 +479,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
return label, unit_old, unit
|
||||
|
||||
def _snapshot_title(self, run, node, title, nml_key, put_time, unit_time=cst.Myr):
|
||||
def _snapshot_title(self, run, node, title, nml_key, put_time, unit_time=U.Myr):
|
||||
title = self._label_run(run, node, title, nml_key)
|
||||
|
||||
if put_time:
|
||||
@@ -497,9 +510,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
put_title=True,
|
||||
nml_key=None,
|
||||
put_time=True,
|
||||
unit_time=cst.Myr,
|
||||
unit_time=U.Myr,
|
||||
put_units=True,
|
||||
unit_space=cst.pc,
|
||||
unit_space=U.pc,
|
||||
cmap="plasma",
|
||||
norm="log",
|
||||
put_cbar=True,
|
||||
@@ -535,14 +548,14 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
elif norm == "linear":
|
||||
norm = mpl.colors.NoNorm()
|
||||
|
||||
if autoscale and not norm is None:
|
||||
if autoscale and norm is not None:
|
||||
norm.autoscale(dmap)
|
||||
|
||||
im = P.imshow(
|
||||
im = plt.imshow(
|
||||
dmap, extent=im_extent, origin="lower", norm=norm, cmap=cmap, **kwargs
|
||||
)
|
||||
|
||||
P.locator_params(axis="both", nbins=self.pp_params.plot.ntick)
|
||||
plt.locator_params(axis="both", nbins=self.pp_params.plot.ntick)
|
||||
|
||||
if xlabel is None:
|
||||
xlabel = self._ax_title[ax_h]
|
||||
@@ -551,19 +564,19 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if put_units:
|
||||
xlabel = xlabel + unit_str(unit_space)
|
||||
ylabel = ylabel + unit_str(unit_space)
|
||||
P.xlabel(xlabel)
|
||||
P.ylabel(ylabel)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel(ylabel)
|
||||
|
||||
try:
|
||||
cbar = P.colorbar(im, cax=P.gca().cax)
|
||||
cbar = plt.colorbar(im, cax=plt.gca().cax)
|
||||
except AttributeError:
|
||||
cbar = P.colorbar()
|
||||
cbar = plt.colorbar()
|
||||
|
||||
if put_title:
|
||||
title = self._snapshot_title(run, node, title, nml_key, put_time, unit_time)
|
||||
P.title(title)
|
||||
plt.title(title)
|
||||
|
||||
if not label is None:
|
||||
if label is not None:
|
||||
cbar.set_label(label)
|
||||
|
||||
for i, plot_overlay in enumerate(overlays):
|
||||
@@ -627,7 +640,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
lw[lvl_array < lvl_th] = 1.0
|
||||
|
||||
cont = P.contour(
|
||||
cont = plt.contour(
|
||||
map_contour,
|
||||
extent=im_extent,
|
||||
origin="lower",
|
||||
@@ -639,7 +652,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
lvls = np.array(cont.levels) + lvl_offset
|
||||
cont.levels = lvls
|
||||
|
||||
P.clabel(
|
||||
plt.clabel(
|
||||
cont,
|
||||
lvls[np.array(lvls) < lvl_max_lbl],
|
||||
inline=1,
|
||||
@@ -663,13 +676,11 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
|
||||
def _overlay_speed(
|
||||
self, ax_los, im_extent, unit=cst.km_s, unit_coeff=1.0, key_v=None, **kwargs
|
||||
self, ax_los, im_extent, unit=U.km_s, unit_coeff=1.0, key_v=None, **kwargs
|
||||
):
|
||||
"""
|
||||
Add an overlay : velocity vector field
|
||||
"""
|
||||
ax_h = self._axes_h[ax_los]
|
||||
ax_v = self._axes_v[ax_los]
|
||||
dmap_vh_node = self.save.get_node("/maps/speed_h_{}".format(ax_los))
|
||||
dmap_vh = dmap_vh_node.read()
|
||||
dmap_vv = self.save.get_node("/maps/speed_v_{}".format(ax_los)).read()
|
||||
@@ -701,11 +712,11 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
max_v = np.max(norm_v)
|
||||
min_v = np.min(norm_v)
|
||||
|
||||
Q = P.quiver(hh, vv, map_vh_red, map_vv_red, units="width", **kwargs)
|
||||
Q = plt.quiver(hh, vv, map_vh_red, map_vv_red, units="width", **kwargs)
|
||||
|
||||
if key_v is None:
|
||||
key_v = (max_v + min_v) / 2.0
|
||||
P.quiverkey(
|
||||
plt.quiverkey(
|
||||
Q,
|
||||
0.6,
|
||||
0.98,
|
||||
@@ -719,8 +730,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"""
|
||||
Add an overlay : magnetic streamlines
|
||||
"""
|
||||
ax_h = self._axes_h[ax_los]
|
||||
ax_v = self._axes_v[ax_los]
|
||||
dmap_Bh_node = self.save.get_node("/maps/B_h_{}".format(ax_los))
|
||||
dmap_Bh = dmap_Bh_node.read()
|
||||
dmap_Bv = self.save.get_node("/maps/B_v_{}".format(ax_los)).read()
|
||||
@@ -744,7 +753,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
) * lbox
|
||||
hh, vv = np.meshgrid(vec_h, vec_v)
|
||||
|
||||
P.streamplot(hh, vv, map_Bh_red, map_Bv_red, **kwargs)
|
||||
plt.streamplot(hh, vv, map_Bh_red, map_Bv_red, **kwargs)
|
||||
|
||||
def _plot_radial(
|
||||
self,
|
||||
@@ -760,7 +769,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
nml_key=None,
|
||||
put_title=True,
|
||||
put_time=True,
|
||||
unit_time=cst.Myr,
|
||||
unit_time=U.Myr,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
@@ -775,23 +784,23 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if ytransform is not None:
|
||||
mean_bin = ytransform(mean_bin)
|
||||
|
||||
P.xlabel(r"$r$")
|
||||
plt.xlabel(r"$r$")
|
||||
|
||||
if xlog:
|
||||
P.xscale("log")
|
||||
plt.xscale("log")
|
||||
if ylog:
|
||||
P.yscale("log")
|
||||
plt.yscale("log")
|
||||
|
||||
if not ylabel is None:
|
||||
P.ylabel(ylabel)
|
||||
if ylabel is not None:
|
||||
plt.ylabel(ylabel)
|
||||
|
||||
title = self._snapshot_title(run, node, title, nml_key, put_time, unit_time)
|
||||
if put_title:
|
||||
P.title(title)
|
||||
if label == None:
|
||||
plt.title(title)
|
||||
if label is None:
|
||||
label = title
|
||||
|
||||
P.plot(bin_centers, mean_bin, label=label, **kwargs)
|
||||
plt.plot(bin_centers, mean_bin, label=label, **kwargs)
|
||||
|
||||
def _plot_hist(
|
||||
self,
|
||||
@@ -808,11 +817,11 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
title=None,
|
||||
nml_key=None,
|
||||
put_time=True,
|
||||
unit_time=cst.Myr,
|
||||
unit_time=U.Myr,
|
||||
xlog=None,
|
||||
ylog=False,
|
||||
kind="bar",
|
||||
ylabel="$\mathcal{P}$",
|
||||
ylabel="$\\mathcal{P}$",
|
||||
color=None,
|
||||
colors=None,
|
||||
nml_color=None,
|
||||
@@ -824,7 +833,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
Plot an histogram (PDF, etc ...)
|
||||
"""
|
||||
# Get node
|
||||
if not ax_los is None:
|
||||
if ax_los is not None:
|
||||
name = name + "_" + ax_los
|
||||
node = self.save.get_node(group + name)
|
||||
if xlog is None:
|
||||
@@ -853,12 +862,12 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
# Set title
|
||||
title = self._snapshot_title(run, node, title, nml_key, put_time, unit_time)
|
||||
if put_title:
|
||||
P.title(title)
|
||||
if label == None:
|
||||
plt.title(title)
|
||||
if label is None:
|
||||
label = title
|
||||
|
||||
# Set colors
|
||||
if color is None and not colors is None:
|
||||
if color is None and colors is not None:
|
||||
if nml_color is None:
|
||||
color = colors[run]
|
||||
else:
|
||||
@@ -870,25 +879,27 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
# Actual plot
|
||||
if kind == "bar":
|
||||
P.bar(centers, values, width, log=ylog, color=color, label=label, **kwargs)
|
||||
plt.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=label, **kwargs)
|
||||
plt.yscale("log")
|
||||
plt.step(centers, values, where="mid", color=color, label=label, **kwargs)
|
||||
else:
|
||||
raise ValueError("kind must be 'bar' or 'step'")
|
||||
|
||||
# put labels
|
||||
if not label is None:
|
||||
P.xlabel(xlabel)
|
||||
if not ylabel is None:
|
||||
P.ylabel(ylabel)
|
||||
if label is not None:
|
||||
plt.xlabel(xlabel)
|
||||
if ylabel is not None:
|
||||
plt.ylabel(ylabel)
|
||||
|
||||
# Also diplay fit, previously saved
|
||||
if ax_los is not None and "/hist/fit_" + name + "_" + ax_los in self.save:
|
||||
slope = node.attrs.slope
|
||||
origin = node.attrs.origin
|
||||
P.plot(
|
||||
plt.plot(
|
||||
centers,
|
||||
10 ** (slope * centers + origin),
|
||||
"--",
|
||||
@@ -896,7 +907,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
color="orange",
|
||||
)
|
||||
# or a new one
|
||||
if not fit is None:
|
||||
if fit is not None:
|
||||
self._overlay_fit(
|
||||
centers, values, kind=fit, ls="--", lw=1.5, label=fitlabel
|
||||
)
|
||||
@@ -912,7 +923,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
xaxis_label=xlabel,
|
||||
yaxis_label=ylabel,
|
||||
xaxis_unit=unit,
|
||||
yaxis_unit=cst.none,
|
||||
yaxis_unit=U.none,
|
||||
plot_title=title,
|
||||
)
|
||||
|
||||
@@ -938,7 +949,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
sigma_err=2.0,
|
||||
grid=False,
|
||||
put_time=False,
|
||||
unit_time=cst.Myr,
|
||||
unit_time=U.Myr,
|
||||
colors=None,
|
||||
nml_color=None,
|
||||
legend=None,
|
||||
@@ -951,7 +962,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"""
|
||||
|
||||
# Get proper hdf5 names
|
||||
if not node_arg is None:
|
||||
if node_arg is not None:
|
||||
name_x, name_y = name_x + "_" + node_arg, name_y + "_" + node_arg
|
||||
|
||||
# Get hdf5 nodes
|
||||
@@ -1031,15 +1042,15 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
if smooth > 0:
|
||||
y = gaussian_filter1d(y, sigma=smooth)
|
||||
if not run is None:
|
||||
if run is not None:
|
||||
label = self._label_run(run, node_y, label, nml_key)
|
||||
|
||||
# Look if special colors method is used
|
||||
if colors is None:
|
||||
if yerr is None:
|
||||
(base_line,) = P.plot(x, y, label=label, **kwargs)
|
||||
(base_line,) = plt.plot(x, y, label=label, **kwargs)
|
||||
else:
|
||||
base_line, _, _ = P.errorbar(x, y, yerr=yerr, label=label, **kwargs)
|
||||
base_line, _, _ = plt.errorbar(x, y, yerr=yerr, label=label, **kwargs)
|
||||
else:
|
||||
if nml_color is None:
|
||||
color = colors[run]
|
||||
@@ -1055,21 +1066,21 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
except:
|
||||
color = colors(nml)
|
||||
if yerr is None:
|
||||
(base_line,) = P.plot(x, y, label=label, color=color, **kwargs)
|
||||
(base_line,) = plt.plot(x, y, label=label, color=color, **kwargs)
|
||||
else:
|
||||
base_line, _, _ = P.errorbar(
|
||||
base_line, _, _ = plt.errorbar(
|
||||
x, y, yerr=yerr, color=color, label=label, **kwargs
|
||||
)
|
||||
|
||||
# Ax decorations
|
||||
P.xlabel(xlabel)
|
||||
P.ylabel(ylabel)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel(ylabel)
|
||||
if grid:
|
||||
P.grid()
|
||||
plt.grid()
|
||||
if legend:
|
||||
P.legend()
|
||||
plt.legend()
|
||||
|
||||
if not fit is None:
|
||||
if fit is not None:
|
||||
self._overlay_fit(
|
||||
x,
|
||||
y,
|
||||
@@ -1121,7 +1132,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
if label is None:
|
||||
label = r"Linear fit with slope ${:.3g}$".format(a)
|
||||
P.plot(x, a * x + b, label=label, **kwargs)
|
||||
plt.plot(x, a * x + b, label=label, **kwargs)
|
||||
elif kind == "power_law":
|
||||
if yerr is None:
|
||||
(a, b, rho, _map_rule, stderr) = linregress(np.log10(x), np.log10(y))
|
||||
@@ -1131,8 +1142,13 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
)
|
||||
else:
|
||||
fitfunc = lambda p, x: p[0] + p[1] * x
|
||||
errfunc = lambda p, x, y, err: (y - fitfunc(p, x)) / err
|
||||
|
||||
def fitfunc(p, x):
|
||||
return p[0] + p[1] * x
|
||||
|
||||
def errfunc(p, x, y, err):
|
||||
return (y - fitfunc(p, x)) / err
|
||||
|
||||
pinit = [1.0, -1.0]
|
||||
out = optimize.leastsq(
|
||||
errfunc,
|
||||
@@ -1151,27 +1167,27 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
)
|
||||
if label is None:
|
||||
label = r"Power-law fit with index {:.1f}".format(a)
|
||||
P.plot(x, (10 ** b) * x ** a, label=label, **kwargs)
|
||||
plt.plot(x, (10 ** b) * x ** a, label=label, **kwargs)
|
||||
|
||||
def overlay_kennicutt(self, n0, step):
|
||||
"""
|
||||
Add an overlay : Kennicutt mass accretion
|
||||
"""
|
||||
P.grid(False)
|
||||
ylim = P.ylim()
|
||||
(tmin, tmax) = P.xlim()
|
||||
plt.grid(False)
|
||||
ylim = plt.ylim()
|
||||
(tmin, tmax) = plt.xlim()
|
||||
tmax = tmax + 20
|
||||
ymax = P.ylim()[1]
|
||||
ymax = plt.ylim()[1]
|
||||
ssfr_sun = 2.5e-9
|
||||
ssfr_ken = ssfr_sun * n0 ** 1.4
|
||||
|
||||
coeff = ssfr_ken * 1e6 * (self.comp.info["unit_length"].express(cst.pc)) ** 2
|
||||
coeff = ssfr_ken * 1e6 * (self.comp.info["unit_length"].express(U.pc)) ** 2
|
||||
for i in np.arange(tmin, max(tmax, tmin + ymax / coeff), step):
|
||||
t = np.linspace(0, tmax, 1000)
|
||||
P.plot(t + i, t * coeff, ls="--", lw=0.9, color="grey")
|
||||
P.plot(t + tmin, (t + i - tmin) * coeff, ls="--", lw=0.9, color="grey")
|
||||
P.xlim(tmin, tmax)
|
||||
P.ylim(ylim)
|
||||
plt.plot(t + i, t * coeff, ls="--", lw=0.9, color="grey")
|
||||
plt.plot(t + tmin, (t + i - tmin) * coeff, ls="--", lw=0.9, color="grey")
|
||||
plt.xlim(tmin, tmax)
|
||||
plt.ylim(ylim)
|
||||
|
||||
def _gen_from_log(self, logrule, name, description="Generated"):
|
||||
self.rules[name] = PlotRule(
|
||||
@@ -1180,7 +1196,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/" + logrule + "/time",
|
||||
"/series/" + logrule + "/" + name,
|
||||
xunit=cst.Myr,
|
||||
xunit=U.Myr,
|
||||
),
|
||||
description=description,
|
||||
kind="series",
|
||||
@@ -1202,7 +1218,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"coldens",
|
||||
label=r"$\Sigma$",
|
||||
# unit=cst.coldens
|
||||
# unit=U.coldens
|
||||
),
|
||||
"Column density map",
|
||||
dependencies=["coldens"],
|
||||
@@ -1235,7 +1251,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"vphi",
|
||||
label=r"$v_\phi$",
|
||||
# unit=cst.km_s
|
||||
# unit=U.km_s
|
||||
),
|
||||
"Azimuthal speed",
|
||||
dependencies=["vphi"],
|
||||
@@ -1246,7 +1262,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"vr",
|
||||
label=r"$v_r$",
|
||||
# unit=cst.km_s
|
||||
# unit=U.km_s
|
||||
),
|
||||
"Radial speed",
|
||||
dependencies=["vr"],
|
||||
@@ -1257,7 +1273,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"rho",
|
||||
label=r"$\rho$",
|
||||
# unit=cst.Msun_pc3
|
||||
# unit=U.Msun_pc3
|
||||
),
|
||||
"Density slice at s = 0, with s = x, y or z.",
|
||||
dependencies=["rho"],
|
||||
@@ -1268,7 +1284,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"coldens",
|
||||
label=r"$\Sigma$",
|
||||
unit=cst.coldens,
|
||||
unit=U.coldens,
|
||||
overlays=[self._overlay_levels],
|
||||
),
|
||||
"Column density with level overlay",
|
||||
@@ -1280,7 +1296,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"rho",
|
||||
label=r"$\rho$",
|
||||
unit=cst.Msun_pc3,
|
||||
unit=U.Msun_pc3,
|
||||
overlays=[self._overlay_speed],
|
||||
),
|
||||
"Density slice with speed overlay",
|
||||
@@ -1292,7 +1308,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"rho",
|
||||
label=r"$\rho$",
|
||||
unit=cst.Msun_pc3,
|
||||
unit=U.Msun_pc3,
|
||||
overlays=[self._overlay_B],
|
||||
),
|
||||
"Density slice with magnetic field overlay",
|
||||
@@ -1304,7 +1320,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot_map,
|
||||
"rho",
|
||||
label=r"$\rho$",
|
||||
unit=cst.Msun_pc3,
|
||||
unit=U.Msun_pc3,
|
||||
overlays=[self._overlay_B, self._overlay_speed],
|
||||
),
|
||||
"Density slice with magnetic field and velocity overlay",
|
||||
@@ -1382,7 +1398,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"B_int": PlotRule(
|
||||
self,
|
||||
partial(
|
||||
self._plot_map, "B_int", label=r"$\mid \mathrm{B} \mid$", unit=cst.T
|
||||
self._plot_map, "B_int", label=r"$\mid \mathrm{B} \mid$", unit=U.T
|
||||
),
|
||||
"Magnetic intensity map",
|
||||
dependencies=["B_int"],
|
||||
@@ -1450,8 +1466,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/sinks_from_log/time",
|
||||
"/series/sinks_from_log/mass_sink",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.Msun,
|
||||
xunit=U.Myr,
|
||||
yunit=U.Msun,
|
||||
),
|
||||
"Mass of the sinks as a function of time",
|
||||
kind="series",
|
||||
@@ -1463,8 +1479,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/sinks_from_log/time",
|
||||
"/series/sinks_from_log/ssm",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.Msun / cst.pc ** 2,
|
||||
xunit=U.Myr,
|
||||
yunit=U.Msun / U.pc ** 2,
|
||||
),
|
||||
"Mass of the sinks as a function of time divided by surface",
|
||||
kind="series",
|
||||
@@ -1477,8 +1493,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"/series/sfr_from_log/time",
|
||||
"/series/sfr_from_log/sfr",
|
||||
ylabel="Averaged surfacic SFR",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.ssfr,
|
||||
xunit=U.Myr,
|
||||
yunit=U.ssfr,
|
||||
),
|
||||
kind="series",
|
||||
dependencies=["sfr_from_log"],
|
||||
@@ -1490,8 +1506,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"/series/sinks_from_log/time",
|
||||
"/series/sinks_from_log/issfr",
|
||||
ylabel="Surfacic SFR",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.ssfr,
|
||||
xunit=U.Myr,
|
||||
yunit=U.ssfr,
|
||||
),
|
||||
kind="series",
|
||||
dependencies=["issfr"],
|
||||
@@ -1502,7 +1518,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
"/series/rms_from_log/turb_rms",
|
||||
xunit=cst.Myr,
|
||||
xunit=U.Myr,
|
||||
),
|
||||
"Turbulent RMS",
|
||||
kind="series",
|
||||
@@ -1514,7 +1530,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
"/series/rms_from_log/turb_energy",
|
||||
xunit=cst.Myr,
|
||||
xunit=U.Myr,
|
||||
),
|
||||
"Turbulent energy",
|
||||
kind="series",
|
||||
@@ -1526,7 +1542,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/rms_from_log/time",
|
||||
"/series/rms_from_log/turb_power",
|
||||
xunit=cst.Myr,
|
||||
xunit=U.Myr,
|
||||
),
|
||||
"Turbulent power",
|
||||
kind="series",
|
||||
@@ -1539,8 +1555,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"/series/time",
|
||||
"/series/time_sigma",
|
||||
ylabel="$\\sigma$",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.km_s,
|
||||
xunit=U.Myr,
|
||||
yunit=U.km_s,
|
||||
),
|
||||
"Velocity dispersion",
|
||||
kind="series",
|
||||
@@ -1552,8 +1568,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/time",
|
||||
"/series/time_mwa_B_int",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.uG,
|
||||
xunit=U.Myr,
|
||||
yunit=U.uG,
|
||||
),
|
||||
"Magnetic intensity average",
|
||||
kind="series",
|
||||
@@ -1565,8 +1581,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/time",
|
||||
"/series/time_mass",
|
||||
xunit=cst.Myr,
|
||||
yunit=cst.Msun,
|
||||
xunit=U.Myr,
|
||||
yunit=U.Msun,
|
||||
),
|
||||
"Total mass in the box",
|
||||
kind="series",
|
||||
@@ -1578,8 +1594,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._plot,
|
||||
"/series/time",
|
||||
"/series/time_max_fluct_coldens_z",
|
||||
ylabel="$\\max(\Sigma/\overline{\Sigma})$",
|
||||
xunit=cst.Myr,
|
||||
ylabel="$\\max(\\Sigma/\\overline{\\Sigma})$",
|
||||
xunit=U.Myr,
|
||||
),
|
||||
"Maximal fluctuation of the column density against time",
|
||||
kind="series",
|
||||
|
||||
Reference in New Issue
Block a user