Gaussian filter generator core.

    Alternative to the :py:class:`GaussianFilter` component that can be
    used to make a non-reconfigurable resizer::

        resize = Resize()
        resize.filter(GaussianFilterCore(x_sigma=1.5))
        ...
        start(..., resize, ...)
        ...

    :keyword float x_sigma: Horizontal standard deviation parameter.

    :keyword float y_sigma: Vertical standard deviation parameter.

    :return: A :py:class:`~pyctools.core.frame.Frame` object containing the
        filter.

def GaussianFilterCore(x_sigma=0.0, y_sigma=0.0):
    """Gaussian filter generator core.

    Alternative to the :py:class:`GaussianFilter` component that can be
    used to make a non-reconfigurable resizer::

        resize = Resize()
        resize.filter(GaussianFilterCore(x_sigma=1.5))
        ...
        start(..., resize, ...)
        ...

    :keyword float x_sigma: Horizontal standard deviation parameter.

    :keyword float y_sigma: Vertical standard deviation parameter.

    :return: A :py:class:`~pyctools.core.frame.Frame` object containing the
        filter.

    """
    def filter_1D(sigma):
        alpha = 1.0 / (2.0 * (max(sigma, 0.0001) ** 2.0))
        coefs = []
        coef = 1.0
        while coef > 0.0001:
            coefs.append(coef)
            coef = math.exp(-(alpha * (float(len(coefs) ** 2))))
        fil_dim = len(coefs) - 1
        result = numpy.zeros(1 + (fil_dim * 2), dtype=numpy.float32)
        for n, coef in enumerate(coefs):
            result[fil_dim - n] = coef
            result[fil_dim + n] = coef
        # normalise result
        result /= result.sum()
        return result

    x_sigma = max(x_sigma, 0.0)
    y_sigma = max(y_sigma, 0.0)
    x_fil = filter_1D(x_sigma)
    y_fil = filter_1D(y_sigma)
    result = numpy.empty(
        [y_fil.shape[0], x_fil.shape[0], 1], dtype=numpy.float32)
    for y in range(y_fil.shape[0]):
        for x in range(x_fil.shape[0]):
            result[y, x, 0] = x_fil[x] * y_fil[y]
    out_frame = Frame()
    out_frame.data = result
    out_frame.type = 'fil'
    audit = out_frame.metadata.get('audit')
    audit += 'data = GaussianFilter()\n'
    if x_sigma != 0.0:
        audit += '    x_sigma: %g\n' % (x_sigma)
    if y_sigma != 0.0:
        audit += '    y_sigma: %g\n' % (y_sigma)
    out_frame.metadata.set('audit', audit)
    return out_frame