{ "cells": [ { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "# raster to geodataframe #\n", "\n", "import geopandas as gpd\n", "import rasterio as rio\n", "from rasterio.plot import show\n", "from rasterio.features import geometry_mask\n", "from rasterio.mask import mask\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import os\n", "import glob\n", "import xarray as xr\n", "import rioxarray as rxr\n", "\n", "# path for output\n", "outputPath = r\"C:/Users/jtrum/Desktop/wb_outputs\"\n", "os.chdir(r'C:/Users/jtrum/world_bank/data/')\n", "aoi = gpd.read_file('aoiLuanda.geojson')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fathom \n", "**IHME (access to improved water sources)** \n", "**IHME (access to improved sanitation)** \n", "**IHME (reliance on open defecation)** \n", "HDSL (children) \n", "HDSL (elderly) \n", "HDSL (women of reproductive age) \n", "**WSF 2019 (built-up area)** " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### IHME (water)" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\jtrum\\AppData\\Local\\Temp\\ipykernel_17780\\2764959518.py:1: DeprecationWarning: open_rasterio is Deprecated in favor of rioxarray. For information about transitioning, see: https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html\n", " improved_water_sources = xr.open_rasterio(r\"C:/Users/jtrum/world_bank/data/IHME_LMIC_WASH_2000_2017_W_IMP_PERCENT_MEAN_2017_Y2020M06D02.tif\")\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "File saved to improved_water_sources_gdf_aoi.geojson\n" ] }, { "data": { "text/html": [ "
\n", " | latitude | \n", "longitude | \n", "pct | \n", "geometry | \n", "
---|---|---|---|---|
9977647 | \n", "-9.312501 | \n", "13.187516 | \n", "33.094032 | \n", "POINT (13.18752 -9.31250) | \n", "
9977646 | \n", "-9.312501 | \n", "13.145849 | \n", "37.536205 | \n", "POINT (13.14585 -9.31250) | \n", "
9971036 | \n", "-9.270834 | \n", "13.145849 | \n", "36.304882 | \n", "POINT (13.14585 -9.27083) | \n", "
9971037 | \n", "-9.270834 | \n", "13.187516 | \n", "36.074020 | \n", "POINT (13.18752 -9.27083) | \n", "
9964425 | \n", "-9.229168 | \n", "13.104183 | \n", "32.597126 | \n", "POINT (13.10418 -9.22917) | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
9885114 | \n", "-8.729168 | \n", "13.479183 | \n", "99.981781 | \n", "POINT (13.47918 -8.72917) | \n", "
9885116 | \n", "-8.729168 | \n", "13.562516 | \n", "98.460533 | \n", "POINT (13.56252 -8.72917) | \n", "
9878503 | \n", "-8.687501 | \n", "13.437516 | \n", "99.396202 | \n", "POINT (13.43752 -8.68750) | \n", "
9878505 | \n", "-8.687501 | \n", "13.520849 | \n", "96.345879 | \n", "POINT (13.52085 -8.68750) | \n", "
9878504 | \n", "-8.687501 | \n", "13.479183 | \n", "99.813766 | \n", "POINT (13.47918 -8.68750) | \n", "
116 rows × 4 columns
\n", "\n", " | pct | \n", "geometry | \n", "
---|---|---|
9977647 | \n", "28.999447 | \n", "POINT (13.18752 -9.31250) | \n", "
9977646 | \n", "21.648537 | \n", "POINT (13.14585 -9.31250) | \n", "
9971036 | \n", "26.851372 | \n", "POINT (13.14585 -9.27083) | \n", "
9971037 | \n", "27.775961 | \n", "POINT (13.18752 -9.27083) | \n", "
9964425 | \n", "26.202843 | \n", "POINT (13.10418 -9.22917) | \n", "
... | \n", "... | \n", "... | \n", "
9885114 | \n", "24.031370 | \n", "POINT (13.47918 -8.72917) | \n", "
9885116 | \n", "21.044580 | \n", "POINT (13.56252 -8.72917) | \n", "
9878503 | \n", "26.772446 | \n", "POINT (13.43752 -8.68750) | \n", "
9878505 | \n", "19.226595 | \n", "POINT (13.52085 -8.68750) | \n", "
9878504 | \n", "18.228943 | \n", "POINT (13.47918 -8.68750) | \n", "
116 rows × 2 columns
\n", "<xarray.DataArray (latitude: 22487, longitude: 22487)>\n", "[505665169 values with dtype=uint8]\n", "Coordinates:\n", " * latitude (latitude) float64 -7.99 -7.99 -7.99 ... -10.01 -10.01 -10.01\n", " * longitude (longitude) float64 11.99 11.99 11.99 11.99 ... 14.01 14.01 14.01\n", "Attributes:\n", " transform: (8.983152841195215e-05, 0.0, 11.989993760200077, 0.0, -8....\n", " crs: +proj=longlat +datum=WGS84 +no_defs=True\n", " res: (8.983152841195215e-05, 8.983152841195215e-05)\n", " is_tiled: 0\n", " nodatavals: (nan,)\n", " scales: (1.0,)\n", " offsets: (0.0,)\n", " AREA_OR_POINT: Area
\n", " | \n", " | built_up_area | \n", "
---|---|---|
latitude | \n", "longitude | \n", "\n", " |
-7.990020 | \n", "13.464713 | \n", "255 | \n", "
13.464803 | \n", "255 | \n", "|
13.464893 | \n", "255 | \n", "|
13.464983 | \n", "255 | \n", "|
13.465072 | \n", "255 | \n", "|
... | \n", "... | \n", "... | \n", "
-10.007726 | \n", "12.498485 | \n", "255 | \n", "
12.498575 | \n", "255 | \n", "|
12.630268 | \n", "255 | \n", "|
12.630358 | \n", "255 | \n", "|
12.630448 | \n", "255 | \n", "
49377713 rows × 1 columns
\n", "\n", " | latitude | \n", "longitude | \n", "built_up_area | \n", "
---|---|---|---|
0 | \n", "-7.990020 | \n", "13.464713 | \n", "255 | \n", "
1 | \n", "-7.990020 | \n", "13.464803 | \n", "255 | \n", "
2 | \n", "-7.990020 | \n", "13.464893 | \n", "255 | \n", "
3 | \n", "-7.990020 | \n", "13.464983 | \n", "255 | \n", "
4 | \n", "-7.990020 | \n", "13.465072 | \n", "255 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
49377708 | \n", "-10.007726 | \n", "12.498485 | \n", "255 | \n", "
49377709 | \n", "-10.007726 | \n", "12.498575 | \n", "255 | \n", "
49377710 | \n", "-10.007726 | \n", "12.630268 | \n", "255 | \n", "
49377711 | \n", "-10.007726 | \n", "12.630358 | \n", "255 | \n", "
49377712 | \n", "-10.007726 | \n", "12.630448 | \n", "255 | \n", "
49377713 rows × 3 columns
\n", "\n", " | geometry | \n", "built | \n", "
---|---|---|
0 | \n", "POINT (13.46471 -7.99002) | \n", "True | \n", "
1 | \n", "POINT (13.46480 -7.99002) | \n", "True | \n", "
2 | \n", "POINT (13.46489 -7.99002) | \n", "True | \n", "
3 | \n", "POINT (13.46498 -7.99002) | \n", "True | \n", "
4 | \n", "POINT (13.46507 -7.99002) | \n", "True | \n", "
... | \n", "... | \n", "... | \n", "
49377708 | \n", "POINT (12.49849 -10.00773) | \n", "True | \n", "
49377709 | \n", "POINT (12.49857 -10.00773) | \n", "True | \n", "
49377710 | \n", "POINT (12.63027 -10.00773) | \n", "True | \n", "
49377711 | \n", "POINT (12.63036 -10.00773) | \n", "True | \n", "
49377712 | \n", "POINT (12.63045 -10.00773) | \n", "True | \n", "
49377713 rows × 2 columns
\n", "\n", " | geometry | \n", "built | \n", "
---|---|---|
0 | \n", "POINT (-7.99002 13.46471) | \n", "True | \n", "
1 | \n", "POINT (-7.99002 13.46480) | \n", "True | \n", "
2 | \n", "POINT (-7.99002 13.46489) | \n", "True | \n", "
3 | \n", "POINT (-7.99002 13.46498) | \n", "True | \n", "
4 | \n", "POINT (-7.99002 13.46507) | \n", "True | \n", "
... | \n", "... | \n", "... | \n", "
49377708 | \n", "POINT (-10.00773 12.49849) | \n", "True | \n", "
49377709 | \n", "POINT (-10.00773 12.49857) | \n", "True | \n", "
49377710 | \n", "POINT (-10.00773 12.63027) | \n", "True | \n", "
49377711 | \n", "POINT (-10.00773 12.63036) | \n", "True | \n", "
49377712 | \n", "POINT (-10.00773 12.63045) | \n", "True | \n", "
49377713 rows × 2 columns
\n", "\n", " | NAME_1 | \n", "GID_0 | \n", "COUNTRY | \n", "GID_1 | \n", "NL_NAME_1 | \n", "GID_2 | \n", "NAME_2 | \n", "VARNAME_2 | \n", "NL_NAME_2 | \n", "TYPE_2 | \n", "ENGTYPE_2 | \n", "CC_2 | \n", "HASC_2 | \n", "geometry | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "MULTIPOLYGON (((13.01919 -9.02194, 13.02049 -9... | \n", "
\n", " | geometry | \n", "built | \n", "index_right | \n", "NAME_1 | \n", "GID_0 | \n", "COUNTRY | \n", "GID_1 | \n", "NL_NAME_1 | \n", "GID_2 | \n", "NAME_2 | \n", "VARNAME_2 | \n", "NL_NAME_2 | \n", "TYPE_2 | \n", "ENGTYPE_2 | \n", "CC_2 | \n", "HASC_2 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
15924125 | \n", "POINT (13.41441 -8.63807) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
16025943 | \n", "POINT (13.41522 -8.63968) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
16025944 | \n", "POINT (13.41531 -8.63968) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
16025945 | \n", "POINT (13.41540 -8.63968) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
16031698 | \n", "POINT (13.41522 -8.63977) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
48886381 | \n", "POINT (13.15426 -9.34297) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
48886382 | \n", "POINT (13.15435 -9.34297) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
48886383 | \n", "POINT (13.15443 -9.34297) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
48886384 | \n", "POINT (13.15452 -9.34297) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
48886385 | \n", "POINT (13.15461 -9.34297) | \n", "True | \n", "0 | \n", "Luanda | \n", "AGO | \n", "Angola | \n", "AGO.11_1 | \n", "NA | \n", "AGO.11.1_1 | \n", "Cacuaco | \n", "NA | \n", "NA | \n", "Município | \n", "Municpality|City Council | \n", "1108 | \n", "AO.LU.CC | \n", "
5539893 rows × 16 columns
\n", "