From 034d96fecdab975da30e1b056dd3e87636658b22 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Thu, 10 Jun 2021 17:20:05 +0200
Subject: [PATCH] Use function `open_shpc`

---
 Inst_eddies/Analysis/eddy_dump.py | 37 +++++++++++++++----------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/Inst_eddies/Analysis/eddy_dump.py b/Inst_eddies/Analysis/eddy_dump.py
index 532f03c4..be08feca 100755
--- a/Inst_eddies/Analysis/eddy_dump.py
+++ b/Inst_eddies/Analysis/eddy_dump.py
@@ -10,6 +10,8 @@ import shapefile
 from os import path
 import pprint
 import sys
+sys.path.append(path.join(sys.path[0], "../../Common"))
+import util_detect_eddies
 
 parser = argparse.ArgumentParser()
 parser.add_argument("directory", help = "containing the three shapefiles")
@@ -19,27 +21,24 @@ reply = input("days_1950, eddy_index = ? ").split(",")
 days_1950 = int(reply[0])
 eddy_index = int(reply[1])
 
-# Find ishape:
-filename = path.join(args.directory, "extremum")
+readers, d_init, ishape_last = util_detect_eddies.open_shpc(args.directory)
 
-with shapefile.Reader(filename) as f:
-    for ishape, rec in enumerate(f.iterRecords()):
-        if rec["days_1950"] == days_1950 and rec["eddy_index"] == eddy_index:
-            break
-    else:
-        sys.exit("Not found")
+# Find ishape:
+for ishape, rec in enumerate(readers["extremum"].iterRecords()):
+    if rec["days_1950"] == days_1950 and rec["eddy_index"] == eddy_index:
+        break
+else:
+    sys.exit("Not found")
 #--
         
 for basename in ["extremum", "outermost_contour", "max_speed_contour"]:
     filename = path.join(args.directory, basename)
-    
-    with shapefile.Reader(filename) as f:
-        shapeRec = f.shapeRecord(ishape)
-        print("\n", filename, ":")
-
-        if shapeRec.shape.shapeType == shapefile.NULL:
-            dct = shapeRec.record.as_dict()
-            pprint.pprint(dct)
-            print("null shape")
-        else:
-            pprint.pprint(shapeRec.__geo_interface__)
+    shapeRec = readers[basename].shapeRecord(ishape)
+    print("\n", filename, ":")
+
+    if shapeRec.shape.shapeType == shapefile.NULL:
+        dct = shapeRec.record.as_dict()
+        pprint.pprint(dct)
+        print("null shape")
+    else:
+        pprint.pprint(shapeRec.__geo_interface__)
-- 
GitLab