From 34424ccdb9f5c726875e0caa4c44a6c9c6fa76fe Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 7 May 2024 21:59:44 +0200
Subject: [PATCH] Polish

---
 Common/util_eddies.py                             | 15 +++++++++------
 Inst_eddies/Analysis/anim_eddy_contours.py        |  6 +++++-
 Inst_eddies/Analysis/plot_eddy_contours.py        |  1 +
 .../Documentation_texfol/documentation.tex        | 10 +++-------
 .../Documentation_texfol/documentation.tex        |  6 ++++++
 Trajectories/cost_function.py                     |  2 +-
 6 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/Common/util_eddies.py b/Common/util_eddies.py
index 57e330ad..470b8904 100644
--- a/Common/util_eddies.py
+++ b/Common/util_eddies.py
@@ -27,7 +27,7 @@ class SHPC_class:
         self.dir = SHPC_dir
         self.def_orient = def_orient
 
-        # Define self.n_slices:
+        # <begin> Define self.n_slices
 
         fname = path.join(SHPC_dir, "n_slices.txt")
 
@@ -53,11 +53,13 @@ class SHPC_class:
                 with open(fname, "w", encoding="utf-8") as f:
                     f.write(f"{self.n_slices}\n")
 
+        # <end> Define self.n_slices
+
         self._readers = [
             {"Anticyclones": {}, "Cyclones": {}} for i in range(self.n_slices)
         ]
 
-        # Define self.d_init:
+        # <begin> Define self.d_init
 
         self.d_init = []
 
@@ -65,6 +67,7 @@ class SHPC_class:
             my_shapefile = path.join(
                 SHPC_dir, f"Slice_{i_slice}", def_orient, "extremum"
             )
+
             try:
                 reader[def_orient]["extremum"] = shapefile.Reader(my_shapefile)
             except shapefile.ShapefileException:
@@ -88,6 +91,8 @@ class SHPC_class:
 
             self.d_init.append(d_init_slice)
 
