pypsa.Network.madd

Contents

pypsa.Network.madd#

Network.madd(class_name: str, names: Sequence, suffix: str = '', **kwargs: Any) Index#

Add multiple components to the network, along with their attributes.

n.madd is deprecated and will be removed in version 1.0. Use pypsa.Network.add() instead. It can handle both single and multiple addition of components.

Make sure when adding static attributes as pandas Series that they are indexed by names. Make sure when adding time-varying attributes as pandas DataFrames that their index is a superset of n.snapshots and their columns are a subset of names.

Any attributes which are not specified will be given the default value from Components.

Parameters:
  • class_name (string) – Component class name in (“Bus”, “Generator”, “Load”, “StorageUnit”, “Store”, “ShuntImpedance”, “Line”, “Transformer”, “Link”).

  • names (list-like or pandas.Index) – Component names

  • suffix (string, default '') – All components are named after names with this added suffix. It is assumed that all Series and DataFrames are indexed by the original names.

  • kwargs – Component attributes, e.g. x=[0.1, 0.2], can be list, pandas.Series of pandas.DataFrame for time-varying

Returns:

new_names – Names of new components (including suffix)

Return type:

pandas.index

Examples

Short Example:

>>> n.madd("Load", ["load 1", "load 2"],
...        bus=["1", "2"],
...        p_set=np.random.rand(len(n.snapshots), 2))

Long Example:

>>> import pandas as pd, numpy as np
>>> buses = range(13)
>>> snapshots = range(7)
>>> n = pypsa.Network()
>>> n.set_snapshots(snapshots)
>>> n.madd("Bus", buses)
>>> # add load as numpy array
>>> n.madd("Load",
...        n.buses.index + " load",
...        bus=buses,
...        p_set=np.random.rand(len(snapshots), len(buses)))
>>> # add wind availability as pandas DataFrame
>>> wind = pd.DataFrame(np.random.rand(len(snapshots), len(buses)),
...        index=n.snapshots,
...        columns=buses)
>>> #use a suffix to avoid boilerplate to rename everything
>>> n.madd("Generator",
...        buses,
...        suffix=' wind',
...        bus=buses,
...        p_nom_extendable=True,
...        capital_cost=1e5,
...        p_max_pu=wind)

Deprecated since version 0.31: This will be removed in 1.0. Use n.add as a drop-in replacement instead.