geocat.comp.climatologies.climatology#

geocat.comp.climatologies.climatology(dset, freq, time_coord_name=None, keep_attrs=None)#

Deprecated since version 2023.02.0: The climatology function is deprecated due to inaccuracies in monthly climatology calculations and when using monthly data to calculate seasonal or yearly climatologies. Use climatology_average instead.

Compute climatologies for a specified time frequency.

Parameters
  • dset (xarray.Dataset, xarray.DataArray) – The data on which to operate

  • freq (str) – Climatology frequency alias. Accepted alias:

    • day: for daily climatologies

    • month: for monthly climatologies

    • year: for annual climatologies

    • `season’: for seasonal climatologies

  • time_coord_name (str, optional) – Name for time coordinate to use. Defaults to None and infers the name from the data.

  • keep_attrs (bool, optional) – If True, attrs will be copied from the original object to the new one. If False, the new object will be returned without attributes. Defaults to None which means the attrs will only be kept in unambiguous circumstances.

Returns

computed_dset (xarray.Dataset, xarray.DataArray) – The computed climatology data

Examples

>>> import xarray as xr
>>> import pandas as pd
>>> import numpy as np
>>> import geocat.comp
>>> # Create toy data set
>>> dates = pd.date_range(start="2000/01/01",
...                       freq="M",
...                       periods=24)
>>> ts = xr.DataArray(np.arange(24).reshape(24, 1, 1),
...                   dims=["time", "lat", "lon"],
...                   coords={"time": dates})
>>> ts
<xarray.DataArray (time: 24, lat: 1, lon: 1)>
array([[[ 0]],
    [[ 1]],
    [[ 2]],

    [[21]],
    [[22]],
    [[23]]])
Coordinates:
* time     (time) datetime64[ns] 2000-01-31 2000-02-29 ... 2001-12-31
Dimensions without coordinates: lat, lon
>>> # Calculate yearly climate averages
>>> geocat.comp.climatology(ts, 'year')
<xarray.DataArray (year: 2, lat: 1, lon: 1)>
array([[[ 5.5]],
    [[17.5]]])
Coordinates:
* year     (year) int64 2000 2001
Dimensions without coordinates: lat, lon
>>> # Calculate seasonal climate averages
>>> geocat.comp.climatology(ts, 'season')
<xarray.DataArray (season: 4, lat: 1, lon: 1)>
array([[[10.]],
    [[12.]],
    [[ 9.]],
    [[15.]]])
Coordinates:
* season   (season) object 'DJF' 'JJA' 'MAM' 'SON'
Dimensions without coordinates: lat, lon

See also

Related GeoCAT Functions: climatology_average

Related NCL Functions: clmDayTLL, clmDayTLLL, clmMonLLLT, clmMonLLT, clmMonTLL, clmMonTLLL, month_to_season