esmtools.temporal.to_annual

esmtools.temporal.to_annual(ds, calendar=None, how='mean', dim='time')[source]

Resample sub-annual temporal resolution to annual resolution with weighting.

Note

Using pandas.groupby() still performs an arithmetic mean. This function properly weights, e.g., February is weighted at 28/365 if going from monthly to annual.

Parameters:
  • ds (xarray object) – Dataset or DataArray with data to be temporally averaged.
  • calendar (str) –
    Calendar type for data. If None and ds is in cftime, infer
    calendar type.
    • ’noleap’/‘365_day’: Gregorian calendar without leap years
      (all are 365 days long).
    • ’gregorian’/’standard’: Mixed Gregorian/Julian calendar. 1582-10-05 to
      1582-10-14 don’t exist, because people are crazy. Nor does year 0.
    • ’proleptic_gregorian’: A Gregorian calendar extended to dates before
      1582-10-15.
    • ’all_leap’/‘366_day’: Gregorian calendar with every year being a leap
      year (all years are 366 days long).
    • ‘360_day’: All years are 360 days divided into 30 day months.
    • ’julian’: Standard Julian calendar.
  • how (optional str) – How to convert to annual. Currently only mean is supported, but we plan to add sum as well.
  • dim (optional str) – Dimension to apply resampling over (default ‘time’).
Returns:

Dataset or DataArray resampled to annual resolution

Return type:

ds_weighted (xarray object)