def test_flyer_descriptor(RE, hw): flyers = [hw.flyer1] hw.flyer1.loop = RE.loop collector = [] RE(fly(flyers), {'descriptor': lambda name, doc: collector.append(doc)}) descriptor = collector.pop() assert 'object_keys' in descriptor
def test_flyer_descriptor(fresh_RE): RE = fresh_RE flyers = [TrivialFlyer()] collector = [] RE(bp.fly(flyers), {'descriptor': lambda name, doc: collector.append(doc)}) descriptor = collector.pop() assert 'object_keys' in descriptor
def fly_scan(E0, mono_speed, device_dict, parent): # Initial settings flyer = device_dict['energyFlyer'] parent.subscribe_callback() parent.toLog("A new fly scan is started!", color='blue') # Set to fly scan speed yield from bps.abs_set(flyer.fly_motor_speed, mono_speed) # Do fly scan yield from bpp.monitor_during_wrapper(bp.fly([flyer]), [ device_dict['ENC_fly_counter'], device_dict['I0_fly_counter'], device_dict['It_fly_counter'], device_dict['If_fly_counter'], device_dict['Ir_fly_counter'] ]) # Set to normal speed yield from bps.abs_set(flyer.fly_motor_speed, parent._orig_mono_speed) # Move to E0 yield from stop_and_mv(dcm, E0) parent.unsubscribe_callback() # Decrease remaining scan-number num_scan = int(parent.control.number_of_scan_edit.value()) if num_scan > 1: _submit(parent.control.number_of_scan_edit.setValue, num_scan - 1) cooling_time = parent.control.flyControl.flyCoolTime.value() parent.toLog( "Cooling dcm. The next scan starts after {} seconds.".format( cooling_time)) yield from bps.sleep(cooling_time)
def test_flyer_descriptor(RE, hw): flyers = [hw.flyer1] hw.flyer1.loop = RE.loop collector = [] RE(fly(flyers), {'descriptor': lambda name, doc: collector.append(doc)}) descriptor = collector.pop() assert 'object_keys' in descriptor
def main(): # Enter a sim_id, aperature name, lens name, optic name, # and watch point separated by spaces RE, db = bluesky_utils() sys.argv.pop(0) sim_id = sys.argv[0] aperture = sys.argv[1] lens = sys.argv[2] optic = sys.argv[3] watch_point = sys.argv[4] sirepo_flyer = flyer(sim_id, aperture, lens, optic, watch_point) RE(bp.fly([sirepo_flyer]))
def run_hardware_fly(motors, detector, population, max_velocity, min_velocity): uid_list = [] flyers = generate_flyers(motors=motors, detector=detector, population=population, max_velocity=max_velocity, min_velocity=min_velocity) for flyer in flyers: yield from bp.fly([flyer]) for i in range(-len(flyers), 0): uid_list.append(i) # uid = (yield from bp.fly([hf])) # uid_list.append(uid) return uid_list
def _test_sirepo_flyer(RE_no_plot, db, tmpdir, sim_id, server_name): import datetime from ophyd.utils import make_dir_tree RE_no_plot.subscribe(db.insert) root_dir = f'{tmpdir}/sirepo_flyer_data' _ = make_dir_tree(datetime.datetime.now().year, base_path=root_dir) params_to_change = [] for i in range(1, 6): key1 = 'Aperture' parameters_update1 = { 'horizontalSize': i * .1, 'verticalSize': (16 - i) * .1 } key2 = 'Lens' parameters_update2 = {'horizontalFocalLength': i + 7} key3 = 'Obstacle' parameters_update3 = {'horizontalSize': 6 - i} params_to_change.append({ key1: parameters_update1, key2: parameters_update2, key3: parameters_update3 }) sirepo_flyer = SirepoFlyer(sim_id=sim_id, server_name=server_name, root_dir=root_dir, params_to_change=params_to_change, watch_name='W60', run_parallel=False) RE_no_plot(bp.fly([sirepo_flyer])) hdr = db[-1] t = hdr.table(stream_name='sirepo_flyer') db_means = [] actual_means = [ 36779651609602.38, 99449330615601.89, 149289119385413.34, 223428480785808.78, 388594677365777.9 ] for i in range(len(t)): db_means.append(t.iloc[i]['sirepo_flyer_mean']) assert set(actual_means) == set( db_means), "fly scan means do not match actual means"
def test_sirepo_flyer(): from re_config import RE, db, ROOT_DIR from sirepo_flyer import SirepoFlyer import bluesky.plans as bp params_to_change = [] for i in range(1, 5 + 1): key1 = 'Aperture' parameters_update1 = {'horizontalSize': i * .1, 'verticalSize': (6 - i) * .1} key2 = 'Lens' parameters_update2 = {'horizontalFocalLength': i + 10} params_to_change.append({key1: parameters_update1, key2: parameters_update2}) sirepo_flyer = SirepoFlyer(sim_id='87XJ4oEb', server_name='http://10.10.10.10:8000', root_dir=ROOT_DIR, params_to_change=params_to_change, watch_name='W60', run_parallel=False) RE(bp.fly([sirepo_flyer]))
def test_flyer_descriptor(RE, hw): class Flyer(TrivialFlyer): def __init__(self, name): self.name = name self.detector = FlyerDetector(name="flyer-detector") def read_configuration(self): return self.detector.read_configuration() def describe_configuration(self): return self.detector.describe_configuration() def describe_collect(self): return { "primary": { "data_key_1": { "dims": [], "dtype": "string", "shape": [], "source": "", }, "data_key_2": { "dims": [], "dtype": "number", "shape": [], "source": "", }, }, "secondary": { "data_key_3": { "dims": [], "dtype": "string", "shape": [], "source": "", }, "data_key_4": { "dims": [], "dtype": "number", "shape": [], "source": "", }, }, } def collect(self): yield { "data": { "data_key_1": "1", "data_key_2": 2 }, "timestamps": { "data_key_1": 0, "data_key_2": 0 }, "time": 0, } yield { "data": { "data_key_3": "3", "data_key_4": 4 }, "timestamps": { "data_key_3": 0, "data_key_4": 0 }, "time": 0, } flyers = [Flyer(name="flyer"), TrivialFlyer()] descriptors = dict() RE( fly(flyers), { "descriptor": lambda name, doc: descriptors.update({doc["name"]: doc}) }, ) primary_descriptor = descriptors["primary"] assert primary_descriptor["configuration"]["flyer"] == { "data": { "config_key_1": "1", "config_key_2": 2, "config_key_3": "3", "config_key_4": 4, }, "timestamps": { "config_key_1": 1, "config_key_2": 2, "config_key_3": 3, "config_key_4": 4, }, "data_keys": { "config_key_1": { "dtype": "string", "shape": [], "source": "PV:Config:1" }, "config_key_2": { "dtype": "number", "shape": [], "source": "PV:Config:2" }, "config_key_3": { "dtype": "string", "shape": [], "source": "PV:Config:3" }, "config_key_4": { "dtype": "number", "shape": [], "source": "PV:Config:4" }, }, } assert "flyer" in primary_descriptor["object_keys"] secondary_descriptor = descriptors["secondary"] assert len(secondary_descriptor["configuration"]["flyer"]["data"]) == 4 assert secondary_descriptor["configuration"] == primary_descriptor[ "configuration"] assert "flyer" in secondary_descriptor["object_keys"] trivial_flyer_descriptor = descriptors["stream_name"] print(f"trivial flyer descriptor: {trivial_flyer_descriptor}") assert len(trivial_flyer_descriptor["configuration"]) == 1 assert "trivial_flyer" in trivial_flyer_descriptor["object_keys"]
def test_device_flyer_descriptor(RE, hw): # TrivialFlyer is not a Device flyers = [FlyerDevice(name="flyer-detector"), TrivialFlyer()] descriptors = dict() RE( fly(flyers), { "descriptor": lambda name, doc: descriptors.update({doc["name"]: doc}) }, ) primary_descriptor = descriptors["primary"] print(f"primary descriptor: {primary_descriptor}") assert len(primary_descriptor["configuration"]) == 1 assert primary_descriptor["configuration"]["flyer-detector"] == { "data": { "config_key_1": "1", "config_key_2": 2, "config_key_3": "3", "config_key_4": 4, }, "timestamps": { "config_key_1": 1, "config_key_2": 2, "config_key_3": 3, "config_key_4": 4, }, "data_keys": { "config_key_1": { "dtype": "string", "shape": [], "source": "PV:Config:1" }, "config_key_2": { "dtype": "number", "shape": [], "source": "PV:Config:2" }, "config_key_3": { "dtype": "string", "shape": [], "source": "PV:Config:3" }, "config_key_4": { "dtype": "number", "shape": [], "source": "PV:Config:4" }, }, } secondary_descriptor = descriptors["secondary"] print(f"secondary_descriptor: {secondary_descriptor}") assert len( secondary_descriptor["configuration"]["flyer-detector"]["data"]) == 4 assert secondary_descriptor["configuration"] == primary_descriptor[ "configuration"] trivial_flyer_descriptor = descriptors["stream_name"] print(f"trivial flyer descriptor: {trivial_flyer_descriptor}") assert len(trivial_flyer_descriptor["configuration"]) == 1 assert "trivial_flyer" in trivial_flyer_descriptor["object_keys"]
def _fly_scan(): yield from bp.fly([flyer])
def fly_scan(mds): RE = RE_with_mds(mds) RE(fly([flyer]))
def fly_scan(mds): RE = RE_with_mds(mds) return RE(fly([flyer]))
def test_flyer_descriptor(RE, hw): from ophyd.sim import TrivialFlyer class Flyer(TrivialFlyer): name = "flyer" def read_configuration(self): return { "data_key_1": { "value": "" }, "data_key_2": { "value": 0 }, "data_key_3": { "value": "" }, "data_key_4": { "value": 0 } } def collect(self): yield { "data": { "data_key_1": "", "data_key_2": 0, }, "timestamps": { "data_key_1": 0, "data_key_2": 0, }, "time": 0 } yield { "data": { "data_key_3": "", "data_key_4": 0 }, "timestamps": { "data_key_3": 0, "data_key_4": 0 }, "time": 0 } def describe_collect(self): return { "primary": { "data_key_1": { "dims": ("dim 1", ), "dtype": "string", "shape": [], "source": "", }, "data_key_2": { "dims": ("dim 1", ), "dtype": "number", "shape": [], "source": "", } }, "secondary": { "data_key_3": { "dims": ("dim 1", ), "dtype": "string", "shape": [], "source": "", }, "data_key_4": { "dims": ("dim 1", ), "dtype": "number", "shape": [], "source": "", } } } flyers = [Flyer(), TrivialFlyer()] descriptors = dict() RE(fly(flyers), { 'descriptor': lambda name, doc: descriptors.update({doc["name"]: doc}) }) primary_descriptor = descriptors["primary"] assert len(primary_descriptor["configuration"]) == 4 assert primary_descriptor["configuration"]["data_key_1"]["value"] == "" assert primary_descriptor["configuration"]["data_key_2"]["value"] == 0 assert primary_descriptor["configuration"]["data_key_3"]["value"] == "" assert primary_descriptor["configuration"]["data_key_4"]["value"] == 0 assert "flyer" in primary_descriptor["object_keys"] secondary_descriptor = descriptors["secondary"] assert len(secondary_descriptor["configuration"]) == 4 assert secondary_descriptor["configuration"]["data_key_1"]["value"] == "" assert secondary_descriptor["configuration"]["data_key_2"]["value"] == 0 assert secondary_descriptor["configuration"]["data_key_3"]["value"] == "" assert secondary_descriptor["configuration"]["data_key_4"]["value"] == 0 assert "flyer" in secondary_descriptor["object_keys"] trivial_flyer_descriptor = descriptors["stream_name"] assert len(trivial_flyer_descriptor["configuration"]) == 0 assert "trivial_flyer" in trivial_flyer_descriptor["object_keys"]
simmotor2.read() simmotor2.set(1) # RE(scan([detector],simmotor1,0,14,10)) #Flyer from ophyd.sim import hw from bluesky.run_engine import RunEngine from databroker import temp_config, Broker from bluesky.plans import fly import bluesky.plans as bp hw = hw() flying_zebra = hw.flyer1 db = Broker.named('temp') RE = RunEngine() RE.subscribe(db.insert) RE(fly([flying_zebra])) RE(fly([flying_zebra])) hdr = db[-1] hdr.stream_names hdr.table('stream_name') hw.direct_img hw.det.exposure_time = 1 RE(bp.count([hw.det], num=3)) db[-1].table()
def _run_flyers(flyers): uid_list = [] for flyer in flyers: uid = (yield from bp.fly(flyer)) uid_list.append(uid) return uid_list