From 294e1e59e0291bd273550464daf8b79512f665b4 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Fri, 29 Apr 2022 23:31:06 +0200
Subject: [PATCH] Remove intermediary variable segment

---
 cost_function.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/cost_function.py b/cost_function.py
index 6ba78fcd..2598bfbc 100755
--- a/cost_function.py
+++ b/cost_function.py
@@ -145,23 +145,22 @@ print("Iterating on vertices...")
 
 for n in g.vertices():
     if n.in_degree() != 0 or n.out_degree() != 0:
-        segment = g.vp.inst_eddies[n]
-        len_seg = len(segment)
+        len_seg = len(g.vp.inst_eddies[n])
 
         if len_seg > n_days_avg:
             # The segment is longer than the number of days over which
             # to average
 
             # First 7 days calculation
-            properties = node_to_prop(segment[:n_days_avg], e_overestim,
-                                      array_d_init, handlers)
+            properties = node_to_prop(g.vp.inst_eddies[n][:n_days_avg],
+                                      e_overestim, array_d_init, handlers)
             g.vp.first_av_rad[n], g.vp.first_av_ros[n] \
                 = calculate_radii_rossby(properties)
             g.vp.pos_first[n] = properties[0]["pos"] # in degrees
 
             # Last 7 days calculation:
-            properties = node_to_prop(segment[- n_days_avg:], e_overestim,
-                                      array_d_init, handlers)
+            properties = node_to_prop(g.vp.inst_eddies[n][- n_days_avg:],
+                                      e_overestim, array_d_init, handlers)
             g.vp.last_av_rad[n], g.vp.last_av_ros[n] \
                 = calculate_radii_rossby(properties)
             g.vp.pos_last[n] = properties[- 1]["pos"] # in degrees
@@ -170,8 +169,8 @@ for n in g.vertices():
             # equal to the number of days over which to average. The
             # values for the end of the segment will be the same as
             # for the begining, except for the position.
-            properties = node_to_prop(segment, e_overestim, array_d_init,
-                                      handlers)
+            properties = node_to_prop(g.vp.inst_eddies[n], e_overestim,
+                                      array_d_init, handlers)
             g.vp.first_av_rad[n], g.vp.first_av_ros[n] \
                 = calculate_radii_rossby(properties)
             g.vp.last_av_rad[n] = g.vp.first_av_rad[n]
-- 
GitLab