NetworkCollection
¶
NetworkCollection(networks: Series | dict[Any, Network | str | Path] | Sequence[Network | str | Path], index: Index | MultiIndex | Sequence | None = None)
A collection of networks that can be accessed like a single network.
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 42 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:
- 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.
- 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 | dict | Sequence[Network | str | Path]) –Sequence, dict, or pd.Series of Network objects or paths (anything that can be passed to pypsa.Network()) to include in the collection. If a dict is provided, keys become the index and values are the networks/paths.
-
index(pd.Index, pd.MultiIndex, Sequence, or None, default:None) –The index to use for the collection. If
networksis of typepd.Seriesor dict, no index is allowed and it will be retrieved from the keys. If None, a default index based on the network names will be created.
- API Reference Networks
- User Guide What's new in PyPSA v1.0 Features Network Collection
- API Reference Networks Network Statistics
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:
-
has_scenarios(bool) –Check if any network in the collection has scenarios.
-
is_collection(bool) –Check if this is a collection of networks or a single network.
pypsa.NetworkCollection.has_scenarios
property
¶
has_scenarios: bool
Check if any network in the collection has scenarios.
Returns:
-
bool–True if any member network has scenarios, False otherwise.
Examples:
>>> nc.has_scenarios
False
See Also
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.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.
- Home Overview Release Notes v1.0.0 14th October 2025 🎉 Features