|
13 | 13 | from collections import defaultdict |
14 | 14 | from pathlib import Path |
15 | 15 |
|
16 | | -from omegaconf import OmegaConf |
17 | | -from plotter import Plotter |
18 | | -from utils import ( |
| 16 | +from omegaconf import DictConfig, OmegaConf |
| 17 | + |
| 18 | +from weathergen.evaluate.utils import ( |
19 | 19 | calc_scores_per_stream, |
20 | 20 | metric_list_to_json, |
21 | 21 | plot_data, |
|
25 | 25 |
|
26 | 26 | _logger = logging.getLogger(__name__) |
27 | 27 |
|
28 | | -if __name__ == "__main__": |
29 | | - parser = argparse.ArgumentParser( |
30 | | - description="Fast evaluation of WeatherGenerator runs." |
31 | | - ) |
32 | | - parser.add_argument( |
33 | | - "--config", |
34 | | - type=str, |
35 | | - help="Path to the configuration yaml file for plotting. e.g. config/plottig_config.yaml", |
36 | | - ) |
37 | | - |
38 | | - args = parser.parse_args() |
39 | | - |
40 | | - # configure logging |
41 | | - logging.basicConfig(level=logging.INFO) |
42 | 28 |
|
43 | | - # load configuration |
44 | | - cfg = OmegaConf.load(args.config) |
| 29 | +def run_main(cfg: DictConfig) -> None: |
45 | 30 | runs = cfg.run_ids |
46 | 31 |
|
47 | 32 | _logger.info(f"Detected {len(runs)} runs") |
|
52 | 37 | out_scores_dir = Path(cfg.output_scores_dir) |
53 | 38 | out_scores_dir.mkdir(parents=True, exist_ok=True) |
54 | 39 |
|
55 | | - results_dir = Path(cfg.results_dir) |
56 | 40 | metrics = cfg.evaluation.metrics |
57 | 41 |
|
58 | 42 | # to get a structure like: scores_dict[metric][stream][run_id] = plot |
59 | 43 | scores_dict = defaultdict(lambda: defaultdict(dict)) |
60 | 44 |
|
61 | 45 | for run_id, run in runs.items(): |
62 | | - plotter = Plotter(cfg, run_id) |
63 | 46 | _logger.info(f"RUN {run_id}: Getting data...") |
64 | 47 |
|
65 | 48 | streams = run["streams"].keys() |
|
71 | 54 |
|
72 | 55 | if stream_dict.get("plotting"): |
73 | 56 | _logger.info(f"RUN {run_id}: Plotting stream {stream}...") |
74 | | - plots = plot_data(cfg, run_id, stream, stream_dict) |
| 57 | + plot_data(cfg, run_id, stream, stream_dict) |
75 | 58 |
|
76 | 59 | if stream_dict.get("evaluation"): |
77 | 60 | _logger.info(f"Retrieve or compute scores for {run_id} - {stream}...") |
|
109 | 92 | scores_dict[metric][stream][run_id] = all_metrics.sel( |
110 | 93 | {"metric": metric} |
111 | 94 | ) |
| 95 | + # plot summary |
| 96 | + if scores_dict and cfg.summary_plots: |
| 97 | + _logger.info("Started creating summary plots..") |
| 98 | + plot_summary(cfg, scores_dict, print_summary=cfg.print_summary) |
112 | 99 |
|
113 | 100 |
|
114 | | -# plot summary |
115 | | -if scores_dict and cfg.summary_plots: |
116 | | - _logger.info("Started creating summary plots..") |
117 | | - plot_summary(cfg, scores_dict, print_summary=cfg.print_summary) |
| 101 | +if __name__ == "__main__": |
| 102 | + parser = argparse.ArgumentParser( |
| 103 | + description="Fast evaluation of WeatherGenerator runs." |
| 104 | + ) |
| 105 | + parser.add_argument( |
| 106 | + "--config", |
| 107 | + type=str, |
| 108 | + help="Path to the configuration yaml file for plotting. e.g. config/plottig_config.yaml", |
| 109 | + ) |
| 110 | + |
| 111 | + args = parser.parse_args() |
| 112 | + |
| 113 | + # configure logging |
| 114 | + logging.basicConfig(level=logging.INFO) |
| 115 | + |
| 116 | + # load configuration |
| 117 | + cfg = OmegaConf.load(args.config) |
| 118 | + run_main(cfg) |
0 commit comments