Skip to content

Carriers dataclass

Carriers(ctype: ComponentType, n: Network | None = None, names: str | int | Sequence[int | str] | None = None, suffix: str = '')

Bases: Components


              flowchart TD
              pypsa.components.Carriers[Carriers]
              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.Carriers
                                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.Carriers href "" "pypsa.components.Carriers"
              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"
            

Carriers components class.

This class is used for carrier components. All functionality specific to carriers is implemented here. Functionality for all components is implemented in the abstract base class.

See Also

pypsa.Components

Examples:

>>> n.components.carriers
'Carrier' Components
--------------------
Attached to PyPSA Network 'AC-DC-Meshed'
Components: 6

Methods:

  • add

    Add new carriers.

  • add_missing_carriers

    Add carriers that are used in the network but not yet defined.

  • assign_colors

    Assign colors to carriers using a matplotlib color palette.

pypsa.components.Carriers.add

add(name: str | int | Sequence[int | str], suffix: str = '', overwrite: bool = False, return_names: bool | None = None, **kwargs: Any) -> Index | None

Add new carriers.

v0.33.0

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 name will 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-params for 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:

  • co2_emissions (float or SeriesLike[float]) –

    Emissions in tCO2 per MWh of primary energy (e.g. methane has 0.2 tCO2/MWhthermal).

  • color (str or SeriesLike[str]) –

    Color for plotting (e.g. matplotlib named colors or hexadecimal color codes like "#AB9812")

  • nice_name (str or SeriesLike[str]) –

    Descriptive name for statistics and visualisations (e.g. "Natural Gas" for carrier gas)

  • max_growth (float or SeriesLike[float]) –

    Maximum new installed capacity per investment period

  • max_relative_growth (float or SeriesLike[float]) –

    Maximum capacity ratio for new installed capacity per investment period

Returns:

  • new_names ( index or None ) –

    Names of new components (including suffix) if return_names is True, otherwise None.

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.Network.add

pypsa.components.Carriers.add_missing_carriers

add_missing_carriers(**kwargs: Any) -> Index

Add carriers that are used in the network but not yet defined.

v1.1.0

This function iterates over all components that have a carrier attribute, collects all unique carrier values, and adds any carriers that are not yet defined in the network.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional keyword arguments to pass to the add() method for the new carriers (e.g., color, co2_emissions, nice_name).

Returns:

  • Index

    Index of newly added carrier names.

Examples:

>>> n = pypsa.Network()
>>> n.components.buses.add('my_bus', carrier='my_carrier')
>>> n.c.carriers.add_missing_carriers()
Index(['my_carrier'], dtype='object')

Carriers are added without needing to call n.add separately:

>>> n.components.carriers.static
            co2_emissions color nice_name  max_growth  max_relative_growth
name
my_carrier            0.0                         inf                  0.0

pypsa.components.Carriers.assign_colors

assign_colors(carriers: str | Sequence[str] | None = None, palette: str = 'tab10', overwrite: bool = False) -> None

Assign colors to carriers using a matplotlib color palette.

v1.1.0

Parameters:

  • carriers (str, Sequence[str], or None, default: None ) –

    Carrier name(s) to assign colors to. If None, assigns colors to all carriers that don't have a color set (or all if overwrite=True).

  • palette (str, default: "tab10" ) –

    Matplotlib color palette to use for assigning colors. Options include: - "tab10" (10 colors, default) - "tab20" (20 colors) - "Set1", "Set2", "Set3" (qualitative palettes) - "Pastel1", "Pastel2" (soft colors) - Any other matplotlib colormap name

  • overwrite (bool, default: False ) –

    If True, overwrite existing colors. If False, only assign colors to carriers that don't have a color set (empty string or NaN).

See Also

add_missing_carriers : Add carriers that are used but not yet defined