{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Modification of time" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this section we will show you how to modify the timeslicing arrangement as well as change the time horizon and benchmark year intervals by modifying the ```settings.toml``` file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Modify timeslicing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Timeslicing is the division of a single benchmark year into multiple different sections. For example, we could slice the benchmark year into different seasons, make a distinction between weekday and weekend or a distinction between morning and night. We do this as energy demand profiles can show a difference between these timeslices. eg. Electricity consumption is lower during the night than during the day.\n", "\n", "To achieve this, we have to modify the ```settings.toml``` file, as well as the files within the preset folder: ```Residential2020Consumption.csv``` and ```Residential2050Consumption.csv```. This is so that we can edit the demand for the residential sector for the new timeslices.\n", "\n", "First we edit the ```settings.toml``` file to add two additional timeslices: early-morning and late-afternoon. We also rename afternoon to mid-afternoon. These settings can be found at the bottom of the `settings.toml` file.\n", "\n", "An example of the changes is shown below:\n", "\n", " [timeslices]\n", " all-year.all-week.night = 1095\n", " all-year.all-week.morning = 1095\n", " all-year.all-week.mid-afternoon = 1095\n", " all-year.all-week.early-peak = 1095\n", " all-year.all-week.late-peak = 1095\n", " all-year.all-week.evening = 1095\n", " all-year.all-week.early-morning = 1095\n", " all-year.all-week.late-afternoon = 1095\n", " level_names = [\"month\", \"day\", \"hour\"]\n", " \n", "The number of timeslices within this should add up to 8760; the number of hours in a benchmark year. Whilst this is required, MUSE does not check and enforce this.\n", " \n", "Next, we modify both Residential Consumption files. Again, we put the text in bold for the modified entries. We must add the demand for the two additional timelsices, which we call timeslice 7 and 8. We make the demand for heat to be 2 for both of the new timeslices.\n", "\n", "Below is the modified ```Residential2020Consumption.csv``` file:\n", " \n", "||RegionName|ProcessName|Timeslice|electricity|gas|heat|CO2f|wind|\n", "|-|-|-|-|-|-|-|-|-|\n", "|0|R1|gasboiler|1|0|0|1|0|0|\n", "|1|R1|gasboiler|2|0|0|1.5|0|0|\n", "|2|R1|gasboiler|3|0|0|1|0|0|\n", "|3|R1|gasboiler|4|0|0|1.5|0|0|\n", "|4|R1|gasboiler|5|0|0|3|0|0|\n", "|5|R1|gasboiler|6|0|0|2|0|0|\n", "|**6**|**R1**|**gasboiler**|**7**|**0**|**0**|**2**|**0**|**0**|\n", "|**7**|**R1**|**gasboiler**|**8**|**0**|**0**|**2**|**0**|**0**|\n", "|0|R2|gasboiler|1|0|0|1|0|0|\n", "|1|R2|gasboiler|2|0|0|1.5|0|0|\n", "|2|R2|gasboiler|3|0|0|1|0|0|\n", "|3|R2|gasboiler|4|0|0|1.5|0|0|\n", "|4|R2|gasboiler|5|0|0|3|0|0|\n", "|5|R2|gasboiler|6|0|0|2|0|0|\n", "|**6**|**R2**|**gasboiler**|**7**|**0**|**0**|**2**|**0**|**0**|\n", "|**7**|**R2**|**gasboiler**|**8**|**0**|**0**|**2**|**0**|**0**|\n", "\n", "The `ProcessName` must be reported, but it is not binding on the results. It is just the way that the model reads the input data.\n", "\n", "We do the same for the ```Residential2050Consumption.csv```, however this time we make the demand for heat in 2050 to both be 5 for the new timeslices. See [here](https://github.com/SGIModel/MUSE_OS/blob/main/docs/tutorial-code/4-modify-timing-data/1-modify-timeslices/technodata/preset/Residential2050Consumption.csv) for the full file.\n", " \n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once the relevant files have been edited, we are able to run the simulation model using ```python -m muse settings.toml```.\n", "\n", "Then, once run, we import the necessary packages:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import seaborn as sns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and visualise the relevant data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mca_capacity = pd.read_csv(\n", " \"../tutorial-code/4-modify-timing-data/1-modify-timeslices/Results/MCACapacity.csv\"\n", ")\n", "\n", "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", " g = sns.FacetGrid(data=sector_capacity, col=\"region\")\n", " g.map_dataframe(\n", " lambda data, **kwargs: data.pivot(\n", " index=\"year\", columns=\"technology\", values=\"capacity\"\n", " ).plot(kind=\"bar\", stacked=True, ax=plt.gca())\n", " )\n", " g.add_legend()\n", " g.set_ylabels(\"Capacity (PJ)\")\n", " g.figure.suptitle(\"{} Sector:\".format(sector_name.capitalize()))\n", " g.figure.subplots_adjust(top=0.8)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compared to the scenario where we added a [region](add-region.ipynb), there is a smaller increase in solarPV in region `R2` in the power sector. However, the rest remains largely unchanged. \n", "\n", "This example shows the trade-off between time granularity and speed of computation. This is due to the fact that as we add more timesteps, the model takes longer to run, but slightly different scenarios emerge. It is up to you to decide what level of granularity is required for your use case." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Modify time horizon and time periods" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For the previous examples, we have run the scenario from 2020 to 2050, in 5 year time steps per benchmark year. This has been set at the top of the ```settings.toml``` file. However, we may want to run a more detailed scenario, with 2 year time steps, and up until the year 2040.\n", "\n", "Making this change is quite simple as we only have two lines to change. We will modify line 2 and 3 of the ```settings.toml``` file, as follows:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " # Global settings - most REQUIRED\n", " time_framework = [2020, 2022, 2024, 2026, 2028, 2030, 2032, 2034, 2036, 2038, 2040]\n", " foresight = 2 # Has to be a multiple of the minimum separation between the benchmark years " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `time_framework` details each benchmark year in which we run the simulation. The ```foresight``` variable details how much foresight an agent has when making investments. \n", "\n", "As we have modified the timeslicing arrangements there will be a change in the underlying demand for heating. This may require more electricity to service this demand. Therefore, we relax the constraints for growth in the power sector for all technologies and constraints in the ```technodata/power/technodata.csv```, as shown below:\n", "\n", "|ProcessName|RegionName|…|MaxCapacityAddition|MaxCapacityGrowth|TotalCapacityLimit|…|Agent1|\n", "|-|-|-|-|-|-|-|-|\n", "|Unit|-|…|PJ|%|PJ|…|New|\n", "|gasCCGT|R1|…|**40**|**0.2**|**120**|…|0|\n", "|windturbine|R1|…|**40**|**0.2**|**120**|…|0|\n", "|solarPV|R1|…|**40**|**0.2**|**120**|…|0|\n", "|gasCCGT|R2|…|**40**|**0.2**|**120**|…|0|\n", "|windturbine|R2|…|**40**|**0.2**|**120**|…|0|\n", "|solarPV|R2|…|**40**|**0.2**|**120**|…|0|\n", "|...|...|...|...|...|...|...|...|\n", "\n", "We also modify the constraints defined in the `technodata.csv` file for the residential sector, as shown below.\n", "\n", "|ProcessName|RegionName|Time|…|MaxCapacityAddition|MaxCapacityGrowth|TotalCapacityLimit|…|Agent1|\n", "|-|-|-|-|-|-|-|-|-|\n", "|Unit|-|Year|…|PJ|%|PJ|…|New|\n", "|gasboiler|R1|2020|…|**60**|**0.5**|**120**|…|0|\n", "|heatpump|R1|2020|…|**60**|**0.5**|**120**|…|0|\n", "|gasboiler|R2|2020|…|**60**|**0.5**|**120**|…|0|\n", "|heatpump|R2|2020|…|**60**|**0.5**|**120**|…|0|\n", "\n", "It must be noted, that this is a toy example. For modelling a real life scenario, data should be sought to ensure that these constraints remain realistic.\n", "\n", "For the full power sector ```technodata.csv``` file click [here](https://github.com/SGIModel/MUSE_OS/blob/main/docs/tutorial-code/4-modify-timing-data/2-modify-time-framework/technodata/power/Technodata.csv), and for the full residential sector ```technodata.csv``` file click [here](https://github.com/SGIModel/MUSE_OS/blob/main/docs/tutorial-code/4-modify-timing-data/2-modify-time-framework/technodata/residential/Technodata.csv).\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mca_capacity = pd.read_csv(\n", " \"../tutorial-code/4-modify-timing-data/2-modify-time-framework/Results/MCACapacity.csv\"\n", ")\n", "\n", "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", " g = sns.FacetGrid(data=sector_capacity, col=\"region\")\n", " g.map_dataframe(\n", " lambda data, **kwargs: data.pivot(\n", " index=\"year\", columns=\"technology\", values=\"capacity\"\n", " ).plot(kind=\"bar\", stacked=True, ax=plt.gca())\n", " )\n", " g.add_legend()\n", " g.set_ylabels(\"Capacity (PJ)\")\n", " g.figure.suptitle(\"{} Sector:\".format(sector_name.capitalize()))\n", " g.figure.subplots_adjust(top=0.8)\n", " g.set(ylim=(0, None))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Through the addition of more benchmark years, we are able to see a different scenario develop." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Next steps " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the next section we detail how to add an exogenous service demand, such as demand for heating or cooking." ] } ], "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.9.18" } }, "nbformat": 4, "nbformat_minor": 4 }