Commit 28929517 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Added verbose option to generate_country_industrial_cells

parent 80be8100
......@@ -1222,6 +1222,7 @@ def generate_country_industrial_cells(
in_crs="EPSG:4326",
consistency_tol_dist=0.05,
consistency_tol_area=0.05,
verbose=False,
):
"""This function reads the input aggregated exposure model of the country (location defined
by aggr_model_pathname and country), identifies the unique points present in this input
......@@ -1316,6 +1317,8 @@ def generate_country_industrial_cells(
range, which is calculated as ([max-min]/mean) of all
cells. Default: 0.05. Only needed if consistency_checks is
True.
verbose (bool): if True, print statements will be executed to describe progress in the
calculations. Default = False.
Returns:
cells_adj_bound_gdf (GeoDataFrame): GeoPandas GeoDataFrame with the cells defined around
......@@ -1394,6 +1397,8 @@ def generate_country_industrial_cells(
# Retrieve unique points in the exposure file, determined with a specific precision
# (points_gdf is a GeoPandas GeoDataFrame, ids_aggr is an array of strings with length
# equal to the number of rows of aggr_mod_df):
if verbose:
print(" Building cells from input points...")
points_gdf, ids_aggr = retrieve_unique_points(
aggr_mod_df, col_lon, col_lat, id_str, precision=precision_points, in_crs=in_crs
)
......@@ -1423,6 +1428,8 @@ def generate_country_industrial_cells(
# Adjust all the coordinates of the corners of the cells (coords_dict) by taking the
# average value of all instances of that coordinate that "should be the same", as identified
# in coords_uq:
if verbose:
print(" Adjusting cells' geometries...")
coords_dict_adj = adjust_coords(coords_dict, coords_uq) # coords_dict_adj is a dictionary
# Generate final output with adjusted cell geometries (cells_adj_gdf is a
......@@ -1436,7 +1443,11 @@ def generate_country_industrial_cells(
big_dist_diff = "Not_Checked"
big_area_diff = "Not_Checked"
else:
if verbose:
print(" Running consistency checks...")
# Consistency check 1: the output geometries should not overlap
if verbose:
print(" Consistency check #1 of 4...")
num_overlaps = 999 # Initialise variable for the while loop to run at least once
while num_overlaps > 0:
intsect_gdf = overlap_by_full_geom_intersection(cells_adj_gdf, "id_1", "id_2")
......@@ -1461,6 +1472,8 @@ def generate_country_industrial_cells(
overlap_found = "False"
# Consistency check 2:
if verbose:
print(" Consistency check #2 of 4...")
gaps_found = True # Initialise variable for the while loop to run at least once
while gaps_found:
# Expand the cells by 25% of their dimensions in all directions:
......@@ -1499,6 +1512,8 @@ def generate_country_industrial_cells(
gap_found = str(gaps_found)
# Consistency check 3: maximum distance between original points and final centroids:
if verbose:
print(" Consistency check #3 of 4...")
max_dist_centr = get_distance_centroids(cells_adj_gdf, col_lon, col_lat)
# Compare the maximum distance against the tolerance:
if max_dist_centr > min(width_EW, width_NS) * consistency_tol_dist:
......@@ -1507,6 +1522,8 @@ def generate_country_industrial_cells(
big_dist_diff = "False"
# Consistency check 4: stability/variability of area of resulting cells:
if verbose:
print(" Consistency check #4 of 4...")
rel_area_range = get_relative_area_range(cells_gdf)
# Compare the relative area range ([max-min]/mean) against the tolerance:
if rel_area_range > consistency_tol_area:
......@@ -1515,6 +1532,8 @@ def generate_country_industrial_cells(
big_area_diff = "False"
# Intersect cells with admnistrative boundary of country:
if verbose:
print(" Intersecting cells with admnistrative boundary of country...")
cells_adj_bound_gdf = gpd.overlay(cells_adj_gdf, bounds_gdf, how="intersection")
# Eliminate columns that are not useful:
if "ID_0" in cells_adj_bound_gdf.columns:
......@@ -1536,6 +1555,9 @@ def generate_country_industrial_cells(
cells_adj_bound_gdf["lat_s"].values[row] = geometry_row.bounds[1]
cells_adj_bound_gdf["lat_n"].values[row] = geometry_row.bounds[3]
if verbose:
print(" generate_country_industrial_cells has finished generating the cells")
return (
cells_adj_bound_gdf,
aggr_mod_df,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment