Statistics
StatisticsAccessor
¶
StatisticsAccessor(n: Network | NetworkCollection)
Bases: AbstractStatisticsAccessor
flowchart TD
pypsa.Network.statistics[StatisticsAccessor]
pypsa.statistics.abstract.AbstractStatisticsAccessor[AbstractStatisticsAccessor]
pypsa.statistics.abstract.AbstractStatisticsAccessor --> pypsa.Network.statistics
click pypsa.Network.statistics href "" "pypsa.Network.statistics"
click pypsa.statistics.abstract.AbstractStatisticsAccessor href "" "pypsa.statistics.abstract.AbstractStatisticsAccessor"
Accessor to calculate different metrics from the network.
All methods and attributes of the accessor can be used with any pypsa.Network
instance via n.statistics, which is the main facade to the statistics module.
The statistics methods are another level of accessors, which means that they can yield statistics as pandas DataFrames or plots based on them. See the examples for more details.
Examples:
The examples below can be used with any statistical method. The default arguments used and the plot type yielded will vary.
Get aggregated statistics in a single DataFrame:
>>> n.statistics()
Optimal Capacity ... Market Value
Generator gas 982.03448 ... 1559.511099
wind 7292.13406 ... 589.813549
Line AC 5613.82931 ... -21.114555
Link DC 4003.90110 ... 0.066009
Load load 0.00000 ... -633.512009
[5 rows x 12 columns]
Get the energy balance:
>>> n.statistics.energy_balance()
component carrier bus_carrier
Generator gas AC 1465.27439
wind AC 31082.35370
Load load AC -32547.62808
dtype: float64
Get the optimal capacity:
>>> n.statistics.optimal_capacity()
component carrier
Generator gas 982.03448
wind 7292.13406
Line AC 5613.82931
Link DC 4003.90110
dtype: float64
Create a basic plot on any statistic:
>>> n.statistics.energy_balance.plot()
#TODO Add plot
Choose a specific plot type:
>>> n.statistics.energy_balance.plot("bar")
#TODO Add plot
Create a interactive plot:
>>> n.statistics.energy_balance.iplot()
#TODO Add plot
-
API Reference
Networks
Network
Network
-
API Reference
Networks
Network
Network
-
API Reference
Networks
Network
Networkstatistics
Methods:
-
__call__–Calculate multiple statistical values for a network.
-
capacity_factor–Calculate the capacity factor of components in the network.
-
capex–Calculate the capital expenditure.
-
curtailment–Calculate the curtailment of components in the network in MWh.
-
energy_balance–Calculate the energy balance of components in network.
-
expanded_capacity–Calculate the expanded capacity of the network components in MW.
-
expanded_capex–Calculate the capital expenditure of expanded capacities.
-
fom–Calculate the fixed operation and maintenance costs.
-
installed_capacity–Calculate the installed capacity of the network components in MW.
-
installed_capex–Calculate the capital expenditure of already built capacities.
-
market_value–Calculate the market value of components in the network.
-
opex–Calculate the operational expenditure in the network in given currency.
-
optimal_capacity–Calculate the optimal capacity of the network components in MW.
-
overnight_cost–Calculate the overnight investment costs (excluding fom).
-
prices–Calculate the average marginal prices in the network per bus.
-
revenue–Calculate the revenue of components in the network in given currency.
-
supply–Calculate the supply of components in the network.
-
system_cost–Calculate the total system cost.
-
transmission–Calculate the transmission of branch components in the network.
-
withdrawal–Calculate the withdrawal of components in the network.
pypsa.Network.statistics.__call__
¶
__call__(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate multiple statistical values for a network.
This function calls multiple function in the background in order to derive a full table of relevant network information. It groups the values to components according to the groupby argument.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Returns:
-
df(DataFrame) –pandas.DataFrame with columns given the different quantities.
Examples:
>>> n.statistics.optimal_capacity()
component carrier
Generator gas 982.03448
wind 7292.13406
Line AC 5613.82931
Link DC 4003.90110
dtype: float64
pypsa.Network.statistics.capacity_factor
¶
capacity_factor(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'mean', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, at_port: PortsLike | None = None, groupby: str | Sequence[str] | Callable = 'carrier', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the capacity factor of components in the network.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–Capacity factor of components in the network with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.capacity_factor()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.capex
¶
capex(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, cost_attribute: str = 'capital_cost') -> DataFrame
Calculate the capital expenditure.
Includes newly installed and existing assets, measured in the specified currency.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
cost_attribute(str) –Network attribute that should be used to calculate Capital Expenditure. Defaults to
capital_cost. When set tocapital_cost, the calculation uses annuitized investment cost (without fixed O&M).
Returns:
-
DataFrame–Capital expenditure with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.capex()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.curtailment
¶
curtailment(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the curtailment of components in the network in MWh.
The calculation only considers assets with a p_max_pu time
series, which is used to quantify the available power potential.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–Curtailment of components in the network with components as rows and either time steps as columns (if aggregate_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.curtailment()
Series([], Name: generators, dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.energy_balance
¶
energy_balance(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable | None = None, at_port: PortsLike = 'all', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, direction: str | None = 'both') -> DataFrame
Calculate the energy balance of components in network.
This method computes the energy balance across various network components, where positive values represent supply and negative values represent withdrawal. Units are inherited from the respective bus carriers.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:["carrier", "bus_carrier"]) –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike, default:"all") –Which ports to consider: - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
-
direction(str) –Type of energy balance to calculate: - 'supply': Only consider positive values (energy production) - 'withdrawal': Only consider negative values (energy consumption) - 'both': Consider both supply and withdrawal
Returns:
-
DataFrame–Energy balance with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values. Units depend on the bus carrier and aggregation method.
Examples:
>>> n.statistics.energy_balance()
Series([], dtype: float64)
- Home Overview Release Notes v0.32.0 5th December 2024 Features
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.expanded_capacity
¶
expanded_capacity(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the expanded capacity of the network components in MW.
Positive capacity values correspond to production capacities and negative values to consumption capacities.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Returns:
-
DataFrame–Expanded capacity of the network components with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.expanded_capacity()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.expanded_capex
¶
expanded_capex(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, cost_attribute: str = 'capital_cost') -> DataFrame
Calculate the capital expenditure of expanded capacities.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
cost_attribute(str) –Network attribute that should be used to calculate Capital Expenditure. Defaults to
capital_cost.
Returns:
-
DataFrame–Capital expenditure of expanded capacities with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.expanded_capex()
component carrier
Generator gas -2.120994e+07
wind -6.761698e+05
...
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.fom
¶
fom(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the fixed operation and maintenance costs.
Returns fom_cost * {p/s}_nom_opt for each component.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components.
-
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier.
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses.
-
nice_names(bool | None, default:None) –Whether to use carrier nice names.
-
drop_zero(bool | None, default:None) –Whether to drop zero values from the result.
-
round(int | None, default:None) –Number of decimal places to round the result to.
Returns:
-
DataFrame–Fixed O&M costs with components as rows and a single column of aggregated values.
See Also
:meth:capex : Returns total fixed costs (investment + fom_cost).
:meth:overnight_cost : Returns annuitized investment costs.
- Home Overview Release Notes v1.0.7 13th January 2026 Enhancements
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.installed_capacity
¶
installed_capacity(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, storage: bool = False) -> DataFrame
Calculate the installed capacity of the network components in MW.
Positive capacity values correspond to production capacities and negative values to consumption capacities.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
storage(bool) –Whether to consider only storage capacities of the components
StoreandStorageUnit.
Returns:
-
pd.DataFrame–Installed capacity of the network components with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.installed_capacity()
component carrier
Generator gas 150000.0
wind 290.0
Line AC 160000.0
Link DC 4000.0
dtype: float64
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.installed_capex
¶
installed_capex(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, cost_attribute: str = 'capital_cost') -> DataFrame
Calculate the capital expenditure of already built capacities.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
cost_attribute(str) –Network attribute that should be used to calculate Capital Expenditure. Defaults to
capital_cost.
Returns:
-
DataFrame–Capital expenditure of already built capacities with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.installed_capex()
component carrier
Generator gas 2.120994e+07
wind 6.761698e+05
Line AC 1.653634e+04
Link DC 1.476534e+03
dtype: float64
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.market_value
¶
market_value(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'mean', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike = 'all', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the market value of components in the network.
Currency is given per unit of the component's reference operational variable.
The market value is always calculated relative to the component's
reference operational variable from get_operation. Filters such as
bus_carrier and at_port only restrict the revenue contribution in the
numerator.
- Default (no
bus_carrier): Returns total revenue across all ports divided by the reference operational variable. - With
bus_carrier: Returns revenue at the specified bus carriers' ports divided by the same reference operational variable.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike, default:"all") –Which ports to consider: - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–Market value of components in the network with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.market_value()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.opex
¶
opex(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, cost_types: str | Sequence[str] | None = None) -> DataFrame
Calculate the operational expenditure in the network in given currency.
Operational expenditures include the marginal, marginal quadratic, storage holding, spillage, start-up, shut-down and stand-by costs.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
-
cost_types(str | Sequence[str] | None) –List of cost types to include in the calculation. Available options are: 'marginal_cost', 'marginal_cost_quadratic', 'marginal_cost_storage', 'spill_cost', 'start_up_cost', 'shut_down_cost', 'stand_by_cost'. Defaults to all (when None).
Returns:
-
DataFrame–Ongoing operational costs with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.opex()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.optimal_capacity
¶
optimal_capacity(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, storage: bool = False) -> DataFrame
Calculate the optimal capacity of the network components in MW.
Positive capacity values correspond to production capacities and negative values to consumption capacities.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
storage(bool) –Whether to consider only storage capacities of the components
StoreandStorageUnit.
Returns:
-
DataFrame–Optimal capacity of the network components with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.optimal_capacity()
component carrier
Generator gas 982.03448
wind 7292.13406
Line AC 5613.82931
Link DC 4003.90110
dtype: float64
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.overnight_cost
¶
overnight_cost(components: str | Sequence[str] | None = None, groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the overnight investment costs (excluding fom).
Returns overnight_cost * {p/s}_nom_opt where overnight_cost is given, else
capital_cost / annuity_factor(lifetime, discount_rate) * {p/s}_nom_opt (PVF calculation).
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components.
-
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier.
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses.
-
nice_names(bool | None, default:None) –Whether to use carrier nice names.
-
drop_zero(bool | None, default:None) –Whether to drop zero values from the result.
-
round(int | None, default:None) –Number of decimal places to round the result to.
Returns:
-
DataFrame–Annuitized overnight investment costs with components as rows and a single column of aggregated values.
See Also
:meth:capex : Returns total fixed costs (overnight_cost + fom_cost).
:meth:fom : Returns fixed operation and maintenance costs.
- Home Overview Release Notes v1.0.7 13th January 2026 Enhancements
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.prices
¶
prices(groupby: bool = False, weighting: str = 'load', groupby_time: bool = True, bus_carrier: Sequence[str] | str | None = None, drop_zero: bool | None = None, round: int | None = None) -> Series
Calculate the average marginal prices in the network per bus.
Currency is currency/MWh or currency/unit_{bus_carrier} where unit_{bus_carrier} is the unit of the bus carrier.
Note
The functions signature of n.statistics.prices is different from other statistics functions as it does not take the same parameters, since prices are only defined for buses.
Parameters:
-
groupby(bool | str, default:False) –How to group components: -
False: No grouping, return all buses individually -"bus_carrier": Prices are aggregated to each bus carrier with weights applied. Other grouping options are not supported and the groupby method can not be set. Seeweightingfor different weighting options. Defaults to False. -
weighting(str, default:'load') –Type of weighting to use. If 'load' the prices are weighted by the load of the buses and if time they are weighted by snapshot weightings. Defaults to 'load'.
-
groupby_time(bool, default:True) –Whether to group the time series by time or return the full time series. No aggregation method can be set. Defaults to True.
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of buses. If specified, only considers buses with the given carrier(s).
-
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
pypsa.options.params.statistics.describe()for more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
pypsa.options.params.statistics.describe()for more information.
Returns:
-
DataFrame–Time-averaged or load-weighted prices per bus or bus carrier.
Examples:
>>> n.statistics.prices()
Series([], dtype: float64)
-
API Reference
Networks
Network
Statistics
StatisticsAccessorprices - User Guide Usage Statistics Metrics
pypsa.Network.statistics.revenue
¶
revenue(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike = 'all', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None, direction: str | None = 'both') -> DataFrame
Calculate the revenue of components in the network in given currency.
The revenue is defined as the net revenue of an asset, i.e cost of input - revenue of output.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike, default:"all") –Which ports to consider: - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
-
direction(str) –Type of revenue to consider. If 'input' only the revenue of the input is considered. If 'output' only the revenue of the output is considered. Defaults to 'both'.
Returns:
-
DataFrame–Revenue of components in the network with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.revenue()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.supply
¶
supply(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike = 'all', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the supply of components in the network.
Units depend on the regarded bus carrier.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike, default:"all") –Which ports to consider: - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–Supply of components in the network with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.supply()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.system_cost
¶
system_cost(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the total system cost.
Sum of the capital and operational expenditures.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike | None, default:None) –Which ports to consider: - None: Automatically set to "all" if bus_carrier is specified, otherwise "bus0" - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–System cost with components as rows and a single column of aggregated values.
Examples:
>>> n.statistics.system_cost()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.transmission
¶
transmission(components: Collection[str] | str | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable | Literal[False] = 'carrier', at_port: PortsLike = 'bus0', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the transmission of branch components in the network.
Only includes branch components (links, lines, transformers) that connect buses of the same carrier. Components connecting buses of different carriers (e.g. sector-coupling links) are excluded.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike, default:"bus0") –Which ports to consider: - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–Transmission of branch components in the network with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.transmission()
Series([], dtype: object)
- User Guide Usage Statistics Metrics
pypsa.Network.statistics.withdrawal
¶
withdrawal(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: Callable | str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike = 'all', carrier: str | Sequence[str] | None = None, bus_carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, drop_zero: bool | None = None, round: int | None = None) -> DataFrame
Calculate the withdrawal of components in the network.
Units depend on the regarded bus carrier.
Parameters:
-
components(str | Sequence[str] | None, default:None) –Components to include in the calculation. If None, includes all one-port and branch components. Available components are 'Generator', 'StorageUnit', 'Store', 'Load', 'Line', 'Transformer' and'Link'.
-
groupby_method(Callable | str, default:"sum") –Function to aggregate groups when using the groupby parameter. Any pandas aggregation function can be used.
-
aggregate_across_components(bool, default:False) –Whether to aggregate across components. If there are different components which would be grouped together due to the same index, this is avoided.
-
groupby(str | Sequence[str] | Callable, default:"carrier") –How to group components: -
False: No grouping, return all components individually - string or list of strings: Group by column names from c.static - callable: Function that takes network and component name as arguments -
at_port(PortsLike, default:"all") –Which ports to consider: - "all": All ports of components - "bus0": Consider only first port - str or list of str: Specific ports to include (e.g., "bus1", "bus2")
-
carrier(str | Sequence[str] | None, default:None) –Filter by carrier. If specified, only considers assets with given carrier(s).
-
bus_carrier(str | Sequence[str] | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s).
-
nice_names(bool | None, default:None) –Whether to use carrier nice names defined in n.carriers.nice_name. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
drop_zero(bool | None, default:None) –Whether to drop zero values from the result. Defaults to module wide option (default: True). See
https://go.pypsa.org/options-paramsfor more information. -
round(int | None, default:None) –Number of decimal places to round the result to. Defaults to module wide option (default: 2). See
https://go.pypsa.org/options-paramsfor more information.
Other Parameters:
-
groupby_time(str | bool) –Type of aggregation when aggregating time series. Deactivate by setting to False. Any pandas aggregation function can be used. Note that when aggregating the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW.
Returns:
-
DataFrame–Withdrawal of components in the network with components as rows and either time steps as columns (if groupby_time=False) or a single column of aggregated values.
Examples:
>>> n.statistics.withdrawal()
Series([], dtype: float64)
- User Guide Usage Statistics Metrics
Groupers
¶
Container for all the get_ methods.
Methods:
-
__getitem__–Get a single or multi-indexed grouper method.
-
__repr__–Get representation of the grouper container.
-
__setitem__–Set a custom grouper method.
-
add_grouper–Add a custom grouper to groupers on module level.
-
bus–Grouper method to group by the attached bus of the components.
-
bus_carrier–Grouper method to group by the carrier of the attached bus of a component.
-
carrier–Grouper method to group by the carrier of the components.
-
country–Grouper method to group by the country of the components corresponding bus.
-
list_groupers–List all available groupers which are avaliable on the module level.
-
location–Grouper method to group by the location of the components corresponding bus.
-
name–Grouper method to group by the name of components.
-
unit–Grouper method to group by the unit of the components corresponding bus.
pypsa.statistics.Groupers.__getitem__
¶
__getitem__(keys: str | Callable | Sequence[str | Callable]) -> Callable
Get a single or multi-indexed grouper method.
Parameters:
-
keys(str | Callable | Sequence[str | Callable]) –Single or multiple keys to get the grouper method.
Returns:
-
Callable–Grouper method.
Examples:
Single indexed grouper
>>> pypsa.statistics.groupers["carrier"]
<function Groupers._multi_grouper.<locals>.multi_grouper at 0x...>
Multi-indexed grouper
>>> pypsa.statistics.groupers[["carrier", "bus"]]
<function Groupers._multi_grouper.<locals>.multi_grouper at 0x...>
pypsa.statistics.Groupers.__repr__
¶
__repr__() -> str
Get representation of the grouper container.
Examples:
>>> pypsa.statistics.groupers
Grouper container with the following groupers: bus, bus_carrier, ...
pypsa.statistics.Groupers.__setitem__
¶
__setitem__(key: str, value: Callable) -> None
Set a custom grouper method.
Parameters:
-
key(str) –Name of the custom grouper.
-
value(Callable) –Custom grouper function.
pypsa.statistics.Groupers.add_grouper
¶
add_grouper(name: str, func: Callable) -> None
Add a custom grouper to groupers on module level.
After registering a custom grouper, it can be accessed via the groupers module level object and used in the statistics methods or as a groupers method.
Parameters:
-
name(str) –Name of the custom grouper. This will be used as the key in the groupby argument.
-
func(Callable) –Custom grouper function, which must return a pandas Series with the same length as the component index and accept as arguments: * n (Network): The PyPSA network instance * c (str): Component name * port (str): Component port as integer string * nice_names (bool, optional): Whether to use nice carrier names
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.bus
¶
bus(n: Network, c: str, port: str = '') -> Series
Grouper method to group by the attached bus of the components.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
-
port(str, default:'') –Port of corresponding bus, which should be used.
Returns:
-
Series–Series with the bus of the components.
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.bus_carrier
¶
bus_carrier(n: Network, c: str, port: str = '', nice_names: bool = True) -> Series
Grouper method to group by the carrier of the attached bus of a component.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
-
port(str, default:'') –Port of corresponding bus, which should be used.
-
nice_names(bool, default:True) –Whether to use nice carrier names.
Returns:
-
Series–Series with the bus and carrier of the components.
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.carrier
¶
carrier(n: Network, c: str, nice_names: bool = True) -> Series
Grouper method to group by the carrier of the components.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
-
nice_names(bool, default:True) –Whether to use nice carrier names.
Returns:
-
Series–Series with the carrier of the components.
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.country
¶
country(n: Network, c: str, port: str = '') -> Series
Grouper method to group by the country of the components corresponding bus.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
-
port(str, default:'') –Port of corresponding bus, which should be used.
Returns:
-
Series–Series with the country of the components corresponding bus.
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.list_groupers
¶
list_groupers() -> dict
List all available groupers which are avaliable on the module level.
Returns:
-
dict–Dictionary with all available groupers. The keys are the grouper names and the values are the grouper methods. The keys can be used to directly access the grouper in any
groupbyargument.
Examples:
>>> pypsa.statistics.groupers.list_groupers().keys()
dict_keys(['bus', 'bus_carrier', ...
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.location
¶
location(n: Network, c: str, port: str = '') -> Series
Grouper method to group by the location of the components corresponding bus.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
-
port(str, default:'') –Port of corresponding bus, which should be used.
Returns:
-
Series–Series with the location of the components corresponding bus.
pypsa.statistics.Groupers.name
¶
name(n: Network, c: str) -> Series
Grouper method to group by the name of components.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
Returns:
-
Series–Series with the component names.
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.statistics.Groupers.unit
¶
unit(n: Network, c: str, port: str = '') -> Series
Grouper method to group by the unit of the components corresponding bus.
Parameters:
-
n(Network) –PyPSA network instance.
-
c(str) –Components type name. E.g. "Generator", "StorageUnit", etc.
-
port(str, default:'') –Port of corresponding bus, which should be used.
Returns:
-
Series–Series with the unit of the components corresponding bus.
- Home Overview Release Notes v0.32.0 5th December 2024 Features
StatisticExpressionsAccessor
¶
StatisticExpressionsAccessor(n: Network | NetworkCollection)
Bases: AbstractStatisticsAccessor
flowchart TD
pypsa.optimization.expressions.StatisticExpressionsAccessor[StatisticExpressionsAccessor]
pypsa.statistics.abstract.AbstractStatisticsAccessor[AbstractStatisticsAccessor]
pypsa.statistics.abstract.AbstractStatisticsAccessor --> pypsa.optimization.expressions.StatisticExpressionsAccessor
click pypsa.optimization.expressions.StatisticExpressionsAccessor href "" "pypsa.optimization.expressions.StatisticExpressionsAccessor"
click pypsa.statistics.abstract.AbstractStatisticsAccessor href "" "pypsa.statistics.abstract.AbstractStatisticsAccessor"
Accessor to calculate different statistical expressions.
This class is used to calculate different statistical expressions like capital expenditure, capacity, energy balance, etc. The results are aggregated by the given groupby function.
Methods:
-
capacity–Calculate the optimal capacity of the network components in MW.
-
capex–Calculate the capital expenditure of the network in given currency.
-
curtailment–Calculate the curtailment of components in the network in MWh.
-
energy_balance–Calculate the energy balance of components in the network.
-
operation–Calculate the operation of components in the network.
-
opex–Calculate the operational expenditure in the network in given currency.
-
supply–Calculate the supply of components in the network.
-
transmission–Calculate the transmission of branch components in the network.
-
withdrawal–Calculate the withdrawal of components in the network.
pypsa.optimization.expressions.StatisticExpressionsAccessor.capacity
¶
capacity(components: str | Sequence[str] | None = None, groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, storage: bool = False, nice_names: bool | None = None, include_non_extendable: bool = True) -> LinearExpression
Calculate the optimal capacity of the network components in MW.
If bus_carrier is given, the capacity is weighed by the output efficiency
of components at buses with carrier bus_carrier.
If storage is set to True, only storage capacities of the component
Store and StorageUnit are taken into account.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
pypsa.optimization.expressions.StatisticExpressionsAccessor.capex
¶
capex(components: str | Sequence[str] | None = None, groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, cost_attribute: str = 'capital_cost', include_non_extendable: bool = True) -> LinearExpression
Calculate the capital expenditure of the network in given currency.
If bus_carrier is given, only components which are connected to buses
with carrier bus_carrier are considered.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
pypsa.optimization.expressions.StatisticExpressionsAccessor.curtailment
¶
curtailment(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None) -> LinearExpression
Calculate the curtailment of components in the network in MWh.
The calculation only considers assets with a p_max_pu time
series, which is used to quantify the available power potential.
If bus_carrier is given, only the assets are considered which are
connected to buses with carrier bus_carrier.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
Parameters:
-
groupby_time((str, bool), default:'sum') –Type of aggregation when aggregating time series. Note that for {'mean', 'sum'} the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW. Defaults to 'sum'.
pypsa.optimization.expressions.StatisticExpressionsAccessor.energy_balance
¶
energy_balance(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable | None = None, at_port: PortsLike = 'all', bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None, direction: str | None = 'both') -> LinearExpression
Calculate the energy balance of components in the network.
Positive values represent a supply and negative a withdrawal. Units depend on the regarded bus carrier.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
Parameters:
-
groupby_time((str, bool), default:'sum') –Type of aggregation when aggregating time series. Note that for {'mean', 'sum'} the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW. Defaults to 'sum'.
-
direction(str, default:"both") –Type of energy balance to calculate: - 'supply': Only consider positive values (energy production) - 'withdrawal': Only consider negative values (energy consumption) - 'both': Consider both supply and withdrawal
- Home Overview Release Notes v0.32.0 5th December 2024 Features
pypsa.optimization.expressions.StatisticExpressionsAccessor.operation
¶
operation(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'mean', groupby_method: str = 'sum', aggregate_across_components: bool = False, at_port: PortsLike | None = None, groupby: str | Sequence[str] | Callable = 'carrier', bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None) -> LinearExpression
Calculate the operation of components in the network.
If bus_carrier is given, only the assets are considered which are
connected to buses with carrier bus_carrier.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
Parameters:
-
groupby_time((str, bool), default:'mean') –Type of aggregation when aggregating time series. Note that for {'mean', 'sum'} the time series are aggregated to using snapshot weightings. With False the time series is given. Defaults to 'mean'.
pypsa.optimization.expressions.StatisticExpressionsAccessor.opex
¶
opex(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None) -> LinearExpression
Calculate the operational expenditure in the network in given currency.
If bus_carrier is given, only components which are connected to buses
with carrier bus_carrier are considered.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
Parameters:
-
groupby_time((str, bool), default:'sum') –Type of aggregation when aggregating time series. Note that for {'mean', 'sum'} the time series are aggregated using snapshot weightings. With False the time series is given in currency/hour. Defaults to 'sum'.
pypsa.optimization.expressions.StatisticExpressionsAccessor.supply
¶
supply(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable | None = None, at_port: PortsLike = 'all', bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None) -> LinearExpression
Calculate the supply of components in the network.
Units depend on the regarded bus carrier.
If bus_carrier is given, only the supply to buses with carrier
bus_carrier is calculated.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
pypsa.optimization.expressions.StatisticExpressionsAccessor.transmission
¶
transmission(components: Collection[str] | str | None = None, groupby_time: str | bool = 'sum', groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable = 'carrier', at_port: PortsLike | None = None, bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None) -> LinearExpression
Calculate the transmission of branch components in the network.
Units depend on the regarded bus carrier.
If bus_carrier is given, only the flow between buses with
carrier bus_carrier is calculated.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.
Parameters:
-
groupby_time((str, bool), default:'sum') –Type of aggregation when aggregating time series. Note that for {'mean', 'sum'} the time series are aggregated to MWh using snapshot weightings. With False the time series is given in MW. Defaults to 'sum'.
pypsa.optimization.expressions.StatisticExpressionsAccessor.withdrawal
¶
withdrawal(components: str | Sequence[str] | None = None, groupby_time: str | bool = 'sum', groupby_method: str = 'sum', aggregate_across_components: bool = False, groupby: str | Sequence[str] | Callable | None = None, at_port: PortsLike = 'all', bus_carrier: str | Sequence[str] | None = None, carrier: str | Sequence[str] | None = None, nice_names: bool | None = None) -> LinearExpression
Calculate the withdrawal of components in the network.
Units depend on the regarded bus carrier.
If bus_carrier is given, only the withdrawal from buses with
carrier bus_carrier is calculated.
For information on the list of arguments, see the docs in
Network.statistics or pypsa.Network.statistics.