code: def base_flow_index(q, freq='YS'):
      r
  
      m7 = q.rolling(time=7, center=True).mean().resample(time=freq)
      mq = q.resample(time=freq)
  
      m7m = m7.min(dim='time')
      return m7m / mq.mean(dim='time')
docs: r"""Base flow index
  
      Return the base flow index, defined as the minimum 7-day average flow divided by the mean flow.
  
      Parameters
      ----------
      q : xarray.DataArray
        Rate of river discharge [m³/s]
      freq : str, optional
        Resampling frequency
  
      Returns
      -------
      xarray.DataArrray
        Base flow index.
  
      Notes
      -----
      Let :math:`\mathbf{q}=q_0, q_1, \ldots, q_n` be the sequence of daily discharge and :math:`\overline{\mathbf{q}}`
      the mean flow over the period. The base flow index is given by:
  
      .. math::
  
         \frac{\min(\mathrm{CMA}_7(\mathbf{q}))}{\overline{\mathbf{q}}}
  
  
      where :math:`\mathrm{CMA}_7` is the seven days moving average of the daily flow:
  
      .. math::
  
         \mathrm{CMA}_7(q_i) = \frac{\sum_{j=i-3}^{i+3} q_j}{7}