Beispiel #1
0
def test_basic_usage():
    for i in range(5):
        insert_run_start(time=float(i), scan_id=i + 1,
                         owner='nedbrainard', beamline_id='example',
                         uid=str(uuid.uuid4()))
    header_1 = db[-1]

    header_ned = db(owner='nedbrainard')
    header_ned = db.find_headers(owner='nedbrainard')  # deprecated API
    header_null = db(owner='this owner does not exist')
    # smoke test
    db.fetch_events(header_1)
    db.fetch_events(header_ned)
    db.fetch_events(header_null)
    list(get_events(header_1))
    list(get_events(header_null))
    get_table(header_1)
    get_table(header_ned)
    get_table(header_null)

    # get events for multiple headers
    list(get_events(db[-2:]))

    # test time shift issue GH9
    table = get_table(db[105])
    assert table.notnull().all().all()
Beispiel #2
0
 def time_single_runstart(self, n):
     for _ in self.obj:
         mdsc.insert_run_start(scan_id=int(self.scan_id),
                               beamline_id='benchmark_b',
                               owner='benchmark_script',
                               time=1315315135.5135,
                               beamline_config=self.bcfg,
                               custom=self.custom)
Beispiel #3
0
def test_data_key():
    rs1_uid = insert_run_start(time=100.0, scan_id=1, owner="nedbrainard", beamline_id="example", uid=str(uuid.uuid4()))
    rs2_uid = insert_run_start(time=200.0, scan_id=2, owner="nedbrainard", beamline_id="example", uid=str(uuid.uuid4()))
    rs1, = find_run_starts(uid=rs1_uid)
    rs2, = find_run_starts(uid=rs2_uid)
    data_keys = {"fork": {"source": "_", "dtype": "number"}, "spoon": {"source": "_", "dtype": "number"}}
    insert_descriptor(run_start=rs1_uid, data_keys=data_keys, time=100.0, uid=str(uuid.uuid4()))
    insert_descriptor(run_start=rs2_uid, data_keys=data_keys, time=200.0, uid=str(uuid.uuid4()))
    result1 = db(data_key="fork")
    result2 = db(data_key="fork", start_time=150)
    assert len(result1) == 2
    assert len(result2) == 1
    actual = result2[0]["start"]["uid"]
    assert actual == str(rs2.uid)
Beispiel #4
0
def test_scan_id_lookup():
    for i in range(5):
        insert_run_start(time=float(i), scan_id=i + 1,
                         owner='docbrown', beamline_id='example',
                         beamline_config=insert_beamline_config({}, time=0.))
    for i in range(5):
        insert_run_start(time=float(i), scan_id=i + 1,
                         owner='nedbrainard', beamline_id='example',
                         beamline_config=insert_beamline_config({}, time=0.))
    header = db[3]
    scan_id = header.scan_id
    owner = header.owner
    assert_equal(scan_id, 3)
    # This should be the most *recent* Scan 3. There is ambiguity.
    assert_equal(owner, 'nedbrainard')
Beispiel #5
0
def test_scan_id_lookup():
    rd1 = [insert_run_start(time=float(i), scan_id=i + 1 + 314159,
                            owner='docbrown', beamline_id='example',
                            uid=str(uuid.uuid4())) for i in range(5)]

    rd2 = [insert_run_start(time=float(i)+1, scan_id=i + 1 + 314159,
                            owner='nedbrainard', beamline_id='example',
                            uid=str(uuid.uuid4())) for i in range(5)]
    header = db[3 + 314159]
    scan_id = header['start']['scan_id']
    assert scan_id == 3 + 314159
    assert rd2[2] == header['start']['uid']
    # This should be the most *recent* Scan 3 + 314159. There is ambiguity.
    owner = header['start']['owner']
    assert owner == 'nedbrainard'
Beispiel #6
0
def setup_module(module):
    mds_setup()
    fs_setup()

    owners = ["docbrown", "nedbrainard"]
    num_entries = 5
    rs = insert_run_start(time=ttime.time(), scan_id=105, owner="stepper", beamline_id="example", uid=str(uuid.uuid4()))
    step_scan.run(run_start_uid=rs)
    for owner in owners:
        for i in range(num_entries):
            logger.debug("{}: {} of {}".format(owner, i + 1, num_entries))
            rs = insert_run_start(
                time=ttime.time(), scan_id=i + 1, owner=owner, beamline_id="example", uid=str(uuid.uuid4())
            )
            # insert some events into mds
            temperature_ramp.run(run_start_uid=rs, make_run_stop=(i != 0))
