lair.air.bin_polar#

lair.air.bin_polar(data, x='ws', wd='wd', xbins=30)[source]#

Bin data into polar coordinates.

Parameters:
  • data (pd.DataFrame) – Data to bin.

  • x (str, optional) – Variable to bin. Default is ‘ws’.

  • wd (str, optional) – Wind direction column name. Default is ‘wd’.

  • xbins (int | list, optional) – Bin edges for x. An int is the number of evenly spaced edges from the minimum to the maximum of x (so xbins - 1 bins); a list gives the edges explicitly. Default is 30.

Returns:

pd.DataFrame – A copy of data with binned wind direction and speed added as wd_bin (compass sector), radian_bin and x_bin. The caller’s frame is not modified.

Return type:

DataFrame

See also

WIND_SECTORS

The sectors.

sector_radians

The sectors in radians, the radian_bin values.

circularize_radial_data

Closes the circle of the aggregated bins for a plot.

lair.plotter.polarPlot

Draws the binned data.

Examples

A wind at 350 and one at 10 degrees are both in the N sector; the speed is put in the bin whose upper edge is given:

>>> import pandas as pd
>>> from lair.air import bin_polar
>>> df = pd.DataFrame({"ws": [1.0, 2.5, 4.0], "wd": [350.0, 10.0, 95.0]})
>>> binned = bin_polar(df, xbins=[0, 2, 4])
>>> binned[["wd_bin", "x_bin"]].astype(str)
  wd_bin x_bin
0      N     2
1      N     4
2      E     4