ego.tools package

ego.tools.economics

This module collects useful functions for economic calculation of eGo which can mainly distinguished in operational and investment costs.

ego.tools.economics.annuity_per_period(capex, n, wacc, t, p)[source]

Calculate per given period

Parameters:
  • capex (float) – Capital expenditure (NPV of investment)
  • n (int) – Number of years that the investment is used (economic lifetime)
  • wacc (float) – Weighted average cost of capital
  • t (int) – Timesteps in hours
  • p (float) – interest rate
ego.tools.economics.edisgo_convert_capital_costs(overnight_cost, t, p, json_file)[source]

Get scenario and calculation specific annuity cost by given capital costs and lifetime.

Parameters:
  • json_file (:obj:dict) – Dictionary of the scenario_setting.json file
  • _start_snapshot (int) – Start point of calculation from scenario_setting.json file
  • _end_snapshot (int) – End point of calculation from scenario_setting.json file
  • _p (numeric) – interest rate of investment
  • _t (int) – lifetime of investment
Returns:

annuity_cost – Scenario and calculation specific annuity cost by given capital costs and lifetime

Return type:

numeric

Examples

PVA =   (1 / p) - (1 / (p*(1 + p)^t))

ego.tools.economics.etrago_convert_overnight_cost(annuity_cost, json_file, t=40, p=0.05)[source]

Get annuity cost of simulation and calculation total overnight_costs by given capital costs and lifetime.

Parameters:
  • json_file (:obj:dict) – Dictionary of the scenario_setting.json file
  • _start_snapshot (int) – Start point of calculation from scenario_setting.json file
  • _end_snapshot (int) – End point of calculation from scenario_setting.json file
  • _p (numeric) – interest rate of investment
  • _T (int) – lifetime of investment
Returns:

overnight_cost – Scenario and calculation total overnight_costs by given annuity capital costs and lifetime.

Return type:

numeric

Examples

PVA =   (1 / p) - (1 / (p*(1 + p)^t))