Beispiel #7
0
def test_configuration():
    rs = insert_run_start(
        time=ttime.time(), scan_id=105, owner="stepper", beamline_id="example", uid=str(uuid.uuid4()), cat="meow"
    )
    step_scan.run(run_start_uid=rs)
    h = db[rs]
    # check that config is not included by default
    ev = next(get_events(h))
    assert set(ev["data"].keys()) == set(["Tsam", "point_det"])
    # find config in descriptor['configuration']
    ev = next(get_events(h, fields=["Tsam", "exposure_time"]))
    assert "exposure_time" in ev["data"]
    assert ev["data"]["exposure_time"] == 5
    assert "exposure_time" in ev["timestamps"]
    assert ev["timestamps"]["exposure_time"] == 0.0
    # find config in start doc
    ev = next(get_events(h, fields=["Tsam", "cat"]))
    assert "cat" in ev["data"]
    assert ev["data"]["cat"] == "meow"
    assert "cat" in ev["timestamps"]
    # find config in stop doc
    ev = next(get_events(h, fields=["Tsam", "exit_status"]))
    assert "exit_status" in ev["data"]
    assert ev["data"]["exit_status"] == "success"
    assert "exit_status" in ev["timestamps"]
Beispiel #8
0
def test_replay_plotx_ploty():
    # insert a run header with one plotx and one ploty
    rs = mdsapi.insert_run_start(
        time=ttime.time(), beamline_id='replay testing', scan_id=1,
        custom={'plotx': 'Tsam', 'ploty': ['point_det']},
        beamline_config=mdsapi.insert_beamline_config({}, ttime.time()))
    temperature_ramp.run(rs)
    # plotting replay in live mode with plotx and ploty should have the
    # following state after a few seconds of execution:
    # replay.
    app = QtApplication()
    ui = replay.create(replay.define_live_params())
    ui.title = 'testing replay with plotx and one value of ploty'
    ui.show()
    app.timed_call(4000, app.stop)
    app.start()
    try:
        # the x axis should be 'plotx'
        assert ui.scalar_collection.x == 'Tsam'
        # there should only be 1 scalar model currently plotting
        assert len([scalar_model for scalar_model
                    in ui.scalar_collection.scalar_models.values()
                    if scalar_model.is_plotting]) == 1
        # the x axis should not be the index
        assert not ui.scalar_collection.x_is_index
    except AssertionError:
        # gotta destroy the app or it will cause cascading errors
        ui.close()
        app.destroy()
        raise

    ui.close()
    app.destroy()
Beispiel #9
0
def test_configuration():
    rs = insert_run_start(time=ttime.time(), scan_id=105,
                          owner='stepper', beamline_id='example',
                          uid=str(uuid.uuid4()), cat='meow')
    step_scan.run(run_start_uid=rs)
    h = db[rs]
    # check that config is not included by default
    ev = next(get_events(h))
    assert set(ev['data'].keys()) == set(['Tsam', 'point_det'])
    # find config in descriptor['configuration']
    ev = next(get_events(h, fields=['Tsam', 'exposure_time']))
    assert 'exposure_time' in ev['data']
    assert ev['data']['exposure_time'] == 5
    assert 'exposure_time' in ev['timestamps']
    assert ev['timestamps']['exposure_time'] == 0.
    # find config in start doc
    ev = next(get_events(h, fields=['Tsam', 'cat']))
    assert 'cat' in ev['data']
    assert ev['data']['cat'] == 'meow'
    assert 'cat' in ev['timestamps']
    # find config in stop doc
    ev = next(get_events(h, fields=['Tsam', 'exit_status']))
    assert 'exit_status' in ev['data']
    assert ev['data']['exit_status'] == 'success'
    assert 'exit_status' in ev['timestamps']
