etrago.tools package¶
etrago.tools.calc_results module¶
calc_results.py defines methods to calculate results of eTraGo
- etrago.tools.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.tools.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:
- etrago.tools.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.tools.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.tools.calc_results.ac_export(self)[source]¶
Calculate electricity exports and imports over AC lines
- Returns:
Electricity export (if negative: import) from Germany
- Return type:
- etrago.tools.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:
- etrago.tools.calc_results.dc_export(self)[source]¶
Calculate electricity exports and imports over DC lines
- Returns:
Electricity export (if negative: import) from Germany
- Return type:
etrago.tools.constraints module¶
etrago.tools.execute module¶
etrago.tools.extendable module¶
Extendable.py defines function to set PyPSA components extendable.
- etrago.tools.extendable.extendable(self, grid_max_D=None, grid_max_abs_D={'110': {'circuits': 2, 'i': 1020, 'wires': 4}, '220': {'circuits': 4, 'i': 1020, 'wires': 4}, '380': {'circuits': 4, 'i': 1020, 'wires': 4}, 'dc': 0}, grid_max_foreign=4, grid_max_abs_foreign=None)[source]¶
Function that sets selected components extendable.
- Parameters:
grid_max_D (int, optional) – Upper bounds for electrical grid expansion relative to existing capacity. The default is None.
grid_max_abs_D (dict, optional) – Absolute upper bounds for electrical grid expansion in Germany.
grid_max_foreign (int, optional) – Upper bounds for expansion of electrical foreign lines relative to the existing capacity. The default is 4.
grid_max_abs_foreign (dict, optional) – Absolute upper bounds for expansion of foreign electrical grid. The default is None.
- Return type:
None.
- etrago.tools.extendable.snommax(i=1020, u=380, wires=4, circuits=4)[source]¶
Function to calculate limitation for capacity expansion.
- Parameters:
- Returns:
s_nom_max – Limitation for capacity expansion.
- Return type:
- etrago.tools.extendable.line_max_abs(network, buses, line_max_abs={'110': {'circuits': 2, 'i': 1020, 'wires': 4}, '220': {'circuits': 4, 'i': 1020, 'wires': 4}, '380': {'circuits': 4, 'i': 1020, 'wires': 4}, 'dc': 0})[source]¶
Function to calculate limitation for capacity expansion of lines in network.
- Parameters:
network (pypsa.Network object) – Container for all network components.
buses (pypsa.Network buses) – Considered buses in network.
line_max_abs (dict, optional) – Line parameters considered to calculate maximum capacity.
- Return type:
None.
- etrago.tools.extendable.transformer_max_abs(network, buses)[source]¶
Function to calculate limitation for capacity expansion of transformers in network.
- Parameters:
network (pypsa.Network object) – Container for all network components.
buses (pypsa.Network buses) – Considered buses in network.
- Return type:
None.
- etrago.tools.extendable.extension_preselection(etrago, method, days=3)[source]¶
Function that preselects lines which are extendend in snapshots leading to overloading to reduce nubmer of extension variables.
- Parameters:
network (pypsa.Network object) – Container for all network components.
args (dict) – Arguments set in appl.py.
method (str) – Choose method of selection: ‘extreme_situations’ for remarkable timsteps (e.g. minimal resiudual load) ‘snapshot_clustering’ for snapshot clustering with number of days
days (int) – Number of clustered days, only used when method = ‘snapshot_clustering’
- Returns:
network – Container for all network components.
- Return type:
pypsa.Network object
etrago.tools.io module¶
io.py
Input/output operations between powerflow schema in the oedb and PyPSA. Additionally oedb wrapper classes to instantiate PyPSA network objects.
- etrago.tools.io.carr_ormclass¶
Orm class name of table with carrier id to carrier name datasets
- Type:
Notes
A configuration file connecting the chosen optimization method with components to be queried is needed for NetworkScenario class.
- class etrago.tools.io.ScenarioBase(engine, session, version=None)[source]¶
Bases:
object
Base class to address the dynamic provision of orm classes representing powerflow components from egoio
- Parameters:
session (sqla.orm.session.Session) – Handles conversations with the database.
version (str) – Version number of data version control in grid schema of the oedb.
- class etrago.tools.io.NetworkScenario(engine, session, scn_name='Status Quo', start_snapshot=1, end_snapshot=20, temp_id=1, **kwargs)[source]¶
Bases:
ScenarioBase
Adapter class between oedb powerflow data and PyPSA. Provides the method build_network to generate a pypsa.Network.
- Parameters:
Methods
build_network
([network])Core method to construct PyPSA Network object.
Construct a DateTimeIndex with the queried temporal resolution, start- and end_snapshot.
fetch_by_relname
(name)Construct DataFrame with component data from filtered table data.
series_fetch_by_relname
(network, name, ...)Construct DataFrame with component timeseries data from filtered table data.
id_to_source
- configure_timeindex()[source]¶
Construct a DateTimeIndex with the queried temporal resolution, start- and end_snapshot.
- fetch_by_relname(name)[source]¶
Construct DataFrame with component data from filtered table data.
- Parameters:
name (str) – Component name.
- Returns:
Component data.
- Return type:
pd.DataFrame
- etrago.tools.io.clear_results_db(session)[source]¶
Used to clear the result tables in the OEDB. Caution! This deletes EVERY RESULT SET!
- etrago.tools.io.results_to_oedb(session, network, args, grid='hv', safe_results=False)[source]¶
Return results obtained from PyPSA to oedb
- Parameters:
session –
network (PyPSA network container) – Holds topology of grid including results from powerflow analysis
args (dict) – Settings from appl.py
grid (str) – Choose voltage-level, currently only ‘hv’ implemented
safe_results (boolean) – If it is set to ‘True’ the result set will be saved to the versioned grid schema eventually apart from being saved to the model_draft by a SQL-script. ONLY set to True if you know what you are doing.
- etrago.tools.io.run_sql_script(conn, scriptname='results_md2grid.sql')[source]¶
This function runs .sql scripts in the folder ‘sql_scripts’
- etrago.tools.io.extension(self, **kwargs)[source]¶
Function that adds an additional network to the existing network container. The new network can include every PyPSA-component (e.g. buses, lines, links). To connect it to the existing network, transformers are needed.
All components and its timeseries of the additional scenario need to be inserted in the fitting ‘model_draft.ego_grid_pf_hv_extension_’ table. The scn_name in the tables have to be labled with ‘extension_’ + scn_name (e.g. ‘extension_nep2035’).
Until now, the tables include three additional scenarios: ‘nep2035_confirmed’: all new lines and needed transformers planed in the ‘Netzentwicklungsplan 2035’ (NEP2035) that have been confirmed by the Bundesnetzagentur (BNetzA)
‘nep2035_b2’: all new lines and needed transformers planned in the NEP 2035 in the scenario 2035 B2
‘BE_NO_NEP 2035’: DC-lines and transformers to connect the upcomming electrical-neighbours Belgium and Norway Generation, loads and its timeseries in Belgium and Norway for scenario ‘NEP 2035’
- Parameters:
network – The existing network container (e.g. scenario ‘NEP 2035’)
session – session-data
overlay_scn_name – Name of the additional scenario (WITHOUT ‘extension_’)
start_snapshot –
end_snapshot – Simulation time
- Return type:
Network container including existing and additional network
- etrago.tools.io.decommissioning(self, **kwargs)[source]¶
Function that removes components in a decommissioning-scenario from the existing network container. Currently, only lines can be decommissioned.
All components of the decommissioning scenario need to be inserted in the fitting ‘model_draft.ego_grid_pf_hv_extension_’ table. The scn_name in the tables have to be labled with ‘decommissioning_’ + scn_name (e.g. ‘decommissioning_nep2035’).
- Parameters:
network – The existing network container (e.g. scenario ‘NEP 2035’)
session – session-data
overlay_scn_name – Name of the decommissioning scenario
- Return type:
Network container including decommissioning
- etrago.tools.io.distance(x0, x1, y0, y1)[source]¶
Function that calculates the square of the distance between two points.
- Parameters:
x0 – x - coordinate of point 0
x1 – x - coordinate of point 1
y0 – y - coordinate of point 0
y1 – y - coordinate of point 1
- Returns:
distance – square of distance
- Return type:
etrago.tools.network module¶
etrago.tools.plot module¶
etrago.tools.utilities module¶
Utilities.py includes a wide range of useful functions.
- etrago.tools.utilities.filter_links_by_carrier(self, carrier, like=True)[source]¶
- Parameters:
- Returns:
df – Dataframe that contains just links with carriers of the types given in the argument carrier.
- Return type:
pandas.DataFrame object
- etrago.tools.utilities.buses_of_vlvl(network, voltage_level)[source]¶
Get bus-ids of given voltage level(s).
- etrago.tools.utilities.buses_grid_linked(network, voltage_level)[source]¶
Get bus-ids of a given voltage level connected to the grid.
- etrago.tools.utilities.geolocation_buses(self, apply_on='grid_model')[source]¶
If geopandas is installed: Use geometries of buses x/y(lon/lat) and polygons of countries from RenpassGisParameterRegion in order to locate the buses
Else: Use coordinats of buses to locate foreign buses, which is less accurate.
TODO: Why not alway use geopandas??
- Parameters:
etrago (
etrago.Etrago
) – Transmission grid objectapply_on (str) – State if this function is applied on the grid_model or the market_model. The market_model options can only be used if the method type is “market_grid”.
- etrago.tools.utilities.buses_by_country(self, apply_on='grid_model')[source]¶
Find buses of foreign countries using coordinates and return them as Pandas Series
- Parameters:
self (Etrago object) – Overall container of PyPSA
apply_on (str) – State if this function is applied on the grid_model or the market_model. The market_model options can only be used if the method type is “market_grid”.
- Return type:
None
- etrago.tools.utilities.clip_foreign(network)[source]¶
Delete all components and timelines located outside of Germany. If applied after optimization, transborder flows divided by country of origin are added as network.foreign_trade.
- etrago.tools.utilities.foreign_links(self)[source]¶
Change transmission technology of foreign lines from AC to DC (links).
- etrago.tools.utilities.set_q_national_loads(self, cos_phi)[source]¶
Set q component of national loads based on the p component and cos_phi
- Parameters:
network (
pypsa.Network
) – Overall container of PyPSAcos_phi (float) – Choose ration of active and reactive power of foreign loads
- Returns:
network – Overall container of PyPSA
- Return type:
pypsa.Network
- etrago.tools.utilities.set_q_foreign_loads(self, cos_phi)[source]¶
Set reative power timeseries of loads in neighbouring countries
- etrago.tools.utilities.connected_grid_lines(network, busids)[source]¶
Get grid lines connected to given buses.
- etrago.tools.utilities.connected_transformer(network, busids)[source]¶
Get transformer connected to given buses.
- etrago.tools.utilities.load_shedding(self, temporal_disaggregation=False, **kwargs)[source]¶
Implement load shedding in existing network to identify feasibility problems
- etrago.tools.utilities.set_control_strategies(network)[source]¶
Sets control strategies for AC generators and storage units
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
- Return type:
None.
- etrago.tools.utilities.data_manipulation_sh(network)[source]¶
Adds missing components to run calculations with SH scenarios.
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
- Return type:
None
- etrago.tools.utilities.export_to_csv(self, path)[source]¶
Write calculation results to csv-files in path.
- etrago.tools.utilities.loading_minimization(network, snapshots)[source]¶
Minimizes the sum of the products of each element in the passive_branches of the model.
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
snapshots ('pandas.core.indexes.datetimes.DatetimeIndex') – snapshots to perform the minimization
- Return type:
None
- etrago.tools.utilities.agg_series_lines(l0, network)[source]¶
Given a pandas DataFrame l0 containing information about lines in a network and a network object, aggregates the data in l0 for all its attributes. Returns a pandas Series containing the aggregated data.
- Parameters:
l0 (pandas.DataFrame) – contain information about lines in a network.
network (:class:`pypsa.Network) – Overall container of PyPSA
- Returns:
A pandas Series containing aggregated data for the lines in the network.
- Return type:
pandas.Series
- etrago.tools.utilities.group_parallel_lines(network)[source]¶
Function that groups parallel lines of the same voltage level to one line component representing all parallel lines
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
- Return type:
None.
- etrago.tools.utilities.delete_dispensable_ac_buses(etrago)[source]¶
Function that identifies and delete AC buses without links, transformers, generators, loads, stores or storage_units, which also are connected to just one or two other buses
- Parameters:
etrago (etrago object) –
- Return type:
None.
- etrago.tools.utilities.set_line_costs(self, cost110=230, cost220=290, cost380=85, costDC=375)[source]¶
Set capital costs for extendable lines in respect to PyPSA [€/MVA]
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
args (dict) – containing settings from appl.py
cost110 – capital costs per km for 110kV lines and cables default: 230€/MVA/km, source: costs for extra circuit in dena Verteilnetzstudie, p. 146)
cost220 – capital costs per km for 220kV lines and cables default: 280€/MVA/km, source: costs for extra circuit in NEP 2025, capactity from most used 220 kV lines in model
cost380 – capital costs per km for 380kV lines and cables default: 85€/MVA/km, source: costs for extra circuit in NEP 2025, capactity from most used 380 kV lines in NEP
costDC – capital costs per km for DC-lines default: 375€/MVA/km, source: costs for DC transmission line in NEP 2035
- etrago.tools.utilities.set_trafo_costs(self, cost110_220=7500, cost110_380=17333, cost220_380=14166)[source]¶
Set capital costs for extendable transformers in respect to PyPSA [€/MVA]
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
cost110_220 – capital costs for 110/220kV transformer default: 7500€/MVA, source: costs for extra trafo in dena Verteilnetzstudie, p. 146; S of trafo used in osmTGmod
cost110_380 – capital costs for 110/380kV transformer default: 17333€/MVA, source: NEP 2025
cost220_380 – capital costs for 220/380kV transformer default: 14166€/MVA, source: NEP 2025
- etrago.tools.utilities.add_missing_components(self)[source]¶
Add a missing transformer at Heizkraftwerk Nord in Munich and a missing transformer in Stuttgart.
- etrago.tools.utilities.convert_capital_costs(self)[source]¶
Convert capital_costs to fit to considered timesteps
- Parameters:
etrago (:class:`etrago.Etrago) – Transmission grid object
- etrago.tools.utilities.find_snapshots(network, carrier, maximum=True, minimum=True, n=3)[source]¶
Function that returns snapshots with maximum and/or minimum feed-in of selected carrier.
- Parameters:
- Returns:
calc_snapshots – List containing snapshots
- Return type:
‘pandas.core.indexes.datetimes.DatetimeIndex’
- etrago.tools.utilities.ramp_limits(network)[source]¶
Add ramping constraints to thermal power plants.
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
- etrago.tools.utilities.get_args_setting(self, jsonpath='scenario_setting.json')[source]¶
Get and open json file with scenaio settings of eTraGo
args
. The settings incluedes all eTraGo specific settings of arguments and parameters for a reproducible calculation.
- etrago.tools.utilities.merge_dicts(dict1, dict2)[source]¶
Return a new dictionary by merging two dictionaries recursively.
- etrago.tools.utilities.get_clustering_data(self, path)[source]¶
Import the final busmap and the initial buses, lines and links
- Parameters:
path (str) – Name of folder from which to import CSVs of network data.
- Return type:
None
- etrago.tools.utilities.set_random_noise(self, sigma=0.01)[source]¶
Sets random noise to marginal cost of each generator.
- etrago.tools.utilities.set_line_country_tags(network)[source]¶
Set country tag for AC- and DC-lines.
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
- etrago.tools.utilities.crossborder_capacity_tyndp2020()[source]¶
This function downloads and extracts a scenario datafile for the TYNDP 2020 (Ten-Year Network Development Plan), reads a specific sheet from the file, filters it based on certain criteria, and then calculates the minimum cross-border capacities for a list of European countries. The minimum cross-border capacity is the minimum of the export and import capacities between two countries.
- Returns:
Dictionary with cossborder capacities.
- Return type:
- etrago.tools.utilities.crossborder_capacity(self)[source]¶
Adjust interconnector capacties.
- Parameters:
network (:class:`pypsa.Network) – Overall container of PyPSA
method (string) – Method of correction. Options are ‘ntc_acer’ and ‘thermal_acer’. ‘ntc_acer’ corrects all capacities according to values published by the ACER in 2016. ‘thermal_acer’ corrects certain capacities where our dataset most likely overestimates the thermal capacity.
- etrago.tools.utilities.set_branch_capacity(etrago)[source]¶
Set branch capacity factor of lines and transformers, different factors for HV (110kV) and eHV (220kV, 380kV).
- Parameters:
etrago (:class:`etrago.Etrago) – Transmission grid object
- etrago.tools.utilities.check_args(etrago)[source]¶
Function that checks the consistency of etragos input parameters.
- Parameters:
etrago (:class:`etrago.Etrago) – Overall container of eTraGo
- Return type:
None.
- etrago.tools.utilities.drop_sectors(self, drop_carriers)[source]¶
Manually drop secors from network. Makes sure the network can be calculated without the dropped sectors.
- Parameters:
drop_carriers (array) – List of sectors that will be dropped. e.g. [‘dsm’, ‘CH4’, ‘H2_saltcavern’, ‘H2_grid’, ‘central_heat’, ‘rural_heat’, ‘central_heat_store’, ‘rural_heat_store’, ‘Li ion’] means everything but AC
- Return type:
None.
- etrago.tools.utilities.update_busmap(self, new_busmap)[source]¶
Update busmap after any clustering process
- Parameters:
new_busmap (dictionary) – busmap used to clusted the network.
- Return type:
None.
- etrago.tools.utilities.adjust_CH4_gen_carriers(self)[source]¶
Precise the carrier for the generators with CH4 carrier
For the eGon2035 scenario, the generators with carrier CH4 represent the prodution od biogas and methan. In the data model, these two differents types are differenciated only by the marginal cost of the generator. This function introduces a carrier distion (CH4_biogas and CH4_NG) in order to avoid the clustering of these two types of generator together and facilitate the contraint applying differently to each of them.
- etrago.tools.utilities.residual_load(network, sector='electricity')[source]¶
Calculate the residual load for the specified sector.
In case of the electricity sector residual load is calculated using all AC loads and all renewable generators with carriers ‘wind_onshore’, ‘wind_offshore’, ‘solar’, ‘solar_rooftop’, ‘biomass’, ‘run_of_river’, and ‘reservoir’.
In case of the central heat sector residual load is calculated using all central heat loads and all renewable generators with carriers ‘solar_thermal_collector’ and ‘geo_thermal’.
- Parameters:
network (PyPSA network) – Network to retrieve load and generation time series from, needed to determine residual load.
sector (str) – Sector to determine residual load for. Possible options are ‘electricity’ and ‘central_heat’. Default: ‘electricity’.
- Returns:
Dataframe with residual load for each bus in the network. Columns of the dataframe contain the corresponding bus name and index of the dataframe is a datetime index with the corresponding time step.
- Return type:
pd.DataFrame