HSF

Abschlussworkshop open_eGo 2018

Session eTraGo - Optimaler Netz- und Speicherausbau auf Hoch- und Höchstspannungsebene

Installation

Zur Verwendung dieses Notebooks wird die aktuelle eTraGo Version sowie das python package jupyter benötigt. Installiere diese mit

pip3 install eTraGo --process-dependency-links

pip3 install jupyter

Allgemeine Vorgehensweise

  1. Parameter-Einstellungen (args) in appl.py vornehmen. (evtl. darüber hinaus default-Annahmen in untergelagerten Funktionsaufrufen anpassen)
  2. appl.py bzw. etrago(args) ausführen.
  3. Ergebnisse auswerten.
  4. evtl als csv oder in der oedb speichern.

Optimaler Speicherausbau im NEP 2035 Szenario

Fragestellung

  1. An welchen Netzknoten entstehen in Zukunft welche Speicherbedarfe? (zentrale vs. dezentrale Lösungen)
  2. Welches Einsatzverhalten weisen diese optimierten Speicher auf? (Langzeit- vs. Kurzzeitspeicher)
In [1]:
# enable jupyter interactive plotting
%matplotlib notebook
from ipywidgets import *

Importieren der benötigten allgemeinen und eTraGo spezifischen python Packete

In [2]:
import datetime
import os
import os.path
import time
import numpy as np
import pandas as pd

if 'READTHEDOCS' not in os.environ:
    # Sphinx does not run this code.
    # Do not import internal packages directly
    from etrago.cluster.disaggregation import (
            MiniSolverDisaggregation,
            UniformDisaggregation)
    
    from etrago.cluster.networkclustering import (
        busmap_from_psql,
        cluster_on_extra_high_voltage,
        kmean_clustering)
    
    from etrago.tools.io import (
        NetworkScenario,
        results_to_oedb,
        extension,
        decommissioning)
    
    from etrago.tools.plot import (
        plot_line_loading,
        plot_stacked_gen,
        add_coordinates,
        curtailment,
        gen_dist,
        storage_distribution,
        storage_expansion,
        nodal_gen_dispatch,
        network_expansion)

    from etrago.tools.utilities import (
        load_shedding,
        data_manipulation_sh,
        convert_capital_costs,
        results_to_csv,
        parallelisation,
        pf_post_lopf,
        loading_minimization,
        calc_line_losses,
        group_parallel_lines,
        add_missing_components,
        distribute_q,
        set_q_foreign_loads,
        clip_foreign,
        foreign_links,
        crossborder_capacity,
        ramp_limits,
        geolocation_buses,
        get_args_setting,
        set_branch_capacity)
    
    from etrago.tools.extendable import extendable, extension_preselection
    from etrago.cluster.snapshot import snapshot_clustering, daily_bounds
    from egoio.tools import db
    from sqlalchemy.orm import sessionmaker
    import oedialect
    
    from etrago.appl import etrago
/home/ulf/venv/lib/python3.5/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
/home/ulf/venv/lib/python3.5/site-packages/sqlalchemy/ext/declarative/base.py:297: SAWarning: Ignoring declarative-like tuple value of attribute segment: possibly a copy-and-paste error with a comma left at the end of the line?
  "left at the end of the line?" % k)
/home/ulf/venv/lib/python3.5/site-packages/sqlalchemy/ext/declarative/base.py:297: SAWarning: Ignoring declarative-like tuple value of attribute cable: possibly a copy-and-paste error with a comma left at the end of the line?
  "left at the end of the line?" % k)
INFO:keyring.backend:Loading Gnome
INFO:keyring.backend:Loading Google
INFO:keyring.backend:Loading Windows (alt)
INFO:keyring.backend:Loading file
INFO:keyring.backend:Loading keyczar
INFO:keyring.backend:Loading multi
INFO:keyring.backend:Loading pyfs
INFO:keyring.backend:Loading KWallet
INFO:keyring.backend:Loading SecretService
INFO:keyring.backend:Loading Windows
INFO:keyring.backend:Loading macOS

Parameter-Einstellungen (args) in appl.py vornehmen

