1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
"""General data processing for general non-reegis data. |
4
|
|
|
|
5
|
|
|
SPDX-FileCopyrightText: 2016-2021 Uwe Krien <[email protected]> |
6
|
|
|
|
7
|
|
|
SPDX-License-Identifier: MIT |
8
|
|
|
""" |
9
|
|
|
__copyright__ = "Uwe Krien <[email protected]>" |
10
|
|
|
__license__ = "MIT" |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
import os |
14
|
|
|
from types import SimpleNamespace |
15
|
|
|
|
16
|
|
|
import pandas as pd |
17
|
|
|
|
18
|
|
|
from reegis import config as cfg |
19
|
|
|
from reegis import tools |
20
|
|
|
|
21
|
|
|
TRANSLATION_FUEL = { |
22
|
|
|
"Abfall": "waste", |
23
|
|
|
"Kernenergie": "nuclear", |
24
|
|
|
"Braunkohle": "lignite", |
25
|
|
|
"Steinkohle": "hard coal", |
26
|
|
|
"Erdgas": "natural gas", |
27
|
|
|
"GuD": "natural gas", |
28
|
|
|
"Gasturbine": "natural gas", |
29
|
|
|
"Öl": "oil", |
30
|
|
|
"Sonstige": "other", |
31
|
|
|
"Emissionszertifikatspreis": "co2_price", |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def get_ewi_data(): |
36
|
|
|
""" |
37
|
|
|
|
38
|
|
|
Returns |
39
|
|
|
------- |
40
|
|
|
namedtuple |
41
|
|
|
|
42
|
|
|
TODO: Keep this in deflex??? |
43
|
|
|
|
44
|
|
|
Examples |
45
|
|
|
-------- |
46
|
|
|
# >>> ewi_data = get_ewi_data() |
47
|
|
|
# >>> round(ewi_data.fuel_costs.loc["hard coal", "value"], 2) |
48
|
|
|
# 11.28 |
49
|
|
|
|
50
|
|
|
""" |
51
|
|
|
# Download file |
52
|
|
|
url = ( |
53
|
|
|
"https://www.ewi.uni-koeln.de/cms/wp-content/uploads/2019/12" |
54
|
|
|
"/EWI_Merit_Order_Tool_2019_1_4.xlsm" |
55
|
|
|
) |
56
|
|
|
fn = os.path.join(cfg.get("paths", "general"), "ewi.xls") |
57
|
|
|
tools.download_file(fn, url) |
58
|
|
|
|
59
|
|
|
# Create named tuple with all sub tables |
60
|
|
|
ewi_tables = { |
61
|
|
|
"fuel_costs": {"skiprows": 7, "usecols": "C:F", "nrows": 7}, |
62
|
|
|
"transport_costs": {"skiprows": 21, "usecols": "C:F", "nrows": 7}, |
63
|
|
|
"variable_costs": {"skiprows": 31, "usecols": "C:F", "nrows": 8}, |
64
|
|
|
"downtime_factor": { |
65
|
|
|
"skiprows": 31, |
66
|
|
|
"usecols": "H:K", |
67
|
|
|
"nrows": 8, |
68
|
|
|
"scale": 0.01, |
69
|
|
|
}, |
70
|
|
|
"emission": {"skiprows": 31, "usecols": "M:P", "nrows": 7}, |
71
|
|
|
"co2_price": {"skiprows": 17, "usecols": "C:F", "nrows": 1}, |
72
|
|
|
} |
73
|
|
|
ewi_data = {} |
74
|
|
|
cols = ["fuel", "value", "unit", "source"] |
75
|
|
|
xls = pd.ExcelFile(fn) |
76
|
|
|
for table in ewi_tables.keys(): |
77
|
|
|
tmp = xls.parse("Start", header=[0], **ewi_tables[table]).replace( |
78
|
|
|
TRANSLATION_FUEL |
79
|
|
|
) |
80
|
|
|
tmp.drop_duplicates(tmp.columns[0], keep="first", inplace=True) |
81
|
|
|
tmp.columns = cols |
82
|
|
|
ewi_data[table] = tmp.set_index("fuel") |
83
|
|
|
if "scale" in ewi_tables[table]: |
84
|
|
|
ewi_data[table]["value"] *= ewi_tables[table]["scale"] |
85
|
|
|
|
86
|
|
|
return SimpleNamespace(**ewi_data) |
87
|
|
|
|