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

Features/#665 interface pre market market optimization #722

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
5 changes: 5 additions & 0 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"type": "market_grid", # type of optimization, currently only 'lopf'
"n_iter": 1, # abort criterion of iterative optimization, 'n_iter' or 'threshold'
"pyomo": True, # set if pyomo is used for model building
"formulation": "pyomo",
"rolling_horizon": { # Define parameter of market optimization
"planning_horizon": 72, # number of snapshots in each optimization
"overlap": 24, # number of overlapping hours
},
},
"pf_post_lopf": {
"active": False, # choose if perform a pf after lopf
Expand Down
43 changes: 35 additions & 8 deletions etrago/cluster/electrical.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def leader(x):
return leader


def adjust_no_electric_network(etrago, busmap, cluster_met):
def adjust_no_electric_network(etrago, busmap, cluster_met, apply_on="grid_model"):
"""
Adjusts the non-electric network based on the electrical network
(esp. eHV network), adds the gas buses to the busmap, and creates the
Expand Down Expand Up @@ -139,7 +139,16 @@ def find_de_closest(network, bus_ne):

return new_ehv_bus

network = etrago.network.copy()
if apply_on=="grid_model":
network = etrago.network.copy()
elif apply_on == "market_model":
network = etrago.network_tsa.copy()
else:
logger.warning(
"""Parameter apply_on must be either 'grid_model' or 'market_model'
"""
)

# network2 is supposed to contain all the not electrical or gas buses
# and links
network2 = network.copy(with_time=False)
Expand Down Expand Up @@ -457,7 +466,7 @@ def ehv_clustering(self):
logger.info("Network clustered to EHV-grid")


def select_elec_network(etrago):
def select_elec_network(etrago, apply_on="grid_model"):
"""
Selects the electric network based on the clustering settings specified
in the Etrago object.
Expand All @@ -475,7 +484,15 @@ def select_elec_network(etrago):
n_clusters : int
number of clusters used in the clustering process.
"""
elec_network = etrago.network.copy()
if apply_on=="grid_model":
elec_network = etrago.network.copy()
elif apply_on=="market_model":
elec_network=etrago.network_tsa.copy()
else:
logger.warning(
"""Parameter apply_on must be either 'grid_model' or 'market_model'
"""
)
settings = etrago.args["network_clustering"]
if settings["cluster_foreign_AC"]:
elec_network.buses = elec_network.buses[
Expand Down Expand Up @@ -626,7 +643,7 @@ def unify_foreign_buses(etrago):
return busmap_foreign


def preprocessing(etrago):
def preprocessing(etrago, apply_on="grid_model"):
"""
Preprocesses an Etrago object to prepare it for network clustering.

Expand All @@ -647,7 +664,16 @@ def preprocessing(etrago):
The Series object with the foreign bus mapping data.
"""

network = etrago.network
if apply_on == "grid_model":
network = etrago.network
elif apply_on == "market_model":
network = etrago.network_tsa
else:
logger.warning(
"""Parameter apply_on must be either 'grid_model' or 'market_model'
"""
)

settings = etrago.args["network_clustering"]

# problem our lines have no v_nom. this is implicitly defined by the
Expand Down Expand Up @@ -736,7 +762,7 @@ def preprocessing(etrago):
else:
busmap_foreign = pd.Series(name="foreign", dtype=str)

network_elec, n_clusters = select_elec_network(etrago)
network_elec, n_clusters = select_elec_network(etrago, apply_on=apply_on)

if settings["method"] == "kmedoids-dijkstra":
lines_col = network_elec.lines.columns
Expand Down Expand Up @@ -777,6 +803,7 @@ def postprocessing(
medoid_idx=None,
aggregate_generators_carriers=None,
aggregate_links=True,
apply_on="grid_model"
):
"""
Postprocessing function for network clustering.
Expand Down Expand Up @@ -846,7 +873,7 @@ def postprocessing(
)

network, busmap = adjust_no_electric_network(
etrago, busmap, cluster_met=method
etrago, busmap, cluster_met=method, apply_on=apply_on
)

# merge busmap for foreign buses with the German buses
Expand Down
2 changes: 1 addition & 1 deletion etrago/cluster/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ def skip_snapshots(self):
if (
self.args["temporal_disaggregation"]["active"]
and not self.args["snapshot_clustering"]["active"]
):
) or self.args["method"]["type"]=="market_grid":
self.network_tsa = self.network.copy()