K_{ON} = K_a*PVA*((t/(period+1))

ego.tools.economics.etrago_operating_costs(network)[source]

Function to get all operating costs of eTraGo.

Parameters:network_etrago (etrago.tools.io.NetworkScenario) – eTraGo network object compiled by etrago.appl.etrago()
Returns:operating_costs – DataFrame with aggregate operational costs per component and voltage level in [EUR] per calculated time steps.
Return type:pandas.Dataframe

Example

>>> from ego.tools.io import eGo
>>> ego = eGo(jsonpath='scenario_setting.json')
>>> ego.etrago.operating_costs
component operation_costs voltage_level
biomass 27.0 ehv
line losses 0.0 ehv
wind_onshore 0.0 ehv
ego.tools.economics.etrago_grid_investment(network, json_file, session)[source]

Function to get grid expantion costs from eTraGo

Parameters:
  • network_etrago (etrago.tools.io.NetworkScenario) – eTraGo network object compiled by etrago.appl.etrago()
  • json_file (:obj:dict) – Dictionary of the scenario_setting.json file
Returns:

grid_investment_costs – Dataframe with voltage_level, number_of_expansion and capital_cost per calculated time steps

Return type:

pandas.Dataframe

Example

>>> from ego.tools.io import eGo
>>> ego = eGo(jsonpath='scenario_setting.json')
>>> ego.etrago.grid_investment_costs
differentiation voltage_level number_of_expansion capital_cost
cross-border ehv 27.0 31514.1305
domestic hv 0.0 0.0
ego.tools.economics.edisgo_grid_investment(edisgo, json_file)[source]

Function aggregates all costs, based on all calculated eDisGo grids and their weightings :param edisgo: Contains multiple eDisGo networks :type edisgo: ego.tools.edisgo_integration.EDisGoNetworks

Returns:Dataframe containing annuity costs per voltage level
Return type:None or pandas.DataFrame
ego.tools.economics.get_generator_investment(network, scn_name)[source]

Get investment costs per carrier/ generator.

ego.tools.edisgo_integration

This file is part of the the eGo toolbox. It contains the class definition for multiple eDisGo networks.

class ego.tools.edisgo_integration.EDisGoNetworks(json_file, etrago_network)[source]

Bases: object

Performs multiple eDisGo runs and stores the resulting edisgo_grids

Parameters:
  • json_file (:obj:dict) – Dictionary of the scenario_setting.json file
  • etrago_network (etrago.tools.io.NetworkScenario) – eTraGo network object compiled by etrago.appl.etrago()
network

Container for eDisGo grids, including all results

Returns:Dictionary of eDisGo objects, keyed by MV grid ID
Return type:dict of edisgo.grid.network.EDisGo
grid_choice

Container for the choice of MV grids, including their weighting

Returns:Dataframe containing the chosen grids and their weightings
Return type:pandas.DataFrame
successfull_grids

Relative number of successfully calculated MV grids (Includes clustering weighting)

Returns:Relative number of grids
Return type:int
grid_investment_costs

Grid investment costs

Returns:Dataframe containing annuity costs per voltage level
Return type:None or pandas.DataFrame
get_mv_grid_from_bus_id(bus_id)[source]

Queries the MV grid ID for a given eTraGo bus

Parameters:bus_id (int) – eTraGo bus ID
Returns:MV grid (ding0) ID
Return type:int
get_bus_id_from_mv_grid(subst_id)[source]

Queries the eTraGo bus ID for given MV grid (ding0) ID

Parameters:subst_id (int) – MV grid (ding0) ID
Returns:eTraGo bus ID
Return type:int
plot_storage_integration(mv_grid_id, **kwargs)[source]

Plots storage position in MV grid of integrated storages. For more information see edisgo.tools.plots.mv_grid_topology().

plot_grid_expansion_costs(mv_grid_id, **kwargs)[source]

Plots costs per MV line. For more information see edisgo.tools.plots.mv_grid_topology().

plot_line_loading(mv_grid_id, **kwargs)[source]

Plots relative line loading (current from power flow analysis to allowed current) of MV lines. For more information see edisgo.tools.plots.mv_grid_topology().

plot_mv_grid_topology(mv_grid_id, **kwargs)[source]

Plots plain MV grid topology. For more information see edisgo.tools.plots.mv_grid_topology().

ego.tools.edisgo_integration.parallelizer(ding0_id_list, func, func_arguments, max_calc_time, workers=4, worker_lifetime=1)[source]

Use python multiprocessing toolbox for parallelization

Several grids are analyzed in parallel based on your custom function that defines the specific application of eDisGo.

Parameters:
  • ding0_id_list (list of int) – List of ding0 grid data IDs (also known as HV/MV substation IDs)
  • func (any function) – Your custom function that shall be parallelized
  • func_arguments (tuple) – Arguments to custom function func
  • workers (int) – Number of parallel process
  • worker_lifetime (int) – Bunch of grids sequentially analyzed by a worker

Notes

Please note, the following requirements for the custom function which is to be executed in parallel

  1. It must return an instance of the type EDisGo.
  2. The first positional argument is the MV grid district id (as int). It is prepended to the tuple of arguments func_arguments
Returns:containers – Dict of EDisGo instances keyed by its ID
Return type:dict of EDisGo

ego.tools.io

This file contains the eGo main class as well as input & output functions of eGo in order to build the eGo application container.

class ego.tools.io.egoBasic(*args, **kwargs)[source]

Bases: object

The eGo basic class select and creates based on your scenario_setting.json file your definded eTraGo and eDisGo results container. And contains the session for the database connection.

Parameters:jsonpath (json) – Path to scenario_setting.json file.
Returns:
class ego.tools.io.eTraGoResults(*args, **kwargs)[source]

Bases: ego.tools.io.egoBasic

The eTraGoResults class creates and contains all results of eTraGo and it’s network container for eGo.

Returns:
class ego.tools.io.eDisGoResults(*args, **kwargs)[source]

Bases: ego.tools.io.eTraGoResults

The eDisGoResults class create and contains all results of eDisGo and its network containers.

edisgo

Contains basic informations about eDisGo

Returns:
Return type:pandas.DataFrame
class ego.tools.io.eGo(jsonpath, *args, **kwargs)[source]

Bases: ego.tools.io.eDisGoResults

Main eGo module which includs all results and main functionalities.

Returns:
total_investment_costs

Contains all investment informations about eGo

Returns:
Return type:pandas.DataFrame
total_operation_costs

Contains all operation costs information about eGo

Returns:
Return type:pandas.DataFrame
plot_total_investment_costs(filename=None, display=False, **kwargs)[source]

Plot total investment costs

plot_power_price(filename=None, display=False)[source]

Plot power prices per carrier of calculation

plot_storage_usage(filename=None, display=False)[source]

Plot storage usage by charge and discharge

plot_edisgo_cluster(filename=None, display=False, **kwargs)[source]

Plot the Clustering of selected Dingo networks

plot_line_expansion(**kwargs)[source]

Plot line expantion per line

plot_storage_expansion(**kwargs)[source]

Plot storage expantion per bus

iplot

Get iplot of results as html

ego.tools.io.results_to_excel(ego)[source]

Wirte results of ego.total_investment_costs to an excel file

ego.tools.io.etrago_from_oedb(session, json_file)[source]

Function which import eTraGo results for the Database by the result_id number.

Parameters:
Returns:

network_etrago – eTraGo network object compiled by etrago.appl.etrago()

Return type:

etrago.tools.io.NetworkScenario

ego.tools.io.recover_resultsettings(session, json_file, orm_meta, result_id)[source]

Recover scenario_setting from database

ego.tools.mv_cluster

This file contains all functions regarding the clustering of MV grids

ego.tools.mv_cluster.analyze_attributes(ding0_files)[source]

Calculates the attributes wind and solar capacity and farthest node for all files in ding0_files. Results are written to ding0_files

Parameters:ding0_files (str) – Path to ding0 files
ego.tools.mv_cluster.cluster_mv_grids(no_grids, cluster_base)[source]

Clusters the MV grids based on the attributes, for a given number of MV grids

Parameters:
  • ding0_files (str) – Path to ding0 files
  • no_grids (int) – Desired number of clusters (of MV grids)
Returns:

Dataframe containing the clustered MV grids and their weightings

Return type:

pandas.DataFrame

ego.tools.plots

Module which collects useful functions for plotting eTraGo, eDisGo and eGo results.

ego.tools.plots.carriers_colore()[source]

Return matplotlib colore set per carrier (technologies of generators) of eTraGo.

Returns:colors – List of carriers and matplotlib colores
Return type:dict
ego.tools.plots.ego_colore()[source]

Get the four eGo colores

Returns:colors – List of eGo matplotlib hex colores
Return type:dict
ego.tools.plots.plot_storage_expansion(ego, filename=None, dpi=300, column='overnight_costs', scaling=1)[source]

Plot line expantion

Parameters:
  • ego (ego.tools.io.eGo) – eGo eGo inclueds eTraGo and eDisGo results
  • filename (str) – Filename and/or path of location to store graphic
  • dpi (int) – dpi value of graphic
  • column (str) – column name of eTraGo’s line costs. Default: overnight_costs in EURO. Also available s_nom_expansion in MVA or annualized investment_costs in EURO
  • scaling (numeric) – Factor to scale storage size of bus_sizes
Returns:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

Return type:

plot matplotlib.pyplot.show

ego.tools.plots.plot_line_expansion(ego, filename=None, dpi=300, column='overnight_costs')[source]

Plot line expantion

Parameters:
  • ego (ego.tools.io.eGo) – eGo eGo inclueds eTraGo and eDisGo results
  • filename (str) – Filename and or path of location to store graphic
  • dpi (int) – dpi value of graphic
  • column (str) – column name of eTraGo’s line costs. Default: overnight_costs in EUR. Also available s_nom_expansion in MVA or annualized investment_costs in EUR
Returns:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

Return type:

plot matplotlib.pyplot.show

ego.tools.plots.plot_grid_storage_investment(costs_df, filename, display, var=None)[source]

Plot total grid and storage investment.

Parameters:
  • costs_df (pandas.DataFrame) – Dataframe containing total_investment_costs of ego
  • filename (str) – Filename and or path of location to store graphic
  • display (bool) – Display plot
  • var (str) – Cost variable of overnight_cost by default displays annualized costs of timesteps
Returns:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

Return type:

plot matplotlib.pyplot.show

ego.tools.plots.power_price_plot(ego, filename, display)[source]

Plot power price of calculated scenario of timesteps and carrier

Parameters:
  • ego (ego.tools.io.eGo) – eGo eGo inclueds eTraGo and eDisGo results
  • filename (str) – Filename and or path of location to store graphic
  • display (bool) – Display plot
Returns:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

Return type:

plot matplotlib.pyplot.show

ego.tools.plots.plot_storage_use(ego, filename, display)[source]

Plot storage use by charge and discharge values

Parameters:
  • ego (ego.tools.io.eGo) – eGo eGo inclueds eTraGo and eDisGo results
  • filename (str) – Filename and or path of location to store graphic
  • display (bool) – Display plot
Returns:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

Return type:

plot matplotlib.pyplot.show

ego.tools.plots.get_country(session, region=None)[source]

Get Geometries of scenario Countries.

Parameters:
Returns:

country – GeoDataFrame inclueds MultiPolygon of selected regions or countries

Return type:

geopandas.GeoDataFrame

ego.tools.plots.prepareGD(session, subst_id=None, version=None)[source]

Get MV grid districts for plotting form oedb.

Parameters:
  • session (sqlalchemy.orm.session.Session) – SQLAlchemy session to the OEDB
  • subst_id (list) – List of integer ids of substation of the pf ehv/hv grid model_draft
  • version (str) – Name of data version saved in the OEDB
Returns:

region – GeoDataFrame inclueds MultiPolygon of selected MV grids

Return type:

geopandas.GeoDataFrame

ego.tools.plots.plot_edisgo_cluster(ego, filename, region=['DE'], display=False, dpi=150, add_ehv_storage=False, grid_choice=None, title='', cmap='jet')[source]

Plot the Clustering of selected Dingo networks

Parameters:
  • ego (ego.tools.io.eGo) – eGo eGo inclueds on eTraGo and eDisGo results
  • filename (str) – file name for plot e.g. cluster_plot.pdf
  • region (list) – List of background countries e.g. [‘DE’, ‘DK’]
  • display (bool) – True show plot false print plot as filename
  • add_ehv_storage (bool) – Display eTraGo ehv/hv storage distribution
  • grid_choice (str) – path to seperate mv/lv grid choice csv file
  • title (str) – Title of Plot
  • cmap (str) – Name of colormap from https://matplotlib.org/gallery/color/colormap_reference.html
Returns:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

Return type:

plot matplotlib.pyplot.show

ego.tools.plots.igeoplot(ego, tiles=None, geoloc=None, save_image=False)[source]

Plot function in order to display eGo results on leaflet OSM map. This function will open the results in your main web browser.

Parameters:
  • ego (ego.tools.io.eGo) – eGo eGo inclueds eTraGo and eDisGo results
  • tiles (str) – Folium background map style None as OSM or Nasa
  • geoloc (list) – List which define center of map as (lon, lat)
  • save_image (bool) – save iplot map as image
Returns:

plot – HTML file with .js plot

Return type:

html

ego.tools.plots.colormapper_lines(colormap, lines, line, column='s_nom')[source]

Make Colore Map for lines.

ego.tools.plots.iplot_griddistrict_legend(mp, repre_grids, start=False)[source]

Add legend to iplot function of mv grids.

ego.tools.plots.iplot_totalresults_legend(mp, ego, start=False)[source]

Add total results as legend to iplot function.

ego.tools.results

This module include the results functions for analyze and creating results based on eTraGo or eDisGo for eGo.

ego.tools.results.create_etrago_results(network, scn_name)[source]

Create eTraGo results

Parameters:
Returns:

generator – Result of generator as DataFrame in ego.etrago.generator

Return type:

pandas.DataFrame

ego.tools.specs

This files contains all eGo interface functions

ego.tools.specs.get_etragospecs_direct(session, bus_id, etrago_network, scn_name, grid_version, pf_post_lopf, max_cos_phi_renewable)[source]

Reads eTraGo Results from Database and returns and returns the interface values as a dictionary of corresponding dataframes

Parameters:
Returns:

Dataframes used as eDisGo inputs

Return type:

dict of pandas.DataFrame

ego.tools.storages

This module contains functions for storage units.

ego.tools.storages.etrago_storages(network)[source]

Sum up the pysical storage values of the total scenario based on eTraGo results.

Parameters:network (etrago.tools.io.NetworkScenario) –

eTraGo NetworkScenario based on PyPSA Network. See also pypsa.network

Returns:results – Summarize and returns a DataFrame of the storage optimaziation.
Return type:pandas.DataFrame

Notes

The results dataframe incluedes following parameters:

charge : numeric
Quantity of charged energy in MWh over scenario time steps
discharge : numeric
Quantity of discharged energy in MWh over scenario time steps
count : int
Number of storage units
p_nom_o_sum: numeric
Sum of optimal installed power capacity
ego.tools.storages.etrago_storages_investment(network, json_file, session)[source]

Calculate storage investment costs of eTraGo

Parameters:network (etrago.tools.io.NetworkScenario) –

eTraGo NetworkScenario based on PyPSA Network. See also pypsa.network

Returns:storage_costs – Storage costs of selected snapshots in [EUR]
Return type:numeric

ego.tools.utilities

This module contains utility functions for the eGo application.

ego.tools.utilities.define_logging(name)[source]

Helps to log your modeling process with eGo and defines all settings.

Parameters:log_name (str) – Name of log file. Default: ego.log.
Returns:logger – Set up logger object of package logging
Return type:logging.basicConfig.
ego.tools.utilities.get_scenario_setting(jsonpath='scenario_setting.json')[source]

Get and open json file with scenaio settings of eGo. The settings incluede eGo, eTraGo and eDisGo specific settings of arguments and parameters for a reproducible calculation.

Parameters:json_file (str) – Default: scenario_setting.json Name of scenario setting json file
Returns:json_file – Dictionary of json file
Return type:dict
ego.tools.utilities.fix_leading_separator(csv_file, **kwargs)[source]

Takes the path to a csv-file. If the first line of this file has a leading separator in its header, this field is deleted. If this is done the second field of every row is removed, too.

ego.tools.utilities.get_time_steps(json_file)[source]

Get time step of calculation by scenario settings.

Parameters:json_file (dict) – Dictionary of the scenario_setting.json file
Returns:time_step – Number of timesteps of the calculation.
Return type:int
ego.tools.utilities.open_oedb_session(ego)[source]