Beispiel #10
0
def test_event_queue():
    scan_id = np.random.randint(1e12)  # unique enough for government work
    rs = insert_run_start(time=0., scan_id=scan_id,
                          owner='queue-tester', beamline_id='example',
                          beamline_config=insert_beamline_config({}, time=0.))
    header = db.find_headers(scan_id=scan_id)
    queue = EventQueue(header)
    # Queue should be empty until we create Events.
    empty_bundle = queue.get()
    assert_equal(len(empty_bundle), 0)
    queue.update()
    empty_bundle = queue.get()
    assert_equal(len(empty_bundle), 0)
    events = temperature_ramp.run(rs)
    # This should add a bundle of Events to the queue.
    queue.update()
    first_bundle = queue.get()
    assert_equal(len(first_bundle), len(events))
    more_events = temperature_ramp.run(rs)
    # Queue should be empty until we update.
    empty_bundle = queue.get()
    assert_equal(len(empty_bundle), 0)
    queue.update()
    second_bundle = queue.get()
    assert_equal(len(second_bundle), len(more_events))
    # Add Events from a different example into the same Header.
    other_events = image_and_scalar.run(rs)
    queue.update()
    third_bundle = queue.get()
    assert_equal(len(third_bundle), len(other_events))
Beispiel #11
0
def setup():
    fs_setup()
    mds_setup()

    rs_uid = insert_run_start(time=0.0, scan_id=1, owner='test',
                              beamline_id='test',
                              uid=str(uuid.uuid4()))
    temperature_ramp.run(run_start_uid=rs_uid)
Beispiel #12
0
def test_get_fields():
    rs = insert_run_start(time=ttime.time(), scan_id=105,
                          owner='stepper', beamline_id='example',
                          uid=str(uuid.uuid4()))
    step_scan.run(run_start_uid=rs)
    h = db[rs]
    actual = get_fields(h)
    assert actual == set(['Tsam', 'point_det'])
Beispiel #13
0
def test_uid_lookup():
    uid = str(uuid.uuid4())
    uid2 = uid[0] + str(uuid.uuid4())[1:]  # same first character as uid
    rs1 = insert_run_start(time=100.0, scan_id=1, uid=uid, owner="drstrangelove", beamline_id="example")
    insert_run_start(time=100.0, scan_id=1, uid=uid2, owner="drstrangelove", beamline_id="example")
    # using full uid
    actual_uid = db[uid]["start"]["uid"]
    assert actual_uid == uid
    assert rs1 == uid

    # using first 6 chars
    actual_uid = db[uid[:6]]["start"]["uid"]
    assert actual_uid == uid
    assert rs1 == uid

    # using first char (will error)
    pytest.raises(ValueError, lambda: db[uid[0]])
Beispiel #14
0
def setup():
    fs_setup()
    mds_setup()

    blc_uid = insert_beamline_config({}, ttime.time())
    rs_uid = insert_run_start(time=0.0, scan_id=1, owner='test',
                              beamline_id='test', beamline_config=blc_uid)
    temperature_ramp.run(run_start_uid=rs_uid)
Beispiel #15
0
def test_find_by_string_time():
    uid = insert_run_start(time=ttime.time(), scan_id=1,
                           owner='nedbrainard', beamline_id='example',
                           uid=str(uuid.uuid4()))
    today = datetime.today()
    tomorrow = date.today() + timedelta(days=1)
    today_str = today.strftime('%Y-%m-%d')
    tomorrow_str = tomorrow.strftime('%Y-%m-%d')
    result = db(start_time=today_str, stop_time=tomorrow_str)
    assert uid in [hdr['start']['uid'] for hdr in result]
Beispiel #16
0
def test_find_by_string_time():
    uid = insert_run_start(
        time=ttime.time(), scan_id=1, owner="nedbrainard", beamline_id="example", uid=str(uuid.uuid4())
    )
    today = datetime.today()
    tomorrow = date.today() + timedelta(days=1)
    today_str = today.strftime("%Y-%m-%d")
    tomorrow_str = tomorrow.strftime("%Y-%m-%d")
    result = db(start_time=today_str, stop_time=tomorrow_str)
    assert uid in [hdr["start"]["uid"] for hdr in result]
