Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/hybit validation #258

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 108 additions & 25 deletions src/egon/data/datasets/fix_ehv_subnetworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def add_bus(x, y, v_nom, scn_name):
)


def drop_bus(x, y, v_nom, scn_name):
def drop_bus(x, y, v_nom, scn_name, attached_comp_to_nearest=False):
bus = select_bus_id(x, y, v_nom, scn_name, carrier="AC")

if bus is not None:
Expand All @@ -90,9 +90,52 @@ def drop_bus(x, y, v_nom, scn_name):
AND carrier = 'AC'
"""
)

if attached_comp_to_nearest==True:

new_bus = select_bus_id(x, y, v_nom, scn_name, carrier="AC", find_closest=True)

one_port = ["load", "generator", "store", "storage"]
for i in one_port:


db.execute_sql(
f"""
UPDATE grid.egon_etrago_{i}
SET
bus = {new_bus}
WHERE
scn_name = '{scn_name}'
AND bus = {bus}
"""
)

two_port = ["line", "link", "transformer"]
for i in two_port:

db.execute_sql(
f"""
UPDATE grid.egon_etrago_{i}
SET
bus0 = {new_bus}
WHERE
scn_name = '{scn_name}'
AND bus0 = {bus}
"""
)
db.execute_sql(
f"""
UPDATE grid.egon_etrago_{i}
SET
bus1 = {new_bus}
WHERE
scn_name = '{scn_name}'
AND bus1 = {bus}
"""
)


def add_line(x0, y0, x1, y1, v_nom, scn_name, cables):
def add_line(x0, y0, x1, y1, v_nom, scn_name, cables, geom_length=None, layingtype='overhead' ):
parameters = get_sector_parameters("electricity", scenario=scn_name)
bus0 = select_bus_id(
x0, y0, v_nom, scn_name, carrier="AC", find_closest=True
Expand All @@ -114,24 +157,45 @@ def add_line(x0, y0, x1, y1, v_nom, scn_name, cables):
)

gdf = link_geom_from_buses(df, scn_name)

gdf["length"] = gdf.to_crs(3035).topo.length.mul(1e-3)

# all the values used for x, r and b are taken from the electrical values
# reference table from oemtgmod: github.com/wupperinst/osmTGmod
if v_nom == 220:
s_nom = 520
x_per_km = 0.001 * 2 * np.pi * 50
r_per_km = 0.05475
b_per_km = 11 * 2 * np.pi * 50 * 1e-9
cost_per_km = parameters["capital_cost"]["ac_ehv_overhead_line"]

elif v_nom == 380:
s_nom = 1790
x_per_km = 0.0008 * 2 * np.pi * 50
r_per_km = 0.027375
b_per_km = 14 * 2 * np.pi * 50 * 1e-9
cost_per_km = parameters["capital_cost"]["ac_ehv_overhead_line"]

if geom_length is not None:
gdf["length"] = geom_length
else:
gdf["length"] = gdf.to_crs(3035).topo.length.mul(1e-3)

if layingtype=='overhead':

# all the values used for x, r and b are taken from the electrical values
# reference table from oemtgmod: github.com/wupperinst/osmTGmod
if v_nom == 110:
s_nom = 260
x_per_km = 0.0012 * 2 * np.pi * 50
r_per_km = 0.05475
b_per_km = 9.5 * 2 * np.pi * 50 * 1e-9
cost_per_km = parameters["capital_cost"]["ac_hv_overhead_line"]

if v_nom == 220:
s_nom = 520
x_per_km = 0.001 * 2 * np.pi * 50
r_per_km = 0.05475
b_per_km = 11 * 2 * np.pi * 50 * 1e-9
cost_per_km = parameters["capital_cost"]["ac_ehv_overhead_line"]

elif v_nom == 380:
s_nom = 1790
x_per_km = 0.0008 * 2 * np.pi * 50
r_per_km = 0.027375
b_per_km = 14 * 2 * np.pi * 50 * 1e-9
cost_per_km = parameters["capital_cost"]["ac_ehv_overhead_line"]

elif layingtype=='underground':

if v_nom == 110:
s_nom = 280
x_per_km = 0.0003 * 2 * np.pi * 50
r_per_km = 0.0177
b_per_km = 250 * 2 * np.pi * 50 * 1e-9
cost_per_km = parameters["capital_cost"]["ac_hv_cable"]

gdf["s_nom"] = s_nom * gdf["cables"] / 3
gdf["s_nom_extendable"] = True
Expand All @@ -148,10 +212,9 @@ def add_line(x0, y0, x1, y1, v_nom, scn_name, cables):
"egon_etrago_line", schema="grid", con=db.engine(), if_exists="append"
)


def drop_line(x0, y0, x1, y1, v_nom, scn_name):
bus0 = select_bus_id(x0, y0, v_nom, scn_name, carrier="AC")
bus1 = select_bus_id(x1, y1, v_nom, scn_name, carrier="AC")
bus0 = select_bus_id(x0, y0, v_nom, scn_name, carrier="AC", find_closest=True)
bus1 = select_bus_id(x1, y1, v_nom, scn_name, carrier="AC", find_closest=True)

if (bus0 is not None) and (bus1 is not None):
db.execute_sql(
Expand Down Expand Up @@ -204,8 +267,8 @@ def add_trafo(x, y, v_nom0, v_nom1, scn_name, n=1):


def drop_trafo(x, y, v_nom0, v_nom1, scn_name):
bus0 = select_bus_id(x, y, v_nom0, scn_name, carrier="AC")
bus1 = select_bus_id(x, y, v_nom1, scn_name, carrier="AC")
bus0 = select_bus_id(x, y, v_nom0, scn_name, carrier="AC", find_closest=True)
bus1 = select_bus_id(x, y, v_nom1, scn_name, carrier="AC", find_closest=True)

if (bus0 is not None) and (bus1 is not None):
db.execute_sql(
Expand All @@ -217,6 +280,26 @@ def drop_trafo(x, y, v_nom0, v_nom1, scn_name):
AND bus1 = {bus1}
"""
)

