From 74b0736e3988ca9393950ec052a4cd7bf3692a68 Mon Sep 17 00:00:00 2001 From: anitagraser Date: Sun, 7 Feb 2021 23:07:05 +0100 Subject: [PATCH] Add environment notebook --- .gitignore | 7 +++ notebooks/environment.ipynb | 112 ++++++++++++++++++++++++++++++++++ notebooks/index.ipynb | 1 + notebooks/utils/dataaccess.py | 43 ++++++++++++- notebooks/wien-ogd.ipynb | 12 +++- 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 notebooks/environment.ipynb diff --git a/.gitignore b/.gitignore index 4a30576..4479b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,10 @@ dmypy.json notebooks/CITYBIKEOGD.json notebooks/ELADESTELLEOGD.json notebooks/6141610.txt +notebooks/heatvulnerabilityindex.csv +notebooks/LUFTGUETENETZOGD.json +notebooks/OGDEXT_ZSP_1_STATISTIK_AUSTRIA_20200101.zip +notebooks/WAHLSPRGR2020OGD.json +notebooks/ZAEHLBEZIRKOGD.json +notebooks/ZAEHLSPRGR0OGD.json +notebooks/lumesakt.csv diff --git a/notebooks/environment.ipynb b/notebooks/environment.ipynb new file mode 100644 index 0000000..095da02 --- /dev/null +++ b/notebooks/environment.ipynb @@ -0,0 +1,112 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Environmental Conditions in Vienna" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/anitagraser/ogd-at-lab/main?urlpath=lab/tree/notebooks/environment.ipynb)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import hvplot.pandas\n", + "import pandas as pd\n", + "import geopandas as gpd\n", + "from utils.dataaccess import gdf_from_wfs, get_weather_df, get_heatvulnerabilityindex_gdf" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Urban Heat Vulnerability Index (UHVI) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "heatvulidx = get_heatvulnerabilityindex_gdf()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "heatvulidx.hvplot(geo=True, tiles='OSM', c='AVG_UHVI_A', title='Urban Heat Vulnerability Index (AVG_UHVI_A)').opts(active_tools=['wheel_zoom'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Air Quality" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "stations = gdf_from_wfs('LUFTGUETENETZOGD')\n", + "stations.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "weather = get_weather_df()\n", + "weather" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/notebooks/index.ipynb b/notebooks/index.ipynb index aadae63..156b7b5 100644 --- a/notebooks/index.ipynb +++ b/notebooks/index.ipynb @@ -19,6 +19,7 @@ "## Lab notebooks\n", "\n", "1. [Accessing geodata from data.wien.gv.at services](wien-ogd.ipynb)\n", + "1. [Environmental conditions in Vienna](environment.ipynb)\n", "1. [Geocoding addresses](geocoding.ipynb)\n", "1. [Getting elevation information](elevation.ipynb)" ] diff --git a/notebooks/utils/dataaccess.py b/notebooks/utils/dataaccess.py index 1180208..071ea16 100644 --- a/notebooks/utils/dataaccess.py +++ b/notebooks/utils/dataaccess.py @@ -1,6 +1,7 @@ from os.path import exists from urllib.request import urlretrieve import geopandas as gpd +import pandas as pd def gdf_from_wfs(layer): """ @@ -47,4 +48,44 @@ def get_elevation(point): if x_wert == raster_x: elevationall = line.split(' ', 1 )[1] return int(elevationall) - \ No newline at end of file + +def get_weather_df(): + """ + Get data from https://go.gv.at/l9lumesakt + """ + file = 'lumesakt.csv' + url = 'https://go.gv.at/l9lumesakt' + urlretrieve(url, file) + df = pd.read_csv(file) + return df + +def get_heatvulnerabilityindex_gdf(): + """ + Get data from https://go.gv.at/l9lumesakt + """ + file = 'heatvulnerabilityindex.csv' + url = 'https://www.wien.gv.at/gogv/l9ogdaverageurbanheatvulnerabilityindex' + if not exists(file): + urlretrieve(url, file) + df = pd.read_csv(file, sep=';', encoding='latin1') + df['AVG_UHVI_A'] = df['AVG_UHVI_A'].str.replace(',', '.').astype(float) + df['AVG_UHVI_O'] = df['AVG_UHVI_O'].str.replace(',', '.').astype(float) + df['AVG_UHVI_Y'] = df['AVG_UHVI_Y'].str.replace(',', '.').astype(float) + df.set_index('SUB_DISTRICT_CODE_VIE', inplace=True) + districts = gdf_from_wfs('ZAEHLBEZIRKOGD') + districts['SUB_DISTRICT_CODE_VIE'] = districts['ZBEZ'].astype(int) + 90000 + districts.set_index('SUB_DISTRICT_CODE_VIE', inplace=True) + gdf = gpd.GeoDataFrame(pd.DataFrame(districts).join(df)) + return gdf + +def get_zaehlsprengel_gdf(year=2020): + """ + Get Zählsprengel districts from Statistik Austria + """ + file = f'OGDEXT_ZSP_1_STATISTIK_AUSTRIA_{year}0101.zip' + url = f'http://data.statistik.gv.at/data/OGDEXT_ZSP_1_STATISTIK_AUSTRIA_{year}0101.zip' + if not exists(file): + urlretrieve(url, file) + gdf = gpd.read_file(f'zip://{file}') + return gdf + \ No newline at end of file diff --git a/notebooks/wien-ogd.ipynb b/notebooks/wien-ogd.ipynb index 3606b64..681fa1a 100644 --- a/notebooks/wien-ogd.ipynb +++ b/notebooks/wien-ogd.ipynb @@ -13,7 +13,7 @@ "\n", "For more information on open government data in Vienna visit [digitales.wien.gv.at](https://digitales.wien.gv.at/site/open-data/)\n", "\n", - "For a full list of available datasets go to [data.gv.at](https://www.data.gv.at/auftritte/?organisation=stadt-wien)\n", + "For a full list of available datasets go to [data.gv.at](https://www.data.gv.at/auftritte/?organisation=stadt-wien&searchterm=&formatFilter%5B%5D=WFS)\n", "\n", "\n" ] @@ -95,6 +95,16 @@ "hvplot_with_buffer(gdf, 100, title='Citybike Stations') + hvplot_with_buffer(gdf2, 100, title='EV Charging Stations')" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "election_districts = gdf_from_wfs('WAHLSPRGR2020OGD')\n", + "election_districts.hvplot(geo=True, tiles='OSM', alpha=0.5).opts(active_tools=['wheel_zoom'])" + ] + }, { "cell_type": "code", "execution_count": null,