Esempio n. 1
0
def test_info():
    """Test info object"""
    raw = Raw(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
                    baseline=(None, 0))

    evoked = epochs.average()

    events = read_events(event_name)

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert_true('a' in info)
    assert_true('b' in info)
    info[42] = 'foo'
    assert_true(info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert_true(isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert_equal(len(info_str.split('\n')), len(obj.info.keys()) + 2)
        assert_true(all(k in info_str for k in obj.info.keys()))

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert_equal(info['nchan'], nchan)
    assert_equal(list(info['ch_names']), ch_names)

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Test updating of fields
    del info['chs'][-1]
    info._update_redundant()
    assert_equal(info['nchan'], nchan - 1)
    assert_equal(list(info['ch_names']), ch_names[:-1])

    info['chs'][0]['ch_name'] = 'foo'
    info._update_redundant()
    assert_equal(info['ch_names'][0], 'foo')

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert_equal(info, info2)
Esempio n. 2
0
def test_info():
    """Test info object."""
    raw = read_raw_fif(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
                    baseline=(None, 0))

    evoked = epochs.average()

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert ('a' in info)
    assert ('b' in info)
    info[42] = 'foo'
    assert (info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert (isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert len(info_str.split('\n')) == len(obj.info.keys()) + 2
        assert all(k in info_str for k in obj.info.keys())
        assert '2002-12-03 19:01:10 GMT' in repr(obj.info), repr(obj.info)

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert info['nchan'] == nchan
    assert list(info['ch_names']) == ch_names

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Test updating of fields
    del info['chs'][-1]
    info._update_redundant()
    assert info['nchan'] == nchan - 1
    assert list(info['ch_names']) == ch_names[:-1]

    info['chs'][0]['ch_name'] = 'foo'
    info._update_redundant()
    assert info['ch_names'][0] == 'foo'

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert info == info2
Esempio n. 3
0
def test_info():
    """Test info object."""
    raw = read_raw_fif(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None, baseline=(None, 0))

    evoked = epochs.average()

    events = read_events(event_name)

    # Test subclassing was successful.
    info = Info(a=7, b="aaaaa")
    assert_true("a" in info)
    assert_true("b" in info)
    info[42] = "foo"
    assert_true(info[42] == "foo")

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert_true(isinstance(obj.info, Info))
        info_str = "%s" % obj.info
        assert_equal(len(info_str.split("\n")), len(obj.info.keys()) + 2)
        assert_true(all(k in info_str for k in obj.info.keys()))

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info["chs"])
    ch_names = [ch["ch_name"] for ch in info["chs"]]
    assert_equal(info["nchan"], nchan)
    assert_equal(list(info["ch_names"]), ch_names)

    # Deleting of regular fields should work
    info["foo"] = "bar"
    del info["foo"]

    # Test updating of fields
    del info["chs"][-1]
    info._update_redundant()
    assert_equal(info["nchan"], nchan - 1)
    assert_equal(list(info["ch_names"]), ch_names[:-1])

    info["chs"][0]["ch_name"] = "foo"
    info._update_redundant()
    assert_equal(info["ch_names"][0], "foo")

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert_equal(info, info2)
def test_info():
    """Test info object"""
    raw = Raw(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
                    baseline=(None, 0))

    evoked = epochs.average()

    events = read_events(event_name)

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert_true('a' in info)
    assert_true('b' in info)
    info[42] = 'foo'
    assert_true(info[42] == 'foo')

    # test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert_true(isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert_equal(len(info_str.split('\n')), (len(obj.info.keys()) + 2))
        assert_true(all(k in info_str for k in obj.info.keys()))
Esempio n. 5
0
def test_info():
    """Test info object."""
    raw = read_raw_fif(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None)

    evoked = epochs.average()

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert ('a' in info)
    assert ('b' in info)
    info[42] = 'foo'
    assert (info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert (isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert len(info_str.split('\n')) == len(obj.info.keys()) + 2
        assert all(k in info_str for k in obj.info.keys())
        rep = repr(obj.info)
        assert '2002-12-03 19:01:10 GMT' in rep, rep
        assert '146 items (3 Cardinal, 4 HPI, 61 EEG, 78 Extra)' in rep
        dig_rep = repr(obj.info['dig'][0])
        assert 'LPA' in dig_rep, dig_rep
        assert '(-71.4, 0.0, 0.0) mm' in dig_rep, dig_rep
        assert 'head frame' in dig_rep, dig_rep
        # Test our BunchConstNamed support
        for func in (str, repr):
            assert '4 (FIFFV_COORD_HEAD)' == \
                func(obj.info['dig'][0]['coord_frame'])

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert info['nchan'] == nchan
    assert list(info['ch_names']) == ch_names

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Test updating of fields
    del info['chs'][-1]
    info._update_redundant()
    assert info['nchan'] == nchan - 1
    assert list(info['ch_names']) == ch_names[:-1]

    info['chs'][0]['ch_name'] = 'foo'
    info._update_redundant()
    assert info['ch_names'][0] == 'foo'

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert info == info2
Esempio n. 6
0
def test_info():
    """Test info object."""
    raw = read_raw_fif(raw_fname, add_eeg_ref=False)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw,
                    events[:1],
                    event_id,
                    tmin,
                    tmax,
                    picks=None,
                    baseline=(None, 0),
                    add_eeg_ref=False)

    evoked = epochs.average()

    events = read_events(event_name)

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert_true('a' in info)
    assert_true('b' in info)
    info[42] = 'foo'
    assert_true(info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert_true(isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert_equal(len(info_str.split('\n')), len(obj.info.keys()) + 2)
        assert_true(all(k in info_str for k in obj.info.keys()))

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert_equal(info['nchan'], nchan)
    assert_equal(list(info['ch_names']), ch_names)

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Test updating of fields
    del info['chs'][-1]
    info._update_redundant()
    assert_equal(info['nchan'], nchan - 1)
    assert_equal(list(info['ch_names']), ch_names[:-1])

    info['chs'][0]['ch_name'] = 'foo'
    info._update_redundant()
    assert_equal(info['ch_names'][0], 'foo')

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert_equal(info, info2)
Esempio n. 7
0
def read_features(fname):
    measures_classes = dict(inspect.getmembers(sys.modules['nice.measures']))
    contents = h5_listdir(fname)
    measures = list()
    epochs = None
    if 'nice/features/order' in contents:
        measure_order = read_hdf5(fname,
                                  title='nice/features/order',
                                  slash='replace')
    else:
        measure_order = [k for k in contents if 'nice/measure/' in k]

    if any('nice/data/epochs' in k for k in contents):
        epochs = read_hdf5(fname, title='nice/data/epochs', slash='replace')
        # MNE fix
        if 'filename' in epochs['info']:
            del (epochs['info']['filename'])
        epochs = mne.EpochsArray(data=epochs.pop('_data'),
                                 info=Info(epochs.pop('info')),
                                 tmin=epochs.pop('tmin'),
                                 event_id=epochs.pop('event_id'),
                                 events=epochs.pop('events'),
                                 reject=epochs.pop('reject'),
                                 flat=epochs.pop('flat'))
    # Read all PowerSpectralDensityEstimator estimators
    estimators = [
        k for k in contents
        if 'nice/container/PowerSpectralDensityEstimator' in k
    ]
    all_estimators = {}
    for estimator_name in estimators:
        estimator_comment = estimator_name.split('/')[-1]
        this_estimator = read_psd_estimator(fname, comment=estimator_comment)
        all_estimators[estimator_comment] = this_estimator
    for content in measure_order:
        _, _, my_class_name, comment = content.split('/')
        my_class = measures_classes[my_class_name]
        if issubclass(my_class, BaseTimeLocked):
            if not epochs:
                raise RuntimeError(
                    'Something weird has happened. You want to read a '
                    'measure that depends on epochs but '
                    'I could not find any epochs in the file you gave me.')
            measures.append(my_class._read(fname, epochs, comment=comment))
        elif issubclass(my_class, BasePowerSpectralDensity):
            measures.append(
                my_class._read(fname,
                               estimators=all_estimators,
                               comment=comment))
        elif issubclass(my_class, BaseMeasure):
            measures.append(my_class._read(fname, comment=comment))
        else:
            raise ValueError('Come on--this is not a Nice class!')
    measures = Features(measures)
    return measures
Esempio n. 8
0
def test_info():
    """Test info object."""
    raw = read_raw_fif(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw,
                    events[:1],
                    event_id,
                    tmin,
                    tmax,
                    picks=None,
                    baseline=(None, 0))

    evoked = epochs.average()

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert ('a' in info)
    assert ('b' in info)
    info[42] = 'foo'
    assert (info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert (isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert len(info_str.split('\n')) == len(obj.info.keys()) + 2
        assert all(k in info_str for k in obj.info.keys())
        assert '2002-12-03 19:01:10 GMT' in repr(obj.info), repr(obj.info)

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert info['nchan'] == nchan
    assert list(info['ch_names']) == ch_names

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Test updating of fields
    del info['chs'][-1]
    info._update_redundant()
    assert info['nchan'] == nchan - 1
    assert list(info['ch_names']) == ch_names[:-1]

    info['chs'][0]['ch_name'] = 'foo'
    info._update_redundant()
    assert info['ch_names'][0] == 'foo'

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert info == info2
Esempio n. 9
0
def _read_container(klass, fname, comment='default'):
    data = read_hdf5(fname, _get_title(klass, comment), slash='replace')
    init_params = {k: v for k, v in data.items() if not k.endswith('_')}
    attrs = {k: v for k, v in data.items() if k.endswith('_')}
    file_info = read_hdf5(fname, title='nice/data/ch_info', slash='replace')
    if 'filename' in file_info:
        del (file_info['filename'])
    attrs['ch_info_'] = Info(file_info)
    out = klass(**init_params)
    for k, v in attrs.items():
        if k.endswith('_'):
            setattr(out, k, v)
    return out
Esempio n. 10
0
def _read_my_marker(klass, fname, comment='default'):
    # MANDATORY: This method should work for any marker as it is now.
    data = read_hdf5(fname,  _get_title(klass, comment), slash='replace')
    init_params = {k: v for k, v in data.items() if not k.endswith('_')}
    attrs = {k: v for k, v in data.items() if k.endswith('_')}
    file_info = read_hdf5(fname, title='nice/data/ch_info', slash='replace')
    if 'filename' in file_info:
        del(file_info['filename'])
    attrs['ch_info_'] = Info(file_info)
    out = klass(**init_params)
    for k, v in attrs.items():
        if k.endswith('_'):
            setattr(out, k, v)
    return out
Esempio n. 11
0
test_info = Info({
    'ch_names': ['ICA 001', 'ICA 002', 'EOG 061'],
    'chs': [{'cal': 1,
             'ch_name': 'ICA 001',
             'coil_trans': None,
             'coil_type': 0,
             'coord_Frame': 0,
             'eeg_loc': None,
             'kind': 502,
             'loc': np.array([0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 1.],
                             dtype=np.float32),
             'logno': 1,
             'range': 1.0,
             'scanno': 1,
             'unit': -1,
             'unit_mul': 0},
            {'cal': 1,
             'ch_name': 'ICA 002',
             'coil_trans': None,
             'coil_type': 0,
             'coord_Frame': 0,
             'eeg_loc': None,
             'kind': 502,
             'loc': np.array([0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 1.],
                             dtype=np.float32),
             'logno': 2,
             'range': 1.0,
             'scanno': 2,
             'unit': -1,
             'unit_mul': 0},
            {'cal': 0.002142000012099743,
             'ch_name': 'EOG 061',
             'coil_trans': None,
             'coil_type': 1,
             'coord_frame': 0,
             'eeg_loc': None,
             'kind': 202,
             'loc': np.array([0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 1.],
                             dtype=np.float32),
             'logno': 61,
             'range': 1.0,
             'scanno': 376,
             'unit': 107,
             'unit_mul': 0}],
    'nchan': 3})
Esempio n. 12
0
def test_info():
    """Test info object"""
    raw = Raw(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
                    baseline=(None, 0))

    evoked = epochs.average()

    events = read_events(event_name)

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert_true('a' in info)
    assert_true('b' in info)
    info[42] = 'foo'
    assert_true(info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert_true(isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert_equal(len(info_str.split('\n')), len(obj.info.keys()) + 2)
        assert_true(all(k in info_str for k in obj.info.keys()))

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert_equal(info['nchan'], nchan)
    assert_equal(list(info['ch_names']), ch_names)

    def _assignment_to_nchan(info):
        info['nchan'] = 42
    assert_raises(ValueError, _assignment_to_nchan, info)

    def _assignment_to_ch_names(info):
        info['ch_names'] = ['foo', 'bar']
    assert_raises(ValueError, _assignment_to_ch_names, info)

    def _del_nchan(info):
        del info['nchan']
    assert_raises(ValueError, _del_nchan, info)

    def _del_ch_names(info):
        del info['ch_names']
    assert_raises(ValueError, _del_ch_names, info)

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Passing read only fields to the constructor
    assert_raises(ValueError, Info, nchan=42)
    assert_raises(ValueError, Info, ch_names=['foo', 'bar'])

    # Test automatic updating of read-only fields
    del info['chs'][-1]
    assert_equal(info['nchan'], nchan - 1)
    assert_equal(list(info['ch_names']), ch_names[:-1])

    info['chs'][0]['ch_name'] = 'foo'
    assert_equal(info['ch_names'][0], 'foo')

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert_equal(info, info2)

    info_dict = info.to_dict()
    info2 = Info(info_dict)
    assert_equal(info, info2)
Esempio n. 13
0
def test_info():
    """Test info object."""
    raw = read_raw_fif(raw_fname)
    event_id, tmin, tmax = 1, -0.2, 0.5
    events = read_events(event_name)
    event_id = int(events[0, 2])
    epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
                    baseline=(None, 0))

    evoked = epochs.average()

    # Test subclassing was successful.
    info = Info(a=7, b='aaaaa')
    assert ('a' in info)
    assert ('b' in info)
    info[42] = 'foo'
    assert (info[42] == 'foo')

    # Test info attribute in API objects
    for obj in [raw, epochs, evoked]:
        assert (isinstance(obj.info, Info))
        info_str = '%s' % obj.info
        assert len(info_str.split('\n')) == len(obj.info.keys()) + 2
        assert all(k in info_str for k in obj.info.keys())
        rep = repr(obj.info)
        assert '2002-12-03 19:01:10 GMT' in rep, rep
        assert '146 items (3 Cardinal, 4 HPI, 61 EEG, 78 Extra)' in rep
        dig_rep = repr(obj.info['dig'][0])
        assert 'LPA' in dig_rep, dig_rep
        assert '(-71.4, 0.0, 0.0) mm' in dig_rep, dig_rep
        assert 'head frame' in dig_rep, dig_rep
        # Test our BunchConstNamed support
        for func in (str, repr):
            assert '4 (FIFFV_COORD_HEAD)' == \
                func(obj.info['dig'][0]['coord_frame'])

    # Test read-only fields
    info = raw.info.copy()
    nchan = len(info['chs'])
    ch_names = [ch['ch_name'] for ch in info['chs']]
    assert info['nchan'] == nchan
    assert list(info['ch_names']) == ch_names

    # Deleting of regular fields should work
    info['foo'] = 'bar'
    del info['foo']

    # Test updating of fields
    del info['chs'][-1]
    info._update_redundant()
    assert info['nchan'] == nchan - 1
    assert list(info['ch_names']) == ch_names[:-1]

    info['chs'][0]['ch_name'] = 'foo'
    info._update_redundant()
    assert info['ch_names'][0] == 'foo'

    # Test casting to and from a dict
    info_dict = dict(info)
    info2 = Info(info_dict)
    assert info == info2