├── README.md
├── .gitignore
├── environment.yaml
├── .pre-commit-config.yaml
├── data
└── connection.csv
├── src
├── availabiltiy.ipynb
├── sankey.ipynb
└── plots.ipynb
└── LICENSE
/README.md:
--------------------------------------------------------------------------------
1 | # Dashboard for PyPSA-Eur-Sec
2 |
3 | Based on Holoviews.
4 |
5 | ## Deploy
6 |
7 | with `heroku`
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *__pycache__
2 | .snakemake
3 | .vscode
4 | dconf
5 | results
6 | *.ipynb_checkpoints
7 | #*.ipynb
8 | summary
9 | *.nc
10 | *.log
11 | *.pdf
12 | *.png
13 | *.html
14 |
15 |
--------------------------------------------------------------------------------
/environment.yaml:
--------------------------------------------------------------------------------
1 | name:
2 | pypsa-dashboard
3 |
4 | channels:
5 | - conda-forge
6 |
7 | dependencies:
8 | - python
9 | - pip
10 | - ipython
11 | - pre-commit
12 | - mamba
13 | - yaml
14 | - pypsa
15 | - cartopy
16 | - networkx
17 | - hvplot
18 | - geoviews
19 | - nodejs
20 | - bokeh
21 | - holoviews
22 | - xarray
23 | - pandas
24 | - geopandas
25 | - numpy
26 | - panel
27 | - jupyterlab
28 | - atlite
29 | - pyepsg
30 | - plotly
31 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v4.3.0
4 | hooks:
5 | - id: trailing-whitespace
6 | #- id: end-of-file-fixer
7 | - id: check-yaml
8 | - id: check-merge-conflict
9 | - id: check-added-large-files
10 | args: ['--maxkb=1000']
11 | # - repo: https://github.com/fsfe/reuse-tool
12 | # rev: latest
13 | # hooks:
14 | # - id: reuse
15 | - repo: https://github.com/psf/black
16 | rev: 22.10.0
17 | hooks:
18 | - id: black
19 | - repo: https://github.com/aflc/pre-commit-jupyter
20 | rev: v1.2.1
21 | hooks:
22 | - id: jupyter-notebook-cleanup
23 | args:
24 | - --remove-kernel-metadata
25 |
--------------------------------------------------------------------------------
/data/connection.csv:
--------------------------------------------------------------------------------
1 | source,target,value
2 | electricity,central air heat pump,1
3 | electricity,central resistive heater,1
4 | H2,fuel cell,1
5 | solid biomass,biomass CHP,1
6 | CH4,central gas boiler,1
7 | CH4,gas CHP,1
8 | central air heat pump,district heating,1
9 | central resistive heater,district heating,1
10 | fuel cell,district heating,1
11 | biomass CHP,district heating,1
12 | central gas boiler,district heating,1
13 | gas CHP,district heating,1
14 | electricity distribution,air heat pump,1
15 | electricity distribution,resistive heater,1
16 | CH4 distribution,gas boiler,1
17 | electricity distribution,ground heat pump,1
18 | air heat pump,urban individual,1
19 | resistive heater,urban individual,1
20 | gas boiler,urban individual,1
21 | gas boiler,rural individual,1
22 | ground heat pump,rural individual,1
23 | central solar thermal,district heating,1
24 | solar thermal,urban individual,1
25 | solar thermal,rural individual,1
26 | urban individual,urban residential,1
27 | urban individual,urban service,1
28 | rural individual,rural residential,1
29 | rural individual,rural service,1
30 | solar energy,solar thermal,1
31 | solar energy,central solar thermal,1
32 | electricity,electricity distribution,1
33 | CH4,CH4 distribution,1
34 |
--------------------------------------------------------------------------------
/src/availabiltiy.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "73b1f3a7-3535-44b1-ac4d-c37fe577e1ef",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": [
10 | "import xarray as xr\n",
11 | "import numpy as np\n",
12 | "import hvplot.xarray\n",
13 | "from rasterio.warp import transform"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": null,
19 | "id": "ae426cf2-fc91-4559-9773-cebb2cb27270",
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "def get_latlon(da):\n",
24 | " \n",
25 | " # Compute the lon/lat coordinates with rasterio.warp.transform\n",
26 | " ny, nx = len(da['y']), len(da['x'])\n",
27 | " x, y = np.meshgrid(da['x'], da['y'])\n",
28 | "\n",
29 | " # Rasterio works with 1D arrays\n",
30 | " lon, lat = transform(da.crs, {'init': 'EPSG:4326'},\n",
31 | " x.flatten(), y.flatten())\n",
32 | " lon = np.asarray(lon).reshape((ny, nx))\n",
33 | " lat = np.asarray(lat).reshape((ny, nx))\n",
34 | " da.coords['lon'] = (('y', 'x'), lon)\n",
35 | " da.coords['lat'] = (('y', 'x'), lat)\n",
36 | " da = da.drop_vars([\"x\", \"y\"])\n",
37 | " return da\n",
38 | "\n",
39 | "fn = \"../data/onwind-av-595.tif\"\n",
40 | "\n",
41 | "def convert_to_dataset(fn):\n",
42 | " da = xr.open_rasterio(fn)\n",
43 | " da = get_latlon(da).mean(dim='band')\n",
44 | " ds = da.where((da.values < 255) & (da.values > 0)).to_dataset(name='availability')\n",
45 | " #ds.to_netcdf(fn.replace(\".tif\", \".nc\")) # much memory\n",
46 | " return ds\n",
47 | "\n",
48 | "\n",
49 | "%memit\n",
50 | "ds = convert_to_dataset(fn)\n",
51 | "\n",
52 | "%memit\n",
53 | "ds.hvplot.contourf(\n",
54 | " 'lon',\n",
55 | " 'lat',\n",
56 | " 'availability',\n",
57 | " geo=True,\n",
58 | " tiles=\"CartoLight\",\n",
59 | " cmap='Greens',\n",
60 | " alpha=0.5,\n",
61 | " frame_height=800,\n",
62 | " colorbar=False,\n",
63 | " legend=False,\n",
64 | " hover=False,\n",
65 | " title=\"Available Land\"\n",
66 | ").opts(\n",
67 | " active_tools=['pan', 'wheel_zoom']\n",
68 | ")"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": null,
74 | "id": "1dc75d2f-2be1-4505-b581-7a1d02de1682",
75 | "metadata": {},
76 | "outputs": [],
77 | "source": []
78 | }
79 | ],
80 | "metadata": {
81 | "kernelspec": {
82 | "display_name": "",
83 | "language": "python",
84 | "name": ""
85 | },
86 | "language_info": {
87 | "codemirror_mode": {
88 | "name": "ipython",
89 | "version": 3
90 | },
91 | "file_extension": ".py",
92 | "mimetype": "text/x-python",
93 | "name": "python",
94 | "nbconvert_exporter": "python",
95 | "pygments_lexer": "ipython3",
96 | "version": "3.8.8"
97 | }
98 | },
99 | "nbformat": 4,
100 | "nbformat_minor": 5
101 | }
--------------------------------------------------------------------------------
/src/sankey.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "a813a8a4-ee0f-4daf-abcb-d0315b1309fd",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": [
10 | "import pypsa\n",
11 | "import pandas as pd\n",
12 | "from pypsa.descriptors import get_switchable_as_dense\n",
13 | "import plotly.graph_objects as go\n",
14 | "import numpy as np\n",
15 | "import yaml\n",
16 | "from matplotlib.colors import to_rgba\n",
17 | "pd.set_option('display.max_rows', 150)"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "id": "5f98d87b-a1af-41bb-abcf-e91f02f3f459",
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "path = \"../../pr/\""
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "id": "e8b246eb-25a5-4e11-b3e2-c663d566d16a",
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "with open(path + \"pypsa-eur-sec/config.yaml\") as file:\n",
38 | " config = yaml.safe_load(file)\n",
39 | "\n",
40 | "colors = config[\"plotting\"][\"tech_colors\"]\n",
41 | "\n",
42 | "colors[\"electricity grid\"] = \"teal\"\n",
43 | "colors[\"ground-sourced ambient\"] = \"orchid\"\n",
44 | "colors[\"air-sourced ambient\"] = \"thistle\""
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "id": "82d4255a-00f2-4226-8bd0-ce341395602e",
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "n = pypsa.Network(\n",
55 | " path + \"pypsa-eur-sec/results/your-run-name-overnight-dev/postnetworks/elec_s_60_lv1.25__Co2L0p0-365H-T-H-B-I-solar+p3-dist1_2030.nc\"\n",
56 | ")"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "id": "6ca681e7-b23e-4546-9853-ab5354cd9f03",
63 | "metadata": {},
64 | "outputs": [],
65 | "source": [
66 | "columns = [\"label\", \"source\", \"target\", \"value\"]"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "id": "386ae142-95fb-4e3a-a524-ed0335a2145d",
73 | "metadata": {
74 | "tags": []
75 | },
76 | "outputs": [],
77 | "source": [
78 | "gen = (n.snapshot_weightings @ n.generators_t.p).groupby([\n",
79 | " n.generators.carrier, n.generators.carrier, n.generators.bus.map(n.buses.carrier)\n",
80 | "]).sum().div(1e6) # TWh\n",
81 | "\n",
82 | "gen.index.set_names(columns[:-1], inplace=True)\n",
83 | "gen = gen.reset_index(name='value')\n",
84 | "gen = gen.loc[gen.value>0.1]"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "id": "68dec579-9201-49af-bb67-78de52ed5dfa",
91 | "metadata": {
92 | "tags": []
93 | },
94 | "outputs": [],
95 | "source": [
96 | "gen[\"source\"] = gen[\"source\"].replace({\n",
97 | " \"gas\": \"fossil gas\",\n",
98 | " \"oil\": \"fossil oil\"\n",
99 | "})"
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": null,
105 | "id": "9c9778aa-4553-4b25-b54a-b860f17f9cf7",
106 | "metadata": {
107 | "tags": []
108 | },
109 | "outputs": [],
110 | "source": [
111 | "sto = (n.snapshot_weightings @ n.stores_t.p).groupby([\n",
112 | " n.stores.carrier, n.stores.carrier, n.stores.bus.map(n.buses.carrier)\n",
113 | "]).sum().div(1e6)\n",
114 | "sto.index.set_names(columns[:-1], inplace=True)\n",
115 | "sto = sto.reset_index(name='value')\n",
116 | "sto = sto.loc[sto.value>.1]"
117 | ]
118 | },
119 | {
120 | "cell_type": "code",
121 | "execution_count": null,
122 | "id": "291df2b3-6047-481c-a662-0619e0688183",
123 | "metadata": {
124 | "tags": []
125 | },
126 | "outputs": [],
127 | "source": [
128 | "su = (n.snapshot_weightings @ n.storage_units_t.p).groupby([\n",
129 | " n.storage_units.carrier, n.storage_units.carrier, n.storage_units.bus.map(n.buses.carrier)\n",
130 | "]).sum().div(1e6)\n",
131 | "su.index.set_names(columns[:-1], inplace=True)\n",
132 | "su = su.reset_index(name='value')\n",
133 | "su = su.loc[su.value>.1]"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": null,
139 | "id": "81b75732-57a6-4cb3-8fbb-89bef7f4d7be",
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "load = (n.snapshot_weightings @ get_switchable_as_dense(n, \"Load\", \"p_set\")).groupby([\n",
144 | " n.loads.carrier, n.loads.carrier, n.loads.bus.map(n.buses.carrier)\n",
145 | "]).sum().div(1e6).swaplevel() # TWh\n",
146 | "load.index.set_names(columns[:-1], inplace=True)\n",
147 | "load = load.reset_index(name='value')"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "id": "53b869dd-ce7a-44fc-bef2-f4f00a7f7ec0",
154 | "metadata": {},
155 | "outputs": [],
156 | "source": [
157 | "load = load.loc[~load.label.str.contains(\"emissions\")]\n",
158 | "load.target += \" demand\""
159 | ]
160 | },
161 | {
162 | "cell_type": "code",
163 | "execution_count": null,
164 | "id": "4321f89c-7134-4bf3-b5e3-de0ddc6285b7",
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "for i in range(5):\n",
169 | " n.links[f\"total_e{i}\"] = (n.snapshot_weightings @ n.links_t[f\"p{i}\"]).div(1e6) # TWh\n",
170 | " n.links[f\"carrier_bus{i}\"] = n.links[f\"bus{i}\"].map(n.buses.carrier)"
171 | ]
172 | },
173 | {
174 | "cell_type": "code",
175 | "execution_count": null,
176 | "id": "a18986e8-4d4a-4da1-8169-0ea212992197",
177 | "metadata": {},
178 | "outputs": [],
179 | "source": [
180 | "def calculate_losses(x):\n",
181 | " energy_ports = x.loc[\n",
182 | " x.index.str.contains(\"carrier_bus\") &\n",
183 | " ~x.str.contains(\"co2\", na=False)\n",
184 | " ].index.str.replace(\"carrier_bus\", \"total_e\")\n",
185 | " return -x.loc[energy_ports].sum()\n",
186 | "\n",
187 | "n.links[\"total_e5\"] = n.links.apply(calculate_losses, axis=1)\n",
188 | "n.links[\"carrier_bus5\"] = \"losses\""
189 | ]
190 | },
191 | {
192 | "cell_type": "code",
193 | "execution_count": null,
194 | "id": "ecd0d6f3-3dcc-435b-ab69-647323856c9e",
195 | "metadata": {},
196 | "outputs": [],
197 | "source": [
198 | "df = pd.concat([\n",
199 | " n.links.groupby([\"carrier\", \"carrier_bus0\", \"carrier_bus\" + str(i)]).sum()[\"total_e\" + str(i)] for i in range(1,6)\n",
200 | "]).reset_index()\n",
201 | "df.columns = columns"
202 | ]
203 | },
204 | {
205 | "cell_type": "code",
206 | "execution_count": null,
207 | "id": "48e26814-b2ba-42dc-9aec-ba8c254a5247",
208 | "metadata": {},
209 | "outputs": [],
210 | "source": [
211 | "# fix heat pump energy balance\n",
212 | "\n",
213 | "hp = n.links.loc[n.links.carrier.str.contains(\"heat pump\")]\n",
214 | "\n",
215 | "hp_t_elec = n.links_t.p0.filter(like=\"heat pump\")\n",
216 | "\n",
217 | "hp_elec = (-n.snapshot_weightings @ hp_t_elec).groupby([hp[\"carrier\"], hp[\"carrier_bus0\"], hp[\"carrier_bus1\"]]).sum().div(1e6).reset_index()\n",
218 | "hp_elec.columns = columns\n",
219 | "\n",
220 | "df = df.loc[~(df.label.str.contains(\"heat pump\") & (df.target == 'losses'))]\n",
221 | "\n",
222 | "df.loc[df.label.str.contains(\"heat pump\"), \"value\"] -= hp_elec[\"value\"].values\n",
223 | "\n",
224 | "df.loc[df.label.str.contains(\"air heat pump\"), \"source\"] = \"air-sourced ambient\"\n",
225 | "df.loc[df.label.str.contains(\"ground heat pump\"), \"source\"] = \"ground-sourced ambient\"\n",
226 | "\n",
227 | "df = pd.concat([df, hp_elec])"
228 | ]
229 | },
230 | {
231 | "cell_type": "code",
232 | "execution_count": null,
233 | "id": "78a51a1e-eada-4ce3-b515-a960e4c6bd38",
234 | "metadata": {},
235 | "outputs": [],
236 | "source": [
237 | "df = df.set_index([\"label\", \"source\", \"target\"]).squeeze()"
238 | ]
239 | },
240 | {
241 | "cell_type": "code",
242 | "execution_count": null,
243 | "id": "bf882f43-ba4d-4306-b9eb-209e2344e00d",
244 | "metadata": {},
245 | "outputs": [],
246 | "source": [
247 | "df = pd.concat([\n",
248 | " df.loc[df<0].mul(-1),\n",
249 | " df.loc[df>0].swaplevel(1, 2),\n",
250 | "]).reset_index()\n",
251 | "\n",
252 | "df.columns = columns"
253 | ]
254 | },
255 | {
256 | "cell_type": "code",
257 | "execution_count": null,
258 | "id": "c8d6d312-802d-4e1a-8fa8-8af99d8d99fd",
259 | "metadata": {},
260 | "outputs": [],
261 | "source": [
262 | "# make DAC demand\n",
263 | "df.loc[df.label=='DAC', \"target\"] = \"DAC\""
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": null,
269 | "id": "bedabe97-0011-4acd-9439-9c40b2578a1d",
270 | "metadata": {},
271 | "outputs": [],
272 | "source": [
273 | "connections = pd.concat([\n",
274 | " df,\n",
275 | " gen,\n",
276 | " su,\n",
277 | " sto,\n",
278 | " load,\n",
279 | "]).sort_index().reset_index(drop=True)"
280 | ]
281 | },
282 | {
283 | "cell_type": "code",
284 | "execution_count": null,
285 | "id": "ab5bdfd1-bcc8-4665-81da-070df4ef3f94",
286 | "metadata": {},
287 | "outputs": [],
288 | "source": [
289 | "# aggregation\n",
290 | "\n",
291 | "src_contains = connections.source.str.contains\n",
292 | "trg_contains = connections.target.str.contains\n",
293 | "\n",
294 | "connections.loc[src_contains(\"low voltage\"), \"source\"] = \"AC\"\n",
295 | "connections.loc[trg_contains(\"low voltage\"), \"target\"] = \"AC\"\n",
296 | "connections.loc[src_contains(\"water tank\"), \"source\"] = \"water tank\"\n",
297 | "connections.loc[trg_contains(\"water tank\"), \"target\"] = \"water tank\"\n",
298 | "connections.loc[src_contains(\"solar thermal\"), \"source\"] = \"solar thermal\"\n",
299 | "connections.loc[src_contains(\"battery\"), \"source\"] = \"battery\"\n",
300 | "connections.loc[trg_contains(\"battery\"), \"target\"] = \"battery\"\n",
301 | "connections.loc[src_contains(\"Li ion\"), \"source\"] = \"battery\"\n",
302 | "connections.loc[trg_contains(\"Li ion\"), \"target\"] = \"battery\"\n",
303 | "\n",
304 | "connections.loc[src_contains(\"heat\") & ~src_contains(\"demand\"), \"source\"] = \"heat\"\n",
305 | "connections.loc[trg_contains(\"heat\") & ~trg_contains(\"demand\"), \"target\"] = \"heat\""
306 | ]
307 | },
308 | {
309 | "cell_type": "code",
310 | "execution_count": null,
311 | "id": "aeed8a23-f45f-4627-a324-2ef3c3ba253c",
312 | "metadata": {},
313 | "outputs": [],
314 | "source": [
315 | "connections = connections.loc[\n",
316 | " ~(connections.source == connections.target) \n",
317 | " & ~connections.source.str.contains(\"co2\")\n",
318 | " & ~connections.target.str.contains(\"co2\")\n",
319 | " & ~connections.source.str.contains(\"emissions\")\n",
320 | " & ~connections.source.isin(['gas for industry', \"solid biomass for industry\"])\n",
321 | " & (connections.value >= 0.5)\n",
322 | "]"
323 | ]
324 | },
325 | {
326 | "cell_type": "code",
327 | "execution_count": null,
328 | "id": "02884f54-197e-478e-aac6-32877ef806bc",
329 | "metadata": {},
330 | "outputs": [],
331 | "source": [
332 | "where = connections.label=='urban central gas boiler'\n",
333 | "connections.loc[where] = connections.loc[where].replace(\"losses\", \"fossil gas\")"
334 | ]
335 | },
336 | {
337 | "cell_type": "code",
338 | "execution_count": null,
339 | "id": "98d6e9fd-e796-4844-802b-87ca0deae74f",
340 | "metadata": {},
341 | "outputs": [],
342 | "source": [
343 | "connections.replace(\"AC\", \"electricity grid\", inplace=True)"
344 | ]
345 | },
346 | {
347 | "cell_type": "code",
348 | "execution_count": null,
349 | "id": "cbc458ec-e312-4a5d-828c-5ecb48371a16",
350 | "metadata": {},
351 | "outputs": [],
352 | "source": [
353 | "labels = np.unique(connections[[\"source\", \"target\"]])"
354 | ]
355 | },
356 | {
357 | "cell_type": "code",
358 | "execution_count": null,
359 | "id": "fedea992-d294-4ccf-8ae8-26a030364e82",
360 | "metadata": {},
361 | "outputs": [],
362 | "source": [
363 | "nodes = pd.Series({v: i for i, v in enumerate(labels)})"
364 | ]
365 | },
366 | {
367 | "cell_type": "code",
368 | "execution_count": null,
369 | "id": "8c5a62a8-615a-4e99-9fcb-94b9c75314b9",
370 | "metadata": {},
371 | "outputs": [],
372 | "source": [
373 | "node_colors = pd.Series(nodes.index.map(colors).fillna(\"grey\"), index=nodes.index)"
374 | ]
375 | },
376 | {
377 | "cell_type": "code",
378 | "execution_count": null,
379 | "id": "f3c83a27-57c3-4aeb-b8dc-f1d1e74c0b80",
380 | "metadata": {},
381 | "outputs": [],
382 | "source": [
383 | "link_colors = [\"rgba{}\".format(to_rgba(node_colors[src], alpha=0.5)) for src in connections.source]"
384 | ]
385 | },
386 | {
387 | "cell_type": "code",
388 | "execution_count": null,
389 | "id": "8f4b647a-9f8b-4ee1-87b5-8554e18dc157",
390 | "metadata": {},
391 | "outputs": [],
392 | "source": [
393 | "fig = go.Figure(go.Sankey(\n",
394 | " arrangement=\"snap\", # [snap, nodepad, perpendicular, fixed]\n",
395 | " valuesuffix = \"TWh\",\n",
396 | " valueformat = \".1f\",\n",
397 | " node = dict(\n",
398 | " pad=15,\n",
399 | " thickness=10,\n",
400 | " label=nodes.index,\n",
401 | " color=node_colors\n",
402 | " ),\n",
403 | " link = dict(\n",
404 | " source=connections.source.map(nodes),\n",
405 | " target=connections.target.map(nodes),\n",
406 | " value=connections.value,\n",
407 | " label=connections.label,\n",
408 | " color=link_colors,\n",
409 | " )\n",
410 | "))\n",
411 | "\n",
412 | "fig.update_layout(\n",
413 | " title=\"Sankey Diagram: PyPSA-Eur-Sec\",\n",
414 | " font_size=15\n",
415 | ")\n",
416 | "\n",
417 | "fig.write_html(\"Co2L0p0.html\")"
418 | ]
419 | },
420 | {
421 | "cell_type": "code",
422 | "execution_count": null,
423 | "id": "d46b699e-9cd1-49a0-bde8-62ec44775d65",
424 | "metadata": {},
425 | "outputs": [],
426 | "source": []
427 | },
428 | {
429 | "cell_type": "code",
430 | "execution_count": null,
431 | "id": "d71666a0-cb19-4e7f-b2b3-c7738b061aa4",
432 | "metadata": {},
433 | "outputs": [],
434 | "source": []
435 | },
436 | {
437 | "cell_type": "code",
438 | "execution_count": null,
439 | "id": "9fb71d86-50c1-45e4-bcb9-a9d361283956",
440 | "metadata": {},
441 | "outputs": [],
442 | "source": []
443 | },
444 | {
445 | "cell_type": "code",
446 | "execution_count": null,
447 | "id": "9c463429-fed7-4f76-8ebb-c637e295f389",
448 | "metadata": {},
449 | "outputs": [],
450 | "source": []
451 | },
452 | {
453 | "cell_type": "code",
454 | "execution_count": null,
455 | "id": "41c5de09-0405-436b-bbb3-9414c87147f8",
456 | "metadata": {},
457 | "outputs": [],
458 | "source": []
459 | },
460 | {
461 | "cell_type": "code",
462 | "execution_count": null,
463 | "id": "def746c4-2a0f-416b-81eb-46e455096f94",
464 | "metadata": {},
465 | "outputs": [],
466 | "source": []
467 | },
468 | {
469 | "cell_type": "code",
470 | "execution_count": null,
471 | "id": "41c6859d-3393-40aa-a235-ebc05f635de4",
472 | "metadata": {},
473 | "outputs": [],
474 | "source": []
475 | },
476 | {
477 | "cell_type": "code",
478 | "execution_count": null,
479 | "id": "e359d938-8c1a-41af-85f2-af3507fc03f7",
480 | "metadata": {},
481 | "outputs": [],
482 | "source": []
483 | }
484 | ],
485 | "metadata": {
486 | "kernelspec": {
487 | "display_name": "",
488 | "language": "python",
489 | "name": ""
490 | },
491 | "language_info": {
492 | "codemirror_mode": {
493 | "name": "ipython",
494 | "version": 3
495 | },
496 | "file_extension": ".py",
497 | "mimetype": "text/x-python",
498 | "name": "python",
499 | "nbconvert_exporter": "python",
500 | "pygments_lexer": "ipython3",
501 | "version": "3.8.8"
502 | }
503 | },
504 | "nbformat": 4,
505 | "nbformat_minor": 5
506 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | Loss Approximation
635 | Copyright (C) 2020 FN
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Loss Approximation Copyright (C) 2020 FN
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/src/plots.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import pypsa\n",
10 | "import atlite\n",
11 | "import yaml\n",
12 | "\n",
13 | "import pandas as pd\n",
14 | "import numpy as np\n",
15 | "import geopandas as gpd\n",
16 | "import xarray as xr\n",
17 | "import networkx as nx\n",
18 | "\n",
19 | "import panel as pn\n",
20 | "import panel.widgets as pnw\n",
21 | "import holoviews as hv\n",
22 | "\n",
23 | "import cartopy.crs as ccrs\n",
24 | "\n",
25 | "from rasterio.warp import transform\n",
26 | "\n",
27 | "import hvplot.pandas\n",
28 | "import hvplot.xarray\n",
29 | "import hvplot.networkx as hvnx"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "from bokeh.models.formatters import DatetimeTickFormatter\n",
39 | "pn.extension()"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "path = \"../../pr/\"\n",
49 | "clusters = 60"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {},
56 | "outputs": [],
57 | "source": [
58 | "with open(path + \"pypsa-eur-sec/config.yaml\") as file:\n",
59 | " config = yaml.safe_load(file)\n",
60 | "\n",
61 | "colors = config[\"plotting\"][\"tech_colors\"]"
62 | ]
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "metadata": {},
67 | "source": [
68 | "## Solved Network"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": null,
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "n = pypsa.Network(\n",
78 | " path + f\"pypsa-eur-sec/results/your-run-name-overnight-dev/postnetworks/elec_s_{clusters}_lv1.25__Co2L0p0-365H-T-H-B-I-solar+p3-dist1_2030.nc\"\n",
79 | ")"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {},
85 | "source": [
86 | "## Geometry Polygon Data"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": null,
92 | "metadata": {},
93 | "outputs": [],
94 | "source": [
95 | "# shapes\n",
96 | "nodes = gpd.read_file(path + f\"pypsa-eur/resources/regions_onshore_elec_s_{clusters}.geojson\").set_index('name')\n",
97 | "cts = gpd.read_file(path + \"pypsa-eur/resources/country_shapes.geojson\").set_index('name')"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": null,
103 | "metadata": {},
104 | "outputs": [],
105 | "source": [
106 | "regions = gpd.read_file(path + \"pypsa-eur/resources/regions_onshore.geojson\").append(\n",
107 | " gpd.read_file(path + \"pypsa-eur/resources/regions_offshore.geojson\"))\n",
108 | "regions = regions.dissolve('name') \n",
109 | "onregions = gpd.read_file(path + \"pypsa-eur/resources/regions_onshore.geojson\").set_index('name')\n",
110 | "regions[\"Area\"] = regions.to_crs(epsg=3035).area.div(1e6)\n",
111 | "onregions[\"Area\"] = onregions.to_crs(epsg=3035).area.div(1e6)"
112 | ]
113 | },
114 | {
115 | "cell_type": "markdown",
116 | "metadata": {},
117 | "source": [
118 | "## Model Inputs"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {},
125 | "outputs": [],
126 | "source": [
127 | "# country-level data\n",
128 | "co2 = pd.read_csv(path + \"pypsa-eur-sec/resources/co2_totals.csv\", index_col=0)\n",
129 | "energy = pd.read_csv(path + \"pypsa-eur-sec/resources/energy_totals.csv\", index_col=0)\n",
130 | "transport = pd.read_csv(path + \"pypsa-eur-sec/resources/transport_data.csv\", index_col=0)\n",
131 | "biomass = pd.read_csv(path + \"pypsa-eur-sec/resources/biomass_potentials.csv\", index_col=0)"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": null,
137 | "metadata": {},
138 | "outputs": [],
139 | "source": [
140 | "# nodal-level data\n",
141 | "pop = pd.read_csv(path + f\"pypsa-eur-sec/resources/pop_layout_elec_s_{clusters}.csv\", index_col=0)\n",
142 | "idist = pd.read_csv(path + f\"pypsa-eur-sec/resources/industrial_distribution_key_elec_s_{clusters}.csv\", index_col=0)\n",
143 | "ienergy = pd.read_csv(path + f\"pypsa-eur-sec/resources/industrial_energy_demand_elec_s_{clusters}.csv\", index_col=0)\n",
144 | "iproduction = pd.read_csv(path + f\"pypsa-eur-sec/resources/industrial_production_elec_s_{clusters}.csv\", index_col=0)\n",
145 | "ienergy[\"total\"] = ienergy.sum(axis=1)\n",
146 | "iproduction[\"total\"] = iproduction.sum(axis=1)"
147 | ]
148 | },
149 | {
150 | "cell_type": "code",
151 | "execution_count": null,
152 | "metadata": {},
153 | "outputs": [],
154 | "source": [
155 | "def cmap(select):\n",
156 | " if \"bio\" in select:\n",
157 | " return \"Greens\"\n",
158 | " elif \"solar\" in select:\n",
159 | " return \"Reds\"\n",
160 | " elif \"wind\" in select:\n",
161 | " return \"Blues\"\n",
162 | " elif \"LULUCF\" in select:\n",
163 | " return \"RdBu\"\n",
164 | " else:\n",
165 | " return \"YlGnBu\""
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": null,
171 | "metadata": {},
172 | "outputs": [],
173 | "source": [
174 | "def plot_geo(gdf, df, options, clim=None, tiles=None, alpha=1., line_width=0.6, select=True):\n",
175 | "\n",
176 | " if select:\n",
177 | " selector = pnw.Select(options=options)\n",
178 | " else:\n",
179 | " selector = pnw.RadioBoxGroup(options=options)\n",
180 | "\n",
181 | " def _plot(select):\n",
182 | " return gdf.hvplot(\n",
183 | " geo=True,\n",
184 | " frame_height=700,\n",
185 | " c=df[select],\n",
186 | " tiles=tiles,\n",
187 | " alpha=alpha,\n",
188 | " line_width=line_width,\n",
189 | " cmap=cmap(select),\n",
190 | " clim=clim,\n",
191 | " hover_cols=['name']\n",
192 | " ).opts(\n",
193 | " active_tools=['pan', 'wheel_zoom']\n",
194 | " )\n",
195 | "\n",
196 | " plot = pn.bind(_plot, selector)\n",
197 | " widgets = pn.Column(selector, plot)\n",
198 | " return widgets"
199 | ]
200 | },
201 | {
202 | "cell_type": "markdown",
203 | "metadata": {},
204 | "source": [
205 | "### country-level"
206 | ]
207 | },
208 | {
209 | "cell_type": "code",
210 | "execution_count": null,
211 | "metadata": {},
212 | "outputs": [],
213 | "source": [
214 | "plt_co2 = plot_geo(cts, co2, list(co2.columns))"
215 | ]
216 | },
217 | {
218 | "cell_type": "code",
219 | "execution_count": null,
220 | "metadata": {},
221 | "outputs": [],
222 | "source": [
223 | "plt_energy = plot_geo(cts, energy, list(energy.columns))"
224 | ]
225 | },
226 | {
227 | "cell_type": "markdown",
228 | "metadata": {},
229 | "source": [
230 | "## nodal level"
231 | ]
232 | },
233 | {
234 | "cell_type": "code",
235 | "execution_count": null,
236 | "metadata": {},
237 | "outputs": [],
238 | "source": [
239 | "plt_production = plot_geo(nodes, iproduction, list(iproduction.columns))"
240 | ]
241 | },
242 | {
243 | "cell_type": "code",
244 | "execution_count": null,
245 | "metadata": {},
246 | "outputs": [],
247 | "source": [
248 | "plt_population = plot_geo(nodes, pop, [\"total\", \"urban\", 'rural'])"
249 | ]
250 | },
251 | {
252 | "cell_type": "markdown",
253 | "metadata": {},
254 | "source": [
255 | "## Powerplantmatching"
256 | ]
257 | },
258 | {
259 | "cell_type": "code",
260 | "execution_count": null,
261 | "metadata": {},
262 | "outputs": [],
263 | "source": [
264 | "plants = pd.read_csv(\"https://raw.githubusercontent.com/FRESNA/powerplantmatching/master/matched_data_red.csv\", index_col=0)\n",
265 | "plants = plants.loc[(plants.lat > 34) & (plants.lon < 72)]"
266 | ]
267 | },
268 | {
269 | "cell_type": "code",
270 | "execution_count": null,
271 | "metadata": {},
272 | "outputs": [],
273 | "source": [
274 | "ppm_colors = {\n",
275 | " \"Hydro\": 'teal',\n",
276 | " \"Hard Coal\": 'black',\n",
277 | " \"Lignite\": 'grey',\n",
278 | " \"Natural Gas\": 'orange',\n",
279 | " \"Nuclear\": 'red',\n",
280 | " \"Oil\": 'brown',\n",
281 | " \"Bioenergy\": 'green',\n",
282 | " \"Wind\": '#235ebc',\n",
283 | " \"Geothermal\": 'purple',\n",
284 | " \"Solar\": '#f9d002',\n",
285 | " \"Waste\": \"magenta\",\n",
286 | " \"Other\": 'white',\n",
287 | "}"
288 | ]
289 | },
290 | {
291 | "cell_type": "code",
292 | "execution_count": null,
293 | "metadata": {},
294 | "outputs": [],
295 | "source": [
296 | "plt_powerplants = plants.hvplot.points(\n",
297 | " 'lon',\n",
298 | " 'lat',\n",
299 | " geo=True,\n",
300 | " frame_height=750,\n",
301 | " c='Fueltype',\n",
302 | " cmap=ppm_colors,\n",
303 | " size=plants[\"Capacity\"] / 5,\n",
304 | " alpha=0.4,\n",
305 | " tiles='CartoLight',\n",
306 | " hover_cols=['Name', 'Fueltype', \"Technology\", 'YearCommissioned', \"Retrofit\", \"Capacity\"],\n",
307 | " xlim=(-12,32),\n",
308 | ").opts(\n",
309 | " active_tools=['pan', 'wheel_zoom']\n",
310 | ")"
311 | ]
312 | },
313 | {
314 | "cell_type": "markdown",
315 | "metadata": {},
316 | "source": [
317 | "### Renewable Potentials Unclustered"
318 | ]
319 | },
320 | {
321 | "cell_type": "code",
322 | "execution_count": null,
323 | "metadata": {},
324 | "outputs": [],
325 | "source": [
326 | "wind = pd.Series()\n",
327 | "for profile in ['onwind', 'offwind-ac', 'offwind-dc']:\n",
328 | " ds = xr.open_dataset(f'{path}/pypsa-eur/resources/profile_{profile}.nc')\n",
329 | " wind = wind.append((ds.p_nom_max * ds.profile.sum('time')).to_pandas())\n",
330 | "wind = wind.sum(level=0).reindex(regions.index, fill_value=0)\n",
331 | "wind_per_skm = pd.DataFrame({\"wind\": wind / regions.Area / 1e3}) # GWh"
332 | ]
333 | },
334 | {
335 | "cell_type": "code",
336 | "execution_count": null,
337 | "metadata": {},
338 | "outputs": [],
339 | "source": [
340 | "ds = xr.open_dataset(f'{path}/pypsa-eur/resources/profile_solar.nc')\n",
341 | "solar = (ds.p_nom_max * ds.profile.sum('time')).to_pandas()\n",
342 | "\n",
343 | "solar = solar.sum(level=0).reindex(onregions.index, fill_value=0)\n",
344 | "solar_per_skm = pd.DataFrame({\"solar\": solar / onregions.Area / 1e3}) # GWh"
345 | ]
346 | },
347 | {
348 | "cell_type": "code",
349 | "execution_count": null,
350 | "metadata": {},
351 | "outputs": [],
352 | "source": [
353 | "plt_wind_per_skm = plot_geo(regions, wind_per_skm, [\"wind\"], tiles='CartoLight', alpha=0.5, line_width=0.1)"
354 | ]
355 | },
356 | {
357 | "cell_type": "code",
358 | "execution_count": null,
359 | "metadata": {},
360 | "outputs": [],
361 | "source": [
362 | "plt_solar_per_skm = plot_geo(onregions, solar_per_skm, [\"solar\"], tiles='CartoLight', alpha=0.7, line_width=0.1)"
363 | ]
364 | },
365 | {
366 | "cell_type": "markdown",
367 | "metadata": {},
368 | "source": [
369 | "### Renewable Potentials Clustered"
370 | ]
371 | },
372 | {
373 | "cell_type": "code",
374 | "execution_count": null,
375 | "metadata": {},
376 | "outputs": [],
377 | "source": [
378 | "cfs = n.generators_t.p_max_pu.groupby([n.generators.carrier, n.generators.bus.map(n.buses.location)], axis=1).mean().mean().unstack(0)"
379 | ]
380 | },
381 | {
382 | "cell_type": "code",
383 | "execution_count": null,
384 | "metadata": {},
385 | "outputs": [],
386 | "source": [
387 | "plt_cfs = plot_geo(nodes, cfs, list(cfs.columns))"
388 | ]
389 | },
390 | {
391 | "cell_type": "code",
392 | "execution_count": null,
393 | "metadata": {},
394 | "outputs": [],
395 | "source": [
396 | "pot = n.generators.p_nom_max.groupby([n.generators.carrier, n.generators.bus.map(n.buses.location)]).sum().unstack(0)"
397 | ]
398 | },
399 | {
400 | "cell_type": "code",
401 | "execution_count": null,
402 | "metadata": {},
403 | "outputs": [],
404 | "source": [
405 | "pot.drop(index=\"EU\", columns=['gas', 'oil', 'ror'], inplace=True)"
406 | ]
407 | },
408 | {
409 | "cell_type": "code",
410 | "execution_count": null,
411 | "metadata": {},
412 | "outputs": [],
413 | "source": [
414 | "plt_pot = plot_geo(nodes, pot, list(pot.columns))"
415 | ]
416 | },
417 | {
418 | "cell_type": "markdown",
419 | "metadata": {},
420 | "source": [
421 | "### Nodal Capacities and Costs"
422 | ]
423 | },
424 | {
425 | "cell_type": "code",
426 | "execution_count": null,
427 | "metadata": {},
428 | "outputs": [],
429 | "source": [
430 | "term_p = \"p_nom_opt\"\n",
431 | "term_e = \"e_nom_opt\""
432 | ]
433 | },
434 | {
435 | "cell_type": "raw",
436 | "metadata": {},
437 | "source": [
438 | "term_e = \"capital_cost * (e_nom_opt-e_nom)\"\n",
439 | "term_p = \"capital_cost * (p_nom_opt-p_nom)\""
440 | ]
441 | },
442 | {
443 | "cell_type": "code",
444 | "execution_count": null,
445 | "metadata": {},
446 | "outputs": [],
447 | "source": [
448 | "gen = n.generators.eval(term_p).groupby([n.generators.carrier, n.generators.bus.map(n.buses.location)]).sum()\n",
449 | "sto = n.stores.eval(term_e).groupby([n.stores.carrier, n.stores.bus.map(n.buses.location)]).sum()\n",
450 | "local_links = n.links.loc[n.links.bus0.map(n.buses.location) == n.links.bus1.map(n.buses.location)]\n",
451 | "link = local_links.eval(term_p).groupby([local_links.carrier, local_links.bus0.map(n.buses.location)]).sum()\n",
452 | "su = n.storage_units.eval(term_p).groupby([n.storage_units.carrier, n.storage_units.bus]).sum()"
453 | ]
454 | },
455 | {
456 | "cell_type": "code",
457 | "execution_count": null,
458 | "metadata": {},
459 | "outputs": [],
460 | "source": [
461 | "gen = gen.unstack().drop(\"EU\", axis=1).dropna(how='all')\n",
462 | "link = link.unstack().drop(\"EU\", axis=1).dropna(how='all')\n",
463 | "sto = sto.unstack().drop(\"EU\", axis=1).dropna(how='all')\n",
464 | "su = su.unstack()"
465 | ]
466 | },
467 | {
468 | "cell_type": "code",
469 | "execution_count": null,
470 | "metadata": {},
471 | "outputs": [],
472 | "source": [
473 | "cap = pd.concat([gen, sto, link, su]).T.div(1e3)"
474 | ]
475 | },
476 | {
477 | "cell_type": "code",
478 | "execution_count": null,
479 | "metadata": {},
480 | "outputs": [],
481 | "source": [
482 | "cap[cap <= 0.1] = 0."
483 | ]
484 | },
485 | {
486 | "cell_type": "code",
487 | "execution_count": null,
488 | "metadata": {},
489 | "outputs": [],
490 | "source": [
491 | "plt_cap = plot_geo(nodes, cap, list(cap.columns))"
492 | ]
493 | },
494 | {
495 | "cell_type": "markdown",
496 | "metadata": {},
497 | "source": [
498 | "## Base Networks"
499 | ]
500 | },
501 | {
502 | "cell_type": "code",
503 | "execution_count": null,
504 | "metadata": {},
505 | "outputs": [],
506 | "source": [
507 | "base = pypsa.Network(path + \"pypsa-eur/networks/base.nc\")"
508 | ]
509 | },
510 | {
511 | "cell_type": "code",
512 | "execution_count": null,
513 | "metadata": {},
514 | "outputs": [],
515 | "source": [
516 | "edge_ln_attrs = [\"s_nom\", \"s_nom_opt\", \"v_nom\", \"type\", \"s_nom_extendable\", \"capital_cost\", \"under_construction\", \"underground\"]\n",
517 | "edge_lk_attrs = [\"p_nom\", \"p_nom_opt\", \"type\", \"p_nom_extendable\", \"capital_cost\", \"under_construction\", \"underground\", \"underwater_fraction\", \"tags\"]"
518 | ]
519 | },
520 | {
521 | "cell_type": "code",
522 | "execution_count": null,
523 | "metadata": {},
524 | "outputs": [],
525 | "source": [
526 | "G_lines = nx.from_pandas_edgelist(base.lines.loc[base.lines.v_nom==380], 'bus0', 'bus1', edge_attr=edge_ln_attrs)\n",
527 | "G_links = nx.from_pandas_edgelist(base.links.loc[base.links.carrier=='DC'], 'bus0', 'bus1', edge_attr=edge_lk_attrs)\n",
528 | "pos = base.buses.loc[base.buses.carrier=='AC', [\"x\", \"y\"]].apply(tuple, axis=1).to_dict()"
529 | ]
530 | },
531 | {
532 | "cell_type": "code",
533 | "execution_count": null,
534 | "metadata": {},
535 | "outputs": [],
536 | "source": [
537 | "network_map = cts.hvplot(\n",
538 | " geo=True,\n",
539 | " alpha=0.,\n",
540 | " height=850,\n",
541 | " width=1400,\n",
542 | " tiles=\"CartoLight\",\n",
543 | ") * \\\n",
544 | "hvnx.draw(\n",
545 | " G_links,\n",
546 | " pos=pos,\n",
547 | " responsive=True,\n",
548 | " geo=True,\n",
549 | " node_size=0,\n",
550 | " edge_color='royalblue',\n",
551 | " inspection_policy=\"edges\",\n",
552 | " edge_width=2,\n",
553 | ") * \\\n",
554 | "hvnx.draw(\n",
555 | " G_lines,\n",
556 | " pos=pos,\n",
557 | " geo=True,\n",
558 | " node_size=0,\n",
559 | " edge_color='firebrick',\n",
560 | " node_color='black',\n",
561 | " inspection_policy=\"edges\",\n",
562 | " edge_width=2,\n",
563 | ").opts(\n",
564 | " active_tools=['pan', 'wheel_zoom']\n",
565 | ")"
566 | ]
567 | },
568 | {
569 | "cell_type": "code",
570 | "execution_count": null,
571 | "metadata": {},
572 | "outputs": [],
573 | "source": [
574 | "if len(base.lines.v_nom.unique()) > 1:\n",
575 | " G_lines_300 = nx.from_pandas_edgelist(base.lines.loc[base.lines.v_nom==300], 'bus0', 'bus1', edge_attr=edge_ln_attrs)\n",
576 | " G_lines_220 = nx.from_pandas_edgelist(base.lines.loc[base.lines.v_nom==220], 'bus0', 'bus1', edge_attr=edge_ln_attrs)\n",
577 | " network_map *= \\\n",
578 | " hvnx.draw(\n",
579 | " G_lines_300,\n",
580 | " pos=pos,\n",
581 | " geo=True,\n",
582 | " node_size=0,\n",
583 | " edge_color='orange',\n",
584 | " edge_width=1.5,\n",
585 | " inspection_policy=\"edges\"\n",
586 | " ) * \\\n",
587 | " hvnx.draw(\n",
588 | " G_lines_220,\n",
589 | " pos=pos,\n",
590 | " geo=True,\n",
591 | " node_size=0,\n",
592 | " edge_width=1,\n",
593 | " edge_color='green',\n",
594 | " inspection_policy=\"edges\",\n",
595 | " )"
596 | ]
597 | },
598 | {
599 | "cell_type": "markdown",
600 | "metadata": {},
601 | "source": [
602 | "## Networks"
603 | ]
604 | },
605 | {
606 | "cell_type": "code",
607 | "execution_count": null,
608 | "metadata": {},
609 | "outputs": [],
610 | "source": [
611 | "G_lines = nx.from_pandas_edgelist(n.lines, 'bus0', 'bus1', edge_attr='s_nom_opt')"
612 | ]
613 | },
614 | {
615 | "cell_type": "code",
616 | "execution_count": null,
617 | "metadata": {},
618 | "outputs": [],
619 | "source": [
620 | "G_links = nx.from_pandas_edgelist(n.links.loc[n.links.carrier=='DC'], 'bus0', 'bus1', edge_attr='p_nom_opt')"
621 | ]
622 | },
623 | {
624 | "cell_type": "code",
625 | "execution_count": null,
626 | "metadata": {},
627 | "outputs": [],
628 | "source": [
629 | "H2 = n.links.loc[n.links.carrier=='H2 pipeline']\n",
630 | "H2[\"location0\"] = H2.bus0.apply(lambda x: x[:-3])\n",
631 | "H2[\"location1\"] = H2.bus1.apply(lambda x: x[:-3])\n",
632 | "G_H2 = nx.from_pandas_edgelist(H2, 'location0', 'location1', edge_attr='p_nom_opt')\n",
633 | "electrolysis = n.links.loc[n.links.carrier=='H2 Electrolysis'].groupby(\"bus0\").p_nom_opt.sum()\n",
634 | "nx.set_node_attributes(G_H2, electrolysis, \"electrolysis\")"
635 | ]
636 | },
637 | {
638 | "cell_type": "code",
639 | "execution_count": null,
640 | "metadata": {},
641 | "outputs": [],
642 | "source": [
643 | "pos = n.buses.loc[n.buses.carrier=='AC', [\"x\", \"y\"]].apply(tuple, axis=1).to_dict()"
644 | ]
645 | },
646 | {
647 | "cell_type": "code",
648 | "execution_count": null,
649 | "metadata": {},
650 | "outputs": [],
651 | "source": [
652 | "elec_net = nodes.hvplot(\n",
653 | " geo=True,\n",
654 | " color='whitesmoke',\n",
655 | " line_color='grey',\n",
656 | " line_width=0.5,\n",
657 | " #transform=ccrs.EuroPP(),\n",
658 | ") * \\\n",
659 | "hvnx.draw(\n",
660 | " G_links, \n",
661 | " pos=pos,\n",
662 | " width=1000,\n",
663 | " height=800,\n",
664 | " node_size=0,\n",
665 | " edge_color='navy',\n",
666 | " edge_width=hv.dim('p_nom_opt') / 3e3,\n",
667 | " geo=True,\n",
668 | " #crs=ccrs.EuroPP(),\n",
669 | " inspection_policy='edges'\n",
670 | ") * \\\n",
671 | "hvnx.draw(\n",
672 | " G_lines, \n",
673 | " pos=pos,\n",
674 | " width=1000,\n",
675 | " height=800,\n",
676 | " node_size=40,\n",
677 | " node_color='gray',\n",
678 | " edge_color='firebrick',\n",
679 | " edge_width=hv.dim('s_nom_opt') / 3e3,\n",
680 | " geo=True,\n",
681 | " #crs=ccrs.EuroPP(),\n",
682 | " inspection_policy='edges'\n",
683 | ").opts(\n",
684 | " active_tools=['pan', 'wheel_zoom']\n",
685 | ")"
686 | ]
687 | },
688 | {
689 | "cell_type": "code",
690 | "execution_count": null,
691 | "metadata": {},
692 | "outputs": [],
693 | "source": [
694 | "h2_net = nodes.hvplot(\n",
695 | " geo=True,\n",
696 | " color='whitesmoke',\n",
697 | " line_color='grey',\n",
698 | " line_width=0.5,\n",
699 | ") * \\\n",
700 | "hvnx.draw(\n",
701 | " G_H2, \n",
702 | " pos=pos,\n",
703 | " width=1000,\n",
704 | " height=800,\n",
705 | " edge_color='cyan',\n",
706 | " edge_width=hv.dim('p_nom_opt') / 3e3,\n",
707 | " node_color='magenta',\n",
708 | " node_size=hv.dim(\"electrolysis\") / 2e2,\n",
709 | " geo=True,\n",
710 | " inspection_policy='edges'\n",
711 | ").opts(\n",
712 | " active_tools=['pan', 'wheel_zoom']\n",
713 | ")"
714 | ]
715 | },
716 | {
717 | "cell_type": "markdown",
718 | "metadata": {},
719 | "source": [
720 | "## System time series"
721 | ]
722 | },
723 | {
724 | "cell_type": "code",
725 | "execution_count": null,
726 | "metadata": {},
727 | "outputs": [],
728 | "source": [
729 | "# one resampled version, one hourly version"
730 | ]
731 | },
732 | {
733 | "cell_type": "code",
734 | "execution_count": null,
735 | "metadata": {},
736 | "outputs": [],
737 | "source": [
738 | "load = n.loads_t.p_set.groupby(n.loads.carrier, axis=1).sum()\n",
739 | "formatter = DatetimeTickFormatter(months='%b')"
740 | ]
741 | },
742 | {
743 | "cell_type": "code",
744 | "execution_count": null,
745 | "metadata": {},
746 | "outputs": [],
747 | "source": [
748 | "plt_load_ts = load.hvplot.area(width=1000, stacked=True, xformatter=formatter)"
749 | ]
750 | },
751 | {
752 | "cell_type": "code",
753 | "execution_count": null,
754 | "metadata": {},
755 | "outputs": [],
756 | "source": [
757 | "selection = [\"offwind-ac\", \"offwind-dc\", \"onwind\", \"ror\", \"solar\"]\n",
758 | "cfs = n.generators_t.p_max_pu.groupby(n.generators.carrier, axis=1).mean()[selection]"
759 | ]
760 | },
761 | {
762 | "cell_type": "code",
763 | "execution_count": null,
764 | "metadata": {},
765 | "outputs": [],
766 | "source": [
767 | "cfs.hvplot.line(width=1000, xformatter=formatter)"
768 | ]
769 | },
770 | {
771 | "cell_type": "code",
772 | "execution_count": null,
773 | "metadata": {},
774 | "outputs": [],
775 | "source": [
776 | "gen = n.generators_t.p.groupby(n.generators.carrier, axis=1).sum()"
777 | ]
778 | },
779 | {
780 | "cell_type": "code",
781 | "execution_count": null,
782 | "metadata": {},
783 | "outputs": [],
784 | "source": [
785 | "su = n.storage_units_t.p.groupby(n.storage_units.carrier, axis=1).sum()"
786 | ]
787 | },
788 | {
789 | "cell_type": "code",
790 | "execution_count": null,
791 | "metadata": {},
792 | "outputs": [],
793 | "source": [
794 | "df = pd.concat([gen, su], axis=1)"
795 | ]
796 | },
797 | {
798 | "cell_type": "code",
799 | "execution_count": null,
800 | "metadata": {},
801 | "outputs": [],
802 | "source": [
803 | "plt_gen_ts = df.hvplot.area(width=1000, height=500, line_width=0, title=\"electricity generation\")"
804 | ]
805 | },
806 | {
807 | "cell_type": "markdown",
808 | "metadata": {},
809 | "source": [
810 | "# Cutouts"
811 | ]
812 | },
813 | {
814 | "cell_type": "code",
815 | "execution_count": null,
816 | "metadata": {},
817 | "outputs": [],
818 | "source": [
819 | "era5 = atlite.Cutout(path + \"pypsa-eur/cutouts/europe-2013-era5.nc\")\n",
820 | "sarah = atlite.Cutout(path + \"pypsa-eur/cutouts/europe-2013-sarah.nc\")"
821 | ]
822 | },
823 | {
824 | "cell_type": "code",
825 | "execution_count": null,
826 | "metadata": {},
827 | "outputs": [],
828 | "source": [
829 | "def plot_cutout(cutout, variable):\n",
830 | "\n",
831 | " return cutout.data.hvplot.quadmesh(\n",
832 | " 'x', 'y', variable,\n",
833 | " frame_height=700,\n",
834 | " cmap='Reds',\n",
835 | " coastline=True,\n",
836 | " project=True,\n",
837 | " geo=True,\n",
838 | " rasterize=True,\n",
839 | " ylim=(34,72),\n",
840 | " xlim=(-12,34),\n",
841 | " #clim=(0,1200),\n",
842 | " widget_location='top',\n",
843 | " #widgets={'time': pnw.DatetimeInput(value=dt.datetime(2013, 2, 8, 0, 0))}\n",
844 | " #tiles='CartoLight'\n",
845 | " #datashade=True, # removes legend\n",
846 | " )"
847 | ]
848 | },
849 | {
850 | "cell_type": "code",
851 | "execution_count": null,
852 | "metadata": {},
853 | "outputs": [],
854 | "source": [
855 | "plt_cutout_wind = plot_cutout(era5, \"wnd100m\")"
856 | ]
857 | },
858 | {
859 | "cell_type": "code",
860 | "execution_count": null,
861 | "metadata": {},
862 | "outputs": [],
863 | "source": [
864 | "plt_cutout_solar = plot_cutout(sarah, \"influx_direct\")"
865 | ]
866 | },
867 | {
868 | "cell_type": "markdown",
869 | "metadata": {},
870 | "source": [
871 | "## Outputs"
872 | ]
873 | },
874 | {
875 | "cell_type": "code",
876 | "execution_count": null,
877 | "metadata": {},
878 | "outputs": [],
879 | "source": [
880 | "import sys, os\n",
881 | "sys.path.insert(0, os.getcwd() + \"/\" + path + \"pypsa-eur-sec/scripts\")\n",
882 | "from plot_summary import rename_techs, preferred_order"
883 | ]
884 | },
885 | {
886 | "cell_type": "code",
887 | "execution_count": null,
888 | "metadata": {},
889 | "outputs": [],
890 | "source": [
891 | "cost_df = pd.read_csv(\n",
892 | " path + \"pypsa-eur-sec/results/your-run-name-overnight-dev/csvs/costs.csv\",\n",
893 | " index_col=list(range(3)),\n",
894 | " header=list(range(4))\n",
895 | ")\n",
896 | "df = cost_df.groupby(cost_df.index.get_level_values(2)).sum()\n",
897 | "df = df / 1e9\n",
898 | "df = df.groupby(df.index.map(rename_techs)).sum()\n",
899 | "\n",
900 | "to_drop = df.index[df.max(axis=1) < 1.]\n",
901 | " \n",
902 | "new_index = preferred_order.intersection(df.index).append(df.index.difference(preferred_order))\n",
903 | "new_columns = df.sum().sort_values().index"
904 | ]
905 | },
906 | {
907 | "cell_type": "code",
908 | "execution_count": null,
909 | "metadata": {},
910 | "outputs": [],
911 | "source": [
912 | "df.columns = [', '.join(col).strip() for col in df.columns.values]"
913 | ]
914 | },
915 | {
916 | "cell_type": "code",
917 | "execution_count": null,
918 | "metadata": {},
919 | "outputs": [],
920 | "source": [
921 | "plt_scen_costs = df.T.hvplot.bar(\n",
922 | " stacked=True,\n",
923 | " rot=65,\n",
924 | " frame_width=800,\n",
925 | " frame_height=600,\n",
926 | " ylim=(0,1000),\n",
927 | " color='Category', cmap=colors)"
928 | ]
929 | },
930 | {
931 | "cell_type": "code",
932 | "execution_count": null,
933 | "metadata": {},
934 | "outputs": [],
935 | "source": [
936 | "energy_df = pd.read_csv(\n",
937 | " path + \"pypsa-eur-sec/results/your-run-name-overnight-dev/csvs/energy.csv\",\n",
938 | " index_col=list(range(2)),\n",
939 | " header=list(range(4))\n",
940 | ")\n",
941 | "df = energy_df.groupby(energy_df.index.get_level_values(1)).sum()\n",
942 | "df = df / 1e6\n",
943 | "df = df.groupby(df.index.map(rename_techs)).sum()\n",
944 | "to_drop = df.index[df.abs().max(axis=1) < 50]\n",
945 | "df = df.drop(to_drop)\n",
946 | "new_index = preferred_order.intersection(df.index).append(df.index.difference(preferred_order))\n",
947 | "new_columns = df.columns.sort_values()"
948 | ]
949 | },
950 | {
951 | "cell_type": "code",
952 | "execution_count": null,
953 | "metadata": {},
954 | "outputs": [],
955 | "source": [
956 | "df.columns = [', '.join(col).strip() for col in df.columns.values]"
957 | ]
958 | },
959 | {
960 | "cell_type": "code",
961 | "execution_count": null,
962 | "metadata": {},
963 | "outputs": [],
964 | "source": [
965 | "plt_scen_energy = df.T.hvplot.bar(stacked=True, rot=65, frame_width=800, frame_height=600, ylim=(-20000,20000), color='Category', cmap=colors)"
966 | ]
967 | },
968 | {
969 | "cell_type": "markdown",
970 | "metadata": {},
971 | "source": [
972 | "## Sankey\n",
973 | "as https://holoviews.org/gallery/demos/bokeh/energy_sankey.html"
974 | ]
975 | },
976 | {
977 | "cell_type": "code",
978 | "execution_count": null,
979 | "metadata": {},
980 | "outputs": [],
981 | "source": [
982 | "edges = pd.read_csv('../data/connection.csv')\n",
983 | "sankey = hv.Sankey(edges, label='Energy Diagram')\n",
984 | "plt_sankes = sankey.opts(label_position='left', edge_color='target', node_color='index', cmap=colors)"
985 | ]
986 | },
987 | {
988 | "cell_type": "markdown",
989 | "metadata": {},
990 | "source": [
991 | "## Industry Sector Ratios"
992 | ]
993 | },
994 | {
995 | "cell_type": "code",
996 | "execution_count": null,
997 | "metadata": {},
998 | "outputs": [],
999 | "source": [
1000 | "iratios = pd.read_csv(path + \"pypsa-eur-sec/resources/industry_sector_ratios.csv\", index_col=0)"
1001 | ]
1002 | },
1003 | {
1004 | "cell_type": "code",
1005 | "execution_count": null,
1006 | "metadata": {},
1007 | "outputs": [],
1008 | "source": [
1009 | "plt_iratios = iratios.T.hvplot.barh(stacked=True, width=1000, height=400, title=\"Industry Sector Ratios [MWh/t material]\")"
1010 | ]
1011 | },
1012 | {
1013 | "cell_type": "markdown",
1014 | "metadata": {},
1015 | "source": [
1016 | "## Land Availability"
1017 | ]
1018 | },
1019 | {
1020 | "cell_type": "code",
1021 | "execution_count": null,
1022 | "metadata": {},
1023 | "outputs": [],
1024 | "source": [
1025 | "def get_latlon(da):\n",
1026 | " \n",
1027 | " # Compute the lon/lat coordinates with rasterio.warp.transform\n",
1028 | " ny, nx = len(da['y']), len(da['x'])\n",
1029 | " x, y = np.meshgrid(da['x'], da['y'])\n",
1030 | "\n",
1031 | " # Rasterio works with 1D arrays\n",
1032 | " lon, lat = transform(da.crs, {'init': 'EPSG:4326'},\n",
1033 | " x.flatten(), y.flatten())\n",
1034 | " lon = np.asarray(lon).reshape((ny, nx))\n",
1035 | " lat = np.asarray(lat).reshape((ny, nx))\n",
1036 | " da.coords['lon'] = (('y', 'x'), lon)\n",
1037 | " da.coords['lat'] = (('y', 'x'), lat)\n",
1038 | " da = da.drop_vars([\"x\", \"y\"])\n",
1039 | " return da"
1040 | ]
1041 | },
1042 | {
1043 | "cell_type": "code",
1044 | "execution_count": null,
1045 | "metadata": {},
1046 | "outputs": [],
1047 | "source": [
1048 | "def convert_to_dataset(fn):\n",
1049 | " da = xr.open_rasterio(fn)\n",
1050 | " da = get_latlon(da).mean(dim='band')\n",
1051 | " ds = da.where((da.values < 255) & (da.values > 0)).to_dataset(name='availability')\n",
1052 | " #ds.to_netcdf(fn.replace(\".tif\", \".nc\")) # much memory\n",
1053 | " return ds"
1054 | ]
1055 | },
1056 | {
1057 | "cell_type": "code",
1058 | "execution_count": null,
1059 | "metadata": {},
1060 | "outputs": [],
1061 | "source": [
1062 | "fn = \"../data/onwind-av-595.tif\"\n",
1063 | "ds = convert_to_dataset(fn)"
1064 | ]
1065 | },
1066 | {
1067 | "cell_type": "code",
1068 | "execution_count": null,
1069 | "metadata": {},
1070 | "outputs": [],
1071 | "source": [
1072 | "av = ds.hvplot.contourf(\n",
1073 | " 'lon',\n",
1074 | " 'lat',\n",
1075 | " 'availability',\n",
1076 | " geo=True,\n",
1077 | " tiles=\"CartoLight\",\n",
1078 | " cmap='Greens',\n",
1079 | " alpha=0.5,\n",
1080 | " frame_height=800,\n",
1081 | " colorbar=False,\n",
1082 | " legend=False,\n",
1083 | " hover=False,\n",
1084 | " title=\"Available Land\"\n",
1085 | ").opts(\n",
1086 | " active_tools=['pan', 'wheel_zoom']\n",
1087 | ")"
1088 | ]
1089 | },
1090 | {
1091 | "cell_type": "markdown",
1092 | "metadata": {},
1093 | "source": [
1094 | "## Hotmaps Raw"
1095 | ]
1096 | },
1097 | {
1098 | "cell_type": "code",
1099 | "execution_count": null,
1100 | "metadata": {},
1101 | "outputs": [],
1102 | "source": [
1103 | "def prepare_hotmaps_database(regions):\n",
1104 | " \"\"\"\n",
1105 | " Load hotmaps database of industrial sites and map onto bus regions.\n",
1106 | " \"\"\"\n",
1107 | "\n",
1108 | " df = pd.read_csv(path + \"pypsa-eur-sec/data/Industrial_Database.csv\", sep=\";\", index_col=0)\n",
1109 | "\n",
1110 | " df[[\"srid\", \"coordinates\"]] = df.geom.str.split(';', expand=True)\n",
1111 | "\n",
1112 | " # remove those sites without valid locations\n",
1113 | " df.drop(df.index[df.coordinates.isna()], inplace=True)\n",
1114 | "\n",
1115 | " df['coordinates'] = gpd.GeoSeries.from_wkt(df['coordinates'])\n",
1116 | "\n",
1117 | " gdf = gpd.GeoDataFrame(df, geometry='coordinates', crs=\"EPSG:4326\")\n",
1118 | "\n",
1119 | " gdf = gpd.sjoin(gdf, regions, how=\"inner\", op='within')\n",
1120 | "\n",
1121 | " gdf.rename(columns={\"index_right\": \"bus\"}, inplace=True)\n",
1122 | " gdf[\"country\"] = gdf.bus.str[:2]\n",
1123 | "\n",
1124 | " return gdf"
1125 | ]
1126 | },
1127 | {
1128 | "cell_type": "code",
1129 | "execution_count": null,
1130 | "metadata": {},
1131 | "outputs": [],
1132 | "source": [
1133 | "hotmaps = prepare_hotmaps_database(nodes)\n",
1134 | "\n",
1135 | "hotmaps[\"geometry\"] = hotmaps.coordinates\n",
1136 | "hotmaps[\"lat\"] = hotmaps.geometry.y\n",
1137 | "hotmaps[\"lon\"] = hotmaps.geometry.x"
1138 | ]
1139 | },
1140 | {
1141 | "cell_type": "code",
1142 | "execution_count": null,
1143 | "metadata": {},
1144 | "outputs": [],
1145 | "source": [
1146 | "plt_hotmaps = hotmaps.hvplot.points(\n",
1147 | " 'lon',\n",
1148 | " 'lat',\n",
1149 | " geo=True,\n",
1150 | " frame_height=750,\n",
1151 | " c='Subsector',\n",
1152 | " size=hotmaps[\"Emissions_ETS_2014\"] / 2e3,\n",
1153 | " alpha=0.4,\n",
1154 | " tiles='CartoLight',\n",
1155 | " hover_cols=['SiteName', \"Emissions_ETS_2014\", \"DataSource\"],\n",
1156 | ").opts(\n",
1157 | " active_tools=['pan', 'wheel_zoom']\n",
1158 | ")"
1159 | ]
1160 | },
1161 | {
1162 | "cell_type": "code",
1163 | "execution_count": null,
1164 | "metadata": {},
1165 | "outputs": [],
1166 | "source": []
1167 | },
1168 | {
1169 | "cell_type": "code",
1170 | "execution_count": null,
1171 | "metadata": {},
1172 | "outputs": [],
1173 | "source": [
1174 | "w0 = pnw.Select(name=\"Run:\", options=[\"your-run-name\"])\n",
1175 | "w1 = pnw.Select(name='Nodes:', options=[60])\n",
1176 | "w2 = pnw.Select(name='Transmission Expansion', options=[1.25])\n",
1177 | "w3 = pnw.Select(name=\"Opts:\", options=[\"Co2L0p0-365H-T-H-B-I-solar+p3-dist1\"])\n",
1178 | "w4 = pnw.Select(name=\"Year:\", options=[2030])\n",
1179 | "\n",
1180 | "box = pn.WidgetBox('### Scenario', w0, w1, w2, w3, w4)"
1181 | ]
1182 | },
1183 | {
1184 | "cell_type": "code",
1185 | "execution_count": null,
1186 | "metadata": {},
1187 | "outputs": [],
1188 | "source": [
1189 | "import panel as pn\n",
1190 | "import numpy as np\n",
1191 | "import holoviews as hv\n",
1192 | "\n",
1193 | "pn.extension()\n",
1194 | "\n",
1195 | "board = pn.template.BootstrapTemplate(title='PyPSA-Eur-Sec Dashboard', header_background=\"#d95568\")\n",
1196 | "\n",
1197 | "pn.config.sizing_mode = 'stretch_width'\n",
1198 | "\n",
1199 | "intro = pn.pane.Markdown('''\n",
1200 | "\n",
1201 | "PyPSA-Eur-Sec is an open model dataset of the European energy system\n",
1202 | "at the transmission network level that covers the full ENTSO-E area.\n",
1203 | "\n",
1204 | "[pypsa-eur-sec.readthedocs.io](https://pypsa-eur-sec.readthedocs.io/)\n",
1205 | "''')\n",
1206 | "\n",
1207 | "_network_map = pn.Row(\n",
1208 | " network_map,\n",
1209 | " align='center'\n",
1210 | ")\n",
1211 | "\n",
1212 | "_existing = pn.Row(\n",
1213 | " pn.Card(plt_powerplants, collapsible=False, title=\"Powerplants\"),\n",
1214 | " pn.Card(plt_hotmaps, collapsible=False, title=\"Industrial Sites\"),\n",
1215 | ")\n",
1216 | "\n",
1217 | "_potentials = pn.Row(\n",
1218 | " pn.Card(plt_wind_per_skm, collapsible=False, title=\"Wind Potential\"),\n",
1219 | " pn.Card(plt_solar_per_skm, collapsible=False, title=\"Solar Potential\"),\n",
1220 | ")\n",
1221 | "\n",
1222 | "_cutouts = pn.Row(\n",
1223 | " pn.Card(plt_cutout_wind, collapsible=False, title=\"Wind Speeds\"),\n",
1224 | " pn.Card(plt_cutout_solar, collapsible=False, title=\"Direct Influx\")\n",
1225 | ")\n",
1226 | "\n",
1227 | "_clustered_potentials = pn.Row(\n",
1228 | " pn.Card(plt_cfs, collapsible=False, title=\"Capacity Factors\"),\n",
1229 | " pn.Card(plt_pot, collapsible=False, title=\"Potential\")\n",
1230 | ")\n",
1231 | "\n",
1232 | "_totals = pn.Row(\n",
1233 | " pn.Card(plt_energy, collapsible=False, title=\"Energy Consumption\"),\n",
1234 | " pn.Card(plt_co2, collapsible=False, title=\"Carbon Emissions\")\n",
1235 | ")\n",
1236 | "\n",
1237 | "_opt_nets = pn.Row(\n",
1238 | " pn.Card(elec_net, collapsible=False, title=\"Electricty Network\"),\n",
1239 | " pn.Card(h2_net, collapsible=False, title=\"Hydrogen Network\")\n",
1240 | ")\n",
1241 | "\n",
1242 | "_timeseries = pn.Column(\n",
1243 | " pn.Card(plt_load_ts, collapsible=False, title=\"Load\"),\n",
1244 | " pn.Card(plt_gen_ts, collapsible=False, title=\"Electricity Generation\")\n",
1245 | ")\n",
1246 | "\n",
1247 | "_sankey = pn.Row(sankey, align=('center', 'center'))\n",
1248 | "\n",
1249 | "_config = pn.pane.JSON(\n",
1250 | " config,\n",
1251 | " sizing_mode='stretch_both',\n",
1252 | " theme='light',\n",
1253 | " hover_preview=True\n",
1254 | ")\n",
1255 | "\n",
1256 | "board.sidebar.append(intro)\n",
1257 | "board.sidebar.append(box)\n",
1258 | "\n",
1259 | "board.main.append(pn.pane.Markdown(\"\"\" \"\"\"))\n",
1260 | "\n",
1261 | "board.main.append(\n",
1262 | " pn.Tabs(\n",
1263 | " (\"Base Network\", _network_map),\n",
1264 | " (\"Infrastructure\", _existing),\n",
1265 | " (\"VRES Potentials\", _potentials),\n",
1266 | " (\"VRES Potentials 2\", _clustered_potentials),\n",
1267 | " (\"Land Availability\", av),\n",
1268 | " (\"Cutouts\", _cutouts),\n",
1269 | " (\"Timeseries\", _timeseries),\n",
1270 | " (\"Energy and Carbon\", _totals),\n",
1271 | " (\"Industry Sectors\", plt_iratios),\n",
1272 | " (\"System Energy\", plt_scen_energy),\n",
1273 | " (\"System Costs\", plt_scen_costs),\n",
1274 | " (\"Networks\", _opt_nets),\n",
1275 | " (\"Expansion Plan\", plt_cap),\n",
1276 | " (\"Sankey\", _sankey),\n",
1277 | " (\"Config\", _config),\n",
1278 | " dynamic=True\n",
1279 | " )\n",
1280 | ")"
1281 | ]
1282 | },
1283 | {
1284 | "cell_type": "code",
1285 | "execution_count": null,
1286 | "metadata": {},
1287 | "outputs": [],
1288 | "source": [
1289 | "board.show() # for development\n",
1290 | "#board.servable() # for deployment"
1291 | ]
1292 | },
1293 | {
1294 | "cell_type": "code",
1295 | "execution_count": null,
1296 | "metadata": {},
1297 | "outputs": [],
1298 | "source": []
1299 | },
1300 | {
1301 | "cell_type": "code",
1302 | "execution_count": null,
1303 | "metadata": {},
1304 | "outputs": [],
1305 | "source": []
1306 | },
1307 | {
1308 | "cell_type": "code",
1309 | "execution_count": null,
1310 | "metadata": {},
1311 | "outputs": [],
1312 | "source": []
1313 | }
1314 | ],
1315 | "metadata": {
1316 | "kernelspec": {
1317 | "display_name": "",
1318 | "language": "python",
1319 | "name": ""
1320 | },
1321 | "language_info": {
1322 | "codemirror_mode": {
1323 | "name": "ipython",
1324 | "version": 3
1325 | },
1326 | "file_extension": ".py",
1327 | "mimetype": "text/x-python",
1328 | "name": "python",
1329 | "nbconvert_exporter": "python",
1330 | "pygments_lexer": "ipython3",
1331 | "version": "3.8.8"
1332 | }
1333 | },
1334 | "nbformat": 4,
1335 | "nbformat_minor": 4
1336 | }
--------------------------------------------------------------------------------