{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Adding a service demand by correlation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the previous section we added an exogenous service demand. That is, we explicitly specified what the demand would be per year.\n", "\n", "However, we may not know what the electricity demand may be per year. Instead, we may conclude that our electricity demand is a function of the GDP and population of a particular region. \n", "\n", "To accommodate such a scenario, MUSE enables us to choose a regression function that estimates service demands from GDP and population, which may be more certain in your case.\n", "\n", "In this section we will show how this can be done." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Additional files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this work, we will use the `default` example from the MUSE repository, and will not build on the previous examples. This is done to simplify the model at this point.\n", "\n", "The full scenario files for the `default` example can be found [here](https://github.com/SGIModel/MUSE_OS/tree/main/src/muse/data/example/default). We recommend that you download these files and save them to a location convenient to you, as we will be amending these throughout this tutorial.\n", "\n", "Similarly to before, we must amend the `preset` folder for this. However, we no longer require the `Residential2020Consumption.csv` and `Residential2050Consumption.csv` files. These files set the exogenous service demand for the residential sector.\n", "\n", "We must replace these files, with the following files:\n", "\n", "- A macrodrivers file. This contains the drivers of the service demand that we want to model. For this example, these will include GDP based on purchasing power parity (GDP PPP) and the population that we expect from 2010 to 2110.\n", "\n", "- A regression parameters file. This file will set the function type we would like to use to predict the service demand and the respective parameters of this regression file per region.\n", "\n", "- A timeslice share file. This file sets how the demand is shared between timeslice.\n", "\n", "The example files for each of those just mentioned can be found below, respectively:\n", "\n", "- [Macrodrivers.csv](https://github.com/SGIModel/MUSE_OS/blob/main/docs/tutorial-code/6-add-correlation-demand/technodata/preset/Macrodrivers.csv)\n", "\n", "- [regressionparameters.csv](https://github.com/SGIModel/MUSE_OS/blob/main/docs/tutorial-code/6-add-correlation-demand/technodata/preset/regressionparameters.csv)\n", "\n", "- [TimesliceSharepreset.csv](https://github.com/SGIModel/MUSE_OS/blob/main/docs/tutorial-code/6-add-correlation-demand/technodata/preset/TimesliceSharepreset.csv)\n", "\n", "For a full introduction to these files, see the link [here](../inputs/correlation_files.rst).\n", "\n", "Download these files and save them within the `preset` folder.\n", "\n", "Next, we must amend our toml file to include our new way of calculating the preset service demand." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## TOML file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Editing the TOML file to include this can be done relatively quickly if we know the variable names.\n", "\n", "In the second bottom section of the toml file, you will see the following section: \n", "\n", "```\n", "[sectors.residential_presets]\n", "type = 'presets'\n", "priority = 0\n", "consumption_path= \"{path}/technodata/preset/*Consumption.csv\"\n", "```\n", "\n", "This enables us to run the model in exogenous mode, but now we would like to run the model from the files previously mentioned. This can be done by linking new variables to the new files, as follows:\n", "\n", "```\n", "[sectors.residential_presets]\n", "type = 'presets'\n", "priority = 0\n", "\n", "timeslice_shares_path = '{path}/technodata/preset/TimesliceSharepreset.csv'\n", "macrodrivers_path = '{path}/technodata/preset/Macrodrivers.csv'\n", "regression_path = '{path}/technodata/preset/regressionparameters.csv'\n", "```\n", "\n", "We effectively linked the new files to MUSE." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Increasing capacity constraints\n", "\n", "Again, we must increase the capacity constraints. This is because the data in our GDP PPP and population files create a much higher demand than our previous toy example, due to the fact that it is more realistic for our particular region.\n", "\n", "To ensure that we don't encounter any problems, we will relax our capacity constraints considerably.\n", "\n", "For the full files see [here](https://github.com/SGIModel/MUSE_OS/tree/main/docs/tutorial-code/6-add-correlation-demand). Make sure to take note of the columns:\n", "\n", "- MaxCapacityAddition\n", "\n", "- MaxCapacityGrowth\n", "\n", "- TotalCapacityLimit\n", "\n", "for the `Technodata.csv` files for each of the sectors. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running and visualising our new results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With those changes made, we are now able to run our modified model, with the `python -m muse settings.toml` command in anaconda prompt, as before.\n", "\n", "As before, we will now visualise the output." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mca_capacity = pd.read_csv(\n", " \"../tutorial-code/6-add-correlation-demand/Results/MCACapacity.csv\"\n", ")\n", "mca_capacity.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for sector_name, sector_data in mca_capacity.groupby(\"sector\"):\n", " sector_capacity = (\n", " sector_data.groupby([\"region\", \"year\", \"technology\"]).sum().reset_index()\n", " )\n", " ax = (\n", " sector_capacity[sector_capacity.region == \"R1\"]\n", " .pivot(index=\"year\", columns=\"technology\", values=\"capacity\")\n", " .plot(kind=\"bar\", stacked=True)\n", " )\n", " ax.set_ylabel(\"Capacity (PJ)\")\n", " ax.set_title(\"{} Sector:\".format(sector_name.capitalize()))\n", " ax.tick_params(axis=\"x\", labelrotation=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected, we see a scenario emerge with much higher capacity limits. The demand does not increase linearly, with variations in the total demand in the residential sector. This is due to the new function not being a linear function." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Next steps\n", "\n", "In the next section we will see how we can enforce outputs of technologies by timeslice. For instance, we can prevent solar photovoltaics from producing electricity at night, or ensure that a nuclear power plant runs at a minimum capacity during the day." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.0 ('muse39')", "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.18" }, "vscode": { "interpreter": { "hash": "22ff8bbda430c28f07def99f448c0c69dabbaf0c7d993cae69f87b3c458d04b2" } } }, "nbformat": 4, "nbformat_minor": 4 }