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

Fixes/#660 fix ehv clustering #676

Merged
merged 17 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 6 additions & 0 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"grid_max_abs_foreign": None, # absolute capacity per voltage level
},
},
"delete_dispensable_ac_buses": False, # bool. Find and delete unnecesary buses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you set the default to false?
It would also make sense to put it to the spatial clustering attributes, wouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you need to add the parameter to the args.json file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setting this to False can save some time when using small datasets. Also setting it to True would keep the current behaviour of eTraGo. I changed it so to True, but probably both of them make perfect sense.

args.json was also updated.

"generator_noise": 789456, # apply generator noise, False or seed number
"extra_functionality": {}, # Choose function name or {}
# Spatial Complexity:
Expand Down Expand Up @@ -383,6 +384,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably not call it "unnecessary buses" that somehow sounds as if it would be a bug.
It would be also good to mention that it affects the electrical grid.
I would suggest:

Choose if electrical buses that are only connecting two lines should be removed. These buses have no other components attached to them, the connected lines are merged. This reduces the spatial complexity without losing any accuracy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

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
Expand Down
2 changes: 2 additions & 0 deletions etrago/cluster/electrical.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,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 = (
Expand Down
45 changes: 27 additions & 18 deletions etrago/cluster/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,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

Expand All @@ -409,7 +415,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.iterrows()
(row.bus0, row.bus1, row.length, ix)
for ix, row in lines_plus_dc.iterrows()
]
M = graph_from_edges(edges)

Expand Down Expand Up @@ -538,24 +545,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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you don't want to include this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included this change intentionally. Using old eHV busmaps leads to errors in the eHV due to the different arguments for the parameter "foreign_lines": {"carrier": "AC",}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but then I would solve it differently. Right now the busmap is only created if there is data in the table. If there is no data, you do not create the busmap and run into problems.
And it is also not that intuitive that there is a table where busmaps are stored, but it is not used.
I would rather change the check if the busmap from the table can be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the busmap is always created. If there is one already, a message is shown to inform that it will be replaced. Since sometimes we know that the busmap can be reused, I will include a new argument called "reuse_busmap" in my next commit. It will be included in the "network_clustering_ehv" parameter.

print(
"Existing busmap will be deleted and a new one will be calculated."
)
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

Expand Down
12 changes: 12 additions & 0 deletions etrago/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +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.v_nom.isin(voltage_level))

df = network.buses[mask]
Expand Down Expand Up @@ -1079,6 +1089,8 @@ def delete_dispensable_ac_buses(etrago):
None.

"""
if etrago.args["delete_dispensable_ac_buses"] is False:
return
ClaraBuettner marked this conversation as resolved.
Show resolved Hide resolved

def delete_buses(delete_buses, network):
drop_buses = delete_buses.index.to_list()
Expand Down