Line
Lines
dataclass
¶
Lines(ctype: ComponentType, n: Network | None = None, names: str | int | Sequence[int | str] | None = None, suffix: str = '')
Bases: Components
flowchart TD
pypsa.components.Lines[Lines]
pypsa.components.components.Components[Components]
pypsa.components.components.ComponentsData[ComponentsData]
pypsa.components.descriptors.ComponentsDescriptorsMixin[ComponentsDescriptorsMixin]
pypsa.components.transform.ComponentsTransformMixin[ComponentsTransformMixin]
pypsa.components.index.ComponentsIndexMixin[ComponentsIndexMixin]
pypsa.components.array.ComponentsArrayMixin[ComponentsArrayMixin]
pypsa.components.abstract._ComponentsABC[_ComponentsABC]
pypsa.components.components.Components --> pypsa.components.Lines
pypsa.components.components.ComponentsData --> pypsa.components.components.Components
pypsa.components.descriptors.ComponentsDescriptorsMixin --> pypsa.components.components.Components
pypsa.components.abstract._ComponentsABC --> pypsa.components.descriptors.ComponentsDescriptorsMixin
pypsa.components.transform.ComponentsTransformMixin --> pypsa.components.components.Components
pypsa.components.index.ComponentsIndexMixin --> pypsa.components.components.Components
pypsa.components.abstract._ComponentsABC --> pypsa.components.index.ComponentsIndexMixin
pypsa.components.array.ComponentsArrayMixin --> pypsa.components.components.Components
pypsa.components.abstract._ComponentsABC --> pypsa.components.array.ComponentsArrayMixin
click pypsa.components.Lines href "" "pypsa.components.Lines"
click pypsa.components.components.Components href "" "pypsa.components.components.Components"
click pypsa.components.components.ComponentsData href "" "pypsa.components.components.ComponentsData"
click pypsa.components.descriptors.ComponentsDescriptorsMixin href "" "pypsa.components.descriptors.ComponentsDescriptorsMixin"
click pypsa.components.transform.ComponentsTransformMixin href "" "pypsa.components.transform.ComponentsTransformMixin"
click pypsa.components.index.ComponentsIndexMixin href "" "pypsa.components.index.ComponentsIndexMixin"
click pypsa.components.array.ComponentsArrayMixin href "" "pypsa.components.array.ComponentsArrayMixin"
click pypsa.components.abstract._ComponentsABC href "" "pypsa.components.abstract._ComponentsABC"
Lines components class.
This class is used for line components. All functionality specific to lines is implemented here. Functionality for all components is implemented in the abstract base class.
See Also
Examples:
>>> n.components.lines
'Line' Components
-----------------
Attached to PyPSA Network 'AC-DC-Meshed'
Components: 7
-
User Guide
-
Core Design
- Component Types
- Design Energy Balances
- Optimization Formulations
-
Core Design
-
API Reference
Networks
Network
NetworkComponentsMixin
Methods:
-
add–Add new lines.
-
calculate_line_length–Get length of the lines in meters.
-
get_bounds_pu–Get per unit bounds for lines.
pypsa.components.Lines.add
¶
add(name: str | int | Sequence[int | str], suffix: str = '', overwrite: bool = False, return_names: bool | None = None, **kwargs: Any) -> Index | None
Add new lines.
Handles addition of single and multiple components along with their attributes. Pass a list of names to add multiple components at once or pass a single name to add a single component.
When a single component is added, all non-scalar attributes are assumed to be time-varying and indexed by snapshots. When multiple components are added, all non-scalar attributes are assumed to be static and indexed by names. A single value sequence is treated as scalar and broadcasted to all components. It is recommended to explicitly pass a scalar instead. If you want to add time-varying attributes to multiple components, you can pass a 2D array/ DataFrame where the first dimension is snapshots and the second dimension is names.
Any attributes which are not specified will be given the default value from Components.
Parameters:
-
name(str or int or list of str or list of int) –Component name(s)
-
suffix(str, default:"") –All components are named after name with this added suffix.
-
overwrite(bool, default:False) –If True, existing components with the same names as in
namewill be overwritten. Otherwise only new components will be added and others will be ignored. -
return_names(bool | None, default:None) –Whether to return the names of the new components. Defaults to module wide option (default: False). See
https://go.pypsa.org/options-paramsfor more information. -
kwargs(Any, default:{}) –Component attributes to add. See Other Parameters for list of default attributes but any attribute could be added.
Other Parameters:
-
bus0(str or SeriesLike[str]) –Name of origin bus to which branch is attached.
-
bus1(str or SeriesLike[str]) –Name of destination bus to which branch is attached.
-
type(str or SeriesLike[str]) –Name of line standard type. If this is not an empty string "", the line standard type impedance parameters are multiplied with the
lengthand divided/multiplied bynum_parallelto computex,r, etc. This will override any values set inr,x, andb. If the string is empty, values manually provided forr,x`, etc. are taken. -
x(float or SeriesLike[float]) –Series reactance, must be non-zero for AC branch for linearised power flow equations. If the line has series inductance \(L\) in Henries then \(x = 2\\pi f L\) where \(f\) is the frequency in Hertz. Series impedance \(z = r + jx\) must be non-zero for non-linear power flow calculations. Ignored if
typedefined. -
r(float or SeriesLike[float]) –Series resistance, must be non-zero for DC branch for linearised power flow equations. Series impedance \(z = r + jx\) must be non-zero for the non-linear power flow. Ignored if
typedefined. -
g(float or SeriesLike[float]) –Shunt conductivity. Shunt admittance is \(y = g + jb\).
-
b(float or SeriesLike[float]) –Shunt susceptance. If the line has shunt capacitance \(C\) in Farads then \(b = 2\\pi f C\) where \(f\) is the frequency in Hertz. Shunt admittance is \(y = g + jb\). Ignored if
typedefined. -
s_nom(float or SeriesLike[float]) –Limit of apparent power which can pass through branch in either direction. Ignored if
s_nom_extendable=True. -
s_nom_mod(float or SeriesLike[float]) –Modular unit size of line expansion of
s_nom(e.g. fixed rating of added circuit). Introduces integer variables. -
s_nom_extendable(bool or SeriesLike[bool]) –Switch to allow capacity
s_nomto be extended in optimisation. -
s_nom_min(float or SeriesLike[float]) –If
s_nom_extendable=True, set the minimum value ofs_nom_opt. -
s_nom_max(float or SeriesLike[float]) –If
s_nom_extendable=True, set the maximum value ofs_nom_opt. -
s_nom_set(float or SeriesLike[float]) –If
s_nomis extendable in optimization, set the value ofs_nom_opt. -
s_max_pu(float or Series or SeriesLike[float or Series]) –The maximum allowed absolute apparent power flow per unit of
s_nomfor the optimisation (e.g. can sets_max_pu<1to approximate \(N-1\) contingency factor, or can be time-varying to represent weather-dependent dynamic line rating for overhead lines). -
capital_cost(float or SeriesLike[float]) –Fixed period costs of extending
s_nomby 1 MVA (e.g. annuitized investment costs). Used directly unlessovernight_costis specified. Anylengthfactor must already be included. -
overnight_cost(float or SeriesLike[float]) –Overnight (upfront) investment cost per MVA. If specified, PyPSA calculates annuity using
discount_rateandlifetime. Takes precedence overcapital_cost. -
discount_rate(float or SeriesLike[float]) –Discount rate for annuity calculation when using
overnight_cost. Supports 0% rate (simple depreciation). -
fom_cost(float or SeriesLike[float]) –Fixed period operation and maintenance cost per MVA, added to annuitized investment cost.
-
active(bool or SeriesLike[bool]) –Whether to consider the component in optimisation or not
-
build_year(int or SeriesLike[int]) –Build year of line.
-
lifetime(float or SeriesLike[float]) –Lifetime of line.
-
length(float or SeriesLike[float]) –Length of line used when
typeis set. Also useful for calculatingcapital_cost. -
carrier(str or SeriesLike[str]) –Type of current. "AC" is the only valid value for lines.
-
terrain_factor(float or SeriesLike[float]) –Terrain factor for increasing
lengthforcapital_costcalculation. -
num_parallel(float or SeriesLike[float]) –When
typeis set, this is the number of parallel circuits. Can also be fractional. Iftypeis empty "" this value is ignored. -
v_ang_min(float or SeriesLike[float]) –Minimum voltage angle difference across the line. Placeholder attribute not currently used.
-
v_ang_max(float or SeriesLike[float]) –Maximum voltage angle difference across the line. Placeholder attribute not currently used.
-
sub_network(str or SeriesLike[str]) –Name of sub-network to which lines belongs, as calculated by
n.determine_network_topology(). Do not set by hand. -
p0(Series or SeriesLike[Series] or ArrayLike[Series]) –Active power at
bus0(positive if branch is withdrawing power frombus0). -
q0(Series or SeriesLike[Series] or ArrayLike[Series]) –Reactive power at
bus0(positive if branch is withdrawing power frombus0). -
p1(Series or SeriesLike[Series] or ArrayLike[Series]) –Active power at
bus1(positive if branch is withdrawing power frombus1). -
q1(Series or SeriesLike[Series] or ArrayLike[Series]) –Reactive power at
bus1(positive if branch is withdrawing power frombus1). -
x_pu(float or SeriesLike[float]) –Per unit series reactance calculated by
n.calculate_dependent_values()fromxandn.buses.v_nom. -
r_pu(float or SeriesLike[float]) –Per unit series resistance calculated by
n.calculate_dependent_values()fromrandn.buses.v_nom. -
g_pu(float or SeriesLike[float]) –Per unit shunt conductivity calculated by
n.calculate_dependent_values()fromgandn.buses.v_nom. -
b_pu(float or SeriesLike[float]) –Per unit shunt susceptance calculated by
n.calculate_dependent_values()frombandn.buses.v_nom. -
x_pu_eff(float or SeriesLike[float]) –Effective per unit series reactance for linear power flow, calculated by
n.calculate_dependent_values()fromxandn.buses.v_nom -
r_pu_eff(float or SeriesLike[float]) –Effective per unit series resistance for linear power flow, calculated by
n.calculate_dependent_values()fromrandn.buses.v_nom -
s_nom_opt(float or SeriesLike[float]) –Optimised nominal capacity for apparent power.
-
mu_lower(Series or SeriesLike[Series] or ArrayLike[Series]) –Shadow price of lower
s_nomlimit \(-F \\leq f\). Always non-negative. -
mu_upper(Series or SeriesLike[Series] or ArrayLike[Series]) –Shadow price of upper
s_nomlimit \(f \\leq F\). Always non-negative.
Returns:
-
new_names(index or None) –Names of new components (including suffix) if return_names is
True, otherwiseNone.
Examples:
The example is shown for Generator component, but the same applies to all component types.
>>> n = pypsa.Network()
>>> c = n.components.generators
>>> c
Empty 'Generator' Components
Add a single component:
>>> c.add("my-generator-1", carrier="AC")
A new generator is added to the components instance:
>>> c
'Generator' Components
----------------------
Attached to PyPSA Network 'Unnamed Network'
Components: 1
With static data (and default values for all attributes):
>>> c.static[["carrier", "p_nom"]]
carrier p_nom
name
my-generator-1 AC 0.0
Add multiple components with static attributes:
>>> c.add(["my-generator-2", "my-generator-3"],
... carrier=["AC", "DC"],
... p_nom=10)
A new generator is added to the components instance:
>>> c
'Generator' Components
----------------------
Attached to PyPSA Network 'Unnamed Network'
Components: 3
With static data:
>>> c.static[["carrier", "p_nom"]]
carrier p_nom
name
my-generator-1 AC 0.0
my-generator-2 AC 10.0
my-generator-3 DC 10.0
The single value for p_nom is broadcasted to all components. So you could also
pass [10, 10] instead of 10.
See Also
pypsa.components.Lines.calculate_line_length
¶
calculate_line_length() -> Series
Get length of the lines in meters.
Based on coordinates of attached buses. Buses must have 'x' and 'y' attributes, otherwise no line length can be calculated. By default the haversine formula is used to calculate the distance between two points.
Returns:
-
Series–Length of the lines.
See Also
Examples:
>>> c = pypsa.examples.scigrid_de().c.lines
>>> ds = c.calculate_line_length()
>>> ds.head()
0 34432.796096
1 59701.666027
2 32242.741010
3 30559.154647
4 21574.543367
dtype: float64
pypsa.components.Lines.get_bounds_pu
¶
get_bounds_pu(attr: str = 's') -> tuple[DataArray, DataArray]
Get per unit bounds for lines.
For passive branch components, min_pu is the negative of max_pu.
Parameters:
-
attr(string, default:'s') –Attribute name for the bounds, e.g. "s"
Returns:
-
tuple[DataArray, DataArray]–Tuple of (min_pu, max_pu) DataArrays.
LineTypes
dataclass
¶
LineTypes(ctype: ComponentType, n: Network | None = None, names: str | int | Sequence[int | str] | None = None, suffix: str = '')
Bases: Components
flowchart TD
pypsa.components.LineTypes[LineTypes]
pypsa.components.components.Components[Components]
pypsa.components.components.ComponentsData[ComponentsData]
pypsa.components.descriptors.ComponentsDescriptorsMixin[ComponentsDescriptorsMixin]
pypsa.components.transform.ComponentsTransformMixin[ComponentsTransformMixin]
pypsa.components.index.ComponentsIndexMixin[ComponentsIndexMixin]
pypsa.components.array.ComponentsArrayMixin[ComponentsArrayMixin]
pypsa.components.abstract._ComponentsABC[_ComponentsABC]
pypsa.components.components.Components --> pypsa.components.LineTypes
pypsa.components.components.ComponentsData --> pypsa.components.components.Components
pypsa.components.descriptors.ComponentsDescriptorsMixin --> pypsa.components.components.Components
pypsa.components.abstract._ComponentsABC --> pypsa.components.descriptors.ComponentsDescriptorsMixin
pypsa.components.transform.ComponentsTransformMixin --> pypsa.components.components.Components
pypsa.components.index.ComponentsIndexMixin --> pypsa.components.components.Components
pypsa.components.abstract._ComponentsABC --> pypsa.components.index.ComponentsIndexMixin
pypsa.components.array.ComponentsArrayMixin --> pypsa.components.components.Components
pypsa.components.abstract._ComponentsABC --> pypsa.components.array.ComponentsArrayMixin
click pypsa.components.LineTypes href "" "pypsa.components.LineTypes"
click pypsa.components.components.Components href "" "pypsa.components.components.Components"
click pypsa.components.components.ComponentsData href "" "pypsa.components.components.ComponentsData"
click pypsa.components.descriptors.ComponentsDescriptorsMixin href "" "pypsa.components.descriptors.ComponentsDescriptorsMixin"
click pypsa.components.transform.ComponentsTransformMixin href "" "pypsa.components.transform.ComponentsTransformMixin"
click pypsa.components.index.ComponentsIndexMixin href "" "pypsa.components.index.ComponentsIndexMixin"
click pypsa.components.array.ComponentsArrayMixin href "" "pypsa.components.array.ComponentsArrayMixin"
click pypsa.components.abstract._ComponentsABC href "" "pypsa.components.abstract._ComponentsABC"
Line types components class.
This class is used for line type components. All functionality specific to line types is implemented here. Functionality for all components is implemented in the abstract base class.
See Also
Examples:
>>> n.components.line_types
'LineType' Components
---------------------
Attached to PyPSA Network 'AC-DC-Meshed'
Components: 59
-
API Reference
Networks
Network
NetworkComponentsMixinline_types_t
Methods:
-
add–Wrap Components.add() and docstring is patched via decorator.
pypsa.components.LineTypes.add
¶
add(name: str | int | Sequence[int | str], suffix: str = '', overwrite: bool = False, return_names: bool | None = None, **kwargs: Any) -> Index | None
Wrap Components.add() and docstring is patched via decorator.