Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 21, 2025
1 parent ab60b77 commit 3d54369
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 18,581 deletions.
7,711 changes: 10 additions & 7,701 deletions notebooks/Implementations/MENA_Benchmarking/FUA_ADMIN_Pop.ipynb

Large diffs are not rendered by default.

109 changes: 34 additions & 75 deletions notebooks/Implementations/MENA_Benchmarking/GHSL_POP_zonal_stats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c9e93d9c",
"execution_count": null,
"id": "0",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/wb411133/.conda/envs/ee/lib/python3.9/site-packages/geopandas/_compat.py:106: UserWarning: The Shapely GEOS version (3.9.1-CAPI-1.14.2) is incompatible with the GEOS version PyGEOS was compiled with (3.10.4-CAPI-1.16.2). Conversions between both will be slow.\n",
" warnings.warn(\n"
]
}
],
"outputs": [],
"source": [
"import sys\n",
"import os\n",
Expand All @@ -25,57 +16,45 @@
"\n",
"sys.path.append(\"/home/wb411133/Code/GOSTrocks/src\")\n",
"\n",
"import GOSTrocks.ntlMisc as ntlMisc\n",
"import GOSTrocks.rasterMisc as rMisc\n",
"from GOSTrocks.misc import tPrint"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f808de90",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"data_folder = \"s3://wbg-geography01/URBANIZATION/MENA/Extents/\"\n",
"ucdb_file = \"/home/wb411133/Code/GOSTurban/GHS_STAT_UCDB2015MT_GLOBE_R2019A_V1_2.gpkg\"\n",
"fua_file = os.path.join(data_folder, \"GHS_FUA_UCDB2015_GLOBE_R2019A_54009_1K_V1_0.gpkg\")\n",
"ucdb_file = \"/home/wb411133/Code/GOSTurban/GHS_STAT_UCDB2015MT_GLOBE_R2019A_V1_2.gpkg\"\n",
"fua_file = os.path.join(data_folder, \"GHS_FUA_UCDB2015_GLOBE_R2019A_54009_1K_V1_0.gpkg\")\n",
"fua_peripheries = os.path.join(data_folder, \"FUA_peripheries.gpkg\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3f1ec746",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"inP = gpd.read_file(fua_peripheries)\\ninP = inP.to_crs(inU.crs)\\ninP['geometry'] = inP.buffer(0)\\n\""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"inU = gpd.read_file(ucdb_file)\n",
"# If the peripheries exists read them in, if not, create them\n",
"inF = gpd.read_file(fua_file)\n",
"inF = inF.to_crs(inU.crs)\n",
"\n",
"'''inP = gpd.read_file(fua_peripheries)\n",
"\"\"\"inP = gpd.read_file(fua_peripheries)\n",
"inP = inP.to_crs(inU.crs)\n",
"inP['geometry'] = inP.buffer(0)\n",
"'''"
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f954d4c4",
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -86,7 +65,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d9caba75",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -107,29 +86,29 @@
" tPrint(\"Reprojected Cores\")\n",
" # Run zonal on FUA\n",
" fua_res = rMisc.zonalStats(inF, inR, minVal=0, maxVal=10000)\n",
" fua_res = pd.DataFrame(fua_res, columns = ['SUM', 'MIN', 'MAX', 'MEAN'])\n",
" fua_zonal[f'ghsl_{year}'] = fua_res['SUM']\n",
" fua_res = pd.DataFrame(fua_res, columns=[\"SUM\", \"MIN\", \"MAX\", \"MEAN\"])\n",
" fua_zonal[f\"ghsl_{year}\"] = fua_res[\"SUM\"]\n",
" # Run zonal on core\n",
" core_res = rMisc.zonalStats(inU, inR, minVal=0, maxVal=10000)\n",
" core_res = pd.DataFrame(fua_res, columns = ['SUM', 'MIN', 'MAX', 'MEAN'])\n",
" core_zonal[f'ghsl_{year}'] = core_res['SUM']\n",
" core_res = pd.DataFrame(fua_res, columns=[\"SUM\", \"MIN\", \"MAX\", \"MEAN\"])\n",
" core_zonal[f\"ghsl_{year}\"] = core_res[\"SUM\"]\n",
" tPrint(f\"Completed {year}\")\n",
"core_zonal.to_csv(core_res_file) \n",
"core_zonal.to_csv(core_res_file)\n",
"fua_zonal.to_csv(fua_res_file)"
]
},
{
"cell_type": "markdown",
"id": "e9115976",
"id": "5",
"metadata": {},
"source": [
"# Population stats"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f646421c",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -139,11 +118,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "71bc0155",
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"'''# Downlaod and unzip GHS_POP data\n",
"\"\"\"# Downlaod and unzip GHS_POP data\n",
"import urllib.request\n",
"import zipfile\n",
"url_path_base = \"https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_POP_GLOBE_R2023A/GHS_POP_E{year}_GLOBE_R2023A_54009_1000/V1-0/GHS_POP_E{year}_GLOBE_R2023A_54009_1000_V1_0.zip\"\n",
Expand All @@ -161,35 +140,15 @@
"for zip_file in zip_files:\n",
" os.remove(os.path.join(ghs_pop_folder, zip_file))\n",
" \n",
"'''"
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "703c8903",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10:55:26\tReprojected FUAs\n",
"10:55:26\tReprojected Cores\n",
"10:56:08\tCompleted 2030\n",
"10:56:50\tCompleted 1975\n",
"10:57:32\tCompleted 1980\n",
"10:58:14\tCompleted 1985\n",
"10:58:56\tCompleted 1990\n",
"10:59:38\tCompleted 1995\n",
"11:00:21\tCompleted 2000\n",
"11:01:03\tCompleted 2005\n",
"11:01:44\tCompleted 2010\n",
"11:02:23\tCompleted 2015\n",
"11:03:03\tCompleted 2020\n"
]
}
],
"outputs": [],
"source": [
"out_folder = \"s3://wbg-geography01/URBANIZATION/MENA/ZONAL_RES/GHSPop\"\n",
"fua_res_file = os.path.join(out_folder, \"fua_ghspop_zonal.csv\")\n",
Expand All @@ -209,21 +168,21 @@
" tPrint(\"Reprojected Cores\")\n",
" # Run zonal on FUA\n",
" fua_res = rMisc.zonalStats(inF, inR, minVal=0)\n",
" fua_res = pd.DataFrame(fua_res, columns = ['SUM', 'MIN', 'MAX', 'MEAN'])\n",
" fua_zonal[f'ghs_pop_{year}'] = fua_res['SUM']\n",
" fua_res = pd.DataFrame(fua_res, columns=[\"SUM\", \"MIN\", \"MAX\", \"MEAN\"])\n",
" fua_zonal[f\"ghs_pop_{year}\"] = fua_res[\"SUM\"]\n",
" # Run zonal on core\n",
" core_res = rMisc.zonalStats(inU, inR, minVal=0, maxVal=10000)\n",
" core_res = pd.DataFrame(fua_res, columns = ['SUM', 'MIN', 'MAX', 'MEAN'])\n",
" core_zonal[f'ghs_pop_{year}'] = core_res['SUM']\n",
" core_res = pd.DataFrame(fua_res, columns=[\"SUM\", \"MIN\", \"MAX\", \"MEAN\"])\n",
" core_zonal[f\"ghs_pop_{year}\"] = core_res[\"SUM\"]\n",
" tPrint(f\"Completed {year}\")\n",
"core_zonal.to_csv(core_res_file) \n",
"core_zonal.to_csv(core_res_file)\n",
"fua_zonal.to_csv(fua_res_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f02642c",
"id": "9",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit 3d54369

Please sign in to comment.