Skip to content

Commit

Permalink
Attempting pypi upload (#11)
Browse files Browse the repository at this point in the history
* Attempting pypi upload

* Include dependencies

* Remove setup.py

* Reorganize docs

* Update gitignore

* Update README

* Update CODE_OF_CONDUCT

---------

Co-authored-by: bpstewar <bstewart@worldbank.org>
Co-authored-by: Gabriel Stefanini Vicente <gvicente@worldbank.org>
Co-authored-by: Gabriel Stefanini Vicente <github@g4brielvs.me>
  • Loading branch information
4 people authored Feb 26, 2024
1 parent eaa4886 commit 8171bcc
Show file tree
Hide file tree
Showing 106 changed files with 410 additions and 29,160 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ dmypy.json

# Pyre type checker
.pyre/

# Project-specific
_build/
docs/api/
src/GOSTurban/_version.py
90 changes: 49 additions & 41 deletions Notebooks/Tutorials/UrbanAreas_tutorials.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run simple urban extent calculation based on 1km gridded population data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -11,31 +18,40 @@
"\n",
"import geopandas as gpd\n",
"\n",
"sys.path.append(\"../../../\")\n",
"\n",
"import src.GOST_Urban.UrbanRaster as urban\n"
"import GOST_Urban.UrbanRaster as urban\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Cannot find header.dxf (GDAL_DATA is not defined)\n"
]
}
],
"source": [
"# Define input population raster\n",
"tutorial_folder = \"../../data/tutorial_data\"\n",
"aoi_file = os.path.join(tutorial_folder, \"AOI.geojson\")\n",
"pop_file = os.path.join(tutorial_folder, \"wp_2020_1k_AOI.tif\")\n",
"\n",
"# Define output files\n",
"out_urban = os.path.join(tutorial_folder, \"urban_extents.geojson\")\n",
"out_hd_urban = os.path.join(tutorial_folder, \"hd_urban_extents.geojson\")\n",
"\n",
"inAOI = gpd.read_file(aoi_file)\n",
"\n",
"# Shouldn't need to execute this unless you change your AOI\n",
"# Shouldn't need to execute this unless you change your AOI; \n",
"# you will need to find a global population to extract from\n",
"if not os.path.exists(pop_file):\n",
" sys.path.append(\"../../../gostrocks/src\")\n",
" import GOSTRocks.rasterMisc as rMisc\n",
" global_population = \"/home/public/Data/GLOBAL/Population/WorldPop_PPP_2020/ppp_2020_1km_Aggregated.tif\"\n",
" global_population = \"/path/to/global/pop_layer/ppp_2020_1km_Aggregated.tif\"\n",
" inR = rasterio.open(global_population)\n",
" rMisc.clipRaster(inR, inAOI, pop_file)\n",
" \n",
Expand All @@ -44,73 +60,65 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# calculate urban\n",
"# Initiate the urban calculator\n",
"urban_calculator = urban.urbanGriddedPop(inR)\n",
"urban_calculator.calculateUrban?"
"#urban_calculator.calculateUrban?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11:17:01\t: Read in urban data\n",
"11:17:03\t: Creating Shape 0\n",
"11:17:07\t: Creating Shape 1000\n",
"11:17:11\t: Creating Shape 2000\n",
"11:17:15\t: Creating Shape 3000\n",
"11:17:19\t: Creating Shape 4000\n",
"11:17:23\t: Creating Shape 5000\n",
"11:17:27\t: Creating Shape 6000\n"
]
}
],
"outputs": [],
"source": [
"# Extract the urban extents (minimum density 300/km2, minimum total population 5000)\n",
"urban_extents = urban_calculator.calculateUrban(densVal=300, totalPopThresh=5000, \n",
" smooth=False, queen=False,\n",
" verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11:17:27\t: Read in urban data\n",
"11:17:27\t: Creating Shape 0\n",
"11:17:31\t: Creating Shape 1000\n"
"15:11:38\t: Read in urban data\n",
"15:11:38\t: Creating Shape 0\n",
"15:11:44\t: Creating Shape 1000\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/wb411133/.conda/envs/geog/lib/python3.7/site-packages/numpy/core/_methods.py:36: RuntimeWarning: overflow encountered in reduce\n",
" return umr_sum(a, axis, dtype, out, keepdims, initial)\n"
"C:\\wbg\\Anaconda3\\envs\\test\\Lib\\site-packages\\numpy\\core\\_methods.py:49: RuntimeWarning: overflow encountered in reduce\n",
" return umr_sum(a, axis, dtype, out, keepdims, initial, where)\n",
"C:\\wbg\\Anaconda3\\envs\\test\\Lib\\site-packages\\GOST_Urban\\UrbanRaster.py:322: UserWarning: Geometry is in a geographic CRS. Results from 'buffer' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n",
"\n",
" xxGeom['geometry'] = xxGeom.buffer((popRaster.res[0] / 2))\n"
]
}
],
"source": [
"# Extract the high density urban extents (minimum density 1500/km2, minimum total population 50000)\n",
"hd_urban_extents = urban_calculator.calculateUrban(densVal=1500, totalPopThresh=50000, \n",
" smooth=True, queen=True,\n",
" verbose=True)"
" smooth=True, queen=True,# high density extents use queen's case contiguity, and \n",
" verbose=True) #High density extents have hole smoothing applied."
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -121,9 +129,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python (geog)",
"display_name": "urban_test",
"language": "python",
"name": "geog"
"name": "urban_test"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -135,7 +143,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.12.1"
}
},
"nbformat": 4,
Expand Down
34 changes: 22 additions & 12 deletions Notebooks/Tutorials/UrbanRural_extents_from_griddedPop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'GOSTRocks'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[2], line 17\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[38;5;66;03m#Import raster helpers\u001b[39;00m\n\u001b[0;32m 11\u001b[0m \u001b[38;5;66;03m#sys.path.append(\"../../../gostrocks/src\")\u001b[39;00m\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m#import GOSTRocks.rasterMisc as rMisc\u001b[39;00m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;66;03m#from GOSTRocks.misc import tPrint\u001b[39;00m\n\u001b[0;32m 14\u001b[0m \n\u001b[0;32m 15\u001b[0m \u001b[38;5;66;03m#Import GOST urban functions\u001b[39;00m\n\u001b[0;32m 16\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mGOST_Urban\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mUrbanRaster\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01murban\u001b[39;00m\n\u001b[1;32m---> 17\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mGOST_Urban\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01murban_helper\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mhelper\u001b[39;00m\n",
"File \u001b[1;32mC:\\wbg\\Anaconda3\\envs\\test\\Lib\\site-packages\\GOST_Urban\\urban_helper.py:18\u001b[0m\n\u001b[0;32m 15\u001b[0m sys\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 16\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mGOST_Urban\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mUrbanRaster\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01murban\u001b[39;00m\n\u001b[1;32m---> 18\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mGOSTRocks\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrasterMisc\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mrMisc\u001b[39;00m\n\u001b[0;32m 19\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mGOSTRocks\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmisc\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m tPrint\n\u001b[0;32m 21\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01msummarize_population\u001b[39;00m(\u001b[38;5;28mobject\u001b[39m):\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'GOSTRocks'"
]
}
],
"source": [
"import sys, os, importlib, json\n",
"import rasterio, geojson\n",
Expand All @@ -23,15 +36,12 @@
"from shapely.geometry import shape, Polygon\n",
"\n",
"#Import raster helpers\n",
"sys.path.append(\"../../../gostrocks/src\")\n",
"import GOSTRocks.rasterMisc as rMisc\n",
"from GOSTRocks.misc import tPrint\n",
"#sys.path.append(\"../../../gostrocks/src\")\n",
"#import GOSTRocks.rasterMisc as rMisc\n",
"#from GOSTRocks.misc import tPrint\n",
"\n",
"#Import GOST urban functions\n",
"sys.path.append(\"../../\")\n",
"import src.UrbanRaster as urban\n",
"import src.urban_helper as helper\n",
"\n"
"import GOST_Urban.UrbanRaster as urban"
]
},
{
Expand Down Expand Up @@ -147,9 +157,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python (geog)",
"display_name": "urban_test",
"language": "python",
"name": "geog"
"name": "urban_test"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -161,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.12.1"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions Notebooks/URB_DECAT_ExtractByISO3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python (geog)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "geog"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -253,7 +253,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
77 changes: 77 additions & 0 deletions Notebooks/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "bf43aa77",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\wbg\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py:21: UserWarning: Pandas requires version '2.8.4' or newer of 'numexpr' (version '2.7.3' currently installed).\n",
" from pandas.core.computation.check import NUMEXPR_INSTALLED\n",
"C:\\wbg\\Anaconda3\\lib\\site-packages\\pandas\\core\\arrays\\masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.2' currently installed).\n",
" from pandas.core import (\n",
"C:\\Users\\WB411133\\AppData\\Local\\Temp/ipykernel_23476/3122314439.py:4: DeprecationWarning: \n",
"Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),\n",
"(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)\n",
"but was not found to be installed on your system.\n",
"If this would cause problems for you,\n",
"please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466\n",
" \n",
" import pandas as pd\n",
"Matplotlib is building the font cache; this may take a moment.\n"
]
}
],
"source": [
"import sys, os, importlib, json\n",
"import rasterio, geojson\n",
"\n",
"import pandas as pd\n",
"import geopandas as gpd\n",
"import numpy as np\n",
"\n",
"from shapely.geometry import shape, Polygon\n",
"\n",
"#Import raster helpers\n",
"sys.path.append(\"../../gostrocks/src\")\n",
"import GOSTRocks.rasterMisc as rMisc\n",
"from GOSTRocks.misc import tPrint"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c85864f",
"metadata": {},
"outputs": [],
"source": [
"data_folder = \"../data\""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Quantifying urbanization
![Accra urbanization](Documents/ACCRA_GHSSMOD_Python_250m.png)

Urbanization is a foundational aspect of understanding the human condition, and has been a focus of economic, social, and development study for many years. This code repository is meant to centralize many of the urban analytics performed by the World Bank's Global Operational Support Team (GOST) in support of World Bank Group operations. There are numerous code examples in the [Notebooks](https://github.com/worldbank/GOST_Urban/tree/main/Notebooks) folder including both tutorials and records of project implementations.
![Accra urbanization](images/ACCRA_GHSSMOD_Python_250m.png)

This repo includes a [gh-pages](https://worldbank.github.io/GOST_Urban/intro.html) and a [wiki](https://github.com/worldbank/GOST_Urban/wiki) for the documentation.
Urbanization is a foundational aspect of understanding the human condition, and has been a focus of economic, social, and development study for many years. This code repository is meant to centralize many of the urban analytics performed by the World Bank's Global Operational Support Team (GOST) in support of World Bank Group operations. There are numerous code examples in the [notebooks](https://github.com/worldbank/GOST_Urban/tree/main/notebooks) folder including both tutorials and records of project implementations.

# Installation
Requires installation/download of the [gostrocks](https://github.com/bpstewar/gostrocks) library
```
pip install gostrocks
This repo includes a [Documentation](https://worldbank.github.io/GOST_Urban/intro.html) and a [Wiki](https://github.com/worldbank/GOST_Urban/wiki) for the documentation.

## Installation

**GOSTurbna** is available on [PyPI](https://pypi.org) and can installed using `pip`:

### From PyPI

```shell
pip install GOSTurban
```

The notebooks should reference the appropriate functions using relative paths
## License

This project is licensed under the [**MIT**](https://opensource.org/license/mit) - see the [LICENSE](LICENSE) file for details.
Binary file removed book/_build/.doctrees/environment.pickle
Binary file not shown.
1 change: 0 additions & 1 deletion book/_build/.doctrees/glue_cache.json

This file was deleted.

Binary file removed book/_build/.doctrees/intro.doctree
Binary file not shown.
Binary file removed book/_build/.doctrees/novel_context.doctree
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions book/_build/html/.buildinfo

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8171bcc

Please sign in to comment.