Skip to content

Commit

Permalink
still wip: optimizing the market model building
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfmueller committed Aug 29, 2023
1 parent cf93f8c commit bef0d55
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 40 deletions.
4 changes: 2 additions & 2 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"method": "kmeans", # choose clustering method: kmeans or kmedoids-dijkstra
"n_clusters_AC": 50, # total number of resulting AC nodes (DE+foreign)
"cluster_foreign_AC": True, # take foreign AC buses into account, True or False
"method_gas": "kmedoids-dijkstra", # choose clustering method: kmeans or kmedoids-dijkstra
"method_gas": "kmeans", # choose clustering method: kmeans or kmedoids-dijkstra
"n_clusters_gas": 14, # total number of resulting CH4 nodes (DE+foreign)
"cluster_foreign_gas": False, # take foreign CH4 buses into account, True or False
"k_elec_busmap": False, # False or path/to/busmap.csv
Expand All @@ -128,7 +128,7 @@
"CPU_cores": 2, # number of cores used during clustering, "max" for all cores available.
},
"sector_coupled_clustering": {
"active": False, # choose if clustering is activated
"active": True, # choose if clustering is activated
"carrier_data": { # select carriers affected by sector coupling
"central_heat": {
"base": ["CH4", "AC"],
Expand Down
70 changes: 37 additions & 33 deletions etrago/cluster/electrical.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,44 +703,48 @@ def preprocessing(etrago):
network.lines.loc[lines_v_nom_b, "v_nom"] = 380.0

trafo_index = network.transformers.index
transformer_voltages = pd.concat(
[
network.transformers.bus0.map(network.buses.v_nom),
network.transformers.bus1.map(network.buses.v_nom),
],
axis=1,
)

network.import_components_from_dataframe(
network.transformers.loc[
:,
if not trafo_index.empty:
transformer_voltages = pd.concat(
[
"bus0",
"bus1",
"x",
"s_nom",
"capital_cost",
"sub_network",
"s_max_pu",
"lifetime",
network.transformers.bus0.map(network.buses.v_nom),
network.transformers.bus1.map(network.buses.v_nom),
],
]
.assign(
x=network.transformers.x
* (380.0 / transformer_voltages.max(axis=1)) ** 2,
length=1,
axis=1,
)
.set_index("T" + trafo_index),
"Line",
)
network.lines.carrier = "AC"

network.transformers.drop(trafo_index, inplace=True)

for attr in network.transformers_t:
network.transformers_t[attr] = network.transformers_t[attr].reindex(
columns=[]

network.import_components_from_dataframe(
network.transformers.loc[
:,
[
"bus0",
"bus1",
"x",
"s_nom",
"capital_cost",
"sub_network",
"s_max_pu",
"lifetime",
],
]
.assign(
x=network.transformers.x
* (380.0 / transformer_voltages.max(axis=1)) ** 2,
length=1,
)
.set_index("T" + trafo_index),
"Line",
)
network.lines.carrier = "AC"

network.transformers.drop(trafo_index, inplace=True)

for attr in network.transformers_t:
network.transformers_t[attr] = network.transformers_t[attr].reindex(
columns=[]
)
elif trafo_index.empty:
logging.info('Your network does not have any transformer')

network.buses["v_nom"].loc[network.buses.carrier.values == "AC"] = 380.0

Expand Down
25 changes: 20 additions & 5 deletions etrago/execute/market_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def market_optimization(self):

logger.info("Start building market model")
build_market_model(self)

logger.info("Start solving market model")
self.market_model.lopf(
solver_name=self.args["solver"],
solver_options=self.args["solver_options"],
Expand Down Expand Up @@ -109,9 +109,8 @@ def build_market_model(self):

net.generators.control = "PV"

#net.lines.sub_network.fillna('', inplace=True)


logger.info("Start market zone specifc clustering")

clustering = get_clustering_from_busmap(
net,
busmap,
Expand All @@ -122,7 +121,23 @@ def build_market_model(self):
line_length_factor=1,
)
net = clustering.network
self.market_model = clustering.network
links_col = net.links.columns
ac = net.lines[net.lines.carrier == "AC"]
str1 = "transshipment_"
ac.index = f"{str1}" + ac.index
transshipment_links = pd.concat([net.links, ac])
transshipment_links = transshipment_links[links_col]
net.links = transshipment_links.copy()
net.links.loc[net.links.carrier == 'AC', 'carrier'] = "DC"
net.lines.drop(net.lines.loc[net.lines.carrier == 'AC'].index, inplace=True)
net.buses.loc[net.buses.carrier == 'AC', 'carrier'] = "DC"


self.market_model = net

# todo: re-apply gas clustering





Expand Down

0 comments on commit bef0d55

Please sign in to comment.