From 4d08f3c271c6294435c5ee5e63020c068fc0ffc5 Mon Sep 17 00:00:00 2001
From: Theophile Terraz <theophile.terraz@inrae.fr>
Date: Mon, 3 Feb 2025 10:09:45 +0100
Subject: [PATCH] pep8

---
 src/Model/Geometry/ProfileXYZ.py    |  3 +--
 src/Model/Results/River/River.py    |  5 +++-
 src/View/MainWindow.py              | 36 ++++++++---------------------
 src/View/Results/CustomPlot/Plot.py | 10 ++++----
 src/View/Results/PlotAC.py          |  6 +++--
 src/View/Results/PlotH.py           |  9 ++------
 src/View/Results/PlotRKC.py         |  3 ++-
 src/View/Results/Table.py           | 15 +++++-------
 src/View/Results/Window.py          | 16 ++++++-------
 src/View/Results/WindowAdisTS.py    |  2 +-
 src/View/Results/translate.py       |  5 +++-
 11 files changed, 46 insertions(+), 64 deletions(-)

diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py
index 39a15c50..6a4f196b 100644
--- a/src/Model/Geometry/ProfileXYZ.py
+++ b/src/Model/Geometry/ProfileXYZ.py
@@ -167,8 +167,7 @@ class ProfileXYZ(Profile, SQLSubModel):
                     filter(
                         lambda s: s.id == sl,
                         data["sediment_layers_list"].sediment_layers
-                    )
-                , None)
+                    ), None)
 
             data["profile"] = new
             new._points = PointXYZ._db_load(execute, data.copy())
diff --git a/src/Model/Results/River/River.py b/src/Model/Results/River/River.py
index c37479e6..fbf979c0 100644
--- a/src/Model/Results/River/River.py
+++ b/src/Model/Results/River/River.py
@@ -57,7 +57,10 @@ class Profile(object):
         )
 
     def get_ts_key(self, timestamp, key):
-        return self._data[timestamp][key]
+        if timestamp in self._data:
+            if key in self._data[timestamp]:
+                return self._data[timestamp][key]
+        return None
 
     def has_sediment(self):
         return any(map(lambda ts: "sl" in self._data[ts], self._data))
diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index cc651de4..1aa86263 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -82,7 +82,7 @@ from View.RunSolver.Window import (
                                    SolverLogWindow,
                                    CompareSolversWindow
                                    )
-from View.Results.Window import ResultsWindow # , CompareResultsWindow
+from View.Results.Window import ResultsWindow
 from View.RunSolver.WindowAdisTS import (
     SelectSolverWindowAdisTS,
     SolverLogWindowAdisTS
@@ -1584,22 +1584,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
         # Windows already opened
         if self.sub_window_exists(
                 ResultsWindow,
-                data=[
-                    self._study,
-                    None] +      # No config
-                    [r._solver for r in results] +
-                    [r._repertory for r in results] +
-                    [r._name for r in results]
+                data=[self._study, None] +
+                     [r._solver for r in results] +
+                     [r._repertory for r in results] +
+                     [r._name for r in results]
         ):
-            #w = self.get_sub_window(
-                    #ResultsWindow,
-                    #data=[
-                        #self._study,
-                        #None,       # No config
-                        #results,
-                        #parent=self
-                    #])
-            #w.add_result(result[1], run.solver2)
             return
 
         res = ResultsWindow(
@@ -1609,15 +1598,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
         )
         res.show()
 
-        #res = CompareResultsWindow(
-            #study=self._study,
-            #solver=results._solver,
-            #results=results,
-            #parent=self
-        #)
-        #res.show()
-
-
     def diff_results(self, solver1, solver2):
         if solver1 is None:
             # TODO message
@@ -1667,7 +1647,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
         result3.set("nb_profile", result1.get("nb_profile"))
         result4.set("nb_profile", result1.get("nb_profile"))
         result5.set("nb_profile", result1.get("nb_profile"))
-        ts = list(result1.get("timestamps").intersection(result2.get("timestamps")))
+        ts = list(result1.get("timestamps").intersection(
+            result2.get("timestamps")))
         result3.set("timestamps", ts)
         result4.set("timestamps", ts)
         result5.set("timestamps", ts)
@@ -1685,7 +1666,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
                 reach3 = result3.river.reach(r)
                 reach4 = result4.river.reach(r)
                 reach5 = result5.river.reach(r)
-                for p, (profile1, profile2) in enumerate(zip(reach1.profiles, reach2.profiles)):
+                for p, (profile1, profile2) in enumerate(zip(
+                        reach1.profiles, reach2.profiles)):
                     for key in ["Z", "Q", "V"]:
                         d1 = profile1.get_ts_key(timestamp, key)
                         d2 = profile2.get_ts_key(timestamp, key)
diff --git a/src/View/Results/CustomPlot/Plot.py b/src/View/Results/CustomPlot/Plot.py
index 9f3a005e..41d1652d 100644
--- a/src/View/Results/CustomPlot/Plot.py
+++ b/src/View/Results/CustomPlot/Plot.py
@@ -241,8 +241,8 @@ class CustomPlot(PamhyrPlot):
             self.lines["bed_elevation"] = line
 
             if (self._envelop and
-                reach.has_sediment() and
-                self._current_res_id != 2):
+                    reach.has_sediment() and
+                    self._current_res_id != 2):
 
                 ax = self._axes[unit["bed_elevation_envelop"]]
 
