nodes: 0, module; 1, function_definition; 2, function_name:maximum_consecutive_dry_days; 3, parameters; 4, block; 5, identifier:pr; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:thresh; 13, string; 14, identifier:freq; 15, string; 16, comment:r"""Maximum number of consecutive dry days
  
      Return the maximum number of consecutive days within the period where precipitation
      is below a certain threshold.
  
      Parameters
      ----------
      pr : xarray.DataArray
        Mean daily precipitation flux [mm]
      thresh : str
        Threshold precipitation on which to base evaluation [mm]. Default : '1 mm/day'
      freq : str, optional
        Resampling frequency
  
      Returns
      -------
      xarray.DataArray
        The maximum number of consecutive dry days.
  
      Notes
      -----
      Let :math:`\mathbf{p}=p_0, p_1, \ldots, p_n` be a daily precipitation series and :math:`thresh` the threshold
      under which a day is considered dry. Then let :math:`\mathbf{s}` be the sorted vector of indices :math:`i` where
      :math:`[p_i < thresh] \neq [p_{i+1} < thresh]`, that is, the days when the temperature crosses the threshold.
      Then the maximum number of consecutive dry days is given by
  
      .. math::
  
         \max(\mathbf{d}) \quad \mathrm{where} \quad d_j = (s_j - s_{j-1}) [p_{s_j} > thresh]
  
      where :math:`[P]` is 1 if :math:`P` is true, and 0 if false. Note that this formula does not handle sequences at
      the start and end of the series, but the numerical algorithm does.
      """; 17, assignment; 18, assignment; 19, call; 20, string_content:1 mm/day; 21, string_content:YS; 22, identifier:t; 23, call; 24, identifier:group; 25, call; 26, attribute; 27, argument_list; 28, attribute; 29, argument_list; 30, attribute; 31, argument_list; 32, identifier:group; 33, identifier:apply; 34, attribute; 35, keyword_argument; 36, identifier:utils; 37, identifier:convert_units_to; 38, identifier:thresh; 39, identifier:pr; 40, string; 41, parenthesized_expression; 42, identifier:resample; 43, keyword_argument; 44, identifier:rl; 45, identifier:longest_run; 46, identifier:dim; 47, string; 48, string_content:hydro; 49, comparison_operator:pr < t; 50, identifier:time; 51, identifier:freq; 52, string_content:time; 53, identifier:pr; 54, identifier:t
code: def maximum_consecutive_dry_days(pr, thresh='1 mm/day', freq='YS'):
      r"""Maximum number of consecutive dry days
  
      Return the maximum number of consecutive days within the period where precipitation
      is below a certain threshold.
  
      Parameters
      ----------
      pr : xarray.DataArray
        Mean daily precipitation flux [mm]
      thresh : str
        Threshold precipitation on which to base evaluation [mm]. Default : '1 mm/day'
      freq : str, optional
        Resampling frequency
  
      Returns
      -------
      xarray.DataArray
        The maximum number of consecutive dry days.
  
      Notes
      -----
      Let :math:`\mathbf{p}=p_0, p_1, \ldots, p_n` be a daily precipitation series and :math:`thresh` the threshold
      under which a day is considered dry. Then let :math:`\mathbf{s}` be the sorted vector of indices :math:`i` where
      :math:`[p_i < thresh] \neq [p_{i+1} < thresh]`, that is, the days when the temperature crosses the threshold.
      Then the maximum number of consecutive dry days is given by
  
      .. math::
  
         \max(\mathbf{d}) \quad \mathrm{where} \quad d_j = (s_j - s_{j-1}) [p_{s_j} > thresh]
  
      where :math:`[P]` is 1 if :math:`P` is true, and 0 if false. Note that this formula does not handle sequences at
      the start and end of the series, but the numerical algorithm does.
      """
      t = utils.convert_units_to(thresh, pr, 'hydro')
      group = (pr < t).resample(time=freq)
  
      return group.apply(rl.longest_run, dim='time')