Пример #1
0
def test_synaxis_subcribe():
    hits = dict.fromkeys(['r', 's', 'a'], 0)
    vals = dict.fromkeys(['r', 's', 'a'], None)

    def p1(tar, value):
        hits[tar] += 1
        vals[tar] = value

    motor = SynAxis(name='motor1')
    # prime the cb cache so these run an subscription
    motor.set(0)
    motor.subscribe(lambda *, value, _tar='a', **kwargs:
                    p1(_tar, value))
    motor.readback.subscribe(lambda *, value, _tar='r', **kwargs:
                             p1(_tar, value))
    motor.setpoint.subscribe(lambda *, value, _tar='s', **kwargs:
                             p1(_tar, value))

    assert vals['r'] == motor.readback.get()
    assert vals['a'] == motor.readback.get()
    assert vals['s'] == motor.setpoint.get()

    assert all(v == 1 for v in hits.values())

    motor.set(1)

    assert vals['r'] == motor.readback.get()
    assert vals['a'] == motor.readback.get()
    assert vals['s'] == motor.setpoint.get()

    assert all(v == 2 for v in hits.values())
Пример #2
0
def test_walk_to_pixel(RE, one_bounce_system):
    logger.debug("test_walk_to_pixel")
    _, mot, det = one_bounce_system

    ##########################
    # Test on simple devices #
    ##########################
    simple_motor = SynAxis(name='motor')
    simple_det = SynSignal(name='det',
                           func=lambda: 5*simple_motor.read()['motor']['value']
                                + 2)

    # Naive step
    plan = run_wrapper(walk_to_pixel(simple_det, simple_motor, 200, 0,
                                     first_step=1e-6,
                                     tolerance=10, average=None,
                                     target_fields=['det', 'motor'],
                                     max_steps=3))
    RE(plan)
    assert np.isclose(simple_det.read()['det']['value'], 200, atol=1)

    simple_motor.set(0.)

    # Gradient
    simple_motor = SynAxis(name='motor')
    simple_det = SynSignal(name='det',
                           func=lambda: 5*simple_motor.read()['motor']['value']
                                + 2)
    plan = run_wrapper(walk_to_pixel(simple_det, simple_motor, 200, 0,
                                     gradient=1.6842e+06,
                                     tolerance=10, average=None,
                                     target_fields=['det', 'motor'],
                                     max_steps=3))
    RE(plan)
    assert np.isclose(simple_det.read()['det']['value'], 200, atol=1)

    ##########################
    # Test on full model #
    ##########################
    # Naive step
    cent = 'detector_stats2_centroid_x'
    plan = run_wrapper(walk_to_pixel(det, mot, 200, 0, first_step=1e-6,
                                     tolerance=10, average=None,
                                     target_fields=[cent, 'sim_alpha'],
                                     max_steps=3))
    RE(plan)
    assert np.isclose(det.read()[det.name + "_" + cent]['value'], 200, atol=1)

    mot.set(0.)

    # Gradient
    plan = run_wrapper(walk_to_pixel(det, mot, 200, 0, gradient=1.6842e+06,
                                     tolerance=10, average=None,
                                     target_fields=[cent, 'sim_alpha'],
                                     max_steps=3))
    RE(plan)
    assert np.isclose(det.read()[det.name + "_" + cent]['value'], 200, atol=10)
Пример #3
0
def test_synaxis_timestamps():
    from ophyd.status import wait
    import time

    def time_getter(m):
        return {k: v['timestamp']
                for k, v in m.read().items()}

    def tester(m, orig_time):
        new_time = time_getter(m)
        assert orig_time != new_time
        return new_time

    motor = SynAxis(name='motor1')
    motor.delay = .01
    orig_time = time_getter(motor)

    wait(motor.set(3))
    orig_time = tester(motor, orig_time)

    wait(motor.setpoint.set(4))
    orig_time = tester(motor, orig_time)

    motor.setpoint.put(3)
    time.sleep(2*motor.delay)
    orig_time = tester(motor, orig_time)
Пример #4
0
from glob import glob
from pathlib import Path

import numpy
from ophyd.sim import SynSignal, SynAxis
import pandas


for filename in glob(str(Path(__file__).parent / "data" / "pitch_vs_I0" / "*.csv")):
    # Grab the first file. Maybe later take a random one.
    # Each one is at a different energy, so it would not make sense to concat them.
    data = pandas.read_csv(filename)
    break


def compute_I0():
    return numpy.interp(pitch.readback.get(), data["dcm_pitch"], data["I0"])


pitch = SynAxis(name="pitch")
pitch.set(4).wait()  # initialize at a reasonable value
pitch.delay = 0.05  # to simulate movement time
I0 = SynSignal(name="I0", func=compute_I0)