Beispiel #17
0
def test_indexing():
    for i in range(5):
        insert_run_start(time=float(i), scan_id=i + 1,
                         owner='nedbrainard', beamline_id='example',
                         uid=str(uuid.uuid4()))

    header = db[-1]
    assert not isinstance(header, list)
    assert header['start']['scan_id'] == 5

    header = db[-2]
    assert not isinstance(header, list)
    assert header['start']['scan_id'] == 4

    f = lambda: db[-100000]
    pytest.raises(IndexError, f)

    headers = db[-5:]
    assert isinstance(headers, list)
    assert len(headers) == 5

    headers = db[-6:]
    assert isinstance(headers, list)
    assert len(headers) == 6

    headers = db[-1:]
    assert isinstance(headers, list)
    assert len(headers) == 1
    assert headers[0]['start']['scan_id'] == 5

    headers = db[-2:-1]
    assert isinstance(headers, list)
    assert len(headers) == 1
    header, = headers
    assert header['start']['scan_id'] == 4

    assert [h['start']['scan_id'] for h in db[-3:-1]] == [4, 3]

    # fancy indexing, by location
    assert [h['start']['scan_id'] for h in db[[-3, -1, -2]]] == [3, 5, 4]

    # fancy indexing, by scan id
    assert [h['start']['scan_id'] for h in db[[3, 1, 2]]] == [3, 1, 2]
Beispiel #18
0
def test_process():
    rs = insert_run_start(time=ttime.time(), scan_id=105, owner="stepper", beamline_id="example", uid=str(uuid.uuid4()))
    step_scan.run(run_start_uid=rs)
    c = count()

    def f(name, doc):
        next(c)

    process(db[rs], f)
    assert next(c) == len(list(restream(db[rs])))
Beispiel #19
0
def test_uid_lookup():
    uid = str(uuid.uuid4())
    uid2 = uid[0] + str(uuid.uuid4())[1:]  # same first character as uid
    rs1 = insert_run_start(time=100., scan_id=1, uid=uid,
                           owner='drstrangelove', beamline_id='example')
    insert_run_start(time=100., scan_id=1, uid=uid2,
                     owner='drstrangelove', beamline_id='example')
    # using full uid
    actual_uid = db[uid]['start']['uid']
    assert_equal(actual_uid, uid)
    assert_equal(rs1, uid)

    # using first 6 chars
    actual_uid = db[uid[:6]]['start']['uid']
    assert_equal(actual_uid, uid)
    assert_equal(rs1, uid)

    # using first char (will error)
    assert_raises(ValueError, lambda: db[uid[0]])
Beispiel #20
0
def test_basic_usage():
    for i in range(5):
        insert_run_start(time=float(i), scan_id=i + 1,
                         owner='nedbrainard', beamline_id='example',
                         beamline_config=insert_beamline_config({}, time=0.))
    header_1 = db[-1]
    # Exercise reprs.
    header_1._repr_html_()
    repr(header_1)
    str(header_1)
    headers = db[-3:]
    headers._repr_html_()
    repr(headers)
    str(headers)

    header_ned = db.find_headers(owner='nedbrainard')
    header_null = db.find_headers(owner='this owner does not exist')
    events_1 = db.fetch_events(header_1)
    events_ned = db.fetch_events(header_ned)
    events_null = db.fetch_events(header_null)
Beispiel #21
0
def test_uid_lookup():
    uid = str(uuid.uuid4())
    uid2 = uid[0] + str(uuid.uuid4())[1:]  # same first character as uid
    rs1 = insert_run_start(time=100., scan_id=1, uid=uid,
                           owner='drstrangelove', beamline_id='example',
                           beamline_config=insert_beamline_config({}, time=0.))
    rs2 = insert_run_start(time=100., scan_id=1, uid=uid2,
                           owner='drstrangelove', beamline_id='example',
                           beamline_config=insert_beamline_config({}, time=0.))
    # using full uid
    actual_uid = db[uid].run_start_uid
    assert_equal(actual_uid, uid)

    # using first 6 chars
    actual_uid = db[uid[:6]].run_start_uid
    assert_equal(actual_uid, uid)

    # using first char (will error)
    f = lambda: db[uid[0]]
    assert_raises(ValueError, f)
Beispiel #22
0
def test_scan_id_lookup():
    rd1 = [
        insert_run_start(
            time=float(i), scan_id=i + 1 + 314159, owner="docbrown", beamline_id="example", uid=str(uuid.uuid4())
        )
        for i in range(5)
    ]

    rd2 = [
        insert_run_start(
            time=float(i) + 1, scan_id=i + 1 + 314159, owner="nedbrainard", beamline_id="example", uid=str(uuid.uuid4())
        )
        for i in range(5)
    ]
    header = db[3 + 314159]
    scan_id = header["start"]["scan_id"]
    assert scan_id == 3 + 314159
    assert rd2[2] == header["start"]["uid"]
    # This should be the most *recent* Scan 3 + 314159. There is ambiguity.
    owner = header["start"]["owner"]
    assert owner == "nedbrainard"
