etrago.analyze package

etrago.analyze.calc_results module

calc_results.py defines methods to calculate results of eTraGo

etrago.analyze.calc_results.calc_investment_cost(self)[source]

Function that calulates overall annualized investment costs.

Returns:

  • network_costs (float) – Investments in line expansion (AC+DC)

  • link_costs (float) – Investments in sectorcoupling link expansion

  • stor_costs (float) – Investments in storage and store expansion

etrago.analyze.calc_results.calc_marginal_cost(self)[source]

Function that caluclates and returns marginal costs, considering generation and link and storage dispatch costs

Returns:

marginal_cost – Annual marginal cost in EUR

Return type:

float

etrago.analyze.calc_results.german_network(self)[source]

Cut out all network components in Germany

Returns:

new_network – Network with all components in Germany

Return type:

pypsa.Network

etrago.analyze.calc_results.system_costs_germany(self)[source]

Calculte system costs for Germany

Returns:

  • marginal_cost (float) – Marginal costs for dispatch in Germany

  • invest_cost (float) – Annualized investment costs for components in Germany

  • import_costs (float) – Costs for energy imported to Germany minus costs for exports

etrago.analyze.calc_results.ac_export(self)[source]

Calculate electricity exports and imports over AC lines

Returns:

Electricity export (if negative: import) from Germany

Return type:

float

etrago.analyze.calc_results.ac_export_per_country(self)[source]

Calculate electricity exports and imports over AC lines per country

Returns:

Electricity export (if negative: import) from Germany in TWh

Return type:

float

etrago.analyze.calc_results.dc_export(self)[source]

Calculate electricity exports and imports over DC lines

Returns:

Electricity export (if negative: import) from Germany

Return type:

float

etrago.analyze.calc_results.dc_export_per_country(self)[source]

Calculate electricity exports and imports over DC lines per country

Returns:

Electricity export (if negative: import) from Germany in TWh

Return type:

float

etrago.analyze.calc_results.calc_etrago_results(self)[source]

Function that calculates main results of grid optimization and adds them to Etrago object.

Return type:

None.

etrago.analyze.calc_results.total_redispatch(network, only_de=True, plot=False)[source]

etrago.analyze.plot module

Plot.py defines functions necessary to plot results of eTraGo.

etrago.analyze.plot.set_epsg_network(network)[source]

Change EPSG from 4326 to 3857. Needed when using osm-background.

Parameters:

network (PyPSA network container) –

etrago.analyze.plot.plot_osm(x, y, zoom, alpha=0.4)[source]

Plots openstreetmap as background of network-plots

Parameters:
  • x (array of two floats) – Define x-axis boundaries (lat) of osm plot

  • y (array of two floats) – Define y-axis boundaries (long) of osm plot

  • zoom (int) – Define zoom of osm, higher values for higher resolution

  • alpha (float) – Sets osm-visibility, increase value if osm covers network-plot

etrago.analyze.plot.coloring()[source]

Return a dictionary with a color assign to each kind of carrier used in etrago.network. This is used for plotting porpuses.

Returns:

colors – Color for each kind of carrier.

Return type:

dict

etrago.analyze.plot.plot_line_loading_diff(networkA, networkB, timestep=0, osm=False)[source]

Plot difference in line loading between two networks (with and without switches) as color on lines

Positive values mean that line loading with switches is bigger than without Plot switches as small dots

Parameters:
  • networkA (PyPSA network container) – Holds topology of grid with switches including results from powerflow analysis

  • networkB (PyPSA network container) – Holds topology of grid without switches including results from powerflow analysis

  • filename (str) – Specify filename If not given, figure will be show directly

  • timestep (int) – timestep to show, default is 0

  • osm (bool or dict, e.g. {'x': [1,20], 'y': [47, 56], 'zoom' : 6}) –

    If not False, osm is set as background with the following settings as dict:

    • ’x’: array of two floats, x axis boundaries (lat)

    • ’y’: array of two floats, y axis boundaries (long)

    • ’zoom’ : resolution of osm

etrago.analyze.plot.network_expansion_diff(networkA, networkB, filename=None, boundaries=[], osm=False)[source]

