windkit.wind.wd_to_sector

windkit.wind.wd_to_sector(wd, bins=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.

  • bins (int) – Number of bins / 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. Note that this is an experimental feature to be used only together with the widkit.mcp module for now. Other WindKit modules may not be compatible with non fixed width sectors. Defaults to False.

Returns:

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

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

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)