Beispiel #23
0
def _insert_run_start(name, doc):
    """Rearrange the dict for unpacking it into the MDS API."""
    # Move dynamic keys into 'custom' for MDS API.
    # We should change this in MDS to save the time of copying here:
    doc = copy.deepcopy(doc)
    for key in list(doc):
        if key not in known_run_start_keys:
            try:
                doc['custom']
            except KeyError:
                doc['custom'] = {}
            doc['custom'][key] = doc.pop(key)
    return mds.insert_run_start(**doc)
Beispiel #24
0
def test_data_key():
    rs1_uid = insert_run_start(time=100., scan_id=1,
                               owner='nedbrainard', beamline_id='example',
                               uid=str(uuid.uuid4()))
    rs2_uid = insert_run_start(time=200., scan_id=2,
                               owner='nedbrainard', beamline_id='example',
                               uid=str(uuid.uuid4()))
    rs1, = find_run_starts(uid=rs1_uid)
    rs2, = find_run_starts(uid=rs2_uid)
    data_keys = {'fork': {'source': '_', 'dtype': 'number'},
                 'spoon': {'source': '_', 'dtype': 'number'}}
    insert_descriptor(run_start=rs1_uid, data_keys=data_keys,
                            time=100.,
                            uid=str(uuid.uuid4()))
    insert_descriptor(run_start=rs2_uid, data_keys=data_keys, time=200.,
                            uid=str(uuid.uuid4()))
    result1 = db(data_key='fork')
    result2 = db(data_key='fork', start_time=150)
    assert len(result1) == 2
    assert len(result2) == 1
    actual = result2[0]['start']['uid']
    assert actual == str(rs2.uid)
Beispiel #25
0
def _insert_run_start(name, doc):
    """Rearrange the dict for unpacking it into the MDS API."""
    # Move dynamic keys into 'custom' for MDS API.
    # We should change this in MDS to save the time of copying here:
    doc = copy.deepcopy(doc)
    for key in list(doc):
        if key not in known_run_start_keys:
            try:
                doc['custom']
            except KeyError:
                doc['custom'] = {}
            doc['custom'][key] = doc.pop(key)
    return mds.insert_run_start(**doc)
Beispiel #26
0
def test_data_key():
    rs1_uid = insert_run_start(time=100., scan_id=1,
                               owner='nedbrainard', beamline_id='example',
                               beamline_config=insert_beamline_config(
                                   {}, time=0.))
    rs2_uid = insert_run_start(time=200., scan_id=2,
                               owner='nedbrainard', beamline_id='example',
                               beamline_config=insert_beamline_config(
                                   {}, time=0.))
    rs1, = find_run_starts(uid=rs1_uid)
    rs2, = find_run_starts(uid=rs2_uid)
    data_keys = {'fork': {'source': '_', 'dtype': 'number'},
                 'spoon': {'source': '_', 'dtype': 'number'}}
    evd1_uid = insert_event_descriptor(run_start=rs1_uid, data_keys=data_keys,
                                       time=100.)
    insert_event_descriptor(run_start=rs2_uid, data_keys=data_keys, time=200.)
    result1 = db.find_headers(data_key='fork')
    result2 = db.find_headers(data_key='fork', start_time=150)
    assert_equal(len(result1), 2)
    assert_equal(len(result2), 1)
    actual = result2[0].run_start_uid
    assert_equal(actual, str(rs2.uid))
Beispiel #27
0
def test_bad_header():
    # Exercise the code path that results in a 'badly formatted header'
    # in this case it works by inserting three run stops
    # one comes from the temperature_ramp.run() command
    # then two more come from stop1 and stop2
    start = insert_run_start(time=ttime.time(), scan_id=8985, owner='docbrown',
                          beamline_id='example',
                          beamline_config=insert_beamline_config({}, time=0.))
    ev = temperature_ramp.run(start)
    stop1 = insert_run_stop(start, time=ttime.time())
    stop2 = insert_run_stop(start, time=ttime.time())

    hdr = db[-1]
