Пример #1
0
def run_publisher(in_port, data_path, quiet=False):
    """
    Acquire data in an infinite loop and publish it.
    """
    publisher = Publisher(f"localhost:{in_port}")
    RE = RunEngine(loop=asyncio.new_event_loop())
    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.baseline.extend([motor1, motor2])
    RE.subscribe(publisher)

    def factory(name, doc):
        serializer = Serializer(data_path / "abc", flush=True)
        return [serializer], []

    rr = RunRouter([factory])
    RE.subscribe(rr)
    if not quiet:
        RE.subscribe(LiveTable(["motor", "det"]))

    motor.delay = 0.2
    det.kind = "hinted"

    def infinite_plan():
        while True:
            for i in range(1, 5):
                yield from sleep(2)
                yield from scan([det], motor, -1, 1, 5 * i)

    # Just as a convenience, avoid collission with scan_ids of runs in Catalog.
    RE.md["scan_id"] = 100
    try:
        RE(infinite_plan())
    finally:
        RE.halt()
Пример #2
0
def run_publisher(in_port, data_path):
    """
    Acquire data in an infinite loop and publish it.
    """
    import asyncio
    from bluesky.callbacks.zmq import Publisher
    from suitcase.jsonl import Serializer
    from ophyd.sim import noisy_det, motor1, motor2
    from bluesky.plans import count
    from bluesky.preprocessors import SupplementalData
    from bluesky.plan_stubs import sleep
    publisher = Publisher(f'localhost:{in_port}')
    RE = RunEngine(loop=asyncio.new_event_loop())
    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.baseline.extend([motor1, motor2])
    RE.subscribe(publisher)

    def factory(name, doc):
        serializer = Serializer(data_path / 'abc')
        serializer('start', doc)
        return [serializer], []

    rr = RunRouter([factory])
    RE.subscribe(rr)

    def infinite_plan():
        while True:
            yield from sleep(3)
            yield from count([noisy_det], 20, delay=0.5)

    try:
        RE(infinite_plan())
    finally:
        RE.halt()
Пример #3
0
def generate_example_catalog(data_path):
    data_path = Path(data_path)

    def factory(name, doc):
        serializer = Serializer(data_path / 'abc')
        serializer('start', doc)
        return [serializer], []

    RE = RunEngine()
    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.baseline.extend([motor1, motor2])
    rr = RunRouter([factory])
    RE.subscribe(rr)
    RE(count([det]))
    RE(count([noisy_det], 5))
    RE(scan([det], motor, -1, 1, 7))
    RE(grid_scan([det4], motor1, -1, 1, 4, motor2, -1, 1, 7, False))
    RE(scan([det], motor, -1, 1, motor2, -1, 1, 5))
    RE(count([noisy_det, det], 5))
    RE(count([random_img], 5))
    RE(count([img], 5))

    def factory(name, doc):
        serializer = Serializer(data_path / 'xyz')
        serializer('start', doc)
        return [serializer], []

    RE = RunEngine()
    rr = RunRouter([factory])
    RE.subscribe(rr)
    RE(count([det], 3))

    catalog_filepath = data_path / 'catalog.yml'
    with open(catalog_filepath, 'w') as file:
        file.write(f'''
sources:
  abc:
    description: Some imaginary beamline
    driver: bluesky-jsonl-catalog
    container: catalog
    args:
      paths: {Path(data_path) / 'abc' / '*.jsonl'}
      handler_registry:
        NPY_SEQ: ophyd.sim.NumpySeqHandler
    metadata:
      beamline: "00-ID"
  xyz:
    description: Some imaginary beamline
    driver: bluesky-jsonl-catalog
    container: catalog
    args:
      paths: {Path(data_path) / 'xyz' / '*.jsonl'}
      handler_registry:
        NPY_SEQ: ophyd.sim.NumpySeqHandler
    metadata:
      beamline: "99-ID"
''')
    return str(catalog_filepath)
Пример #4
0
def example_data(hw, detector, RE):  # noqa
    sd = SupplementalData(baseline=[hw.motor])
    RE.preprocessors.append(sd)

    docs = []

    def collect(name, doc):
        docs.append((name, event_model.sanitize_doc(doc)))

    uid, = RE(scan([detector], hw.motor, -1, 1, 20), collect)
    return uid, docs
Пример #5
0
def test_monitoring(db, RE, hw):
    # A monitored signal emits Events from its subscription thread, which
    # silently failed on the sqlite backend until it was refactored to make
    # this test pass.
    import bluesky.plan_stubs as bps
    import bluesky.plans as bp
    from bluesky.preprocessors import SupplementalData

    RE.subscribe(db.insert)
    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.monitors.append(hw.rand)
    RE(bp.count([hw.det], 5, delay=1))
    assert len(db[-1].table('rand_monitor')) > 1
Пример #6
0
def test_two_streams(RE):
    def pretty_print(name, doc):
        pprint.pprint(name)
        pprint.pprint(doc)

    def serializer_factory(name, start_doc):
        serializer = Serializer("xdi")
        serializer("start", start_doc)
        return [serializer], []

    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.baseline = [det1, motor1, motor2]

    RE.subscribe(pretty_print)
    RE.subscribe(RunRouter([serializer_factory]))

    suitcase_meta_data = {"config": xdi_file_template}

    xdi_meta_data = {
        "Element_symbol": "A",
        "Element_edge": "K",
        "Mono_d_spacing": 10.0
    }

    nx_meta_data = {
        "Source": {
            "name": "NSLS-II"
        },
        "Instrument": {
            "name": "BMM"
        },
        "Beam": {
            "incident_energy": 1000.0
        },
    }

    dets = [det1, det2]
    RE(
        count(dets, num=5),
        md={
            "suitcase-xdi": suitcase_meta_data,
            "NX": nx_meta_data,
            "XDI": xdi_meta_data,
        },
    )
