From 1a6a693add27dae6ff2d88a14b64f0b63eb888df Mon Sep 17 00:00:00 2001 From: "v.gramlich1" <v.gramlichfz-juelich.de> Date: Wed, 4 Aug 2021 10:36:06 +0200 Subject: [PATCH] Added bias and titles to PlotOversamplingContingency --- mlair/plotting/postprocessing_plotting.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index ed114830..6801addb 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -35,7 +35,7 @@ class PlotOversamplingContingency(AbstractPlotClass): def __init__(self, station_names, file_path, comp_path, file_name, plot_folder: str = ".", model_name: str = "nn", obs_name: str = "obs", comp_names: str = "IntelliO3", plot_names=["oversampling_threat_score", "oversampling_hit_rate", "oversampling_false_alarm_rate", - "oversampling_all_scores"]): + "oversampling_bias", "oversampling_all_scores"]): super().__init__(plot_folder, plot_names[0]) self._stations = station_names @@ -50,7 +50,7 @@ class PlotOversamplingContingency(AbstractPlotClass): self._plot_names = plot_names self._min_threshold, self._max_threshold = self._min_max_threshold() contingency_array = self._calculate_contingencies() - self._scores = ["ts", "h", "f"] + self._scores = ["ts", "h", "f", "b"] score_array = self._calculate_all_scores(contingency_array) self._plot_counter = 0 @@ -60,6 +60,8 @@ class PlotOversamplingContingency(AbstractPlotClass): self._save() self._plot(score_array, "f") self._save() + self._plot(score_array, "b") + self._save() self._plot(score_array, "all_scores") self._save() @@ -70,6 +72,7 @@ class PlotOversamplingContingency(AbstractPlotClass): else: for type in data.type.values.tolist(): plt.plot(range(self._min_threshold, self._max_threshold), data.loc[dict(type=type, scores=score)], label=type) + plt.title(self._plot_names[self._plot_counter][13:]) plt.legend() self.plot_name = self._plot_names[self._plot_counter] self._plot_counter = self._plot_counter + 1 @@ -132,7 +135,7 @@ class PlotOversamplingContingency(AbstractPlotClass): contingency_cell = ["ta", "fa", "fb", "tb"] contingency_array = xr.DataArray(dims=["thresholds", "contingency_cell", "type"], coords=[thresholds, contingency_cell, self._all_names]) - contingency_array = contingency_array.fillna(0) + contingency_array = contingency_array.fillna(1) for station in self._stations: file = os.path.join(self._file_path, self._file_name % station) forecast_file = xr.open_dataarray(file) @@ -193,14 +196,19 @@ class PlotOversamplingContingency(AbstractPlotClass): score_value = true_above/(true_above + false_above + false_below) elif score == "h": if (true_above + false_below) == 0: - score_value = 1 + score_value = 0 else: score_value = true_above/(true_above + false_below) elif score == "f": if (false_above + true_below) == 0: - score_value = 1 + score_value = 0 else: score_value = false_above/(false_above + true_below) + elif score == "b": + if (true_above + false_below) == 0: + score_value = 0 + else: + score_value = (true_above + false_above)/(true_above + false_below) return score_value -- GitLab