Exemplo n.º 1
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))
def test_cross_calibrate():
    reference_file_name = get_data_file("FilmCalib.prs")
    measured_file_name = get_data_file("FilmCalib_EBT_vert_strip.png")

    cal_curve = Profile().cross_calibrate(reference_file_name,
                                          measured_file_name)
    assert min(cal_curve.x) <= 1
    assert max(cal_curve.x) >= 0
Exemplo n.º 3
0
def test_cross_calibrate():
    data_directory = os.path.abspath(os.path.dirname(__file__))
    data_directory = os.path.join(data_directory, "data")
    reference_file_name = os.path.join(data_directory, "FilmCalib.prs")
    measured_file_name = os.path.join(data_directory,
                                      "FilmCalib_EBT_vert_strip.png")
    cal_curve = Profile().cross_calibrate(reference_file_name,
                                          measured_file_name)
    assert min(cal_curve.x) <= 1
    assert max(cal_curve.x) >= 0
Exemplo n.º 4
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)
Exemplo n.º 5
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])
def test_from_snc_profiler():
    file_name = get_data_file("test_varian_open.prs")

    x_profile = Profile().from_snc_profiler(file_name, "tvs")
    y_profile = Profile().from_snc_profiler(file_name, "rad")
    assert np.isclose(x_profile.get_y(0), 45.50562901780488)
    assert np.isclose(y_profile.get_y(0), 45.50562901780488)
    assert x_profile.meta["SSD"] == y_profile.meta["SSD"]
Exemplo n.º 7
0
def test_from_snc_profiler():
    data_directory = os.path.abspath(os.path.dirname(__file__))
    data_directory = os.path.join(data_directory, "data")
    file_name = os.path.join(data_directory, "test_varian_open.prs")
    x_profile = Profile().from_snc_profiler(file_name, "tvs")
    y_profile = Profile().from_snc_profiler(file_name, "rad")
    assert np.isclose(x_profile.get_y(0), 45.50562901780488)
    assert np.isclose(y_profile.get_y(0), 45.50562901780488)
    assert x_profile.meta["SSD"] == y_profile.meta["SSD"]
Exemplo n.º 8
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))
Exemplo n.º 9
0
def test_init():
    assert np.allclose(Profile(x=[0], y=[0]).x, [0])
Exemplo n.º 10
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
Exemplo n.º 11
0
def test_from_pulse():
    pulse = 4 * Profile().from_pulse(0.0, 1, (-5, 5), 0.1)
    assert np.isclose(sum(pulse.y), 40)
Exemplo n.º 12
0
def test_align_to():
    profiler = Profile().from_tuples(PROFILER)
    assert np.isclose(
        profiler.align_to(profiler + (2)).x[0], profiler.x[0] + 2)
Exemplo n.º 13
0
def test_make_centered():
    profiler = Profile().from_tuples(PROFILER)
    assert np.isclose(np.sum(profiler.make_centered().get_edges()), 0.0)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
0
def test_from_lists():
    empty = Profile()
    also_empty = empty
    also_empty.from_lists([], [])
    assert empty == also_empty
Exemplo n.º 17
0
def test_get_increment():
    profiler = Profile().from_tuples(PROFILER)
    assert np.isclose(profiler.get_increment(), 0.4)
Exemplo n.º 18
0
def test_get_x():
    profiler = Profile().from_tuples(PROFILER)
    assert np.allclose(profiler.get_x(10), (-5.17742830712, 5.1740693196))
Exemplo n.º 19
0
def test_get_y():
    profiler = Profile().from_tuples(PROFILER)
    assert np.isclose(profiler.get_y(0), 45.23)
Exemplo n.º 20
0
def test_from_narrow_png():
    data_directory = os.path.abspath(os.path.dirname(__file__))
    data_directory = os.path.join(data_directory, "data")
    file_name = os.path.join(data_directory, "FilmCalib_EBT_vert_strip.png")
    png = Profile().from_narrow_png(file_name)
    assert np.isclose(png.get_y(0), 0.609074819347117)
Exemplo n.º 21
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))
Exemplo n.º 22
0
def test_interp():
    assert Profile().interp is None
    assert np.isclose(Profile(x=[0, 1], y=[0, 1]).interp(0.5), 0.5)
Exemplo n.º 23
0
def test_get_flatness():
    profiler = Profile().from_tuples(PROFILER)
    profiler = profiler.resample_x(0.1)
    assert np.isclose(profiler.get_flatness(), 0.03042644213284108)
Exemplo n.º 24
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)
Exemplo n.º 25
0
def test_make_symmetric():
    profiler = Profile().from_tuples(PROFILER)
    assert np.isclose(profiler.make_symmetric().get_symmetry(), 0.0)
Exemplo n.º 26
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)
Exemplo n.º 27
0
def test_make_flipped():
    profiler = Profile().from_tuples(PROFILER)
    assert np.isclose(profiler.get_y(3), profiler.make_flipped().get_y(-3))
Exemplo n.º 28
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)
Exemplo n.º 29
0
def test_resample_y():
    profiler = Profile().from_tuples(PROFILER)
    assert len(profiler.resample_y(0.5)) > len(profiler.resample_y(1))
Exemplo n.º 30
0
def test_from_tuples():
    empty = Profile()
    profiler = empty.from_tuples(PROFILER)
    assert len(profiler.x) == len(PROFILER)
    assert profiler.x[0] == PROFILER[0][0]