Skip to content
Snippets Groups Projects
Commit bdd0ce41 authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Rewrite the loop on vertices

Motivation: performance. We eliminate repeated reading of the same
information from the shapefiles. If the length of the segment is
smaller than 14 days then we re-use for the last part of the segment
some of the properties from the first part. Also, we do not compute
properties for the first part of the segment if the segment has no
predecessor and for the last part of the segment if the segment has no
successor.
parent 294e1e59
No related branches found
No related tags found
No related merge requests found
...@@ -144,39 +144,49 @@ n_days_avg = 7 # number of days to average ...@@ -144,39 +144,49 @@ n_days_avg = 7 # number of days to average
print("Iterating on vertices...") print("Iterating on vertices...")
for n in g.vertices(): for n in g.vertices():
if n.in_degree() != 0 or n.out_degree() != 0: if n.in_degree() != 0:
len_seg = len(g.vp.inst_eddies[n]) # Define properties for beginning of the segment:
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
if len_seg > n_days_avg: if n.out_degree() != 0:
# The segment is longer than the number of days over which # Define properties for end of the segment:
# to average
# First 7 days calculation len_seg = len(g.vp.inst_eddies[n])
properties = node_to_prop(g.vp.inst_eddies[n][:n_days_avg],
e_overestim, array_d_init, handlers) if n.in_degree() == 0 or len_seg > n_days_avg:
g.vp.first_av_rad[n], g.vp.first_av_ros[n] \ # We have to read more from the shapefiles and redefine
= calculate_radii_rossby(properties) # properties.
g.vp.pos_first[n] = properties[0]["pos"] # in degrees
if n.in_degree() == 0 or len_seg > 2 * n_days_avg:
# We cannot use part of properties from the beginning
# of the segment.
properties = node_to_prop(g.vp.inst_eddies[n][- n_days_avg:],
e_overestim, array_d_init, handlers)
else:
# assertion: n.in_degree() != 0 and n_days_avg <
# len_seg < 2 * n_days_avg
# 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:],
e_overestim, array_d_init, handlers)
# Last 7 days calculation:
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] \ g.vp.last_av_rad[n], g.vp.last_av_ros[n] \
= calculate_radii_rossby(properties) = calculate_radii_rossby(properties)
g.vp.pos_last[n] = properties[- 1]["pos"] # in degrees
else: else:
# The number of eddies in the segment is lower than or # The number of eddies in the segment is lower than or
# equal to the number of days over which to average. The # equal to the number of days over which to average. The
# values for the end of the segment will be the same as # values for the end of the segment will be the same as
# for the begining, except for the position. # for the begining, except for the position.
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] g.vp.last_av_rad[n] = g.vp.first_av_rad[n]
g.vp.last_av_ros[n] = g.vp.first_av_ros[n] g.vp.last_av_ros[n] = g.vp.first_av_ros[n]
g.vp.pos_first[n] = properties[0]["pos"] # in degrees
g.vp.pos_last[n] = properties[- 1]["pos"] # in degrees g.vp.pos_last[n] = properties[- 1]["pos"] # in degrees
t1 = time.perf_counter() t1 = time.perf_counter()
timings.write(f"iterating on vertices: {t1 - t0:.0f} s\n") timings.write(f"iterating on vertices: {t1 - t0:.0f} s\n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment