From 21996474d1df45640af82bdb8613c0ee70a12c17 Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Tue, 28 May 2024 14:13:11 +0200 Subject: [PATCH 1/6] added additional functionalities to the add_line function and fixed a bug in the drop_line function --- src/egon/data/datasets/fix_ehv_subnetworks.py | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/src/egon/data/datasets/fix_ehv_subnetworks.py b/src/egon/data/datasets/fix_ehv_subnetworks.py index 16872ce3f..27dc7f1d5 100644 --- a/src/egon/data/datasets/fix_ehv_subnetworks.py +++ b/src/egon/data/datasets/fix_ehv_subnetworks.py @@ -92,7 +92,7 @@ def drop_bus(x, y, v_nom, scn_name): ) -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 @@ -114,24 +114,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 @@ -148,10 +169,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( From bb3eaee1f20d0fab0ec9db1364c316c2d682bacb Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Wed, 5 Jun 2024 14:00:43 +0200 Subject: [PATCH 2/6] added new function to change trafo parameters --- src/egon/data/datasets/fix_ehv_subnetworks.py | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/egon/data/datasets/fix_ehv_subnetworks.py b/src/egon/data/datasets/fix_ehv_subnetworks.py index 27dc7f1d5..e9a3561af 100644 --- a/src/egon/data/datasets/fix_ehv_subnetworks.py +++ b/src/egon/data/datasets/fix_ehv_subnetworks.py @@ -224,8 +224,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( @@ -237,6 +237,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): From 17a75a4b5e356dca7e2f8a3a738d84d7606e3380 Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Thu, 20 Jun 2024 11:11:57 +0200 Subject: [PATCH 3/6] changed to the right base power for the transformer x --- src/egon/data/datasets/osmtgmod/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egon/data/datasets/osmtgmod/__init__.py b/src/egon/data/datasets/osmtgmod/__init__.py index 21a84b73a..9ff53f87b 100644 --- a/src/egon/data/datasets/osmtgmod/__init__.py +++ b/src/egon/data/datasets/osmtgmod/__init__.py @@ -583,7 +583,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, From 0c6c5ff5670ff0d59152df55cfa3e353c63eb098 Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Thu, 20 Jun 2024 13:37:40 +0200 Subject: [PATCH 4/6] math bug fix --- src/egon/data/datasets/osmtgmod/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egon/data/datasets/osmtgmod/__init__.py b/src/egon/data/datasets/osmtgmod/__init__.py index 9ff53f87b..51e13f745 100644 --- a/src/egon/data/datasets/osmtgmod/__init__.py +++ b/src/egon/data/datasets/osmtgmod/__init__.py @@ -583,7 +583,7 @@ def to_pypsa(): branch_id AS trafo_id, f_bus AS bus0, t_bus AS bus1, - br_x/(100*rate_a) AS x, --- change base from 100MVA (osmtgmod) to the transformer's s_nom (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, From 8f80126dd0d279b171874a68a3ea7ea077a2cde0 Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Thu, 4 Jul 2024 13:49:13 +0200 Subject: [PATCH 5/6] add function to optionally add isolated components to nearest bus after deleting its original bus --- src/egon/data/datasets/fix_ehv_subnetworks.py | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/egon/data/datasets/fix_ehv_subnetworks.py b/src/egon/data/datasets/fix_ehv_subnetworks.py index e9a3561af..48d07206a 100644 --- a/src/egon/data/datasets/fix_ehv_subnetworks.py +++ b/src/egon/data/datasets/fix_ehv_subnetworks.py @@ -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: @@ -90,6 +90,49 @@ 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, geom_length=None, layingtype='overhead' ): From 5bdc20ed8cf4cbe99062289cf8b28809f69a535b Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Tue, 9 Jul 2024 10:28:47 +0200 Subject: [PATCH 6/6] fixed bug in capital cost assignment for underground cables --- src/egon/data/datasets/osmtgmod/__init__.py | 34 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/egon/data/datasets/osmtgmod/__init__.py b/src/egon/data/datasets/osmtgmod/__init__.py index 51e13f745..497333a95 100644 --- a/src/egon/data/datasets/osmtgmod/__init__.py +++ b/src/egon/data/datasets/osmtgmod/__init__.py @@ -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 @@ -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