Skip to content

NetworkCollection ΒΆ

NetworkCollection(
    networks: Series | Sequence[Network | str],
    index: Index | MultiIndex | Sequence | None = None,
)

A collection of networks that can be accessed like a single network.

v0.35.0 | Collection

Examples:

Create a collection from file paths:

>>> nc = pypsa.NetworkCollection(["network1.nc", "network2.nc"])

Create a collection from Network objects:

>>> n
PyPSA Network 'AC-DC-Meshed'
----------------------------
Components:
 - Bus: 9
 - Carrier: 6
 - Generator: 6
 - GlobalConstraint: 1
 - Line: 7
 - Link: 4
 - Load: 6
 - SubNetwork: 3
Snapshots: 10

>>> n_shuffled_load
PyPSA Network 'AC-DC-Meshed-Shuffled-Load'
------------------------------------------
Components:
 - Bus: 9
 - Carrier: 6
 - Generator: 6
 - GlobalConstraint: 1
 - Line: 7
 - Link: 4
 - Load: 6
 - SubNetwork: 3
Snapshots: 10

>>> nc = pypsa.NetworkCollection([n, n_shuffled_load])
>>> nc
NetworkCollection
-----------------
Networks: 2
Index name: 'network'
Entries: ['AC-DC-Meshed', 'AC-DC-Meshed-Shuffled-Load']

Access component data across all networks:

>>> nc.generators
                                               bus  ...    p_nom_opt
network                    name                         ...
AC-DC-Meshed               Manchester Wind  Manchester  ...  ...
                           Manchester Gas   Manchester  ...  ...
                           Norway Wind          Norway  ...  ...
                           Norway Gas           Norway  ...  ...
                           Frankfurt Wind    Frankfurt  ...  ...
                           Frankfurt Gas     Frankfurt  ...  ...
AC-DC-Meshed-Shuffled-Load Manchester Wind  Manchester  ...  ...
                           Manchester Gas   Manchester  ...  ...
                           Norway Wind          Norway  ...  ...
                           Norway Gas           Norway  ...  ...
                           Frankfurt Wind    Frankfurt  ...  ...
                           Frankfurt Gas     Frankfurt  ...  ...

[12 rows x 38 columns]
>>> nc.statistics.energy_balance()
component  network                     carrier  bus_carrier
Generator  AC-DC-Meshed                gas      AC              1465.27439
                                       wind     AC             31082.35370
           AC-DC-Meshed-Shuffled-Load  gas      AC              ...
                                       wind     AC             ...
Load       AC-DC-Meshed                load     AC            -32547.62808
           AC-DC-Meshed-Shuffled-Load  load     AC            -32547.62808
dtype: float64

Use custom index:

>>> import pandas as pd
>>> index = pd.Index(["scenario_A", "scenario_B"])
>>> nc = pypsa.NetworkCollection([n, n_shuffled_load], index=index)
>>> nc
NetworkCollection
-----------------
Networks: 2
Index name: 'network'
Entries: ['scenario_A', 'scenario_B']
Notes

A single network is mirrored in two ways:

  1. For each nested method or property of a network, the collection will dynamically create a new MemberProxy object that wraps around it and allows for custom processing. The '_method_patterns' dictionary in the MemberProxy class defines which processor is used for which method or property. If no processor is defined, a NotImplementedError is raised.
  2. Some accessors of the Network class already support Networks and NetworkCollections, since via the step above the NetworkCollection can already duck-type to a Network. If this is the case, the accessor is directly initialised with a NetworkCollection instead.

Parameters:

  • networks (Series | Sequence[Network | str]) –

    Sequence or pd.Series of Network objects or strings (file paths/ urls) to include in the collection. If strings are provided, they will be passed to pypsa.Network() to create Network objects.

  • index (pd.Index, pd.MultiIndex, Sequence, or None, default: None ) –

    The index to use for the collection. If networks is of type pd.Series, no index is allowed and it will be retrieved from the Series. If None, a default index based on the network names will be created.

Methods:

  • __getitem__ –

    Get a subset of networks using pandas Series indexing.

  • __iter__ –

    Iterate over the Network objects in the container.

  • __len__ –

    Get the number of networks in the collection.

  • __repr__ –

    Get representation of NetworkCollection.

  • get_network –

    Return a single network from the collection.

Attributes:

  • is_collection (bool) –

    Check if this is a collection of networks or a single network.

pypsa.NetworkCollection.is_collection property ΒΆ

is_collection: bool

Check if this is a collection of networks or a single network.

Returns:

  • bool –

    True, since this is a NetworkCollection.

Examples:

>>> nc
NetworkCollection
-----------------
Networks: 2
Index name: 'network'
Entries: ['AC-DC-Meshed', 'AC-DC-Meshed-Shuffled-Load']
>>> nc.is_collection
True
>>> n
PyPSA Network 'AC-DC-Meshed'
----------------------------
Components:
 - Bus: 9
 ...
Snapshots: 10

>>> n.is_collection
False
See Also

pypsa.Network, pypsa.NetworkCollection

pypsa.NetworkCollection.__getitem__ ΒΆ

__getitem__(key: Any) -> Any

Get a subset of networks using pandas Series indexing.

Examples:

>>> nc["AC-DC-Meshed"]
PyPSA Network 'AC-DC-Meshed'
----------------------------
Components:
 - Bus: 9
 - Carrier: 6
 - Generator: 6
 - GlobalConstraint: 1
 - Line: 7
 - Link: 4
 - Load: 6
 - SubNetwork: 3
Snapshots: 10

pypsa.NetworkCollection.__iter__ ΒΆ

__iter__() -> Iterator[Network]

Iterate over the Network objects in the container.

pypsa.NetworkCollection.__len__ ΒΆ

__len__() -> int

Get the number of networks in the collection.

Examples:

>>> nc
NetworkCollection
-----------------
Networks: 2
Index name: 'network'
Entries: ['AC-DC-Meshed', 'AC-DC-Meshed-Shuffled-Load']
>>> len(nc)
2

pypsa.NetworkCollection.__repr__ ΒΆ

__repr__() -> str

Get representation of NetworkCollection.

Examples:

>>> nc
NetworkCollection
-----------------
Networks: 2
Index name: 'network'
Entries: ['AC-DC-Meshed', 'AC-DC-Meshed-Shuffled-Load']

pypsa.NetworkCollection.get_network ΒΆ

get_network(collection: Any) -> Network

Return a single network from the collection.

Parameters:

  • collection (Any) –

    Name or identifier of the network to retrieve.

Returns:

  • Network –

    The requested network from the collection.

Examples:

>>> nc.get_network("AC-DC-Meshed")
PyPSA Network 'AC-DC-Meshed'
----------------------------
Components:
 - Bus: 9
 - Carrier: 6
 - Generator: 6
 - GlobalConstraint: 1
 - Line: 7
 - Link: 4
 - Load: 6
 - SubNetwork: 3
Snapshots: 10

Raises:

  • KeyError –

    If the collection name is not found.