def test_separate_devices(): b1 = B('', name='b1') b2 = B('', name='b2') a = A('', name='a') assert separate_devices([b1, b1.a1]) == [b1] assert separate_devices([b1.a1, b1.a2]) == [b1.a1, b1.a2] assert separate_devices([b1, b2.a1]) == [b1, b2.a1] assert separate_devices([b1.a1, b2.a2]) == [b1.a1, b2.a2] assert separate_devices([b1, a]) == [b1, a]
def test_separate_devices(): b1 = B('', name='b1') b2 = B('', name='b2') a = A('', name='a') assert separate_devices([b1, b1.a1]) == [b1] assert separate_devices([b1.a1, b1.a2]) == [b1.a1, b1.a2] assert separate_devices([b1, b2.a1]) == [b1, b2.a1] assert separate_devices([b1.a1, b2.a2]) == [b1.a1, b2.a2] assert separate_devices([b1, a]) == [b1, a]
def adaptive_core(): next_pos = start step = (max_step - min_step) / 2 past_I = None cur_I = None cur_det = {} while next_pos < stop: yield Msg('checkpoint') yield Msg('set', motor, next_pos, group='A') yield Msg('wait', None, 'A') yield Msg('create', None, name='primary') for det in detectors: yield Msg('trigger', det, group='B') yield Msg('wait', None, 'B') for det in separate_devices(detectors + [motor]): cur_det = yield Msg('read', det) if cur_det is not None and target_field in cur_det: cur_I = cur_det[target_field]['value'] yield Msg('save') # special case first first loop if past_I is None: past_I = cur_I next_pos += step continue dI = np.abs(cur_I - past_I) slope = dI / step if slope: new_step = np.clip(target_delta / slope, min_step, max_step) else: new_step = np.min([step * 1.1, max_step]) # if we over stepped, go back and try again if backstep and (new_step < step * threshold): next_pos -= step step = new_step else: past_I = cur_I step = 0.2 * new_step + 0.8 * step next_pos += step
def adaptive_core(): next_pos = start step = (stop - start) / 2 past_I = None cur_I = target_val + 99 # start the while loop repeat = 0 largest_out_of_bound = stop cnt = 0 if stop >= start: direction_sign = 1 else: direction_sign = -1 while cur_I > target_val or ( (largest_out_of_bound - next_pos) > accuracy) or repeat < 3: debug = False if debug: print( 'Current value = {}; largest_out_of_bound = {}; repeat = {}' .format(cur_I, largest_out_of_bound, repeat)) yield Msg('checkpoint') yield from bps.mv(motor, next_pos) yield Msg('create', None, name='primary') for det in detectors: yield Msg('trigger', det, group='B') yield Msg('wait', None, 'B') for det in utils.separate_devices(detectors + [motor] + [outer_motor]): cur_det = yield Msg('read', det) if target_field in cur_det: cur_I = calc_function( value=cur_det[target_field]['value']) yield Msg('save') # special case first first loop if past_I is None: past_I = cur_I next_pos += step * direction_sign continue # binary search if cur_I > past_I: if cur_I < target_val: direction_sign = 1 else: direction_sign = -1 largest_out_of_bound = np.min( [largest_out_of_bound, next_pos]) elif cur_I <= past_I: if cur_I < target_val: direction_sign = 1 else: direction_sign = -1 largest_out_of_bound = np.min( [largest_out_of_bound, next_pos]) else: print('binary search error') # the logic here is non-conventional: # once the dynamic reserve is exceeded measurements jump around significantly # so we search for the largest interfering amplitude that does NOT cause a # deviation over 5% (target_val) # and that is a specified voltage maximum voltage away from an interferer amplitude that did cause # a deviation greater than the target value. past_I = cur_I step = np.max([step / 2, min_step]) if (cur_I < target_val) and ( abs(largest_out_of_bound - next_pos) < accuracy): repeat += 1 next_pos = next_pos else: repeat = 0 next_pos += step * direction_sign next_pos = np.clip( next_pos, start, stop ) # by binary search this shouldn't be needed. Just in case # handle conditions that might get stuck. Only run 30 loops, if ((next_pos == start) or (next_pos == stop) and (repeat == 0) and (cnt > 8)) or (cnt > 50): break cnt += 1
a2scan = bpp.subs_decorator(bec)(hxntools.scans.a2scan) scan_steps = bpp.subs_decorator(bec)(hxntools.scans.scan_steps) dets1 = [zebra, sclr1, merlin1, xspress3] dets2 = [zebra, sclr1, xspress3, merlin2] #dets2 = [zebra, sclr1, xspress3, lakeshore2] dets3 = [zebra, sclr1, merlin1, xspress3, merlin2] dets4 = [zebra, sclr1, merlin1, lakeshore2] dets5 = [zebra, sclr1, xspress3, dexela1] # dets5 = [zebra, sclr1, merlin1, xspress3, lakeshore2,dexela1] # define all the position names and save them to baseline # need to remove confict names conflict_name = ['pmllf', 'zplab', 'pmllc'] #descs = {d.name: set(d.describe()) # for d in bu.separate_devices # (ophyd.utils.instances_from_namespace(ophyd.PositionerBase))} # sd.baseline = [dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, zp] # sd.baseline = [dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, bpm1, bpm2, smlld] sd.baseline = [ ugap, e, dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, mllosa, zp, zps, smlld, fdet1, diff ] BlueskyMagics.positioners = [ d for d in bu.separate_devices( ophyd.utils.instances_from_namespace((ophyd.EpicsMotor, ophyd.PseudoSingle))) ]
#dets10 = [zebra, sclr1, xspress3, dexela1] dets8= [fs, zebra, sclr1, xspress3] #dets11= [fs, zebra, sclr1, xspress3, eiger1m_single] # define all the position names and save them to baseline # need to remove confict names conflict_name = ['pmllf', 'zplab', 'pmllc'] #descs = {d.name: set(d.describe()) # for d in bu.separate_devices # (ophyd.utils.instances_from_namespace(ophyd.PositionerBase))} # sd.baseline = [dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, zp] # sd.baseline = [dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, bpm1, bpm2, smlld] sd.baseline = [ugap,e,dcm, m1, m2, beamline_status, smll, vmll, hmll, ssa2, mllosa, zp, zps, zposa, zpbs, smlld, fdet1, diff, p, ps, pp] # The following is a temporary solution, which replaces fixed list of devices passed to 'BlueskyMagics.positioners' (deprecated). # TODO: The proper way to label devices is to pass 'labels' to the device (Ophyd object) constructor. Use meaningful labels. dev_list_motor = [d for d in bu.separate_devices(ophyd.utils.instances_from_namespace((ophyd.EpicsMotor,)))] dev_list_pseudo = [d for d in bu.separate_devices(ophyd.utils.instances_from_namespace((ophyd.PseudoSingle,)))] for d in dev_list_motor: d._ophyd_labels_ = set(["Epics Motor"]) for d in dev_list_pseudo: d._ophyd_labels_ = set(["Pseudo Single"]) # BlueskyMagics.positioners = [d for d in # bu.separate_devices( # ophyd.utils.instances_from_namespace( # (ophyd.EpicsMotor, ophyd.PseudoSingle)))]