windkit.wd_to_sector#

windkit.wd_to_sector(wd, sectors=12, output_type='centers', quantiles=False)[source]#

Convert wind directions to 0-based sector indices.

Parameters:
  • wd (xarray.DataArray, numpy.array) – Wind directions. The function uses xarray.apply_ufunc, so the return value will keep the shape of the input value.

  • sectors (int) – Number of sectors. Defaults to 12.

  • output_type (str) – If set to ‘centers’ the values in ‘wd’ are the sector centers. If set to ‘indices’, the values in ‘wd’ are the sector indices. Defaults to ‘centers’.

  • quantiles (bool) – Allows to use equal probability sectors (quantiles=True) instead of fixed width sectors. The sector edges are the quantiles of all values in wd pooled together, so an input with several points gets one shared set of edges rather than one set per point. Unlike the fixed width layout, whose sector 0 is centred on north, quantile sector 0 starts at north. Note that this is an experimental feature to be used only together with the windkit.ltc module for now. Other windkit modules may not be compatible with non fixed width sectors. Defaults to False.

Returns:

  • sector_centers (xarray.DataArray,np.array) – wind speed sector centers.

  • sector_coords (xarray.DataArray) – data array with sector coordinates incling center, ceiling and floor.

Raises:
  • ValueError – If output_type is unknown or sectors is not positive.

  • WindkitValidationError – If quantiles=True and wd is an xarray.Dataset, has no finite values, or holds too few distinct directions to build sectors sectors with unique quantile edges.

Examples

>>> wd = xr.DataArray([355.0, 14.0, 25.0, 270.0,], dims=('time',))
>>> wd_to_sector(wd)
(<xarray.DataArray (time: 4)>
array([  0.,   0.,  30., 270.])
Dimensions without coordinates: time,
<xarray.DataArray (sector: 12)>
array([  0.,  30.,  60.,  90., 120., 150., 180., 210., 240., 270., 300.,
    330.])
Coordinates:
  * sector        (sector) float64 0.0 30.0 60.0 90.0 ... 270.0 300.0 330.0
    sector_ceil   (sector) float64 15.0 45.0 75.0 105.0 ... 285.0 315.0 345.0
    sector_floor  (sector) float64 345.0 15.0 45.0 75.0 ... 255.0 285.0 315.0)