Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine friedrichshain examples #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed data/friedrichshain_network.gpkg
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file modified data/nairobi_population.gpkg
Binary file not shown.
Binary file added data/nairobi_population_raster.tif
Binary file not shown.
Binary file modified data/nairobi_pt_high.gpkg
Binary file not shown.
Binary file modified data/nairobi_pt_low.gpkg
Binary file not shown.
Binary file removed data/net_example.gpkg
Binary file not shown.
Binary file removed data/pt_high_example.gpkg
Binary file not shown.
Binary file removed data/pt_low_example.gpkg
Binary file not shown.
373 changes: 193 additions & 180 deletions notebooks/friedrichshain_example.ipynb

Large diffs are not rendered by default.

495 changes: 0 additions & 495 deletions notebooks/friedrichshain_example_2.ipynb

This file was deleted.

263 changes: 152 additions & 111 deletions notebooks/nairobi_example.ipynb

Large diffs are not rendered by default.

127 changes: 28 additions & 99 deletions notebooks/population_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,133 +4,62 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## An example how to convert population raster data to points"
"## An example how to process population information\n",
"\n",
"This example will show how to process population information for usage in PtAC. For now, this just includes the\n",
"generation of point geodataframes based on a population raster dataset. In the future we want to include functionality\n",
"download and process population information directly from WSF."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'numpy' has no attribute 'ndarray'",
"output_type": "error",
"traceback": [
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[1;31mAttributeError\u001B[0m Traceback (most recent call last)",
"\u001B[1;32m<ipython-input-1-1ab2d3f802c3>\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[1;33m \u001B[1;32mimport\u001B[0m \u001B[0mptac\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mpopulation\u001B[0m \u001B[1;32mas\u001B[0m \u001B[0mpopulation\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m 2\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mos\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 3\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0msys\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 4\u001B[0m \u001B[0mproject_path\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0mos\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mpath\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mabspath\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m'../'\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 5\u001B[0m \u001B[0msys\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mpath\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mproject_path\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n",
"\u001B[1;32mD:\\trak\\PtAC_serra\\ptac\\population.py\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m 10\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mos\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 11\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mnumpy\u001B[0m \u001B[1;32mas\u001B[0m \u001B[0mnp\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m---> 12\u001B[1;33m \u001B[1;32mimport\u001B[0m \u001B[0mpandas\u001B[0m \u001B[1;32mas\u001B[0m \u001B[0mpd\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m 13\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mgeopandas\u001B[0m \u001B[1;32mas\u001B[0m \u001B[0mgpd\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 14\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mrasterio\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n",
"\u001B[1;32mC:\\Anaconda3\\envs\\sdgtool\\lib\\site-packages\\pandas\\__init__.py\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m 20\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 21\u001B[0m \u001B[1;31m# numpy compat\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m---> 22\u001B[1;33m from pandas.compat.numpy import (\n\u001B[0m\u001B[0;32m 23\u001B[0m \u001B[0mnp_version_under1p17\u001B[0m \u001B[1;32mas\u001B[0m \u001B[0m_np_version_under1p17\u001B[0m\u001B[1;33m,\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 24\u001B[0m \u001B[0mnp_version_under1p18\u001B[0m \u001B[1;32mas\u001B[0m \u001B[0m_np_version_under1p18\u001B[0m\u001B[1;33m,\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n",
"\u001B[1;32mC:\\Anaconda3\\envs\\sdgtool\\lib\\site-packages\\pandas\\compat\\__init__.py\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m 12\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mwarnings\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 13\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m---> 14\u001B[1;33m \u001B[1;32mfrom\u001B[0m \u001B[0mpandas\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0m_typing\u001B[0m \u001B[1;32mimport\u001B[0m \u001B[0mF\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m 15\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 16\u001B[0m \u001B[0mPY38\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0msys\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mversion_info\u001B[0m \u001B[1;33m>=\u001B[0m \u001B[1;33m(\u001B[0m\u001B[1;36m3\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;36m8\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n",
"\u001B[1;32mC:\\Anaconda3\\envs\\sdgtool\\lib\\site-packages\\pandas\\_typing.py\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[0;32m 52\u001B[0m \u001B[1;31m# array-like\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 53\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m---> 54\u001B[1;33m \u001B[0mAnyArrayLike\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0mTypeVar\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"AnyArrayLike\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\"ExtensionArray\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\"Index\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\"Series\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mndarray\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m 55\u001B[0m \u001B[0mArrayLike\u001B[0m \u001B[1;33m=\u001B[0m \u001B[0mTypeVar\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"ArrayLike\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\"ExtensionArray\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mnp\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mndarray\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m 56\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n",
"\u001B[1;31mAttributeError\u001B[0m: module 'numpy' has no attribute 'ndarray'"
]
}
],
"outputs": [],
"source": [
"import ptac.population as population\n",
"import os\n",
"import sys\n",
"project_path = os.path.abspath('../')\n",
"sys.path.append(project_path)\n",
"import geopandas as gpd\n",
"from matplotlib import pyplot as plt\n",
"\n",
"from ptac import population as population\n",
"from ptac import osm as osm\n"
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"This is a simple example on how to generate a point geodataframe from a raster data set."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>pop</th>\n",
" <th>x_coord</th>\n",
" <th>y_coord</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.889245</td>\n",
" <td>13.441986</td>\n",
" <td>52.530828</td>\n",
" <td>POINT (13.44199 52.53083)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.585283</td>\n",
" <td>13.441716</td>\n",
" <td>52.530558</td>\n",
" <td>POINT (13.44172 52.53056)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>6.065472</td>\n",
" <td>13.437135</td>\n",
" <td>52.529480</td>\n",
" <td>POINT (13.43713 52.52948)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>6.065472</td>\n",
" <td>13.437404</td>\n",
" <td>52.529480</td>\n",
" <td>POINT (13.43740 52.52948)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.988679</td>\n",
" <td>13.440099</td>\n",
" <td>52.529480</td>\n",
" <td>POINT (13.44010 52.52948)</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" pop x_coord y_coord geometry\n",
"0 1.889245 13.441986 52.530828 POINT (13.44199 52.53083)\n",
"1 2.585283 13.441716 52.530558 POINT (13.44172 52.53056)\n",
"2 6.065472 13.437135 52.529480 POINT (13.43713 52.52948)\n",
"3 6.065472 13.437404 52.529480 POINT (13.43740 52.52948)\n",
"4 1.988679 13.440099 52.529480 POINT (13.44010 52.52948)"
]
"text/plain": " pop x_coord y_coord geometry\n0 1.889245 13.441986 52.530828 POINT (13.44199 52.53083)\n1 2.585283 13.441716 52.530558 POINT (13.44172 52.53056)\n2 6.065472 13.437135 52.529480 POINT (13.43713 52.52948)\n3 6.065472 13.437404 52.529480 POINT (13.43740 52.52948)\n4 1.988679 13.440099 52.529480 POINT (13.44010 52.52948)",
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>pop</th>\n <th>x_coord</th>\n <th>y_coord</th>\n <th>geometry</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1.889245</td>\n <td>13.441986</td>\n <td>52.530828</td>\n <td>POINT (13.44199 52.53083)</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2.585283</td>\n <td>13.441716</td>\n <td>52.530558</td>\n <td>POINT (13.44172 52.53056)</td>\n </tr>\n <tr>\n <th>2</th>\n <td>6.065472</td>\n <td>13.437135</td>\n <td>52.529480</td>\n <td>POINT (13.43713 52.52948)</td>\n </tr>\n <tr>\n <th>3</th>\n <td>6.065472</td>\n <td>13.437404</td>\n <td>52.529480</td>\n <td>POINT (13.43740 52.52948)</td>\n </tr>\n <tr>\n <th>4</th>\n <td>1.988679</td>\n <td>13.440099</td>\n <td>52.529480</td>\n <td>POINT (13.44010 52.52948)</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdf = population.raster_to_points(path=project_path + \"/data/friedrichshain_raster.tif\")\n",
"gdf = population.raster_to_points(path=project_path + \"/data/friedrichshain_population_raster.tif\")\n",
"gdf.head()"
]
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
Expand Down