Example #1
0
def test_to_event_model_new_api_multi_parent(RE, hw):
    source = Stream()
    t = FromEventStream("event", ("data", "motor"), source, principle=True)
    t2 = FromEventStream("event", ("data", "motor"), source, principle=True)
    assert t.principle

    n = simple_to_event_stream_new_api({
        t.zip(t2).pluck(0): {
            "data_keys": {
                "ct": {
                    "units": "arb",
                    "precision": 2
                }
            }
        }
    })
    tt = t.sink_to_list()
    p = n.pluck(0).sink_to_list()
    d = n.pluck(1).sink_to_list()

    RE.subscribe(unstar(source.emit))
    RE.subscribe(print)

    RE(scan([hw.motor], hw.motor, 0, 9, 10))

    assert tt
    assert set(p) == {"start", "stop", "event", "descriptor"}
    assert d[1]["hints"] == {"analyzer": {"fields": ["ct"]}}
    assert d[1]["data_keys"]["ct"]["units"] == "arb"
    assert d[-1]["run_start"]
Example #2
0
def test_to_event_model_new_api_no_principle(RE, hw):
    source = Stream()
    stop = FromEventStream("stop", (), source)
    t = FromEventStream("event", ("data", "motor"), source, stream_name="hi")
    tt = t.zip(stop)
    simple_to_event_stream_new_api(
        {
            t: {
                "data_keys": {
                    "ct": {
                        "units": "arb",
                        "precision": 2
                    }
                }
            },
            tt: {
                "name": "final",
                "data_keys": {
                    "ct": {
                        "units": "arb",
                        "precision": 2
                    }
                },
            },
        },
        hello="world",
    )
Example #3
0
def test_parent_nodes():
    # build the graph
    g1 = FromEventStream(
        "event",
        ("data", "det_image"),
        principle=True,
        stream_name="g1",
        asynchronous=True,
    )
    g11 = FromEventStream("event", ("data", "det_image"),
                          stream_name="g11",
                          asynchronous=True)
    g2 = g1.zip(g11).starmap(op.mul, stream_name="mul")
    g = g2.SimpleToEventStream(("img2", ))
    l1 = g.sink_to_list()
    # g.sink(print)
    assert len(g.translation_nodes) == 2
    print("start experiment")

    # run the experiment
    l0 = []
    for yy in y(5):
        l0.append(yy)
        g11.update(yy)
        g1.update(yy)
        print(g11.start_uid)

    assert len(l1[0][1]["parent_node_map"]) == 2
Example #4
0
def test_no_parent_nodes():
    # build the graph
    g1 = FromEventStream("event", ("data", "det_image"),
                         stream_name="g1",
                         asynchronous=True)
    g11 = FromEventStream("event", ("data", "det_image"),
                          stream_name="g11",
                          asynchronous=True)
    g2 = g1.zip(g11).starmap(op.mul, stream_name="mul")
    g2.SimpleToEventStream(("img2", ))
Example #5
0
def test_to_event_model_new_api_multi(RE, hw):
    source = Stream()
    stop = FromEventStream("stop", (), source)
    t = FromEventStream("event", ("data", "motor"),
                        source,
                        principle=True,
                        stream_name="hi")
    assert t.principle

    tt = t.zip(stop)
    n = simple_to_event_stream_new_api(
        {
            t: {
                "data_keys": {
                    "ct": {
                        "units": "arb",
                        "precision": 2
                    }
                }
            },
            tt: {
                "name": "final",
                "data_keys": {
                    "ct": {
                        "units": "arb",
                        "precision": 2
                    }
                },
            },
        },
        hello="world",
    )
    tt = t.sink_to_list()
    p = n.pluck(0).sink_to_list()
    d = n.pluck(1).sink_to_list()

    RE.subscribe(unstar(source.emit))
    RE.subscribe(print)

    RE(scan([hw.motor], hw.motor, 0, 9, 10))

    assert tt
    assert set(p) == {"start", "stop", "event", "descriptor"}
    assert d[0]["hello"] == "world"
    assert d[1]["hints"] == {"analyzer": {"fields": ["ct"]}}
    assert d[1]["data_keys"]["ct"]["units"] == "arb"
    assert d[-3]["name"] == "final"
    assert d[-1]["run_start"]
Example #6
0
def test_replay_export_test():
    def y():
        suid = str(uuid.uuid4())
        yield ("start", {"uid": suid, "time": time.time()})
        duid = str(uuid.uuid4())
        yield (
            "descriptor",
            {
                "uid": duid,
                "run_start": suid,
                "name": "primary",
                "data_keys": {
                    "det_image": {
                        "dtype": "int",
                        "units": "arb"
                    }
                },
                "time": time.time(),
            },
        )
        for i in range(5):
            yield (
                "event",
                {
                    "uid": str(uuid.uuid4()),
                    "data": {
                        "det_image": i
                    },
                    "timestamps": {
                        "det_image": time.time()
                    },
                    "seq_num": i + 1,
                    "time": time.time(),
                    "descriptor": duid,
                },
            )
        yield (
            "stop",
            {
                "uid": str(uuid.uuid4()),
                "time": time.time(),
                "run_start": suid
            },
        )

    print("build graph")
    g1 = FromEventStream("event", ("data", "det_image"),
                         principle=True,
                         stream_name="g1")
    g11 = FromEventStream("event", ("data", "det_image"), stream_name="g11")
    g11_1 = g1.zip(g11)
    g2 = g11_1.starmap(op.mul).map(np.log)
    g = g2.SimpleToEventStream(("img2", ))
    from pprint import pprint

    g.sink(pprint)
    L = g.sink_to_list()

    print("run experiment")
    for yy in y():
        print(yy[0])
        g11.update(yy)
        g1.update(yy)
    assert L[-1][1]["run_start"]