{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", "
\n", " National generation capacity: Check notebook\n", " \n", "
This Notebook is part of the National Generation Capacity Datapackage of Open Power System Data.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Table of Contents\n", "* [1. Introductory notes](#1.-Introductory-notes)\n", "* [2. Script setup](#2.-Script-setup)\n", "* [3. Import of processed data](#3.-Import-of-processed-data)\n", "* [4. Visualisation of results for different energy source levels](#4.-Visualisation-of-results-for-different-energy-source-levels)\n", "\t* [4.1 Energy source level 1](#4.1-Energy-source-level-1)\n", "\t\t* [4.1.1 Table](#4.1.1-Table)\n", "\t\t* [4.1.2 Bokeh chart](#4.1.2-Bokeh-chart)\n", "\t* [4.2 Energy source level 2](#4.2-Energy-source-level-2)\n", "\t\t* [4.2.1 Table](#4.2.1-Table)\n", "\t\t* [4.2.2 Bokeh chart](#4.2.2-Bokeh-chart)\n", "\t* [4.3 Energy source level 3](#4.3-Energy-source-level-3)\n", "\t\t* [4.3.1 Table](#4.3.1-Table)\n", "\t\t* [4.3.2 Bokeh chart](#4.3.2-Bokeh-chart)\n", "\t* [4.4 Technology level](#4.4-Technology-level)\n", "\t\t* [4.4.1 Table](#4.4.1-Table)\n", "\t\t* [4.4.2 Bokeh chart](#4.4.2-Bokeh-chart)\n", "* [5. Comparison of total capacity for energy source levels](#5.-Comparison-of-total-capacity-for-energy-source-levels)\n", "\t* [5.1 Calculation of total capacity for energy source levels](#5.1-Calculation-of-total-capacity-for-energy-source-levels)\n", "\t* [5.2 Identifcation of capacity differences for energy source levels](#5.2-Identifcation-of-capacity-differences-for-energy-source-levels)\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# 1. Introductory notes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The notebook extends the [processing notebook](processing.ipynb) to make visualisations." ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# 2. Script setup" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os.path\n", "import math\n", "import functions.plots as fp # predefined functions in extra file\n", "\n", "import bokeh.plotting as plo\n", "from bokeh.io import show, output_notebook\n", "from bokeh.layouts import row, column\n", "from bokeh.models import Panel, Tabs\n", "from bokeh.models.widgets import RangeSlider, MultiSelect, Select\n", "output_notebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Data import" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_file = 'national_generation_capacity_stacked.csv'\n", "filepath = os.path.join('output', data_file)\n", "data = fp.load_opsd_data(filepath)\n", "data.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. Create interactive plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Select individual width and height that fits your jupyter notebook settings." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "width = 1000\n", "height = 500" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def comparison_plot(doc):\n", " \n", " # init of 5 plots for each energy level\n", " sources = []\n", " plots = []\n", "\n", " for level in fp.energy_levels:\n", " # init plots with the predfined function\n", " s, p = fp.init_plot(data, level, size=(width, height))\n", " sources.append(s)\n", " plots.append(p)\n", "\n", " # associate each plot with a tab of the interactive plot\n", " panels= []\n", " for p, level in zip(plots, fp.energy_levels):\n", " panels.append(Panel(child=p, title=level))\n", "\n", " tabs = Tabs(tabs=panels, tabs_location='below', active=2)\n", "\n", " # Range slider for available years\n", " oldest_year = min(data[\"year\"])\n", " newest_year = max(data[\"year\"])\n", " y_slider = RangeSlider(title=\"Years\",\n", " value=(2015,2016),\n", " start=oldest_year,\n", " end=newest_year,\n", " step=1)\n", "\n", " # Select field for sources\n", " m_select = MultiSelect(title=\"Available Sources:\", \n", " value=fp.global_sources,\n", " options=[(s,s) for s in fp.global_sources])\n", "\n", " # Select button for countries\n", " countries = list(data[\"country\"].unique())\n", " c_select = Select(title=\"Country\", options=countries, value='FR')\n", "\n", " # catch all widgets \n", " wid = [c_select, y_slider, m_select]\n", " rows = row(wid)\n", "\n", " # update function for `on_change` trigger\n", " def update(attrname, old, new):\n", "\n", " y = y_slider.value\n", " y_range = [x for x in range(y[0],y[1]+1)]\n", " s_selected = m_select.value\n", " co = c_select.value\n", "\n", " # run update for each plot\n", " for p, s, l in zip(plots, sources, fp.energy_levels):\n", " df = fp.filter_data_set(data, co, y_range, s_selected, l)\n", " source_data, x_axis = fp.prepare_data(df)\n", " s.data = source_data\n", " p.x_range.factors = x_axis\n", "\n", " # associate `update` function with each widget to apply updates for each change\n", " for w in wid:\n", " w.on_change('value', update)\n", "\n", " \n", " layout = column(rows, tabs)\n", " doc.add_root(layout)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After the bokeh plot is set up a bokeh server is started to make the plot interactive.\n", "\n", "Possible options:\n", "\n", " - Select a country from the dropdown menu in the top left\n", " - Select a range of years from the range slider\n", " - Multiselect the sources you want to compare in the top right\n", " - Choose which \"energy level\" you want to investigate with the tabs below the plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "show(comparison_plot)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "anaconda-cloud": {}, "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.6.9" } }, "nbformat": 4, "nbformat_minor": 1 }