本文整理汇总了Python中mne.io.read_raw_brainvision函数的典型用法代码示例。如果您正苦于以下问题:Python read_raw_brainvision函数的具体用法?Python read_raw_brainvision怎么用?Python read_raw_brainvision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_raw_brainvision函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_vhdr_codepage_ansi
def test_vhdr_codepage_ansi():
"""Test BV reading with ANSI codepage."""
raw_init = read_raw_brainvision(vhdr_path)
data_expected, times_expected = raw_init[:]
tempdir = _TempDir()
ansi_vhdr_path = op.join(tempdir, op.split(vhdr_path)[-1])
ansi_vmrk_path = op.join(tempdir, op.split(vmrk_path)[-1])
ansi_eeg_path = op.join(tempdir, op.split(eeg_path)[-1])
# copy data file
shutil.copy(eeg_path, ansi_eeg_path)
# modify header file
with open(ansi_vhdr_path, 'wb') as fout:
with open(vhdr_path, 'rb') as fin:
for line in fin:
# Common Infos section
if line.startswith(b'Codepage'):
line = b'Codepage=ANSI\n'
fout.write(line)
# modify marker file
with open(ansi_vmrk_path, 'wb') as fout:
with open(vmrk_path, 'rb') as fin:
for line in fin:
# Common Infos section
if line.startswith(b'Codepage'):
line = b'Codepage=ANSI\n'
fout.write(line)
raw = read_raw_brainvision(ansi_vhdr_path)
data_new, times_new = raw[:]
assert_equal(raw_init.ch_names, raw.ch_names)
assert_allclose(data_new, data_expected, atol=1e-15)
assert_allclose(times_new, times_expected, atol=1e-15)
示例2: test_read_segment
def test_read_segment():
"""Test writing raw eeg files when preload is False
"""
tempdir = _TempDir()
raw1 = read_raw_brainvision(vhdr_path, eog=eog, preload=False)
raw1_file = op.join(tempdir, 'test1-raw.fif')
raw1.save(raw1_file, overwrite=True)
raw11 = Raw(raw1_file, preload=True)
data1, times1 = raw1[:, :]
data11, times11 = raw11[:, :]
assert_array_almost_equal(data1, data11, 8)
assert_array_almost_equal(times1, times11)
assert_equal(sorted(raw1.info.keys()), sorted(raw11.info.keys()))
raw2 = read_raw_brainvision(vhdr_path, eog=eog, preload=True)
raw2_file = op.join(tempdir, 'test2-raw.fif')
raw2.save(raw2_file, overwrite=True)
data2, times2 = raw2[:, :]
assert_array_equal(data1, data2)
assert_array_equal(times1, times2)
raw1 = Raw(raw1_file, preload=True)
raw2 = Raw(raw2_file, preload=True)
assert_array_equal(raw1._data, raw2._data)
# save with buffer size smaller than file
raw3_file = op.join(tempdir, 'test3-raw.fif')
raw3 = read_raw_brainvision(vhdr_path, eog=eog)
raw3.save(raw3_file, buffer_size_sec=2)
raw3 = Raw(raw3_file, preload=True)
assert_array_equal(raw3._data, raw1._data)
示例3: test_brainvision_data
def test_brainvision_data():
"""Test reading raw Brain Vision files
"""
raw_py = read_raw_brainvision(vhdr_path, elp_path, elp_names, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_py, times_py = raw_py[picks]
print(raw_py) # to test repr
print(raw_py.info) # to test Info repr
# compare with a file that was generated using MNE-C
raw_bin = Raw(eeg_bin, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_bin, times_bin = raw_bin[picks]
assert_array_almost_equal(data_py, data_bin)
assert_array_almost_equal(times_py, times_bin)
# Make sure EOG channels are marked correctly
raw_py = read_raw_brainvision(vhdr_path, elp_path, elp_names, eog=eog,
preload=True)
for ch in raw_py.info['chs']:
if ch['ch_name'] in eog:
assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH)
elif ch['ch_name'] in elp_names:
assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH)
elif ch['ch_name'] == 'STI 014':
assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH)
else:
raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
示例4: test_brainvision_data
def test_brainvision_data():
"""Test reading raw Brain Vision files."""
pytest.raises(IOError, read_raw_brainvision, vmrk_path)
pytest.raises(ValueError, read_raw_brainvision, vhdr_path, montage,
preload=True, scale="foo")
raw_py = _test_raw_reader(
read_raw_brainvision, vhdr_fname=vhdr_path, montage=montage,
eog=eog, misc='auto', event_id=event_id)
assert ('RawBrainVision' in repr(raw_py))
assert_equal(raw_py.info['highpass'], 0.)
assert_equal(raw_py.info['lowpass'], 250.)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_py, times_py = raw_py[picks]
# compare with a file that was generated using MNE-C
raw_bin = read_raw_fif(eeg_bin, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_bin, times_bin = raw_bin[picks]
assert_array_almost_equal(data_py, data_bin)
assert_array_almost_equal(times_py, times_bin)
# Make sure EOG channels are marked correctly
for ch in raw_py.info['chs']:
if ch['ch_name'] in eog:
assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH)
elif ch['ch_name'] == 'STI 014':
assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH)
elif ch['ch_name'] in ('CP5', 'CP6'):
assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH)
assert_equal(ch['unit'], FIFF.FIFF_UNIT_NONE)
elif ch['ch_name'] == 'ReRef':
assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH)
assert_equal(ch['unit'], FIFF.FIFF_UNIT_CEL)
elif ch['ch_name'] in raw_py.info['ch_names']:
assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH)
assert_equal(ch['unit'], FIFF.FIFF_UNIT_V)
else:
raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
# test loading v2
read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True,
event_id=event_id,
trig_shift_by_type={'response': 1000},
verbose='error')
# For the nanovolt unit test we use the same data file with a different
# header file.
raw_nV = _test_raw_reader(
read_raw_brainvision, vhdr_fname=vhdr_nV_path, montage=montage,
eog=eog, misc='auto', event_id=event_id)
assert_equal(raw_nV.info['chs'][0]['ch_name'], 'FP1')
assert_equal(raw_nV.info['chs'][0]['kind'], FIFF.FIFFV_EEG_CH)
data_nanovolt, _ = raw_nV[0]
assert_array_almost_equal(data_py[0, :], data_nanovolt[0, :])
示例5: test_brainvision_with_montage
def test_brainvision_with_montage():
"""Test reading embedded montage information."""
raw = read_raw_brainvision(vhdr_v2_path, eog=eog, misc=['ReRef'])
for i, d in enumerate(raw.info['dig'], 1):
assert_equal(d['coord_frame'], FIFF.FIFFV_COORD_HEAD)
assert_equal(d['ident'], i)
assert_equal(d['kind'], FIFF.FIFFV_POINT_EEG)
assert_equal(len(d['r']), 3)
raw_none = read_raw_brainvision(vhdr_v2_path, verbose='error')
for r, n in zip(raw.info['chs'], raw_none.info['chs']):
if r['kind'] != n['kind']:
assert_array_equal(r['loc'], n['loc'])
示例6: test_brainvision_data
def test_brainvision_data():
"""Test reading raw Brain Vision files
"""
assert_raises(IOError, read_raw_brainvision, vmrk_path)
assert_raises(ValueError, read_raw_brainvision, vhdr_path, montage,
preload=True, scale="foo")
with warnings.catch_warnings(record=True) as w: # event parsing
raw_py = _test_raw_reader(
read_raw_brainvision, vhdr_fname=vhdr_path, montage=montage,
eog=eog, misc='auto')
assert_true(all('parse triggers that' in str(ww.message) for ww in w))
assert_true('RawBrainVision' in repr(raw_py))
assert_equal(raw_py.info['highpass'], 0.)
assert_equal(raw_py.info['lowpass'], 250.)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_py, times_py = raw_py[picks]
# compare with a file that was generated using MNE-C
raw_bin = Raw(eeg_bin, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_bin, times_bin = raw_bin[picks]
assert_array_almost_equal(data_py, data_bin)
assert_array_almost_equal(times_py, times_bin)
# Make sure EOG channels are marked correctly
for ch in raw_py.info['chs']:
if ch['ch_name'] in eog:
assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH)
elif ch['ch_name'] == 'STI 014':
assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH)
elif ch['ch_name'] == 'CP6':
assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH)
assert_equal(ch['unit'], FIFF.FIFF_UNIT_NONE)
elif ch['ch_name'] == 'ReRef':
assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH)
assert_equal(ch['unit'], FIFF.FIFF_UNIT_CEL)
elif ch['ch_name'] in raw_py.info['ch_names']:
assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH)
assert_equal(ch['unit'], FIFF.FIFF_UNIT_V)
else:
raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
# test loading v2
read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True,
response_trig_shift=1000)
示例7: test_fif_dig_montage
def test_fif_dig_montage():
"""Test FIF dig montage support"""
dig_montage = read_dig_montage(fif=fif_dig_montage_fname)
# Make a BrainVision file like the one the user would have had
with warnings.catch_warnings(record=True) as w:
raw_bv = read_raw_brainvision(bv_fname, preload=True)
assert_true(any('will be dropped' in str(ww.message) for ww in w))
raw_bv_2 = raw_bv.copy()
mapping = dict()
for ii, ch_name in enumerate(raw_bv.ch_names[:-1]):
mapping[ch_name] = 'EEG%03d' % (ii + 1,)
raw_bv.rename_channels(mapping)
for ii, ch_name in enumerate(raw_bv_2.ch_names[:-1]):
mapping[ch_name] = 'EEG%03d' % (ii + 33,)
raw_bv_2.rename_channels(mapping)
raw_bv.drop_channels(['STI 014'])
raw_bv.add_channels([raw_bv_2])
# Set the montage
raw_bv.set_montage(dig_montage)
# Check the result
evoked = read_evokeds(evoked_fname)[0]
assert_equal(len(raw_bv.ch_names), len(evoked.ch_names))
for ch_py, ch_c in zip(raw_bv.info['chs'], evoked.info['chs']):
assert_equal(ch_py['ch_name'], ch_c['ch_name'].replace('EEG ', 'EEG'))
# C actually says it's unknown, but it's not (?):
# assert_equal(ch_py['coord_frame'], ch_c['coord_frame'])
assert_equal(ch_py['coord_frame'], FIFF.FIFFV_COORD_HEAD)
assert_allclose(ch_py['loc'], ch_c['loc'])
assert_dig_allclose(raw_bv.info, evoked.info)
示例8: test_brainvision_data_filters
def test_brainvision_data_filters():
"""Test reading raw Brain Vision files
"""
raw = read_raw_brainvision(vhdr_highpass_path, elp_path, elp_names,
preload=False)
assert_equal(raw.info['highpass'], 0.1)
assert_equal(raw.info['lowpass'], 250.)
示例9: test_read_vhdr_annotations_and_events
def test_read_vhdr_annotations_and_events():
"""Test load brainvision annotations and parse them to events."""
sfreq = 1000.0
expected_orig_time = 1384359243.794231
expected_onset_latency = np.array(
[0, 486., 496., 1769., 1779., 3252., 3262., 4935., 4945., 5999., 6619.,
6629., 7629., 7699.]
)
expected_annot_description = [
'New Segment/', 'Stimulus/S253', 'Stimulus/S255', 'Stimulus/S254',
'Stimulus/S255', 'Stimulus/S254', 'Stimulus/S255', 'Stimulus/S253',
'Stimulus/S255', 'Response/R255', 'Stimulus/S254', 'Stimulus/S255',
'SyncStatus/Sync On', 'Optic/O 1'
]
expected_events = np.stack([
expected_onset_latency,
np.zeros_like(expected_onset_latency),
[99999, 253, 255, 254, 255, 254, 255, 253, 255, 1255, 254, 255, 99998,
2001],
]).astype('int64').T
expected_event_id = {'New Segment/': 99999, 'Stimulus/S253': 253,
'Stimulus/S255': 255, 'Stimulus/S254': 254,
'Response/R255': 1255, 'SyncStatus/Sync On': 99998,
'Optic/O 1': 2001}
raw = read_raw_brainvision(vhdr_path, eog=eog)
# validate annotations
assert raw.annotations.orig_time == expected_orig_time
assert_allclose(raw.annotations.onset, expected_onset_latency / sfreq)
assert_array_equal(raw.annotations.description, expected_annot_description)
# validate event extraction
events, event_id = events_from_annotations(raw)
assert_array_equal(events, expected_events)
assert event_id == expected_event_id
# validate that None gives us a sorted list
expected_none_event_id = {desc: idx + 1 for idx, desc in enumerate(sorted(
event_id.keys()))}
events, event_id = events_from_annotations(raw, event_id=None)
assert event_id == expected_none_event_id
# Add some custom ones, plus a 2-digit one
s_10 = 'Stimulus/S 10'
raw.annotations.append([1, 2, 3], 10, ['ZZZ', s_10, 'YYY'])
expected_event_id.update(YYY=10001, ZZZ=10002) # others starting at 10001
expected_event_id[s_10] = 10
_, event_id = events_from_annotations(raw)
assert event_id == expected_event_id
# Concatenating two shouldn't change the resulting event_id
# (BAD and EDGE should be ignored)
with pytest.warns(RuntimeWarning, match='expanding outside'):
raw_concat = concatenate_raws([raw.copy(), raw.copy()])
_, event_id = events_from_annotations(raw_concat)
assert event_id == expected_event_id
示例10: test_brainvision_data_filters
def test_brainvision_data_filters():
"""Test reading raw Brain Vision files
"""
raw = read_raw_brainvision(vhdr_highpass_path, montage, eog=eog,
preload=True)
assert_equal(raw.info['highpass'], 0.1)
assert_equal(raw.info['lowpass'], 250.)
raw.info["lowpass"] = None
raw.filter(1, 30)
示例11: test_vmrk_meas_date
def test_vmrk_meas_date():
"""Test successful extraction of measurement date."""
# Test file that does have a specific date
with pytest.warns(RuntimeWarning, match='will be dropped'):
raw = read_raw_brainvision(vhdr_path)
assert_allclose(raw.info['meas_date'], [1384359243, 794231])
assert '2013-11-13 16:14:03 GMT' in repr(raw.info)
# Test file with multiple dates ... we should only take the first
with pytest.warns(RuntimeWarning, match='software filter'):
raw = read_raw_brainvision(vhdr_old_path)
assert_allclose(raw.info['meas_date'], [1184588560, 937453])
assert '2007-07-16 12:22:40 GMT' in repr(raw.info)
# Test files with no date, we should get DATE_NONE from mne.io.write
with pytest.warns(RuntimeWarning, match='coordinate information'):
raw = read_raw_brainvision(vhdr_v2_path)
assert_allclose(raw.info['meas_date'], DATE_NONE)
assert 'unspecified' in repr(raw.info)
示例12: test_brainvision_data
def test_brainvision_data():
"""Test reading raw Brain Vision files
"""
assert_raises(IOError, read_raw_brainvision, vmrk_path)
assert_raises(TypeError, read_raw_brainvision, vhdr_path, montage,
preload=True, scale="0")
raw_py = read_raw_brainvision(vhdr_path, montage, eog=eog, preload=True)
raw_py.load_data() # currently does nothing
assert_true('RawBrainVision' in repr(raw_py))
assert_equal(raw_py.info['highpass'], 0.)
assert_equal(raw_py.info['lowpass'], 250.)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_py, times_py = raw_py[picks]
print(raw_py) # to test repr
print(raw_py.info) # to test Info repr
# compare with a file that was generated using MNE-C
raw_bin = Raw(eeg_bin, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_bin, times_bin = raw_bin[picks]
assert_array_almost_equal(data_py, data_bin)
assert_array_almost_equal(times_py, times_bin)
# Make sure EOG channels are marked correctly
raw_py = read_raw_brainvision(vhdr_path, montage, eog=eog,
preload=True)
for ch in raw_py.info['chs']:
if ch['ch_name'] in eog:
assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH)
elif ch['ch_name'] == 'STI 014':
assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH)
elif ch['ch_name'] in raw_py.info['ch_names']:
assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH)
else:
raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
# Make sure concatenation works
raw_concat = concatenate_raws([raw_py.copy(), raw_py])
assert_equal(raw_concat.n_times, 2 * raw_py.n_times)
示例13: test_read_segment
def test_read_segment():
"""Test writing raw eeg files when preload is False
"""
tempdir = _TempDir()
raw1 = read_raw_brainvision(vhdr_path, eog=eog, preload=False)
raw1_file = op.join(tempdir, "test1-raw.fif")
raw1.save(raw1_file, overwrite=True)
raw11 = Raw(raw1_file, preload=True)
data1, times1 = raw1[:, :]
data11, times11 = raw11[:, :]
assert_array_almost_equal(data1, data11, 8)
assert_array_almost_equal(times1, times11)
assert_equal(sorted(raw1.info.keys()), sorted(raw11.info.keys()))
raw2 = read_raw_brainvision(vhdr_path, eog=eog, preload=True)
raw2_file = op.join(tempdir, "test2-raw.fif")
raw2.save(raw2_file, overwrite=True)
data2, times2 = raw2[:, :]
assert_array_equal(data1, data2)
assert_array_equal(times1, times2)
raw1 = Raw(raw1_file, preload=True)
raw2 = Raw(raw2_file, preload=True)
assert_array_equal(raw1._data, raw2._data)
# save with buffer size smaller than file
raw3_file = op.join(tempdir, "test3-raw.fif")
raw3 = read_raw_brainvision(vhdr_path, eog=eog)
raw3.save(raw3_file, buffer_size_sec=2)
raw3 = Raw(raw3_file, preload=True)
assert_array_equal(raw3._data, raw1._data)
# add reference channel
raw4_file = op.join(tempdir, "test4-raw.fif")
raw4 = read_raw_brainvision(vhdr_path, eog=eog, reference="A1")
raw4.save(raw4_file, buffer_size_sec=2)
raw4 = Raw(raw4_file, preload=True)
ref_idx = raw4.ch_names.index("A1")
assert_equal(len(raw4._data), len(raw1._data) + 1)
ref_data, _ = raw4[ref_idx]
assert_array_equal(ref_data, 0)
示例14: test_orig_units
def test_orig_units(recwarn):
"""Test exposure of original channel units."""
raw = read_raw_brainvision(vhdr_path)
orig_units = raw._orig_units
assert len(orig_units) == 32
assert orig_units['FP1'] == u'µV'
assert orig_units['CP5'] == 'n/a' # originally BS, not a valid unit
assert orig_units['CP6'] == u'µS'
assert orig_units['HL'] == 'n/a' # originally ARU, not a valid unit
assert orig_units['HR'] == 'n/a' # originally uS ...
assert orig_units['Vb'] == 'S'
assert orig_units['ReRef'] == 'C'
示例15: test_fif_dig_montage
def test_fif_dig_montage():
"""Test FIF dig montage support."""
dig_montage = read_dig_montage(fif=fif_dig_montage_fname)
# test round-trip IO
temp_dir = _TempDir()
fname_temp = op.join(temp_dir, 'test.fif')
_check_roundtrip(dig_montage, fname_temp)
# Make a BrainVision file like the one the user would have had
with warnings.catch_warnings(record=True) as w:
raw_bv = read_raw_brainvision(bv_fname, preload=True)
assert_true(any('will be dropped' in str(ww.message) for ww in w))
raw_bv_2 = raw_bv.copy()
mapping = dict()
for ii, ch_name in enumerate(raw_bv.ch_names[:-1]):
mapping[ch_name] = 'EEG%03d' % (ii + 1,)
raw_bv.rename_channels(mapping)
for ii, ch_name in enumerate(raw_bv_2.ch_names[:-1]):
mapping[ch_name] = 'EEG%03d' % (ii + 33,)
raw_bv_2.rename_channels(mapping)
raw_bv.drop_channels(['STI 014'])
raw_bv.add_channels([raw_bv_2])
for ii in range(2):
if ii == 1:
dig_montage.transform_to_head() # should have no meaningful effect
# Set the montage
raw_bv.set_montage(dig_montage)
# Check the result
evoked = read_evokeds(evoked_fname)[0]
assert_equal(len(raw_bv.ch_names), len(evoked.ch_names))
for ch_py, ch_c in zip(raw_bv.info['chs'], evoked.info['chs']):
assert_equal(ch_py['ch_name'],
ch_c['ch_name'].replace('EEG ', 'EEG'))
# C actually says it's unknown, but it's not (?):
# assert_equal(ch_py['coord_frame'], ch_c['coord_frame'])
assert_equal(ch_py['coord_frame'], FIFF.FIFFV_COORD_HEAD)
c_loc = ch_c['loc'].copy()
c_loc[c_loc == 0] = np.nan
assert_allclose(ch_py['loc'], c_loc, atol=1e-7)
assert_dig_allclose(raw_bv.info, evoked.info)
# Roundtrip of non-FIF start
names = ['nasion', 'lpa', 'rpa', '1', '2', '3', '4', '5']
montage = read_dig_montage(hsp, hpi, elp, names, transform=False)
assert_raises(RuntimeError, montage.save, fname_temp) # must be head coord
montage = read_dig_montage(hsp, hpi, elp, names)
_check_roundtrip(montage, fname_temp)