code: def tg_mean(tas, freq='YS'):
      r
  
      arr = tas.resample(time=freq) if freq else tas
      return arr.mean(dim='time', keep_attrs=True)
docs: r"""Mean of daily average temperature.
  
      Resample the original daily mean temperature series by taking the mean over each period.
  
      Parameters
      ----------
      tas : xarray.DataArray
        Mean daily temperature [℃] or [K]
      freq : str, optional
        Resampling frequency
  
      Returns
      -------
      xarray.DataArray
        The mean daily temperature at the given time frequency
  
      Notes
      -----
      Let :math:`TN_i` be the mean daily temperature of day :math:`i`, then for a period :math:`p` starting at
      day :math:`a` and finishing on day :math:`b`:
  
      .. math::
  
         TG_p = \frac{\sum_{i=a}^{b} TN_i}{b - a + 1}
  
  
      Examples
      --------
      The following would compute for each grid cell of file `tas.day.nc` the mean temperature
      at the seasonal frequency, ie DJF, MAM, JJA, SON, DJF, etc.:
  
      >>> t = xr.open_dataset('tas.day.nc')
      >>> tg = tm_mean(t, freq="QS-DEC")