code: def mixed_layer(p, *args, **kwargs):
      r
      # Pull out keyword arguments, remove when we drop Python 2.7
      heights = kwargs.pop('heights', None)
      bottom = kwargs.pop('bottom', None)
      depth = kwargs.pop('depth', 100 * units.hPa)
      interpolate = kwargs.pop('interpolate', True)
  
      layer = get_layer(p, *args, heights=heights, bottom=bottom,
                        depth=depth, interpolate=interpolate)
      p_layer = layer[0]
      datavars_layer = layer[1:]
  
      ret = []
      for datavar_layer in datavars_layer:
          actual_depth = abs(p_layer[0] - p_layer[-1])
          ret.append((-1. / actual_depth.m) * np.trapz(datavar_layer, p_layer)
                     * datavar_layer.units)
      return ret
docs: r"""Mix variable(s) over a layer, yielding a mass-weighted average.
  
      This function will integrate a data variable with respect to pressure and determine the
      average value using the mean value theorem.
  
      Parameters
      ----------
      p : array-like
          Atmospheric pressure profile
      datavar : array-like
          Atmospheric variable measured at the given pressures
      heights: array-like, optional
          Atmospheric heights corresponding to the given pressures (default None)
      bottom : `pint.Quantity`, optional
          The bottom of the layer as a pressure or height above the surface pressure
          (default None)
      depth : `pint.Quantity`, optional
          The thickness of the layer as a pressure or height above the bottom of the layer
          (default 100 hPa)
      interpolate : bool, optional
          Interpolate the top and bottom points if they are not in the given data
  
      Returns
      -------
      `pint.Quantity`
          The mixed value of the data variable.