Skip to content

Commit

Permalink
Fix scenario building with deflex
Browse files Browse the repository at this point in the history
  • Loading branch information
uvchik committed Feb 3, 2021
1 parent 64d44b8 commit dd1e566
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/scenario_builder/commodity.py
Expand Up @@ -38,9 +38,9 @@ def scenario_commodity_sources(year):
>>> round(src.loc[("DE", "natural gas"), "emission"], 2) # doctest: +SKIP
201.0
"""
if cfg.get("basic", "costs_source") == "reegis":
if cfg.get("creator", "costs_source") == "reegis":
commodity_src = create_commodity_sources_reegis(year)
elif cfg.get("basic", "costs_source") == "ewi":
elif cfg.get("creator", "costs_source") == "ewi":
commodity_src = create_commodity_sources_ewi()
else:
commodity_src = None
Expand Down
31 changes: 14 additions & 17 deletions src/scenario_builder/demand.py
Expand Up @@ -35,17 +35,18 @@ def get_heat_profiles_deflex(
"""
# separate_regions=keep all demand connected to the region
separate_regions = cfg.get_list("demand_heat", "separate_heat_regions")
separate_regions = cfg.get_list("creator", "separate_heat_regions")
# Add lower and upper cases to be not case sensitive
separate_regions = [x.upper() for x in separate_regions] + [
x.lower() for x in separate_regions
]

# add second fuel to first
combine_fuels = cfg.get_dict("combine_heat_fuels")
# combine_fuels = cfg.get_dict("combine_heat_fuels")
combine_fuels = {"natural gas": "gas"}

# fuels to be dissolved per region
region_fuels = cfg.get_list("demand_heat", "local_fuels")
region_fuels = cfg.get_list("creator", "local_fuels")

fn = os.path.join(
cfg.get("paths", "demand"),
Expand All @@ -63,8 +64,7 @@ def get_heat_profiles_deflex(
# Decentralised demand is combined to a nation-wide demand if not part
# of region_fuels.
regions = list(
set(demand_region.columns.get_level_values(0).unique())
- set(separate_regions)
set(demand_region.columns.get_level_values(0).unique()) - set(separate_regions)
)

# If region_fuels is 'all' fetch all fuels to be local.
Expand All @@ -87,10 +87,7 @@ def get_heat_profiles_deflex(
demand_region.index = time_index

if not keep_unit:
msg = (
"The unit of the source is 'TJ'. "
"Will be divided by {0} to get 'MWh'."
)
msg = "The unit of the source is 'TJ'. " "Will be divided by {0} to get 'MWh'."
converter = 0.0036
demand_region = demand_region.div(converter)
logging.debug(msg.format(converter))
Expand All @@ -104,14 +101,15 @@ def get_heat_profiles_deflex(
return demand_region


def scenario_demand(regions, year, name, weather_year=None):
def scenario_demand(regions, year, name, opsd_version=None, weather_year=None):
"""
Parameters
----------
regions
year
name
opsd_version
weather_year
Returns
Expand All @@ -129,9 +127,10 @@ def scenario_demand(regions, year, name, weather_year=None):
"""
demand_series = scenario_elec_demand(
pd.DataFrame(), regions, year, name, weather_year=weather_year
pd.DataFrame(), regions, year, name, weather_year=weather_year,
version=opsd_version
)
if cfg.get("basic", "heat"):
if cfg.get("creator", "heat"):
demand_series = scenario_heat_demand(
demand_series, regions, year, weather_year=weather_year
)
Expand All @@ -156,16 +155,14 @@ def scenario_heat_demand(table, regions, year, weather_year=None):
table = pd.concat(
[
table,
get_heat_profiles_deflex(
regions, year, idx, weather_year=weather_year
),
get_heat_profiles_deflex(regions, year, idx, weather_year=weather_year),
],
axis=1,
)
return table.sort_index(1)


def scenario_elec_demand(table, regions, year, name, weather_year=None):
def scenario_elec_demand(table, regions, year, name, version=None, weather_year=None):
"""
Parameters
Expand All @@ -186,7 +183,7 @@ def scenario_elec_demand(table, regions, year, name, weather_year=None):
demand_year = weather_year

df = demand_elec.get_entsoe_profile_by_region(
regions, demand_year, name, annual_demand="bmwi"
regions, demand_year, name, annual_demand="bmwi", version=version
)
df = pd.concat([df], axis=1, keys=["electrical_load"]).swaplevel(0, 1, 1)
df = df.reset_index(drop=True)
Expand Down
2 changes: 1 addition & 1 deletion src/scenario_builder/powerplants.py
Expand Up @@ -378,7 +378,7 @@ def scenario_chp(table_collection, regions, year, name, weather_year=None):
cb = energy_balance.get_transformation_balance_by_region(
regions, year, name
)
cb.rename(columns={"re": cfg.get("chp", "renewable_source")}, inplace=True)
cb.rename(columns={"re": "bioenergy"}, inplace=True)
heat_b = powerplants.calculate_chp_share_and_efficiency(cb)

heat_demand = demand.get_heat_profiles_deflex(
Expand Down

0 comments on commit dd1e566

Please sign in to comment.