Skip to content

Commit

Permalink
Merge branch 'dev' into features/#866-data-bundle-v10
Browse files Browse the repository at this point in the history
  • Loading branch information
IlkaCu authored Sep 1, 2022
2 parents 05f33cb + 379f1a8 commit b38c77c
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 57 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ Added
`#382 <https://github.com/openego/eGon-data/issues/382>`_
* Add motorized individual travel
`#553 <https://github.com/openego/eGon-data/issues/553>`_
* Add mapping zensus - weather cells
`#845 <https://github.com/openego/eGon-data/issues/845>`_
* Add pv rooftop plants per mv grid for eGon100RE
`#861 <https://github.com/openego/eGon-data/issues/861>`_

.. _PR #159: https://github.com/openego/eGon-data/pull/159
.. _PR #703: https://github.com/openego/eGon-data/pull/703
Expand Down Expand Up @@ -387,6 +391,11 @@ Changed
`#817 <https://github.com/openego/eGon-data/issues/817>`_
* Integrate new data bundle using zenodo sandbox
`#866 <https://github.com/openego/eGon-data/issues/866>`_
* Add noflex scenario for motorized individual travel
`#821 <https://github.com/openego/eGon-data/issues/821>`_
* Parallelize sanity checks
`#882 <https://github.com/openego/eGon-data/issues/882>`_


Bug Fixes
---------
Expand Down Expand Up @@ -560,6 +569,10 @@ Bug Fixes
`#849 <https://github.com/openego/eGon-data/issues/849>`_
* Fix final demand of heat demand timeseries
`#781 <https://github.com/openego/eGon-data/issues/781>`_
* Add extendable batteries only to buses at substations
`#852 <https://github.com/openego/eGon-data/issues/852>`_
* Temporarily set upper version limit for pandas
`#829 <https://github.com/openego/eGon-data/issues/829>`_

.. _PR #692: https://github.com/openego/eGon-data/pull/692
.. _#343: https://github.com/openego/eGon-data/issues/343
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def read(*names, **kwargs):
"atlite==0.2.5",
"cdsapi",
"click",
"geopandas>=0.10.0",
"geopandas>=0.10.0,<0.11.0",
"geopy",
"geovoronoi==0.3.0",
"importlib-resources",
Expand Down
9 changes: 7 additions & 2 deletions src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@
load_area = LoadArea(dependencies=[osm, vg250])

# Calculate feedin from renewables
renewable_feedin = RenewableFeedin(dependencies=[vg250, weather_data])
renewable_feedin = RenewableFeedin(
dependencies=[vg250, zensus_vg250, weather_data]
)

# Demarcate district heating areas
district_heating_areas = DistrictHeatingAreas(
Expand Down Expand Up @@ -400,7 +402,10 @@

# Link between methane grid and respective hydrogen buses
insert_h2_to_ch4_grid_links = HydrogenMethaneLinkEtrago(
dependencies=h2_infrastructure
dependencies=[
h2_infrastructure,
insert_power_to_h2_installations
]
)

# Create gas voronoi eGon100RE
Expand Down
14 changes: 14 additions & 0 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,12 @@ storage_etrago:
bus:
table: 'egon_etrago_bus'
schema: 'grid'
ehv-substation:
table: 'egon_ehv_substation'
schema: 'grid'
hv-substation:
table: 'egon_hvmv_substation'
schema: 'grid'
targets:
storage:
schema: 'grid'
Expand Down Expand Up @@ -1066,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
2 changes: 1 addition & 1 deletion src/egon/data/datasets/power_plants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PowerPlants(Dataset):
def __init__(self, dependencies):
super().__init__(
name="PowerPlants",
version="0.0.8",
version="0.0.9",
dependencies=dependencies,
tasks=(
create_tables,
Expand Down
33 changes: 26 additions & 7 deletions src/egon/data/datasets/power_plants/pv_rooftop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@
from egon.data.datasets.scenario_parameters import get_sector_parameters


def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):
def pv_rooftop_per_mv_grid():
"""Execute pv rooftop distribution method per scenario
Returns
-------
None.
"""

pv_rooftop_per_mv_grid_and_scenario(
scenario="eGon2035", level="federal_state"
)

pv_rooftop_per_mv_grid_and_scenario(scenario="eGon100RE", level="national")


def pv_rooftop_per_mv_grid_and_scenario(scenario, level):
"""Intergate solar rooftop per mv grid district
The target capacity is distributed to the mv grid districts linear to
Expand All @@ -16,9 +32,9 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):
Parameters
----------
scenario : str, optional
Name of the scenario The default is 'eGon2035'.
Name of the scenario
level : str, optional
Choose level of target values. The default is 'federal_state'.
Choose level of target values.
Returns
-------
Expand Down Expand Up @@ -67,7 +83,7 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):
JOIN {sources['map_grid_boundaries']['schema']}.
{sources['map_grid_boundaries']['table']} c
ON c.bus_id = b.bus_id
WHERE scenario = 'eGon2035'
WHERE scenario = '{scenario}'
GROUP BY (b.bus_id, vg250_lan)
"""
)
Expand All @@ -83,6 +99,7 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):
{sources['federal_states']['table']} b
ON a.nuts = b.nuts
WHERE carrier = 'solar_rooftop'
AND scenario_name = '{scenario}'
""",
index_col="gen",
)
Expand All @@ -101,21 +118,23 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):
demand["target_federal_state"]
)
else:

target = db.select_dataframe(
f"""
SELECT capacity
FROM {sources['scenario_capacities']['schema']}.
{sources['scenario_capacities']['table']} a
WHERE carrier = 'solar_rooftop'
AND scenario_name = '{scenario}'
"""
).capacity[0]

demand["share_country"] = demand.demand / demand.demand.sum()

capacities = demand["share_country"].mul(target)

demand.set_index("bus_id", inplace=True)

capacities = demand["share_country"].mul(target)

# Select next id value
new_id = db.next_etrago_id("generator")

Expand Down Expand Up @@ -177,7 +196,7 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):

pv_rooftop = pv_rooftop.set_index("generator_id")
pv_rooftop["marginal_cost"] = get_sector_parameters(
"electricity", "eGon2035"
"electricity", scenario
)["marginal_cost"]["solar"]

# Insert data to database
Expand Down
Loading

0 comments on commit b38c77c

Please sign in to comment.