Beispiel #28
0
def setup():
    global conn
    db_disconnect()
    conn = db_connect(db_name, 'localhost', 27017)
    blc = insert_beamline_config({}, ttime.time())

    switch(channelarchiver=False)
    start, end = '2015-01-01 00:00:00', '2015-01-01 00:01:00'
    simulated_ca_data = generate_ca_data(['ch1', 'ch2'], start, end)
    ca.insert_data(simulated_ca_data)

    for i in range(5):
        insert_run_start(time=float(i),
                         scan_id=i + 1,
                         owner='docbrown',
                         beamline_id='example',
                         beamline_config=insert_beamline_config({}, time=0.))
    for i in range(5):
        insert_run_start(time=float(i),
                         scan_id=i + 1,
                         owner='nedbrainard',
                         beamline_id='example',
                         beamline_config=insert_beamline_config({}, time=0.))
Beispiel #29
0
def _insert_run_start(name, doc):
    "Add a beamline config that, for now, only knows the time."
    doc['beamline_config'] = _make_blc()
    # Move dynamic keys into 'custom' for MDS API.
    # We should change this in MDS to save the time of copying here:
    doc = copy.deepcopy(doc)
    for key in list(doc):
        if key not in known_run_start_keys:
            try:
                doc['custom']
            except KeyError:
                doc['custom'] = {}
            doc['custom'][key] = doc.pop(key)
    return mds.insert_run_start(**doc)
Beispiel #30
0
def _insert_run_start(doc):
    "Add a beamline config that, for now, only knows the time."
    doc['beamline_config'] = _make_blc()
    # Move dynamic keys into 'custom' for MDS API.
    # We should change this in MDS to save the time of copying here:
    doc = copy.deepcopy(doc)
    for key in list(doc):
        if key not in known_run_start_keys:
            try:
                doc['custom']
            except KeyError:
                doc['custom'] = {}
            doc['custom'][key] = doc.pop(key)
    return mds.insert_run_start(**doc)
Beispiel #31
0
def test_basic_usage():
    for i in range(5):
        insert_run_start(time=float(i), scan_id=i + 1,
                         owner='nedbrainard', beamline_id='example',
                         uid=str(uuid.uuid4()))
    header_1 = db[-1]

    header_ned = db(owner='nedbrainard')
    header_ned = db.find_headers(owner='nedbrainard')  # deprecated API
    header_null = db(owner='this owner does not exist')
    # smoke test
    db.fetch_events(header_1)
    db.fetch_events(header_ned)
    db.fetch_events(header_null)
    get_events(header_1)
    get_events(header_ned)
    get_events(header_null)
    get_table(header_1)
    get_table(header_ned)
    get_table(header_null)

    # get events for multiple headers
    get_events([header_1, header_ned])
Beispiel #32
0
 def mock_run_start(run_start_uid=None, sleep=0, make_run_stop=True):
     if run_start_uid is None:
         blc_uid = insert_beamline_config({}, time=get_time())
         run_start_uid = insert_run_start(time=get_time(), scan_id=1,
                                          beamline_id='example',
                                          uid=str(uuid.uuid4()),
                                          beamline_config=blc_uid)
     # these events are already the sanitized version, not raw mongo objects
     events = func(run_start_uid, sleep)
     # Infer the end run time from events, since all the times are
     # simulated and not necessarily based on the current time.
     time = max([event['time'] for event in events])
     if make_run_stop:
         run_stop_uid = insert_run_stop(run_start_uid, time=get_time(),
                                        exit_status='success')
         run_stop, = find_run_stops(uid=run_stop_uid)
     return events
Beispiel #33
0
def setup():
    mds_setup()
    fs_setup()

    owners = ['docbrown', 'nedbrainard']
    num_entries = 5
    for owner in owners:
        for i in range(num_entries):
            logger.debug('{}: {} of {}'.format(owner, i+1, num_entries))
            rs = insert_run_start(time=ttime.time(), scan_id=i + 1,
                                  owner=owner, beamline_id='example',
                                  uid=str(uuid.uuid4()))
            # insert some events into mds
            temperature_ramp.run(run_start_uid=rs, make_run_stop=(i != 0))
            if i == 0:
                # only need to do images once, it takes a while...
                image_and_scalar.run(run_start_uid=rs, make_run_stop=True)