def change_trafo(x, y, v_nom0, v_nom1, scn_name, s_nom, reactance_pu):
bus0 = select_bus_id(x, y, v_nom0, scn_name, carrier="AC", find_closest=True)
bus1 = select_bus_id(x, y, v_nom1, scn_name, carrier="AC", find_closest=True)

if (bus0 is not None) and (bus1 is not None):
db.execute_sql(
f"""
UPDATE grid.egon_etrago_transformer
SET
s_nom = {s_nom},
s_nom_min = {s_nom},
x = {reactance_pu}
WHERE
scn_name = '{scn_name}'
AND bus0 = {bus0}
AND bus1 = {bus1}
"""
)



def fix_subnetworks(scn_name):
Expand Down
36 changes: 30 additions & 6 deletions src/egon/data/datasets/osmtgmod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,19 @@ def to_pypsa():
)

for scenario_name in ["'eGon2035'", "'eGon100RE'", "'status2019'"]:



electrical_parameters = get_sector_parameters(
"electricity", scenario_name.replace("'", "")
)["electrical_parameters"]

capital_cost = get_sector_parameters(
"electricity", scenario_name.replace("'", "")
)["capital_cost"]
lifetime = get_sector_parameters(
"electricity", scenario_name.replace("'", "")
)["lifetime"]

db.execute_sql(
f"""
-- BUS DATA
Expand Down Expand Up @@ -583,7 +589,7 @@ def to_pypsa():
branch_id AS trafo_id,
f_bus AS bus0,
t_bus AS bus1,
br_x/100 AS x, --- change base from 100MVA (osmtgmod) to 1 MVA (pypsa)
(br_x/100)*rate_a AS x, --- change base from 100MVA (osmtgmod) to the transformer's s_nom (pypsa)
rate_a as s_nom,
rate_a as s_nom_min,
TRUE,
Expand Down Expand Up @@ -628,17 +634,35 @@ def to_pypsa():
WHERE a.line_id = result.line_id
AND scn_name = {scenario_name};

-- set capital costs for eHV-lines
-- set capital costs for eHV-lines (overhead)
UPDATE grid.egon_etrago_line
SET capital_cost = {capital_cost['ac_ehv_overhead_line']} * length
WHERE v_nom > 110
AND scn_name = {scenario_name};
AND scn_name = {scenario_name}
AND ((s_nom/{electrical_parameters['ac_line_220kV']['s_nom']}) % 1 = 0
OR (s_nom/{electrical_parameters['ac_line_380kV']['s_nom']}) % 1 = 0);

-- set capital costs for HV-lines
-- set capital costs for HV-lines (overhead)
UPDATE grid.egon_etrago_line
SET capital_cost = {capital_cost['ac_hv_overhead_line']} * length
WHERE v_nom = 110
AND scn_name = {scenario_name};
AND scn_name = {scenario_name}
AND (s_nom/{electrical_parameters['ac_line_110kV']['s_nom']}) % 1 = 0;

-- set capital costs for eHV-cables (underground)
UPDATE grid.egon_etrago_line
SET capital_cost = {capital_cost['ac_ehv_cable']} * length
WHERE v_nom > 110
AND scn_name = {scenario_name}
AND ((s_nom/{electrical_parameters['ac_cable_220kV']['s_nom']}) % 1 = 0
OR (s_nom/{electrical_parameters['ac_cable_380kV']['s_nom']}) % 1 = 0);

-- set capital costs for HV-cables (underground)
UPDATE grid.egon_etrago_line
SET capital_cost = {capital_cost['ac_hv_cable']} * length
WHERE v_nom = 110
AND scn_name = {scenario_name}
AND (s_nom/{electrical_parameters['ac_cable_110kV']['s_nom']}) % 1 = 0;

-- set capital costs for transformers
UPDATE grid.egon_etrago_transformer a
Expand Down
Loading