Ejemplo n.º 1
0
def test_polynom2d_guess_y0():
    """Check guess works okay: polynom2d

    What happens when y=0
    """

    mdl = basic.Polynom2D()

    for p in mdl.pars:
        if p.name == 'c':
            assert p.val == pytest.approx(1.0)
        else:
            assert p.val == pytest.approx(0.0)

        assert p.min == pytest.approx(-hugeval)
        assert p.max == pytest.approx(hugeval)

    x = np.asarray([1, 2, 30])
    y = np.asarray([-2, 4, -2])
    z = np.asarray([0, 0, 0])

    mdl.guess(z, x, y)

    # This is a regression test
    for p in mdl.pars:
        assert p.val == pytest.approx(0.0)

    def check(par, maxval):
        assert par.min == pytest.approx(-maxval)
        assert par.max == pytest.approx(maxval)

    for par in mdl.pars:
        check(par, 0)
Ejemplo n.º 2
0
def test_basic_unop_abs():

    cpt = basic.Polynom2D()
    mdl = abs(cpt)

    assert mdl.name == 'abs(polynom2d)'
    assert mdl.op == np.absolute
    assert mdl.ndim == 2
Ejemplo n.º 3
0
def test_basic_unop_abs_raw():

    cpt = basic.Polynom2D()
    mdl = UnaryOpModel(cpt, np.absolute, 'foo')

    assert mdl.name == 'foo(polynom2d)'
    assert mdl.op == np.absolute
    assert mdl.ndim == 2
Ejemplo n.º 4
0
def test_basic_unop_neg():

    cpt = basic.Polynom2D()
    mdl = -cpt

    assert mdl.name == '-(polynom2d)'
    assert mdl.op == np.negative
    assert mdl.ndim == 2
Ejemplo n.º 5
0
def test_basic_unop_neg_raw():

    cpt = basic.Polynom2D()
    mdl = UnaryOpModel(cpt, np.negative, '<->')

    assert mdl.name == '<->(polynom2d)'
    assert mdl.op == np.negative
    assert mdl.ndim == 2
Ejemplo n.º 6
0
def test_basic_binop(op, opstr):

    l = basic.Polynom2D()
    r = basic.Gauss2D()
    mdl = op(l, r)

    assert isinstance(mdl, BinaryOpModel)
    assert mdl.name == '(polynom2d {} gauss2d)'.format(opstr)
    assert mdl.op == op
    assert len(mdl.parts) == 2
    assert mdl.parts[0] == l
    assert mdl.parts[1] == r
    assert mdl.ndim == 2
Ejemplo n.º 7
0
def test_basic_binop_raw(op):

    l = basic.Polynom2D()
    r = basic.Gauss2D()
    mdl = BinaryOpModel(l, r, op, 'xOx')

    assert isinstance(mdl, BinaryOpModel)
    assert mdl.name == '(polynom2d xOx gauss2d)'
    assert mdl.op == op
    assert len(mdl.parts) == 2
    assert mdl.parts[0] == l
    assert mdl.parts[1] == r
    assert mdl.ndim == 2
Ejemplo n.º 8
0
def test_polynom2d_guess_ymax0():
    """Check guess works okay: polynom2d

    What happens when ymax=0
    """

    mdl = basic.Polynom2D()

    for p in mdl.pars:
        if p.name == 'c':
            assert p.val == pytest.approx(1.0)
        else:
            assert p.val == pytest.approx(0.0)

        assert p.min == pytest.approx(-hugeval)
        assert p.max == pytest.approx(hugeval)

    x = np.asarray([1, 2, 30])
    y = np.asarray([-2, 4, -2])
    z = np.asarray([-10, -12, 0])

    mdl.guess(z, x, y)

    # This is a regression test
    for p in mdl.pars:
        if p.name == 'c':
            assert p.val == pytest.approx(-6.0)
        else:
            assert p.val == pytest.approx(0.0)

    for par in [mdl.c, mdl.cx1y2, mdl.cx2y1, mdl.cx2y2]:
        assert par.min == pytest.approx(-12)
        assert par.max == pytest.approx(0)

    def check(par, maxval):
        assert par.min == pytest.approx(-maxval)
        assert par.max == pytest.approx(maxval)

    check(mdl.cy1, 200)
    check(mdl.cy2, 33.33333333333333)
    check(mdl.cx1, 41.37931034482759)
    check(mdl.cx2, 1.426872770511296)
    check(mdl.cx1y1, 6.896551724137931)
Ejemplo n.º 9
0
def test_polynom2d_guess():
    """Check guess works okay: polynom2d"""

    mdl = basic.Polynom2D()

    for p in mdl.pars:
        if p.name == 'c':
            assert p.val == pytest.approx(1.0)
        else:
            assert p.val == pytest.approx(0.0)

        assert p.min == pytest.approx(-hugeval)
        assert p.max == pytest.approx(hugeval)

    x = np.asarray([1, 2, 30])
    y = np.asarray([-2, 4, -2])
    z = np.asarray([10, 12, -2])

    mdl.guess(z, x, y)

    # This is a regression test
    for p in mdl.pars:
        if p.name == 'c':
            assert p.val == pytest.approx(5.0)
        else:
            assert p.val == pytest.approx(0.0)

    for par in [mdl.c, mdl.cx1y2, mdl.cx2y1, mdl.cx2y2]:
        assert par.min == pytest.approx(-2)
        assert par.max == pytest.approx(12)

    def check(par, maxval):
        assert par.min == pytest.approx(-maxval)
        assert par.max == pytest.approx(maxval)

    check(mdl.cy1, 233.33333333333334)
    check(mdl.cy2, 38.88888888888889)
    check(mdl.cx1, 48.275862068965516)
    check(mdl.cx2, 1.6646848989298455)
    check(mdl.cx1y1, 8.045977011494253)