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