Für diesen Fall sollen die Netzkapazitäten keine Variable sein. Neben der dispatch-Optimierung soll ausschließlich Speicherausbau optimiert werden. Hierzu wird die array Variable 'extendable': ['storage'] gesetzt.

In [3]:
args = {  # Setup and Configuration:
    'db': 'local',  # database session
    'gridversion': 'v0.4.5',  # None for model_draft or Version number
    'method': 'lopf',  # lopf or pf
    'pf_post_lopf': False,  # perform a pf after a lopf simulation
    'start_snapshot': 48,
    'end_snapshot': 52,
    'solver': 'gurobi',  # glpk, cplex or gurobi
    'solver_options': {},  # {} for default or dict of solver options
    'scn_name': 'NEP 2035',  # a scenario: Status Quo, NEP 2035, eGo 100
    # Scenario variations:
    'scn_extension': None, # None or array of extension scenarios
    'scn_decommissioning': None, # None or decommissioning scenario
    # Export options:
    'lpfile': False,  # save pyomo's lp file: False or /path/tofolder
    'csv_export': './results',  # save results as csv: False or /path/tofolder
    'db_export': False,  # export the results back to the oedb
    # Settings:
    'extendable': ['storage'],  # Array of components to optimize
    'generator_noise': 789456,  # apply generator noise, False or seed number
    'minimize_loading': False,
    'ramp_limits': False, # Choose if using ramp limit of generators
    'extra_functionality': None,  # Choose function name or None
    # Clustering:
    'network_clustering_kmeans': 500,  # False or the value k for clustering
    'load_cluster': "load_cluster_nep_500",  # False or predefined busmap for k-means
    'network_clustering_ehv': False,  # clustering of HV buses to EHV buses.
    'disaggregation': None, # or None, 'mini' or 'uniform'
    'snapshot_clustering': False,  # False or the number of 'periods'
    # Simplifications:
    'parallelisation': False,  # run snapshots parallely.
    'skip_snapshots': False,
    'line_grouping': False,  # group lines parallel lines
    'branch_capacity_factor': {'HV': 0.5, 'eHV' : 0.7},  # factors to change branch capacities
    'load_shedding': False, # meet the demand at very high cost
    'foreign_lines' : {'carrier': 'AC', 'capacity': 'osmTGmod'}, # dict containing carrier and capacity settings of foreign lines
    'comments': None}

Starten der Rechnung

Hierzu muss die appl.py bzw. die Funktion etrago(args) ausgeführt werden. Die Ergebnisse werden in Form eines PyPSA container (pandas) zur Verfügung gestellt.

In [4]:
network, disagg_network = etrago(args)
No data for StoragePqSet in column p_set.
Series p_set of component StorageUnit could not be imported
start k-mean clustering
/home/ulf/venv/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:893: RuntimeWarning: Explicit initial center position passed: performing only one init in k-means instead of n_init=10
  return_n_iter=True)
Inertia of k-means =  315.5491611310268
INFO:pypsa.pf:Slack bus for sub-network 0 is 0
INFO:pypsa.opf:Performed preliminary steps
INFO:pypsa.opf:Building pyomo model using `angles` formulation
INFO:pypsa.opf:Solving model using gurobi
INFO:pypsa.opf:Optimization successful
Time for LOPF [min]: 0.15
Investment costs for all storage units in selected snapshots [EUR]: 22088.15
INFO:pypsa.io:Exported network results has lines, generators, links, storage_units, carriers, buses, loads

Auswertung

Insbesondere die Plotting-Funktionen in etrago.tools.plot können für die Analyse der Ergebnisse verwendet werden.

In [5]:
# Speicherausbau je Technologie und Knoten

storage_expansion(network, scaling=1)

Optimaler Netz- und Speicherausbau

Fragestellung

Welche Kombination aus Netz- und Speicherausbau ist ökonmisch sinnvoll und technisch machbar?

args Einstellungen vornehmen

  1. Zeitraum einstellen: 'start_snapshot': 48, 'end_snapshot': 72
  2. Szenario einstellen: 'scn_name': 'eGo 100'
  3. Netzausbau aktivieren und Speicherausbau im Ausland als Variable setzen: 'extendable': ['network', 'storage', 'foreign_storage']
