Exemple #1
0
def test_circle_fit_paper():
    """
    This test was extracted from the paper: "Least-Squares Circle" Fit by Randy Bullock.

    It test correctness of the fit.
    """
    x = numpy.array([0.000, 0.500, 1.000, 1.500, 2.000, 2.500, 3.000])
    y = numpy.array([0.000, 0.250, 1.000, 2.250, 4.000, 6.250, 9.000])
    xc, yc, r = circle_fit(x,y)
    assert(xc + 11.839 < 0.001)
    assert(yc - 8.4464 < 0.0001)
    assert(r  - 14.686 < 0.001)

    # This is to check if it works also with uncertainties values
    X = unarray(x, [0.001]*len(x))
    Y = unarray(y, [0.001]*len(y))
    Xc, Yc, R = circle_fit(X,Y)

    # test the chi squared quantity
    assert(relative_difference_circle_fit(x,y,xc,yc,r)==relative_difference_circle_fit(X,Y,Xc,Yc,R))
Exemple #2
0
def test_siunitx_num():
    tc = TabularContent()
    tc.add_column(a_v, siunitx_num = False)
    try:
       tc.save('test.tmp') 
    except NotImplementedError:
        pass
        
    tc = TabularContent()
    tc.add_column(unarray(a_v, a_u), siunitx_num = False)
    try:
       tc.save('test.tmp') 
    except NotImplementedError:
        pass
Exemple #3
0
def test_column():
    tc = TabularContent()
    c1 = TabularColumn(a_v, global_unc = 6.0)
    c2 = TabularColumn(unarray(b_v, b_u), show_unc = False, unc_digits = 2)
    c3 = TabularColumn(a_v, value_digits = 1)
    c4 = TabularColumn(unarray(a_v, a_u), unc_digits = 2)
    c5 = TabularColumn(unarray(b_v, b_u), unc_digits=3)
    tc.add_column(c1)
    tc.add_column(c2)
    tc.add_column(c3)
    tc.add_column(c4)
    tc.add_column(c5)
    tc.save('test.tmp')
    assert(filecmp.cmp('test/outputs/test_column.tex', 'test.tmp'))
    
    tc = TabularContent()
    tc.add_column(b_v, global_unc = 0.00044528, unc_digits = 4)
    try:
        tc.add_column('error')
    except TypeError:
        pass
        
    tc.save('test.tmp')
    assert(filecmp.cmp('test/outputs/test_column2.tex', 'test.tmp'))
Exemple #4
0

def umodel(x, a, b):
    return unumpy.sqrt(a * x + b)


def dumodel(x, a, b):
    return a / (2 * unumpy.sqrt(a * x + b))


x = numpy.array([3., 41., 100.])
y = numpy.array([5., 15., 25.])
ux = x / 100.
uy = y / 100.

X = unarray(x, ux)
Y = unarray(y, uy)

p0 = ucurve_fit(umodel, X, Y)


def test_ucurve_fit_with_chi2():
    print(chi2(umodel, p0, X, Y))


def test_iteraed_fit_with_chi2():
    p = iterated_fit(umodel, X, Y, df=dumodel)
    assert ((p[0] - p0[0]).n < 0.01)
    assert ((p[1] - p0[1]).n < 0.01)
    print(chi2iterated(umodel, p, X, Y, df=dumodel))