def execute_loop_trajectory(comment='', **metadata): flyers = [pb9.enc1, pba2.adc6, pba2.adc7] def inner(): md = { 'plan_args': {}, 'plan_name': 'execute_trajectory', 'comment': comment } md.update(**metadata) yield from bp.open_run(md=md) # TODO Replace this with actual status object logic. hhm.enable_loop.put("1") ttime.sleep(2) while (hhm.theta.moving == True or hhm.enable_loop_rbv.value == 1): ttime.sleep(.1) #write_file(comment, [flyers[0].filepath.value, flyers[1].filepath.value, flyers[2].filepath.value] , '') yield from bp.close_run() for flyer in flyers: yield from bp.stage(flyer) yield from bp.stage(hhm) yield from bp.fly_during_wrapper(inner(), flyers) yield from bp.unstage(hhm) for flyer in flyers: yield from bp.unstage(flyer)
def insert_take_dark(msg): now = time.time() nonlocal need_dark # print('after nonlocal dark, need_dark={}'.format(need_dark)) qualified_dark_uid = _validate_dark(expire_time=glbl.dk_window) # print('qualified_dark_uid is {}'.format(qualified_dark_uid)) # FIXME: should we do "or" or "and"? if (not need_dark) and (not qualified_dark_uid): need_dark = True if need_dark \ and (not qualified_dark_uid) \ and msg.command == 'open_run' \ and ('dark_frame' not in msg.kwargs): # We are about to start a new 'run' (e.g., a count or a scan). # Insert a dark frame run first. need_dark = False # Annoying detail: the detector was probably already staged. # Unstage it (if it wasn't staged, nothing will happen) and # then take_dark() and then re-stage it. return bp.pchain(bp.unstage(glbl.area_det), take_dark(), bp.stage(glbl.area_det), bp.single_gen(msg)), None else: # do nothing if (not need_dark) return None, None
def insert_take_dark(msg): now = time.time() nonlocal need_dark qualified_dark_uid = _validate_dark(expire_time=glbl.dk_window) # FIXME: should we do "or" or "and"? if (not need_dark) and (not qualified_dark_uid): need_dark = True if need_dark \ and (not qualified_dark_uid) \ and msg.command == 'open_run' \ and ('dark_frame' not in msg.kwargs): # We are about to start a new 'run' (e.g., a count or a scan). # Insert a dark frame run first. need_dark = False # Annoying detail: the detector was probably already staged. # Unstage it (if it wasn't staged, nothing will happen) and # then take_dark() and then re-stage it. return bp.pchain(bp.unstage(glbl.area_det), take_dark(), bp.stage(glbl.area_det), bp.single_gen(msg), bp.abs_set(glbl.shutter, 60, wait=True)), None elif msg.command == 'open_run' and 'dark_frame' not in msg.kwargs: return bp.pchain(bp.single_gen(msg), bp.abs_set(glbl.shutter, 60, wait=True)), None else: # do nothing if (not need_dark) return None, None
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 execute_xia_trajectory(comment='', **metadata): flyers = [pb9.enc1, pb4.di] def inner(): md = { 'plan_args': {}, 'plan_name': 'execute_xia_trajectory', 'comment': comment } md.update(**metadata) yield from bp.open_run(md=md) # TODO Replace this with actual status object logic. xia1.start_mapping_scan() hhm.enable_loop.put("0") hhm.start_trajectory.put("1") ttime.sleep(3) finished = 0 while (hhm.theta.moving == True or finished == 0): finished = 0 ttime.sleep(.1) if (hhm.theta.moving == False): ttime.sleep(.5) finished = 1 xia1.stop_scan() #write_file(comment, [flyers[0].filepath.value, flyers[1].filepath.value, flyers[2].filepath.value] , '') yield from bp.close_run() for flyer in flyers: yield from bp.stage(flyer) yield from bp.stage(hhm) #yield from bp.stage(xia1) yield from bp.fly_during_wrapper(inner(), flyers) #yield from bp.unstage(xia1) yield from bp.unstage(hhm) for flyer in flyers: yield from bp.unstage(flyer)
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 energy_multiple_scans(start, stop, repeats, comment='', **metadata): """ Example ------- >>> RE(energy_scan(11350, 11450, 2)) """ flyers = [pb9.enc1, pba2.adc6, pba2.adc7] def inner(): md = { 'plan_args': {}, 'plan_name': 'energy_multiple_scans', 'comment': comment } md.update(**metadata) yield from bp.open_run(md=md) for i in range(0, repeats): print('Run:', i + 1) hhm_en.energy.move(start) ttime.sleep(2) while (hhm_en.energy.moving == True): ttime.sleep(.1) hhm_en.energy.move(stop) ttime.sleep(2) while (hhm_en.energy.moving == True): ttime.sleep(.1) #write_file(comment, [flyers[0].filepath.value, flyers[1].filepath.value, flyers[2].filepath.value] , '') yield from bp.close_run() for flyer in flyers: yield from bp.stage(flyer) yield from bp.stage(hhm) yield from bp.fly_during_wrapper(inner(), flyers) yield from bp.unstage(hhm) for flyer in flyers: yield from bp.unstage(flyer)
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 hhm_theta_scan(start, stop, num, flyers=[pb9.enc1, pba2.adc6, pba2.adc7], comment='', **metadata): """ Example ------- >>> RE(hhm_theta_scan(-0.1, 0.1, 2, [pb4.di, xia])) """ def inner(): md = {'plan_args': {}, 'plan_name': 'step scan', 'comment': comment} md.update(**metadata) yield from bp.open_run(md=md) # Start with a step scan. plan = bp.relative_scan([hhm_en.energy], hhm_en.energy, start, stop, num, md={'comment': comment}) # Wrap it in a fly scan with the Pizza Box. plan = bp.fly_during_wrapper(plan, flyers) # Working around a bug in fly_during_wrapper, stage and unstage the pizza box manually. for flyer in flyers: yield from bp.stage(flyer) yield from bp.stage(hhm) plan = bp.pchain(plan) #plan = bp.pchain(bp.stage(pb9.enc1), bp.stage(pba2.adc6), bp.stage(pba2.adc7), # plan, # bp.unstage(pb9.enc1), bp.unstage(pba2.adc6), bp.unstage(pba2.adc7)) yield from plan