Skip to content
Snippets Groups Projects
Commit 4d79f00f authored by leufen1's avatar leufen1
Browse files

encapsulate all plot routines into a try except statement with a general Exception case

parent 7c87b30f
No related branches found
No related tags found
3 merge requests!226Develop,!225Resolve "release v1.2.0",!209Resolve "Use try except statements for all plots"
Pipeline #54879 passed
...@@ -239,6 +239,7 @@ class PostProcessing(RunEnvironment): ...@@ -239,6 +239,7 @@ class PostProcessing(RunEnvironment):
model = keras.models.load_model(model_name, custom_objects=model_class.custom_objects) model = keras.models.load_model(model_name, custom_objects=model_class.custom_objects)
return model return model
# noinspection PyBroadException
def plot(self): def plot(self):
""" """
Create all plots. Create all plots.
...@@ -263,14 +264,26 @@ class PostProcessing(RunEnvironment): ...@@ -263,14 +264,26 @@ class PostProcessing(RunEnvironment):
plot_list = self.data_store.get("plot_list", "postprocessing") plot_list = self.data_store.get("plot_list", "postprocessing")
time_dimension = self.data_store.get("time_dim") time_dimension = self.data_store.get("time_dim")
if ("filter" in self.test_data[0].get_X(as_numpy=False)[0].coords) and ("PlotSeparationOfScales" in plot_list): try:
if ("filter" in self.test_data[0].get_X(as_numpy=False)[0].coords) and (
"PlotSeparationOfScales" in plot_list):
PlotSeparationOfScales(self.test_data, plot_folder=self.plot_path) PlotSeparationOfScales(self.test_data, plot_folder=self.plot_path)
except Exception as e:
logging.error(f"Could not create plot PlotSeparationOfScales due to the following error: {e}")
try:
if (self.bootstrap_skill_scores is not None) and ("PlotBootstrapSkillScore" in plot_list): if (self.bootstrap_skill_scores is not None) and ("PlotBootstrapSkillScore" in plot_list):
PlotBootstrapSkillScore(self.bootstrap_skill_scores, plot_folder=self.plot_path, model_setup="CNN") PlotBootstrapSkillScore(self.bootstrap_skill_scores, plot_folder=self.plot_path, model_setup="CNN")
except Exception as e:
logging.error(f"Could not create plot PlotBootstrapSkillScore due to the following error: {e}")
try:
if "PlotConditionalQuantiles" in plot_list: if "PlotConditionalQuantiles" in plot_list:
PlotConditionalQuantiles(self.test_data.keys(), data_pred_path=path, plot_folder=self.plot_path) 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}")
try:
if "PlotStationMap" in plot_list: if "PlotStationMap" in plot_list:
if self.data_store.get("hostname")[:2] in self.data_store.get("hpc_hosts") or self.data_store.get( if self.data_store.get("hostname")[:2] in self.data_store.get("hpc_hosts") or self.data_store.get(
"hostname")[:6] in self.data_store.get("hpc_hosts"): "hostname")[:6] in self.data_store.get("hpc_hosts"):
...@@ -284,25 +297,50 @@ class PostProcessing(RunEnvironment): ...@@ -284,25 +297,50 @@ class PostProcessing(RunEnvironment):
gens = [(self.train_val_data, {"marker": 8, "ms": 9}), gens = [(self.train_val_data, {"marker": 8, "ms": 9}),
(self.test_data, {"marker": 9, "ms": 9})] (self.test_data, {"marker": 9, "ms": 9})]
PlotStationMap(generators=gens, plot_folder=self.plot_path, plot_name="station_map_var") 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}")
try:
if "PlotMonthlySummary" in plot_list: if "PlotMonthlySummary" in plot_list:
PlotMonthlySummary(self.test_data.keys(), path, r"forecasts_%s_test.nc", self.target_var, PlotMonthlySummary(self.test_data.keys(), path, r"forecasts_%s_test.nc", self.target_var,
plot_folder=self.plot_path) plot_folder=self.plot_path)
except Exception as e:
logging.error(f"Could not create plot PlotMonthlySummary due to the following error: {e}")
try:
if "PlotClimatologicalSkillScore" in plot_list: if "PlotClimatologicalSkillScore" in plot_list:
PlotClimatologicalSkillScore(self.skill_scores[1], plot_folder=self.plot_path, model_setup="CNN") PlotClimatologicalSkillScore(self.skill_scores[1], plot_folder=self.plot_path, model_setup="CNN")
PlotClimatologicalSkillScore(self.skill_scores[1], plot_folder=self.plot_path, score_only=False, PlotClimatologicalSkillScore(self.skill_scores[1], plot_folder=self.plot_path, score_only=False,
extra_name_tag="all_terms_", model_setup="CNN") extra_name_tag="all_terms_", model_setup="CNN")
except Exception as e:
logging.error(f"Could not create plot PlotClimatologicalSkillScore due to the following error: {e}")
try:
if "PlotCompetitiveSkillScore" in plot_list: if "PlotCompetitiveSkillScore" in plot_list:
PlotCompetitiveSkillScore(self.skill_scores[0], plot_folder=self.plot_path, model_setup="CNN") PlotCompetitiveSkillScore(self.skill_scores[0], plot_folder=self.plot_path, model_setup="CNN")
except Exception as e:
logging.error(f"Could not create plot PlotCompetitiveSkillScore due to the following error: {e}")
try:
if "PlotTimeSeries" in plot_list: if "PlotTimeSeries" in plot_list:
PlotTimeSeries(self.test_data.keys(), path, r"forecasts_%s_test.nc", plot_folder=self.plot_path, PlotTimeSeries(self.test_data.keys(), path, r"forecasts_%s_test.nc", plot_folder=self.plot_path,
sampling=self._sampling) sampling=self._sampling)
except Exception as e:
logging.error(f"Could not create plot PlotTimeSeries due to the following error: {e}")
try:
if "PlotAvailability" in plot_list: if "PlotAvailability" in plot_list:
avail_data = {"train": self.train_data, "val": self.val_data, "test": self.test_data} avail_data = {"train": self.train_data, "val": self.val_data, "test": self.test_data}
PlotAvailability(avail_data, plot_folder=self.plot_path, time_dimension=time_dimension) PlotAvailability(avail_data, plot_folder=self.plot_path, time_dimension=time_dimension)
except Exception as e:
logging.error(f"Could not create plot PlotAvailability due to the following error: {e}")
try:
if "PlotAvailabilityHistogram" in plot_list: if "PlotAvailabilityHistogram" in plot_list:
avail_data = {"train": self.train_data, "val": self.val_data, "test": self.test_data} avail_data = {"train": self.train_data, "val": self.val_data, "test": self.test_data}
PlotAvailabilityHistogram(avail_data, plot_folder=self.plot_path, ) # time_dimension=time_dimension) PlotAvailabilityHistogram(avail_data, plot_folder=self.plot_path, ) # time_dimension=time_dimension)
except Exception as e:
logging.error(f"Could not create plot PlotAvailabilityHistogram due to the following error: {e}")
def calculate_test_score(self): def calculate_test_score(self):
"""Evaluate test score of model and save locally.""" """Evaluate test score of model and save locally."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment