[plotter] perso rcParams is now contextualized within the Plotter
This commit is contained in:
+106
-110
@@ -173,10 +173,6 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
# Define rules
|
# Define rules
|
||||||
self.def_rules()
|
self.def_rules()
|
||||||
|
|
||||||
# Load rcParams
|
|
||||||
if self.params.rcParams is not None:
|
|
||||||
plt.rcParams.update(params.rcParams)
|
|
||||||
|
|
||||||
# Generate astrophysix's simulations object
|
# Generate astrophysix's simulations object
|
||||||
self.gen_simus()
|
self.gen_simus()
|
||||||
|
|
||||||
@@ -269,116 +265,116 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
"""
|
"""
|
||||||
Open storage and figure if needed before processing a rule
|
Open storage and figure if needed before processing a rule
|
||||||
"""
|
"""
|
||||||
|
with plt.rc_context(self.params.rcParams):
|
||||||
# Set full name according to argument
|
# Set full name according to argument
|
||||||
if arg is not None:
|
if arg is not None:
|
||||||
name_full = (
|
name_full = (
|
||||||
name
|
name
|
||||||
+ "_"
|
+ "_"
|
||||||
+ str(arg)
|
+ str(arg)
|
||||||
.replace(" ", "")
|
.replace(" ", "")
|
||||||
.replace("[", "")
|
.replace("[", "")
|
||||||
.replace("]", "")
|
.replace("]", "")
|
||||||
.replace(",", "_")
|
.replace(",", "_")
|
||||||
.replace("'", "")
|
.replace("'", "")
|
||||||
.replace("/", "")
|
.replace("/", "")
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
name_full = name
|
|
||||||
|
|
||||||
# get filetype of the output
|
|
||||||
filetype = filetype_from_ext[self.params.out.ext]
|
|
||||||
|
|
||||||
# Select runs and nums
|
|
||||||
if select is not None:
|
|
||||||
runs, nums = self.selector.select(**select)
|
|
||||||
else:
|
|
||||||
runs = self.runs
|
|
||||||
nums = self.nums
|
|
||||||
|
|
||||||
datafiles = []
|
|
||||||
|
|
||||||
if rule.kind == "snapshot" or rule.kind == "cells":
|
|
||||||
run_num = [(run, num) for run in runs for num in nums[run]]
|
|
||||||
if movie:
|
|
||||||
filenames = {run: [] for run in runs}
|
|
||||||
elif rule.kind == "comp":
|
|
||||||
run_num = [(None, None)]
|
|
||||||
if movie:
|
|
||||||
self._log(f"No movie possible for rule {name}", "WARNING")
|
|
||||||
movie = False
|
|
||||||
else:
|
|
||||||
run_num = [(run, None) for run in runs]
|
|
||||||
if movie:
|
|
||||||
self._log(f"No movie possible for rule {name}", "WARNING")
|
|
||||||
movie = False
|
|
||||||
|
|
||||||
onefigure = False # If axes are provided, only save/close once
|
|
||||||
if ax is not None:
|
|
||||||
onefigure = True
|
|
||||||
plot_filename = self._find_filename(name_full)
|
|
||||||
|
|
||||||
for i, (run, num) in enumerate(run_num):
|
|
||||||
|
|
||||||
# Find filename
|
|
||||||
if not onefigure:
|
|
||||||
plot_filename = self._find_filename(name_full, run, num)
|
|
||||||
|
|
||||||
# Find ax
|
|
||||||
try:
|
|
||||||
real_ax = ax[i]
|
|
||||||
except TypeError as e:
|
|
||||||
if ax is None:
|
|
||||||
_, real_ax = plt.subplots(1, 1)
|
|
||||||
elif not_array_error(e):
|
|
||||||
real_ax = ax
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Find underlying processor
|
|
||||||
if rule.kind == "snapshot":
|
|
||||||
self.current_processor = self.snaps[run][num]
|
|
||||||
else:
|
else:
|
||||||
self.current_processor = self.study
|
name_full = name
|
||||||
|
|
||||||
# Call plot routine
|
# get filetype of the output
|
||||||
close = (not onefigure) or (i == len(run_num) - 1)
|
filetype = filetype_from_ext[self.params.out.ext]
|
||||||
plot_info = self._plot_rule(
|
|
||||||
rule,
|
# Select runs and nums
|
||||||
arg,
|
if select is not None:
|
||||||
plot_filename,
|
runs, nums = self.selector.select(**select)
|
||||||
overwrite,
|
else:
|
||||||
ax=real_ax,
|
runs = self.runs
|
||||||
close=close,
|
nums = self.nums
|
||||||
run=run,
|
|
||||||
**kwargs,
|
datafiles = []
|
||||||
)
|
|
||||||
|
if rule.kind == "snapshot" or rule.kind == "cells":
|
||||||
|
run_num = [(run, num) for run in runs for num in nums[run]]
|
||||||
|
if movie:
|
||||||
|
filenames = {run: [] for run in runs}
|
||||||
|
elif rule.kind == "comp":
|
||||||
|
run_num = [(None, None)]
|
||||||
|
if movie:
|
||||||
|
self._log(f"No movie possible for rule {name}", "WARNING")
|
||||||
|
movie = False
|
||||||
|
else:
|
||||||
|
run_num = [(run, None) for run in runs]
|
||||||
|
if movie:
|
||||||
|
self._log(f"No movie possible for rule {name}", "WARNING")
|
||||||
|
movie = False
|
||||||
|
|
||||||
|
onefigure = False # If axes are provided, only save/close once
|
||||||
|
if ax is not None:
|
||||||
|
onefigure = True
|
||||||
|
plot_filename = self._find_filename(name_full)
|
||||||
|
|
||||||
|
for i, (run, num) in enumerate(run_num):
|
||||||
|
|
||||||
|
# Find filename
|
||||||
|
if not onefigure:
|
||||||
|
plot_filename = self._find_filename(name_full, run, num)
|
||||||
|
|
||||||
|
# Find ax
|
||||||
|
try:
|
||||||
|
real_ax = ax[i]
|
||||||
|
except TypeError as e:
|
||||||
|
if ax is None:
|
||||||
|
_, real_ax = plt.subplots(1, 1)
|
||||||
|
elif not_array_error(e):
|
||||||
|
real_ax = ax
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
# Find underlying processor
|
||||||
|
if rule.kind == "snapshot":
|
||||||
|
self.current_processor = self.snaps[run][num]
|
||||||
|
else:
|
||||||
|
self.current_processor = self.study
|
||||||
|
|
||||||
|
# Call plot routine
|
||||||
|
close = (not onefigure) or (i == len(run_num) - 1)
|
||||||
|
plot_info = self._plot_rule(
|
||||||
|
rule,
|
||||||
|
arg,
|
||||||
|
plot_filename,
|
||||||
|
overwrite,
|
||||||
|
ax=real_ax,
|
||||||
|
close=close,
|
||||||
|
run=run,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Save in astrophysix format
|
||||||
|
df = rule.datafile(name, arg)
|
||||||
|
df[filetype] = plot_filename
|
||||||
|
if movie:
|
||||||
|
filenames[run].append(plot_filename)
|
||||||
|
if plot_info is not None:
|
||||||
|
df.plot_info = plot_info
|
||||||
|
if num is not None:
|
||||||
|
snap = self.snaps[run][num].snapshot
|
||||||
|
|
||||||
|
if overwrite and df.name in snap.datafiles:
|
||||||
|
del snap.datafiles[df.name]
|
||||||
|
elif df.name not in snap.datafiles:
|
||||||
|
snap.datafiles.add(df)
|
||||||
|
|
||||||
|
if snap not in self.simulations[run].snapshots:
|
||||||
|
self.simulations[run].snapshots.add(snap)
|
||||||
|
|
||||||
|
datafiles.append(df)
|
||||||
|
|
||||||
# Save in astrophysix format
|
|
||||||
df = rule.datafile(name, arg)
|
|
||||||
df[filetype] = plot_filename
|
|
||||||
if movie:
|
if movie:
|
||||||
filenames[run].append(plot_filename)
|
for run in runs:
|
||||||
if plot_info is not None:
|
clip = ImageSequenceClip(filenames[run], fps=movie_fps)
|
||||||
df.plot_info = plot_info
|
movie_filename = self._find_filename(name_full, run=run, ext=".mp4")
|
||||||
if num is not None:
|
clip.write_videofile(movie_filename)
|
||||||
snap = self.snaps[run][num].snapshot
|
|
||||||
|
|
||||||
if overwrite and df.name in snap.datafiles:
|
|
||||||
del snap.datafiles[df.name]
|
|
||||||
elif df.name not in snap.datafiles:
|
|
||||||
snap.datafiles.add(df)
|
|
||||||
|
|
||||||
if snap not in self.simulations[run].snapshots:
|
|
||||||
self.simulations[run].snapshots.add(snap)
|
|
||||||
|
|
||||||
datafiles.append(df)
|
|
||||||
|
|
||||||
if movie:
|
|
||||||
for run in runs:
|
|
||||||
clip = ImageSequenceClip(filenames[run], fps=movie_fps)
|
|
||||||
movie_filename = self._find_filename(name_full, run=run, ext=".mp4")
|
|
||||||
clip.write_videofile(movie_filename)
|
|
||||||
|
|
||||||
return datafiles
|
return datafiles
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user