lair.clock.seasonal#

lair.clock.seasonal(data, statistic='mean')[source]#

Aggregate data by season and year.

Seasons are DJF, MAM, JJA and SON. DJF is labeled by the year of its January and February: DJF 2024 is Dec 2023 + Jan 2024 + Feb 2024 (December rows count towards the next year). The other seasons keep their calendar year.

Partial seasons at the edges of the data are kept, not dropped. For data covering calendar year 2024, DJF 2024 is Jan-Feb 2024 only and DJF 2025 is Dec 2024 only.

Parameters:
  • data (pd.DataFrame) – The data to aggregate. Panda DataFrame with a DateTimeIndex.

  • statistic (str, optional) – The statistic to compute for each group. Default is ‘mean’.

Returns:

pd.DataFrame – The aggregated data, indexed by (season, year).

Return type:

DataFrame

See also

SEASONS

The season of each month.

diurnal

Aggregates by the time of day.

Examples

Monthly data for 2024, where each month’s value is its number minus one:

>>> import numpy as np
>>> import pandas as pd
>>> from lair.clock import seasonal
>>> months = pd.date_range("2024-01-01", periods=12, freq="MS")
>>> seasons = seasonal(pd.DataFrame({"value": np.arange(12.0)}, index=months))
>>> [f"{season} {year}" for season, year in seasons.index]
['DJF 2024', 'MAM 2024', 'JJA 2024', 'SON 2024', 'DJF 2025']
>>> seasons["value"].tolist()
[0.5, 3.0, 6.0, 9.0, 11.0]