예제 #1
0
파일: tomo.py 프로젝트: tacaswell/xpdAn
def pencil_tomo(source: Stream,
                qoi_name,
                translation,
                rotation,
                stack=None,
                **kwargs):
    """Extract data from a raw stream for pencil beam tomography

    Parameters
    ----------
    source : Stream
        The stream of raw event model data
    qoi_name : str
        The name of the QOI for this reconstruction
    kwargs

    Returns
    -------
    dict :
        The namespace
    """
    start = SimpleFromEventStream('start', (), upstream=source)
    if stack:
        stack_position = SimpleFromEventStream("event", ("data", stack),
                                               upstream=source)
    x = SimpleFromEventStream("event", ("data", translation), upstream=source)
    th = SimpleFromEventStream("event", ("data", rotation), upstream=source)

    # Extract the index for the translation and rotation so we can
    # extract the dimensions and extents
    # TODO: turn into proper function
    translation_position = SimpleFromEventStream(
        "start", ("motors", ),
        upstream=source).map(lambda x: x.index(translation))
    rotation_position = SimpleFromEventStream(
        "start", ("motors", ),
        upstream=source).map(lambda x: x.index(rotation))

    dims = SimpleFromEventStream("start", ("shape", ), upstream=source)
    th_dim = dims.zip(rotation_position).starmap(op.getitem)
    x_dim = dims.zip(translation_position).starmap(op.getitem)

    extents = SimpleFromEventStream("start", ("extents", ), upstream=source)
    th_extents = extents.zip(rotation_position).starmap(op.getitem)
    x_extents = extents.zip(translation_position).starmap(op.getitem)

    qoi = SimpleFromEventStream("event", ("data", qoi_name),
                                upstream=source,
                                principle=True)
    center = SimpleFromEventStream("start", ("tomo", "center"),
                                   upstream=source)
    source.starsink(StartStopCallback())
    return locals()
예제 #2
0
파일: tomo.py 프로젝트: xpdAcq/xpdAn
def pencil_tomo(source: Stream, qoi_name, translation, rotation, stack=None,
                **kwargs):
    """Extract data from a raw stream for pencil beam tomography

    Parameters
    ----------
    source : Stream
        The stream of raw event model data
    qoi_name : str
        The name of the QOI for this reconstruction
    kwargs

    Returns
    -------
    dict :
        The namespace
    """
    start = SimpleFromEventStream('start', (), upstream=source)
    if stack:
        stack_position = SimpleFromEventStream("event", ("data", stack),
                                               upstream=source)
    x = SimpleFromEventStream("event", ("data", translation), upstream=source)
    th = SimpleFromEventStream("event", ("data", rotation), upstream=source)

    # Extract the index for the translation and rotation so we can
    # extract the dimensions and extents
    # TODO: turn into proper function
    translation_position = SimpleFromEventStream(
        "start", ("motors",), upstream=source
    ).map(lambda x: x.index(translation))
    rotation_position = SimpleFromEventStream(
        "start", ("motors",), upstream=source
    ).map(lambda x: x.index(rotation))

    dims = SimpleFromEventStream("start", ("shape",), upstream=source)
    th_dim = dims.zip(rotation_position).starmap(op.getitem)
    x_dim = dims.zip(translation_position).starmap(op.getitem)

    extents = SimpleFromEventStream("start", ("extents",), upstream=source)
    th_extents = extents.zip(rotation_position).starmap(op.getitem)
    x_extents = extents.zip(translation_position).starmap(op.getitem)

    qoi = SimpleFromEventStream(
        "event", ("data", qoi_name), upstream=source, principle=True
    )
    center = SimpleFromEventStream(
        "start", ("tomo", "center"), upstream=source
    )
    source.starsink(StartStopCallback())
    return locals()
예제 #3
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"]
예제 #4
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"]
예제 #5
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
예제 #6
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",))
예제 #7
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"]
예제 #8
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",
    )