From a4b582661221ba04609d3d8ac9c754b34dec7740 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Mon, 19 Jun 2023 16:45:52 +0200
Subject: [PATCH] Invert order of arguments orientation and layer

Invert order of dummy arguments orientation and layer of method
`get_reader`. Take the same order than in the path. `orientation` was at
the end because, at first, in commit d858fb7, it was an optional
argument.
---
 Common/util_eddies.py                      |  7 +++----
 Inst_eddies/Analysis/anim_eddy_contours.py |  4 ++--
 Inst_eddies/Analysis/eddy_dump.py          |  2 +-
 Inst_eddies/Analysis/plot_eddy_contours.py | 14 ++++++--------
 Inst_eddies/Analysis/write_date_range.py   |  6 +++---
 Overlap/report_graph.py                    |  2 +-
 Trajectories/cost_function.py              | 11 ++++++-----
 Trajectories/plot_traj.py                  |  4 ++--
 8 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/Common/util_eddies.py b/Common/util_eddies.py
index 571df9c0..adb82000 100644
--- a/Common/util_eddies.py
+++ b/Common/util_eddies.py
@@ -126,7 +126,7 @@ class SHPC_class:
 
         return self._ishape_last[i_slice][orientation]
 
-    def get_reader(self, i_slice, layer, orientation):
+    def get_reader(self, i_slice, orientation, layer):
         if layer not in self._readers[i_slice][orientation]:
             my_shapefile = path.join(self.dir, f"Slice_{i_slice}", orientation,
                                      layer)
@@ -143,8 +143,7 @@ class SHPC_class:
 
     def get_n_shapes(self, i_slice, orientation):
         if self._n_shapes[i_slice][orientation] == 0:
-            reader = self.get_reader(i_slice, layer = "extremum",
-                                     orientation = orientation)
+            reader = self.get_reader(i_slice, orientation, layer = "extremum")
             self._n_shapes[i_slice][orientation] = len(reader)
 
         return self._n_shapes[i_slice][orientation]
@@ -154,7 +153,7 @@ class SHPC_class:
 
         last_date = self.d_init[i_slice]
         date_ishape = [] # list of tuples (date, ishape)
-        reader = self.get_reader(i_slice, "extremum", orientation)
+        reader = self.get_reader(i_slice, orientation, "extremum")
 
         if reader is None:
             print('Could not create "ishape_last.txt".')
diff --git a/Inst_eddies/Analysis/anim_eddy_contours.py b/Inst_eddies/Analysis/anim_eddy_contours.py
index f7b7d7e3..b3d79ae5 100755
--- a/Inst_eddies/Analysis/anim_eddy_contours.py
+++ b/Inst_eddies/Analysis/anim_eddy_contours.py
@@ -60,8 +60,8 @@ def anim_eddies(fig, ax, SHPC, window, d_min, d_max, light):
         
         for orientation in ["Anticyclones", "Cyclones"]:
             b2 = compute_bbox(ishape_lists_all[orientation],
-                              SHPC.get_reader(0, "outermost_contour",
-                                              orientation))
+                              SHPC.get_reader(0, orientation,
+                                              "outermost_contour"))
             bbox = bbox_union(bbox, b2)
     else:
         bbox = window
diff --git a/Inst_eddies/Analysis/eddy_dump.py b/Inst_eddies/Analysis/eddy_dump.py
index 53454c02..6f1ca5d0 100755
--- a/Inst_eddies/Analysis/eddy_dump.py
+++ b/Inst_eddies/Analysis/eddy_dump.py
@@ -44,7 +44,7 @@ for layer in ["extremum", "outermost_contour", "max_speed_contour", "centroid"]:
     print()
 
     try:
-        shapeRec = SHPC.get_reader(0, layer, args.orientation)\
+        shapeRec = SHPC.get_reader(0, args.orientation, layer)\
                        .shapeRecord(ishape)
     except AttributeError:
         pass
