def test_timeout(RE):
    from ophyd.positioner import SoftPositioner
    from ophyd.sim import SynGauss
    from ophyd import StatusBase

    mot = SoftPositioner(name='mot')
    mot.set(0)
    det = SynGauss('det', mot, 'mot', 0, 3)

    def kickoff():
        # This process should take a total of 5 seconds, but it will be
        # interrupted after 0.1 seconds via the timeout keyword passed to
        # ramp_plan below.
        yield Msg('null')
        for j in range(100):
            RE.loop.call_later(.05 * j, lambda j=j: mot.set(j))

        return StatusBase()

    def inner_plan():
        yield from trigger_and_read([det])

    g = ramp_plan(kickoff(), mot, inner_plan, period=.01, timeout=.1)

    start = time.time()
    with pytest.raises(RampFail):
        RE(g)
    stop = time.time()
    elapsed = stop - start

    # This test has a tendency to randomly fail, so we're giving it plenty of
    # time to run. 4, though much greater than 0.1, is still less than 5.
    assert .1 < elapsed < 4
Exemple #2
0
def wiggle_plan(dets, motor, delta, *, md=None):
    '''
    dets, a list of detectors to read, must have det.cam.acquire_time attribute
    delta, relative range to wiggle
    move through range in 5 step
    '''

    original_pos = motor.position

    def kickoff():  # plan for moving

        st = StatusBase()

        # move once every second for 2 min
        for i in range(24):  # 24*5 = 120
            for loc in np.linspace(-delta / 2, delta / 2, 5):  # 5s,
                RE.loop.call_later(1, lambda v=loc: motor.set(v))

        st._finished()

        return st

    def inner_plan():
        yield from bp.count(dets)

    def clean_up():
        yield from bps.mv(motor, original_pos)

    timeout = dets[0].cam.acquire_time.value

    rp = bp.ramp_plan(kickoff(), motor, inner_plan, timeout=timeout, md=md)

    return (yield from bpp.finalize_wrapper(rp, clean_up()))
Exemple #3
0
def test_timeout(RE):
    from ophyd.positioner import SoftPositioner
    from bluesky.examples import SynGauss
    from ophyd import StatusBase

    mot = SoftPositioner(name='mot')
    mot.set(0)
    det = SynGauss('det', mot, 'mot', 0, 3)

    def kickoff():
        yield Msg('null')
        for j in range(5):
            RE.loop.call_later(.05 * j, lambda j=j: mot.set(j))

        return StatusBase()

    def inner_plan():
        yield from trigger_and_read([det])

    g = ramp_plan(kickoff(), mot, inner_plan, period=.01, timeout=.1)

    start = time.time()
    with pytest.raises(RampFail):
        RE(g)
    stop = time.time()
    elapsed = stop - start

    assert .1 < elapsed < .2
Exemple #4
0
def test_timeout(RE):
    from ophyd.positioner import SoftPositioner
    from bluesky.examples import SynGauss
    from ophyd import StatusBase

    mot = SoftPositioner(name='mot')
    mot.set(0)
    det = SynGauss('det', mot, 'mot', 0, 3)

    def kickoff():
        # This process should take a total of 0.5 seconds, but it will be
        # interrupted after 0.1 seconds via the timeout keyword passed to
        # ramp_plan below.
        yield Msg('null')
        for j in range(10):
            RE.loop.call_later(.05 * j, lambda j=j: mot.set(j))

        return StatusBase()

    def inner_plan():
        yield from trigger_and_read([det])

    g = ramp_plan(kickoff(), mot, inner_plan, period=.01, timeout=.1)

    start = time.time()
    with pytest.raises(RampFail):
        RE(g)
    stop = time.time()
    elapsed = stop - start

    assert .1 < elapsed < .4
Exemple #5
0
def xpdacq_ramp_count(motor: typing.Any,
                      value: typing.Any,
                      inner_plan: typing.Callable,
                      take_pre_data=True,
                      timeout=None,
                      period=None,
                      md=None) -> typing.Generator:
    """
    Take data while ramping one or more motors.

    Parameters
    ----------
    inner_plan :
        The plan to repeat in loop. It returns a generator inner_plan().

    motor :
        A positioner to ramp up.

    value:
        A value to ramp up to.

    timeout : float, optional
        If not None, the maximum time the ramp can run.

        In seconds

    take_pre_data: Bool, optional
        If True, add a pre data at beginning

    period : float, optional
        If not None, take data no faster than this.  If None, take
        data as fast as possible

        If running the inner plan takes longer than `period` than take
        data with no dead time.

        In seconds.

    md : dict
        The metadata of this plan.
    """
    for detector in detectors:
        yield from bps.stage(detector)

    def go_plan():
        status, = yield from bps.mv(motor, value)
        return status

    yield from bp.ramp_plan(go_plan(),
                            motor,
                            inner_plan,
                            take_pre_data=take_pre_data,
                            timeout=timeout,
                            period=period,
                            md=md)

    for detector in detectors:
        yield from bps.unstage(detector)
