def refine_pixel(func, subsample, yx_pixel, yx, **kwargs):
    """Subsample an array-generating function over a pixel.

    The function is numerically averaged over the area.

    Parameters
    ----------
    func : function
      The array-generating function.  The first argument must be
      `shape`.  See `xarray` for an example.
    subsample : int
      The subsample factor.
    yx_pixel : array of int
      The coordinates of the pixel to consider.
    yx : array
      The function's origin.
    **kwargs
      Keyword arguments to pass on to `func`.

    Returns
    -------
    f : float
      The average pixel value over the subsampled area.

    Example
    -------
    >>> import numpy as np
    >>> from sbpy.imageanalysis.utils import rarray, refine_pixel
    >>> yx = (2, 2)  # the center of the radial array
    >>> r = rarray((5, 5), yx=yx)
    >>> r[2, 2]
    0.0
    >>> f = refine_pixel(rarray, 10, (2, 2), yx)
    >>> np.isclose(f, 0.03826, rtol=0.01, atol=0.01)
    True
    """
    import numpy as np
    yx_s = (np.array(yx) - np.array(yx_pixel) + 0.5) * subsample - 0.5
    f = func((subsample, subsample), yx=yx_s, **kwargs) / subsample ** 2
    return f.mean()
