Example #1
0
def test_ufloat():
    """Test of ufloat from uncertainties."""
    x = ufloat(1, 0.1)
    assert_allclose(x.nominal_value, 1.0, rtol=1.e-7)
    assert_allclose(x.std_dev, 0.1, rtol=1.e-7)

    y = x * x
    assert_allclose(y.nominal_value, 1.0, rtol=1.e-7)
    assert_allclose(y.std_dev, 0.2, rtol=1.e-7)

    y = x - x
    assert_allclose(y.nominal_value, 0.0, rtol=1.e-7)
    assert_allclose(y.std_dev, 0.0, rtol=1.e-7)
Example #2
0
def params2group(params, paramgroup):
    """fill Parameter objects in paramgroup with
    values from lmfit.Parameters
    """
    for name, param in params.items():
        this = getattr(paramgroup, name, None)
        if is_param(this):
            for attr in ('value', 'vary', 'stderr', 'min', 'max', 'expr',
                         'name', 'correl', 'brute_step', 'user_data'):
                setattr(this, attr, getattr(param, attr, None))
            if this.stderr is not None:
                try:
                    this.uvalue = ufloat((this.value, this.stderr))
                except:
                    pass