From bca53a79db0da452589e5f6c4146d988b8eb65cc Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Tue, 26 Sep 2023 16:41:00 +0200 Subject: [PATCH 1/6] Add dc-lines to edges of ehv clustering --- etrago/cluster/spatial.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/etrago/cluster/spatial.py b/etrago/cluster/spatial.py index 43af10b9..7c4b4850 100755 --- a/etrago/cluster/spatial.py +++ b/etrago/cluster/spatial.py @@ -395,6 +395,12 @@ def busmap_by_shortest_path(etrago, scn_name, fromlvl, tolvl, cpu_cores=4): transformer = connected_transformer(etrago.network, s_buses) mask = transformer.bus1.isin(buses_of_vlvl(etrago.network, tolvl)) + dc = etrago.network.links[etrago.network.links.carrier == "DC"] + dc.index = "DC_" + dc.index + lines_plus_dc = pd.concat([lines, dc]) + lines_plus_dc = lines_plus_dc[etrago.network.lines.columns] + lines_plus_dc["carrier"] = "AC" + # temporary end points, later replaced by bus1 pendant t_buses = transformer[mask].bus0 @@ -403,7 +409,7 @@ def busmap_by_shortest_path(etrago, scn_name, fromlvl, tolvl, cpu_cores=4): # graph creation edges = [ - (row.bus0, row.bus1, row.length, ix) for ix, row in lines.iterrows() + (row.bus0, row.bus1, row.length, ix) for ix, row in lines_plus_dc.iterrows() ] M = graph_from_edges(edges) From 5e566b1de1b8a126b94ef2b6efeeadb3f8d3f8ae Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Tue, 26 Sep 2023 16:41:28 +0200 Subject: [PATCH 2/6] Add buses connected by dc lines to connected_buses --- etrago/tools/utilities.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etrago/tools/utilities.py b/etrago/tools/utilities.py index d44171bc..c3f29dee 100755 --- a/etrago/tools/utilities.py +++ b/etrago/tools/utilities.py @@ -127,6 +127,8 @@ def buses_grid_linked(network, voltage_level): mask = ( network.buses.index.isin(network.lines.bus0) | (network.buses.index.isin(network.lines.bus1)) + | (network.buses.index.isin(network.links.loc[network.links.carrier=="DC", "bus0"])) + | (network.buses.index.isin(network.links.loc[network.links.carrier=="DC", "bus1"])) ) & (network.buses.v_nom.isin(voltage_level)) df = network.buses[mask] From 3edaf2574abfb0013be44f5b37e6e29ae7ef60b1 Mon Sep 17 00:00:00 2001 From: CarlosEpia Date: Wed, 4 Oct 2023 17:36:07 +0200 Subject: [PATCH 3/6] discard DC links under 220kV --- etrago/cluster/electrical.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index e46d6b0f..a834e8c3 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -320,6 +320,8 @@ def cluster_on_extra_high_voltage(etrago, busmap, with_time=True): # Dealing with links links = network.links.copy() dc_links = links[links["carrier"] == "DC"] + # Discard links connected to buses under 220 kV + dc_links = dc_links[dc_links.bus0.isin(buses.index)] links = links[links["carrier"] != "DC"] new_links = ( From c63a459fa4b57dee6c4efb1432fad2078344b6d6 Mon Sep 17 00:00:00 2001 From: CarlosEpia Date: Thu, 5 Oct 2023 08:55:39 +0200 Subject: [PATCH 4/6] create hv busmap everytime eHV clus runs --- etrago/cluster/spatial.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/etrago/cluster/spatial.py b/etrago/cluster/spatial.py index 7c4b4850..0cfe098f 100755 --- a/etrago/cluster/spatial.py +++ b/etrago/cluster/spatial.py @@ -409,7 +409,8 @@ def busmap_by_shortest_path(etrago, scn_name, fromlvl, tolvl, cpu_cores=4): # graph creation edges = [ - (row.bus0, row.bus1, row.length, ix) for ix, row in lines_plus_dc.iterrows() + (row.bus0, row.bus1, row.length, ix) + for ix, row in lines_plus_dc.iterrows() ] M = graph_from_edges(edges) @@ -538,24 +539,26 @@ def fetch(): busmap = fetch() - # TODO: Or better try/except/finally - if not busmap: - print("Busmap does not exist and will be created.\n") - - cpu_cores = etrago.args["network_clustering"]["CPU_cores"] - if cpu_cores == "max": - cpu_cores = mp.cpu_count() - else: - cpu_cores = int(cpu_cores) - - busmap_by_shortest_path( - etrago, - scn_name, - fromlvl=[110], - tolvl=[220, 380, 400, 450], - cpu_cores=cpu_cores, + if busmap: + print( + "Existing busmap will be deleted and a new one will be calculated.\n" ) - busmap = fetch() + etrago.engine.execute("""DELETE FROM grid.egon_etrago_hv_busmap""") + + cpu_cores = etrago.args["network_clustering"]["CPU_cores"] + if cpu_cores == "max": + cpu_cores = mp.cpu_count() + else: + cpu_cores = int(cpu_cores) + + busmap_by_shortest_path( + etrago, + scn_name, + fromlvl=[110], + tolvl=[220, 380, 400, 450], + cpu_cores=cpu_cores, + ) + busmap = fetch() return busmap From 18a454d42a3b589362948f8fda83b3ce5a9cceb6 Mon Sep 17 00:00:00 2001 From: CarlosEpia Date: Thu, 5 Oct 2023 10:33:14 +0200 Subject: [PATCH 5/6] make optional delete_dispensable_ac_buses --- etrago/appl.py | 6 ++++++ etrago/cluster/spatial.py | 2 +- etrago/tools/utilities.py | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/etrago/appl.py b/etrago/appl.py index cdf3f3ad..a1745fa7 100644 --- a/etrago/appl.py +++ b/etrago/appl.py @@ -103,6 +103,7 @@ "generator_noise": 789456, # apply generator noise, False or seed number "extra_functionality": {}, # Choose function name or {} # Spatial Complexity: + "delete_dispensable_ac_buses": False, # bool. Find and delete unnecesary buses "network_clustering_ehv": False, # clustering of HV buses to EHV buses "network_clustering": { "active": True, # choose if clustering is activated @@ -379,6 +380,11 @@ def run_etrago(args, json_path): Limit overall energy production country-wise for each generator by carrier. Set upper/lower limit in p.u. + delete_dispensable_ac_buses: bool + Choose if unnecessary buses should be identified and deleted from the + grid. This buses have no load or generation attached. Additionally, + they are just connected to two other buses. + Default: False. network_clustering_ehv : bool Choose if you want to cluster the full HV/EHV dataset down to only the EHV buses. In that case, all HV buses are assigned to their closest EHV diff --git a/etrago/cluster/spatial.py b/etrago/cluster/spatial.py index 0cfe098f..db3cc161 100755 --- a/etrago/cluster/spatial.py +++ b/etrago/cluster/spatial.py @@ -541,7 +541,7 @@ def fetch(): if busmap: print( - "Existing busmap will be deleted and a new one will be calculated.\n" + "Existing busmap will be deleted and a new one will be calculated." ) etrago.engine.execute("""DELETE FROM grid.egon_etrago_hv_busmap""") diff --git a/etrago/tools/utilities.py b/etrago/tools/utilities.py index c3f29dee..ebc858f1 100755 --- a/etrago/tools/utilities.py +++ b/etrago/tools/utilities.py @@ -127,8 +127,16 @@ def buses_grid_linked(network, voltage_level): mask = ( network.buses.index.isin(network.lines.bus0) | (network.buses.index.isin(network.lines.bus1)) - | (network.buses.index.isin(network.links.loc[network.links.carrier=="DC", "bus0"])) - | (network.buses.index.isin(network.links.loc[network.links.carrier=="DC", "bus1"])) + | ( + network.buses.index.isin( + network.links.loc[network.links.carrier == "DC", "bus0"] + ) + ) + | ( + network.buses.index.isin( + network.links.loc[network.links.carrier == "DC", "bus1"] + ) + ) ) & (network.buses.v_nom.isin(voltage_level)) df = network.buses[mask] @@ -1081,6 +1089,8 @@ def delete_dispensable_ac_buses(etrago): None. """ + if etrago.args["delete_dispensable_ac_buses"] is False: + return def delete_buses(delete_buses, network): drop_buses = delete_buses.index.to_list() From 5af51c24df4a041c5f6cc1c77538d53259dfd4b7 Mon Sep 17 00:00:00 2001 From: CarlosEpia Date: Thu, 5 Oct 2023 15:28:05 +0200 Subject: [PATCH 6/6] correct typo --- etrago/appl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etrago/appl.py b/etrago/appl.py index a1745fa7..364e5be1 100644 --- a/etrago/appl.py +++ b/etrago/appl.py @@ -103,7 +103,7 @@ "generator_noise": 789456, # apply generator noise, False or seed number "extra_functionality": {}, # Choose function name or {} # Spatial Complexity: - "delete_dispensable_ac_buses": False, # bool. Find and delete unnecesary buses + "delete_dispensable_ac_buses": False, # bool. Find and delete unnecessary buses "network_clustering_ehv": False, # clustering of HV buses to EHV buses "network_clustering": { "active": True, # choose if clustering is activated