Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,176 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
sphinx>=1.3 | ||
sphinx-rtd-theme | ||
reegis | ||
pandas | ||
|
||
setuptools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
"""Create a basic scenario from the internal data structure. | ||
SPDX-FileCopyrightText: 2016-2019 Uwe Krien <krien@uni-bremen.de> | ||
SPDX-License-Identifier: MIT | ||
""" | ||
|
||
import logging | ||
from warnings import warn | ||
|
||
import pandas as pd | ||
from reegis import commodity_sources | ||
|
||
from scenario_builder import config as cfg | ||
from scenario_builder import data | ||
|
||
|
||
def scenario_commodity_sources(year): | ||
""" | ||
Parameters | ||
---------- | ||
year | ||
Returns | ||
------- | ||
Examples | ||
-------- | ||
>>> from reegis import geometries | ||
>>> from scenario_builder import powerplants | ||
>>> fs=geometries.get_federal_states_polygon() # doctest: +SKIP | ||
>>> pp=powerplants.scenario_powerplants(dict(), fs, 2014, "federal_states" | ||
... ) # doctest: +SKIP | ||
>>> src=scenario_commodity_sources(pp) # doctest: +SKIP | ||
>>> round(src.loc[("DE", "hard coal"), "costs"], 2) # doctest: +SKIP | ||
12.53 | ||
>>> round(src.loc[("DE", "natural gas"), "emission"], 2) # doctest: +SKIP | ||
201.0 | ||
""" | ||
if cfg.get("basic", "costs_source") == "reegis": | ||
commodity_src = create_commodity_sources_reegis(year) | ||
elif cfg.get("basic", "costs_source") == "ewi": | ||
commodity_src = create_commodity_sources_ewi() | ||
else: | ||
commodity_src = None | ||
|
||
commodity_src = commodity_src.transpose() | ||
|
||
# Add region level to be consistent to other tables | ||
commodity_src.columns = pd.MultiIndex.from_product( | ||
[["DE"], commodity_src.columns] | ||
) | ||
|
||
return commodity_src.transpose() | ||
|
||
|
||
def create_commodity_sources_ewi(): | ||
""" | ||
Returns | ||
------- | ||
""" | ||
ewi = data.get_ewi_data() | ||
df = pd.DataFrame() | ||
df["costs"] = ewi.fuel_costs["value"] + ewi.transport_costs["value"] | ||
df["emission"] = ewi.emission["value"].multiply(1000) | ||
df["co2_price"] = float(ewi.co2_price["value"]) | ||
missing = "bioenergy" | ||
msg = ( | ||
"Costs/Emission for {0} in ewi is missing.\n" | ||
"Values for {0} are hard coded! Use with care." | ||
) | ||
warn(msg.format(missing), UserWarning) | ||
df.loc[missing, "emission"] = 7.2 | ||
df.loc[missing, "costs"] = 20 | ||
df.loc[missing, "co2_price"] = df.loc["natural gas", "co2_price"] | ||
return df | ||
|
||
|
||
def create_commodity_sources_reegis(year, use_znes_2014=True): | ||
""" | ||
Parameters | ||
---------- | ||
year | ||
use_znes_2014 | ||
Returns | ||
------- | ||
""" | ||
msg = ( | ||
"The unit for {0} of the source is '{1}'. " | ||
"Will multiply it with {2} to get '{3}'." | ||
) | ||
|
||
converter = { | ||
"costs": ["costs", "EUR/J", 1e9 * 3.6, "EUR/MWh"], | ||
"emission": ["emission", "g/J", 1e6 * 3.6, "kg/MWh"], | ||
} | ||
|
||
cs = commodity_sources.get_commodity_sources() | ||
rename_cols = { | ||
key.lower(): value | ||
for key, value in cfg.get_dict("source_names").items() | ||
} | ||
cs = cs.rename(columns=rename_cols) | ||
cs_year = cs.loc[year] | ||
if use_znes_2014: | ||
before = len(cs_year[cs_year.isnull()]) | ||
cs_year = cs_year.fillna(cs.loc[2014]) | ||
after = len(cs_year[cs_year.isnull()]) | ||
if before - after > 0: | ||
logging.warning("Values were replaced with znes2014 data.") | ||
cs_year = cs_year.sort_index().unstack() | ||
|
||
# convert units | ||
for key in converter.keys(): | ||
cs_year[key] = cs_year[key].multiply(converter[key][2]) | ||
logging.warning(msg.format(*converter[key])) | ||
|
||
return cs_year |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Create a basic scenario from the internal data structure. | ||
SPDX-FileCopyrightText: 2016-2019 Uwe Krien <krien@uni-bremen.de> | ||
SPDX-License-Identifier: MIT | ||
""" | ||
|
||
import os | ||
|
||
from reegis.config import get # noqa: F401 | ||
from reegis.config import get_dict # noqa: F401 | ||
from reegis.config import get_dict_list # noqa: F401 | ||
from reegis.config import init # noqa: F401 | ||
|
||
_loaded = False | ||
if not _loaded: | ||
init(paths=[os.path.dirname(__file__)]) | ||
_loaded = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Create a basic scenario from the internal data structure. | ||
SPDX-FileCopyrightText: 2016-2019 Uwe Krien <krien@uni-bremen.de> | ||
SPDX-License-Identifier: MIT | ||
""" | ||
|
||
import os | ||
from types import SimpleNamespace | ||
|
||
import pandas as pd | ||
from reegis.tools import download_file | ||
|
||
from scenario_builder import config as cfg | ||
|
||
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 | ||
Examples | ||
-------- | ||
>>> my_ewi_data = get_ewi_data() | ||
>>> round(my_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", "general"), "ewi.xlsm") | ||
download_file(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) |
Oops, something went wrong.