nwm_region_mgr.utils.hydrofabric_utils.area_weighted_average#

nwm_region_mgr.utils.hydrofabric_utils.area_weighted_average(gdf_target, gdf_source, value_col, target_id_col='divide_id', crs_proj='EPSG:5070')[source]#

Map area-weighted average of value_col from source polygons to target polygons.

The function computes the area-weighted average of a specified attribute from source polygons (gdf_source) and assigns it to target polygons (gdf_target) based on their spatial intersection. It works in both directions: coarse-to-fine and fine-to-coarse.

Return type:

GeoDataFrame

Parameters:
  • gdf_target – GeoDataFrame with target polygons

  • gdf_source – GeoDataFrame with source polygons and the value to be averaged

  • value_col – Name of the column in gdf_source to average

  • target_id_col – Name of unique identifier column in gdf_target (default is ‘divide_id’)

  • crs_proj – Projected CRS (in meters) for accurate area computation (default is ‘EPSG:5070’)

Returns:

{value_col}_weighted

Return type:

gdf_target with a new column