SubNetwork
¶
SubNetwork(n: Network, name: str)
Bases: NetworkGraphMixin, SubNetworkPowerFlowMixin
flowchart TD
pypsa.SubNetwork[SubNetwork]
pypsa.network.graph.NetworkGraphMixin[NetworkGraphMixin]
pypsa.network.power_flow.SubNetworkPowerFlowMixin[SubNetworkPowerFlowMixin]
pypsa.network.graph.NetworkGraphMixin --> pypsa.SubNetwork
pypsa.network.power_flow.SubNetworkPowerFlowMixin --> pypsa.SubNetwork
click pypsa.SubNetwork href "" "pypsa.SubNetwork"
click pypsa.network.graph.NetworkGraphMixin href "" "pypsa.network.graph.NetworkGraphMixin"
click pypsa.network.power_flow.SubNetworkPowerFlowMixin href "" "pypsa.network.power_flow.SubNetworkPowerFlowMixin"
SubNetwork for electric buses (AC or DC).
SubNetworks are generated by pypsa.Network.determine_network_topology for
electric buses with passive flows or isolated non-electric buses and stored in
the n.components.sub_networks component.`
Parameters:
-
n(Network) –The parent network of the sub-network.
-
name(str) –The name of the sub-network.
- Home Overview Release Notes v0.31.0 1st October 2024 Features
Methods:
-
adjacency_matrix–Construct an adjacency matrix (directed) as a pandas DataFrame or sparse matrix.
-
branches–Get the branches in the sub-network.
-
branches_i–Get the index of the branches in the sub-network.
-
buses–Get the buses in the sub-network.
-
buses_i–Get the index of the buses in the sub-network.
-
calculate_BODF–Calculate the Branch Outage Distribution Factor (BODF) for sub_network.
-
calculate_B_H–Calculate B and H matrices for AC or DC sub-networks.
-
calculate_PTDF–Calculate the Power Transfer Distribution Factor (PTDF) for sub_network.
-
calculate_Y–Calculate bus admittance matrices for AC sub-networks.
-
component–Get a component from the sub-network.
-
df–Get a static component from the sub-network.
-
dynamic–Get a dynamic component from the sub-network.
-
find_bus_controls–Find slack and all PV and PQ buses for a sub_network.
-
find_slack_bus–Find the slack bus in a connected sub-network.
-
generators–Get the generators in the sub-network.
-
generators_i–Get the index of the generators in the sub-network.
-
graph–Build NetworkX graph.
-
incidence_matrix–Construct a sparse incidence matrix (directed).
-
iterate_components–Iterate over components of the sub-network.
-
lines_i–Get the index of the lines in the sub-network.
-
loads–Get the loads in the sub-network.
-
loads_i–Get the index of the loads in the sub-network.
-
lpf–Linear power flow for connected sub-network.
-
pf–Non-linear power flow for connected sub-network.
-
pnl–Get a dynamic component from the sub-network.
-
shunt_impedances–Get the shunt impedances in the sub-network.
-
shunt_impedances_i–Get the index of the shunt impedances in the sub-network.
-
static–Get a static component from the sub-network.
-
storage_units–Get the storage units in the sub-network.
-
storage_units_i–Get the index of the storage units in the sub-network.
-
stores–Get the stores in the sub-network.
-
stores_i–Get the index of the stores in the sub-network.
-
transformers_i–Get the index of the transformers in the sub-network.
Attributes:
-
c(ComponentsStore) –Get the components for the sub-network.
-
components(ComponentsStore) –Get the components for the sub-network.
-
has_scenarios(bool) –Check if the network has scenarios.
-
investment_period_weightings(DataFrame) –Get the investment period weightings for the sub-network.
-
investment_periods(Index) –Get the investment periods for the sub-network.
-
n(Network) –Get the parent network of the sub-network.
-
scenarios(Series) –Get the scenarios for the network.
-
snapshot_weightings(DataFrame) –Get the snapshot weightings for the sub-network.
-
snapshots(Index | MultiIndex) –Get the snapshots for the sub-network.
pypsa.SubNetwork.c
property
¶
c: ComponentsStore
Get the components for the sub-network.
Alias for sub_network.components.
See Also
pypsa.SubNetwork.components
property
¶
components: ComponentsStore
Get the components for the sub-network.
Sub network components behave like Components in a basic pypsa.Network, but are a special class (SubNetworkComponents) to only return a view from the parent network.
Examples:
Get single component:
>>> sub_network.components.generators
'Generator' SubNetworkComponents
--------------------------------
Attached to Sub-Network of PyPSA Network 'AC-DC-Meshed'
Components: 6
Getting a component is also possible via getitem:
>>> sub_network.components['generators']
'Generator' SubNetworkComponents
...
Or with the component name instead of list notation:
>>> sub_network.components['Generator']
'Generator' SubNetworkComponents
...
See Also
pypsa.SubNetwork.has_scenarios
property
¶
has_scenarios: bool
Check if the network has scenarios.
Returns:
-
bool–True if the network has scenarios, False otherwise.
pypsa.SubNetwork.investment_period_weightings
property
¶
investment_period_weightings: DataFrame
Get the investment period weightings for the sub-network.
pypsa.SubNetwork.investment_periods
property
¶
investment_periods: Index
Get the investment periods for the sub-network.
See Also
pypsa.SubNetwork.n
property
¶
n: Network
Get the parent network of the sub-network.
Examples:
>>> sub_network.n
PyPSA Network 'AC-DC-Meshed'
----------------------------
Components:
- Bus: 9
...
pypsa.SubNetwork.scenarios
property
¶
scenarios: Series
Get the scenarios for the network.
Returns:
-
Series–The scenarios for the network.
pypsa.SubNetwork.snapshot_weightings
property
¶
snapshot_weightings: DataFrame
Get the snapshot weightings for the sub-network.
See Also
pypsa.SubNetwork.snapshots
property
¶
snapshots: Index | MultiIndex
Get the snapshots for the sub-network.
See Also
pypsa.SubNetwork.adjacency_matrix
¶
adjacency_matrix(branch_components: Collection[str] | None = None, investment_period: int | str | None = None, busorder: Index | None = None, weights: Series | None = None, return_dataframe: bool | None = None) -> DataFrame | coo_matrix
Construct an adjacency matrix (directed) as a pandas DataFrame or sparse matrix.
Parameters:
-
branch_components(iterable sublist of `branch_components`, default:None) –Buses connected by any of the selected branches are adjacent (default: branch_components (network) or passive_branch_components (sub_network))
-
investment_period(int | str | None, default:None) –If given, only assets active in the given investment period are considered in the network topology.
-
busorder(pd.Index subset of n.buses.index, default:None) –Basis to use for the matrix representation of the adjacency matrix (default: buses.index (network) or buses_i() (sub_network))
-
weights(Series or None(default), default:None) –If given must provide a weight for each branch, multi-indexed on branch_component name and branch name.
-
return_dataframe(bool | None, default:None) –If True, returns a pandas DataFrame. If False, returns a sparse coo_matrix for backwards compatibility. If None (default), returns a sparse coo_matrix with a deprecation warning.
Returns:
-
adjacency_matrix(DataFrame or coo_matrix) –Directed adjacency matrix as DataFrame (if return_dataframe=True) or sparse matrix (if return_dataframe=False) with bus indices
pypsa.SubNetwork.branches_i
¶
branches_i(active_only: bool = False) -> MultiIndex
Get the index of the branches in the sub-network.
Parameters:
-
active_only(bool, default:False) –If True, only return the index of the active branches.
Returns:
-
MultiIndex–The index of the branches in the sub-network.
Examples:
>>> sub_network.branches_i()
MultiIndex([('Line', '0'),
('Line', '1'),
('Line', '5')],
names=['type', 'name'])
pypsa.SubNetwork.buses
¶
buses() -> DataFrame
Get the buses in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.buses.static instead.
See Also
pypsa.SubNetwork.buses_i
¶
buses_i() -> Index
Get the index of the buses in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.buses.static.index instead.
See Also
pypsa.SubNetwork.calculate_BODF
¶
calculate_BODF(skip_pre: bool = False) -> None
Calculate the Branch Outage Distribution Factor (BODF) for sub_network.
Sets sub_network.BODF as a (dense) numpy array.
The BODF is a num_branch x num_branch 2d array.
For the outage of branch l, the new flow on branch k is given in terms of the flow before the outage
f_k^after = f_k^before + BODF_{kl} f_l^before
Note that BODF_{ll} = -1.
Parameters:
-
skip_pre(bool, default:False) –Skip the preliminary step of computing the PTDF.
- User Guide Optimization Formulations Contingencies N-1 Security Constraints for SCLOPF
pypsa.SubNetwork.calculate_B_H
¶
calculate_B_H(skip_pre: bool = False) -> None
Calculate B and H matrices for AC or DC sub-networks.
pypsa.SubNetwork.calculate_PTDF
¶
calculate_PTDF(skip_pre: bool = False) -> None
Calculate the Power Transfer Distribution Factor (PTDF) for sub_network.
Sets sub_network.PTDF as a (dense) numpy array.
Parameters:
-
skip_pre(bool, default:False) –Skip the preliminary steps of computing topology, calculating dependent values, finding bus controls and computing B and H.
- User Guide Optimization Formulations Linearised Power Flow Kirchhoff's Voltage Law (KVL)
pypsa.SubNetwork.calculate_Y
¶
calculate_Y(skip_pre: bool = False, active_branches_only: bool = True) -> None
Calculate bus admittance matrices for AC sub-networks.
pypsa.SubNetwork.component
¶
component(c_name: str) -> SubNetworkComponents
Get a component from the sub-network.
Deprecated in v1.0.0
Use sub_network.components.<c_name> instead.
See Also
pypsa.SubNetwork.df
¶
df(c_name: str) -> DataFrame
Get a static component from the sub-network.
Deprecated in
Use sub_network.components.<c_name>.static instead.
See Also
pypsa.SubNetwork.dynamic
¶
dynamic(c_name: str) -> Dict
Get a dynamic component from the sub-network.
Deprecated in v1.0.0
Use sub_network.components.<c_name>.dynamic instead.
See Also
pypsa.SubNetwork.find_bus_controls
¶
find_bus_controls() -> None
Find slack and all PV and PQ buses for a sub_network.
This function also fixes sub_network.buses_o, a DataFrame ordered by control type.
pypsa.SubNetwork.find_slack_bus
¶
find_slack_bus() -> None
Find the slack bus in a connected sub-network.
pypsa.SubNetwork.generators
¶
generators() -> DataFrame
Get the generators in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.generators.static instead.
See Also
pypsa.SubNetwork.generators_i
¶
generators_i() -> Index
Get the index of the generators in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.generators.static.index instead.
See Also
pypsa.SubNetwork.graph
¶
graph(branch_components: Collection[str] | None = None, weight: str | None = None, inf_weight: bool | float = False, include_inactive: bool = True) -> OrderedGraph
Build NetworkX graph.
Parameters:
-
branch_components([str], default:None) –Components to use as branches. The default are passive_branch_components in the case of a SubNetwork and branch_components in the case of a Network.
-
weight(str, default:None) –Branch attribute to use as weight
-
inf_weight(bool | float, default:False) –How to treat infinite weights (default: False). True keeps the infinite weight. False skips edges with infinite weight. If a float is given it is used instead.
-
include_inactive(bool, default:True) –Whether to include inactive components in the graph.
Returns:
-
graph(OrderedGraph) –NetworkX graph
pypsa.SubNetwork.incidence_matrix
¶
incidence_matrix(branch_components: Collection[str] | None = None, busorder: Index | None = None) -> csr_matrix
Construct a sparse incidence matrix (directed).
Parameters:
-
branch_components(iterable sublist of `branch_components`, default:None) –Buses connected by any of the selected branches are adjacent (default: branch_components (network) or passive_branch_components (sub_network))
-
busorder(pd.Index subset of n.buses.index, default:None) –Basis to use for the matrix representation of the adjacency matrix (default: buses.index (network) or buses_i() (sub_network))
Returns:
-
incidence_matrix(csr_matrix) – -
Directed incidence matrix–
Examples:
>>> n.incidence_matrix()
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 22 stored elements and shape (9, 11)>
- User Guide Optimization Formulations Linearised Power Flow Linear Loss Approximation
pypsa.SubNetwork.iterate_components
¶
iterate_components(components: Collection[str] | None = None, skip_empty: bool = True) -> Iterator[SubNetworkComponents]
Iterate over components of the sub-network.
Parameters:
-
components(list - like, default:None) –List of components ('Generator', 'Line', etc.) to iterate over, by default None
-
skip_empty(bool, default:True) –Whether to skip a components with no assigned assets, by default True
See Also
Yields:
-
Component–Container for component data. See Component class for details.
pypsa.SubNetwork.lines_i
¶
lines_i() -> Index
Get the index of the lines in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.lines.static.index instead.
See Also
pypsa.SubNetwork.loads
¶
loads() -> DataFrame
Get the loads in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.loads.static instead.
See Also
pypsa.SubNetwork.loads_i
¶
loads_i() -> Index
Get the index of the loads in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.loads.static.index instead.
See Also
pypsa.SubNetwork.lpf
¶
lpf(snapshots: Sequence | None = None, skip_pre: bool = False) -> None
Linear power flow for connected sub-network.
Parameters:
-
snapshots(list-like|single snapshot, default:None) –A subset or an elements of n.snapshots on which to run the power flow, defaults to n.snapshots
-
skip_pre(bool, default:False) –Skip the preliminary steps of computing topology, calculating dependent values and finding bus controls.
pypsa.SubNetwork.pf
¶
pf(snapshots: Sequence | None = None, skip_pre: bool = False, x_tol: float = 1e-06, use_seed: bool = False, distribute_slack: bool = False, slack_weights: Series | dict | str = 'p_set') -> tuple[Series, Series, Series]
Non-linear power flow for connected sub-network.
Parameters:
-
snapshots(list-like|single snapshot, default:None) –A subset or an elements of n.snapshots on which to run the power flow, defaults to n.snapshots
-
skip_pre(bool, default:False) –Skip the preliminary steps of computing topology, calculating dependent values and finding bus controls.
-
x_tol(float, default:1e-06) –Tolerance for Newton-Raphson power flow.
-
use_seed(bool, default:False) –Use a seed for the initial guess for the Newton-Raphson algorithm.
-
distribute_slack(bool, default:False) –If
True, distribute the slack power across generators proportional to generator dispatch by default or according to the distribution scheme provided inslack_weights. IfFalseonly the slack generator takes up the slack. -
slack_weights(Series | str, default:'p_set') –Distribution scheme describing how to determine the fraction of the total slack power a bus of the sub-network takes up. Default is to distribute proportional to generator dispatch ('p_set'). Another option is to distribute proportional to (optimised) nominal capacity ('p_nom' or 'p_nom_opt'). Custom weights can be provided via a pandas.Series/dict that has the buses or the generators of the sub-network as index/keys. When using custom weights with buses as index/keys the slack power of a bus is distributed among its generators in proportion to their nominal capacity (
p_nom) if given, otherwise evenly.
Returns:
-
Tuple of three pandas.Series indicating number of iterations,– -
remaining error, and convergence status for each snapshot–
pypsa.SubNetwork.pnl
¶
pnl(c_name: str) -> Dict
Get a dynamic component from the sub-network.
Deprecated in v1.0.0
Use sub_network.components.<c_name>.dynamic instead.
See Also
pypsa.SubNetwork.shunt_impedances
¶
shunt_impedances() -> DataFrame
Get the shunt impedances in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.shunt_impedances.static instead.
See Also
pypsa.SubNetwork.shunt_impedances_i
¶
shunt_impedances_i() -> Index
Get the index of the shunt impedances in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.shunt_impedances.static.index instead.
See Also
pypsa.SubNetwork.static
¶
static(c_name: str) -> DataFrame
Get a static component from the sub-network.
Deprecated in v1.0.0
Use sub_network.components.<c_name>.static instead.
See Also
pypsa.SubNetwork.storage_units
¶
storage_units() -> DataFrame
Get the storage units in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.storage_units.static instead.
See Also
pypsa.SubNetwork.storage_units_i
¶
storage_units_i() -> Index
Get the index of the storage units in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.storage_units.static.index instead.
See Also
pypsa.SubNetwork.stores
¶
stores() -> DataFrame
Get the stores in the sub-network.
Deprecated in v1.0.0
Use sub_network.components.stores.static instead.
pypsa.SubNetwork.stores_i
¶
stores_i() -> Index
Get the index of the stores in the sub-network.
!!! warning "Deprecated in <!-- md:badge-version
Use `sub_network.components.stores.static.index` instead.