Esempio n. 1
0
def test_gauss_fit():
    x = np.arange(-1, 1, 0.01)
    amplitude = 1
    center = 0
    sigma = 1
    true_val = [amplitude, center, sigma]
    y = amplitude / np.sqrt(2 * np.pi) / sigma * np.exp(-(x - center)**2 / 2 / sigma**2)

    g = gaussian_model('',
                       1, 'fixed', [0, 1],
                       0.1, 'free', [0, 0.5],
                       0.5, 'free', [0, 1])

    result, yfit = fit_engine(g, x, y)

    out = result.values
    fitted_val = (out['amplitude'], out['center'], out['sigma'])
    assert_array_almost_equal(true_val, fitted_val)
Esempio n. 2
0
def test_lorentzian2_fit():
    x = np.arange(-1, 1, 0.01)
    area = 1
    center = 0
    sigma = 1
    true_val = [area, center, sigma]

    y = (area/(1 + ((x - center) / sigma)**2)**2) / (np.pi * sigma)

    m = lorentzian2_model('',
                          0.8, 'wrong', [0, 1],
                          0.1, 'free', [0, 0.5],
                          0.5, 'free', [0, 1])

    result, yfit = fit_engine(m, x, y)
    out = result.values

    fitted_val = (out['area'], out['center'], out['sigma'])
    assert_array_almost_equal(true_val, fitted_val)
Esempio n. 3
0
def test_lorentzian_fit():
    x = np.arange(-1, 1, 0.01)
    amplitude = 1
    center = 0
    sigma = 1
    true_val = [amplitude, center, sigma]

    y = (amplitude/(1 + ((x - center) / sigma)**2)) / (np.pi * sigma)

    m = lorentzian_model('',
                         0.8, 'free', [0, 1],
                         0.1, 'free', [0, 0.5],
                         0.8, 'bounded', [0, 2])

    result, yfit = fit_engine(m, x, y)
    out = result.values

    fitted_val = (out['amplitude'], out['center'], out['sigma'])
    assert_array_almost_equal(true_val, fitted_val)
Esempio n. 4
0
def test_quadratic_fit():
    x = np.arange(-1, 1, .01)
    a = 1
    b = 2
    c = 3

    true_val = [a, b, c]

    y = a * x*x + b * x + c

    m = quadratic_model('',
                        a, 'free', [-1, 1],
                        b, 'free', [-1, 1],
                        c, 'free', [-1, 1])

    result, yfit = fit_engine(m, x, y)
    out = result.values
    fitted_val = (out['a'], out['b'], out['c'])
    assert_array_almost_equal(true_val, fitted_val)