def test_ramp(RE):
    from ophyd.positioner import SoftPositioner
    from ophyd import StatusBase
    from ophyd.sim import SynGauss

    tt = SoftPositioner(name='mot')
    tt.set(0)
    dd = SynGauss('det', tt, 'mot', 0, 3)

    st = StatusBase()

    def kickoff():
        yield Msg('null')
        for j, v in enumerate(np.linspace(-5, 5, 10)):
            RE.loop.call_later(.1 * j, lambda v=v: tt.set(v))
        RE.loop.call_later(1.2, st._finished)
        return st

    def inner_plan():
        yield from trigger_and_read([dd])

    g = ramp_plan(kickoff(), tt, inner_plan, period=0.08)
    db = DocCollector()
    RE.subscribe(db.insert)
    rs = RE(g)
    if RE.call_returns_result:
        uid = rs.run_start_uids[0]
    else:
        uid = rs[0]
    assert db.start[0]['uid'] == uid
    assert len(db.descriptor[uid]) == 2
    descs = {d['name']: d for d in db.descriptor[uid]}

    assert set(descs) == set(['primary', 'mot_monitor'])

    primary_events = db.event[descs['primary']['uid']]
    assert len(primary_events) > 11

    monitor_events = db.event[descs['mot_monitor']['uid']]
    # the 10 from the updates, 1 from 'run at subscription time'
    assert len(monitor_events) == 11
Exemple #7
0
def test_ramp(RE, db):
    from ophyd.positioner import SoftPositioner
    from ophyd import StatusBase
    from bluesky.examples import SynGauss

    tt = SoftPositioner(name='mot')
    tt.set(0)
    dd = SynGauss('det', tt, 'mot', 0, 3)

    st = StatusBase()

    def kickoff():
        yield Msg('null')
        for j, v in enumerate(np.linspace(-5, 5, 10)):
            RE.loop.call_later(.1 * j, lambda v=v: tt.set(v))
        RE.loop.call_later(1.2, st._finished)
        return st

    def inner_plan():
        yield from trigger_and_read([dd])

    g = ramp_plan(kickoff(), tt, inner_plan, period=0.08)
    RE.subscribe('all', db.mds.insert)
    RE.msg_hook = MsgCollector()
    rs_uid, = RE(g)
    hdr = db[-1]
    assert hdr.start.uid == rs_uid
    assert len(hdr.descriptors) == 2

    assert set([d['name'] for d in hdr.descriptors]) == \
        set(['primary', 'mot_monitor'])

    primary_events = list(db.get_events(hdr, stream_name='primary'))
    assert len(primary_events) > 11

    monitor_events = list(db.get_events(hdr, stream_name='mot_monitor'))
    assert len(monitor_events) == 10
Exemple #8
0
def test_ramp(RE, db):
    from ophyd.positioner import SoftPositioner
    from ophyd import StatusBase
    from bluesky.examples import SynGauss

    tt = SoftPositioner(name="mot")
    tt.set(0)
    dd = SynGauss("det", tt, "mot", 0, 3)

    st = StatusBase()

    def kickoff():
        yield Msg("null")
        for j, v in enumerate(np.linspace(-5, 5, 25)):
            RE.loop.call_later(0.05 * j, lambda v=v: tt.set(v))
        RE.loop.call_later(0.05 * 30, st._finished)
        return st

    def inner_plan():
        yield from trigger_and_read([dd])

    g = ramp_plan(kickoff(), tt, inner_plan, period=0.04)
    RE.subscribe("all", db.mds.insert)
    RE.msg_hook = MsgCollector()
    rs_uid, = RE(g)
    hdr = db[-1]
    assert hdr.start.uid == rs_uid
    assert len(hdr.descriptors) == 2

    assert set([d["name"] for d in hdr.descriptors]) == set(["primary", "mot-monitor"])

    primary_events = list(db.get_events(hdr, stream_name="primary"))
    assert len(primary_events) > 27

    monitor_events = list(db.get_events(hdr, stream_name="mot-monitor"))
    assert len(monitor_events) == 25
Exemple #9
0
# go_plan
def kickoff():
    st = StatusBase()
    for i in range(20):
        yield from mvr(motor, -1)
        yield from mvr(motor, 1)
    return st


def inner_plan():
    yield from trigger_and_read([det])


# Final call
RE(ramp_plan(kickoff(), motor, inner_plan))

# def ramp_plan(go_plan, monitor_sig, inner_plan_func,
# take_pre_data=True, timeout=None, period=None, md=None)
from databroker import Broker
from bluesky.plans import ramp_plan
from bluesky.plan_stubs import trigger_and_read
from bluesky import Msg
from bluesky.utils import RampFail
import numpy as np
import time

from ophyd.positioner import SoftPositioner
from ophyd import StatusBase
from ophyd.sim import SynGauss