Ejemplo n.º 1
0
def test_recording_from_arrays():
    # need a list of array-like data structures
    x = np.random.rand(3, 200)
    y = np.random.rand(1, 200)
    z = np.random.rand(5, 200)
    arrays = [x, y, z]
    # a name for the recording that will hold the signals
    rec_name = 'testing123'
    # the sampling rate for the signals, or a list of
    # individual sampling rates (if different)
    fs = [100, 100, 200]
    # a list of signal names (optional, but preferred)
    names = ['stim', 'resp', 'reference']
    # a list of keyword arguments for each signal,
    # such as channel names or epochs (also optional)
    kwargs = [{
        'chans': ['2kHz', '4kHz', '8kHz']
    }, {
        'chans': ['spike_rate']
    }, {
        'meta': {
            'experiment': 'oddball_2'
        },
        'chans': ['One', 'Two', 'Three', 'Four', 'Five']
    }]
    rec = Recording.load_from_arrays(arrays,
                                     rec_name,
                                     fs,
                                     sig_names=names,
                                     signal_kwargs=kwargs)
    # should also work with integer fs instead of list
    rec = Recording.load_from_arrays(arrays,
                                     rec_name,
                                     100,
                                     sig_names=names,
                                     signal_kwargs=kwargs)

    # All signal names should be present in recording signals dict
    contains = [(n in rec.signals.keys()) for n in names]
    assert not (False in contains)

    bad_names = ['stim']
    # should get an error now since len(names)
    # doesn't match up with len(arrays)
    with pytest.raises(ValueError):
        rec = Recording.load_from_arrays(arrays,
                                         rec_name,
                                         fs,
                                         sig_names=bad_names,
                                         signal_kwargs=kwargs)
Ejemplo n.º 2
0
def simple_recording():
    stim = np.random.rand(18, 200)
    resp = np.random.rand(1, 200)
    return Recording.load_from_arrays([stim, resp],
                                      'simple_recording',
                                      100,
                                      sig_names=['stim', 'resp'])