From def3b750540dba42798d7162f919c5e31e703e06 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Wed, 3 Jan 2024 11:42:07 +0100
Subject: [PATCH] Factorize statements

---
 Overlap/plot_components.py | 48 +++++++++-----------------------------
 1 file changed, 11 insertions(+), 37 deletions(-)

diff --git a/Overlap/plot_components.py b/Overlap/plot_components.py
index 9b8c24e8..05f01276 100755
--- a/Overlap/plot_components.py
+++ b/Overlap/plot_components.py
@@ -150,20 +150,20 @@ if __name__ == "__main__":
 
     plt.figure()
 
-    if args.window is not None:
-        if args.time:
-            print("Reading edge list and SHPC...")
-            t0 = time.perf_counter()
+    if args.time:
+        print("Reading edge list and SHPC...")
+        t0 = time.perf_counter()
 
-        G = report_graph.read_eddy_graph(args.edgelist, args.shpc_dir,
-                                         args.orientation)
+    G = report_graph.read_eddy_graph(args.edgelist, args.shpc_dir,
+                                     args.orientation)
 
-        if args.time:
-            t1 = time.perf_counter()
-            print("Elapsed time:", t1 - t0, "s")
-            t0 = t1
-            print("Finding components...")
+    if args.time:
+        t1 = time.perf_counter()
+        print("Elapsed time:", t1 - t0, "s")
+        t0 = t1
+        print("Finding components...")
 
+    if args.window is not None:
         for n, d in G.nodes.items():
             if util_eddies.in_window(d["coordinates"], args.window):
                 if "component" not in d: report_graph.add_component(G, n)
@@ -178,19 +178,6 @@ if __name__ == "__main__":
         ax = plt.axes(projection = dest_crs)
         plot_all_components(G, label)
     elif args.node is not None:
-        if args.time:
-            print("Reading edge list and SHPC...")
-            t0 = time.perf_counter()
-
-        G = report_graph.read_eddy_graph(args.edgelist, args.shpc_dir,
-                                         args.orientation)
-
-        if args.time:
-            t1 = time.perf_counter()
-            print("Elapsed time:", t1 - t0, "s")
-            t0 = t1
-            print("Finding components...")
-
         report_graph.add_component(G, args.node)
 
         if args.time:
@@ -202,19 +189,6 @@ if __name__ == "__main__":
         ax = plt.axes(projection = dest_crs)
         plot_nbunch(G, G.nodes[args.node]["component"], label = label)
     else:
-        if args.time:
-            print("Reading edge list and SHPC...")
-            t0 = time.perf_counter()
-
-        G = report_graph.read_eddy_graph(args.edgelist, args.shpc_dir,
-                                         args.orientation)
-
-        if args.time:
-            t1 = time.perf_counter()
-            print("Elapsed time:", t1 - t0, "s")
-            t0 = t1
-            print("Finding components...")
-
         assign_all_components(G)
 
         if args.time:
-- 
GitLab