@@ -547,7 +547,7 @@ class CustomPlot(PamhyrPlot):
                         reach2.profiles
                     )
                 )
-                fr =  list(
+                fr = list(
                     map(
                         lambda x, y: x - y,
                         fr1, fr2
@@ -1336,8 +1336,8 @@ class CustomPlot(PamhyrPlot):
         for axes in self._y_axes[1:]:
             print("axes: ", axes)
             if axes in self._axes.keys():
-                for l in self._axes[axes].lines:
-                    l.remove()
+                for ll in self._axes[axes].lines:
+                    ll.remove()
             else:
                 ax_new = self.canvas.axes.twinx()
                 self._axes[axes] = ax_new
diff --git a/src/View/Results/PlotAC.py b/src/View/Results/PlotAC.py
index a8204708..614d1b4e 100644
--- a/src/View/Results/PlotAC.py
+++ b/src/View/Results/PlotAC.py
@@ -150,7 +150,8 @@ class PlotAC(PamhyrPlot):
     def set_timestamp(self, timestamp):
         self._current_timestamp = timestamp
 
-        reach = self.results[self._current_res_id].river.reach(self._current_reach_id)
+        reach = self.results[self._current_res_id].river.reach(
+            self._current_reach_id)
         profile = reach.profile(self._current_profile_id)
         x = profile.geometry.get_station()
         z = profile.geometry.z()
@@ -162,7 +163,8 @@ class PlotAC(PamhyrPlot):
         if not self._init:
             self.draw()
 
-        reach = self.results[self._current_res_id].river.reach(self._current_reach_id)
+        reach = self.results[self._current_res_id].river.reach(
+            self._current_reach_id)
         profile = reach.profile(self._current_profile_id)
         x = profile.geometry.get_station()
         z = profile.geometry.z()
diff --git a/src/View/Results/PlotH.py b/src/View/Results/PlotH.py
index d5fd0e73..09d6acb3 100644
--- a/src/View/Results/PlotH.py
+++ b/src/View/Results/PlotH.py
@@ -62,8 +62,8 @@ class PlotH(PamhyrPlot):
 
         self._isometric_axis = False
 
-        #self._auto_relim_update = False
-        #self._autoscale_update = False
+        # self._auto_relim_update = False
+        # self._autoscale_update = False
 
     @property
     def results(self):
@@ -182,11 +182,6 @@ class PlotH(PamhyrPlot):
 
         self._line.set_data(x, y)
 
-        #self._current.set_data(
-            #[self._current_timestamp, self._current_timestamp],
-            #self.canvas.axes.get_ylim()
-        #)
-
     def update_current(self):
         y = self._current.get_ydata()
         self._current.set_data(
diff --git a/src/View/Results/PlotRKC.py b/src/View/Results/PlotRKC.py
index ea21f435..e2446963 100644
--- a/src/View/Results/PlotRKC.py
+++ b/src/View/Results/PlotRKC.py
@@ -112,11 +112,12 @@ class PlotRKC(PamhyrPlot):
         self._river_bottom = z
 
     def draw_profiles_hs(self, reach):
+        results = self.results[self._current_res_id]
         lhs = filter(
             lambda hs: hs._input_reach.reach is reach.geometry,
             filter(
                 lambda hs: hs._input_reach is not None,
-                self.results[self._current_res_id].study.river.hydraulic_structures.lst
+                results.study.river.hydraulic_structures.lst
             )
         )
 
diff --git a/src/View/Results/Table.py b/src/View/Results/Table.py
index 13d7c29d..436b9bf6 100644
--- a/src/View/Results/Table.py
+++ b/src/View/Results/Table.py
@@ -89,21 +89,18 @@ class TableModel(PamhyrTableModel):
                     return f"{p.rk:.4f}"
                 return f"{p.name}"
             elif self._headers[column] == "water_elevation":
-                try:
-                    v = self._lst[row].get_ts_key(self._timestamp, "Z")
-                except:
+                v = self._lst[row].get_ts_key(self._timestamp, "Z")
+                if v is None:
                     v = 0.0
                 return f"{v:.4f}"
             elif self._headers[column] == "discharge":
-                try:
-                    v = self._lst[row].get_ts_key(self._timestamp, "Q")
-                except:
+                v = self._lst[row].get_ts_key(self._timestamp, "Q")
+                if v is None:
                     v = 0.0
                 return f"{v:.4f}"
             elif self._headers[column] == "velocity":
-                try:
-                    v = self._lst[row].get_ts_key(self._timestamp, "V")
-                except:
+                v = self._lst[row].get_ts_key(self._timestamp, "V")
+                if v is None:
                     v = 0.0
                 return f"{v:.4f}"
             elif self._headers[column] == "width":
diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py
index 0fa5f828..ad1c2b7f 100644
--- a/src/View/Results/Window.py
+++ b/src/View/Results/Window.py
@@ -957,7 +957,7 @@ class ResultsWindow(PamhyrWindow):
                         reach2.profiles
                     )
                 )
-                fr =  list(
+                fr = list(
                     map(
                         lambda x, y: x - y,
                         fr1, fr2
@@ -1027,14 +1027,14 @@ class ResultsWindow(PamhyrWindow):
             if self._current_results != 2:
                 z_min = [profile.geometry.z_min()] * len(self._timestamps)
             else:
-                    z_min1 = profile1.geometry.z_min()
-                    z_min2 = profile2.geometry.z_min()
-                    z_min = list(
-                        map(
-                            lambda ts:  z_min1 - z_min2,
-                            self._timestamps
-                        )
+                z_min1 = profile1.geometry.z_min()
+                z_min2 = profile2.geometry.z_min()
+                z_min = list(
+                    map(
+                        lambda ts:  z_min1 - z_min2,
+                        self._timestamps
                     )
+                )
             my_dict[dict_y["bed_elevation"]] = z_min
         if "discharge" in y:
             my_dict[dict_y["discharge"]] = q
diff --git a/src/View/Results/WindowAdisTS.py b/src/View/Results/WindowAdisTS.py
index 1388745b..811dcff2 100644
--- a/src/View/Results/WindowAdisTS.py
+++ b/src/View/Results/WindowAdisTS.py
@@ -555,7 +555,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
         self.update(pol_id=rows)
 
     def _set_current_profile_raw_data(self):
-       return
+        return
 
     def _set_current_timestamp(self):
         timestamp = self._timestamps[self._slider_time.value()]
diff --git a/src/View/Results/translate.py b/src/View/Results/translate.py
index 11dc8b40..a2903b96 100644
--- a/src/View/Results/translate.py
+++ b/src/View/Results/translate.py
@@ -139,11 +139,14 @@ class ResultsTranslate(MainTranslate):
             "unit_thickness": self._dict["unit_thickness"],
             }
 
+
 class CompareResultsTranslate(ResultsTranslate):
     def __init__(self):
         super(CompareResultsTranslate, self).__init__()
 
-        self._dict['label_water'] = u"Δ "+_translate("Results", "Water elevation")
+        self._dict['label_water'] = u"Δ "+_translate(
+            "Results", "Water elevation"
+            )
         self._dict['unit_elevation'] = u"Δ "+self._dict["unit_elevation"]
 
         self._sub_dict["table_headers_raw_data"] = {
-- 
GitLab