In [8]:
args_gs = {  # Setup and Configuration:
    'db': 'local',  # database session
    'gridversion': 'v0.4.5',  # None for model_draft or Version number
    'method': 'lopf',  # lopf or pf
    'pf_post_lopf': False,  # perform a pf after a lopf simulation
    'start_snapshot': 48,
    'end_snapshot': 72,
    'solver': 'gurobi',  # glpk, cplex or gurobi
    'solver_options': {},  # {} for default or dict of solver options
    'scn_name': 'eGo 100',  # a scenario: Status Quo, NEP 2035, eGo 100
    # Scenario variations:
    'scn_extension': None, # None or array of extension scenarios
    'scn_decommissioning': None, # None or decommissioning scenario
    # Export options:
    'lpfile': False,  # save pyomo's lp file: False or /path/tofolder
    'csv_export': './results',  # save results as csv: False or /path/tofolder
    'db_export': False,  # export the results back to the oedb
    # Settings:
    'extendable': ['network', 'storage', 'foreign_storage'],  # Array of components to optimize
    'generator_noise': 789456,  # apply generator noise, False or seed number
    'minimize_loading': False,
    'ramp_limits': False, # Choose if using ramp limit of generators
    'extra_functionality': None,  # Choose function name or None
    # Clustering:
    'network_clustering_kmeans': 50,  # False or the value k for clustering
    'load_cluster': False,  # False or predefined busmap for k-means
    'network_clustering_ehv': False,  # clustering of HV buses to EHV buses.
    'disaggregation': None, # or None, 'mini' or 'uniform'
    'snapshot_clustering': False,  # False or the number of 'periods'
    # Simplifications:
    'parallelisation': False,  # run snapshots parallely.
    'skip_snapshots': False,
    'line_grouping': False,  # group lines parallel lines
    'branch_capacity_factor': {'HV': 0.5, 'eHV' : 0.7},  # factors to change branch capacities
    'load_shedding': False, # meet the demand at very high cost
    'foreign_lines' : {'carrier': 'AC', 'capacity': 'osmTGmod'}, # dict containing carrier and capacity settings of foreign lines
    'comments': None}

Starten der Rechnung

In [9]:
network, disagg_network = etrago(args_gs)
No data for StoragePqSet in column p_set.
Series p_set of component StorageUnit could not be imported
start k-mean clustering
Inertia of k-means =  5985.797310710579
INFO:pypsa.pf:Slack bus for sub-network 0 is 0
INFO:pypsa.opf:Performed preliminary steps
INFO:pypsa.opf:Building pyomo model using `angles` formulation
INFO:pypsa.opf:Solving model using gurobi
INFO:pypsa.opf:Optimization successful
INFO:pypsa.io:Exported network results has lines, generators, links, storage_units, carriers, buses, loads
Time for LOPF [min]: 1.01
Investment costs for all storage units in selected snapshots [EUR]: 826715.57
Investment costs for all lines and transformers in selected snapshots [EUR]: 339075.76
In [10]:
# Netzausbau je Leitung relativ zur ursprünglich installierten Leistung
# maximal-möglicher Leitungsausbau je Leitung beträgt vier Mal der ursprünglich installierten Leistung

network_expansion(network, ext_width=80)
/home/ulf/venv/lib/python3.5/site-packages/matplotlib/colorbar.py:890: RuntimeWarning: invalid value encountered in true_divide
  z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db
In [11]:
# Speicherausbau je Technologie und Knoten

storage_expansion(network, scaling=100)

Bewertung von NEP Maßnahmen

Fragestellung

Wie werden die Maßnahmen des NEP 2035 B2 in eTraGo bewertet?

Daraus resultierende Einstellungen

  • Auswahl von Szenario NEP 2035
  • geplante Leitungen nach dem NEP 2035 B2 hinzufügen
  • Rückbau aus dem Bestandsnetz nach dem NEP 2035 B2
  • technisch-wirtschaftliche Optimierung der geplanten Leitungen
