Skip to content

Commit

Permalink
Merge pull request #736 from openego/fixes/#735-gas-clustering-not-wo…
Browse files Browse the repository at this point in the history
…rking-with-status2019

Fixes/#735 gas clustering not working with status2019
  • Loading branch information
CarlosEpia authored Apr 18, 2024
2 parents 697e871 + b7b4960 commit 5709025
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 56 deletions.
50 changes: 2 additions & 48 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,49 +681,6 @@ def run_etrago(args, json_path):
# adjust network regarding eTraGo setting
etrago.adjust_network()

if etrago.args["scn_name"] == "status2019":
etrago.network.mremove(
"Link",
etrago.network.links[
~etrago.network.links.bus0.isin(etrago.network.buses.index)
].index,
)
etrago.network.mremove(
"Link",
etrago.network.links[
~etrago.network.links.bus1.isin(etrago.network.buses.index)
].index,
)
etrago.network.lines.loc[etrago.network.lines.r == 0.0, "r"] = 10

# delete following unconnected CH4 buses. why are they there?
etrago.network.buses.drop(
etrago.network.buses[
etrago.network.buses.index.isin(["37865", "37870"])
].index,
inplace=True,
)

etrago.network.links.loc[
etrago.network.links.carrier.isin(
["central_gas_chp", "industrial_gas_CHP"]
),
"p_nom",
] *= 1e-3
etrago.network.generators.loc[
etrago.network.generators.carrier.isin(
[
"central_lignite_CHP",
"industrial_lignite_CHP",
"central_oil_CHP",
"industrial_coal_CHP",
"central_coal_CHP",
"industrial_oil_CHP" "central_others_CHP",
]
),
"p_nom",
] *= 1e-3

# ehv network clustering
etrago.ehv_clustering()

Expand All @@ -739,19 +696,16 @@ def run_etrago(args, json_path):
etrago.skip_snapshots()

# Temporary drop DLR as it is currently not working with sclopf
if etrago.args["method"] != "lopf":
if etrago.args["method"]["type"] != "lopf":
etrago.network.lines_t.s_max_pu = pd.DataFrame(
index=etrago.network.snapshots,
columns=etrago.network.lines.index,
data=1.0,
)

# start linear optimal powerflow calculations

etrago.network.storage_units.cyclic_state_of_charge = True

etrago.network.lines.loc[etrago.network.lines.r == 0.0, "r"] = 10

# start linear optimal powerflow calculations
etrago.optimize()

# conduct lopf with full complex timeseries for dispatch disaggregation
Expand Down
2 changes: 1 addition & 1 deletion etrago/cluster/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def weighting_for_scenario(ch4_buses, save=None):
weight_ch4.loc[loaded_weights.index] = loaded_weights
else:
weight_ch4 = weighting_for_scenario(network_ch4.buses, save=False)
return network_ch4, weight_ch4.squeeze(), n_clusters
return network_ch4, weight_ch4.squeeze(axis=1), n_clusters


def kmean_clustering_gas(etrago, network_ch4, weight, n_clusters):
Expand Down
24 changes: 17 additions & 7 deletions etrago/cluster/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,23 @@ def kmedoids_dijkstra_clustering(

medoid_idx = distances.idxmin()

# dijkstra's algorithm
busmap = dijkstras_algorithm(
buses,
connections,
medoid_idx,
etrago.args["network_clustering"]["CPU_cores"],
)
if len(busmap) > n_clusters:
# dijkstra's algorithm
busmap = dijkstras_algorithm(
buses,
connections,
medoid_idx,
etrago.args["network_clustering"]["CPU_cores"],
)
elif len(busmap) < n_clusters:
logger.warning(
f"""
The number supplied to the parameter n_clusters for
{buses.carrier[0]} buses is larger than the actual number of buses
in the network.
"""
)

busmap.index.name = "bus_id"

return busmap, medoid_idx
Expand Down

0 comments on commit 5709025

Please sign in to comment.