+        # <end> Define self.d_init
+
         self._ishape_last = [
             {"Anticyclones": None, "Cyclones": None}
             for i in range(self.n_slices)
@@ -104,7 +109,6 @@ class SHPC_class:
         ishape_last = self.get_ishape_last(self.n_slices - 1, self.def_orient)
 
         self.n_dates = np.ediff1d(self.d_init, to_end=ishape_last.size)
-
         self._i_slice = []
 
         for i_slice, n_dates in enumerate(self.n_dates):
@@ -126,7 +130,6 @@ class SHPC_class:
             fname = path.join(
                 self.dir, f"Slice_{i_slice}", orientation, "ishape_last.txt"
             )
-            print("Reading", fname, "...")
 
             try:
                 self._ishape_last[i_slice][orientation] = np.loadtxt(
@@ -224,8 +227,8 @@ class SHPC_class:
     def comp_ishape(self, date, eddy_index, orientation):
         """Compute the location in the shapefiles: return `(i_slice, ishape)`.
 
-        Returns None if ishape_last is None. Returns None if
-        eddy_index is greater than the maximum value.
+        Returns None if ishape_last is None or eddy_index is greater
+        than the maximum value.
 
         """
 
diff --git a/Inst_eddies/Analysis/anim_eddy_contours.py b/Inst_eddies/Analysis/anim_eddy_contours.py
index 9d6bc3da..e97fc08b 100755
--- a/Inst_eddies/Analysis/anim_eddy_contours.py
+++ b/Inst_eddies/Analysis/anim_eddy_contours.py
@@ -58,7 +58,11 @@ def func(d, ax, i_slices, ishape_lists_all, SHPC, bbox, light):
 
 
 def anim_eddies(fig, ax, SHPC, window, d_min, d_max, light):
-    """SHPC is an instance of SHPC_class."""
+    """SHPC is an instance of SHPC_class. We define i_slices and
+    ishape_lists_all[orientation] here rather than in func because we
+    need them to compute bbox.
+
+    """
 
     ishape_lists_all = {}
     i_slices = {}
diff --git a/Inst_eddies/Analysis/plot_eddy_contours.py b/Inst_eddies/Analysis/plot_eddy_contours.py
index 263977fd..6e1292c7 100755
--- a/Inst_eddies/Analysis/plot_eddy_contours.py
+++ b/Inst_eddies/Analysis/plot_eddy_contours.py
@@ -21,6 +21,7 @@ import numpy as np
 from cartopy.mpl import geoaxes
 import cartopy.crs as ccrs
 from matplotlib import patches
+
 import util_eddies
 
 
diff --git a/Inst_eddies/Documentation_texfol/documentation.tex b/Inst_eddies/Documentation_texfol/documentation.tex
index c1459578..c0e801a2 100644
--- a/Inst_eddies/Documentation_texfol/documentation.tex
+++ b/Inst_eddies/Documentation_texfol/documentation.tex
@@ -115,7 +115,7 @@ Cf. algorithme \ref{alg:principal}.
 \label{sec:identification}
 
 Instantaneous eddies (also called occurences of eddies) with a given
-orientation may be identified in four ways:
+orientation may be identified in three ways:
 \begin{itemize}
 \item By a couple date index $d$ and eddy index $e$ at that date
   index. This is the way eddies are identified in program
@@ -131,10 +131,6 @@ orientation may be identified in four ways:
   created by program \verb+inst_eddies+. It is used in program
   \verb+eddy_graph+. It is also used in Python scripts to determine
   trajectories and to analyze and plot the results.
-\item By a vertex index in the abstract graph of instantaneous eddies
-  and in the abstract graph of segments. The vertex index is defined
-  and used by the graph software, graph-tool. It appears in the file
-  \verb+traj_vert_ind.json+ created by script \verb+trajectories.py+.
 \end{itemize}
 
 The date index $d$ is an integer value. It is a number of time steps
@@ -160,8 +156,8 @@ The intra-date eddy indices $e$ for eddies at date index $d$ start at 1 and
 increment 1 by 1, without any jump. So they go from 1 to
 $e_\mathrm{max}(d)$.
 
-The relation between inter-date index $n$, date index $d$ and intra-date eddy index $e$
-is:
+The relation between inter-date index $n$, date index $d$ and
+intra-date eddy index $e$ is:
 \begin{equation*}
   n = d E + e
 \end{equation*}
diff --git a/Trajectories/Documentation_texfol/documentation.tex b/Trajectories/Documentation_texfol/documentation.tex
index c255725b..079caaf1 100644
--- a/Trajectories/Documentation_texfol/documentation.tex
+++ b/Trajectories/Documentation_texfol/documentation.tex
@@ -181,6 +181,12 @@ segment isolé.
 La révision 6f5bb0c1 donne exactement le même résultat que la 787726e0
 sur le graphe global 1993-2020.
 
+A segment may be identified by a vertex index in the abstract graph of
+segments. The vertex index is defined and used by the graph software,
+graph-tool. Is is between 0 and $N - 1$ where $N$ is the number of
+vertices in the graph. It appears in the file
+\verb+traj_vert_ind.json+ created by script \verb+trajectories.py+.
+
 \section{Script \texttt{trajectory.py}}
 
 Les trajectoires sont presque toujours, mais pas toujours, des
diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py
index 857376ca..38b312d0 100755
--- a/Trajectories/cost_function.py
+++ b/Trajectories/cost_function.py
@@ -63,7 +63,7 @@ def calculate_radii_rossby(properties):
 
 
 def node_to_prop(node_list, e_overestim, SHPC, orientation):
-    """node_list is a list of node identification numbers for
+    """node_list is a list of inter-date identification numbers for
     instantaneous eddies. This function returns some properties of the
     eddies, read from shapefiles: position of extremum, radius of
     outermost contour or maximum speed contour, and speed. The three
-- 
GitLab