Exemplo n.º 1
0
    def insert_take_dark(msg):
        nonlocal need_dark
        qualified_dark_uid = _validate_dark(expire_time=glbl["dk_window"])
        area_det = xpd_configuration["area_det"]

        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 (
                bpp.pchain(
                    bps.unstage(area_det),
                    take_dark(),
                    bps.stage(area_det),
                    bpp.single_gen(msg),
                    open_shutter_stub(),
                ),
                None,
            )
        elif msg.command == "open_run" and "dark_frame" not in msg.kwargs:
            return (
                bpp.pchain(bpp.single_gen(msg), open_shutter_stub()),
                None,
            )
        else:
            # do nothing if (not need_dark)
            return None, None
def motor_dark_step(detectors, motor, step):
    """
    Take darks while moving motors, wait for all to be finished before 
    taking light
    """

    yield from bps.checkpoint()
    print('l120')
    # close the shutter
    #yield from _close_shutter_stub() COMMENTED OUT (dark per light)
    print('l123')
    # move motors don't wait yet.
    # Note for Soham: use `group=None` to ramp temp after dark collected
    # (Broken and replaced below) yield from bps.abs_set(motor, step, group="dark_motor")
    yield from bps.abs_set(motor, step, group="dark_motor")
    print('l127')
    # take dark (this has an internal wait on the readback)
    #yield from bps.trigger_and_read(list(detectors), name="dark") COMMENTED OUT (dark per light)
    print('l130')
    # (Broken) now wait for the motors to be done too
    yield from bps.wait(group="dark_motor")
    print('l133')
    # open shutter
    yield from open_shutter_stub()
    print('l136')
    # take data
    yield from bps.trigger_and_read(list(detectors) + [motor])
    print('l139')
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
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"])
Exemplo n.º 7
0
 def inner():
     yield from open_shutter_stub()
     yield msg