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:
-
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.jsonfile - _start_snapshot (int) – Start point of calculation from
scenario_setting.jsonfile - _end_snapshot (int) – End point of calculation from
scenario_setting.jsonfile - _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

- json_file (:obj:dict) – Dictionary of the
-
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_costsby given capital costs and lifetime.Parameters: - json_file (:obj:dict) – Dictionary of the
scenario_setting.jsonfile - _start_snapshot (int) – Start point of calculation from
scenario_setting.jsonfile - _end_snapshot (int) – End point of calculation from
scenario_setting.jsonfile - _p (numeric) – interest rate of investment
- _T (int) – lifetime of investment
Returns: overnight_cost – Scenario and calculation total
overnight_costsby given annuity capital costs and lifetime.Return type: numeric
Examples

- json_file (:obj:dict) – Dictionary of the
-
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 byetrago.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 byetrago.appl.etrago() - json_file (:obj:dict) – Dictionary of the
scenario_setting.jsonfile
Returns: grid_investment_costs – Dataframe with
voltage_level,number_of_expansionandcapital_costper calculated time stepsReturn type: 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 - network_etrago (
-
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.EDisGoNetworksReturns: Dataframe containing annuity costs per voltage level Return type: None or pandas.DataFrame
ego.tools.edisgo_integration¶
This file is part of the eGo toolbox. It contains the class definition for multiple eDisGo networks.
-
class
ego.tools.edisgo_integration.EDisGoNetworks(json_file, etrago_network)[source]¶ Bases:
objectPerforms multiple eDisGo runs and stores the resulting edisgo_grids
Parameters: - json_file (:obj:dict) – Dictionary of the
scenario_setting.jsonfile - etrago_network (
etrago.tools.io.NetworkScenario) – eTraGo network object compiled byetrago.appl.etrago()
-
network¶ Container for EDisGo objects, including all results
Returns: Dictionary of EDisGo objects, keyed by MV grid ID Return type: dict[int, edisgo.EDisGo]
-
grid_choice¶ Container for the choice of MV grids, including their weighting
Returns: Dataframe containing the chosen grids and their weightings ‘no_of_points_per_cluster’, ‘the_selected_network_id’, ‘represented_grids’ Return type: pandas.DataFrame
-
successful_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
-
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().
- json_file (:obj:dict) – Dictionary of the
-
ego.tools.edisgo_integration.parallelizer(ding0_id_list, func, func_arguments, max_calc_time, workers=2, 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
- It must return an instance of the type
EDisGo. - 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:
objectThe eGo basic class select and creates based on your
scenario_setting.jsonfile your definded eTraGo and eDisGo results container. And contains the session for the database connection.Parameters: jsonpath ( json) – Path toscenario_setting.jsonfile.Returns: - json_file (:obj:dict) – Dictionary of the
scenario_setting.jsonfile - session (sqlalchemy.orm.session.Session) – SQLAlchemy session to the OEDB
- json_file (:obj:dict) – Dictionary of the
-
class
ego.tools.io.eTraGoResults(*args, **kwargs)[source]¶ Bases:
ego.tools.io.egoBasicThe
eTraGoResultsclass creates and contains all results of eTraGo and it’s network container for eGo.Returns: - network_etrago (
etrago.tools.io.NetworkScenario) – eTraGo network object compiled byetrago.appl.etrago() - etrago (pandas.Dataframe) – DataFrame which collects several eTraGo results
- network_etrago (
-
class
ego.tools.io.eDisGoResults(*args, **kwargs)[source]¶ Bases:
ego.tools.io.eTraGoResultsThe
eDisGoResultsclass 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.eDisGoResultsMain eGo module which includs all results and main functionalities.
Returns: - network_etrago (
etrago.tools.io.NetworkScenario) – eTraGo network object compiled byetrago.appl.etrago() - edisgo.network (
ego.tools.edisgo_integration.EDisGoNetworks) – Contains multiple eDisGo networks - edisgo (pandas.Dataframe) – aggregated results of eDisGo
- etrago (pandas.Dataframe) – aggregated results of eTraGo
-
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
-
iplot¶ Get iplot of results as html
- network_etrago (
-
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_idnumber.Parameters: - session (sqlalchemy.orm.session.Session) – SQLAlchemy session to the OEDB
- json_file (
dict) – Dictionary of thescenario_setting.jsonfile
Returns: network_etrago – eTraGo network object compiled by
etrago.appl.etrago()Return type: etrago.tools.io.NetworkScenario
ego.tools.mv_cluster¶
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) – eGoeGoinclueds 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_costsin EURO. Also availables_nom_expansionin MVA or annualizedinvestment_costsin 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 (
-
ego.tools.plots.plot_line_expansion(ego, filename=None, dpi=300, column='overnight_costs')[source]¶ Plot line expantion
Parameters: - ego (
ego.tools.io.eGo) – eGoeGoinclueds 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_costsin EUR. Also availables_nom_expansionin MVA or annualizedinvestment_costsin EUR
Returns: https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show
Return type: plot
matplotlib.pyplot.show- ego (
-
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_costby 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) – eGoeGoinclueds 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 (
-
ego.tools.plots.plot_storage_use(ego, filename, display)[source]¶ Plot storage use by charge and discharge values
Parameters: - ego (
ego.tools.io.eGo) – eGoeGoinclueds 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 (
-
ego.tools.plots.get_country(session, region=None)[source]¶ Get Geometries of scenario Countries.
Parameters: - session (sqlalchemy.orm.session.Session) – SQLAlchemy session to the OEDB
- region (list) – List of background countries e.g. [‘DE’, ‘DK’]
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', labelsize=10, fontsize=10)[source]¶ Plot the Clustering of selected Dingo networks
Parameters: - ego (
ego.tools.io.eGo) – eGoeGoinclueds 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 (
-
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) – eGoeGoinclueds 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 (
-
ego.tools.plots.colormapper_lines(colormap, lines, line, column='s_nom')[source]¶ Make Colore Map for lines.
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: - network (
NetworkScenario) – eTraGoNetworkScenariobased on PyPSA Network. See also pypsa.network - scn_name (str) – Name of used scenario
Returns: generator – Result of generator as DataFrame in
ego.etrago.generatorReturn type: - network (
ego.tools.specs¶
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
NetworkScenariobased on PyPSA Network. See also pypsa.networkReturns: results – Summarize and returns a DataFrameof the storage optimaziation.Return type: pandas.DataFrame Notes
The
resultsdataframe 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
NetworkScenariobased on PyPSA Network. See also pypsa.networkReturns: 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 loggerobject of packageloggingReturn type: logging.basicConfig.
-
ego.tools.utilities.get_scenario_setting(jsonpath=None)[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.jsonName of scenario setting json fileReturns: 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.