Skip to content

Commit 307485e

Browse files
authored
Merge pull request #21 from robcalon/bugfix/v1.3.5
Bugfix/v1.3.5
2 parents c5f0467 + b188a1b commit 307485e

File tree

9 files changed

+545
-79
lines changed

9 files changed

+545
-79
lines changed

examples/1. scenarios.ipynb

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"### First Use Examples\n",
8-
"The ETMClient is the link between the ETM API and Python. In order to interact with a scenario, the ETMClient first needs to connect to a scenario in the ETM. The scenario to which the client is connected is referenced to with a scenario_id. There are several ways to connect to a scenario, you can create a new scenario, you can create a copy of existing scenario's or you can connect to an existing scenario. First time users probably want to create an entire new scenario or a scenario that is based on a predefined template."
7+
"**First Use Examples**\n",
8+
"\n",
9+
"In order to interact with a scenario, a Client first needs to initialized by\n",
10+
"pointing to a specific scenario in the ETM. There are several options to establish\n",
11+
"a connection, e.g. by creating a new scenario, creating a copy of an existing scenario \n",
12+
"or reconnecting to a previously created scenario.\n",
13+
"\n",
14+
"Note that the parameter `scenario_id` refers to which is also known as an `api_session_id`. \n",
15+
"This id does not directly refers to a `saved_scenario_id` of scenarios stored under \n",
16+
"an ETM user account."
917
]
1018
},
1119
{
@@ -41,9 +49,13 @@
4149
"cell_type": "markdown",
4250
"metadata": {},
4351
"source": [
44-
"### Scenario properties\n",
45-
"After a connection with a scenario is established, you can request specific properties of that given scenario. The more basic properties that can be accessed for example are the start year, area code, or date dat which the scenario was created. Some properties can also be changed, for example if the scenario is read only and thus cannot be modified via the API.\n",
46-
"\n"
52+
"**Scenario properties**\n",
53+
"\n",
54+
"After a connection with a scenario is established, you can request specific \n",
55+
"properties of that given scenario. The more basic properties that can be accessed \n",
56+
"for example are the start year, area code, or creation data. Some properties can \n",
57+
"also be changed, for example if the scenario is read only and thus cannot be modified \n",
58+
"via the API."
4759
]
4860
},
4961
{
@@ -55,13 +67,6 @@
5567
"client.created_at"
5668
]
5769
},
58-
{
59-
"cell_type": "markdown",
60-
"metadata": {},
61-
"source": [
62-
"More relevant properties of the scenario are the user configured parameters of the scenarios. You can access and change them via the user values property of the scenario."
63-
]
64-
},
6570
{
6671
"cell_type": "code",
6772
"execution_count": null,
@@ -106,10 +111,14 @@
106111
"cell_type": "markdown",
107112
"metadata": {},
108113
"source": [
109-
"As the user_values can be passed in different formats, it is possible to load a json as a dictonairy or a csv-file as series or dataframe with a 'user' column. When parameters are passed with a value outside the domain that is specified, the client will raise an error. \n",
114+
"**Result Curves**\n",
110115
"\n",
111-
"### Result Curves\n",
112-
"Simular to the scenario properties, the results of a scenario can also be accessed as properties of the scenario. When scenario parameters are changed, all results curves are automatically reset and are requested again upon accessing the client property. This means that the first time that a result curve is requested some time will pass before the result is loaded, as the ETM is evaluating the scenario in the background."
116+
"Simular to the scenario properties, the results of a scenario can also be accessed \n",
117+
"as properties of the scenario. When scenario parameters are changed, all result \n",
118+
"curves are automatically reset and are requested again upon accessing the client \n",
119+
"property. This means that the first time that a result curve is requested some time \n",
120+
"will pass before the result is loaded, as the ETM is evaluating the scenario in the \n",
121+
"background."
113122
]
114123
},
115124
{
@@ -127,7 +136,8 @@
127136
"cell_type": "markdown",
128137
"metadata": {},
129138
"source": [
130-
"### Custom Curves\n",
139+
"**Custom Curves**\n",
140+
"\n",
131141
"It is also possible to upload custom curves for a select number of parameters."
132142
]
133143
},
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"**Mapping**\n",
8+
"\n",
9+
"ETM offers quite some granularity in the returned hourly carrier curves which\n",
10+
"depending on the usecase might not always be desirable. The default keys can\n",
11+
"simply be replaced and aggregated to an user-defined naming convention."
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from pyetm import Client\n",
21+
"import pandas as pd\n",
22+
"\n",
23+
"# get electricity curves\n",
24+
"client = Client(1008593)\n",
25+
"ecurves = client.get_hourly_electricity_curves()\n",
26+
"\n",
27+
"# show head\n",
28+
"ecurves.head()"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"# load example mappping\n",
38+
"mapping = pd.read_csv('data/hourly_electricity_curve_mapping.csv', index_col=0)\n",
39+
"mapping.head()"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"from pyetm.utils import categorise_curves\n",
49+
"\n",
50+
"# categorize electricity curves\n",
51+
"mapped = categorise_curves(ecurves, mapping)\n",
52+
"mapped.head()"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"Alternativly the mapping can also be applied directly from the client."
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"mapped = client.categorise_curves('electricity', mapping)\n",
69+
"mapped.head()"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"**Regionalisation**\n",
77+
"\n",
78+
"Curves can also be regionionalized by distributing them over different regions/nodes."
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"metadata": {},
85+
"outputs": [],
86+
"source": [
87+
"import numpy as np\n",
88+
"\n",
89+
"# this example uses a randomly generated regionalisation\n",
90+
"# the regionalization is compatible with the 'mapped' electricity curves.\n",
91+
"values = np.random.dirichlet(np.ones(10), size=len(mapped.columns))\n",
92+
"reg = pd.DataFrame(values.T, columns=mapped.columns)\n",
93+
"\n",
94+
"reg.round(4).head()"
95+
]
96+
},
97+
{
98+
"cell_type": "code",
99+
"execution_count": null,
100+
"metadata": {},
101+
"outputs": [],
102+
"source": [
103+
"from pyetm.utils import regionalise_curves\n",
104+
"\n",
105+
"# regionalize the mapped curves\n",
106+
"# the regionalisation returns the residual profile\n",
107+
"regionalised = regionalise_curves(mapped, reg=reg)\n",
108+
"regionalised.round(4).head()"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"The `regionalise_curves` function returns the residual profiles per region/node.\n",
116+
"This is mainly due to performance and memory constraints that make it difficult \n",
117+
"to hold the mapped curves for each region/node in memory. When needed, the \n",
118+
"`regionalise_node` function makes it possible to return the detailed profiles\n",
119+
"for the selected node."
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": null,
125+
"metadata": {},
126+
"outputs": [],
127+
"source": [
128+
"from pyetm.utils import regionalise_node\n",
129+
"\n",
130+
"# return detailed curves for a specific node\n",
131+
"ncurves = regionalise_node(mapped, reg=reg, node=0)\n",
132+
"ncurves.round(4).head()"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"metadata": {},
139+
"outputs": [],
140+
"source": []
141+
}
142+
],
143+
"metadata": {
144+
"kernelspec": {
145+
"display_name": "pyetm",
146+
"language": "python",
147+
"name": "python3"
148+
},
149+
"language_info": {
150+
"codemirror_mode": {
151+
"name": "ipython",
152+
"version": 3
153+
},
154+
"file_extension": ".py",
155+
"mimetype": "text/x-python",
156+
"name": "python",
157+
"nbconvert_exporter": "python",
158+
"pygments_lexer": "ipython3",
159+
"version": "3.9.18"
160+
}
161+
},
162+
"nbformat": 4,
163+
"nbformat_minor": 2
164+
}

0 commit comments

Comments
 (0)