Skip to content
Snippets Groups Projects
Commit 32b3f35b authored by lukas leufen's avatar lukas leufen
Browse files

Merge branch 'lukas_issue107_refac_try-except-for-plots' into 'develop', /close #107

Resolve "Use try except statements for all plots"

See merge request toar/mlair!209
parents 7c87b30f 4d79f00f
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 #55013 passed
This commit is part of merge request !225. Comments created here will be created in the context of that merge request.
......@@ -239,6 +239,7 @@ class PostProcessing(RunEnvironment):
model = keras.models.load_model(model_name, custom_objects=model_class.custom_objects)
return model
# noinspection PyBroadException
def plot(self):
"""
Create all plots.
......@@ -263,14 +264,26 @@ class PostProcessing(RunEnvironment):
plot_list = self.data_store.get("plot_list", "postprocessing")
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)
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):
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:
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 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"):
......@@ -284,25 +297,50 @@ class PostProcessing(RunEnvironment):
gens = [(self.train_val_data, {"marker": 8, "ms": 9}),
(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}")
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}")
try:
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, score_only=False,
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:
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:
PlotTimeSeries(self.test_data.keys(), path, r"forecasts_%s_test.nc", plot_folder=self.plot_path,
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:
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)
except Exception as e:
logging.error(f"Could not create plot PlotAvailability due to the following error: {e}")
try:
if "PlotAvailabilityHistogram" in plot_list:
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)
except Exception as e:
logging.error(f"Could not create plot PlotAvailabilityHistogram due to the following error: {e}")
def calculate_test_score(self):
"""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