def test_count(): actual_intensity = [] col = collector('det', actual_intensity) motor.set(0) scan = Count([det]) RE(scan, subs={'event': col}) assert actual_intensity[0] == 1. # multiple counts, via updating attribute actual_intensity = [] col = collector('det', actual_intensity) scan = Count([det], num=3, delay=0.05) RE(scan, subs={'event': col}) assert scan.num == 3 assert actual_intensity == [1., 1., 1.] # multiple counts, via passing arts to __call__ actual_intensity = [] col = collector('det', actual_intensity) scan = Count([det], num=3, delay=0.05) RE(scan(num=2), subs={'event': col}) assert actual_intensity == [1., 1.] # attribute should still be 3 assert scan.num == 3 actual_intensity = [] col = collector('det', actual_intensity) RE(scan, subs={'event': col}) assert actual_intensity == [1., 1., 1.]
def test_pre_run_post_run(): c = Count([]) def f(x): yield Msg('HEY', None) c.pre_run = f list(c)[0].command == 'HEY' c = Count([]) def f(x): yield Msg('HEY', None) c.pre_run = f list(c)[-1].command == 'HEY'
def test_round_trip_from_run_engine(): try: import bluesky except ImportError as ie: raise pytest.skip('ImportError: {0}'.format(ie)) # generate a new specfile from bluesky.tests.utils import setup_test_run_engine from bluesky.examples import motor, det from bluesky.plans import RelativeScan, Scan, Count RE = setup_test_run_engine() RE.ignore_callback_exceptions = False fname = tempfile.NamedTemporaryFile().name cb = DocumentToSpec(fname) dscan = RelativeScan([det], motor, -1, 1, 10) RE(dscan, {'all': cb}) ascan = Scan([det], motor, -1, 1, 10) RE(ascan, {'all': cb}) # add count to hit some lines in # suitcase.spec:_get_motor_name # suitcase.spec:_get_motor_position # suitcase.spec:_get_plan_type ct = Count([det]) RE(ct, {'all': cb}) sf = Specfile(fname) sf1 = _round_trip(sf) assert len(sf) == len(sf1)
def test_prun_with_bleusky_plan(self): cc = Count([det], 2) self.sp = ScanPlan('bluesky', {'bluesky_plan': cc}, shutter=False) self.sc = Scan(self.sa, self.sp) self.assertEqual(self.sc.sp, self.sp) cfg_f_name = 'srxconfig.cfg' cfg_src = os.path.join(os.path.dirname(__file__), cfg_f_name) # __file__ gives relative path cfg_dst = os.path.join(glbl.config_base, cfg_f_name) shutil.copy(cfg_src, cfg_dst) # sp_params should be id to object self.assertEqual(id(cc), self.sp.md['sp_params']['bluesky_plan']) # case 1: bluesky plan object exist in current name space prun(self.sa, self.sp) # is xpdRE used? self.assertTrue(glbl.xpdRE.called) # is md updated? self.assertFalse(glbl.xpdRE.call_args_list[-1][1] == self.sc.md) # is prun passed eventually? self.assertTrue('sc_isprun' in glbl.xpdRE.call_args_list[-1][1]) # is auto_dark executed? -> No as we don't support self.assertFalse('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1]) # is calibration loaded? self.assertTrue(cfg_f_name in glbl.xpdRE.call_args_list[-1][1] ['sc_calibration_file_name']) # is 'blusky_plan' appears in sp_params ? self.assertTrue( 'bluesky_plan' in glbl.xpdRE.call_args_list[-1][1]['sp_params']) # is ScanPlan.md remain unchanged after scan? self.assertFalse('sc_isprun' in self.sp.md) # case 2: bluesky plan object doesn't exist in current name spaece del cc self.assertRaises(NameError, lambda: prun(self.sa, self, sp))
def test_dets(db, tmp_dir, name, fp): det = det_factory(name, db.fs, fp, save_path=tmp_dir) RE = setup_test_run_engine() RE.subscribe('all', db.mds.insert) scan = Count([det], ) uid = RE(scan) db.fs.register_handler('RWFS_NPY', be.ReaderWithFSHandler) cycle2 = build_image_cycle(fp) cg = cycle2() for n, d in db.restream(db[-1], fill=True): if n == 'event': assert_array_equal(d['data']['pe1_image'], next(cg)['pe1_image']) assert uid is not None
def test_plan_md(fresh_RE): mutable = [] md = {'color': 'red'} def collector(name, doc): mutable.append(doc) # test genereator mutable.clear() fresh_RE(count([det], md=md), collector) assert 'color' in mutable[0] # test Plan with explicit __init__ mutable.clear() fresh_RE(Count([det], md=md), collector) assert 'color' in mutable[0] # test Plan with implicit __init__ (created via metaclasss) mutable.clear() fresh_RE(Scan([det], motor, 1, 2, 2, md=md), collector) assert 'color' in mutable[0]
def test_pre_run_post_run(): c = Count([]) def f(x): yield Msg('HEY', None) c.pre_run = f list(c)[0].command == 'HEY' c = Count([]) def f(x): yield Msg('HEY', None) c.pre_run = f list(c)[-1].command == 'HEY'
def test_dets_shutter(db, tmp_dir, name, fp): det = det_factory(name, db.fs, fp, save_path=tmp_dir, shutter=shctl1) RE = setup_test_run_engine() RE.subscribe('all', db.mds.insert) scan = Count([det], ) db.fs.register_handler('RWFS_NPY', be.ReaderWithFSHandler) cycle2 = build_image_cycle(fp) cg = cycle2() # With the shutter down RE(abs_set(shctl1, 0, wait=True)) uid = RE(scan) for n, d in db.restream(db[-1], fill=True): if n == 'event': assert_array_equal(d['data']['pe1_image'], np.zeros(next(cg)['pe1_image'].shape)) assert uid is not None # With the shutter up RE(abs_set(shctl1, 1, wait=True)) uid = RE(scan) for n, d in db.restream(db[-1], fill=True): if n == 'event': assert_array_equal(d['data']['pe1_image'], next(cg)['pe1_image']) assert uid is not None
from bluesky.plans import Count print('Waiting for pb6 to report connected') pb6.wait_for_connection() c = Count([]) c.flyers = [pb6.enc1] RE(c, LiveTable([]))
import asyncio import os import sys from bluesky.examples import det, motor, motor1, motor2, MockFlyer, det1, det2 from bluesky.plans import (Count, AbsScanPlan, AbsListScanPlan, DeltaListScanPlan, InnerProductAbsScanPlan, OuterProductAbsScanPlan) count_with_flyers = Count([det]) count_with_flyers.flyers = [ MockFlyer(det, motor, loop=asyncio.new_event_loop()) ] mf = count_with_flyers.flyers[0] mf.root = mf plans = { 'count-one-det': 'Count([det])', 'count-two-dets': 'Count([det1, det2], 2)', 'count-with-flyers': 'count_with_flyers', 'ascan': 'AbsScanPlan([det], motor, 1, 5, 3)', 'list-scan': 'AbsListScanPlan([det], motor, [1, 3, 8])', 'dscan-from-8': 'DeltaListScanPlan([det], motor, [1, 3, 8])', 'inner': 'InnerProductAbsScanPlan([det], 2, motor1, 1, 2, motor2, 10, 20)', 'outer':
from bluesky.plans import Count uid, = RE(Count([fm]), LiveTable([fm])) db[uid]
from bluesky.plans import Count print('Waiting for pb6 to report connected') pb6.wait_for_connection() c = Count([]) c.flyers = [pb6.enc1] RE(c, LiveTable([]))
import asyncio import os import sys from bluesky.examples import det, motor, motor1, motor2, MockFlyer, det1, det2 from bluesky.plans import (Count, AbsScanPlan, AbsListScanPlan, DeltaListScanPlan, InnerProductAbsScanPlan, OuterProductAbsScanPlan) count_with_flyers = Count([det]) count_with_flyers.flyers = [MockFlyer(det, motor, loop=asyncio.new_event_loop())] mf = count_with_flyers.flyers[0] mf.root = mf plans = {'count-one-det': 'Count([det])', 'count-two-dets': 'Count([det1, det2], 2)', 'count-with-flyers': 'count_with_flyers', 'ascan': 'AbsScanPlan([det], motor, 1, 5, 3)', 'list-scan': 'AbsListScanPlan([det], motor, [1, 3, 8])', 'dscan-from-8': 'DeltaListScanPlan([det], motor, [1, 3, 8])', 'inner': 'InnerProductAbsScanPlan([det], 2, motor1, 1, 2, motor2, 10, 20)', 'outer': 'OuterProductAbsScanPlan([det], motor1, 1, 2, 2, motor2, 10, 20, 2, ' 'False)'} def main(path): for name, plan in plans.items(): with open(os.path.join(path, name), 'w') as f: f.write(plan + "\n") for msg in list(eval(plan)): if 'group' in msg.kwargs: msg.kwargs['group'] = 'PLACEHOLDER'
from bluesky.plans import Count ct = Count([]) ct.flyers = [topoff_inj, diag6_flyer5, diag6_flyer1] uid, = RE(ct, LiveTable([])) assert len(db[uid].descriptors) == 3 # one event stream per flyer
from bluesky.plans import Count from bluesky.callbacks import LiveTable, LivePlot assert diag6_monitor.connected assert sclr.connected RE(Count([diag6_monitor, sclr]), LiveTable(['sclr_ch2', 'diag6_monitor']))