Beispiel #34
0
def hdf_data_io():
    """
    Save data to db and run test when data is retrieved.
    """
    blc = insert_beamline_config({'cfg1': 1}, 0.0)
    run_start_uid = insert_run_start(time=0., scan_id=1, beamline_id='csx',
                                     uid=str(uuid.uuid4()),
                                     beamline_config=blc)

    # data keys entry
    data_keys = {'x_pos': dict(source='MCA:pos_x', dtype='number'),
                 'y_pos': dict(source='MCA:pos_y', dtype='number'),
                 'xrf_spectrum': dict(source='MCA:spectrum', dtype='array',
                                      #shape=(5,),
                                      external='FILESTORE:')}

    # save the event descriptor
    descriptor_uid = insert_event_descriptor(
        run_start=run_start_uid, data_keys=data_keys, time=0.,
        uid=str(uuid.uuid4()))

    # number of positions to record, basically along a horizontal line
    num = 5

    events = []
    for i in range(num):
        v_pos = 0
        h_pos = i

        spectrum_uid = get_data(v_pos, h_pos)

        # Put in actual ndarray data, as broker would do.
        data1 = {'xrf_spectrum': spectrum_uid,
                 'v_pos': v_pos,
                 'h_pos': h_pos}
        timestamps1 = {k: noisy(i) for k in data1}

        event_uid = insert_event(descriptor=descriptor_uid, seq_num=i,
                                 time=noisy(i), data=data1,
                                 uid=str(uuid.uuid4()),
                                 timestamps=timestamps1)
        event, = find_events(uid=event_uid)
        # test on retrieve data for all data sets
        events.append(event)
    return events
Beispiel #35
0
    def mock_run_start(run_start_uid=None, sleep=0, make_run_stop=True):
        if run_start_uid is None:
            run_start_uid = insert_run_start(time=get_time(),
                                             scan_id=1,
                                             beamline_id='example',
                                             uid=str(uuid.uuid4()))

        # these events are already the sanitized version, not raw mongo objects
        events = func(run_start_uid, sleep)
        # Infer the end run time from events, since all the times are
        # simulated and not necessarily based on the current time.
        time = max([event['time'] for event in events])
        if make_run_stop:
            run_stop_uid = insert_run_stop(run_start_uid,
                                           time=time,
                                           exit_status='success',
                                           uid=str(uuid.uuid4()))
            run_stop, = find_run_stops(uid=run_stop_uid)
        return events
Beispiel #36
0
 def setup(self, n):
     self.obj = range(n)
     self.bcfg = mdsc.insert_beamline_config(time=1315315135.5135,
                                             config_params={'param1': 1})
     self.data_keys = {'linear_motor': {'source': 'PV:pv1',
                                        'shape': None,
                                        'dtype': 'number'},
                       'scalar_detector': {'source': 'PV:pv2',
                                           'shape': None,
                                           'dtype': 'number'},
                       'Tsam': {'source': 'PV:pv3',
                                'dtype': 'number',
                                'shape': None}}
     self.custom = {'custom_key': 'value'}
     self.scan_id = 1903
     self.run_start = mdsc.insert_run_start(scan_id=int(self.scan_id),
                                            owner='benchmark_script',
                                            beamline_id='benchmark_b',
                                            time=1315315135.5135,
                                            beamline_config=self.bcfg,
                                            custom=self.custom)
     self.e_desc = mdsc.insert_event_descriptor(data_keys=self.data_keys,
                                                time=1315315135.5135,
                                                run_start=self.run_start)
     # Compose event data list for 1mil events in setup.
     # See params in event insert test to see how many of these are used
     func = np.cos
     num = EVENT_COUNT
     start = 0
     stop = 10
     sleep_time = .1
     self.data = list()
     for idx, i in enumerate(np.linspace(start, stop, num)):
         self.data.append({'linear_motor': [i, 1315315135.5135],
                           'Tsam': [i + 5, 1315315135.5135],
                           'scalar_detector': [func(i) +
                                               np.random.randn() / 100,
                                               1315315135.5135]})
Beispiel #37
0
    # Temperature Events
    for i, (time, temp) in enumerate(zip(*deadbanded_ramp)):
        time = float(time) + base_time
        data = {'Tsam': temp, 'Troom': temp + 10}
        timestamps = {'Tsam': time, 'Troom': time}
        event_uid = insert_event(descriptor=ev_desc2_uid,
                                 time=time,
                                 data=data,
                                 seq_num=i,
                                 uid=str(uuid.uuid4()),
                                 timestamps=timestamps)
        event, = find_events(uid=event_uid)
        events.append(event)
    return events


if __name__ == '__main__':
    import metadatastore.api as mdsc
    run_start_uid = mdsc.insert_run_start(
        scan_id=2032013,
        beamline_id='testbed',
        owner='tester',
        group='awesome-devs',
        project='Nikea',
        time=0.,
        uid=str(uuid.uuid4()),
    )

    print('run_start_uid = {0!s}'.format(run_start_uid))
    run(run_start_uid)
