本文整理汇总了Python中mne.io.Raw.load_data方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.load_data方法的具体用法?Python Raw.load_data怎么用?Python Raw.load_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.Raw
的用法示例。
在下文中一共展示了Raw.load_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_ecg
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_find_ecg():
"""Test find ECG peaks"""
raw = Raw(raw_fname)
# once with mag-trick
# once with characteristic channel
for ch_name in ['MEG 1531', None]:
events, ch_ECG, average_pulse, ecg = find_ecg_events(
raw, event_id=999, ch_name=None, return_ecg=True)
assert_equal(len(raw.times), len(ecg))
n_events = len(events)
_, times = raw[0, :]
assert_true(55 < average_pulse < 60)
picks = pick_types(
raw.info, meg='grad', eeg=False, stim=False,
eog=False, ecg=True, emg=False, ref_meg=False,
exclude='bads')
raw.load_data()
ecg_epochs = create_ecg_epochs(raw, picks=picks, keep_ecg=True)
assert_equal(len(ecg_epochs.events), n_events)
assert_true('ECG-SYN' not in raw.ch_names)
assert_true('ECG-SYN' in ecg_epochs.ch_names)
picks = pick_types(
ecg_epochs.info, meg=False, eeg=False, stim=False,
eog=False, ecg=True, emg=False, ref_meg=False,
exclude='bads')
assert_true(len(picks) == 1)
示例2: test_ica_rank_reduction
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_ica_rank_reduction():
"""Test recovery of full data when no source is rejected"""
# Most basic recovery
raw = Raw(raw_fname).crop(0.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
n_components = 5
max_pca_components = len(picks)
for n_pca_components in [6, 10]:
with warnings.catch_warnings(record=True): # non-convergence
warnings.simplefilter('always')
ica = ICA(n_components=n_components,
max_pca_components=max_pca_components,
n_pca_components=n_pca_components,
method='fastica', max_iter=1).fit(raw, picks=picks)
rank_before = raw.estimate_rank(picks=picks)
assert_equal(rank_before, len(picks))
raw_clean = ica.apply(raw, copy=True)
rank_after = raw_clean.estimate_rank(picks=picks)
# interaction between ICA rejection and PCA components difficult
# to preduct. Rank_after often seems to be 1 higher then
# n_pca_components
assert_true(n_components < n_pca_components <= rank_after <=
rank_before)
示例3: test_compute_proj_eog
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_compute_proj_eog():
"""Test computation of EOG SSP projectors"""
raw = Raw(raw_fname).crop(0, 10, False)
raw.load_data()
for average in [False, True]:
n_projs_init = len(raw.info['projs'])
projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
bads=['MEG 2443'], average=average,
avg_ref=True, no_proj=False,
l_freq=None, h_freq=None,
reject=None, tmax=dur_use)
assert_true(len(projs) == (7 + n_projs_init))
assert_true(np.abs(events.shape[0] -
np.sum(np.less(eog_times, dur_use))) <= 1)
# XXX: better tests
# This will throw a warning b/c simplefilter('always')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
average=average, bads=[],
avg_ref=True, no_proj=False,
l_freq=None, h_freq=None,
tmax=dur_use)
assert_equal(len(w), 1)
assert_equal(projs, None)
示例4: test_ica_reset
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_ica_reset():
"""Test ICA resetting"""
raw = Raw(raw_fname).crop(0.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
run_time_attrs = (
'_pre_whitener',
'unmixing_matrix_',
'mixing_matrix_',
'n_components_',
'n_samples_',
'pca_components_',
'pca_explained_variance_',
'pca_mean_'
)
with warnings.catch_warnings(record=True):
ica = ICA(
n_components=3, max_pca_components=3, n_pca_components=3,
method='fastica', max_iter=1).fit(raw, picks=picks)
assert_true(all(hasattr(ica, attr) for attr in run_time_attrs))
ica._reset()
assert_true(not any(hasattr(ica, attr) for attr in run_time_attrs))
示例5: test_compute_proj_ecg
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_compute_proj_ecg():
"""Test computation of ECG SSP projectors"""
raw = Raw(raw_fname).crop(0, 10, False)
raw.load_data()
for average in [False, True]:
# For speed, let's not filter here (must also not reject then)
projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
ch_name='MEG 1531', bads=['MEG 2443'],
average=average, avg_ref=True,
no_proj=True, l_freq=None,
h_freq=None, reject=None,
tmax=dur_use, qrs_threshold=0.5)
assert_true(len(projs) == 7)
# heart rate at least 0.5 Hz, but less than 3 Hz
assert_true(events.shape[0] > 0.5 * dur_use and
events.shape[0] < 3 * dur_use)
# XXX: better tests
# without setting a bad channel, this should throw a warning
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
ch_name='MEG 1531', bads=[],
average=average, avg_ref=True,
no_proj=True, l_freq=None,
h_freq=None, tmax=dur_use)
assert_equal(len(w), 1)
assert_equal(projs, None)
示例6: test_ica_full_data_recovery
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_ica_full_data_recovery():
"""Test recovery of full data when no source is rejected"""
# Most basic recovery
raw = Raw(raw_fname).crop(0.5, stop, False)
raw.load_data()
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
with warnings.catch_warnings(record=True): # bad proj
epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
evoked = epochs.average()
n_channels = 5
data = raw._data[:n_channels].copy()
data_epochs = epochs.get_data()
data_evoked = evoked.data
for method in ['fastica']:
stuff = [(2, n_channels, True), (2, n_channels // 2, False)]
for n_components, n_pca_components, ok in stuff:
ica = ICA(n_components=n_components,
max_pca_components=n_pca_components,
n_pca_components=n_pca_components,
method=method, max_iter=1)
with warnings.catch_warnings(record=True):
ica.fit(raw, picks=list(range(n_channels)))
raw2 = ica.apply(raw, exclude=[], copy=True)
if ok:
assert_allclose(data[:n_channels], raw2._data[:n_channels],
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(data[:n_channels] - raw2._data[:n_channels])
assert_true(np.max(diff) > 1e-14)
ica = ICA(n_components=n_components,
max_pca_components=n_pca_components,
n_pca_components=n_pca_components)
with warnings.catch_warnings(record=True):
ica.fit(epochs, picks=list(range(n_channels)))
epochs2 = ica.apply(epochs, exclude=[], copy=True)
data2 = epochs2.get_data()[:, :n_channels]
if ok:
assert_allclose(data_epochs[:, :n_channels], data2,
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(data_epochs[:, :n_channels] - data2)
assert_true(np.max(diff) > 1e-14)
evoked2 = ica.apply(evoked, exclude=[], copy=True)
data2 = evoked2.data[:n_channels]
if ok:
assert_allclose(data_evoked[:n_channels], data2,
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(evoked.data[:n_channels] - data2)
assert_true(np.max(diff) > 1e-14)
assert_raises(ValueError, ICA, method='pizza-decomposision')
示例7: test_ica_reject_buffer
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_ica_reject_buffer():
"""Test ICA data raw buffer rejection"""
raw = Raw(raw_fname).crop(1.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
ica = ICA(n_components=3, max_pca_components=4, n_pca_components=4)
raw._data[2, 1000:1005] = 5e-12
with catch_logging() as drop_log:
with warnings.catch_warnings(record=True):
ica.fit(raw, picks[:5], reject=dict(mag=2.5e-12), decim=2,
tstep=0.01, verbose=True)
assert_true(raw._data[:5, ::2].shape[1] - 4 == ica.n_samples_)
log = [l for l in drop_log.getvalue().split('\n') if 'detected' in l]
assert_equal(len(log), 1)
示例8: test_hash_raw
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_hash_raw():
"""Test hashing raw objects
"""
raw = read_raw_fif(fif_fname)
assert_raises(RuntimeError, raw.__hash__)
raw = Raw(fif_fname).crop(0, 0.5, False)
raw.load_data()
raw_2 = Raw(fif_fname).crop(0, 0.5, False)
raw_2.load_data()
assert_equal(hash(raw), hash(raw_2))
# do NOT use assert_equal here, failing output is terrible
assert_equal(pickle.dumps(raw), pickle.dumps(raw_2))
raw_2._data[0, 0] -= 1
assert_not_equal(hash(raw), hash(raw_2))
示例9: test_maxwell_filter_additional
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_maxwell_filter_additional():
"""Test processing of Maxwell filtered data"""
# TODO: Future tests integrate with mne/io/tests/test_proc_history
# Load testing data (raw, SSS std origin, SSS non-standard origin)
data_path = op.join(testing.data_path(download=False))
file_name = 'test_move_anon'
raw_fname = op.join(data_path, 'SSS', file_name + '_raw.fif')
with warnings.catch_warnings(record=True): # maxshield
# Use 2.0 seconds of data to get stable cov. estimate
raw = Raw(raw_fname, preload=False, proj=False,
allow_maxshield=True).crop(0., 2., False)
# Get MEG channels, compute Maxwell filtered data
raw.load_data()
raw.pick_types(meg=True, eeg=False)
int_order, ext_order = 8, 3
raw_sss = maxwell.maxwell_filter(raw, int_order=int_order,
ext_order=ext_order)
# Test io on processed data
tempdir = _TempDir()
test_outname = op.join(tempdir, 'test_raw_sss.fif')
raw_sss.save(test_outname)
raw_sss_loaded = Raw(test_outname, preload=True, proj=False,
allow_maxshield=True)
# Some numerical imprecision since save uses 'single' fmt
assert_allclose(raw_sss_loaded._data[:, :], raw_sss._data[:, :],
rtol=1e-6, atol=1e-20)
# Test rank of covariance matrices for raw and SSS processed data
cov_raw = compute_raw_covariance(raw)
cov_sss = compute_raw_covariance(raw_sss)
scalings = None
cov_raw_rank = _estimate_rank_meeg_cov(cov_raw['data'], raw.info, scalings)
cov_sss_rank = _estimate_rank_meeg_cov(cov_sss['data'], raw_sss.info,
scalings)
assert_equal(cov_raw_rank, raw.info['nchan'])
assert_equal(cov_sss_rank, maxwell.get_num_moments(int_order, 0))
示例10: test_ica_twice
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_ica_twice():
"""Test running ICA twice"""
raw = Raw(raw_fname).crop(1.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg='grad', exclude='bads')
n_components = 0.9
max_pca_components = None
n_pca_components = 1.1
with warnings.catch_warnings(record=True):
ica1 = ICA(n_components=n_components,
max_pca_components=max_pca_components,
n_pca_components=n_pca_components, random_state=0)
ica1.fit(raw, picks=picks, decim=3)
raw_new = ica1.apply(raw, n_pca_components=n_pca_components)
ica2 = ICA(n_components=n_components,
max_pca_components=max_pca_components,
n_pca_components=1.0, random_state=0)
ica2.fit(raw_new, picks=picks, decim=3)
assert_equal(ica1.n_components_, ica2.n_components_)
示例11: test_maxwell_filter_additional
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_maxwell_filter_additional():
"""Test processing of Maxwell filtered data"""
# TODO: Future tests integrate with mne/io/tests/test_proc_history
# Load testing data (raw, SSS std origin, SSS non-standard origin)
data_path = op.join(testing.data_path(download=False))
file_name = "test_move_anon"
raw_fname = op.join(data_path, "SSS", file_name + "_raw.fif")
with warnings.catch_warnings(record=True): # maxshield
# Use 2.0 seconds of data to get stable cov. estimate
raw = Raw(raw_fname, allow_maxshield=True).crop(0.0, 2.0, False)
# Get MEG channels, compute Maxwell filtered data
raw.load_data()
raw.pick_types(meg=True, eeg=False)
int_order = 8
raw_sss = maxwell_filter(raw, origin=mf_head_origin, regularize=None, bad_condition="ignore")
# Test io on processed data
tempdir = _TempDir()
test_outname = op.join(tempdir, "test_raw_sss.fif")
raw_sss.save(test_outname)
raw_sss_loaded = Raw(test_outname, preload=True)
# Some numerical imprecision since save uses 'single' fmt
assert_allclose(raw_sss_loaded[:][0], raw_sss[:][0], rtol=1e-6, atol=1e-20)
# Test rank of covariance matrices for raw and SSS processed data
cov_raw = compute_raw_covariance(raw)
cov_sss = compute_raw_covariance(raw_sss)
scalings = None
cov_raw_rank = _estimate_rank_meeg_cov(cov_raw["data"], raw.info, scalings)
cov_sss_rank = _estimate_rank_meeg_cov(cov_sss["data"], raw_sss.info, scalings)
assert_equal(cov_raw_rank, raw.info["nchan"])
assert_equal(cov_sss_rank, _get_n_moments(int_order))
示例12: test_compute_proj_ecg
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_compute_proj_ecg():
"""Test computation of ECG SSP projectors"""
raw = Raw(raw_fname).crop(0, 10, copy=False)
raw.load_data()
for average in [False, True]:
# For speed, let's not filter here (must also not reject then)
projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
ch_name='MEG 1531', bads=['MEG 2443'],
average=average, avg_ref=True,
no_proj=True, l_freq=None,
h_freq=None, reject=None,
tmax=dur_use, qrs_threshold=0.5,
filter_length=6000)
assert_true(len(projs) == 7)
# heart rate at least 0.5 Hz, but less than 3 Hz
assert_true(events.shape[0] > 0.5 * dur_use and
events.shape[0] < 3 * dur_use)
ssp_ecg = [proj for proj in projs if proj['desc'].startswith('ECG')]
# check that the first principal component have a certain minimum
ssp_ecg = [proj for proj in ssp_ecg if 'PCA-01' in proj['desc']]
thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
for proj in ssp_ecg:
if 'planar' in proj['desc']:
assert_true(proj['explained_var'] > thresh_planar)
elif 'axial' in proj['desc']:
assert_true(proj['explained_var'] > thresh_axial)
elif 'eeg' in proj['desc']:
assert_true(proj['explained_var'] > thresh_eeg)
# XXX: better tests
# without setting a bad channel, this should throw a warning
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
ch_name='MEG 1531', bads=[],
average=average, avg_ref=True,
no_proj=True, l_freq=None,
h_freq=None, tmax=dur_use)
assert_true(len(w) >= 1)
assert_equal(projs, None)
示例13: test_find_ecg
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_find_ecg():
"""Test find ECG peaks"""
raw = Raw(raw_fname)
# once with mag-trick
# once with characteristic channel
for ch_name in ['MEG 1531', None]:
events, ch_ECG, average_pulse, ecg = find_ecg_events(
raw, event_id=999, ch_name=ch_name, return_ecg=True)
assert_equal(raw.n_times, ecg.shape[-1])
n_events = len(events)
_, times = raw[0, :]
assert_true(55 < average_pulse < 60)
picks = pick_types(
raw.info, meg='grad', eeg=False, stim=False,
eog=False, ecg=True, emg=False, ref_meg=False,
exclude='bads')
raw.load_data()
ecg_epochs = create_ecg_epochs(raw, picks=picks, keep_ecg=True)
assert_equal(len(ecg_epochs.events), n_events)
assert_true('ECG-SYN' not in raw.ch_names)
assert_true('ECG-SYN' in ecg_epochs.ch_names)
picks = pick_types(
ecg_epochs.info, meg=False, eeg=False, stim=False,
eog=False, ecg=True, emg=False, ref_meg=False,
exclude='bads')
assert_true(len(picks) == 1)
ecg_epochs = create_ecg_epochs(raw, ch_name='MEG 2641')
assert_true('MEG 2641' in ecg_epochs.ch_names)
# test with user provided ecg channel
raw.info['projs'] = list()
raw.set_channel_types({'MEG 2641': 'ecg'})
create_ecg_epochs(raw)
示例14: test_compute_proj_eog
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_compute_proj_eog():
"""Test computation of EOG SSP projectors"""
raw = Raw(raw_fname).crop(0, 10, copy=False)
raw.load_data()
for average in [False, True]:
n_projs_init = len(raw.info['projs'])
projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
bads=['MEG 2443'], average=average,
avg_ref=True, no_proj=False,
l_freq=None, h_freq=None,
reject=None, tmax=dur_use,
filter_length=6000)
assert_true(len(projs) == (7 + n_projs_init))
assert_true(np.abs(events.shape[0] -
np.sum(np.less(eog_times, dur_use))) <= 1)
ssp_eog = [proj for proj in projs if proj['desc'].startswith('EOG')]
# check that the first principal component have a certain minimum
ssp_eog = [proj for proj in ssp_eog if 'PCA-01' in proj['desc']]
thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
for proj in ssp_eog:
if 'planar' in proj['desc']:
assert_true(proj['explained_var'] > thresh_planar)
elif 'axial' in proj['desc']:
assert_true(proj['explained_var'] > thresh_axial)
elif 'eeg' in proj['desc']:
assert_true(proj['explained_var'] > thresh_eeg)
# XXX: better tests
# This will throw a warning b/c simplefilter('always')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
average=average, bads=[],
avg_ref=True, no_proj=False,
l_freq=None, h_freq=None,
tmax=dur_use)
assert_true(len(w) >= 1)
assert_equal(projs, None)
示例15: test_compute_proj_parallel
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import load_data [as 别名]
def test_compute_proj_parallel():
"""Test computation of ExG projectors using parallelization"""
raw_0 = Raw(raw_fname).crop(0, 10, copy=False)
raw_0.load_data()
raw = raw_0.copy()
projs, _ = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
bads=['MEG 2443'], average=False,
avg_ref=True, no_proj=False, n_jobs=1,
l_freq=None, h_freq=None, reject=None,
tmax=dur_use)
raw_2 = raw_0.copy()
projs_2, _ = compute_proj_eog(raw_2, n_mag=2, n_grad=2, n_eeg=2,
bads=['MEG 2443'], average=False,
avg_ref=True, no_proj=False, n_jobs=2,
l_freq=None, h_freq=None, reject=None,
tmax=dur_use)
projs = activate_proj(projs)
projs_2 = activate_proj(projs_2)
projs, _, _ = make_projector(projs, raw_2.info['ch_names'],
bads=['MEG 2443'])
projs_2, _, _ = make_projector(projs_2, raw_2.info['ch_names'],
bads=['MEG 2443'])
assert_array_almost_equal(projs, projs_2, 10)