diff --git a/config/evaluate/eval_config.yml b/config/evaluate/eval_config.yml index c1f44ea84..15ab11af6 100644 --- a/config/evaluate/eval_config.yml +++ b/config/evaluate/eval_config.yml @@ -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 diff --git a/packages/evaluate/src/weathergen/evaluate/plotting/plot_orchestration.py b/packages/evaluate/src/weathergen/evaluate/plotting/plot_orchestration.py index 7a832ba7c..9099dc89c 100644 --- a/packages/evaluate/src/weathergen/evaluate/plotting/plot_orchestration.py +++ b/packages/evaluate/src/weathergen/evaluate/plotting/plot_orchestration.py @@ -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( @@ -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), } + apply_font_settings(plotter_cfg) plotter = Plotter(plotter_cfg, reader.runplot_dir) available_data = reader.check_availability(stream, mode="plotting") @@ -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())) diff --git a/packages/evaluate/src/weathergen/evaluate/plotting/plot_utils.py b/packages/evaluate/src/weathergen/evaluate/plotting/plot_utils.py index bf9bd421e..49605f5b8 100644 --- a/packages/evaluate/src/weathergen/evaluate/plotting/plot_utils.py +++ b/packages/evaluate/src/weathergen/evaluate/plotting/plot_utils.py @@ -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. @@ -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] @@ -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: diff --git a/packages/evaluate/src/weathergen/evaluate/plotting/plotter.py b/packages/evaluate/src/weathergen/evaluate/plotting/plotter.py index 2d4c104a1..8e1fdcb2d 100644 --- a/packages/evaluate/src/weathergen/evaluate/plotting/plotter.py +++ b/packages/evaluate/src/weathergen/evaluate/plotting/plotter.py @@ -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) @@ -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 @@ -1178,6 +1178,9 @@ 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 ------- @@ -1185,6 +1188,8 @@ def get_map_title(self, var, valid_time, data): 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: