Skip to content

Commit

Permalink
Merge branch 'main' of github.com:worldbank/GOSTurban into update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
elbeejay committed Feb 29, 2024
2 parents 8734791 + ab9ce32 commit 0bcd030
Show file tree
Hide file tree
Showing 8 changed files with 1,334 additions and 746 deletions.
107 changes: 52 additions & 55 deletions data/tutorial_data/hd_urban_extents.geojson

Large diffs are not rendered by default.

1,306 changes: 653 additions & 653 deletions data/tutorial_data/urban_extents.geojson

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ parts:
- caption: Documentation
chapters:
- file: api/GOSTurban.rst
- file: CONTRIBUTING
- caption: Novel Urbanization
chapters:
- file: novel_context
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"sphinx_jupyterbook_latex",
"sphinx.ext.napoleon",
"sphinxcontrib.apidoc",
#"nbsphinx"
]
external_toc_exclude_missing = True
external_toc_path = "_toc.yml"
Expand Down
1 change: 1 addition & 0 deletions docs/notebooks
56 changes: 56 additions & 0 deletions notebooks/Replications/URB_NovelUrbanization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sys, os, shutil, requests
import rasterio

import pandas as pd
import geopandas as gpd
import numpy as np

import GOSTurban.UrbanRaster as urban

def download_pop_file(url, filename):
# Open the url
r = requests.get(url)
# Set decode_content value to True, otherwise the downloaded image file's size will be zero.
r.raw.decode_content = True
# Open a local file with wb ( write binary ) permission.
with open(filename,'wb') as f:
shutil.copyfileobj(r.raw, f)

def main(iso3, out_folder):
# download the population data
wp_url = f'https://data.worldpop.org/GIS/Population/Global_2000_2020_1km/2020/{iso3.upper()}/{iso3.lower()}_ppp_2020_1km_Aggregated.tif'
print (wp_url)
if not os.path.exists(out_folder):
os.makedirs(out_folder)
out_file = os.path.join(out_folder, f'{iso3}_ppp_2020_1km_Aggregated.tif')
out_urban = os.path.join(out_folder, "urban_extents.geojson")
out_hd_urban = os.path.join(out_folder, "hd_urban_extents.geojson")

try:
if not os.path.exists(out_file):
download_pop_file(wp_url, out_file)
except:
print(f"Could not download national population data for {iso3} from {wp_url}")
print("If you can manually download to the defined out_folder, the script will run")
if os.path.exists(out_file):
inR = rasterio.open(out_file)
urban_calculator = urban.urbanGriddedPop(inR)
urban_extents = urban_calculator.calculateUrban(
densVal=300, totalPopThresh=5000, smooth=False, queen=False
)

hd_urban_extents = urban_calculator.calculateUrban(
densVal=1500,
totalPopThresh=50000,
smooth=True,
queen=True, # high density extents use queen's case contiguity, and are smoothed
)

urban_extents.to_file(out_urban, driver="GeoJSON")
hd_urban_extents.to_file(out_hd_urban, driver="GeoJSON")

if __name__ == "__main__":
iso3 = sys.argv[1]
out_folder = sys.argv[2]
main(iso3, out_folder)

198 changes: 180 additions & 18 deletions notebooks/Tutorials/LEI_Example.ipynb

Large diffs are not rendered by default.

410 changes: 391 additions & 19 deletions notebooks/Tutorials/UrbanAreas_tutorials.ipynb

Large diffs are not rendered by default.

0 comments on commit 0bcd030

Please sign in to comment.