diff --git a/gt_segmented_cf.py b/gt_segmented_cf.py index fd3ddc85fea1a75e9926b8ec34562146db093adc..de1db6f03174339828d514408e160f73aad5a640 100644 --- a/gt_segmented_cf.py +++ b/gt_segmented_cf.py @@ -18,21 +18,12 @@ from os import path import shapefile import datetime from numpy import loadtxt +import report_graph ###################### # Utility functions: # ###################### -def node_to_date_eddy(node_index, e_overestim, d_init): - """Convert from node identification in graph to eddy identification in - shapefiles. - - """ - k = (node_index - 1) // e_overestim - d = d_init + k - return {"eddy_index": node_index - k * e_overestim, "date_index": k, - "days_1950": d} - def comp_ishape(d_init, ishape_last, days_1950, eddy_index): k = days_1950 - d_init @@ -47,7 +38,7 @@ def comp_ishape(d_init, ishape_last, days_1950, eddy_index): # Necessary functions # ####################### -def calculate_radii_and_rossby(start, end, inc, segment, e_overestim, d_init, ext_shp_rcd, max_rcd, ishape_last): +def calculate_radii_and_rossby(start, end, inc, segment, e_overestim, ext_shp_rcd, max_rcd, ishape_last): radii = 0 #[m] rossby = 0 #[1/s] @@ -55,14 +46,14 @@ def calculate_radii_and_rossby(start, end, inc, segment, e_overestim, d_init, ex days_modifier = 0 for i in range(start, end, inc): - current_eddy = node_to_date_eddy(segment[i], e_overestim, d_init) - date = datetime.date(1950,1,1) + datetime.timedelta(current_eddy['days_1950']) + current_eddy = report_graph.node_to_date_eddy(segment[i], e_overestim) + date = datetime.date(1950,1,1) + datetime.timedelta(current_eddy['date_index']) year = date.year # calculate the location in the shapefile d_init_1 = ext_shp_rcd[year][0].record[1] location = comp_ishape(d_init_1, ishape_last[year], - current_eddy['days_1950'], current_eddy['eddy_index']) + current_eddy['date_index'], current_eddy['eddy_index']) # now that we have the location in the shapefiles, we need to get the radius and the rossby number @@ -89,14 +80,13 @@ def calculate_radii_and_rossby(start, end, inc, segment, e_overestim, d_init, ex return {"radii": radii, "rossby": rossby, "days_modifier": days_modifier} ############################### -# grab e_overestim and d_init # +# grab e_overestim ############################### node_id_param_file = "/data/misic/Convert_Global/node_id_param.json" with open(node_id_param_file) as f: node_id_param = json.load(f) # assign attributes to the whole graphs e_overestim = node_id_param["e_overestim"] -d_init = node_id_param["d_init"] ################################################ # set some values needed for the cost function # @@ -192,13 +182,13 @@ for yr in range(1993, 2019): segment = g.vp.segment[n] # calculate the indexes and dates - first = node_to_date_eddy(segment[0], e_overestim, d_init) + first = report_graph.node_to_date_eddy(segment[0], e_overestim) # get days since 1950 - first_days = first['days_1950'] + first_days = first['date_index'] # get year - first_date = datetime.date(1950,1,1) + datetime.timedelta(first['days_1950']) + first_date = datetime.date(1950,1,1) + datetime.timedelta(first['date_index']) first_year = first_date.year #print(f'Segment size: {len(segment)}, first: {first_year}, last: {last_year}, yr: {yr}') @@ -213,10 +203,10 @@ for yr in range(1993, 2019): first_pos = [] last_pos = [] - last = node_to_date_eddy(segment[-1], e_overestim, d_init) - last_days = last['days_1950'] + last = report_graph.node_to_date_eddy(segment[-1], e_overestim) + last_days = last['date_index'] - last_date = datetime.date(1950,1,1) + datetime.timedelta(last['days_1950']) + last_date = datetime.date(1950,1,1) + datetime.timedelta(last['date_index']) last_year = last_date.year print(f'Segment size: {len(segment)}, first: {first_year}, last: {last_year}, yr: {yr}') @@ -226,8 +216,8 @@ for yr in range(1993, 2019): d_init_1 = ext_shp_rcd[first_year][0].record[1] d_init_2 = ext_shp_rcd[last_year][0].record[1] - first_loc = comp_ishape(d_init_1, ishape_last[first_year], first['days_1950'], first['eddy_index']) - last_loc = comp_ishape(d_init_2, ishape_last[last_year], last['days_1950'], last['eddy_index']) + first_loc = comp_ishape(d_init_1, ishape_last[first_year], first['date_index'], first['eddy_index']) + last_loc = comp_ishape(d_init_2, ishape_last[last_year], last['date_index'], last['eddy_index']) # grab the centers @@ -249,7 +239,7 @@ for yr in range(1993, 2019): # First 7 days calculation first_res = calculate_radii_and_rossby(0, num_of_days_to_avg, 1, segment, e_overestim, - d_init, ext_shp_rcd, max_rcd, ishape_last) + ext_shp_rcd, max_rcd, ishape_last) # average and assign radii first_radii = first_res['radii'] / num_of_days_to_avg @@ -269,7 +259,7 @@ for yr in range(1993, 2019): # Last 7 days calculation last_res = calculate_radii_and_rossby(len(segment) - 1, len(segment) - (num_of_days_to_avg + 1), -1, - segment, e_overestim, d_init, ext_shp_rcd, + segment, e_overestim, ext_shp_rcd, max_rcd, ishape_last) # Average and assign the last radii @@ -292,7 +282,7 @@ for yr in range(1993, 2019): # for the positions else: res = calculate_radii_and_rossby(0, num_of_days, 1, segment, e_overestim, - d_init, ext_shp_rcd, max_rcd, ishape_last) + ext_shp_rcd, max_rcd, ishape_last) # grab the days modifier modifier = res['days_modifier']