From 201c752287c3d7d5dd3131dd70cb05b45d8c83ce Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Tue, 28 May 2024 19:37:10 +0200 Subject: [PATCH] Define `ip_beg` and `ip_end` This does not change any result, it is just an equivalent formulation. We are preparing for a generalization of the choice of `ip_beg` and `ip_end`. --- Trajectories/cost_function.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py index b6681c92..0c09635c 100755 --- a/Trajectories/cost_function.py +++ b/Trajectories/cost_function.py @@ -174,41 +174,44 @@ print("Iterating on vertices...") for n in g.vertices(): if n.in_degree() != 0: # Define properties for beginning of the segment: + ip_beg = min(n_days_avg, len(g.vp.inst_eddies[n])) properties = node_to_prop( - g.vp.inst_eddies[n][:n_days_avg], + g.vp.inst_eddies[n][:ip_beg], g.gp.e_overestim, SHPC, args.orientation, ) first_av_rad[n], first_av_ros[n] = calculate_radii_rossby(properties) pos_first[n] = properties[0]["pos"] # in rad + else: + ip_beg = 0 if n.out_degree() != 0: # Define properties for end of the segment: len_seg = len(g.vp.inst_eddies[n]) - if n.in_degree() == 0 or len_seg > n_days_avg: + if ip_beg < len_seg: # We have to read more from the shapefiles and redefine # properties. + ip_end = max(len_seg - n_days_avg, 0) - if n.in_degree() == 0 or len_seg >= 2 * n_days_avg: + if ip_beg <= ip_end: # We cannot use part of properties from the beginning # of the segment. properties = node_to_prop( - g.vp.inst_eddies[n][-n_days_avg:], + g.vp.inst_eddies[n][ip_end:], g.gp.e_overestim, SHPC, args.orientation, ) else: - # assertion: n.in_degree() != 0 and n_days_avg < - # len_seg < 2 * n_days_avg + # assertion: ip_end < ip_beg < len_seg # We can use part of the properties from the beginning # of the segment. - properties = properties[len_seg - n_days_avg:] + node_to_prop( - g.vp.inst_eddies[n][n_days_avg:], + properties = properties[ip_end:] + node_to_prop( + g.vp.inst_eddies[n][ip_beg:], g.gp.e_overestim, SHPC, args.orientation, -- GitLab