def test_scan_vars(RE, daq): logger.debug('test_scan_vars') daq.configure(events=120) scan_vars = ScanVars('TST', name='tst', RE=RE) scan_vars.enable() check = CheckVals(scan_vars) RE.subscribe(check) check.plan = 'scan' RE( scan([det1, det2], motor1, 0, 10, motor2, 20, 0, motor3, 0, 1, motor, 0, 1, 11)) check.plan = 'count' RE(count([det1, det2], 11)) def custom(detector): for i in range(3): yield from create() yield from read(detector) yield from save() check.plan = 'custom' daq.configure(duration=4) RE(stage_wrapper(run_wrapper(custom(det1)), [det1])) scan_vars.disable() # Last, let's force an otherwise uncaught error to cover the catch-all # try-except block to make sure the log message doesn't error scan_vars.start({'motors': 4})
def test_fill_and_multiple_streams(db, RE, tmpdir, hw): from ophyd import sim RE.subscribe(db.insert) detfs1 = sim.SynSignalWithRegistry(name='detfs1', func=lambda: np.ones((5, 5)), reg=db.reg, save_path=str(tmpdir.mkdir('a'))) detfs2 = sim.SynSignalWithRegistry(name='detfs2', func=lambda: np.ones((5, 5)), reg=db.reg, save_path=str(tmpdir.mkdir('b'))) # In each event stream, put one 'fillable' (external-writing) # detector and one simple detector. primary_dets = [detfs1, hw.det1] baseline_dets = [detfs2, hw.det2] uid, = RE( stage_wrapper(baseline_wrapper(count(primary_dets), baseline_dets), baseline_dets)) db.reg.register_handler('NPY_SEQ', sim.NumpySeqHandler) h = db[uid] list(h.documents(stream_name=ALL, fill=False)) list(h.documents(stream_name=ALL, fill=True))
def test_basic_plans(daq, RE): logger.debug('test_basic_plans') daq.configure(events=12) start = time.time() RE(stage_wrapper(run_wrapper(trigger_and_read([daq])), [daq])) dt = time.time() - start assert 0.1 < dt < 0.2 assert daq.state == 'Configured' start = time.time() RE(count([daq], num=10)) dt = time.time() - start assert 1 < dt < 2 assert daq.state == 'Configured' def n_runs(det, n): for i in range(n): yield from run_wrapper(trigger_and_read([det])) RE(stage_wrapper(n_runs(daq, 10), [daq])) assert daq.state == 'Configured'
def cls_plan(): current_settings = {} for key, val in kwargs.items(): current_settings[key] = getattr(self, key) setattr(self, key, val) try: plan = self._gen() plan = bpp.subs_wrapper(plan, subs) plan = bpp.stage_wrapper(plan, flyers) plan = bpp.fly_during_wrapper(plan, flyers) return (yield from plan) finally: for key, val in current_settings.items(): setattr(self, key, val)
def daq_during_wrapper(plan, record=None, use_l3t=False, controls=None): """ Run a plan with the `Daq`. This can be used with an ordinary ``bluesky`` plan that you'd like the daq to run along with. This also stages the daq so that the run start/stop will be synchronized with the bluesky runs. This must be applied outside the ``run_wrapper``. All configuration must be done by supplying config kwargs to this wrapper. The `daq_during_decorator` is the same as the `daq_during_wrapper`, but it is meant to be used as a function decorator. Parameters ---------- plan: ``plan`` The ``plan`` to use the daq in record: ``bool``, optional If ``True``, we'll record the data. Otherwise, we'll run without recording. Defaults to ``False``, or the last set value for ``record``. use_l3t: ``bool``, optional If ``True``, an ``events`` argument to begin will be reinterpreted to only count events that pass the level 3 trigger. Defaults to ``False``. controls: ``dict{name: device}`` or ``list[device...]``, optional If provided, values from these will make it into the DAQ data stream as variables. We will check ``device.position`` and ``device.value`` for quantities to use and we will update these values each time begin is called. To provide a list, all devices must have a ``name`` attribute. """ daq = get_daq() yield from configure(daq, events=None, duration=None, record=record, use_l3t=use_l3t, controls=controls) yield from stage_wrapper(fly_during_wrapper(plan, flyers=[daq]), [daq])
def homs_fiducialize(slit_set, yag_set, x_width=.01, y_width=.01, samples=10, filters=None, centroid='detector_stats2_centroid_y'): """ Run slit_scan_fiducialize on a series of yags and their according slits. Automatically restore yags to OUT state and slits to initial position after running. Paramaters ---------- slit_set : [pcdsdevices.epics.slits.Slits,...] List of slits to be used for fiducialization process. yags and slits are paired elementwise and each pair is tested independantly. length of lists must match. yag_set : [pcdsdevices.epics.pim.PIM,...] List of yags to be used for fiducialization process. yags and slits are paired elementwise and each pair is tested independantly. length of lists must match. x_width : float, optional CHANGE SOON - this is the only one actually used y_width : float, optional CHANGE SOON - passed down to ssf method but not used. samples : int, optional Number of shots to average over for measurments. filters : dict, optional Filters to eliminate shots centroid : string, optional Field name of centroid measurement Returns ------- [float,float,float...] This list of floats represents the field measured for each slit/yag pairing. The floats are in the same order as the slits and yags prsesented in the arguments. Length matches number of slit/yag pairs. """ if len(slit_set) != len(yag_set): raise Exception( "Number of slits, yags does not match. Cannot be paired") results = [] for slit, yag in zip(slit_set, yag_set): ''' fiducial = yield from stage_wrapper(slit_scan_fiducialize,[slit,yag])( slit, yag, x_width, y_width, samples = samples, filters = filters, centroid = centroid, ) ''' wrapped = stage_wrapper( partial( slit_scan_fiducialize, slit, yag, x_width, y_width, samples=samples, filters=filters, centroid=centroid, )(), [slit, yag]) fiducial = yield from wrapped results.append(fiducial) return results
def on_slits_button(self): """ Slot for the slits procedure. This checks the slit fiducialization. """ try: logger.info('Starting slit check process.') image_to_check = [] slits_to_check = [] # First, check the slit checkboxes. for img_obj, slit_obj, goal_group in zip(self.imagers_padded(), self.slits_padded(), self.goals_groups): if slit_obj is not None and goal_group.is_checked: image_to_check.append(img_obj) slits_to_check.append(slit_obj) if not slits_to_check: logger.info('No valid slits selected!') return logger.info('Checking the following slits: %s', [slit.name for slit in slits_to_check]) self.install_pick_cam() self.auto_switch_cam = True slit_width = self.settings_cache['slit_width'] samples = self.settings_cache['samples'] def plan(img, slit, rot, output_obj, slit_width=slit_width, samples=samples): rot_info = ad_stats_x_axis_rot(img, rot) det_rbv = rot_info['key'] fidu = slit_scan_fiducialize(slit, img, centroid=det_rbv, x_width=slit_width, samples=samples) output = yield from fidu modifier = rot_info['mod_x'] if modifier is not None: output = modifier - output output_obj[img.name] = output self.initialize_RE() results = {} for img, slit in zip(image_to_check, slits_to_check): systems = self.loader.get_systems_with(img.name) objs = self.loader.get_subsystem(systems[0]) rotation = objs.get('rotation', 0) this_plan = plan(img, slit, rotation, results) wrapped = run_wrapper(this_plan) wrapped = stage_wrapper(wrapped, [img, slit]) self.RE(wrapped) logger.info('Slit scan found the following goals: %s', results) if self.ui.slit_fill_check.isChecked(): logger.info('Filling goal fields automatically.') for img, fld in zip(self.imagers_padded(), self.goals_groups): if img is not None: try: fld.value = round(results[img.name], 1) except KeyError: pass except: logger.exception('Error on slits button') finally: self.auto_switch_cam = False