Skip to content

Commit

Permalink
resolve new conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
elbeejay committed Jun 14, 2024
2 parents e755db6 + 6050ebb commit 2a44a11
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 0 deletions.
108 changes: 108 additions & 0 deletions notebooks/Implementations/MENA_Benchmarking/NTL_zonal_stats.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Benchmarking cities in MENA\n",
"\n",
"In support of an upcoming Urban flagship report, the MENA team is looking for a series of zonal statistics:\n",
"\n",
"- Nighttime Lights, Population, and built-area: \n",
" - Entire FUA \n",
" - Its associated urban center / “core” \n",
" - Associated “periphery” \n",
"\n",
"The unit of analysis is the Functional Urban Areas (FUAs) from the [UCDB Database](https://human-settlement.emergency.copernicus.eu/ghs_stat_ucdb2015mt_r2019a.php). For each FUA, we need to grab the associated urban periphary (lower threshold urban areas)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"\n",
"import geopandas as gpd\n",
"\n",
"\n",
"sys.path.append(\"C:/WBG/Work/Code/GOSTrocks/src\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_folder = \"C:/WBG/Work/data\"\n",
"ucdb_file = os.path.join(\n",
" data_folder,\n",
" \"URBAN\",\n",
" \"GHS_STAT_UCDB2015MT_GLOBE_R2019A\",\n",
" \"GHS_STAT_UCDB2015MT_GLOBE_R2019A_V1_2.gpkg\",\n",
")\n",
"fua_file = os.path.join(\n",
" data_folder, \"URBAN\", \"GHS_FUA_UCDB2015_GLOBE_R2019A_54009_1K_V1_0.gpkg\"\n",
")\n",
"\n",
"out_folder = \"C:/WBG/Work/MENA_Urban/\"\n",
"urban_res_folder = os.path.join(out_folder, \"urban_data\")\n",
"\n",
"for out_folder in [urban_res_folder]:\n",
" if not os.path.exists(out_folder):\n",
" os.makedirs(out_folder)\n",
"\n",
"urban_periphary_file = os.path.join(urban_res_folder, \"urban_periphary.gpkg\")\n",
"urban_core_file = os.path.join(urban_res_folder, \"urban_core.gpkg\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"inD = gpd.read_file(ucdb_file)\n",
"inF = gpd.read_file(fua_file)\n",
"inD = inD.to_crs(inF.crs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"inF.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fua_peripheries = inF.copy()\n",
"for idx, row in inF.iterrows():\n",
" # grab the related UCDBs\n",
" ucdb_ids = row[\"UC_IDs\"].split(\";\")\n",
" ucdb_ids = [int(x) for x in ucdb_ids]\n",
" sel_cores = inD.loc[inD[\"ID_HDC_G0\"].isin(ucdb_ids)]\n",
" periphery_geom = row[\"geometry\"].difference(sel_cores.unary_union)\n",
" fua_peripheries.loc[idx, \"geometry\"] = periphery_geom\n",
"\n",
"fua_peripheries.to_file(os.path.join(out_folder, \"FUA_peripheries.gpkg\"), driver=\"GPKG\")"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
131 changes: 131 additions & 0 deletions notebooks/Implementations/URB_LKA_CCDR_Support/LKA_Urban_Comp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "9fd5e3dd",
"metadata": {},
"source": [
"# Urbanization comparison\n",
"\n",
"Compare the multiple urban extents in the project\n",
"\n",
"1. Official administrative boundaries provided by the project team. \n",
" a. Need to get metadata on these boundaries from Swati \n",
"2. Official administrative boundaries with buffers \n",
" a. Why these specific buffer distances? \n",
"3. DoU boundaries \n",
" a. Which population source \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c6da02f",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import rasterio\n",
"\n",
"import pandas as pd\n",
"import geopandas as gpd\n",
"\n",
"import GOSTurban.UrbanRaster as urban"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df1bf2ed",
"metadata": {},
"outputs": [],
"source": [
"base_folder = \"C:/WBG/Work/LKA_URB_CCDR/Data\"\n",
"urban_folder = os.path.join(base_folder, \"Urban_extents\")\n",
"population_folder = os.path.join(base_folder, \"Population\")\n",
"\n",
"worldpop_file = os.path.join(population_folder, \"lka_ppp_2020_UNadj.tif\")\n",
"combo_extents = os.path.join(urban_folder, \"combo_extents.shp\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b135cd57",
"metadata": {},
"outputs": [],
"source": [
"# Combine all the urban extents into a single file\n",
"if not os.path.exists(combo_extents):\n",
" urban_extents = [\n",
" x\n",
" for x in os.listdir(os.path.join(urban_folder, \"Final_AoI\"))\n",
" if x.endswith(\".shp\")\n",
" ]\n",
" all_extents = []\n",
" for urban_extent in urban_extents:\n",
" urban_extent_gdf = gpd.read_file(\n",
" os.path.join(urban_folder, \"Final_AoI\", urban_extent)\n",
" )\n",
" type = urban_extent.split(\"_\")[1].replace(\".shp\", \"\").lower()\n",
" if type == \"colombo\":\n",
" type = \"city\"\n",
" if \"buffer\" in urban_extent:\n",
" type = \"20km\"\n",
" urban_extent_gdf[\"Type\"] = type\n",
" all_extents.append(urban_extent_gdf)\n",
"\n",
" all_extents_gdf = gpd.GeoDataFrame(pd.concat(all_extents, ignore_index=True))\n",
" all_extents_gdf.to_file(combo_extents)\n",
"else:\n",
" all_extents_gdf = gpd.read_file(combo_extents)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97add9be",
"metadata": {},
"outputs": [],
"source": [
"# extract urban extents from population grids\n",
"for pop_layer, name in [[worldpop_file, \"WorldPop\"]]:\n",
" urb_out_file = os.path.join(urban_folder, \"DOU_urb_extent_%s.shp\" % name)\n",
" hd_out_file = os.path.join(urban_folder, \"DOU_hd_extent_%s.shp\" % name)\n",
" if not os.path.exists(hd_out_file):\n",
" curPop = rasterio.open(pop_layer)\n",
" urban_calculator = urban.urbanGriddedPop(curPop)\n",
" urban_extents = urban_calculator.calculateUrban(\n",
" densVal=3, totalPopThresh=5000, smooth=False, queen=False, verbose=True\n",
" )\n",
" urban_extents[\"Type\"] = name\n",
" urban_extents.to_file(urb_out_file)\n",
"\n",
" hd_urban_extents = urban_calculator.calculateUrban(\n",
" densVal=15,\n",
" totalPopThresh=50000,\n",
" smooth=True,\n",
" queen=True, # high density extents use queen's case contiguity, and\n",
" verbose=True,\n",
" ) # High density extents have hole smoothing applied.\n",
" hd_urban_extents[\"Type\"] = name\n",
" hd_urban_extents.to_file(hd_out_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "50115a0d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
12 changes: 12 additions & 0 deletions notebooks/Implementations/URB_LKA_CCDR_Support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Urbanization for CCDR

The Sri Lanka CCDR team is looking for support in urban deep dives on 9 provincial capitals. The following analysis will be completed:

| Analysis | Phase | Notebook | Plan |
| --- | --- | --- | --- |
| Urbanization analysis | 1 | | Compare official and buffered boundaries to quantified boundaries (DoU); summarize population within all boundaries |
| Urban expansion | 1 | | Summariuze GHSL within urban extents |
| Urban Poverty | 3 | | Analyze high-resolution satellite imagery to identify informality in residential settlements |
| Urban economics | 2 | | Summarize monthly nighttime lights |
| Status of infrastructure | 2 | | TBD |
| GHG emissions | 1 | | Summarize Brian B's GHG emissions data |

0 comments on commit 2a44a11

Please sign in to comment.