n_skip = self.args["skip_snapshots"]
Expand Down
83 changes: 47 additions & 36 deletions etrago/execute/grid_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,33 @@ def fix_chp_generation(self):
# Fix generator dispatch from market simulation:
# Set p_max_pu of generators using results from (disaggregated) market
# model
self.network.generators_t.p_max_pu.loc[
:, gens_fixed
] = self.market_model.generators_t.p[gens_fixed].mul(
1 / self.market_model.generators.p_nom[gens_fixed]
self.network.generators_t.p_max_pu.loc[:, gens_fixed] = (
self.market_model.generators_t.p[gens_fixed].mul(
1 / self.market_model.generators.p_nom[gens_fixed]
)
)

# Set p_min_pu of generators using results from (disaggregated) market
# model
self.network.generators_t.p_min_pu.loc[
:, gens_fixed
] = self.market_model.generators_t.p[gens_fixed].mul(
1 / self.market_model.generators.p_nom[gens_fixed]
self.network.generators_t.p_min_pu.loc[:, gens_fixed] = (
self.market_model.generators_t.p[gens_fixed].mul(
1 / self.market_model.generators.p_nom[gens_fixed]
)
)

# Fix link dispatch (gas turbines) from market simulation
# Set p_max_pu of links using results from (disaggregated) market model
self.network.links_t.p_max_pu.loc[
:, links_fixed
] = self.market_model.links_t.p0[links_fixed].mul(
1 / self.market_model.links.p_nom[links_fixed]
self.network.links_t.p_max_pu.loc[:, links_fixed] = (
self.market_model.links_t.p0[links_fixed].mul(
1 / self.market_model.links.p_nom[links_fixed]
)
)

# Set p_min_pu of links using results from (disaggregated) market model
self.network.links_t.p_min_pu.loc[
:, links_fixed
] = self.market_model.links_t.p0[links_fixed].mul(
1 / self.market_model.links.p_nom[links_fixed]
self.network.links_t.p_min_pu.loc[:, links_fixed] = (
self.market_model.links_t.p0[links_fixed].mul(
1 / self.market_model.links.p_nom[links_fixed]
)
)


Expand Down Expand Up @@ -139,33 +139,33 @@ def add_redispatch_generators(self):
# Fix generator dispatch from market simulation:
# Set p_max_pu of generators using results from (disaggregated) market
# model
self.network.generators_t.p_max_pu.loc[
:, gens_redispatch
] = self.market_model.generators_t.p[gens_redispatch].mul(
1 / self.market_model.generators.p_nom[gens_redispatch]
self.network.generators_t.p_max_pu.loc[:, gens_redispatch] = (
self.market_model.generators_t.p[gens_redispatch].mul(
1 / self.market_model.generators.p_nom[gens_redispatch]
)
)

# Set p_min_pu of generators using results from (disaggregated) market
# model
self.network.generators_t.p_min_pu.loc[
:, gens_redispatch
] = self.market_model.generators_t.p[gens_redispatch].mul(
1 / self.market_model.generators.p_nom[gens_redispatch]
self.network.generators_t.p_min_pu.loc[:, gens_redispatch] = (
self.market_model.generators_t.p[gens_redispatch].mul(
1 / self.market_model.generators.p_nom[gens_redispatch]
)
)

# Fix link dispatch (gas turbines) from market simulation
# Set p_max_pu of links using results from (disaggregated) market model
self.network.links_t.p_max_pu.loc[
:, links_redispatch
] = self.market_model.links_t.p0[links_redispatch].mul(
1 / self.market_model.links.p_nom[links_redispatch]
self.network.links_t.p_max_pu.loc[:, links_redispatch] = (
self.market_model.links_t.p0[links_redispatch].mul(
1 / self.market_model.links.p_nom[links_redispatch]
)
)

# Set p_min_pu of links using results from (disaggregated) market model
self.network.links_t.p_min_pu.loc[
:, links_redispatch
] = self.market_model.links_t.p0[links_redispatch].mul(
1 / self.market_model.links.p_nom[links_redispatch]
self.network.links_t.p_min_pu.loc[:, links_redispatch] = (
self.market_model.links_t.p0[links_redispatch].mul(
1 / self.market_model.links.p_nom[links_redispatch]
)
)

# Calculate costs for redispatch
Expand Down Expand Up @@ -221,7 +221,8 @@ def add_redispatch_generators(self):
self.network.generators_t.p_max_pu.loc[:, gens_redispatch].mul(
self.network.generators.loc[gens_redispatch, "p_nom"]
)
- (self.market_model.generators_t.p.loc[:, gens_redispatch])
- (self.market_model.generators_t.p.loc[self.network.snapshots,
gens_redispatch])
)
.clip(lower=0.0)
.values
Expand All @@ -247,7 +248,7 @@ def add_redispatch_generators(self):
self.network.links_t.p_max_pu.loc[:, links_redispatch + " ramp_up"] = (
(
self.network.links.loc[links_redispatch, "p_nom"]
- (self.market_model.links_t.p0.loc[:, links_redispatch])
- (self.market_model.links_t.p0.loc[self.network.snapshots, links_redispatch])
)
.clip(lower=0.0)
.values
Expand All @@ -273,7 +274,13 @@ def add_redispatch_generators(self):
# (disaggregated) generators in the market model
self.network.generators_t.p_min_pu.loc[
:, gens_redispatch + " ramp_down"
] = (-(self.market_model.generators_t.p.loc[:, gens_redispatch])).values
] = (
-(
self.market_model.generators_t.p.loc[self.network.snapshots, gens_redispatch].clip(
lower=0.0
)
)
).values

# Add ramp down links to the network for the grid optimization
# Marginal cost are currently only the management fee of 4 EUR/MWh,
Expand All @@ -295,7 +302,11 @@ def add_redispatch_generators(self):
# Ramp down can be at maximum as high as the feed-in of the
# (disaggregated) links in the market model
self.network.links_t.p_min_pu.loc[:, links_redispatch + " ramp_down"] = (
-(self.market_model.links_t.p0.loc[:, links_redispatch])
-(
self.market_model.links_t.p0.loc[self.network.snapshots, links_redispatch].clip(
lower=0.0
)
)
).values

# Check if the network contains any problems
Expand Down
Loading
Loading