本文整理汇总了Python中mne.io.read_raw_edf函数的典型用法代码示例。如果您正苦于以下问题:Python read_raw_edf函数的具体用法?Python read_raw_edf怎么用?Python read_raw_edf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_raw_edf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gdf2_data
def test_gdf2_data():
"""Test reading raw GDF 2.x files."""
raw = read_raw_edf(gdf2_path + '.gdf', eog=None, misc=None, preload=True,
stim_channel='STATUS')
nchan = raw.info['nchan']
ch_names = raw.ch_names # Renamed STATUS -> STI 014.
picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
data, _ = raw[picks]
# This .mat was generated using the official biosig matlab package
mat = sio.loadmat(gdf2_path + '_biosig.mat')
data_biosig = mat['dat'] * 1e-6 # data are stored in microvolts
data_biosig = data_biosig[picks]
# Assert data are almost equal
assert_array_almost_equal(data, data_biosig, 8)
# Find events
events = find_events(raw, verbose=1)
events[:, 2] >>= 8 # last 8 bits are system events in biosemi files
assert_equal(events.shape[0], 2) # 2 events in file
assert_array_equal(events[:, 2], [20, 28])
with pytest.warns(RuntimeWarning, match='No events found'):
# header contains no events
raw = read_raw_edf(gdf2_path + '.gdf', stim_channel='auto')
assert_equal(nchan, raw.info['nchan']) # stim channel not constructed
assert_array_equal(ch_names[1:], raw.ch_names[1:])
# gh-5604
assert raw.info['meas_date'] == DATE_NONE
_test_raw_reader(read_raw_edf, input_fname=gdf2_path + '.gdf',
eog=None, misc=None, stim_channel='STATUS')
示例2: test_gdf2_data
def test_gdf2_data():
"""Test reading raw GDF 2.x files."""
raw = read_raw_edf(gdf2_path + '.gdf', eog=None, misc=None, preload=True,
stim_channel='STATUS')
nchan = raw.info['nchan']
ch_names = raw.ch_names # Renamed STATUS -> STI 014.
picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
data, _ = raw[picks]
# This .mat was generated using the official biosig matlab package
mat = sio.loadmat(gdf2_path + '_biosig.mat')
data_biosig = mat['dat'] * 1e-6 # data are stored in microvolts
data_biosig = data_biosig[picks]
# Assert data are almost equal
assert_array_almost_equal(data, data_biosig, 8)
# Find events
events = find_events(raw, verbose=1)
events[:, 2] >>= 8 # last 8 bits are system events in biosemi files
assert_equal(events.shape[0], 2) # 2 events in file
assert_array_equal(events[:, 2], [20, 28])
with warnings.catch_warnings(record=True) as w:
# header contains no events
raw = read_raw_edf(gdf2_path + '.gdf', stim_channel='auto')
assert_equal(len(w), 1)
assert_true(str(w[0].message).startswith('No events found.'))
assert_equal(nchan, raw.info['nchan']) # stim channel not constructed
assert_array_equal(ch_names[1:], raw.ch_names[1:])
示例3: test_edf_data
def test_edf_data():
"""Test reading raw edf files"""
raw_py = read_raw_edf(edf_path, misc=range(-4, 0), stim_channel=139,
preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True,
exclude=['EDF Annotations'])
data_py, _ = raw_py[picks]
print(raw_py) # to test repr
print(raw_py.info) # to test Info repr
# this .mat was generated using the EEG Lab Biosemi Reader
raw_eeglab = io.loadmat(edf_eeglab_path)
raw_eeglab = raw_eeglab['data'] * 1e-6 # data are stored in microvolts
data_eeglab = raw_eeglab[picks]
assert_array_almost_equal(data_py, data_eeglab, 10)
# Make sure concatenation works
raw_concat = concatenate_raws([raw_py.copy(), raw_py])
assert_equal(raw_concat.n_times, 2 * raw_py.n_times)
# Test uneven sampling
raw_py = read_raw_edf(edf_uneven_path, stim_channel=None)
data_py, _ = raw_py[0]
# this .mat was generated using the EEG Lab Biosemi Reader
raw_eeglab = io.loadmat(edf_uneven_eeglab_path)
raw_eeglab = raw_eeglab['data']
data_eeglab = raw_eeglab[0]
# match upsampling
upsample = len(data_eeglab) / len(raw_py)
data_py = np.repeat(data_py, repeats=upsample)
assert_array_equal(data_py, data_eeglab)
示例4: test_read_segment
def test_read_segment():
"""Test writing raw edf files when preload is False
"""
tempdir = _TempDir()
raw1 = read_raw_edf(edf_path, stim_channel=139, preload=False)
raw1_file = op.join(tempdir, 'test1-raw.fif')
raw1.save(raw1_file, overwrite=True, buffer_size_sec=1)
raw11 = Raw(raw1_file, preload=True)
data1, times1 = raw1[:139, :]
data11, times11 = raw11[:139, :]
assert_allclose(data1, data11, rtol=1e-6)
assert_array_almost_equal(times1, times11)
assert_equal(sorted(raw1.info.keys()), sorted(raw11.info.keys()))
raw2 = read_raw_edf(edf_path, stim_channel=139, preload=True)
raw2_file = op.join(tempdir, 'test2-raw.fif')
raw2.save(raw2_file, overwrite=True)
data2, times2 = raw2[:139, :]
assert_allclose(data1, data2, rtol=1e-6)
assert_array_equal(times1, times2)
raw1 = Raw(raw1_file, preload=True)
raw2 = Raw(raw2_file, preload=True)
assert_array_equal(raw1._data, raw2._data)
# test the _read_segment function by only loading some of the data
raw1 = read_raw_edf(edf_path, preload=False)
raw2 = read_raw_edf(edf_path, preload=True)
# select some random range of data to compare
data1, times1 = raw1[:, 345:417]
data2, times2 = raw2[:, 345:417]
assert_array_equal(data1, data2)
assert_array_equal(times1, times2)
示例5: test_bdf_stim_channel
def test_bdf_stim_channel():
"""Test BDF stim channel."""
# test if last channel is detected as STIM by default
raw_py = _test_raw_reader(read_raw_edf, input_fname=bdf_path,
stim_channel='auto')
assert channel_type(raw_py.info, raw_py.info["nchan"] - 1) == 'stim'
# test BDF file with wrong scaling info in header - this should be ignored
# for BDF stim channels
events = [[242, 0, 4],
[310, 0, 2],
[952, 0, 1],
[1606, 0, 1],
[2249, 0, 1],
[2900, 0, 1],
[3537, 0, 1],
[4162, 0, 1],
[4790, 0, 1]]
with pytest.deprecated_call(match='stim_channel'):
raw = read_raw_edf(bdf_stim_channel_path, preload=True)
bdf_events = find_events(raw)
assert_array_equal(events, bdf_events)
raw = read_raw_edf(bdf_stim_channel_path, preload=False,
stim_channel='auto')
bdf_events = find_events(raw)
assert_array_equal(events, bdf_events)
示例6: test_edf_overlapping_annotations
def test_edf_overlapping_annotations():
"""Test EDF with overlapping annotations."""
n_warning = 2
with warnings.catch_warnings(record=True) as w:
read_raw_edf(edf_overlap_annot_path, preload=True, verbose=True)
assert_equal(sum('overlapping' in str(ww.message) for ww in w),
n_warning)
示例7: test_stim_channel
def test_stim_channel():
"""Test reading raw edf files with stim channel"""
raw_py = read_raw_edf(edf_path, misc=range(-4, 0), stim_channel=139,
preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True,
exclude=['EDF Annotations'])
data_py, _ = raw_py[picks]
print(raw_py) # to test repr
print(raw_py.info) # to test Info repr
# this .mat was generated using the EEG Lab Biosemi Reader
raw_eeglab = io.loadmat(edf_eeglab_path)
raw_eeglab = raw_eeglab['data'] * 1e-6 # data are stored in microvolts
data_eeglab = raw_eeglab[picks]
assert_array_almost_equal(data_py, data_eeglab, 10)
# Test uneven sampling
raw_py = read_raw_edf(edf_uneven_path, stim_channel=None)
data_py, _ = raw_py[0]
# this .mat was generated using the EEG Lab Biosemi Reader
raw_eeglab = io.loadmat(edf_uneven_eeglab_path)
raw_eeglab = raw_eeglab['data']
data_eeglab = raw_eeglab[0]
# match upsampling
upsample = len(data_eeglab) / len(raw_py)
data_py = np.repeat(data_py, repeats=upsample)
assert_array_equal(data_py, data_eeglab)
assert_raises(RuntimeError, read_raw_edf, edf_path, preload=False)
示例8: test_read_raw_edf_stim_channel_input_parameters
def test_read_raw_edf_stim_channel_input_parameters():
"""Test edf raw reader deprecation."""
_MSG = "`read_raw_edf` is not supposed to trigger a deprecation warning"
with pytest.warns(None) as recwarn:
read_raw_edf(edf_path)
assert all([w.category != DeprecationWarning for w in recwarn.list]), _MSG
for invalid_stim_parameter in ['EDF Annotations', 'BDF Annotations']:
with pytest.raises(ValueError,
match="stim channel is not supported"):
read_raw_edf(edf_path, stim_channel=invalid_stim_parameter)
示例9: test_stim_channel
def test_stim_channel():
"""Test reading raw edf files with stim channel."""
raw_py = read_raw_edf(edf_path, misc=range(-4, 0), stim_channel=139,
preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True,
exclude=['EDF Annotations'])
data_py, _ = raw_py[picks]
print(raw_py) # to test repr
print(raw_py.info) # to test Info repr
# this .mat was generated using the EEG Lab Biosemi Reader
raw_eeglab = io.loadmat(edf_eeglab_path)
raw_eeglab = raw_eeglab['data'] * 1e-6 # data are stored in microvolts
data_eeglab = raw_eeglab[picks]
assert_array_almost_equal(data_py, data_eeglab, 10)
events = find_edf_events(raw_py)
assert_true(len(events) - 1 == len(find_events(raw_py))) # start not found
# Test uneven sampling
raw_py = read_raw_edf(edf_uneven_path, stim_channel=None)
data_py, _ = raw_py[0]
# this .mat was generated using the EEG Lab Biosemi Reader
raw_eeglab = io.loadmat(edf_uneven_eeglab_path)
raw_eeglab = raw_eeglab['data']
data_eeglab = raw_eeglab[0]
# match upsampling
upsample = len(data_eeglab) / len(raw_py)
data_py = np.repeat(data_py, repeats=upsample)
assert_array_equal(data_py, data_eeglab)
assert_raises(RuntimeError, read_raw_edf, edf_path, preload=False,
stim_channel=-1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
raw = read_raw_edf(edf_stim_resamp_path, verbose=True, stim_channel=-1)
assert_equal(len(w), 2)
assert_true(any('Events may jitter' in str(ww.message) for ww in w))
assert_true(any('truncated' in str(ww.message) for ww in w))
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
raw[:]
assert_equal(len(w), 0)
events = raw_py.find_edf_events()
assert_true(len(events) == 0)
示例10: test_read_raw_edf_deprecation_of_annot_annotmap
def test_read_raw_edf_deprecation_of_annot_annotmap(tmpdir):
"""Test deprecation of annot and annotmap."""
annot = (b'+0.1344\x150.2560\x14two\x14\x00\x00\x00\x00'
b'+0.3904\x151.0\x14two\x14\x00\x00\x00\x00'
b'+2.0\x14three\x14\x00\x00\x00\x00\x00\x00\x00\x00'
b'+2.5\x152.5\x14two\x14\x00\x00\x00\x00')
annot_file = tmpdir.join('annotations.txt')
annot_file.write(annot)
annotmap_file = tmpdir.join('annotations_map.txt')
annotmap_file.write('two:2,three:3')
with pytest.warns(DeprecationWarning, match="annot.*annotmap.*"):
read_raw_edf(input_fname=edf_path, annot=str(annot_file),
annotmap=str(annotmap_file), preload=True)
示例11: test_edf_data
def test_edf_data():
"""Test edf files."""
raw = _test_raw_reader(read_raw_edf, input_fname=edf_path,
stim_channel=None, exclude=['Ergo-Left', 'H10'],
verbose='error')
raw_py = read_raw_edf(edf_path, stim_channel='auto', preload=True)
assert_equal(len(raw.ch_names) + 2, len(raw_py.ch_names))
# Test saving and loading when annotations were parsed.
edf_events = find_events(raw_py, output='step', shortest_event=0,
stim_channel='STI 014')
# onset, duration, id
events = [[0.1344, 0.2560, 2],
[0.3904, 1.0000, 2],
[2.0000, 0.0000, 3],
[2.5000, 2.5000, 2]]
events = np.array(events)
events[:, :2] *= 512 # convert time to samples
events = np.array(events, dtype=int)
events[:, 1] -= 1
events[events[:, 1] <= 0, 1] = 1
events[:, 1] += events[:, 0]
onsets = events[:, [0, 2]]
offsets = events[:, [1, 2]]
events = np.zeros((2 * events.shape[0], 3), dtype=int)
events[0::2, [0, 2]] = onsets
events[1::2, [0, 1]] = offsets
assert_array_equal(edf_events, events)
# Test with number of records not in header (-1).
tempdir = _TempDir()
broken_fname = op.join(tempdir, 'broken.edf')
with open(edf_path, 'rb') as fid_in:
fid_in.seek(0, 2)
n_bytes = fid_in.tell()
fid_in.seek(0, 0)
rbytes = fid_in.read(int(n_bytes * 0.4))
with open(broken_fname, 'wb') as fid_out:
fid_out.write(rbytes[:236])
fid_out.write(b'-1 ')
fid_out.write(rbytes[244:])
with pytest.warns(RuntimeWarning,
match='records .* not match the file size'):
raw = read_raw_edf(broken_fname, preload=True, stim_channel='auto')
read_raw_edf(broken_fname, exclude=raw.ch_names[:132], preload=True,
stim_channel='auto')
示例12: test_gdf_data
def test_gdf_data():
"""Test reading raw GDF 1.x files."""
with warnings.catch_warnings(record=True): # interpolate / overlap events
raw = read_raw_edf(gdf1_path + '.gdf', eog=None,
misc=None, preload=True, stim_channel='auto')
picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
data, _ = raw[picks]
# this .npy was generated using the official biosig python package
raw_biosig = np.load(gdf1_path + '_biosig.npy')
raw_biosig = raw_biosig * 1e-6 # data are stored in microvolts
data_biosig = raw_biosig[picks]
# Assert data are almost equal
assert_array_almost_equal(data, data_biosig, 8)
# Test for stim channel
events = find_events(raw, shortest_event=1)
# The events are overlapping.
assert_array_equal(events[:, 0], raw._raw_extras[0]['events'][1][::2])
# Test events are encoded to stim channel.
events = find_events(raw)
evs = raw.find_edf_events()
assert_true(all([event in evs[1] for event in events[:, 0]]))
示例13: test_gdf2_data
def test_gdf2_data():
"""Test reading raw GDF 2.x files."""
raw = read_raw_edf(gdf2_path + '.gdf', eog=None, misc=None, preload=True)
picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
data, _ = raw[picks]
# This .mat was generated using the official biosig matlab package
mat = sio.loadmat(gdf2_path + '_biosig.mat')
data_biosig = mat['dat'] * 1e-6 # data are stored in microvolts
data_biosig = data_biosig[picks]
# Assert data are almost equal
assert_array_almost_equal(data, data_biosig, 8)
# Find events
events = find_events(raw, verbose=1)
events[:, 2] >>= 8 # last 8 bits are system events in biosemi files
assert_equal(events.shape[0], 2) # 2 events in file
assert_array_equal(events[:, 2], [20, 28])
# gh-5604
assert raw.info['meas_date'] == DATE_NONE
_test_raw_reader(read_raw_edf, input_fname=gdf2_path + '.gdf',
eog=None, misc=None)
示例14: test_gdf_data
def test_gdf_data():
"""Test reading raw GDF 1.x files."""
raw = read_raw_edf(gdf1_path + '.gdf', eog=None, misc=None, preload=True)
picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
data, _ = raw[picks]
# Test Status is added as event
EXPECTED_EVS_ONSETS = raw._raw_extras[0]['events'][1]
evs, evs_id = events_from_annotations(raw)
assert_array_equal(evs[:, 0], EXPECTED_EVS_ONSETS)
assert evs_id == {'Unknown': 1}
# this .npy was generated using the official biosig python package
raw_biosig = np.load(gdf1_path + '_biosig.npy')
raw_biosig = raw_biosig * 1e-6 # data are stored in microvolts
data_biosig = raw_biosig[picks]
# Assert data are almost equal
assert_array_almost_equal(data, data_biosig, 8)
# Test for events
assert len(raw.annotations.duration == 963)
# gh-5604
assert raw.info['meas_date'] == DATE_NONE
示例15: test_gdf_data
def test_gdf_data():
"""Test reading raw GDF 1.x files."""
with pytest.warns(RuntimeWarning, match='Overlapping events'):
raw = read_raw_edf(gdf1_path + '.gdf', eog=None,
misc=None, preload=True, stim_channel='auto')
picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
data, _ = raw[picks]
# this .npy was generated using the official biosig python package
raw_biosig = np.load(gdf1_path + '_biosig.npy')
raw_biosig = raw_biosig * 1e-6 # data are stored in microvolts
data_biosig = raw_biosig[picks]
# Assert data are almost equal
assert_array_almost_equal(data, data_biosig, 8)
# Test for stim channel
events = find_events(raw, shortest_event=1)
# The events are overlapping.
assert_array_equal(events[:, 0], raw._raw_extras[0]['events'][1][::2])
# Test events are encoded to stim channel.
events = find_events(raw)
evs = raw.find_edf_events()
assert (all([event in evs[1] for event in events[:, 0]]))
# gh-5604
assert raw.info['meas_date'] == DATE_NONE
with pytest.warns(RuntimeWarning, match='Overlapping events'):
_test_raw_reader(read_raw_edf, input_fname=gdf1_path + '.gdf',
eog=None, misc=None, stim_channel='auto')