diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index ecba8a4e0a3369fbb170a7427ef81365d531bc3b..e89a84366fa440ca4ed959fa3addf0303ba52bcd 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -847,13 +847,14 @@ class PlotTimeSeries: """ def __init__(self, stations: List, data_path: str, name: str, window_lead_time: int = None, plot_folder: str = ".", - sampling="daily", model_name="nn", obs_name="obs"): + sampling="daily", model_name="nn", obs_name="obs", ahead_dim="ahead"): """Initialise.""" self._data_path = data_path self._data_name = name self._stations = stations self._model_name = model_name self._obs_name = obs_name + self._ahead_dim = ahead_dim self._window_lead_time = self._get_window_lead_time(window_lead_time) self._sampling = self._get_sampling(sampling) self._plot(plot_folder) @@ -876,7 +877,7 @@ class PlotTimeSeries: :param window_lead_time: lead time from arguments to validate :return: validated lead time, comes either from given argument or from data itself """ - ahead_steps = len(self._load_data(self._stations[0]).ahead) + ahead_steps = len(self._load_data(self._stations[0]).coords[self._ahead_dim]) if window_lead_time is None: window_lead_time = ahead_steps return min(ahead_steps, window_lead_time) @@ -938,9 +939,8 @@ class PlotTimeSeries: def _plot_ahead(self, ax, data): color = sns.color_palette("Blues_d", self._window_lead_time).as_hex() - for ahead in data.coords["ahead"].values: - plot_data = data.sel(type=self._model_name, ahead=ahead).drop(["type", "ahead"]).squeeze().shift( - index=ahead) + for ahead in data.coords[self._ahead_dim].values: + plot_data = data.sel({"type": self._model_name, self._ahead_dim: ahead}).drop(["type", self._ahead_dim]).squeeze().shift(index=ahead) label = f"{ahead}{self._sampling}" ax.plot(plot_data, color=color[ahead - 1], label=label) diff --git a/mlair/run_modules/post_processing.py b/mlair/run_modules/post_processing.py index edab0a3e8ad3ee6f7eeb50318f617d3b661255bd..ae53d3b6f066a71877fd4245a5db7ad3f8f07554 100644 --- a/mlair/run_modules/post_processing.py +++ b/mlair/run_modules/post_processing.py @@ -6,6 +6,7 @@ __date__ = '2019-12-11' import inspect import logging import os +import sys from typing import Dict, Tuple, Union, List, Callable import keras @@ -336,7 +337,8 @@ class PostProcessing(RunEnvironment): PlotSeparationOfScales(self.test_data, plot_folder=self.plot_path, time_dim=time_dim, window_dim=window_dim, target_dim=target_dim, **{"filter_dim": filter_dim}) except Exception as e: - logging.error(f"Could not create plot PlotSeparationOfScales due to the following error: {e}") + logging.error(f"Could not create plot PlotSeparationOfScales due to the following error:" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if (self.bootstrap_skill_scores is not None) and ("PlotBootstrapSkillScore" in plot_list): @@ -349,7 +351,8 @@ class PostProcessing(RunEnvironment): bootstrap_type=boot_type, bootstrap_method=boot_method) except Exception as e: logging.error(f"Could not create plot PlotBootstrapSkillScore ({boot_type}, {boot_method}) " - f"due to the following error: {e}") + f"due to the following error:\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n" + f"{sys.exc_info()[2]}") except Exception as e: logging.error(f"Could not create plot PlotBootstrapSkillScore due to the following error: {e}") @@ -357,14 +360,16 @@ class PostProcessing(RunEnvironment): if "PlotConditionalQuantiles" in plot_list: PlotConditionalQuantiles(self.test_data.keys(), data_pred_path=path, plot_folder=self.plot_path) except Exception as e: - logging.error(f"Could not create plot PlotConditionalQuantiles due to the following error: {e}") + logging.error(f"Could not create plot PlotConditionalQuantiles due to the following error:" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotMonthlySummary" in plot_list: PlotMonthlySummary(self.test_data.keys(), path, r"forecasts_%s_test.nc", self.target_var, plot_folder=self.plot_path) except Exception as e: - logging.error(f"Could not create plot PlotMonthlySummary due to the following error: {e}") + logging.error(f"Could not create plot PlotMonthlySummary due to the following error:" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotClimatologicalSkillScore" in plot_list: @@ -373,21 +378,24 @@ class PostProcessing(RunEnvironment): PlotClimatologicalSkillScore(self.skill_scores[1], plot_folder=self.plot_path, score_only=False, extra_name_tag="all_terms_", model_setup=self.forecast_indicator) except Exception as e: - logging.error(f"Could not create plot PlotClimatologicalSkillScore due to the following error: {e}") + logging.error(f"Could not create plot PlotClimatologicalSkillScore due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotCompetitiveSkillScore" in plot_list: PlotCompetitiveSkillScore(self.skill_scores[0], plot_folder=self.plot_path, model_setup=self.forecast_indicator) except Exception as e: - logging.error(f"Could not create plot PlotCompetitiveSkillScore due to the following error: {e}") + logging.error(f"Could not create plot PlotCompetitiveSkillScore due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotTimeSeries" in plot_list: PlotTimeSeries(self.test_data.keys(), path, r"forecasts_%s_test.nc", plot_folder=self.plot_path, - sampling=self._sampling) + sampling=self._sampling, ahead_dim=self.ahead_dim) except Exception as e: - logging.error(f"Could not create plot PlotTimeSeries due to the following error: {e}") + logging.error(f"Could not create plot PlotTimeSeries due to the following error:\n{sys.exc_info()[0]}\n" + f"{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotStationMap" in plot_list: @@ -404,7 +412,8 @@ class PostProcessing(RunEnvironment): (self.test_data, {"marker": 9, "ms": 9})] PlotStationMap(generators=gens, plot_folder=self.plot_path, plot_name="station_map_var") except Exception as e: - logging.error(f"Could not create plot PlotStationMap due to the following error: {e}") + logging.error(f"Could not create plot PlotStationMap due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotAvailability" in plot_list: @@ -412,7 +421,8 @@ class PostProcessing(RunEnvironment): PlotAvailability(avail_data, plot_folder=self.plot_path, time_dimension=time_dim, window_dimension=window_dim) except Exception as e: - logging.error(f"Could not create plot PlotAvailability due to the following error: {e}") + logging.error(f"Could not create plot PlotAvailability due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotAvailabilityHistogram" in plot_list: @@ -420,7 +430,8 @@ class PostProcessing(RunEnvironment): PlotAvailabilityHistogram(avail_data, plot_folder=self.plot_path, station_dim=iter_dim, history_dim=window_dim) except Exception as e: - logging.error(f"Could not create plot PlotAvailabilityHistogram due to the following error: {e}") + logging.error(f"Could not create plot PlotAvailabilityHistogram due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotPeriodogram" in plot_list: @@ -428,7 +439,8 @@ class PostProcessing(RunEnvironment): variables_dim=target_dim, sampling=self._sampling, use_multiprocessing=use_multiprocessing) except Exception as e: - logging.error(f"Could not create plot PlotPeriodogram due to the following error: {e}") + logging.error(f"Could not create plot PlotPeriodogram due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: if "PlotDataHistogram" in plot_list: @@ -437,7 +449,8 @@ class PostProcessing(RunEnvironment): PlotDataHistogram(gens, plot_folder=self.plot_path, time_dim=time_dim, variables_dim=target_dim, upsampling=upsampling) except Exception as e: - logging.error(f"Could not create plot PlotDataHistogram due to the following error: {e}") + logging.error(f"Could not create plot PlotDataHistogram due to the following error: {e}" + f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") def calculate_test_score(self): """Evaluate test score of model and save locally."""