Пример #7
0
def generate_example_data(callback):
    from ophyd.sim import det, motor1, motor2, motor3
    motor1.set(3.1).wait()
    motor2.set(-1000.02).wait()
    motor3.set(5.01).wait()

    RE = RunEngine()
    sd = SupplementalData(baseline=[motor1, motor2, motor3])
    RE.preprocessors.append(sd)

    RE.md["operator"] = "Dmitri"
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-01-01 9:00", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-01-01 9:05", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-01-01 9:07", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 9:00", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 9:05", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 13:00", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 15:00", callback))
    RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 15:05", callback))
    RE(
        count([det], 5, delay=0.05),
        RewriteTimes("2020-02-01 15:07", callback),
        operator="Michael",
    )
    RE(
        count([det], 5, delay=0.05),
        RewriteTimes("2020-02-01 15:08", callback),
        operator="Michael",
    )
    _generate_newton_data(
        RE,
        callback,
        [
            "2020-02-02 9:00",
            "2020-02-02 10:00",
            "2020-02-02 12:00",
            "2020-02-02 13:00",
            "2020-02-02 15:00",
            "2020-02-02 17:00",
            "2020-02-02 19:00",
        ],
    )
Пример #8
0
def test_num_events(RE, hw, db):
    RE.subscribe(db.insert)

    uid1, = RE(count([]))
    h = db[uid1]
    assert h.stop['num_events'] == {}

    uid2, = RE(count([hw.det], 5))
    h = db[uid2]
    assert h.stop['num_events'] == {'primary': 5}

    sd = SupplementalData(baseline=[hw.det])
    RE.preprocessors.append(sd)

    uid3, = RE(count([]))
    h = db[uid3]
    assert h.stop['num_events'] == {'baseline': 2}

    uid4, = RE(count([hw.det], 5))
    h = db[uid4]
    assert h.stop['num_events'] == {'primary': 5, 'baseline': 2}
Пример #9
0
def test_num_events(RE, hw, db):

    RE.subscribe(db.insert)

    rs1 = RE(count([]))
    if RE.call_returns_result:
        uid1 = rs1.run_start_uids[0]
    else:
        uid1 = rs1[0]
    h = db[uid1]
    assert h.stop['num_events'] == {}

    rs2 = RE(count([hw.det], 5))
    if RE.call_returns_result:
        uid2 = rs2.run_start_uids[0]
    else:
        uid2 = rs2[0]
    h = db[uid2]
    assert h.stop['num_events'] == {'primary': 5}

    sd = SupplementalData(baseline=[hw.det])
    RE.preprocessors.append(sd)

    rs3 = RE(count([]))
    if RE.call_returns_result:
        uid3 = rs3.run_start_uids[0]
    else:
        uid3 = rs3[0]
    h = db[uid3]
    assert h.stop['num_events'] == {'baseline': 2}

    rs4 = RE(count([hw.det], 5))
    if RE.call_returns_result:
        uid4 = rs4.run_start_uids[0]
    else:
        uid4 = rs4[0]
    h = db[uid4]
    assert h.stop['num_events'] == {'primary': 5, 'baseline': 2}
Пример #10
0
def test_with_baseline(RE, hw):
    bec = BestEffortCallback()
    RE.subscribe(bec)
    sd = SupplementalData(baseline=[hw.det])
    RE.preprocessors.append(sd)
    RE(scan([hw.ab_det], hw.motor, 1, 5, 5))
fg2.freq.set(test_frequency)
fg2.v.set(0.1)
fg2.offset.set(0)
fg2.output.set('OFF')

# ------------------------------------------------
#           Setup Supplemental Data
# ------------------------------------------------
from bluesky.preprocessors import SupplementalData

baseline_detectors = []
for dev in [fg, lia]:
    for name in dev.component_names:
        if getattr(dev, name).kind == Kind.config:
            baseline_detectors.append(getattr(dev, name))
sd = SupplementalData(baseline=baseline_detectors, monitors=[], flyers=[])
RE.preprocessors.append(sd)

# --------------------------------------------------------
#                   Get a baseline with averaging
# --------------------------------------------------------
uid_baseline = RE(
    count([lia.disp_val], num=40, delay=0.2),
    LiveTable(['lockin_A']),
    # input parameters below are added to metadata
    attenuator='60dB',
    purpose='dynamic_reserve_SR810',
    operator='Lucas',
    dut='SR810',
    preamp='yes_AD8655',
    notes='baseline-no-interferer')
Пример #12
0
            return []

    return [], [subfactory]


db.filler.handler_registry['npy'] = handler
RE = RunEngine({})
RE.subscribe(db.v1.insert)
dispatching_filler = DispatchingFiller(handler, inplace=False)
dispatching_filler.subscribe(RunRouter([factory]))
#RE.subscribe(dispatching_filler)

# image = self.image_class(func, shape=shape, ax=ax, **self.imshow_options)
# RE.subscribe(RunRouter([factory]))

sd = SupplementalData()
sd.baseline.extend([motor1, motor2, motor])
RE.preprocessors.append(sd)


class ArraySignal(EpicsSignalBase):
    def __init__(self, read_pv, **kwargs):
        super().__init__(read_pv, **kwargs)
        cl = self.cl
        base_pv, _ = read_pv.rsplit(':', maxsplit=1)
        self._size_pv = cl.get_pv(':'.join((base_pv, 'ArraySize_RBV')))

        self._last_ret = None
        self._asset_docs_cache = []

    def trigger(self):