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

Do not loop on years

Since we no longer load all the contents of shapefiles for a given
year in advance, we no longer need to process the segments year by
year. Motivation: this will allow us to get free of the imposed
arborescence of SHPC by year.
parent 9ba75bf0
No related branches found
No related tags found
No related merge requests found
...@@ -120,132 +120,123 @@ for year in range(1993,2019): ...@@ -120,132 +120,123 @@ for year in range(1993,2019):
# change if there is a change over the number of days to average # change if there is a change over the number of days to average
num_of_days_to_avg = 7 num_of_days_to_avg = 7
# We iterate on the years because the segments are non sequential in # iterate on the vertices
# time. For each year, we are going to process only the segments that for n in g.vertices():
# begin in that year. # Get the segment and the number of days
for yr in range(1993, 2019): segment = g.vp.segment[n]
print(f'Current year: {yr}')
# calculate the indexes and dates
# iterate on the vertices first = report_graph.node_to_date_eddy(segment[0], e_overestim)
for n in g.vertices():
# Get the segment and the number of days # get year
segment = g.vp.segment[n] first_date = datetime.date(1950, 1, 1) \
+ datetime.timedelta(first['date_index'])
# calculate the indexes and dates first_year = first_date.year
first = report_graph.node_to_date_eddy(segment[0], e_overestim)
num_of_days = len(segment)
# get year
first_date = datetime.date(1950, 1, 1) \ # start processing
+ datetime.timedelta(first['date_index'])
first_year = first_date.year last = report_graph.node_to_date_eddy(segment[-1], e_overestim)
last_date = datetime.date(1950, 1, 1) \
# chech if we are in the current year + datetime.timedelta(last['date_index'])
last_year = last_date.year
if (first_year == yr):
num_of_days = len(segment) # calculate the location in the shapefile
first_loc = util_eddies.comp_ishape(handlers[first_year],
# start processing first['date_index'],
first['eddy_index'])
last = report_graph.node_to_date_eddy(segment[-1], e_overestim) last_loc = util_eddies.comp_ishape(handlers[last_year],
last_date = datetime.date(1950, 1, 1) \ last['date_index'],
+ datetime.timedelta(last['date_index']) last['eddy_index'])
last_year = last_date.year
# grab the centers
# calculate the location in the shapefile
first_loc = util_eddies.comp_ishape(handlers[first_year], first_pos = handlers[first_year]["readers"]["extremum"]\
first['date_index'], .shape(first_loc).points[0]
first['eddy_index']) last_pos = handlers[last_year]["readers"]["extremum"]\
last_loc = util_eddies.comp_ishape(handlers[last_year], .shape(last_loc).points[0]
last['date_index'],
last['eddy_index']) ##### STORE POSITIONS IN THE VPS ######
g.vp.pos_first[n] = first_pos # [deg, deg]
# grab the centers g.vp.pos_last[n] = last_pos # [deg, deg]
first_pos = handlers[first_year]["readers"]["extremum"]\ # if the segments are longer than the # of days over which to avg
.shape(first_loc).points[0]
last_pos = handlers[last_year]["readers"]["extremum"]\ if (num_of_days > num_of_days_to_avg):
.shape(last_loc).points[0] first_radii = 0 # [m]
last_radii = 0 # [m]
##### STORE POSITIONS IN THE VPS ######
g.vp.pos_first[n] = first_pos # [deg, deg] first_rossby = 0 # []
g.vp.pos_last[n] = last_pos # [deg, deg] last_rossby = 0 # []
# if the segments are longer than the # of days over which to avg # First 7 days calculation
first_res = calculate_radii_and_rossby(0, num_of_days_to_avg,
if (num_of_days > num_of_days_to_avg): 1, segment, e_overestim,
first_radii = 0 # [m] handlers)
last_radii = 0 # [m]
# average and assign radii
first_rossby = 0 # [] first_radii = first_res['radii'] / num_of_days_to_avg
last_rossby = 0 # [] g.vp.first_av_rad[n] = first_radii
# First 7 days calculation # grab the days modifier
first_res = calculate_radii_and_rossby(0, num_of_days_to_avg, modifier = first_res['days_modifier']
1, segment, e_overestim,
handlers) if (num_of_days_to_avg - modifier > 0):
# Average and assign the rossbies:
# average and assign radii first_rossby = first_res['rossby'] / (num_of_days_to_avg - modifier)
first_radii = first_res['radii'] / num_of_days_to_avg g.vp.first_av_ros[n] = first_rossby
g.vp.first_av_rad[n] = first_radii else:
# there is division by zero, average rossby is undefinied
# grab the days modifier pass
modifier = first_res['days_modifier']
# Last 7 days calculation
if (num_of_days_to_avg - modifier > 0): last_res = calculate_radii_and_rossby(len(segment) - 1,
# Average and assign the rossbies: len(segment) - (num_of_days_to_avg + 1),
first_rossby = first_res['rossby'] / (num_of_days_to_avg - modifier) -1,
g.vp.first_av_ros[n] = first_rossby segment, e_overestim,
else: handlers)
# there is division by zero, average rossby is undefinied
pass # Average and assign the last radii
last_radii = last_res['radii'] / num_of_days_to_avg
# Last 7 days calculation g.vp.last_av_rad[n] = last_radii
last_res = calculate_radii_and_rossby(len(segment) - 1,
len(segment) - (num_of_days_to_avg + 1),
-1, # grab the days modifier
segment, e_overestim, modifier = last_res['days_modifier']
handlers)
if (num_of_days_to_avg - modifier > 0):
# Average and assign the last radii # Average and assign the rossbies:
last_radii = last_res['radii'] / num_of_days_to_avg last_rossby = last_res['rossby'] / (num_of_days_to_avg - modifier)
g.vp.last_av_rad[n] = last_radii g.vp.last_av_ros[n] = last_rossby
else:
# there is division by zero, average rossby is undefinied
# grab the days modifier pass
modifier = last_res['days_modifier'] # else, the number of eddies in a segment is lower than the # of
# days over which to average, the values will be the same except
if (num_of_days_to_avg - modifier > 0): # for the positions
# Average and assign the rossbies: else:
last_rossby = last_res['rossby'] / (num_of_days_to_avg - modifier) res = calculate_radii_and_rossby(0, num_of_days, 1, segment,
g.vp.last_av_ros[n] = last_rossby e_overestim, handlers)
else:
# there is division by zero, average rossby is undefinied # grab the days modifier
pass modifier = res['days_modifier']
# else, the number of eddies in a segment is lower than the # of
# days over which to average, the values will be the same except if (num_of_days - modifier > 0):
# for the positions # Average and assign the rossbies:
else: rossby = res['rossby'] / (num_of_days - modifier)
res = calculate_radii_and_rossby(0, num_of_days, 1, segment, g.vp.first_av_ros[n] = rossby
e_overestim, handlers) g.vp.last_av_ros[n] = rossby
else:
# grab the days modifier # there is division by zero, average rossby is undefinied
modifier = res['days_modifier'] pass
if (num_of_days - modifier > 0): # Average and assign the radii
# Average and assign the rossbies:
rossby = res['rossby'] / (num_of_days - modifier) radii = res['radii'] / num_of_days
g.vp.first_av_ros[n] = rossby g.vp.first_av_rad[n] = radii
g.vp.last_av_ros[n] = rossby g.vp.last_av_rad[n] = radii
else:
# there is division by zero, average rossby is undefinied
pass
# Average and assign the radii
radii = res['radii'] / num_of_days
g.vp.first_av_rad[n] = radii
g.vp.last_av_rad[n] = radii
############################### ###############################
# Calculate the cost function # # Calculate the cost function #
############################### ###############################
......
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