<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def tg_mean(tas, freq='YS'):
 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.: """


    arr = tas.resample(time=freq) if freq else tas
    return arr.mean(dim='time', keep_attrs=True)