Пример #1
0
def nearest(a, v):
    """Alternative (not optimized) implementation of find_nearest
    Used for testing purpose only

    """
    nr = a[0]
    diff = 1e+9
    for x in a:
        if np.abs(x - v) < diff:
            nr = x
            diff = np.abs(x - v)
    return nr


def test_simple_find_nearest():
    x = np.arange(100)
    assert find_nearest(x, 75.6) == exactly(76)
    assert find_nearest(x, 75.5) == exactly(75)


def test_gauss_find_nearest():
    e = np.random.normal(100, 10, 100)

    for x in range(1, 100, 10):
        assert find_nearest(e, x) == approx(nearest(e, x), rel=1e-3)


@given(float_arrays(min_value=1, max_value=100))
def test_find_nearest(data):
    assert find_nearest(data, 10) == approx(nearest(data, 10), rel=1e-3)
Пример #2
0
    """

    maps = read_maps(map_filename)
    assert np.all(maps.chi2 == 1)
    assert np.all(maps.e0 == 13000)
    assert np.all(maps.e0u == 2)
    assert np.all(maps.lt == 5000)
    assert np.all(maps.ltu == 3)


@given(random_length_float_arrays(min_value=0, max_value=3e4))
def test_correct_geometry_properly(x):
    assert_array_equal(correct_geometry_(x), (1 / x))


@given(float_arrays(min_value=0, max_value=530),
       float_arrays(min_value=1, max_value=1e4))
def test_correct_geometry_properly(z, lt):
    compute_corr = np.exp(z / lt)
    assert_array_equal(correct_lifetime_(z, lt), compute_corr)


@given(floats(min_value=0, max_value=1e4))
def test_time_coefs_corr(map_filename, time):
    """
    In the map taken as input, none of the parameters
    changes with time, thus all outputs of
    time_coefs_corr function must be 1.
    """

    maps = read_maps(map_filename)
Пример #3
0
from .fit_functions import sigmoid
from .fit_functions import compute_drift_v
from .fit_functions import relative_errors
from .fit_functions import to_relative
from .fit_functions import fit_profile_1d_expo
from .fit_functions import fit_slices_2d_gauss
from .fit_functions import fit_slices_2d_expo

from .kr_types import Measurement
sensible_floats = floats(-1e4, +1e4)
fractions = floats(0, 1)
sensible_arrays_variable = random_length_float_arrays(1,
                                                      10,
                                                      min_value=-1e4,
                                                      max_value=1e4)
sensible_arrays_fixed = float_arrays(5, min_value=-1e4, max_value=1e4)
measurements = builds(Measurement, sensible_arrays_fixed,
                      sensible_arrays_fixed.map(abs))


def test_get_chi2f_when_data_equals_error_and_fit_equals_zero():
    Nevt = int(1e6)
    xdata = np.zeros(Nevt)  # Dummy value, not needed
    ydata = np.random.uniform(1, 100, Nevt)
    errs = ydata
    f = lambda x: np.zeros_like(x)
    chi2 = chi2f(f, 0, xdata, ydata, errs)
    assert chi2 == approx(1, rel=1e-3)


def test_get_chi2f_when_data_equals_fit():