netallocation.common module¶
Created on Wed Dec 18 17:46:45 2019
@author: fabian
- class netallocation.common.AllocationAccessor(xarray_obj)[source]¶
Bases:
object
Accessor for netallocation package.
This accessor enables to call several functions to modify, plot and store the allocation dataset.
- as_dense()¶
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
- as_sparse()¶
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
- by_carriers(n, chunksize=None)¶
Breakdown allocation into production and demand carriers.
Use this funtion to breakdown the share of single production carriers (carriers of generators, storage units, stores) and demand carriers (carriers of loads, storage units, stores). Note that carrier names of all components have to be unique. The funtion will return the a dataset or dataarray with two additional dimensions, source_carrier and sink_carrier.
- Parameters
ds (xarray.Dataset) – Allocation Data with dimension sink and source
n (pypsa.Network) – Network which the allocation was derived from
chunksize (int) – Chunksize of the snapshot chunks passed to dask for computing faster and with less memory usage for large datasets.
Example
>>> ap = ntl.flow_allocation(n, n.snapshots, method='ap') >>> ntl.breakdown.carriers(ap, n)
- filter_null(dim=None)¶
Drop all coordinates with only null/nan entries on dimensions dim.
- lower()¶
Clip all positive entries of a xr.Dataset/xr.DataArray.
- plot_chord_diagram(agg='mean', minimum_quantile=0, groups=None, size=200, pallette='Category20', fig_inches=4)¶
Build a chord diagram on the base of holoviews [1].
It visualizes allocated peer-to-peer flows for all buses given in the data. As for compatibility with ipython shell the rendering of the image is passed to matplotlib however to the disfavour of interactivity. Note that the plot becomes only meaningful for networks with N > 5, because of sparse flows otherwise.
[1] http://holoviews.org/reference/elements/bokeh/Chord.html
- Parameters
allocation (xarray.Dataset) – Dataset with ‘peer_to_peer’ variable.
lower_bound (int, default is 0) – filter small power flows by a lower bound
groups (pd.Series, default is None) – Specify the groups of your buses, which are then used for coloring. The series must contain values for all allocated buses.
size (int, default is 300) – Set the size of the holoview figure
save_path (str, default is '/tmp/chord_diagram_pypsa') – set the saving path of your figure
- upper()¶
Clip all negative entries of a xr.Dataset/xr.DataArray.
- vip_to_p2p(n, direct=False)¶
- virtual_patterns(n, q=0.5)¶
Convert a peer-on-branch-to-peer into a virtual flow/injection pattern.
If a virtual flow pattern array is already existent, nothing is done.
- Parameters
ds (xarray.Dataset or xarray.DataArray) –
n (pypsa.Network) – Underlying network. This is needed for determining the Incidence matrix.
q (float in [0,1]) – Ratio of net source and net sink contributions in the virtual patterns. If q=0 then only net importers are taken into account (if q=1 only net exporters).
- Returns
A xarray.Dataset with the virtual flow pattern variable appended if a
Dataset was passed, passes the converted DataArray if a DataArray was passed.