Plot relative network expansion derivation of AC- and DC-lines.

Parameters:
  • networkA (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • networkB (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • filename (str or None) – Save figure in this direction

  • boundaries (array) – Set boundaries of heatmap axis

  • osm (bool or dict, e.g. {'x': [1,20], 'y': [47, 56], 'zoom' : 6}) –

    If not False, osm is set as background with the following settings as dict:

    • ’x’: array of two floats, x axis boundaries (lat)

    • ’y’: array of two floats, y axis boundaries (long)

    • ’zoom’ : resolution of osm

etrago.analyze.plot.plot_residual_load(network)[source]

Plots residual load summed of all exisiting buses.

Parameters:

network (PyPSA network containter) –

Return type:

Plot

etrago.analyze.plot.plot_stacked_gen(network, bus=None, resolution='GW', filename=None)[source]

Plot stacked sum of generation grouped by carrier type

Parameters:
  • network (PyPSA network container) –

  • bus (string) – Plot all generators at one specific bus. If none, sum is calulated for all buses

  • resolution (string) – Unit for y-axis. Can be either GW/MW/KW

Return type:

Plot

etrago.analyze.plot.plot_gen_diff(networkA, networkB, leave_out_carriers=['geothermal', 'oil', 'other_non_renewable', 'reservoir', 'waste'])[source]

Plot difference in generation between two networks grouped by carrier type

Parameters:
  • networkA (PyPSA network container with switches) –

  • networkB (PyPSA network container without switches) –

  • leave_out_carriers – list of carriers to leave out (default to all small carriers)

Return type:

Plot

etrago.analyze.plot.plot_voltage(network, boundaries=[], osm=False)[source]

Plot voltage at buses as hexbin

Parameters:
  • network (PyPSA network container) –

  • boundaries (list of 2 values, setting the lower and upper bound of colorbar) –

  • osm (bool or dict, e.g. {'x': [1,20], 'y': [47, 56], 'zoom' : 6}) –

    If not False, osm is set as background with the following settings as dict:

    • ’x’: array of two floats, x axis boundaries (lat)

    • ’y’: array of two floats, y axis boundaries (long)

    • ’zoom’ : resolution of osm

Return type:

Plot

etrago.analyze.plot.curtailment(network, carrier='solar', filename=None)[source]

Plot curtailment of selected carrier

Parameters:
  • network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • carrier (str) – Plot curtailemt of this carrier

  • filename (str or None) – Save figure in this direction

Return type:

Plot

etrago.analyze.plot.calc_dispatch_per_carrier(network, timesteps, dispatch_type='total')[source]

Function that calculates dispatch per carrier in given timesteps

Parameters:
  • network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • timesteps (array) – Timesteps considered in dispatch calculation

  • dispatch_type (str) – This parameter can receive 3 different options: total, ramp_up and ramp_down. The default is total, which plots the total energy supplied by carrier by the given timesteps.

Returns:

dist – dispatch per carrier

Return type:

pandas.Series

etrago.analyze.plot.calc_storage_expansion_per_bus(network, carriers=['battery', 'H2_overground', 'H2_underground', 'rural_heat_store', 'central_heat_store'])[source]

Function that calculates storage expansion per bus and technology

Parameters:

network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

Returns:

dist – storage expansion per bus and technology

Return type:

pandas.Series

etrago.analyze.plot.gen_dist_diff(networkA, networkB, techs=None, snapshot=0, n_cols=3, gen_size=0.2, filename=None, buscmap=<matplotlib.colors.LinearSegmentedColormap object>)[source]

Difference in generation distribution Green/Yellow/Red colors mean that the generation at a location is bigger with switches than without Blue colors mean that the generation at a location is smaller with switches than without

Parameters:
  • networkA (PyPSA network container) – Holds topology of grid with switches including results from powerflow analysis

  • networkB (PyPSA network container) – Holds topology of grid without switches including results from powerflow analysis

  • techs (dict) – type of technologies which shall be plotted

  • snapshot (int) – snapshot

  • n_cols (int) – number of columns of the plot

  • gen_size (num) – size of generation bubbles at the buses

  • filename (str) – Specify filename If not given, figure will be show directly

Return type:

None.

etrago.analyze.plot.nodal_gen_dispatch(network, networkB=None, techs=['wind_onshore', 'solar'], item='energy', direction=None, scaling=1, filename=None, osm=False)[source]

Plot nodal dispatch or capacity. If networkB is given, difference in dispatch is plotted.

Parameters:
  • network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • networkB (PyPSA network container) – If given and item is ‘energy’, difference in dispatch between network and networkB is plotted. If item is ‘capacity’, networkB is ignored. default None

  • techs (None or list,) – Techs to plot. If None, all techs are plotted. default [‘wind_onshore’, ‘solar’]

  • item (str) – Specifies the plotted item. Options are ‘energy’ and ‘capacity’. default ‘energy’

  • direction (str) – Only considered if networkB is given and item is ‘energy’. Specifies the direction of change in dispatch between network and networkB. If ‘positive’, generation per tech which is higher in network than in networkB is plotted. If ‘negative’, generation per tech whcih is lower in network than in networkB is plotted. If ‘absolute’, total change per node is plotted. Green nodes have higher dispatch in network than in networkB. Red nodes have lower dispatch in network than in networkB. default None

  • scaling (int) – Scaling to change plot sizes. default 1

  • filename (path to folder) –

  • osm (bool or dict, e.g. {'x': [1,20], 'y': [47, 56], 'zoom' : 6}) –

    If not False, osm is set as background with the following settings as dict:

    • ’x’: array of two floats, x axis boundaries (lat)

    • ’y’: array of two floats, y axis boundaries (long)

    • ’zoom’ : resolution of osm

Return type:

None.

etrago.analyze.plot.nodal_production_balance(network, timesteps, scaling=1e-05)[source]

Function that calculates residual load per node in given timesteps

Parameters:
  • network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • timesteps (array) – timesteps considered in calculation

  • scaling (float, optional) – Scaling factor for bus size. The default is 0.00001.

Returns:

  • bus_sizes (pandas.Series) – scaled residual load per node

  • bus_colors (pandas.Series) – ‘green’ for producer and ‘red’ for consumer

etrago.analyze.plot.storage_p_soc(network, mean='1H', filename=None)[source]

Plots the dispatch and state of charge (SOC) of extendable storages.

Parameters:
  • network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • mean (str) – Defines over how many snapshots the p and soc values will averaged.

  • filename (path to folder) –

Return type:

None.

etrago.analyze.plot.storage_soc_sorted(network, filename=None)[source]

Plots the soc (state-pf-charge) of extendable storages

Parameters:
  • network (PyPSA network container) – Holds topology of grid including results from powerflow analysis

  • filename (path to folder) –

Return type:

None.

etrago.analyze.plot.mul_weighting(network, timeseries)[source]

Returns timeseries considering snapshot_weighting

Parameters:
  • network (:class:`pypsa.Network) – Overall container of PyPSA

  • timeseries (pd.Series) – timeseries not considering snapshot_weighting

Returns:

timeseries considering snapshot_weightings

Return type:

pd.Series

etrago.analyze.plot.calc_ac_loading(network, timesteps)[source]

Calculates loading of AC-lines

Parameters:
  • network (:class:`pypsa.Network) – Overall container of PyPSA

  • timesteps (range) – Defines which timesteps are considered. If more than one, an average line loading is calculated.

Returns:

AC line loading in MVA

Return type:

pandas.Series

etrago.analyze.plot.calc_dc_loading(network, timesteps)[source]

Calculates loading of DC-lines

Parameters:
  • network (:class:`pypsa.Network) – Overall container of PyPSA

  • timesteps (range) – Defines which timesteps are considered. If more than one, an average line loading is calculated.

Returns:

DC line loading in MW

Return type:

pandas.Series

etrago.analyze.plot.plotting_colors(network)[source]

Add color values to network.carriers

Parameters:

network (:class:`pypsa.Network) – Overall container of PyPSA

Return type:

None.

etrago.analyze.plot.calc_network_expansion(network, method='abs', ext_min=0.1)[source]

Calculates absolute or relative expansion per AC- and DC-line

Parameters:
  • network (:class:`pypsa.Network) – Overall container of PyPSA

  • method (str, optional) – Choose ‘rel’ or ‘abs’. The default is ‘abs’.

  • ext_min (float, optional) – Remove lines extended less than this value. The default is 0.1.

Returns:

  • network (:class:`pypsa.Network) – Whole network including not extended lines

  • extension_lines (pandas.Series) – AC-line expansion

  • extension_links (pandas.Series) – DC-line expansion

etrago.analyze.plot.plot_background_grid(network, ax, geographical_boundaries, osm)[source]

Plots grid topology in background of other network.plot

Parameters:
  • network (:class:`pypsa.Network) – Overall container of PyPSA

  • ax (matplotlib.axes._subplots.AxesSubplot) – axes of plot

  • geographical_boundaries (list) – Set georaphical boundaries for the plots

  • osm (False or dict.) – False if not osm background map is required or dictionary with x, y and zoom information.

Return type:

None.

etrago.analyze.plot.demand_side_management(self, buses, snapshots, agg='5h', used=False, apply_on='grid_model')[source]

Calculate shifting potential of demand side management

Parameters:
  • buses (array) – List of electricity buses.

  • snapshots (array) – List of snapshots.

  • agg (str, optional) – Temporal resolution. The default is ‘5h’.

  • used (boolean, optional) – State if usage should be included in the results. The default is False.

  • apply_on (str, optional) – Choose which network is plotted. The available networks depend on your settings. The default is ‘grid_model’

Returns:

df – Shifting potential (and usage) of power (MW) and energy (MWh)

Return type:

pandas.DataFrame

etrago.analyze.plot.bev_flexibility_potential(self, buses, snapshots, agg='5h', used=False, apply_on='grid_model')[source]

Calculate shifting potential of electric vehicles

Parameters:
  • buses (array) – List of electricity buses.

  • snapshots (array) – List of snapshots.

  • agg (str, optional) – Temporal resolution. The default is ‘5h’.

  • used (boolean, optional) – State if usage should be included in the results. The default is False.

  • apply_on (str, optional) – Choose which network is plotted. The available networks depend on your settings. The default is ‘grid_model’

Returns:

df – Shifting potential (and usage) of power (MW) and energy (MWh)

Return type:

pandas.DataFrame

etrago.analyze.plot.heat_stores(self, buses, snapshots, agg='5h', used=False, apply_on='grid_model')[source]

Calculate shifting potential (and usage) of heat stores

Parameters:
  • buses (array) – List of electricity buses.

  • snapshots (array) – List of snapshots.

  • agg (str, optional) – Temporal resolution. The default is ‘5h’.

  • used (boolean, optional) – State if usage should be included in the results. The default is False.

  • apply_on (str, optional) – Choose which network is plotted. The available networks depend on your settings. The default is ‘grid_model’

Returns:

df – Shifting potential (and usage) of power (MW) and energy (MWh)

Return type:

pandas.DataFrame

etrago.analyze.plot.hydrogen_stores(self, buses, snapshots, agg='5h', used=False, apply_on='grid_model')[source]

Calculate shifting potential (and usage) of heat stores

Parameters:
  • buses (array) – List of electricity buses.

  • snapshots (array) – List of snapshots.

  • agg (str, optional) – Temporal resolution. The default is ‘5h’.

  • used (boolean, optional) – State if usage should be included in the results. The default is False.

  • apply_on (str, optional) – Choose which network is plotted. The available networks depend on your settings. The default is ‘grid_model’

Returns:

df – Shifting potential (and usage) of power (MW) and energy (MWh)

Return type:

pandas.DataFrame

etrago.analyze.plot.flexibility_usage(self, flexibility, agg='5h', snapshots=[], buses=[], pre_path=None, apply_on='grid_model')[source]

Plots temporal distribution of potential and usage for flexibilities

Parameters:
  • flexibility (str) – Name of flexibility option.

  • agg (str, optional) – Temporal resolution. The default is “5h”.

  • snapshots (list, optional) – Considered snapshots, if empty all are considered. The default is [].

  • buses (list, optional) – Considered components at AC buses, if empty all are considered. The default is [].

  • pre_path (str, optional) – State of and where you want to store the figure. The default is None.

  • apply_on (str, optional) – Choose which network is plotted. The available networks depend on your settings. The default is ‘grid_model’

Return type:

None.

etrago.analyze.plot.plot_carrier(etrago, carrier_links=['AC'], carrier_buses=['AC'], apply_on='grid_model')[source]
Parameters:
  • network (:class:`pypsa.Network) – Overall container of PyPSA

  • carrier_links (list) – List of links to be plotted. The default is [“AC”].

  • carrier_buses (list) – List of buses to be plotted. The default is [“AC”].

  • cartopy (bool, optional) – Provide data about the availability of Cartopy. The default is True.

Return type:

None.

etrago.analyze.plot.plot_grid(self, line_colors, bus_sizes=0.001, bus_colors='grey', timesteps=range(0, 2), osm=False, boundaries=None, filename=None, apply_on='grid_model', ext_min=0.1, ext_width=False, legend_entries='all', scaling_store_expansion=False, geographical_boundaries=[-2.5, 16, 46.8, 58])[source]

Function that plots etrago.network and results for lines and buses

Parameters:
  • line_colors (str) –

    Set static line color or attribute to plot e.g. ‘expansion_abs’ Current options:

    • ’line_loading’: mean line loading in p.u. in selected timesteps

    • ’v_nom’: nominal voltage of lines

    • ’expansion_abs’: absolute network expansion in MVA

    • ’expansion_rel’: network expansion in p.u. of existing capacity

    • ’q_flow_max’: maximal reactive flows

    • ’dlr’: energy above nominal capacity

    • ’grey’: plot all lines and DC links grey colored

  • bus_sizes (float, optional) – Size of buses. The default is 0.001.

  • bus_colors (str, optional) –

    Set static bus color or attribute to plot. The default is ‘grey’. Current options:

    • ’nodal_production_balance’: net producer/consumer in selected

      time steps

    • ’storage_expansion’: storage expansion per bus and technology

    • ’storage_distribution’: installed storage units per bus

    • ’h2_battery_storage_expansion’: storage expansion per bus and

      technology for underground and overground H2 and batteries.

    • ’gen_dist’: dispatch per carrier in selected timesteps

    • ’ramp_up’: re-dispatch up per carrier in selected timesteps

    • ’ramp_down’: re-dispatch down per carrier in selected timesteps

    • ’PowerToH2’: location and sizes of electrolyzers

    • ’flexibility_usage’: use of DSM and BEV charger

    • ’PowerToH2_correlation’: indication of degree of correlation to

    market or nodal price of electrolyzers

  • timesteps (array, optional) – Timesteps consideredd in time depended plots. The default is range(2).

  • osm (bool or dict, e.g. {'x': [1,20], 'y': [47, 56], 'zoom' : 6}) –

    If not False, osm is set as background with the following settings as dict:

    • ’x’: array of two floats, x axis boundaries (lat)

    • ’y’: array of two floats, y axis boundaries (long)

    • ’zoom’ : resolution of osm. The default is False.

  • boundaries (array) – Set fixed boundaries of heatmap axis. The default is None.

  • filename (str or None) – Save figure in this direction. The default is None.

  • apply_on (str, optional) – Choose which network is plotted. The available networks depend on your settings. The default is ‘grid_model’

  • ext_min (float) – Choose minimum relative line extension shown in plot in p.u..

  • ext_width (float or bool) – Choose if line_width respects line extension. Turn off with ‘False’ or set linear factor to decremise extension line_width. The default is False.

  • legend_entries (list, optional) – Set the legends for buses to be plotted. The default is ‘all’.

  • scaling_store_expansion (dict, optional) – Set scaling values to be used per technology for the plots storage_expansion and h2_battery_storage_expansion. The default is False, it could be assinged like this: {“H2”: 50, “heat”: 0.1, “battery”: 10}

  • geographical_boundaries (list, optional) – Set georaphical boundaries for the plots. This parameter is overwritten when osm is used. The default is [-2.5, 16, 46.8, 58]

Return type:

None.

etrago.analyze.plot.make_handler_map_to_scale_circles_as_in(ax, dont_resize_actively=False)[source]
etrago.analyze.plot.make_legend_circles_for(sizes, scale=1.0, **kw)[source]
etrago.analyze.plot.plot_clusters(self, carrier='AC', save_path=False, transmission_lines=False, gas_pipelines=False)[source]
Parameters:
  • carrier (str, optional) – This variable set the carrier of the buses that will be plotted. The default is “AC”.

  • cartopy (bool, optional) – Set it to True when cartopy is installed and the map is supposed to include country’s boundaries and bodies of water

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

  • transmission_lines (bool, optional) – The default is False. Define if the original transmission lines are plotted or not.

  • gas_pipelines (bool, optional) – The default is False. Define if the original gas pipelines are plotted or not.

Return type:

None.

etrago.analyze.plot.plot_gas_generation(self, t_resolution='20H', save_path=False)[source]

Plots timeseries data for gas generation

Parameters:
  • self (:class:`Etrago) – Overall container of Etrago

  • t_resolution (str, optional) – sets the resampling rate of timeseries data to allow for smoother line plots

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

Return type:

None.

etrago.analyze.plot.plot_gas_summary(self, t_resolution='20H', stacked=True, save_path=False)[source]

Plots timeseries data for gas loads (and generation)

Parameters:
  • self (:class:`Etrago) – Overall container of Etrago

  • t_resolution (str, optional) – sets the resampling rate of timeseries data to allow for smoother line plots

  • stacked (bool, optional) – If True all TS data will be shown as stacked area plot. Total gas generation will then also be plotted to check for matching demand and generation.

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

Return type:

None.

etrago.analyze.plot.plot_h2_generation(self, t_resolution='20H', save_path=False)[source]

Plots timeseries data for H2 generation

Parameters:
  • self (:class:`Etrago) – Overall container of Etrago

  • t_resolution (str, optional) – sets the resampling rate of timeseries data to allow for smoother line plots

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

Return type:

None.

etrago.analyze.plot.plot_h2_summary(self, t_resolution='20H', stacked=True, save_path=False)[source]

Plots timeseries data for H2 loads (and generation)

Parameters:
  • self (:class:`Etrago) – Overall container of Etrago

  • t_resolution (str, optional) – sets the resampling rate of timeseries data to allow for smoother line plots

  • stacked (bool, optional) – If True all TS data will be shown as stacked area plot. Total H2 generation will then also be plotted to check for matching demand and generation.

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

Return type:

None.

etrago.analyze.plot.plot_heat_loads(self, t_resolution='20H', save_path=False)[source]

Plots timeseries data for heat loads

Parameters:
  • self (:class:`Etrago) – Overall container of Etrago

  • t_resolution (str, optional) – sets the resampling rate of timeseries data to allow for smoother line plots

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

Return type:

None.

etrago.analyze.plot.plot_heat_summary(self, t_resolution='20H', stacked=True, save_path=False)[source]

Plots timeseries data for heat generation (and demand)

Parameters:
  • self (:class:`Etrago) – Overall container of Etrago

  • t_resolution (str, optional) – sets the resampling rate of timeseries data to allow for smoother line plots

  • stacked (bool, optional) – If True all TS data will be shown as stacked area plot. Total heat demand will then also be plotted to check for matching generation and demand.

  • save_path (bool, optional) – Path to save the generated plot. The default is False.

Return type:

None.

etrago.analyze.plot.shifted_energy(self, carrier, buses)[source]

Calulate shifted energy for a specific carrier

Parameters:
  • carrier (str) – Name of energy carrier

  • buses (list) – List of considered bus indices

Returns:

shifted – Shifted energy per time step

Return type:

pandas.Series

etrago.analyze.plot.flexibility_duration_curve(etrago, etrago_lowflex, filename=None)[source]

Plot duration curves of flexibility options

Parameters:
  • etrago (Etrago) – Object including network with flexibility options

  • etrago_lowflex (Etrago) – Object including network with less flexibility options

  • filename (str, optional) – Name of file to save plot. The default is None.

Return type:

None.