netallocation.utils module

This module contains tool functions for making the life easier in the other modules.

netallocation.utils.as_dense(ds)[source]

Convert sparse dataset/dataarray into a dense dataset.

Parameters

ds (xr.Dataset or xr.DataArray) –

Returns

Dataset or DataArray with dense data.

Return type

xr.Dataset or xr.DataArray

netallocation.utils.as_sparse(ds)[source]

Convert dense dataset/dataarray into a sparse dataset.

Parameters

ds (xr.Dataset or xr.DataArray) –

Returns

Dataset or DataArray with sparse data.

Return type

xr.Dataset or xr.DataArray

netallocation.utils.bus_distances(n)[source]

Calculate the geographical distances between all buses.

Parameters

n (pypsa.Network) –

Returns

Distance matrix of size N x N, with N being the number of buses.

Return type

xr.DataArray

netallocation.utils.check_branch_comps(arg, n)[source]

Set argument to n.branch_components if None

netallocation.utils.check_carriers(n)[source]

Ensure if carrier of stores is defined.

Parameters

n (pypsa.Network) –

netallocation.utils.check_dataset(ds)[source]

Ensure the argument is an xarray.Dataset.

If the argument was a Dataset, the a tupel (ds, True) is returned, if it isn’t’ a Dataset a tuple of the (Dataset(ds), False) is returned.

netallocation.utils.check_duplicated_carrier(n)[source]
netallocation.utils.check_one_port_comps(arg, n)[source]

Set argument to n.one_port_components if None

netallocation.utils.check_passive_branch_comps(arg, n)[source]

Set argument to n.passive_branch_components if None

netallocation.utils.check_snapshots(arg, n)[source]

Set argument to n.snapshots if None

netallocation.utils.filter_null(da, dim=None)[source]

Drop all coordinates with only null/nan entries on dimensions dim.

netallocation.utils.generation_carriers(n)[source]
netallocation.utils.get_as_dense_by_bus_carrier(n, attr, comps=None, snapshots=None)[source]
netallocation.utils.get_branches_i(n, branch_components=None)[source]

Get a pd.Multiindex for all branches in the network.

netallocation.utils.get_ext_branches_b(n)[source]
netallocation.utils.get_ext_branches_i(n, branch_components=None)[source]

Get a pd.Multiindex for all extendable branches in the network.

netallocation.utils.get_ext_one_ports_b(n)[source]
netallocation.utils.get_ext_one_ports_i(n, per_carrier=True)[source]

Get a pd.Multiindex for all extendable branches in the network.

netallocation.utils.get_non_ext_branches_i(n, branch_components=None)[source]

Get a pd.Multiindex for all non-extendable branches in the network.

netallocation.utils.get_non_ext_one_ports_i(n, per_carrier=True)[source]

Get a pd.Multiindex for all non-extendable branches in the network.

netallocation.utils.is_sparse(ds)[source]

Check if a xarray.Dataset or a xarray.DataArray is sparse.

Parameters

ds (xarray.Dataset or xarray.DataArray) –

Returns

Return type

Bool

netallocation.utils.lower(ds)[source]

Clip all positive entries of a xr.Dataset/xr.DataArray.

netallocation.utils.obj_if_acc(obj)[source]

Get the object of underying Accessor if Accessor is passed.

This function is usefull to straightforwardly make functions through the AllocationAccessor accessible.

Parameters

obj (AllocationAccessor or xarray.Dataset) –

Returns

Dataset of the accessor if accessor was is passed, ingoing object otherwise.

Return type

obj

netallocation.utils.reindex_by_bus_carrier(df, c, n)[source]

Group a time-dependent dataframe by bus and carrier.

Parameters
  • df (pd.DataFrame) – Time-dependent series to group, e.g. n.generators_t.p

  • c (str) – Component name of the underlying data.

  • n (pypsa.Network) –

Returns

Grouped array with dimension (‘snapshot’, ‘bus’, ‘carrier’).

Return type

xarray.DataArray

netallocation.utils.set_default_if_none(arg, n, attr)[source]

Set any argument to an attribute of n if None

netallocation.utils.snapshot_weightings(n, snapshots=None)[source]
netallocation.utils.split_branches(ds, n)[source]

Split data into extendable one ports and nonextendable one ports

netallocation.utils.split_one_ports(ds, n, dim='bus')[source]

Split data into extendable one ports and nonextendable one ports

netallocation.utils.upper(ds)[source]

Clip all negative entries of a xr.Dataset/xr.DataArray.