Пример #1
0
def test_magic_methods():
    assert not Profile()
    # __len__
    assert len(profile_from.tuples(PROFILER)) == 83
    # __eq__
    assert Profile() == Profile()
    assert Profile(x=[], y=[]) == Profile()
    assert Profile(x=[0], y=[0]) != Profile()
    # __copy__
    original = Profile()
    same = original
    assert same == original
    # __str__
    empty_profile = Profile()
    print(empty_profile)
    profiler = profile_from.tuples(PROFILER)
    assert profiler.__str__()
    # __add__, __radd__, __iadd__
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.get_y(0), (profiler + 2).get_y(2))
    # __sub__, __rsub__, __isub__
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.get_y(0), (profiler - 2).get_y(-2))
    # __mul__, __rmul__, __imul__
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(4 * sum(profiler.y), sum((4 * profiler).y))
    assert np.isclose(4 * sum(profiler.y), sum((profiler * 4).y))
    ref = 4 * sum(profiler.y)
    profiler *= 4
    assert np.isclose(sum(profiler.y), ref)
Пример #2
0
def test_slice_penumbra():
    profiler = profile_from.tuples(PROFILER).resample_x(0.1)
    lt_penum, rt_penum = profiler.slice_penumbra()
    assert np.all(lt_penum.x < 0)
    assert np.all(rt_penum.x > 0)
    assert np.all(lt_penum.y < profiler.get_y(0))
    assert np.all(rt_penum.y < profiler.get_y(0))
Пример #3
0
def test_slice_segment():
    profiler = profile_from.tuples(PROFILER)
    # NO POINTS
    no_points = profiler.slice_segment(start=1, stop=0)
    assert np.array_equal(no_points.x, [])
    assert np.array_equal(no_points.y, [])
    # ONE POINT
    profiler = profile_from.tuples(PROFILER)
    one_point = profiler.slice_segment(start=0, stop=0)
    assert np.array_equal(one_point.x, [0])
    assert np.array_equal(one_point.y, [45.23])
    # ALL POINTS
    profiler = profile_from.tuples(PROFILER)
    all_points = profiler.slice_segment()
    assert np.array_equal(all_points.x, profiler.x)
    assert np.array_equal(all_points.y, profiler.y)
Пример #4
0
def test_resample_x():
    profiler = profile_from.tuples(PROFILER, meta={'depth': 10})
    assert profiler.meta['depth'] == 10
    assert np.isclose(profiler.interp(0), profiler.resample_x(0.1).interp(0))
    assert np.isclose(profiler.interp(6.372),
                      profiler.resample_x(0.1).interp(6.372))
    resampled = profiler.resample_x(0.1)
    increments = np.diff([i for i in resampled.x])
    assert np.allclose(increments, 0.1)
    assert np.isclose(resampled.y[0], profiler.y[0])
Пример #5
0
def test_get_flatness():
    profiler = profile_from.tuples(PROFILER)
    profiler = profiler.resample_x(0.1)
    assert np.isclose(profiler.get_flatness(), 0.03042644213284108)
Пример #6
0
def test_slice_tails():
    profiler = profile_from.tuples(PROFILER).resample_x(0.1)
    lt_tail, rt_tail = profiler.slice_tails()
    assert np.all(lt_tail.x < min(rt_tail.x))
    assert np.all(rt_tail.x > max(lt_tail.x))
Пример #7
0
def test_slice_shoulders():
    profiler = profile_from.tuples(PROFILER).resample_x(0.1)
    lt_should, rt_should = profiler.slice_shoulders()
    assert np.all(lt_should.x < min(rt_should.x))
    assert np.all(rt_should.x > max(lt_should.x))
Пример #8
0
def test_get_y():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.get_y(0), 45.23)
Пример #9
0
def test_align_to():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(
        profiler.align_to(profiler + (2)).x[0], profiler.x[0] + 2)
Пример #10
0
def test_make_centered():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(np.sum(profiler.make_centered().get_edges()), 0.0)
Пример #11
0
def test_make_normal_y():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.make_normal_y(x=0).get_y(0), 1.0)
Пример #12
0
def test_resample_y():
    profiler = profile_from.tuples(PROFILER)
    assert len(profiler.resample_y(0.5)) > len(profiler.resample_y(1))
Пример #13
0
def test_get_increment():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.get_increment(), 0.4)
Пример #14
0
def test_get_x():
    profiler = profile_from.tuples(PROFILER)
    assert np.allclose(profiler.get_x(10), (-5.17742830712, 5.1740693196))
Пример #15
0
def test_get_symmetry():
    profiler = profile_from.tuples(PROFILER)
    profiler = profiler.resample_x(0.1)
    symmetry = profiler.get_symmetry()
    assert np.isclose(symmetry, 0.024152376510553037)
Пример #16
0
def test_make_symmetric():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.make_symmetric().get_symmetry(), 0.0)
Пример #17
0
def test_get_edges():
    profiler = profile_from.tuples(PROFILER)
    assert np.allclose(profiler.get_edges(), (-5.2, 4.8))
    assert len(profiler) == len(PROFILER)
Пример #18
0
def test_make_flipped():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.get_y(3), profiler.make_flipped().get_y(-3))
Пример #19
0
def test_make_normal_x():
    profiler = profile_from.tuples(PROFILER)
    assert np.isclose(profiler.make_normal_x().x[0], -3.1538461538461533)
    profiler = profile_from.tuples(PROFILER)
    assert len(PROFILER) == len(profiler.make_normal_x().x)
Пример #20
0
def test_slice_umbra():
    profiler = profile_from.tuples(PROFILER).resample_x(0.1)
    profiler_length = len(profiler)
    umbra = profiler.slice_umbra()
    assert len(umbra) < profiler_length
Пример #21
0
def test_fromtuples():
    profiler = profile_from.tuples(PROFILER)
    assert len(profiler.x) == len(PROFILER)
    assert profiler.x[0] == PROFILER[0][0]