Skip to content

Statistics

StatisticsAccessor ΒΆ

StatisticsAccessor(n: Network | NetworkCollection)

Bases: AbstractStatisticsAccessor

Accessor to calculate different metrics from the network.

Statistics

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  ...    -43.277041
Link      DC          4003.90110  ...      0.132018
Load      load           0.00000  ...           NaN

[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

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.

  • 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.

  • 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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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 with components as rows and a single column of aggregated values.

Examples:

>>> n.statistics.capex()
Series([], dtype: float64)

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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = True,
    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 = None,
) -> 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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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 | None) –

    Type of energy balance to calculate: - 'supply': Only consider positive values (energy production) - 'withdrawal': Only consider negative values (energy consumption) - None: 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)

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: str | Sequence[str] | bool | 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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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
...

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: str | Sequence[str] | bool | 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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for more information.

Other Parameters:

  • storage (bool) –

    Whether to consider only storage capacities of the components Store and StorageUnit.

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

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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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

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: bool | str | Sequence[str] = True,
    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.

Curreny is currency/MWh or currency/unit_{bus_carrier} where unit_{bus_carrier} is the unit of the 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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: str | Sequence[str] | bool | 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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for more information.

Other Parameters:

  • storage (bool) –

    Whether to consider only storage capacities of the components Store and StorageUnit.

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

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. See weighting for 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)

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: bool | str | Sequence[str] = True,
    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 = None,
) -> 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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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 None.

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)

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: bool | str | Sequence[str] = True,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = False,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = False,
    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.

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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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: bool | str | Sequence[str] = True,
    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", "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 (bool | str | Sequence[str], default: True ) –

    Which ports to consider: - True: All ports of components - False: Exclude first port ("bus"/"bus0") - str or list of str: Specific ports to include

  • 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-params for 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-params 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 https://go.pypsa.org/options-params for 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)

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

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.

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.

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.

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.

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 groupby argument.

Examples:

>>> pypsa.statistics.groupers.list_groupers().keys()
dict_keys(['bus', 'bus_carrier', ...

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.

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.

StatisticExpressionsAccessor ΒΆ

StatisticExpressionsAccessor(
    n: Network | NetworkCollection,
)

Bases: 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: str | Sequence[str] | bool | 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: bool | str | Sequence[str] = False,
    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: bool | str | Sequence[str] = False,
    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: bool | str | Sequence[str] = True,
    bus_carrier: str | Sequence[str] | None = None,
    carrier: str | Sequence[str] | None = None,
    nice_names: bool | None = None,
    kind: str | None = None,
) -> 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.

Additional parameter

aggregate_bus: bool, optional Whether to obtain the nodal or carrier-wise energy balance. Default is True, corresponding to the carrier-wise balance. groupby_time : str, bool, optional 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.operation ΒΆ

operation(
    components: str | Sequence[str] | None = None,
    groupby_time: str | bool = "mean",
    groupby_method: str = "sum",
    aggregate_across_components: bool = False,
    at_port: bool | str | Sequence[str] = False,
    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: bool | str | Sequence[str] = False,
    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: bool | str | Sequence[str] = True,
    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.statitics.StatisticsAccessor.

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: bool | str | Sequence[str] = False,
    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: bool | str | Sequence[str] = True,
    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.statitics.StatisticsAccessor.