In [15]:
args_nep = {
    # Setup and Configuration:
    'db': 'oedb',  # database session
    'gridversion': None,  # None for model_draft or Version number
    'method': 'lopf',  # lopf or pf
    'pf_post_lopf': False,  # perform a pf after a lopf simulation
    'start_snapshot': 48,
    'end_snapshot': 72,
    'solver': 'gurobi',  # glpk, cplex or gurobi
    'solver_options': {'BarConvTol': 1.e-5, 'FeasibilityTol': 1.e-5,
                       'method':2, 'crossover':0,
                       'logFile': 'solver.log'},  # {} for default options
    'scn_name': 'NEP 2035',  # a scenario: Status Quo, NEP 2035, eGo 100
    # Scenario variations:
    'scn_extension': ['nep2035_b2', 'BE_NO_NEP 2035'],  # None or array of extension scenarios
    'scn_decommissioning': 'nep2035_b2',  # None or decommissioning scenario   
    # Export options:
    'lpfile': False,  # save pyomo's lp file: False or /path/tofolder
    'csv_export': False,  # save results as csv: False or /path/tofolder
    'db_export': False,  # export the results back to the oedb
    # Settings:
    'extendable': ['overlay_network'],  # Array of components to optimize
    'generator_noise': 789456,  # apply generator noise, False or seed number
    'minimize_loading': False,
    'ramp_limits': False,  # Choose if using ramp limit of generators
    'extra_functionality': None,  # Choose function name or None
    # Clustering:
    'network_clustering_kmeans': 500,  # False or the value k for clustering
    'load_cluster': 'load_cluster_nep_ext_500',  # False or predefined busmap for k-means
    'network_clustering_ehv': False,  # clustering of HV buses to EHV buses.
    'disaggregation': None,  # None, 'mini' or 'uniform'
    'snapshot_clustering': False,  # False or the number of 'periods'
    # Simplifications:
    'parallelisation': False,  # run snapshots parallely.
    'skip_snapshots': False,
    'line_grouping': False,  # group lines parallel lines
    '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
    'foreign_lines': {'carrier': 'AC', 'capacity': 'osmTGmod'},
    'comments': None}

Ausführen der Berechnung

In [16]:
# Start eTraGo calculation with args setting
# create network object which incluedes all input and output data
network, disagg_network = etrago(args_nep)
No data for StoragePqSet in column p_set.
Series p_set of component StorageUnit could not be imported
No data for GeneratorPqSet in column p_set.
Series p_set of component Generator could not be imported
No data for GeneratorPqSet in column p_max_pu.
Series p_max_pu of component Generator could not be imported
No data for LoadPqSet in column p_set.
Series p_set of component Load could not be imported
No data for LoadPqSet in column q_set.
Series q_set of component Load could not be imported
No data for StoragePqSet in column p_set.
Series p_set of component StorageUnit could not be imported
ERROR:pypsa.io:Error, new components for Carrier are not unique
No data for StoragePqSet in column p_set.
Series p_set of component StorageUnit could not be imported
ERROR:pypsa.io:Error, new components for Carrier are not unique
start k-mean clustering
Inertia of k-means =  423.1414097481512
INFO:pypsa.pf:Slack bus for sub-network 0 is 0
INFO:pypsa.pf:Slack bus for sub-network 1 is 13
INFO:pypsa.pf:Slack bus for sub-network 2 is 4
INFO:pypsa.opf:Performed preliminary steps
INFO:pypsa.opf:Building pyomo model using `angles` formulation
INFO:pypsa.opf:Solving model using gurobi
INFO:pypsa.opf:Optimization successful
Time for LOPF [min]: 1.18
Investment costs for all lines and transformers in selected snapshots [EUR]: 2047.98

Berechnung des absoluten Netzausbaus

In [17]:
(network.lines.s_nom_opt - network.lines.s_nom_min)[network.lines.s_nom_extendable].sum()\
+ (network.links.p_nom_opt - network.links.p_nom_min)[network.links.p_nom_extendable].sum()
Out[17]:
9159.6612861311

Darstellung des Ausbaus der geplanten Leitungen

In [18]:
network_expansion(network, ext_min = 0)
In [ ]: