def light_dark_nd_step(detectors, step, pos_cache): """ Inner loop of an N-dimensional step scan This is the default function for ``per_step`` param`` in ND plans. Parameters ---------- detectors : iterable devices to read step : dict mapping motors to positions in this step pos_cache : dict mapping motors to their last-set positions """ def move(): yield Msg("checkpoint") grp = _short_uid("set") for motor, pos in step.items(): if pos == pos_cache[motor]: # This step does not move this motor. continue yield Msg("set", motor, pos, group=grp) pos_cache[motor] = pos yield Msg("wait", None, group=grp) motors = step.keys() yield from close_shutter_stub() yield from move() for k, v in sub_sample_dict.items(): if np.abs(sample_motor.get().user_readback - k) < 1.5: inner_dict = v break else: inner_dict = {"exposure": .1, "wait": 1} print(inner_dict) yield from configure_area_det_expo(inner_dict["exposure"]) # This is to make certain that the detector has properly configured the # exposure time, uncomment if waits don't work # yield from bps.sleep(10) yield from bps.trigger_and_read(list(detectors) + list(motors) + [shutter], name="dark") yield from open_shutter_stub() t0 = time.time() yield from bps.trigger_and_read(list(detectors) + list(motors) + [shutter]) t1 = time.time() print("INFO: exposure time (plus minor message overhead) = {:.2f}".format( t1 - t0)) yield from close_shutter_stub() yield from bps.sleep(inner_dict["wait"])
def take_dark(): """a plan for taking a single dark frame""" print("INFO: closing shutter...") yield from close_shutter_stub() print("INFO: taking dark frame....") # upto this stage, area_det has been configured to so exposure time is # correct area_det = xpd_configuration["area_det"] acq_time = area_det.cam.acquire_time.get() if hasattr(area_det, 'images_per_set'): num_frame = area_det.images_per_set.get() else: num_frame = 1 computed_exposure = acq_time * num_frame # update md _md = { "sp_time_per_frame": acq_time, "sp_num_frames": num_frame, "sp_computed_exposure": computed_exposure, "sp_type": "ct", "sp_plan_name": "dark_{}".format(computed_exposure), "dark_frame": True, } c = bp.count([area_det], md=_md) yield from bpp.subs_wrapper(c, {"stop": [_update_dark_dict_list]}) # TODO: remove this, since it kinda depends on what happens next? print("opening shutter...")
def per_step(detectors, step: dict, pos_cache: dict): _motors = step.keys() yield from my_move_per_step(step, pos_cache) yield from bps.sleep(wait_for_step) yield from open_shutter_stub() yield from bps.sleep(wait_for_shutter) yield from bps.trigger_and_read(list(detectors) + list(_motors)) yield from close_shutter_stub()
def xpdacq_trigger_and_read(detectors: list, name: str = "primary") -> typing.Generator: """Open shutter, wait, trigger and read detectors, close shutter.""" yield from bps.checkpoint() yield from xb.open_shutter_stub() yield from bps.sleep(xb.glbl["shutter_sleep"]) yield from bps.trigger_and_read(detectors, name=name) yield from xb.close_shutter_stub()
def per_step(detectors, motor, step): """ customized step to ensure shutter is open before reading at each motor point and close shutter after reading """ yield from bps.checkpoint() yield from bps.abs_set(motor, step, wait=True) yield from bps.sleep(wait) yield from open_shutter_stub() yield from bps.sleep(glbl["shutter_sleep"]) yield from bps.trigger_and_read(list(detectors) + [motor]) yield from close_shutter_stub()
def inner_shutter_control(msg): if msg.command == "trigger": def inner(): yield from open_shutter_stub() yield msg return inner(), None elif msg.command == "save": return None, close_shutter_stub() else: return None, None