Fit the log of the input to the log of a gaussian.

    Parameters
    ----------
    X: 1d array
        X values
    Y: 1d array
        Y values

    Returns
    -------
    mean: number
        The mean of the gaussian curve
    var: number
        The variance of the gaussian curve

    Notes
    -----
    The least square method is used.
    As this is a log, make sure the amplitude is >> noise

    See the gausslog_sympy.py file for explaination

def gauss_fit_log(X, Y):
    """
    Fit the log of the input to the log of a gaussian.

    Parameters
    ----------
    X: 1d array
        X values
    Y: 1d array
        Y values

    Returns
    -------
    mean: number
        The mean of the gaussian curve
    var: number
        The variance of the gaussian curve

    Notes
    -----
    The least square method is used.
    As this is a log, make sure the amplitude is >> noise

    See the gausslog_sympy.py file for explaination
    """
    X = np.asarray(X)
    Y = np.asarray(Y)
    # take log data
    Data = np.log(Y)
    # Get Di and Xi
    D = [(Data * X**i).sum() for i in range(3)]
    X = [(X**i).sum() for i in range(5)]
    # compute numerator and denominator for mean and variance
    num = (D[0] * (X[1] * X[4] - X[2] * X[3]) +
           D[1] * (X[2]**2 - X[0] * X[4]) +
           D[2] * (X[0] * X[3] - X[1] * X[2]))
    den = 2 * (D[0] * (X[1] * X[3] - X[2]**2) +
               D[1] * (X[1] * X[2] - X[0] * X[3]) +
               D[2] * (X[0] * X[2] - X[1]**2))
    varnum = (-X[0] * X[2] * X[4] + X[0] * X[3]**2 + X[1]**2 * X[4] -
              2 * X[1] * X[2] * X[3] + X[2]**3)
    # if denominator is 0, can't do anything
    if abs(den) < 0.00001:
        #        print('Warning: zero denominator!',den)
        return np.nan, np.nan
    # compute mean and variance
    mean = num / den
    var = varnum / den
    # if variance is negative, the data are not a gaussian
    if var < 0:
        #        print('Warning: negative Variance!',var)
        return np.nan, np.nan
    return mean, var