Esempio n. 1
0
def test_OffsetMirror_raises_limit_error_on_oob_positions():
    om = OffsetMirror("TEST", "TEST_XY")
    om.limits = (-10, 10)
    with pytest.raises(ValueError):   
        om.move(-11)
    with pytest.raises(ValueError):   
        om.move(11)
    assert(om.move(0))
Esempio n. 2
0
def test_OffsetMirror_raises_value_error_on_invalid_positions():
    om = OffsetMirror("TEST", "TEST_XY")
    with pytest.raises(ValueError):   
        om.move(None)
    with pytest.raises(ValueError):   
        om.move(np.nan)
    with pytest.raises(ValueError):   
        om.move(np.inf)
Esempio n. 3
0
def test_OffsetMirror_noise():
    om = OffsetMirror("TEST", "TEST_XY", x=5, y=10, z=15, alpha=20, 
                      noise_x=True, noise_y=True, noise_z=True, 
                      noise_alpha=True, noise_kwargs={"scale":0.25}, 
                      noise_type="uni")
    # import ipdb; ipdb.set_trace()
    assert(om.sim_x.value != 5 and np.isclose(om.sim_x.value, 5, atol=0.25))
    assert(om.sim_y.value != 10 and np.isclose(om.sim_y.value, 10, atol=0.25))
    assert(om.sim_z.value != 15 and np.isclose(om.sim_z.value, 15, atol=0.25))
    assert(om.sim_alpha.value != 20 and np.isclose(om.sim_alpha.value, 20, 
                                                   atol=0.25))
Esempio n. 4
0
def test_OffsetMirror_noise_changes_on_every_read():
    om = OffsetMirror("TEST", "TEST_XY", x=5, y=5, z=5, alpha=5, noise_x=0.1, 
                      noise_y=0.1, noise_z=0.1, noise_alpha=0.1)
    x_vals = [om.sim_x.value for i in range(10)]
    assert(len(x_vals) == len(set(x_vals)))
    y_vals = [om.sim_y.value for i in range(10)]
    assert(len(y_vals) == len(set(y_vals)))
    z_vals = [om.sim_z.value for i in range(10)]
    assert(len(z_vals) == len(set(z_vals)))
    alpha_vals = [om.sim_alpha.value for i in range(10)]
    assert(len(alpha_vals) == len(set(alpha_vals)))    
Esempio n. 5
0
def patch_pims(pims,
               mirrors=OffsetMirror("TEST_MIRROR", "TEST_XY"),
               source=Undulator("TEST_UND")):
    """
    Takes the inputted set of pims and mirrors and then the internal centroid
    calculating function for the pims to be one of the ray-tracing equations
    according to their position relative to the mirrors

    It does this by looping through each of the pims and comparing the stored z
    position against the z positions of the mirrors, and then pads the centroid
    readback accordingly.

    Parameters
    ----------
    pims : PIM or list
        PIMs to patch

    mirrors : OffsetMirror or list, optional
        Mirrors to calculate reflections off

    source : Undulator, optional
        Object to function as the source of the beam

    Returns
    -------
    pims : PIM or list
        The inputted pim objects but with their centroid readbacks patched with
        the ray tracing functions.
    """
    # Make sure the inputted mirrors and pims are iterables
    if not isiterable(mirrors):
        mirrors = [mirrors]
    if not isiterable(pims):
        pims = [pims]

    # Go through each pim
    for pim in pims:
        # If the pim is before the first mirror or there arent any mirrors
        if not mirrors or pim.sim_z.value <= mirrors[0].sim_z.value:
            logger.debug("Patching '{0}' with no bounce equation.".format(
                pim.name))
            pim.detector._get_readback_centroid_x = partial(
                _calc_cent_x, source, pim)

        elif mirrors[0].sim_z.value < pim.sim_z.value:
            # If there is only one mirror and the pim is after it
            if len(mirrors) == 1:
                logger.debug("Patching '{0}' with one bounce equation.".format(
                    pim.name))
                pim.detector._get_readback_centroid_x = partial(
                    _m1_calc_cent_x, source, mirrors[0], pim)

            # If the pim is behind the second mirror
            elif pim.sim_z.value <= mirrors[1].sim_z.value:
                logger.debug("Patching '{0}' with one bounce equation.".format(
                    pim.name))
                pim.detector._get_readback_centroid_x = partial(
                    _m1_calc_cent_x, source, mirrors[0], pim)

            # If the pim is after the second mirror
            elif mirrors[1].sim_z.value < pim.sim_z.value:
                logger.debug("Patching '{0}' with two bounce equation.".format(
                    pim.name))
                pim.detector._get_readback_centroid_x = partial(
                    _m1_m2_calc_cent_x, source, mirrors[0], mirrors[1], pim)

        # Patch the y centroid to always be the center of the image
        pim.detector._get_readback_centroid_y = lambda: (int(
            pim.detector.cam.size.size_x.value / 2))

    # Return just the pim if there was only one of them
    if len(pims) == 1:
        return pims[0]

    return pims
Esempio n. 6
0
def test_OffsetMirror_move_method():
    om = OffsetMirror("TEST", "TEST_XY")
    om.move(10)
    assert(om.position == 10)
    assert(om.pitch.position == 10)
Esempio n. 7
0
def test_OffsetMirror_runs_ophyd_functions():
    om = OffsetMirror("TEST", "TEST_XY")
    assert(isinstance(om.read(), OrderedDict))
    assert(isinstance(om.describe(), OrderedDict))
    assert(isinstance(om.describe_configuration(), OrderedDict))
    assert(isinstance(om.read_configuration(), OrderedDict))
Esempio n. 8
0
def test_OffsetMirror_motors_all_read():
    om = OffsetMirror("TEST", "TEST_XY")
    assert(isinstance(om.gan_x_p.read(), OrderedDict))
    assert(isinstance(om.gan_y_p.read(), OrderedDict))
    assert(isinstance(om.pitch.read(), OrderedDict))
Esempio n. 9
0
def test_OffsetMirror_instantiates():
    assert(OffsetMirror("TEST", "TEST_XY"))
Esempio n. 10
0
def test_OffsetMirror_timeout():
    tmo = 1.0
    om = OffsetMirror("TEST", "TEST_XY", timeout=tmo)
    om.move(42)
    assert(om.pitch.timeout == tmo)