lair.synoptic.hourly_mean#

lair.synoptic.hourly_mean(df, speed='wind_speed_set_1', direction='wind_direction_set_1')[source]#

Hourly means of a timeseries() frame, with wind averaged as a vector.

Numeric columns are averaged over each clock hour (labeled by its start). Where speed and direction exist, Uwind/Vwind are computed per observation and averaged, and direction is replaced by the direction of the mean vector (NaN for a dead-calm hour); speed stays the scalar mean. n_obs counts the wind observations in the hour. Hours with no data are dropped. Works per station when a stid column is present.

Parameters:
  • df (pd.DataFrame) – Observations as timeseries() returns them, with a Time column.

  • speed (str, optional) – Column of wind speed. Default "wind_speed_set_1".

  • direction (str, optional) – Column of wind direction (degrees, blowing from). Default "wind_direction_set_1".

Returns:

pd.DataFrame – stid (if given), Time and the averaged columns.

Return type:

DataFrame

See also

timeseries

Returns the frame it takes.

lair.air.wind_components

Splits a wind into u and v.

lair.air.wind_direction

Turns u and v back into a direction.

Examples

Two observations in one hour, from 350 and 10 degrees, average to a wind from the north (0 degrees), where a mean of the two directions gives 180:

>>> import pandas as pd
>>> from lair.synoptic import hourly_mean
>>> obs = pd.DataFrame(
...     {
...         "Time": pd.to_datetime(
...             ["2024-01-15 12:00", "2024-01-15 12:30"], utc=True
...         ),
...         "wind_speed_set_1": [4.0, 4.0],
...         "wind_direction_set_1": [350.0, 10.0],
...     }
... )
>>> hourly = hourly_mean(obs)
>>> hourly[["wind_speed_set_1", "wind_direction_set_1", "n_obs"]].round(1)
   wind_speed_set_1  wind_direction_set_1  n_obs
0               4.0                   0.0      2