Add some doc

This commit is contained in:
Noe Brucy
2020-06-10 09:11:55 +02:00
committed by Noe Brucy
parent 89365f3df5
commit 267122178d
2 changed files with 174 additions and 125 deletions
+3 -1
View File
@@ -198,7 +198,9 @@ class BaseProcessor:
def def_rules(self):
for rule in self.rules:
setattr(self, rule, partial(self.process, rule))
func = partial(self.process, rule)
func.__doc__ = self.rules[rule].description
setattr(self, rule, func)
class HDF5Container(BaseProcessor):
+171 -124
View File
@@ -1,5 +1,13 @@
# coding: utf-8
"""
This software is a helper to use pysmes tools to read and analyse RAMSES Outputs.
It's a rule based interface.
This is the plotter module.
@author Noé Brucy 2019-2020
"""
import sys
import os
from functools import partial
@@ -27,13 +35,24 @@ P.rcParams.update(tex_params)
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)
"""
def plot(self, save, arg, **kwargs):
"""
Set the plotter's storage to 'save' and exetute the rule
Parameters
----------
save : opended pytables hdf5 file, where to find the data
arg : main argument of the plotting function
kargs : optional keyword arguments to the plotting function
"""
self.postproc.save = save
return self.process_fn(arg, **kwargs)
def is_valid(self, arg):
return self.is_valid_add(arg)
class Plotter(Aggregator, BaseProcessor):
"""
@@ -50,6 +69,7 @@ class Plotter(Aggregator, BaseProcessor):
G = 1.0 # Gravitational constant
# Conversion table from namelist keys (from amses config file) into LaTex strings
label_convert = {
"turb_rms": "$f_{rms}$",
"beta": "$\\beta$",
@@ -60,6 +80,7 @@ class Plotter(Aggregator, BaseProcessor):
"comp_frac": "$\\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),
@@ -77,6 +98,22 @@ class Plotter(Aggregator, BaseProcessor):
**kwargs
):
"""
Create a new Plotter instance. Will select run and outputs via a RunSelector object.
Parameters
----------
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])
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
tag : string to add in the output and data files.
kwargs : Keyword arguments for RunSelector.
"""
super(Plotter, self).__init__(path, path_out, pp_params, tag)
# Select runs
@@ -105,6 +142,7 @@ class Plotter(Aggregator, BaseProcessor):
self.save = None
def _not_self_dep(self, name, dep, dep_arg, overwrite, **kwargs):
""""""
if dep in self.comp.rules:
done = self.comp.process(dep, dep_arg, overwrite, overwrite)
self.just_done.extend(done)
@@ -874,13 +912,13 @@ class Plotter(Aggregator, BaseProcessor):
"coldens": PlotRule(
self,
partial(self._plot_map, "coldens", label=r"$\Sigma$", unit=cst.coldens),
"Column density",
"Column density map",
dependencies=["coldens"],
),
"rho": PlotRule(
self,
partial(self._plot_map, "rho", label=r"$\rho$", unit=cst.Msun_pc3),
"Density slice",
"Density slice at s = 0, with s = x, y or z.",
dependencies=["rho"],
),
"coldens_l": PlotRule(
@@ -892,7 +930,7 @@ class Plotter(Aggregator, BaseProcessor):
unit=cst.coldens,
overlays=[self._overlay_levels],
),
"Column density",
"Column density with level overlay",
dependencies=["coldens", "levels"],
),
"rho_v": PlotRule(
@@ -904,7 +942,7 @@ class Plotter(Aggregator, BaseProcessor):
unit=cst.Msun_pc3,
overlays=[self._overlay_speed],
),
"Density slice",
"Density slice with speed overlay",
dependencies=["rho", "speed_h", "speed_v"],
),
"jeans_ratio": PlotRule(
@@ -948,22 +986,145 @@ class Plotter(Aggregator, BaseProcessor):
xlog=True,
put_time=False,
),
"PDF",
"Column density PDF, averaged in time",
kind="runs",
dependencies={"avg_time_coldens_pdf": "z"},
),
"T_pdf": PlotRule(
self, partial(self._plot_hist, "T_pdf"), "T-PDF", dependencies=["T_pdf"]
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", dependencies=["P_pdf"]
self,
partial(self._plot_hist, "P_pdf"),
"P-PDF on a 2D slice ",
dependencies=["P_pdf"],
),
"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}),
"kappa_beta": PlotRule(
self,
partial(
self._plot,
"/comp/nml_cloud_params/beta_cool",
"/comp/avg_time_pdf_slope_coldens",
),
"Slope of the Sigma-PDF against cooling beta factor",
kind="comp",
dependencies={
"nml": "cloud_params/beta_cool",
"avg_time_pdf_slope_coldens": None,
},
),
"sink_mass": PlotRule(
self,
partial(
self._plot,
"/series/sinks_from_log/time",
"/series/sinks_from_log/mass_sink",
"Mass of the sinks against time",
xunit=cst.Myr,
yunit=cst.Msun,
),
kind="series",
dependencies=["sinks_from_log"],
),
"assfr": PlotRule(
self,
partial(
self._plot,
"/series/sfr_from_log/time",
"/series/sfr_from_log/sfr",
ylabel="Averaged surfacic SFR",
xunit=cst.Myr,
yunit=cst.ssfr,
),
kind="series",
dependencies=["sfr_from_log"],
),
"issfr": PlotRule(
self,
partial(
self._plot,
"/series/sinks_from_log/time",
"/series/sinks_from_log/issfr",
ylabel="Surfacic SFR",
xunit=cst.Myr,
yunit=cst.ssfr,
),
kind="series",
dependencies=["issfr"],
),
"turb_rms": PlotRule(
self,
partial(
self._plot,
"/series/rms_from_log/time",
"/series/rms_from_log/turb_rms",
xunit=cst.Myr,
),
"Turbulent RMS",
kind="series",
dependencies=["rms_from_log"],
),
"turb_energy": PlotRule(
self,
partial(
self._plot,
"/series/rms_from_log/time",
"/series/rms_from_log/turb_energy",
xunit=cst.Myr,
),
"Turbulent energy",
kind="series",
dependencies=["rms_from_log"],
),
"turb_power": PlotRule(
self,
partial(
self._plot,
"/series/rms_from_log/time",
"/series/rms_from_log/turb_power",
xunit=cst.Myr,
),
"Turbulent power",
kind="series",
dependencies=["turb_power"],
),
"sigma": PlotRule(
self,
partial(
self._plot,
"/series/time",
"/series/time_sigma",
ylabel="$\\sigma$",
xunit=cst.Myr,
yunit=cst.km_s,
),
"Velocity dispersion",
kind="series",
dependencies=["time_sigma"],
),
"max_fluct_coldens": PlotRule(
self,
partial(
self._plot,
"/series/time",
"/series/time_max_fluct_coldens_z",
ylabel="$\\max(\Sigma/\overline{\Sigma})$",
xunit=cst.Myr,
),
"Maximal fluctuation of the column density against time",
kind="series",
dependencies={"time_max_fluct_coldens": "z"},
),
}
averageables = ["coldens", "rho", "T", "Q"]
@@ -1006,118 +1167,4 @@ class Plotter(Aggregator, BaseProcessor):
dependencies=["fit_pdf_" + name],
)
self.rules.update(
{
"kappa_beta": PlotRule(
self,
partial(
self._plot,
"/comp/nml_cloud_params/beta_cool",
"/comp/avg_time_pdf_slope_coldens",
),
kind="comp",
dependencies={
"nml": "cloud_params/beta_cool",
"avg_time_pdf_slope_coldens": None,
},
),
"sink_mass": PlotRule(
self,
partial(
self._plot,
"/series/sinks_from_log/time",
"/series/sinks_from_log/mass_sink",
xunit=cst.Myr,
yunit=cst.Msun,
),
kind="series",
dependencies=["sinks_from_log"],
),
"assfr": PlotRule(
self,
partial(
self._plot,
"/series/sfr_from_log/time",
"/series/sfr_from_log/sfr",
ylabel="Averaged surfacic SFR",
xunit=cst.Myr,
yunit=cst.ssfr,
),
kind="series",
dependencies=["sfr_from_log"],
),
"issfr": PlotRule(
self,
partial(
self._plot,
"/series/sinks_from_log/time",
"/series/sinks_from_log/issfr",
ylabel="Surfacic SFR",
xunit=cst.Myr,
yunit=cst.ssfr,
),
kind="series",
dependencies=["issfr"],
),
"turb_rms": PlotRule(
self,
partial(
self._plot,
"/series/rms_from_log/time",
"/series/rms_from_log/turb_rms",
xunit=cst.Myr,
),
kind="series",
dependencies=["rms_from_log"],
),
"turb_energy": PlotRule(
self,
partial(
self._plot,
"/series/rms_from_log/time",
"/series/rms_from_log/turb_energy",
xunit=cst.Myr,
),
kind="series",
dependencies=["rms_from_log"],
),
"turb_power": PlotRule(
self,
partial(
self._plot,
"/series/rms_from_log/time",
"/series/rms_from_log/turb_power",
xunit=cst.Myr,
),
kind="series",
dependencies=["turb_power"],
),
"sigma": PlotRule(
self,
partial(
self._plot,
"/series/time",
"/series/time_sigma",
ylabel="$\\sigma$",
xunit=cst.Myr,
yunit=cst.km_s,
),
kind="series",
dependencies=["time_sigma"],
),
"max_fluct_coldens": PlotRule(
self,
partial(
self._plot,
"/series/time",
"/series/time_max_fluct_coldens_z",
ylabel="$\\max(\Sigma/\overline{\Sigma})$",
xunit=cst.Myr,
),
kind="series",
dependencies={"time_max_fluct_coldens": "z"},
),
}
)
super(Plotter, self).def_rules()