GlobalConstraints
dataclass
ΒΆ
GlobalConstraints(
ctype: ComponentType,
n: Network | None = None,
names: str | int | Sequence[int | str] | None = None,
suffix: str = "",
)
Bases: Components
Global constraints components class.
This class is used for global constraint components. All functionality specific to global constraints is implemented here. Functionality for all components is implemented in the abstract base class.
See Also
Examples:
>>> n.components.global_constraints
'GlobalConstraint' Components
-----------------------------
Attached to PyPSA Network 'AC-DC-Meshed'
Components: 1
Methods:
-
addβAdd new global_constraints.
pypsa.components.GlobalConstraints.add
ΒΆ
add(
name: str | int | Sequence[int | str],
suffix: str = "",
overwrite: bool = False,
return_names: bool | None = None,
**kwargs: Any,
) -> Index | None
Add new global_constraints.
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:
-
type(str or SeriesLike[str]) βType of constraint (e.g. "primary energy", "tech_capacity_expansion_limit", "operational_limit", "transmission_volume_expansion_limit", "transmission_expansion_cost_limit")
-
investment_period(float or SeriesLike[float]) βInvestment period for which the constraint is applied. If not specified, the constraint is applied to all investment periods together.
-
bus(str or SeriesLike[str]) βBus to which the global constraint applies. Only relevant for `type="tech_expansion_limit". If not specified, the constraint applies to all buses.
-
carrier_attribute(str or SeriesLike[str]) βIf the global constraint is connected with a carrier, name the associated carrier attribute. This must appear as a column in
n.carriers. -
sense(str or SeriesLike[str]) βConstraint sense; must be one of <=, == or >=
-
constant(float or SeriesLike[float]) βConstant for right-hand-side of constraint for optimisation period. For a CO2 constraint, this would be tonnes of CO2.
-
mu(float or SeriesLike[float]) βShadow price of global constraint
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.