-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
7,992 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7,834 changes: 7,834 additions & 0 deletions
7,834
notebooks/Implementations/MENA_Benchmarking/FUA_ADMIN_Pop.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
notebooks/Implementations/MENA_Benchmarking/Pop-weighted-RWI.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys, os\n", | ||
"import rasterio\n", | ||
"\n", | ||
"import pandas as pd\n", | ||
"import geopandas as gpd\n", | ||
"\n", | ||
"from shapely.geometry import Point\n", | ||
"from pyquadkey2 import quadkey\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"meta_pop_geotiff = \"s3://dataforgood-fb-data/hrsl-cogs/hrsl_general/hrsl_general-latest.vrt\"\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
40 changes: 40 additions & 0 deletions
40
notebooks/Implementations/MENA_Benchmarking/admin_pop_functions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import GOSTrocks.rasterMisc as rMisc | ||
import pandas as pd | ||
|
||
def calculate_admin_pop(city, admin_bounds, popR, | ||
city_id = 'eFUA_ID', city_name = 'eFUA_name'): | ||
"""_summary_ | ||
Parameters | ||
---------- | ||
city_shape : _type_ | ||
_description_ | ||
admin_bounds : _type_ | ||
_description_ | ||
popR : _type_ | ||
_description_ | ||
""" | ||
|
||
# Identify admin regions that intersect with the FUA, clip them, and calculate zonal stats | ||
sel_admin = admin_bounds.loc[admin_bounds.intersects(city['geometry'])].copy() | ||
sel_admin['geometry'] = sel_admin['geometry'].apply(lambda x: x.intersection(city['geometry'])) | ||
cur_zonal = rMisc.zonalStats(sel_admin, popR, minVal=0) | ||
cur_zonal = pd.DataFrame(cur_zonal, columns=['SUM', 'MIN', 'MAX', 'MEAN']) | ||
cur_zonal['per_city_pop'] = cur_zonal['SUM'] / cur_zonal['SUM'].sum() | ||
|
||
# For those intersecting admin regions, calculate the percentage of their population outside the city | ||
sel_admin = admin_bounds.loc[admin_bounds.intersects(city['geometry'])].copy() | ||
total_pop = rMisc.zonalStats(sel_admin, popR, minVal=0) | ||
total_pop = pd.DataFrame(total_pop, columns=['SUM', 'MIN', 'MAX', 'MEAN']) | ||
sel_admin['geometry'] = sel_admin['geometry'].apply(lambda x: x.difference(city['geometry'])) | ||
not_city_pop = rMisc.zonalStats(sel_admin, popR, minVal=0) | ||
not_city_pop = pd.DataFrame(not_city_pop, columns=['SUM', 'MIN', 'MAX', 'MEAN']) | ||
not_city_pop['admin_pop'] = total_pop['SUM'] | ||
not_city_pop['per_not_city'] = not_city_pop['SUM'] / not_city_pop['admin_pop'] | ||
|
||
# Concat results | ||
admin_res = pd.DataFrame(sel_admin.drop(columns=['geometry']).copy()) | ||
admin_res = pd.concat([admin_res.reset_index(), cur_zonal.drop(['SUM','MIN','MAX','MEAN'], axis=1), not_city_pop.drop(['admin_pop','SUM','MIN','MAX','MEAN'], axis=1)], axis=1) | ||
admin_res['city_id'] = city[city_id] | ||
admin_res['city_name'] = city[city_name] | ||
return(admin_res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ elevation | |
geojson | ||
hatch | ||
git | ||
richdem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters