From 1ec62fd2e3867b3d83f1ab973926e4f84aac8ced Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 12 Sep 2023 12:52:33 +0200
Subject: [PATCH] Test `args.min_duration` outside the loop

Test `args.min_duration` outside the loop on `expanded_traj`. Clearer.
---
 Trajectories/plot_traj.py | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/Trajectories/plot_traj.py b/Trajectories/plot_traj.py
index 3853fe93..7b98f87c 100755
--- a/Trajectories/plot_traj.py
+++ b/Trajectories/plot_traj.py
@@ -80,25 +80,31 @@ if __name__ == "__main__":
     projection = ccrs.PlateCarree(central_longitude = 110)
     fig, ax = plt.subplots(subplot_kw = {"projection": projection})
     random.seed(0)
-    n_long_traj = 0
 
-    for traj in expanded_traj:
-        if args.min_duration > 1:
+    if args.min_duration == 1:
+        for traj in expanded_traj:
+            plot_single_traj(traj, e_overestim, SHPC, args.orientation, ax,
+                             src_crs, args.annotate)
+    else:
+        # args.min_duration > 1
+        n_long_traj = 0
+
+        for traj in expanded_traj:
             duration = report_graph.node_to_date_eddy(traj[- 1], e_overestim,
                                                       only_date = True) \
                 - report_graph.node_to_date_eddy(traj[0], e_overestim,
                                                  only_date = True)
-        if args.min_duration == 1 or duration >= args.min_duration:
-            if args.min_duration > 1: n_long_traj += 1
-            plot_single_traj(traj, e_overestim, SHPC, args.orientation, ax,
-                             src_crs, args.annotate)
 
-    ax.add_feature(cfeature.LAND, edgecolor = "black")
-    ax.gridlines(draw_labels = True)
+            if duration >= args.min_duration:
+                n_long_traj += 1
+                plot_single_traj(traj, e_overestim, SHPC, args.orientation, ax,
+                                 src_crs, args.annotate)
 
-    if args.min_duration > 1:
         print("Number of trajectories with sufficient duration:", n_long_traj)
 
+    ax.add_feature(cfeature.LAND, edgecolor = "black")
+    ax.gridlines(draw_labels = True)
+
     if args.save:
         plt.savefig(f"plot_traj.{args.save}")
         print(f'Created "plot_traj.{args.save}".')
-- 
GitLab