def test_trigger_and_read(): msgs = list(trigger_and_read([det])) expected = [Msg("trigger", det), Msg("wait"), Msg("create", name="primary"), Msg("read", det), Msg("save")] for msg in msgs: msg.kwargs.pop("group", None) assert msgs == expected msgs = list(trigger_and_read([det], "custom")) expected = [Msg("trigger", det), Msg("wait"), Msg("create", name="custom"), Msg("read", det), Msg("save")] for msg in msgs: msg.kwargs.pop("group", None) assert msgs == expected
def test_trigger_and_read(): msgs = list(trigger_and_read([det])) expected = [Msg('trigger', det), Msg('wait'), Msg('create', name='primary'), Msg('read', det), Msg('save')] for msg in msgs: msg.kwargs.pop('group', None) assert msgs == expected msgs = list(trigger_and_read([det], 'custom')) expected = [Msg('trigger', det), Msg('wait'), Msg('create', name='custom'), Msg('read', det), Msg('save')] for msg in msgs: msg.kwargs.pop('group', None) assert msgs == expected
def test_read_clash(fresh_RE): dcm = DCM('', name='dcm') dcm2 = DCM('', name='dcm') with pytest.raises(ValueError): fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm2.th])) + [Msg('close_run')])) with pytest.raises(ValueError): fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm2])) + [Msg('close_run')])) with pytest.raises(ValueError): fresh_RE( ([Msg('open_run')] + list(trigger_and_read([dcm.th, dcm2.th])) + [Msg('close_run')]))
def plan(): while True: for step in np.linspace(start, stop, num): yield from abs_set(motor, step, wait=True) yield from trigger_and_read(list(detectors) + [motor]) err = errorbar(lf.result, 'sigma') if err < .03: break
def step_scan_pcharge(mymotor, motor_min, motor_max, motor_step, pcharge): "Step mymotor from min -> max with a step size of step and collect for a given pcharge" for num in np.arange(motor_min, motor_max, motor_step): yield from abs_set(mymotor, num, wait=True) yield from bp.kickoff(detector, wait=True) yield from _waitfor_proton_charge(pcharge) yield from bp.complete(detector, wait=True) yield from bp.collect(detector) yield from bp.trigger_and_read([mymotor, bs_neutrons_roi, bs_pcharge])
def test_read_clash(fresh_RE): dcm = DCM('', name='dcm') dcm2 = DCM('', name='dcm') with pytest.raises(ValueError): fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm2.th])) + [Msg('close_run')])) with pytest.raises(ValueError): fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm2])) + [Msg('close_run')])) with pytest.raises(ValueError): fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm.th, dcm2.th])) + [Msg('close_run')]))
def multicount(dets, num): "Creates a single 'run'" for det in dets: yield from bp.stage(det) yield from bp.open_run() for _ in range(num): yield from bp.trigger_and_read(dets) yield from bp.close_run() for det in dets: yield from bp.unstage(det)
def multicount(dets, num): "Adds some metadata specific to this plan" md = {'plan_name': 'multicount', 'num': num} for det in dets: yield from bp.stage(det) yield from bp.open_run(md=md) for _ in range(num): yield from bp.trigger_and_read(dets) yield from bp.close_run() for det in dets: yield from bp.unstage(det)
def multicount(dets, num, md=None): "Allows user to pass in custom metadata." if md is None: md = {} md = ChainMap(md, {'plan_name': 'multicount', 'num': num}) for det in dets: yield from bp.stage(det) yield from bp.open_run(md=md) for _ in range(num): yield from bp.trigger_and_read(dets) yield from bp.close_run() for det in dets: yield from bp.unstage(det)
def inner(): print('Beamline Ready... waiting for HPLC Injected Signal') yield from kickoff(hplc, wait=True) print('Acquiring data...') for mo in monitors: yield from monitor(mo) status = yield from complete(hplc, wait=False) while True: yield from trigger_and_read(detectors) # one 'primary' event per loop if status.done: break for mo in monitors: yield from unmonitor(mo) print('Collecting the data...') yield from collect(hplc)
def test_nonrewindable_detector(fresh_RE, motor_det, start_state, msg_seq): class FakeSig: def get(self): return False motor, det = motor_det det.rewindable = FakeSig() RE = fresh_RE RE.rewindable = start_state m_col = MsgCollector() RE.msg_hook = m_col RE(bp.run_wrapper(bp.trigger_and_read([motor, det]))) assert [m.command for m in m_col.msgs] == msg_seq
def inner(): print('Beamline Ready... waiting for HPLC Injected Signal') yield from kickoff(hplc, wait=True) print('Acquiring data...') for mo in monitors: yield from monitor(mo) status = yield from complete(hplc, wait=False) while True: yield from trigger_and_read( detectors) # one 'primary' event per loop if status.done: break for mo in monitors: yield from unmonitor(mo) print('Collecting the data...') yield from collect(hplc)
def inner_plan(): yield from trigger_and_read([det])
def test_overlapping_read(fresh_RE): dcm = DCM('', name='dcm') dcm2 = DCM('', name='dcm') def collect(name, doc): docs[name].append(doc) docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm.th])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 2 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm])) + list(trigger_and_read([dcm.th])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 2 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm])) + list(trigger_and_read([dcm2])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 2 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm.th])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 1 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm.th, dcm.x, dcm])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 1 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm.th, dcm.x])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 1
def dwell(detectors, motor, step): yield from checkpoint() yield from bp.abs_set(motor, step, wait=True) yield from bp.sleep(sleep_time) return (yield from bp.trigger_and_read(list(detectors)+[motor]))
def test_overlapping_read(fresh_RE): dcm = DCM('', name='dcm') dcm2 = DCM('', name='dcm') def collect(name, doc): docs[name].append(doc) docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm.th])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 2 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm])) + list(trigger_and_read([dcm.th])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 2 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm])) + list(trigger_and_read([dcm2])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 2 docs = defaultdict(list) fresh_RE(([Msg('open_run')] + list(trigger_and_read([dcm, dcm.th])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 1 docs = defaultdict(list) fresh_RE( ([Msg('open_run')] + list(trigger_and_read([dcm.th, dcm.x, dcm])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 1 docs = defaultdict(list) fresh_RE( ([Msg('open_run')] + list(trigger_and_read([dcm, dcm.th, dcm.x])) + list(trigger_and_read([dcm])) + [Msg('close_run')]), collect) assert len(docs['descriptor']) == 1