From a1d4356fdbd8479706067eddde68c23c5f078a8a Mon Sep 17 00:00:00 2001
From: "v.gramlich1" <v.gramlichfz-juelich.de>
Date: Wed, 27 Oct 2021 08:31:06 +0200
Subject: [PATCH] Output tables with all values for contingency tables and
 scores

---
 mlair/plotting/postprocessing_plotting.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py
index 4ca6412c..29ef70a3 100644
--- a/mlair/plotting/postprocessing_plotting.py
+++ b/mlair/plotting/postprocessing_plotting.py
@@ -51,8 +51,10 @@ class PlotContingency(AbstractPlotClass):
         self._plot_names = plot_names
         self._min_threshold, self._max_threshold = self._min_max_threshold()
         contingency_array = self._calculate_contingencies()
+        self._save_tables(contingency_array, "contingency")
         self._scores = ["gss", "ts", "h", "f", "b"]
         score_array = self._calculate_all_scores(contingency_array)
+        self._save_tables(score_array, "scores_contingency")
         self._plot_counter = 0
 
         self._plot(score_array, "gss")
@@ -73,6 +75,25 @@ class PlotContingency(AbstractPlotClass):
             self._plot_contingency(contingency_array, comp)
             self._save()
 
+    def _save_tables(self, array, name):
+        for model in self._all_names:
+            type_array = array.sel(type=model).drop("type")
+            if name is "contingency":
+                df = pd.DataFrame({"a": type_array.sel(contingency_cell="ta").values,
+                                   "b": type_array.sel(contingency_cell="fa").values,
+                                   "c": type_array.sel(contingency_cell="fb").values,
+                                   "d": type_array.sel(contingency_cell="tb").values})
+            else:
+                df = pd.DataFrame({"gss": type_array.sel(scores="gss").values,
+                                   "ts": type_array.sel(scores="ts").values,
+                                   "h": type_array.sel(scores="h").values,
+                                   "f": type_array.sel(scores="f").values,
+                                   "b": type_array.sel(scores="b").values})
+
+            helpers.tables.save_to_tex(self.plot_folder, f"table_{name}_{model}",
+                                       helpers.tables.create_column_format_for_tex(df), df)
+
+
     def _plot_contingency(self, contingency_array, type):
         plt.plot(range(self._min_threshold, self._max_threshold),
                  contingency_array.loc[dict(contingency_cell="ta", type=type)], label="a")
-- 
GitLab