Beispiel #1
0
def to_event_model(data, output_info, md=None):
    """Take an iterable of data and put it into the event model

    Parameters
    ----------
    data: iterable
        The data to be inserted
    output_info: list of tuple
        The name of the data and information to put into the descriptor
    md : iterable of dicts
        an iterable of dictionaries to use as metadata for the start documents


    Yields
    -------
    name: str
        Name of doc
    document: dict
        Document of data

    Notes
    -----
    This is only for demonstration/example use, do not use for production.
    """
    if md is None:
        md = {}
    else:
        md = md.copy()
    # add some metadata
    md.update({"source": "to_event_model"})
    source = Stream()
    fes = SimpleFromEventStream("start", (), source, principle=True)
    tes = SimpleToEventStream(fes, output_info, **md)

    start = None
    for d in data:
        if not start:
            yield tes.start(d)
            yield tes.descriptor(d)
        yield tes.event(d)
    yield "stop", tes._create_stop(d)
Beispiel #2
0
    def run_exp(delay):  # pragma: no cover
        time.sleep(delay)
        print("running exp")

        p = Publisher(proxy[0], prefix=b"raw")
        RE.subscribe(p)

        # Tiny fake pipeline
        pp = Publisher(proxy[0], prefix=b"an")
        raw_source = Stream()
        SimpleFromEventStream(
            "event",
            ("data", "img"),
            raw_source.starmap(Retrieve({"NPY_SEQ": NumpySeqHandler})),
            principle=True,
        ).map(lambda x: x * 2).SimpleToEventStream(
            ("img2", ), analysis_stage="pdf").starsink(pp)
        RE.subscribe(lambda *x: raw_source.emit(x))

        RE(bp.count([hw.img], md=dict(analysis_stage="raw")))
        print("finished exp")
        p.close()
Beispiel #3
0
    motors = step.keys()
    yield from move()
    plt.pause(.001)
    yield from trigger_and_read(list(detectors) + list(motors))


install_kicker()
bec = BestEffortCallback()
bec.enable_plots()
hw = hw()
RE = RunEngine()
# build the pipeline
raw_source = Stream()
raw_output = SimpleFromEventStream('event', ('data', 'det_a'),
                                   raw_source,
                                   principle=True)
raw_output2 = SimpleFromEventStream('event', ('data', 'noisy_det'), raw_source)

pipeline = raw_output.union(raw_output2).map(lambda x: 1).accumulate(
    lambda x, y: x + y)

res = SimpleToEventStream(pipeline, ('result', ))

merge = AlignEventStreams(res, raw_source)
merge.starsink(bec)

RE.subscribe(lambda *x: raw_source.emit(x))
RE(
    pchain(
        bp.scan([hw.noisy_det], hw.motor, 0, 10, 10),
Beispiel #4
0
install_kicker()
p = Publisher(glbl_dict["inbound_proxy_address"])
hw = hw()
import numpy as np

rand_img = SynSignal(
    func=lambda: np.array(np.random.random((10, 10))),
    name="img",
    labels={"detectors"},
)
RE = RunEngine()
# build the pipeline
raw_source = Stream()
raw_output = SimpleFromEventStream("event", ("data", "det_a"),
                                   raw_source,
                                   principle=True)
raw_output2 = SimpleFromEventStream("event", ("data", "noisy_det"), raw_source)
raw_output3 = SimpleFromEventStream("event", ("data", "img"), raw_source)

pipeline = (raw_output.union(raw_output2, raw_output3.map(
    np.sum)).map(lambda x: x**2).accumulate(lambda x, y: x + y))

res = SimpleToEventStream(pipeline, ("result", ))

merge = AlignEventStreams(raw_source.starmap(StripDepVar()), res)
merge.sink(pprint)
# send to viz server
merge.starsink(p)

RE.subscribe(lambda *x: raw_source.emit(x))
Beispiel #5
0
def amorphsivity_fem(source, **kwargs):
    pdf = SimpleFromEventStream(
        "event", ("data", "gr"), source, principle=True
    )
    return locals()