{ "cells": [ { "cell_type": "markdown", "id": "e3232e9a", "metadata": {}, "source": [ "\"dsi\n", "\n", "# Electricity production plants - Geo Visualisation\n", "\n", "\n", "Data origins from https://opendata.swiss/en/dataset/elektrizitatsproduktionsanlagen\n" ] }, { "cell_type": "markdown", "id": "ea31f196", "metadata": {}, "source": [ "## Loading data " ] }, { "cell_type": "code", "execution_count": null, "id": "2d5f105d", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from ipyleaflet import Map, Marker, Popup\n", "from ipywidgets import HTML\n", "\n", "import geopandas as gpd\n", "from shapely.geometry import Point\n", "\n", "epp = pd.read_csv('../../data-science-course/data/ch.bfe.elektrizitaetsproduktionsanlagen/ElectricityProductionPlant.csv', parse_dates=['BeginningOfOperation']).set_index('xtf_id')\n", "epp" ] }, { "cell_type": "markdown", "id": "8b232aa2", "metadata": {}, "source": [ "## Coordinate System Transformation\n", "\n", "The x,y values in the dataset are based on the LV95 coordinate system. To render the data we first transform the data into WGS84 (latitute/longitude) coordinates" ] }, { "cell_type": "code", "execution_count": null, "id": "5cb1f9b7-fd22-462a-93b9-0b05e1b2df3c", "metadata": { "scrolled": true }, "outputs": [], "source": [ "epp['geometry'] = epp.apply(lambda row: Point(row['_x'], row['_y']), axis=1)\n", "gdf = gpd.GeoDataFrame(epp, geometry='geometry', crs='EPSG:2056')\n", "gdf = gdf.to_crs(epsg=4326)\n", "epp.head()" ] }, { "cell_type": "markdown", "id": "453bfb01", "metadata": {}, "source": [ "# Sample IPLeaflet Map\n", "\n", "Sample from https://ipyleaflet.readthedocs.io/en/latest/" ] }, { "cell_type": "code", "execution_count": null, "id": "786fc58f", "metadata": {}, "outputs": [], "source": [ "center = (46.030414,7.307939)\n", "\n", "m = Map(center=center, zoom=15)\n", "\n", "marker = Marker(location=center, draggable=True)\n", "\n", "m.add_layer(marker);\n", "\n", "display(m)\n" ] }, { "cell_type": "markdown", "id": "4f9d7655", "metadata": {}, "source": [ "***\n", " ## Put Power Plants on Map \n", "\n", "
\n", "Exercise: Create a map with all nuclear power plants in Switzerland \n", "\n", "1. Create a 'Marker` for each nuclear power plant\n", "\n", "2. Put the total power into the `title` of the `Marker` \n", "\n", "3. (Optional) Display Municipality in the `popup` of the `Marker`\n", "\n", "4. (Optional) Display the 100 largest water power plants with different colors (depending on the total power) as `Circle`. \n", " \n", " \n", "\n", " \n", " \n", "
\n", "\n", "*Hints*\n", "- Use `pd.apply()` with `axis=1` to execute a function on each row of a `DataFrame`\n", "- Read the coordinates from a GeoPandas `row` by `row.geometry.x` and `row.geometry.y`, respectively\n", "- IPLeaflet Doc: https://ipyleaflet.readthedocs.io/en/latest/\n", "\n", "***" ] }, { "cell_type": "code", "execution_count": null, "id": "26d01414", "metadata": {}, "outputs": [], "source": [] } ], "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }