Example #1
0
def lcls_two_bounce_system():
    """
    Simple system that consists of a source, two mirrors, and two imagers.
    """
    s = source.Undulator('test_undulator')
    m1 = mirror.OffsetMirror('test_m1h',
                             'test_m1h_xy',
                             z=90.510,
                             alpha=0.0014 * 1e6)
    m2 = mirror.OffsetMirror('test_m2h',
                             'test_m2h_xy',
                             x=0.0317324,
                             z=101.843,
                             alpha=0.0014 * 1e6)
    y1 = pim.PIM('test_p3h', x=0.0317324, z=103.660)
    y2 = pim.PIM('test_dg3', x=0.0317324, z=375.000)

    # Patch with calculated centroids
    patch_pims([y1, y2], mirrors=[m1, m2], source=s)

    # Patch with image
    yield_image_hx2 = yield_seq_beam_image(images_hx2, idx=0)
    y1.detector.image1._image = lambda: _next_image(
        y1.detector.image1.array_counter, yield_image_hx2)

    yield_image_dg3 = yield_seq_beam_image(images_dg3, idx=0)
    y2.detector.image1._image = lambda: _next_image(
        y2.detector.image1.array_counter, yield_image_dg3)

    return s, m1, m2, y1, y2
Example #2
0
def test_patch_pims_with_one_bounce_func(simple_two_bounce_system):
    s, m1, m2 = simple_two_bounce_system
    pim_1 = [pim.PIM('test_pim', name='pim_1', z=13)]
    pim_2 = [pim.PIM('test_pim', name='pim_1', z=15)]

    pim_1 = patch_pims(pim_1, [m1, m2])
    assert pim_1.detector.stats2.centroid.x.value == _m1_calc_cent_x(
        s, m1, pim_1)

    pim_2 = patch_pims(pim_2, m1)
    assert pim_2.detector.stats2.centroid.x.value == _m1_calc_cent_x(
        s, m1, pim_2)
Example #3
0
def test_patch_pims_with_no_bounce_func(simple_two_bounce_system):
    s, m1, m2 = simple_two_bounce_system
    pim_1 = [pim.PIM('test_pim', z=3)]
    pim_2 = [pim.PIM('test_pim', z=5)]
    pim_3 = [pim.PIM('test_pim', z=7)]

    pim_1 = patch_pims(pim_1)
    assert pim_1.detector.stats2.centroid.x.value == _calc_cent_x(s, pim_1)

    pim_2 = patch_pims(pim_2, m1)
    assert pim_2.detector.stats2.centroid.x.value == _calc_cent_x(s, pim_2)

    pim_3 = patch_pims(pim_3, [m1, m2])
    assert pim_3.detector.stats2.centroid.x.value == _calc_cent_x(s, pim_3)
Example #4
0
def test_pim_set_and_read(one_bounce_system):
    s, mot, pim = one_bounce_system
    set_x = 100
    set_z = 10
    pim.sim_x.put(set_x)
    pim.sim_z.put(set_z)
    pim = patch_pims(pim, [mot])
    assert pim.sim_x.value == set_x
    assert pim.sim_z.value == set_z
    assert pim.detector.stats2.centroid.x.value == _m1_calc_cent_x(s, mot, pim)
Example #5
0
def one_bounce_system():
    """
    Generic single bounce system consisting one mirror with a linear
    relationship with YAG centroid
    """
    s = source.Undulator('test_source', name='test_source')
    mot = mirror.OffsetMirror('mirror', 'mirror_xy', name='mirror', z=50)
    det = pim.PIM('yag', name='yag', z=60, size=(500, 500))
    det = patch_pims(det, mot)
    return s, mot, det
Example #6
0
def slow_lcls_two_bounce_system():
    """
    Simple system that consists of a source, two mirrors, and two imagers.
    """
    s = source.Undulator('test_undulator')
    m1 = SlowOffsetMirror('test_m1h', 'test_m1h_xy', z=90.510, alpha=0.0014)
    m2 = SlowOffsetMirror('test_m2h',
                          'test_m2h_xy',
                          x=0.0317324,
                          z=101.843,
                          alpha=0.0014)
    y1 = pim.PIM('test_p3h', x=0.0317324, z=103.660)
    y2 = pim.PIM('test_dg3', x=0.0317324, z=375.000)

    patch_pims([y1, y2], mirrors=[m1, m2], source=s)

    def make_update_pixel(yag):
        def update_pixel(*args, **kwargs):
            sig = yag.detector.stats2.centroid.x
            sig._run_subs(sub_type=sig.SUB_VALUE,
                          value=sig.value,
                          timestamp=time.time())

        return update_pixel

    # Patch with image
    yield_image_hx2 = yield_seq_beam_image(images_hx2, idx=0)
    y1.detector.image1._image = lambda: _next_image(
        y1.detector.image1.array_counter, yield_image_hx2)

    yield_image_dg3 = yield_seq_beam_image(images_dg3, idx=0)
    y2.detector.image1._image = lambda: _next_image(
        y2.detector.image1.array_counter, yield_image_dg3)

    m1.subscribe(make_update_pixel(y1), m1.SUB_READBACK)
    m2.subscribe(make_update_pixel(y2), m2.SUB_READBACK)

    m1.high_limit = 2000
    m1.low_limit = 1000
    m2.high_limit = 2000
    m2.low_limit = 1000

    return s, m1, m2, y1, y2
Example #7
0
def lcls_two_bounce_system():
    """
    Simple system that consists of a source, two mirrors, and two imagers.
    """
    s = source.Undulator('test_undulator', name='test_undulator')
    m1 = mirror.OffsetMirror('test_m1h',
                             'test_m1h_xy',
                             name='test_m1h',
                             z=90.510,
                             alpha=0.0014 * 1e6)
    m2 = mirror.OffsetMirror('test_m2h',
                             'test_m2h_xy',
                             name='test_m2h',
                             x=0.0317324,
                             z=101.843,
                             alpha=0.0014 * 1e6)
    y1 = pim.PIM('test_p3h', name='test_p3h', x=0.0317324, z=103.660)
    y2 = pim.PIM('test_dg3', name='test_dg3', x=0.0317324, z=375.000)

    # Patch with calculated centroids
    patch_pims([y1, y2], mirrors=[m1, m2], source=s)

    return s, m1, m2, y1, y2
Example #8
0
def slow_lcls_two_bounce_system():
    """
    Simple system that consists of a source, two mirrors, and two imagers.
    """
    s = source.Undulator('test_undulator', name='test_undulator')
    m1 = SlowOffsetMirror('test_m1h',
                          'test_m1h_xy',
                          name='test_m1h',
                          z=90.510,
                          alpha=0.0014)
    m2 = SlowOffsetMirror('test_m2h',
                          'test_m2h_xy',
                          name='test_m2h',
                          x=0.0317324,
                          z=101.843,
                          alpha=0.0014)
    y1 = pim.PIM('test_p3h', name='test_p3h', x=0.0317324, z=103.660)
    y2 = pim.PIM('test_dg3', name='test_dg3', x=0.0317324, z=375.000)

    patch_pims([y1, y2], mirrors=[m1, m2], source=s)

    def make_update_pixel(yag):
        def update_pixel(*args, **kwargs):
            sig = yag.detector.stats2.centroid.x
            sig._run_subs(sub_type=sig.SUB_VALUE,
                          value=sig.value,
                          timestamp=time.time())

        return update_pixel

    m1.subscribe(make_update_pixel(y1), m1.SUB_READBACK)
    m2.subscribe(make_update_pixel(y2), m2.SUB_READBACK)

    m1.pitch._limits = (1000, 2000)
    m2.pitch._limits = (1000, 2000)

    return s, m1, m2, y1, y2
Example #9
0
                 name='test_p3h',
                 zero_outside_yag=True)
y2 = sim.pim.PIM('test_dg3',
                 x=0.0317324,
                 z=375.000,
                 name='test_dg3',
                 zero_outside_yag=True)
mecy1 = sim.pim.PIM('test_mecy1',
                    x=0.0317324,
                    z=350,
                    name='test_mect1',
                    zero_outside_yag=True)
mfxdg1 = mecy1

#Create simulation with proper distances
patch_pims([y1, y2], mirrors=[m1, m2], source=s)
patch_pims([mecy1], mirrors=[xrtm2], source=s)

#Pseudo-config
sim_config = {
    'sim_m1h': {
        'mirror': m1,
        'imager': y1,
        'rotation': 0,
        'slits': None
    },
    'sim_m2h': {
        'mirror': m2,
        'imager': y2,
        'rotation': 0,
        'slits': None
Example #10
0
def test_patch_pims_with_two_bounce_func(simple_two_bounce_system):
    s, m1, m2 = simple_two_bounce_system
    pim_1 = [pim.PIM('test_pim', z=25)]
    pim_1 = patch_pims(pim_1, [m1, m2])
    assert pim_1.detector.stats2.centroid.x.value == _m1_m2_calc_cent_x(
        s, m1, m2, pim_1)