Skip to content

Commit

Permalink
Merge pull request #832 from openego/features/#821_emob_mit_noflex_sc…
Browse files Browse the repository at this point in the history
…enario

Features/#821 emob mit noflex scenario
  • Loading branch information
nesnoj committed Aug 23, 2022
2 parents 2b71c2f + 5e0ab3b commit 6bcae7c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ Changed
`#803 <https://github.com/openego/eGon-data/issues/803>`_
* Integrate additional industrial electricity demands for eGon100RE
`#817 <https://github.com/openego/eGon-data/issues/817>`_
* Add noflex scenario for motorized individual travel
`#821 <https://github.com/openego/eGon-data/issues/821>`_


Bug Fixes
---------
Expand Down
8 changes: 8 additions & 0 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,17 @@ emobility_mit:
file: "eGon100RE_RS7_min2k_2022-06-01_175444_simbev_run.tar.gz"
file_metadata: "metadata_simbev_run.json"
scenario:
# used scenario variation (available scenarios see parameters.py)
variation:
eGon2035: "NEP C 2035"
eGon100RE: "Reference 2050"
# name of no-flex scenario
noflex:
create_noflex_scenario: True
names:
eGon2035: "eGon2035_noflex"
eGon100RE: "eGon100RE_noflex"

model_timeseries:
reduce_memory: True
export_results_to_csv: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def generate_model_data_tasks(scenario_name):

super().__init__(
name="MotorizedIndividualTravel",
version="0.0.2",
version="0.0.3",
dependencies=dependencies,
tasks=(
create_tables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ def write_model_data_to_db(
Scenario name
run_config : pd.DataFrame
simBEV metadata: run config
bat_cap : pd.DataFrame
Battery capacities per EV type
Returns
-------
Expand Down Expand Up @@ -582,11 +584,11 @@ def calc_initial_ev_soc(bus_id: int, scenario_name: str) -> pd.DataFrame:
/ initial_soc_per_ev_type.battery_capacity_sum.sum()
)

def write_to_db() -> None:
def write_to_db(write_noflex_model: bool) -> None:
"""Write model data to eTraGo tables"""

@db.check_db_unique_violation
def write_bus():
def write_bus(scenario_name: str) -> None:
# eMob MIT bus
emob_bus_id = db.next_etrago_id("bus")
with db.session_scope() as session:
Expand All @@ -604,7 +606,7 @@ def write_bus():
return emob_bus_id

@db.check_db_unique_violation
def write_link():
def write_link(scenario_name: str) -> None:
# eMob MIT link [bus_el] -> [bus_ev]
emob_link_id = db.next_etrago_id("link")
with db.session_scope() as session:
Expand Down Expand Up @@ -645,7 +647,7 @@ def write_link():
)

@db.check_db_unique_violation
def write_store():
def write_store(scenario_name: str) -> None:
# eMob MIT store
emob_store_id = db.next_etrago_id("store")
with db.session_scope() as session:
Expand Down Expand Up @@ -682,15 +684,17 @@ def write_store():
)

@db.check_db_unique_violation
def write_load():
def write_load(
scenario_name: str, connection_bus_id: int, load_ts: list
) -> None:
# eMob MIT load
emob_load_id = db.next_etrago_id("load")
with db.session_scope() as session:
session.add(
EgonPfHvLoad(
scn_name=scenario_name,
load_id=emob_load_id,
bus=emob_bus_id,
bus=connection_bus_id,
carrier="land transport EV",
sign=-1,
)
Expand All @@ -701,9 +705,7 @@ def write_load():
scn_name=scenario_name,
load_id=emob_load_id,
temp_id=1,
p_set=(
hourly_load_time_series_df.driving_load_time_series.to_list()
),
p_set=load_ts,
)
)

Expand All @@ -728,11 +730,33 @@ def write_load():
f"with bus_id {bus_id} in table egon_etrago_bus!"
)

# Write component data
emob_bus_id = write_bus()
write_link()
write_store()
write_load()
# Call DB writing functions for regular or noflex scenario
# * use corresponding scenario name as defined in datasets.yml
# * no storage for noflex scenario
# * load timeseries:
# * regular (flex): use driving load
# * noflex: use dumb charging load
if write_noflex_model is False:
emob_bus_id = write_bus(scenario_name=scenario_name)
write_link(scenario_name=scenario_name)
write_store(scenario_name=scenario_name)
write_load(
scenario_name=scenario_name,
connection_bus_id=emob_bus_id,
load_ts=(
hourly_load_time_series_df.driving_load_time_series.to_list()
),
)
else:
# Get noflex scenario name
noflex_scenario_name = DATASET_CFG["scenario"]["noflex"]["names"][
scenario_name
]
write_load(
scenario_name=noflex_scenario_name,
connection_bus_id=etrago_bus.bus_id,
load_ts=hourly_load_time_series_df.load_time_series.to_list(),
)

def write_to_file():
"""Write model data to file (for debugging purposes)"""
Expand Down Expand Up @@ -806,11 +830,20 @@ def write_to_file():
# Crop hourly TS if needed
hourly_load_time_series_df = hourly_load_time_series_df[:8760]

# Get initial average SoC
# Create noflex scenario?
write_noflex_model = DATASET_CFG["scenario"]["noflex"][
"create_noflex_scenario"
]

# Get initial average storage SoC
initial_soc_mean = calc_initial_ev_soc(bus_id, scenario_name)

# Write to database
write_to_db()
# Write to database: regular and noflex scenario
write_to_db(write_noflex_model=False)
print(' Writing flex scenario...')
if write_noflex_model is True:
print(' Writing noflex scenario...')
write_to_db(write_noflex_model=True)

# Export to working dir if requested
if DATASET_CFG["model_timeseries"]["export_results_to_csv"]:
Expand Down

0 comments on commit 6bcae7c

Please sign in to comment.