def gausspars(fwhm, nsigma=1.5, ratio=1, theta=0.):
    """
        height - the amplitude of the gaussian
        x0, y0, - center of the gaussian
        fwhm - full width at half maximum of the observation
        nsigma - cut the gaussian at nsigma
        ratio = ratio of xsigma/ysigma
        theta - angle of position angle of the major axis measured
        counter-clockwise from the x axis

        Returns dimensions nx and ny of the elliptical kernel as well as the
        ellipse parameters a, b, c, and f when defining an ellipse through the
        quadratic form: a*(x-x0)^2+b(x-x0)*(y-y0)+c*(y-y0)^2 <= 2*f
    """

    xsigma = fwhm / FWHM2SIG
    ysigma = ratio * xsigma

    f = nsigma**2/2.

    theta = np.deg2rad(theta)
    cost  = np.cos(theta)
    sint  = np.sin(theta)

    if ratio == 0: # 1D Gaussian

        if theta == 0 or theta == 180:
            a = 1/xsigma**2
            b = 0.0
            c = 0.0
        elif theta  == 90:
            a = 0.0
            b = 0.0
            c = 1/xsigma**2
        else:
            print('Unable to construct 1D Gaussian with these parameters\n')
            raise ValueError

        nx = 2 * int(max(2, (xsigma*nsigma*np.abs(cost))))+1
        ny = 2 * int(max(2, (xsigma*nsigma*np.abs(sint))))+1

    else: #2D gaussian

        xsigma2 = xsigma * xsigma
        ysigma2 = ysigma * ysigma

        a = cost**2/xsigma2 + sint**2/ysigma2
        b = 2 * cost * sint *(1.0/xsigma2-1.0/ysigma2)
        c = sint**2/xsigma2 + cost**2/ysigma2

        d = b**2 - 4*a*c # discriminant

        #        nx = int(2*max(2, math.sqrt(-8*c*f/d)))+1
        #        ny = int(2*max(2, math.sqrt(-8*a*f/d)))+1
        nx = 2 * int(2*max(1, nsigma*math.sqrt(-c/d)))+1
        ny = 2 * int(2*max(1, nsigma*math.sqrt(-a/d)))+1

    return nx, ny, a, b, c, f
height - the amplitude of the gaussian
        x0, y0, - center of the gaussian
        fwhm - full width at half maximum of the observation
        nsigma - cut the gaussian at nsigma
        ratio = ratio of xsigma/ysigma
        theta - angle of position angle of the major axis measured
        counter-clockwise from the x axis

        Returns dimensions nx and ny of the elliptical kernel as well as the
        ellipse parameters a, b, c, and f when defining an ellipse through the
        quadratic form: a*(x-x0)^2+b(x-x0)*(y-y0)+c*(y-y0)^2 <= 2*f