コード例 #1
0
def test_iterate_spb_raw_run(mock_spb_raw_run):
    run = RunDirectory(mock_spb_raw_run)
    trains_iter = run.trains()
    tid, data = next(trains_iter)
    assert tid == 10000
    device = 'SPB_IRU_CAM/CAM/SIDEMIC:daqOutput'
    assert device in data
    assert data[device]['data.image.pixels'].shape == (1024, 768)
コード例 #2
0
def test_iterate_select_trains(mock_fxe_run):
    run = RunDirectory(mock_fxe_run)

    tids = [tid for (tid, _) in run.trains(train_range=by_id[10004:10006])]
    assert tids == [10004, 10005]

    tids = [tid for (tid, _) in run.trains(train_range=by_id[:10003])]
    assert tids == [10000, 10001, 10002]

    # Overlap with start of run
    tids = [tid for (tid, _) in run.trains(train_range=by_id[9000:10003])]
    assert tids == [10000, 10001, 10002]

    # Overlap with end of run
    tids = [tid for (tid, _) in run.trains(train_range=by_id[10478:10500])]
    assert tids == [10478, 10479]

    # Not overlapping
    with pytest.raises(ValueError) as excinfo:
        list(run.trains(train_range=by_id[9000:9050]))
    assert 'before' in str(excinfo.value)

    with pytest.raises(ValueError) as excinfo:
        list(run.trains(train_range=by_id[10500:10550]))
    assert 'after' in str(excinfo.value)

    tids = [tid for (tid, _) in run.trains(train_range=by_index[4:6])]
    assert tids == [10004, 10005]
コード例 #3
0
def test_iterate_run_glob_devices(mock_fxe_run):
    run = RunDirectory(mock_fxe_run)
    trains_iter = run.trains([("*/DET/*", "image.data")])
    tid, data = next(trains_iter)
    assert tid == 10000
    assert 'FXE_DET_LPD1M-1/DET/15CH0:xtdf' in data
    assert 'image.data' in data['FXE_DET_LPD1M-1/DET/15CH0:xtdf']
    assert 'detector.data' not in data['FXE_DET_LPD1M-1/DET/15CH0:xtdf']
    assert 'FXE_XAD_GEC/CAM/CAMERA' not in data
コード例 #4
0
def test_iterate_fxe_run(mock_fxe_raw_run):
    run = RunDirectory(mock_fxe_raw_run)
    trains_iter = run.trains()
    tid, data = next(trains_iter)
    assert tid == 10000
    assert 'FXE_DET_LPD1M-1/DET/15CH0:xtdf' in data
    assert 'image.data' in data['FXE_DET_LPD1M-1/DET/15CH0:xtdf']
    assert 'FXE_XAD_GEC/CAM/CAMERA' in data
    assert 'firmwareVersion.value' in data['FXE_XAD_GEC/CAM/CAMERA']
コード例 #5
0
def serve_files(path,
                port,
                fast_devices=None,
                require_all=False,
                repeat_stream=True,
                **kwargs):
    """Stream data from files through a TCP socket.

    Parameters
    ----------
    path: str
        Path to the HDF5 file or file folder.
    port: int
        Local TCP port to bind socket to.
    slow_devices: list of tuples
        [('src', 'prop')]
    fast_devices: list of tuples
        [('src', 'prop')]
    require_all: bool
        If set to True, will stream only trainIDs that has data
        corresponding to keys specified in fast_devices.
        Default: False
    repeat_stream: bool
        If set to True, will continue streaming when trains()
        iterator is empty. Trainids will be monotonically increasing.
        Default: False
    """
    try:
        corr_data = RunDirectory(path)
        num_trains = len(corr_data.train_ids)
    except Exception as ex:
        print(repr(ex))
        return

    streamer = ZMQStreamer(port, **kwargs)
    streamer.start()

    counter = 0
    repeat_stream = False
    while True:
        for tid, train_data in corr_data.trains(devices=fast_devices,
                                                require_all=require_all):
            # loop over corrected DataCollection
            if train_data:
                # Generate fake meta data with monotically increasing
                # trainids only after the actual trains in corrected data
                meta = generate_meta(train_data.keys(), tid +
                                     counter) if counter > 0 else None
                streamer.feed(train_data, metadata=meta)
        if not repeat_stream:
            break
        # increase the counter by total number of trains in a run
        counter += num_trains

    streamer.stop()
コード例 #6
0
def test_read_spb_proc_run(mock_spb_proc_run):
    run = RunDirectory(mock_spb_proc_run)  #Test for calib data
    assert len(run.files) == 16  # only 16 detector modules for calib data
    assert run.train_ids == list(range(10000, 10064))  #64 trains
    tid, data = next(run.trains())
    device = 'SPB_DET_AGIPD1M-1/DET/15CH0:xtdf'
    assert tid == 10000
    for prop in ('image.gain', 'image.mask', 'image.data'):
        assert prop in data[device]
    assert 'u1' == data[device]['image.gain'].dtype
    assert 'u4' == data[device]['image.mask'].dtype
    assert 'f4' == data[device]['image.data'].dtype
    run.info()  # Smoke test
コード例 #7
0
ファイル: test_reader.py プロジェクト: Landau1908/karabo_data
def test_run():
    test_run = RunDirectory(RUNPATH)

    train = test_run.trains()

    first_train = next(train)
    next(train)
    third_train = next(train)

    train_id = first_train[0]
    train_data = first_train[1]

    assert train_id == 1472806005
    for i in range(11):
        key = 'SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf'.format(i)
        assert key in train_data.keys()

    train_id = third_train[0]
    train_data = third_train[1]

    assert train_id == 1472810838
    assert len(train_data) == 11