Skip to content

Commit

Permalink
Merge pull request #898 from openego/feature/#749-pv-home-batteries
Browse files Browse the repository at this point in the history
Feature/#749 pv home batteries
  • Loading branch information
IlkaCu committed Nov 1, 2022
2 parents 3dcd28c + 9f344f1 commit 416f543
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ Changed
`#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>`_
* Allocate PV home batteries to mv grid districts
`#749 <https://github.com/openego/eGon-data/issues/749>`_
* Add sanity checks for motorized individual travel
`#820 <https://github.com/openego/eGon-data/issues/820>`_
* Parallelize sanity checks
Expand All @@ -427,6 +429,7 @@ Changed
* Introduce carrier name 'others'
`#819 <https://github.com/openego/eGon-data/issues/819>`_


Bug Fixes
---------

Expand Down
3 changes: 3 additions & 0 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ storages:
egon_mv_grid_district: "grid.egon_mv_grid_district"
ehv_voronoi: "grid.egon_ehv_substation_voronoi"
nep_conv: "supply.egon_nep_2021_conventional_powerplants"
nep_capacities: "NEP2035_V2021_scnC2035.xlsx"
generators: "grid.egon_etrago_generator"
bus: "grid.egon_etrago_bus"
target:
table: 'egon_storages'
schema: 'supply'
Expand Down
123 changes: 113 additions & 10 deletions src/egon/data/datasets/storages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The central module containing all code dealing with power plant data.
"""
from geoalchemy2 import Geometry
from pathlib import Path
from sqlalchemy import BigInteger, Column, Float, Integer, Sequence, String
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
Expand Down Expand Up @@ -41,11 +42,14 @@ class PumpedHydro(Dataset):
def __init__(self, dependencies):
super().__init__(
name="Storages",
version="0.0.1",
version="0.0.2",
dependencies=dependencies,
tasks=(create_tables,
allocate_pumped_hydro_eGon2035,
allocate_pumped_hydro_eGon100RE),
tasks=(
create_tables,
allocate_pumped_hydro_eGon2035,
allocate_pumped_hydro_eGon100RE,
allocate_pv_home_batteries,
),
)


Expand Down Expand Up @@ -240,7 +244,7 @@ def allocate_pumped_hydro_eGon2035(export=True):
bus_id=row.bus_id,
scenario=row.scenario,
geom=f"SRID=4326;POINT({row.geometry.x} {row.geometry.y})",
)
)
session.add(entry)
session.commit()

Expand Down Expand Up @@ -279,11 +283,11 @@ def allocate_pumped_hydro_eGon100RE():

if boundary == "Schleswig-Holstein":
# Break capacity of pumped hydron plants down SH share in eGon2035
capacity_phes = capacity.iat[0,0]*0.0176
capacity_phes = capacity.iat[0, 0] * 0.0176

elif boundary == "Everything":
# Select national capacity for pumped hydro
capacity_phes = capacity.iat[0,0]
capacity_phes = capacity.iat[0, 0]

else:
raise ValueError(f"'{boundary}' is not a valid dataset boundary.")
Expand All @@ -292,11 +296,11 @@ def allocate_pumped_hydro_eGon100RE():
# for the distribution in eGon100RE scenario
allocation = allocate_pumped_hydro_eGon2035(export=False)

scaling_factor = capacity_phes/allocation.el_capacity.sum()
scaling_factor = capacity_phes / allocation.el_capacity.sum()

power_plants = allocation.copy()
power_plants["scenario"] = "eGon100RE"
power_plants["el_capacity"] = allocation.el_capacity*scaling_factor
power_plants["el_capacity"] = allocation.el_capacity * scaling_factor

# Insert into target table
session = sessionmaker(bind=db.engine())()
Expand All @@ -310,6 +314,105 @@ def allocate_pumped_hydro_eGon100RE():
bus_id=row.bus_id,
scenario=row.scenario,
geom=f"SRID=4326;POINT({row.geometry.x} {row.geometry.y})",
)
)
session.add(entry)
session.commit()


def home_batteries_per_scenario(scenario):
"""Allocates home batteries which define a lower boundary for extendable
battery storage units. The overall installed capacity is taken from NEP
for eGon2035 scenario. The spatial distribution of installed battery
capacities is based on the installed pv rooftop capacity.
Parameters
----------
None
Returns
-------
None
"""

cfg = config.datasets()["storages"]
dataset = config.settings()["egon-data"]["--dataset-boundary"]

if scenario == "eGon2035":

target_file = (
Path(".")
/ "data_bundle_egon_data"
/ "nep2035_version2021"
/ cfg["sources"]["nep_capacities"]
)

capacities_nep = pd.read_excel(
target_file,
sheet_name="1.Entwurf_NEP2035_V2021",
index_col="Unnamed: 0",
)

# Select target value in MW
target = capacities_nep.Summe["PV-Batteriespeicher"]*1000

else:
target = db.select_dataframe(
f"""
SELECT capacity
FROM {cfg['sources']['capacities']}
WHERE scenario_name = '{scenario}'
AND carrier = 'battery';
"""
).capacity[0]

pv_rooftop = db.select_dataframe(
f"""
SELECT bus, p_nom, generator_id
FROM {cfg['sources']['generators']}
WHERE scn_name = '{scenario}'
AND carrier = 'solar_rooftop'
AND bus IN
(SELECT bus_id FROM {cfg['sources']['bus']}
WHERE scn_name = '{scenario}' AND country = 'DE' );
"""
)

if dataset == "Schleswig-Holstein":
target = target / 16

battery = pv_rooftop
battery["p_nom_min"] = target * battery["p_nom"] / battery["p_nom"].sum()
battery = battery.drop(columns=["p_nom"])

battery["carrier"] = "home_battery"
battery["scenario"] = scenario

if scenario == "eGon2035":
source = "NEP"

else:
source = "p-e-s"

battery[
"source"
] = f"{source} capacity allocated based in installed PV rooftop capacity"

# Insert into target table
session = sessionmaker(bind=db.engine())()
for i, row in battery.iterrows():
entry = EgonStorages(
sources={"el_capacity": row.source},
source_id={"generator_id": row.generator_id},
carrier=row.carrier,
el_capacity=row.p_nom_min,
bus_id=row.bus,
scenario=row.scenario,
)
session.add(entry)
session.commit()


def allocate_pv_home_batteries():

home_batteries_per_scenario("eGon2035")
home_batteries_per_scenario("eGon100RE")
22 changes: 21 additions & 1 deletion src/egon/data/datasets/storages_etrago/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import geopandas as gpd
import pandas as pd
from egon.data import db, config
import egon.data.datasets.scenario_parameters.parameters as scenario_parameters
from egon.data.datasets import Dataset
Expand All @@ -17,7 +18,7 @@ class StorageEtrago(Dataset):
def __init__(self, dependencies):
super().__init__(
name="StorageEtrago",
version="0.0.7",
version="0.0.8",
dependencies=dependencies,
tasks=(insert_PHES, extendable_batteries),
)
Expand Down Expand Up @@ -112,6 +113,17 @@ def extendable_batteries_per_scenario(scenario):
"""
)

# Select information on allocated capacities for home batteries from database
home_batteries = db.select_dataframe(
f"""
SELECT el_capacity as p_nom_min, bus_id as bus FROM
{sources['storage']['schema']}.
{sources['storage']['table']}
WHERE carrier = 'home_battery'
AND scenario = '{scenario}';
"""
)

# Update index
extendable_batteries[
"storage_id"
Expand Down Expand Up @@ -146,6 +158,14 @@ def extendable_batteries_per_scenario(scenario):

extendable_batteries["carrier"] = "battery"

# Merge dataframes to fill p_nom_min column
extendable_batteries = extendable_batteries.merge(
right=home_batteries, left_on="bus", right_on="bus", how="outer"
)
extendable_batteries["p_nom_min"] = extendable_batteries[
"p_nom_min"
].fillna(0)

# Write data to db
extendable_batteries.to_sql(
targets["storage"]["table"],
Expand Down

0 comments on commit 416f543

Please sign in to comment.