From a5dc120f96dd8828d9f356ffd7321970e30c3d43 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 13 Feb 2024 19:37:05 +0100
Subject: [PATCH] Manage slices other than slice 0

---
 Overlap/report_graph.py | 42 ++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/Overlap/report_graph.py b/Overlap/report_graph.py
index 50a90ab2..594fe479 100755
--- a/Overlap/report_graph.py
+++ b/Overlap/report_graph.py
@@ -40,14 +40,19 @@ def read_eddy_graph(edgelist, shpc_dir=None, orientation="Cyclones"):
 
 
 def set_attribute(G, SHPC, orientation):
-    reader = SHPC.get_reader(0, orientation, "extremum")
-
-    if G.number_of_nodes() <= SHPC.get_n_shapes(0, orientation) / 100:
+    if (
+        G.number_of_nodes()
+        <= SHPC.get_n_shapes(0, orientation) * SHPC.n_slices / 100
+    ):
         for n in G:
             date_index, eddy_index = util_eddies.node_to_date_eddy(
                 n, G.graph["e_overestim"]
             )
-            ishape = SHPC.comp_ishape(date_index, eddy_index, 0, orientation)
+            i_slice = SHPC.get_slice(date_index)
+            ishape = SHPC.comp_ishape(
+                date_index, eddy_index, i_slice, orientation
+            )
+            reader = SHPC.get_reader(i_slice, orientation, "extremum")
             shape_rec = reader.shapeRecord(ishape)
             G.add_node(
                 n,
@@ -56,21 +61,24 @@ def set_attribute(G, SHPC, orientation):
                 ssh=shape_rec.record.ssh,
             )
     else:
-        for shape_rec in reader:
-            n = util_eddies.date_eddy_to_node(
-                shape_rec.record.date,
-                shape_rec.record.eddy_index,
-                G.graph["e_overestim"],
-            )
-
-            if n in G:
-                G.add_node(
-                    n,
-                    coordinates=tuple(shape_rec.shape.points[0]),
-                    speed=shape_rec.record.speed,
-                    ssh=shape_rec.record.ssh,
+        for i_slice in range(SHPC.n_slices):
+            reader = SHPC.get_reader(i_slice, orientation, "extremum")
+
+            for shape_rec in reader:
+                n = util_eddies.date_eddy_to_node(
+                    shape_rec.record.date,
+                    shape_rec.record.eddy_index,
+                    G.graph["e_overestim"],
                 )
 
+                if n in G:
+                    G.add_node(
+                        n,
+                        coordinates=tuple(shape_rec.shape.points[0]),
+                        speed=shape_rec.record.speed,
+                        ssh=shape_rec.record.ssh,
+                    )
+
 
 def partition_graph_date(A, e_overestim):
     """Add subgraphs in pygraphviz graph, one subgraph for each date. We
-- 
GitLab