From cf983ab997b108a6570b89ff5c8789f649f2d340 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 12 Sep 2023 12:19:51 +0200
Subject: [PATCH] Create function `get_duration`

---
 Trajectories/plot_traj.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Trajectories/plot_traj.py b/Trajectories/plot_traj.py
index 42f005ee..49b366c3 100755
--- a/Trajectories/plot_traj.py
+++ b/Trajectories/plot_traj.py
@@ -2,6 +2,7 @@
 
 import report_graph
 import random
+import numpy as np
 
 def get_extr_coord(traj, e_overestim, SHPC, orientation):
     """Get the coordinates of the extrema of instantaneous eddies along a
@@ -37,6 +38,18 @@ def plot_single_traj(traj, e_overestim, SHPC, orientation, ax, src_crs,
                     xytext = (3 * random.random(), 3 * random.random()),
                     textcoords = "offset points")
 
+def get_duration(expanded_traj, e_overestim):
+    duration_list = []
+
+    for traj in expanded_traj:
+        init_date = report_graph.node_to_date_eddy(traj[0], e_overestim,
+                                                   only_date = True)
+        final_date = report_graph.node_to_date_eddy(traj[- 1], e_overestim,
+                                                    only_date = True)
+        duration_list.append(final_date - init_date)
+
+    return np.array(duration_list)
+
 if __name__ == "__main__":
     import util_eddies
     import matplotlib.pyplot as plt
-- 
GitLab