<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def heating_degree_days(tas, thresh='17.0 degC', freq='YS'):
 r"""Heating degree days Sum of degree days below the temperature threshold at which spaces are heated. Parameters tas : xarray.DataArray Mean daily temperature [℃] or [K] thresh : str Threshold temperature on which to base evaluation [℃] or [K]. Default: '17.0 degC'. freq : str, optional Resampling frequency Returns ------- xarray.DataArray Heating degree days index. Notes ----- Let :math:`TG_{ij}` be the daily mean temperature at day :math:`i` of period :math:`j`. Then the heating degree days are: .. math:: HD17_j = \sum_{i=1}^{I} (17℃ - TG_{ij}) """

    thresh = utils.convert_units_to(thresh, tas)

    return tas.pipe(lambda x: thresh - x) \
        .clip(0) \
        .resample(time=freq) \
        .sum(dim='time')