diff --git a/Inst_eddies/Analysis/plot_eddy_contours.py b/Inst_eddies/Analysis/plot_eddy_contours.py
index a4ef1d35..3f2b500c 100755
--- a/Inst_eddies/Analysis/plot_eddy_contours.py
+++ b/Inst_eddies/Analysis/plot_eddy_contours.py
@@ -39,8 +39,7 @@ def select_ishapes(d: int, SHPC: util_eddies.SHPC_class, i_slice: int,
         ishape_list_filt = ishape_list
     else:
         ishape_list_filt = []
-        reader = SHPC.get_reader(i_slice, layer = "extremum",
-                                 orientation = orientation)
+        reader = SHPC.get_reader(i_slice, orientation, layer = "extremum")
 
         for ishape in ishape_list:
             points = reader.shape(ishape).points[0]
@@ -67,12 +66,11 @@ def snapshot(ax: geoaxes.GeoAxesSubplot, ishape_list, SHPC, i_slice,
         color_outer = "red"
         color_m_s = "magenta"
 
-    reader_extr = SHPC.get_reader(i_slice, layer = "extremum",
-                                  orientation = orientation)
-    reader_outer = SHPC.get_reader(i_slice, layer = "outermost_contour",
-                                   orientation = orientation)
-    reader_m_s = SHPC.get_reader(i_slice, layer = "max_speed_contour",
-                                 orientation = orientation)
+    reader_extr = SHPC.get_reader(i_slice, orientation, layer = "extremum")
+    reader_outer = SHPC.get_reader(i_slice, orientation,
+                                   layer = "outermost_contour")
+    reader_m_s = SHPC.get_reader(i_slice, orientation,
+                                 layer = "max_speed_contour")
 
     for ishape in ishape_list:
         shape_rec_extr = reader_extr.shapeRecord(ishape)
diff --git a/Inst_eddies/Analysis/write_date_range.py b/Inst_eddies/Analysis/write_date_range.py
index 55fd8ccb..024af703 100755
--- a/Inst_eddies/Analysis/write_date_range.py
+++ b/Inst_eddies/Analysis/write_date_range.py
@@ -29,9 +29,9 @@ os.makedirs(slice_dir)
 for orientation in ["Anticyclones", "Cyclones"]:
     orient_dir = path.join(slice_dir, orientation)
     os.mkdir(orient_dir)
-    extremum = SHPC.get_reader(i_slice, "extremum", orientation)
-    outermost_cont = SHPC.get_reader(i_slice, "outermost_contour", orientation)
-    max_speed_cont = SHPC.get_reader(i_slice, "max_speed_contour", orientation)
+    extremum = SHPC.get_reader(i_slice, orientation, "extremum")
+    outermost_cont = SHPC.get_reader(i_slice, orientation, "outermost_contour")
+    max_speed_cont = SHPC.get_reader(i_slice, orientation, "max_speed_contour")
     fname = path.join(orient_dir, "ishape_last.txt")
 
     with shapefile.Writer(path.join(orient_dir, "extremum")) as extremum_filt, \
diff --git a/Overlap/report_graph.py b/Overlap/report_graph.py
index f501370a..d26d5f31 100755
--- a/Overlap/report_graph.py
+++ b/Overlap/report_graph.py
@@ -46,7 +46,7 @@ def read_eddy_graph(edgelist, shpc_dir = None, orientation = "Cyclones"):
     return G
 
 def set_attribute(G, SHPC, orientation):
-    reader = SHPC.get_reader(0, "extremum", orientation)
+    reader = SHPC.get_reader(0, orientation, "extremum")
 
     if G.number_of_nodes() <= SHPC.get_n_shapes(0, orientation) / 100:
         for n in G:
diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py
index 444995d9..d2e54704 100755
--- a/Trajectories/cost_function.py
+++ b/Trajectories/cost_function.py
@@ -69,15 +69,16 @@ def node_to_prop(node_list, e_overestim, SHPC, orientation):
         date_index, eddy_index = report_graph.node_to_date_eddy(n, e_overestim)
         i_slice = SHPC.get_slice(date_index)
         ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice, orientation)
-        shapeRec = SHPC.get_reader(i_slice, "extremum", orientation)\
+        shapeRec = SHPC.get_reader(i_slice, orientation, "extremum")\
                        .shapeRecord(ishape)
         prop = {"pos": shapeRec.shape.points[0], "speed": shapeRec.record.speed}
-        prop["radius"] = SHPC.get_reader(i_slice, "max_speed_contour",
-                                         orientation).record(ishape).r_eq_area
+        prop["radius"] \
+            = SHPC.get_reader(i_slice, orientation, "max_speed_contour")\
+                  .record(ishape).r_eq_area
 
         if prop["radius"] < 0:
-            prop["radius"] = SHPC.get_reader(i_slice, "outermost_contour",
-                                             orientation)\
+            prop["radius"] = SHPC.get_reader(i_slice, orientation,
+                                             "outermost_contour")\
                 .record(ishape).r_eq_area
 
         properties.append(prop)
diff --git a/Trajectories/plot_traj.py b/Trajectories/plot_traj.py
index 3898e483..3b8392e5 100755
--- a/Trajectories/plot_traj.py
+++ b/Trajectories/plot_traj.py
@@ -12,8 +12,8 @@ def get_extr_coord(traj, e_overestim, SHPC, orientation):
                                                                 e_overestim)
         i_slice = SHPC.get_slice(date_index)
         ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice, orientation)
-        shape = SHPC.get_reader(i_slice, layer = "extremum",
-                                orientation = orientation).shape(ishape)
+        shape = SHPC.get_reader(i_slice, orientation, layer = "extremum")\
+                    .shape(ishape)
         x.append(shape.points[0][0])
         y.append(shape.points[0][1])
 
-- 
GitLab