Beispiel #38
0
        'dtype': 'number',
        'shape': None
    }
}

try:
    last_hdr = next(find_last())
    scan_id = int(last_hdr.scan_id) + 1
except (IndexError, TypeError):
    scan_id = 1

custom = {}
# Create a BeginRunEvent that serves as entry point for a run
run_start = insert_run_start(scan_id=scan_id,
                             beamline_id='csx',
                             time=time.time(),
                             custom=custom,
                             uid=str(uuid.uuid4()))

# Create an EventDescriptor that indicates the data
# keys and serves as header for set of Event(s)
descriptor = insert_descriptor(data_keys=data_keys,
                               time=time.time(),
                               run_start=run_start,
                               uid=str(uuid.uuid4()))
func = np.cos
num = 1000
start = 0
stop = 10
sleep_time = .1
for idx, i in enumerate(np.linspace(start, stop, num)):
Beispiel #39
0
        events.append(event)

    # Temperature Events
    for i, (time, temp) in enumerate(zip(*deadbanded_ramp)):
        time = float(time) + base_time
        data = {'Tsam': temp}
        timestamps = {'Tsam': time}
        event_dict = dict(descriptor=ev_desc2_uid, time=time,
                          data=data, timestamps=timestamps, seq_num=i,
                          uid=str(uuid.uuid4()))
        event_uid = insert_event(**event_dict)
        event, = find_events(uid=event_uid)
        events.append(event)

    return events


if __name__ == '__main__':
    import metadatastore.api as mdsc

    run_start_uid = mdsc.insert_run_start(scan_id=3022013,
                                          beamline_id='testbed',
                                          owner='tester',
                                          group='awesome-devs',
                                          project='Nikea',
                                          time=common.get_time(),
                                          uid=str(uuid.uuid4()))

    print('run_start_uid = {0!s}'.format(run_start_uid))
    run(run_start_uid)
Beispiel #40
0
    # Temperature Events
    for i, (time, temp) in enumerate(zip(*deadbanded_ramp)):
        time = float(time) + base_time 
        data = {'Tsam': temp}
        timestamps = {'Tsam': time}
        event_dict = dict(descriptor=ev_desc2_uid, time=time,
                          data=data, timestamps=timestamps, seq_num=i)
        event_uid = insert_event(**event_dict)
        event, = find_events(uid=event_uid)
        events.append(event)

    #todo insert run stop if run_start_uid is not None

    return events


if __name__ == '__main__':
    import metadatastore.api as mdsc
    blc_uid = mdsc.insert_beamline_config({}, time=common.get_time())
    run_start_uid = mdsc.insert_run_start(scan_id=3022013,
                                          beamline_id='testbed',
                                          beamline_config=blc_uid,
                                          owner='tester',
                                          group='awesome-devs',
                                          project='Nikea',
                                          time=common.get_time())

    print('beamline_config_uid = %s' % blc_uid)
    print('run_start_uid = %s' % run_start_uid)
    run(run_start_uid)
db = client.toBemigrated1
beamline_cfg_mapping = dict()

beamline_configs = db.beamline_config.find()
for bc in beamline_configs:
    bcfg_id = bc['_id']
    the_bc = insert_beamline_config(config_params=bc['config_params'],
                                    time=bc['time'])
    beamline_cfg_mapping[bc['_id']] = the_bc

begin_runs = db.begin_run_event.find()
for br in begin_runs:
    the_run_start = insert_run_start(time=br['time'],
                                     beamline_id=br['beamline_id'],
                                     beamline_config=the_bc,
                                     owner=br['owner'],
                                     scan_id=br['scan_id'],
                                     custom=br.get('custom', {}),
                                     uid=br['uid'])
    event_descs = db.event_descriptor.find({'begin_run_id': br['_id']})
    max_time = 0.0
    for e_desc in event_descs:
        the_e_desc = insert_event_descriptor(run_start=the_run_start,
                                             data_keys=e_desc['data_keys'],
                                             time=e_desc['time'],
                                             uid=e_desc['uid'])
        events = db.event.find({'descriptor_id': e_desc['_id']})
        for ev in events:
            if ev['time'] > max_time:
                max_time = ev['time']
            insert_event(event_descriptor=the_e_desc,