Skip to content

Commit

Permalink
Merge branch 'dev' into fixes/#589-unpin-broken-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Mar 24, 2023
2 parents dc8a7ed + 62598cc commit 405bf1e
Show file tree
Hide file tree
Showing 13 changed files with 3,997 additions and 1,672 deletions.
97 changes: 55 additions & 42 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import datetime
import os
import os.path

import numpy as np

__copyright__ = (
Expand Down Expand Up @@ -67,7 +68,7 @@
"FeasibilityTol": 1.0e-5,
"method": 2,
"crossover": 0,
"logFile": "solver_etragos.log",
"logFile": "solver_etrago.log",
"threads": 4,
},
"model_formulation": "kirchhoff", # angles or kirchhoff
Expand All @@ -80,7 +81,9 @@
"csv_export": "results", # save results as csv: False or /path/tofolder
# Settings:
"extendable": {
"extendable_components": ["as_in_db"], # Array of components to optimize
"extendable_components": [
"as_in_db"
], # Array of components to optimize
"upper_bounds_grid": { # Set upper bounds for grid expansion
# lines in Germany
"grid_max_D": None, # relative to existing capacity
Expand All @@ -107,8 +110,8 @@
"method_gas": "kmedoids-dijkstra", # choose clustering method: kmeans or kmedoids-dijkstra
"n_clusters_gas": 17, # total number of resulting CH4 nodes (DE+foreign)
"cluster_foreign_gas": False, # take foreign CH4 buses into account, True or False
"k_busmap": False, # False or path/to/busmap.csv
"kmeans_gas_busmap": False, # False or path/to/ch4_busmap.csv
"k_elec_busmap": False, # False or path/to/busmap.csv
"k_gas_busmap": False, # False or path/to/ch4_busmap.csv
"line_length_factor": 1, #
"remove_stubs": False, # remove stubs bevore kmeans clustering
"use_reduced_coordinates": False, #
Expand All @@ -118,32 +121,38 @@
"gas_weight_fromcsv": None, # None or path/to/gas_bus_weight.csv
"n_init": 10, # affects clustering algorithm, only change when neccesary
"max_iter": 100, # 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.
"tol": 1e-6, # affects clustering algorithm, only change when neccesary
"CPU_cores": 4, # number of cores used during clustering. "max" for all cores available.
},
"sector_coupled_clustering": {
"active": True, # choose if clustering is activated
"carrier_data": { # select carriers affected by sector coupling
"central_heat": {"base": ["CH4", "AC"], "strategy": "simultaneous"},
"central_heat": {
"base": ["CH4", "AC"],
"strategy": "simultaneous",
},
},
},
"network_clustering_ehv": False, # clustering of HV buses to EHV buses.
"disaggregation": "uniform", # None, 'mini' or 'uniform'
"disaggregation": None, # None, 'mini' or 'uniform'
# Temporal Complexity:
"snapshot_clustering": {
"active": False, # choose if clustering is activated
"method": "segmentation", # 'typical_periods' or 'segmentation'
"extreme_periods": None, # consideration of extreme timesteps; e.g. 'append'
"how": "daily", # type of period, currently only 'daily' - only relevant for 'typical_periods'
"extreme_periods": None, # consideration of extreme timesteps; e.g. 'append'
"how": "daily", # type of period - only relevant for 'typical_periods'
"storage_constraints": "soc_constraints", # additional constraints for storages - only relevant for 'typical_periods'
"n_clusters": 5, # number of periods - only relevant for 'typical_periods'
"n_segments": 5,
}, # number of segments - only relevant for segmentation
"n_segments": 5, # number of segments - only relevant for segmentation
},
"skip_snapshots": 5, # False or number of snapshots to skip
"dispatch_disaggregation": False, # choose if full complex dispatch optimization should be conducted
"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": False, # meet the demand at value of loss load cost
"load_shedding": True, # meet the demand at value of loss load cost
"foreign_lines": {
"carrier": "AC", # 'DC' for modeling foreign lines as links
"capacity": "osmTGmod",
Expand Down Expand Up @@ -331,7 +340,7 @@ def run_etrago(args, json_path):
{'active': True, method: 'kmedoids-dijkstra', 'n_clusters_AC': 30,
'cluster_foreign_AC': False, method_gas: 'kmeans',
'n_clusters_gas': 30, 'cluster_foreign_gas': False,
'k_busmap': False, 'kmeans_gas_busmap': False, 'line_length_factor': 1,
'k_elec_busmap': False, 'k_ch4_busmap': False, 'line_length_factor': 1,
'remove_stubs': False, 'use_reduced_coordinates': False,
'bus_weight_tocsv': None, 'bus_weight_fromcsv': None,
'gas_weight_tocsv': None, 'gas_weight_fromcsv': None, 'n_init': 10,
Expand All @@ -348,8 +357,10 @@ def run_etrago(args, json_path):
With ``'method'`` you can choose between two clustering methods:
k-means Clustering considering geopraphical locations of buses or
k-medoids Dijkstra Clustering considering electrical distances between buses.
With ``'k_busmap'`` you can choose if you want to load cluster
coordinates from a previous run.
With ``'k_elec_busmap'`` or ``'k_ch4_busmap'``you can choose if you
want to load cluster coordinates from a previous run for the respecting carrier.
It should be considered that once this option is set to True, the
provided number of clusters will be ignored.
Option ``'remove_stubs'`` reduces the overestimating of line meshes.
The other options affect the kmeans algorithm and should only be
changed carefully, documentation and possible settings are described
Expand Down Expand Up @@ -402,9 +413,15 @@ def run_etrago(args, json_path):
State if you only want to consider every n-th timestep
to reduce temporal complexity.
dispatch_disaggregation : bool
temporal_disaggregation : dict
{'active': True, 'no_slices': 4},
State if you to apply a second lopf considering dispatch only
to disaggregate the dispatch to the whole temporal complexity.
Be aware that a load shedding will be applied in this optimization.
With "no_slices" the optimization problem will be calculated as a given
number of subproblems while using some information on the state of charge
of storage units and stores from the former optimization (at the moment
only possible with skip_snapshots; extra_functionalities disregarded)
branch_capacity_factor : dict
{'HV': 0.5, 'eHV' : 0.7},
Expand Down Expand Up @@ -434,7 +451,7 @@ def run_etrago(args, json_path):
<https://www.pypsa.org/doc/components.html#network>`_
"""
etrago = Etrago(args, json_path)
etrago = Etrago(args, json_path=json_path)

# import network from database
etrago.build_network_from_db()
Expand All @@ -449,21 +466,30 @@ def run_etrago(args, json_path):
# happen in the next data creation run

etrago.network.lines_t.s_max_pu = (
etrago.network.lines_t.s_max_pu.transpose()
[etrago.network.lines_t.s_max_pu.columns.isin(
etrago.network.lines.index)].transpose())
etrago.network.lines_t.s_max_pu.transpose()[
etrago.network.lines_t.s_max_pu.columns.isin(
etrago.network.lines.index
)
].transpose()
)

# Set gas grid links bidirectional
etrago.network.links.loc[etrago.network.links[
etrago.network.links.carrier=='CH4'].index, 'p_min_pu'] = -1.
etrago.network.links.loc[
etrago.network.links[etrago.network.links.carrier == "CH4"].index,
"p_min_pu",
] = -1.0

# Set efficiences of CHP
etrago.network.links.loc[etrago.network.links[
etrago.network.links.carrier.str.contains('CHP')].index, 'efficiency'] = 0.43
etrago.network.links.loc[
etrago.network.links[
etrago.network.links.carrier.str.contains("CHP")
].index,
"efficiency",
] = 0.43

etrago.network.links_t.p_min_pu.fillna(0., inplace=True)
etrago.network.links_t.p_max_pu.fillna(1., inplace=True)
etrago.network.links_t.efficiency.fillna(1., inplace=True)
etrago.network.links_t.p_min_pu.fillna(0.0, inplace=True)
etrago.network.links_t.p_max_pu.fillna(1.0, inplace=True)
etrago.network.links_t.efficiency.fillna(1.0, inplace=True)

etrago.adjust_network()

Expand All @@ -472,20 +498,15 @@ def run_etrago(args, json_path):

# spatial clustering
etrago.spatial_clustering()

etrago.spatial_clustering_gas()

etrago.args["load_shedding"] = True
etrago.load_shedding()

# snapshot clustering
etrago.snapshot_clustering()

# skip snapshots
etrago.skip_snapshots()

# start linear optimal powerflow calculations
# needs to be adjusted for new sectors
etrago.lopf()

# conduct lopf with full complex timeseries for dispatch disaggregation
Expand All @@ -510,11 +531,3 @@ def run_etrago(args, json_path):
etrago = run_etrago(args, json_path=None)
print(datetime.datetime.now())
etrago.session.close()
# plots
# make a line loading plot
# plot_line_loading(network)
# plot stacked sum of nominal power for each generator type and timestep
# plot_stacked_gen(network, resolution="MW")
# plot to show extendable storages
# storage_distribution(network)
# extension_overlay_network(network)
4 changes: 4 additions & 0 deletions etrago/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"n_segments": 5
},
"skip_snapshots": 3,
"temporal_disaggregation": {
"active": true,
"no_slices": 8,
},
"branch_capacity_factor": {
"HV": 0.5,
"eHV": 0.7
Expand Down
Loading

0 comments on commit 405bf1e

Please sign in to comment.