black without mortimer
This commit is contained in:
+61
-51
@@ -104,16 +104,15 @@ def quiver(ax, map_h, map_v, extent, key_v=None, lognorm=False, label="", **kwar
|
||||
min_v = np.min(norm_v)
|
||||
|
||||
if key_v is None:
|
||||
key_v = (max_v + min_v) / 2.0
|
||||
key_v = (max_v + min_v) / 2.0
|
||||
|
||||
key = f"${key_v:g}$ {label}"
|
||||
|
||||
if lognorm:
|
||||
lognorm_v = np.log10(norm_v)
|
||||
map_h *= lognorm_v/norm_v
|
||||
map_v *= lognorm_v/norm_v
|
||||
key_v = np.log10(key_v)
|
||||
|
||||
lognorm_v = np.log10(norm_v)
|
||||
map_h *= lognorm_v / norm_v
|
||||
map_v *= lognorm_v / norm_v
|
||||
key_v = np.log10(key_v)
|
||||
|
||||
# plot vector field
|
||||
vec_field = ax.quiver(hh, vv, map_h, map_v, units="width", **kwargs)
|
||||
@@ -203,7 +202,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
# Conversion table from namelist values (from ramses config file) into suitanle units
|
||||
value_convert = {
|
||||
"sfr_avg_window": lambda x: 80 * x, # Myr
|
||||
"sfr_avg_window": lambda x: 80 * x, # Myr
|
||||
"Bx": lambda x: x * 7.6189439,
|
||||
}
|
||||
|
||||
@@ -241,7 +240,6 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
# log info
|
||||
self.log_id = "plotter({})".format(tag)
|
||||
|
||||
|
||||
super(Plotter, self).__init__(path, path_out, params, tag)
|
||||
|
||||
# Select runs
|
||||
@@ -421,7 +419,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if ax is not None:
|
||||
onefigure = True
|
||||
if not movie:
|
||||
plot_filename = self._find_filename(name_full)
|
||||
plot_filename = self._find_filename(name_full)
|
||||
|
||||
for i, (run, num) in enumerate(run_num):
|
||||
|
||||
@@ -465,7 +463,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if self.params.astrophysix.generate:
|
||||
df = rule.datafile(name, arg)
|
||||
df[filetype] = plot_filename
|
||||
|
||||
|
||||
if plot_info is not None:
|
||||
df.plot_info = plot_info
|
||||
if num is not None:
|
||||
@@ -499,7 +497,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if self.params.plot.tight_layout and close:
|
||||
plt.tight_layout(pad=1)
|
||||
|
||||
if self.params.out.save:
|
||||
if self.params.out.save:
|
||||
os.makedirs(os.path.dirname(plot_filename), exist_ok=True)
|
||||
plt.savefig(plot_filename)
|
||||
self.logger.info(f"{plot_filename} plotted")
|
||||
@@ -565,10 +563,10 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
prop_label = self.label_convert[prop_name]
|
||||
else:
|
||||
prop_label = prop_name
|
||||
try:
|
||||
prop_value = self.study.get_nml(nml_key, run)
|
||||
try:
|
||||
prop_value = self.study.get_nml(nml_key, run)
|
||||
except KeyError:
|
||||
return ""
|
||||
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:
|
||||
@@ -594,8 +592,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
elif nml_key is not None:
|
||||
if not type(nml_key) == list:
|
||||
nml_key = [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
|
||||
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 and len(label) > 0:
|
||||
@@ -831,7 +829,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
s=title,
|
||||
color=overtext_color,
|
||||
transform=ax.transAxes,
|
||||
**text_kwargs
|
||||
**text_kwargs,
|
||||
)
|
||||
else:
|
||||
plt.title(title)
|
||||
@@ -971,9 +969,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
if sinks:
|
||||
try:
|
||||
self.current_processor.sinks()
|
||||
data = pd.DataFrame(
|
||||
self.current_processor.get_value("/datasets/sinks")
|
||||
)
|
||||
data = pd.DataFrame(self.current_processor.get_value("/datasets/sinks"))
|
||||
part_pos = data[["x", "y", "z"]].values
|
||||
unit_length /= self.current_processor.lbox
|
||||
except KeyError:
|
||||
@@ -1038,6 +1034,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
# Scatter plot
|
||||
scatter = plt.scatter(part_h, part_v, s=s, c=c, **kwargs)
|
||||
|
||||
return scatter
|
||||
|
||||
def _overlay_vector(
|
||||
self,
|
||||
name,
|
||||
@@ -1160,7 +1158,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
else:
|
||||
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)
|
||||
nml_value = self.value_convert[os.path.basename(nml_color)](
|
||||
nml_value
|
||||
)
|
||||
try:
|
||||
color = colors[nml_value]
|
||||
except TypeError:
|
||||
@@ -1219,32 +1219,31 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
def plot(
|
||||
self,
|
||||
x:np.array,
|
||||
y:np.array,
|
||||
xlabel:str="",
|
||||
ylabel:str="",
|
||||
label:str="",
|
||||
xscale:str="linear",
|
||||
yscale:str="linear",
|
||||
fit:str=None,
|
||||
fitlabel:str=None,
|
||||
smooth:float=0,
|
||||
x: np.array,
|
||||
y: np.array,
|
||||
xlabel: str = "",
|
||||
ylabel: str = "",
|
||||
label: str = "",
|
||||
xscale: str = "linear",
|
||||
yscale: str = "linear",
|
||||
fit: str = None,
|
||||
fitlabel: str = None,
|
||||
smooth: float = 0,
|
||||
nml_key=None,
|
||||
run:str=None,
|
||||
yerr:np.array=None,
|
||||
grid:bool=False,
|
||||
put_time:bool=False,
|
||||
run: str = None,
|
||||
yerr: np.array = None,
|
||||
grid: bool = False,
|
||||
put_time: bool = False,
|
||||
unit_time=U.Myr,
|
||||
colors=None,
|
||||
nml_color=None,
|
||||
legend:bool=False,
|
||||
legend: bool = False,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Generic plot routine, with x, y two numpy arrauys
|
||||
"""
|
||||
|
||||
|
||||
# Option to smooth data for readability (beware)
|
||||
if smooth > 0:
|
||||
y = gaussian_filter1d(y, sigma=smooth)
|
||||
@@ -1283,7 +1282,9 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
else:
|
||||
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)
|
||||
nml_value = self.value_convert[os.path.basename(nml_color)](
|
||||
nml_value
|
||||
)
|
||||
try:
|
||||
color = colors[nml_value]
|
||||
except TypeError:
|
||||
@@ -1321,8 +1322,8 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
def _plot(
|
||||
self,
|
||||
name_x:str,
|
||||
name_y:str,
|
||||
name_x: str,
|
||||
name_y: str,
|
||||
node_arg=None,
|
||||
xlabel=None,
|
||||
ylabel=None,
|
||||
@@ -1363,10 +1364,18 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
|
||||
# Find proper labels
|
||||
xlabel, xunit_old, xunit = self._ax_label_unit(
|
||||
name_x, xlabel, xunit, xunit_coeff, put_units=put_units,
|
||||
name_x,
|
||||
xlabel,
|
||||
xunit,
|
||||
xunit_coeff,
|
||||
put_units=put_units,
|
||||
)
|
||||
ylabel, yunit_old, yunit = self._ax_label_unit(
|
||||
name_y, ylabel, yunit, yunit_coeff, put_units=put_units,
|
||||
name_y,
|
||||
ylabel,
|
||||
yunit,
|
||||
yunit_coeff,
|
||||
put_units=put_units,
|
||||
)
|
||||
|
||||
# Manage the different forms in which the data may be stored :
|
||||
@@ -1426,8 +1435,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"Errorbar may be meaningless when ytransform is used"
|
||||
)
|
||||
|
||||
self.plot(x, y, yerr=yerr, xlabel=xlabel,
|
||||
ylabel=ylabel, run=run, **kwargs)
|
||||
self.plot(x, y, yerr=yerr, xlabel=xlabel, ylabel=ylabel, run=run, **kwargs)
|
||||
|
||||
if subname_x:
|
||||
hdf5_x.close()
|
||||
@@ -1518,13 +1526,15 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
This is where rules are defined
|
||||
"""
|
||||
self.rules = {
|
||||
"plot_comp": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="comp"
|
||||
"plot_comp": PlotRule(
|
||||
lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="comp"
|
||||
),
|
||||
"plot_run": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="run"
|
||||
"plot_run": PlotRule(
|
||||
lambda arg, **kwargs: self._plot(*arg, **kwargs), kind="run"
|
||||
),
|
||||
"plot_snapshot": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs)
|
||||
),
|
||||
"plot_map": PlotRule(lambda mapname, **kwargs: self._plot_map(mapname, **kwargs)
|
||||
"plot_snapshot": PlotRule(lambda arg, **kwargs: self._plot(*arg, **kwargs)),
|
||||
"plot_map": PlotRule(
|
||||
lambda mapname, **kwargs: self._plot_map(mapname, **kwargs)
|
||||
),
|
||||
"coldens": PlotRule(
|
||||
partial(
|
||||
@@ -1955,7 +1965,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
self._gen_from_log("fine_step_from_log", name)
|
||||
for name in ["time", "dt", "a", "mem_cells", "mem_parts"]:
|
||||
self._gen_from_log("fine_step_from_log", name_y=name, name_x="fine_step")
|
||||
|
||||
|
||||
self._gen_from_log("SN_momentum_from_log", name_x="time", name_y="SN_momentum")
|
||||
|
||||
# Dict of overlays
|
||||
@@ -1963,7 +1973,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
"g": partial(self._overlay_vector, "g"),
|
||||
"B": self._overlay_B,
|
||||
"vel": self._overlay_speed,
|
||||
"speed": self._overlay_speed,
|
||||
"speed": self._overlay_speed,
|
||||
"levels": self._overlay_levels,
|
||||
"contour": self._overlay_contour,
|
||||
"particles": self._overlay_particles,
|
||||
|
||||
Reference in New Issue
Block a user