Skip to content

Commit

Permalink
wip first try market optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfmueller committed Aug 28, 2023
1 parent 2a57cfd commit 52a01bb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 28 deletions.
40 changes: 20 additions & 20 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@

args = {
# Setup and Configuration:
"db": "egon-data", # database session
"db": "local", # database session
"gridversion": None, # None for model_draft or Version number
"method": { # Choose method and settings for optimization
"type": "lopf", # type of optimization, currently only 'lopf'
"type": "market_grid", # type of optimization, currently only 'lopf'
"n_iter": 4, # abort criterion of iterative optimization, 'n_iter' or 'threshold'
"pyomo": True, # set if pyomo is used for model building
},
"pf_post_lopf": {
"active": True, # choose if perform a pf after lopf
"active": False, # choose if perform a pf after lopf
"add_foreign_lopf": True, # keep results of lopf for foreign DC-links
"q_allocation": "p_nom", # allocate reactive power via 'p_nom' or 'p'
},
"start_snapshot": 1,
"end_snapshot": 10,
"end_snapshot": 2,
"solver": "gurobi", # glpk, cplex or gurobi
"solver_options": {
"BarConvTol": 1.0e-5,
Expand All @@ -74,7 +74,7 @@
"threads": 4,
},
"model_formulation": "kirchhoff", # angles or kirchhoff
"scn_name": "eGon2035", # scenario: eGon2035, eGon100RE or status2019
"scn_name": "status2019", # scenario: eGon2035, eGon100RE or status2019
# Scenario variations:
"scn_extension": None, # None or array of extension scenarios
"scn_decommissioning": None, # None or decommissioning scenario
Expand All @@ -100,17 +100,17 @@
"grid_max_abs_foreign": None, # absolute capacity per voltage level
},
},
"generator_noise": 789456, # apply generator noise, False or seed number
"generator_noise": 123456, # apply generator noise, False or seed number
"extra_functionality": {}, # Choose function name or {}
# Spatial Complexity:
"network_clustering_ehv": False, # clustering of HV buses to EHV buses
"network_clustering": {
"active": True, # choose if clustering is activated
"method": "kmedoids-dijkstra", # choose clustering method: kmeans or kmedoids-dijkstra
"n_clusters_AC": 30, # total number of resulting AC nodes (DE+foreign)
"cluster_foreign_AC": False, # take foreign AC buses into account, True or False
"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
"n_clusters_gas": 17, # total number of resulting CH4 nodes (DE+foreign)
"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
"k_gas_busmap": False, # False or path/to/ch4_busmap.csv
Expand All @@ -122,13 +122,13 @@
"remove_stubs": False, # remove stubs bevore kmeans clustering
"use_reduced_coordinates": False, # If True, do not average cluster coordinates
"random_state": 42, # random state for replicability of clustering results
"n_init": 10, # affects clustering algorithm, only change when neccesary
"max_iter": 100, # affects clustering algorithm, only change when neccesary
"n_init": 2, # affects clustering algorithm, only change when neccesary
"max_iter": 10, # affects clustering algorithm, only change when neccesary
"tol": 1e-6, # affects clustering algorithm, only change when neccesary
"CPU_cores": 4, # number of cores used during clustering, "max" for all cores available.
"CPU_cores": 2, # number of cores used during clustering, "max" for all cores available.
},
"sector_coupled_clustering": {
"active": True, # choose if clustering is activated
"active": False, # choose if clustering is activated
"carrier_data": { # select carriers affected by sector coupling
"central_heat": {
"base": ["CH4", "AC"],
Expand All @@ -148,14 +148,14 @@
"n_clusters": 5, # number of periods - only relevant for 'typical_periods'
"n_segments": 5, # number of segments - only relevant for segmentation
},
"skip_snapshots": 5, # False or number of snapshots to skip
"skip_snapshots": False, # False or number of snapshots to skip
"temporal_disaggregation": {
"active": False, # choose if temporally full complex dispatch optimization should be conducted
"no_slices": 8, # number of subproblems optimization is divided into
},
# Simplifications:
"branch_capacity_factor": {"HV": 0.5, "eHV": 0.7}, # p.u. branch derating
"load_shedding": True, # meet the demand at value of loss load cost
"load_shedding": False, # meet the demand at value of loss load cost
"foreign_lines": {
"carrier": "AC", # 'DC' for modeling foreign lines as links
"capacity": "osmTGmod", # 'osmTGmod', 'tyndp2020', 'ntc_acer' or 'thermal_acer'
Expand Down Expand Up @@ -476,17 +476,17 @@ def run_etrago(args, json_path):
etrago.optimize()

# conduct lopf with full complex timeseries for dispatch disaggregation
etrago.dispatch_disaggregation()
#etrago.dispatch_disaggregation()

# start power flow based on lopf results
etrago.pf_post_lopf()
#etrago.pf_post_lopf()

# spatial disaggregation
# needs to be adjusted for new sectors
etrago.disaggregation()
#etrago.disaggregation()

# calculate central etrago results
etrago.calc_results()
#etrago.calc_results()

return etrago

Expand Down
1 change: 0 additions & 1 deletion etrago/cluster/electrical.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,6 @@ def postprocessing(etrago, busmap, busmap_foreign, medoid_idx=None):
network.generators["weight"] = network.generators["p_nom"]
aggregate_one_ports = network.one_port_components.copy()
aggregate_one_ports.discard("Generator")

clustering = get_clustering_from_busmap(
network,
busmap,
Expand Down
4 changes: 2 additions & 2 deletions etrago/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ def optimize(self):

self.market_optimization()

self.market_results_to_grid()
#self.market_results_to_grid()

self.grid_optimization()
#self.grid_optimization()

else:
print("Method not defined")
Expand Down
58 changes: 53 additions & 5 deletions etrago/execute/market_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@

import numpy as np
import pandas as pd

from etrago.cluster.electrical import preprocessing
from etrago.cluster.spatial import (
strategies_one_ports,
strategies_generators,)

from pypsa.networkclustering import get_clustering_from_busmap




logger = logging.getLogger(__name__)
Expand All @@ -47,9 +56,10 @@

def market_optimization(self):

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

self.market_model.lopf(
self.network.lopf(
solver_name=self.args["solver"],
solver_options=self.args["solver_options"],
pyomo=True,
Expand All @@ -59,7 +69,7 @@ def market_optimization(self):
)


def build_market_model():
def build_market_model(self):
"""Builds market model based on imported network from eTraGo
Expand All @@ -73,9 +83,47 @@ def build_market_model():
None.
"""
# Not useful, just for demonstration
self.market_model = self.network.copy()

# use existing preprocessing to get only the electricity system

net, weight, n_clusters, busmap_foreign = preprocessing(self)

df = pd.DataFrame({'country': net.buses.country.unique(),
'marketzone': net.buses.country.unique()},
columns = ["country", "marketzone"])

df.loc[(df.country == 'DE')| (df.country == 'LU'), 'marketzone'] = 'DE/LU'

df['cluster'] = df.groupby(df.marketzone).grouper.group_info[0]


for i in net.buses.country.unique():

net.buses.loc[net.buses.country== i , 'cluster'] = df.loc[df.country == i, 'cluster'].values[0]


busmap = pd.Series(net.buses.cluster.astype(int).astype(str), net.buses.index)

aggregate_one_ports = net.one_port_components.copy()
aggregate_one_ports.discard("Generator")

net.generators.control = "PV"

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


clustering = get_clustering_from_busmap(
net,
busmap,
aggregate_generators_weighted=False,
one_port_strategies=strategies_one_ports(),
generator_strategies=strategies_generators(),
aggregate_one_ports=aggregate_one_ports,
line_length_factor=1,
)
net = clustering.network
self.network = net



def extra_functionality():
Expand Down

0 comments on commit 52a01bb

Please sign in to comment.