Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/evaluate/eval_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# regions: ["europe", "global"] # Have regions here, if you want for them to apply to all streams (map generation)
# image_format : "png" #options: "png", "pdf", "svg", "eps", "jpg" ..
# animation_format: "gif" #options: "mp4", "gif"
# font_size: 12
# font_type: "serif"

# dpi_val : 300
# fps: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,11 @@ def run_score_map_pipeline(
"fig_size": cfg.get("fig_size", None),
"animation_format": cfg.get("animation_format", "gif"),
"fps": cfg.get("fps", 2),
"font_size": cfg.get("font_size"),
"font_type": cfg.get("font_type"),
}
output_basedir = str(reader.runplot_dir)
apply_font_settings(plotter_cfg)
run_id = reader.run_id

_computed, raw_results = _compute_scores(
Expand Down Expand Up @@ -888,9 +891,12 @@ def plot_data(
"log_y": global_plotting_opts.get("log_y", False),
"n_bins": global_plotting_opts.get("n_bins", 50),
"plot_subtimesteps": reader.get_inference_stream_attr(stream, "tokenize_spacetime", False)
"font_size": global_plotting_opts.get("font_size"),
"font_type": global_plotting_opts.get("font_type"),
| plot_settings.get("plot_subtimesteps", False),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a part of l. 893 and in this form it should return a syntax error

}

apply_font_settings(plotter_cfg)
plotter = Plotter(plotter_cfg, reader.runplot_dir)

available_data = reader.check_availability(stream, mode="plotting")
Expand Down Expand Up @@ -1251,8 +1257,11 @@ def plot_summary(cfg: dict, scores_dict: dict, summary_dir: Path):
"add_grid": eval_opt.get("add_grid", False),
"plot_ensemble": eval_opt.get("plot_ensemble", False),
"baseline": eval_opt.get("baseline", None),
"font_size": plt_opt.get("font_size"),
"font_type": plt_opt.get("font_type"),
}

apply_font_settings(plot_cfg)
# Prefix the output directory with a run_ids identifier so that
# different evaluation configs can coexist in the same base directory.
run_ids_str = "_".join(sorted(runs.keys()))
Expand Down
34 changes: 31 additions & 3 deletions packages/evaluate/src/weathergen/evaluate/plotting/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,31 @@
import xarray as xr
from numpy.typing import NDArray

import matplotlib as mpl

_logger = logging.getLogger(__name__)


def apply_font_settings(cfg: dict) -> None:
"""Apply font settings from plotter config to matplotlib rcParams.

Parameters
----------
cfg : dict
Plotter configuration dictionary. Recognised keys:

- ``font_size``: base font size (default: matplotlib default)
- ``font_type``: font family, e.g. ``'serif'``, ``'sans-serif'``,
``'monospace'`` (default: matplotlib default)
"""
font_size = cfg.get("font_size")
font_type = cfg.get("font_type")
if font_size is not None:
mpl.rcParams["font.size"] = font_size
if font_type is not None:
mpl.rcParams["font.family"] = font_type


class PlotSubdir(str, Enum):
"""Known plot subdirectory names produced by the plotting pipeline.

Expand Down Expand Up @@ -393,12 +415,15 @@ def plot_metric_region(
continue

selected_data.append(data.sel(channel=ch))
labels.append(runs[run_id].get("label", run_id))
label = runs[run_id].get("label", run_id)
if label != run_id:
label = f"{run_id} - {label}"
labels.append(label)
run_ids.append(run_id)
colors.append(runs[run_id].get("color", None))

if selected_data:
_logger.info(f"Creating line plot for {metric} - {region} - {stream} - {ch}.")
_logger.info(f"Creating plot for {metric} - {region} - {stream} - {ch}.")

name = create_filename(
prefix=[metric, region], middle=sorted(set(run_ids)), suffix=[stream, ch]
Expand Down Expand Up @@ -760,7 +785,10 @@ def quantile_plot_metric_region(
qq_full_data.append(qq_dataset)

selected_data.append(data_for_channel)
labels.append(runs[run_id].get("label", run_id))
label = runs[run_id].get("label", run_id)
if label != run_id:
label = f"{run_id} - {label}"
labels.append(label)
run_ids.append(run_id)

if selected_data:
Expand Down
9 changes: 7 additions & 2 deletions packages/evaluate/src/weathergen/evaluate/plotting/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def create_maps_per_sample(
region,
tag=tag,
map_kwargs=self._match_glob_kwargs(map_kwargs, var) | map_kwargs_stream,
title=self.get_map_title(var, valid_time, da_t),
title=self.get_map_title(var, valid_time, da_t, tag=tag),
)
plot_names.append(name)

Expand Down Expand Up @@ -1165,7 +1165,7 @@ def get_hist_output_dir(self):
"""
return self.out_plot_basedir / self.stream / "histograms"

def get_map_title(self, var, valid_time, data):
def get_map_title(self, var, valid_time, data, tag=""):
"""Build the title string for a map plot.

Parameters
Expand All @@ -1178,13 +1178,18 @@ def get_map_title(self, var, valid_time, data):
data : xr.DataArray
DataArray from which to extract ``valid_time`` range when
*valid_time* is ``None``.
tag : str
Plot tag. When ``"targets"``, ``" (target)"`` is appended
to the title.

Returns
-------
str
Formatted title string.
"""
title = f"{self.stream}, {var} : fstep = {self.fstep:03}"
if tag == "targets":
title += " (target)"
if valid_time is not None:
title += f" ({format_datetime(valid_time)})"
elif "valid_time" in data.coords:
Expand Down
Loading