예제 #1
0
def setup_peakstats(*, motors, gs):
    "Set up peakstats"
    motor = list(motors)[0]
    key = first_key_heuristic(motor)
    ps = PeakStats(key, gs.MASTER_DET_FIELD, **gs.PS_CONFIG)
    gs.PS = ps
    ps.motor = motor
    return ps
예제 #2
0
def setup_peakstats(*, motors, gs):
    "Set up peakstats"
    motor = list(motors)[0]
    key = first_key_heuristic(motor)
    ps = PeakStats(key, gs.MASTER_DET_FIELD, **gs.PS_CONFIG)
    gs.PS = ps
    ps.motor = motor
    return ps
예제 #3
0
def setup_liveraster(*, motors, gs, shape, extent):
    """Setup a LiveTable by inspecting motors, shape, extent, and gs.
    """
    if len(motors) != 2:
        return None
    ylab, xlab = [first_key_heuristic(m) for m in motors]
    raster = LiveRaster(shape, gs.MASTER_DET_FIELD, xlabel=xlab,
                        ylabel=ylab, extent=extent, clim=[0, 1])
    return raster
예제 #4
0
def setup_liveraster(*, motors, gs, shape, extent):
    """Setup a LiveTable by inspecting motors, shape, extent, and gs.
    """
    if len(motors) != 2:
        return None
    ylab, xlab = [first_key_heuristic(m) for m in motors]
    raster = LiveRaster(shape, gs.MASTER_DET_FIELD, xlabel=xlab,
                        ylabel=ylab, extent=extent)
    return raster
예제 #5
0
    def plan(self):
        from bluesky.plans import subs_decorator, scan
        from bluesky.callbacks import LiveTable, LivePlot
        from bluesky.utils import first_key_heuristic

        lp = LivePlot(first_key_heuristic(self.dets[0]),
                      first_key_heuristic(self.motor),
                      fig=self.fig)

        @subs_decorator([LiveTable([self.motor] + self.dets), lp])
        def scan_gui_plan():
            yield from scan(self.dets,
                            self.motor,
                            self.start.value(),
                            self.stop.value(),
                            self.steps.value(),
                            md={'created_by': 'GUI'})

        return scan_gui_plan()
예제 #6
0
def setup_plot(*, motors, gs):
    """Setup a LivePlot by inspecting motors and gs.

    If motors is empty, use sequence number.
    """
    y_key = gs.PLOT_Y
    if motors:
        x_key = first_key_heuristic(list(motors)[0])
        fig_name = _figure_name('BlueSky: {} v {}'.format(y_key, x_key))
        ax = plt.figure(fig_name).gca()
        return LivePlot(y_key, x_key, ax=ax)
    else:
        fig_name = _figure_name('BlueSky: {} v sequence number'.format(y_key))
        ax = plt.figure(fig_name).gca()
        return LivePlot(y_key, ax=ax)
예제 #7
0
def setup_plot(*, motors, gs):
    """Setup a LivePlot by inspecting motors and gs.

    If motors is empty, use sequence number.
    """
    y_key = gs.PLOT_Y
    if motors:
        x_key = first_key_heuristic(list(motors)[0])
        fig_name = _figure_name('BlueSky: {} v {}'.format(y_key, x_key))
        ax = plt.figure(fig_name).gca()
        return LivePlot(y_key, x_key, ax=ax)
    else:
        fig_name = _figure_name('BlueSky: {} v sequence number'.format(y_key))
        ax = plt.figure(fig_name).gca()
        return LivePlot(y_key, ax=ax)
예제 #8
0
def _inner_loop(dets,
                exposure_count,
                delay,
                deadline,
                per_step,
                stream_name,
                done_signal=None):
    """Helper plan for the inner loop of the sinter plans

    This is very much like the repeat plan, but has less
    delay input types and more logic about finishing on a deadline.

    Parameters
    ----------
    dets : List[OphydObj]
        The detectors passed to per_step

    exposure_count : int
        The maximum number of times to call per_step

    delay : float
        The target delay between subsequent starts of per_step.

    deadline : float
         Wall time to be done by.  Under no condition take longer
         than this to completely run through plan.

    per_step : Callable[List[OphydObj], Optional[str]] -> Generator[Msg]
        The plan to run 'per step'.

        This is the signature of triger_and_read

    primary : str
        Passed to per_step

    done_signal : Signal, optional
        If passed, will exit early when goes to 1
    """
    if done_signal is not None:

        from bluesky.utils import first_key_heuristic
        signal_key = first_key_heuristic(done_signal)

        def _check_signal():
            val = yield from bps.read(done_signal)
            if val is None:
                return True
            val = val[signal_key]['value']
            return bool(val)
    else:
        _check_signal = None

    for j in range(exposure_count):
        start_time = time.monotonic()

        yield from bps.checkpoint()
        # if things get bogged down in data collection, bail early!
        if start_time > deadline:
            print(f'{start_time} > {deadline} bail!')
            break

        # this triggers the cameras
        yield from per_step(dets, stream_name)

        stop_time = time.monotonic()
        exp_actual = stop_time - start_time
        sleep_time = delay - exp_actual

        yield from bps.checkpoint()
        if _check_signal is not None:
            done = yield from _check_signal()
            if done:
                return
        if stop_time + sleep_time > deadline:
            yield from bps.sleep(deadline - stop_time)
            return
        else:
            yield from bps.sleep(delay - exp_actual)