本文整理汇总了Python中mne.Epochs.crop方法的典型用法代码示例。如果您正苦于以下问题:Python Epochs.crop方法的具体用法?Python Epochs.crop怎么用?Python Epochs.crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.Epochs
的用法示例。
在下文中一共展示了Epochs.crop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crop
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
def test_crop():
"""Test of crop of epochs
"""
raw, events, picks = _get_data()
epochs = Epochs(raw, events[:5], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=False,
reject=reject, flat=flat)
assert_raises(RuntimeError, epochs.crop, None, 0.2) # not preloaded
data_normal = epochs.get_data()
epochs2 = Epochs(raw, events[:5], event_id, tmin, tmax,
picks=picks, baseline=(None, 0), preload=True,
reject=reject, flat=flat)
with warnings.catch_warnings(record=True) as w:
epochs2.crop(-20, 200)
assert_true(len(w) == 2)
# indices for slicing
tmin_window = tmin + 0.1
tmax_window = tmax - 0.1
tmask = (epochs.times >= tmin_window) & (epochs.times <= tmax_window)
assert_true(tmin_window > tmin)
assert_true(tmax_window < tmax)
epochs3 = epochs2.crop(tmin_window, tmax_window, copy=True)
data3 = epochs3.get_data()
epochs2.crop(tmin_window, tmax_window)
data2 = epochs2.get_data()
assert_array_equal(data2, data_normal[:, :, tmask])
assert_array_equal(data3, data_normal[:, :, tmask])
示例2: test_compute_covariance_auto_reg
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
def test_compute_covariance_auto_reg():
"""Test automated regularization"""
raw = Raw(raw_fname, preload=False)
events = find_events(raw, stim_channel='STI 014')
event_ids = [1, 2, 3, 4]
reject = dict(mag=4e-12)
# cov with merged events and keep_sample_mean=True
events_merged = merge_events(events, event_ids, 1234)
picks = pick_types(raw.info, meg='mag', eeg=False)
epochs = Epochs(raw, events_merged, 1234, tmin=-0.2, tmax=0,
picks=picks[:5], baseline=(-0.2, -0.1), proj=True,
reject=reject, preload=True)
epochs.crop(None, 0)[:10]
method_params = dict(factor_analysis=dict(iter_n_components=[30]),
pca=dict(iter_n_components=[30]))
with warnings.catch_warnings(record=True) as w:
covs = compute_covariance(epochs, method='auto',
method_params=method_params,
projs=True,
return_estimators=True)
warnings.simplefilter('always')
assert_equal(len(w), 1)
logliks = [c['loglik'] for c in covs]
assert_true(np.diff(logliks).max() <= 0) # descending order
methods = ['empirical',
'factor_analysis',
'ledoit_wolf',
# 'pca', XXX FAILS
]
with warnings.catch_warnings(record=True) as w:
cov3 = compute_covariance(epochs, method=methods,
method_params=method_params, projs=False,
return_estimators=True)
warnings.simplefilter('always')
assert_equal(len(w), 1)
assert_equal(set([c['method'] for c in cov3]),
set(methods))
# projs not allowed with FA or PCA
assert_raises(ValueError, compute_covariance, epochs, method='pca',
projs=True)
# invalid prespecified method
assert_raises(ValueError, compute_covariance, epochs, method='pizza')
# invalid scalings
assert_raises(ValueError, compute_covariance, epochs, method='shrunk',
scalings=dict(misc=123))
示例3: test_crop
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
def test_crop():
"""Test of crop of epochs
"""
epochs = Epochs(
raw, events[:5], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=False, reject=reject, flat=flat
)
data_normal = epochs.get_data()
epochs2 = Epochs(
raw, events[:5], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True, reject=reject, flat=flat
)
# indices for slicing
tmin_window = tmin + 0.1
tmax_window = tmax - 0.1
tmask = (epochs.times >= tmin_window) & (epochs.times <= tmax_window)
assert_true(tmin_window > tmin)
assert_true(tmax_window < tmax)
epochs3 = epochs2.crop(tmin_window, tmax_window, copy=True)
data3 = epochs3.get_data()
epochs2.crop(tmin_window, tmax_window)
data2 = epochs2.get_data()
assert_array_equal(data2, data_normal[:, :, tmask])
assert_array_equal(data3, data_normal[:, :, tmask])
示例4: test_compute_covariance_auto_reg
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
def test_compute_covariance_auto_reg():
"""Test automated regularization"""
raw = read_raw_fif(raw_fname, preload=True)
raw.resample(100, npad='auto') # much faster estimation
events = find_events(raw, stim_channel='STI 014')
event_ids = [1, 2, 3, 4]
reject = dict(mag=4e-12)
# cov with merged events and keep_sample_mean=True
events_merged = merge_events(events, event_ids, 1234)
# we need a few channels for numerical reasons in PCA/FA
picks = pick_types(raw.info, meg='mag', eeg=False)[:10]
raw.pick_channels([raw.ch_names[pick] for pick in picks])
raw.info.normalize_proj()
epochs = Epochs(
raw, events_merged, 1234, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True, reject=reject, preload=True)
epochs = epochs.crop(None, 0)[:10]
method_params = dict(factor_analysis=dict(iter_n_components=[3]),
pca=dict(iter_n_components=[3]))
covs = compute_covariance(epochs, method='auto',
method_params=method_params,
projs=True,
return_estimators=True)
logliks = [c['loglik'] for c in covs]
assert_true(np.diff(logliks).max() <= 0) # descending order
methods = ['empirical',
'factor_analysis',
'ledoit_wolf',
'pca']
cov3 = compute_covariance(epochs, method=methods,
method_params=method_params, projs=None,
return_estimators=True)
assert_equal(set([c['method'] for c in cov3]),
set(methods))
# invalid prespecified method
assert_raises(ValueError, compute_covariance, epochs, method='pizza')
# invalid scalings
assert_raises(ValueError, compute_covariance, epochs, method='shrunk',
scalings=dict(misc=123))
示例5: test_compute_covariance_auto_reg
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
def test_compute_covariance_auto_reg():
"""Test automated regularization."""
raw = read_raw_fif(raw_fname, preload=True)
raw.resample(100, npad='auto') # much faster estimation
events = find_events(raw, stim_channel='STI 014')
event_ids = [1, 2, 3, 4]
reject = dict(mag=4e-12)
# cov with merged events and keep_sample_mean=True
events_merged = merge_events(events, event_ids, 1234)
# we need a few channels for numerical reasons in PCA/FA
picks = pick_types(raw.info, meg='mag', eeg=False)[:10]
raw.pick_channels([raw.ch_names[pick] for pick in picks])
raw.info.normalize_proj()
epochs = Epochs(
raw, events_merged, 1234, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True, reject=reject, preload=True)
epochs = epochs.crop(None, 0)[:10]
method_params = dict(factor_analysis=dict(iter_n_components=[3]),
pca=dict(iter_n_components=[3]))
covs = compute_covariance(epochs, method='auto',
method_params=method_params,
return_estimators=True)
# make sure regularization produces structured differencess
diag_mask = np.eye(len(epochs.ch_names)).astype(bool)
off_diag_mask = np.invert(diag_mask)
for cov_a, cov_b in itt.combinations(covs, 2):
if (cov_a['method'] == 'diagonal_fixed' and
# here we have diagnoal or no regularization.
cov_b['method'] == 'empirical'):
assert_true(not np.any(
cov_a['data'][diag_mask] ==
cov_b['data'][diag_mask]))
# but the rest is the same
assert_array_equal(
cov_a['data'][off_diag_mask],
cov_b['data'][off_diag_mask])
else:
# and here we have shrinkage everywhere.
assert_true(not np.any(
cov_a['data'][diag_mask] ==
cov_b['data'][diag_mask]))
assert_true(not np.any(
cov_a['data'][diag_mask] ==
cov_b['data'][diag_mask]))
logliks = [c['loglik'] for c in covs]
assert_true(np.diff(logliks).max() <= 0) # descending order
methods = ['empirical', 'factor_analysis', 'ledoit_wolf', 'oas', 'pca',
'shrunk', 'shrinkage']
cov3 = compute_covariance(epochs, method=methods,
method_params=method_params, projs=None,
return_estimators=True)
method_names = [cov['method'] for cov in cov3]
for method in ['factor_analysis', 'ledoit_wolf', 'oas', 'pca',
'shrinkage']:
this_lik = cov3[method_names.index(method)]['loglik']
assert -55 < this_lik < -45
this_lik = cov3[method_names.index('empirical')]['loglik']
assert -110 < this_lik < -100
this_lik = cov3[method_names.index('shrunk')]['loglik']
assert -45 < this_lik < -35
assert_equal(set([c['method'] for c in cov3]), set(methods))
cov4 = compute_covariance(epochs, method=methods,
method_params=method_params, projs=None,
return_estimators=False)
assert cov3[0]['method'] == cov4['method'] # ordering
# invalid prespecified method
assert_raises(ValueError, compute_covariance, epochs, method='pizza')
# invalid scalings
assert_raises(ValueError, compute_covariance, epochs, method='shrunk',
scalings=dict(misc=123))
示例6: find_events
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
# strip channel names of "." characters
raw.rename_channels(lambda x: x.strip('.'))
# Apply band-pass filter
raw.filter(7., 30., method='iir')
events = find_events(raw, shortest_event=0, stim_channel='STI 014')
picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
exclude='bads')
# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
baseline=None, preload=True, add_eeg_ref=False)
epochs_train = epochs.crop(tmin=1., tmax=2., copy=True)
labels = epochs.events[:, -1] - 2
###############################################################################
# Classification with linear discrimant analysis
from sklearn.lda import LDA # noqa
from sklearn.cross_validation import ShuffleSplit # noqa
# Assemble a classifier
svc = LDA()
csp = CSP(n_components=4, reg=None, log=True)
# Define a monte-carlo cross-validation generator (reduce variance):
cv = ShuffleSplit(len(labels), 10, test_size=0.2, random_state=42)
scores = []
示例7: test_compute_covariance_auto_reg
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import crop [as 别名]
def test_compute_covariance_auto_reg(rank):
"""Test automated regularization."""
raw = read_raw_fif(raw_fname, preload=True)
raw.resample(100, npad='auto') # much faster estimation
events = find_events(raw, stim_channel='STI 014')
event_ids = [1, 2, 3, 4]
reject = dict(mag=4e-12)
# cov with merged events and keep_sample_mean=True
events_merged = merge_events(events, event_ids, 1234)
# we need a few channels for numerical reasons in PCA/FA
picks = pick_types(raw.info, meg='mag', eeg=False)[:10]
raw.pick_channels([raw.ch_names[pick] for pick in picks])
raw.info.normalize_proj()
epochs = Epochs(
raw, events_merged, 1234, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True, reject=reject, preload=True)
epochs = epochs.crop(None, 0)[:5]
method_params = dict(factor_analysis=dict(iter_n_components=[3]),
pca=dict(iter_n_components=[3]))
covs = compute_covariance(epochs, method='auto',
method_params=method_params,
return_estimators=True, rank=rank)
# make sure regularization produces structured differencess
diag_mask = np.eye(len(epochs.ch_names)).astype(bool)
off_diag_mask = np.invert(diag_mask)
for cov_a, cov_b in itt.combinations(covs, 2):
if (cov_a['method'] == 'diagonal_fixed' and
# here we have diagnoal or no regularization.
cov_b['method'] == 'empirical' and rank == 'full'):
assert not np.any(cov_a['data'][diag_mask] ==
cov_b['data'][diag_mask])
# but the rest is the same
assert_array_equal(cov_a['data'][off_diag_mask],
cov_b['data'][off_diag_mask])
else:
# and here we have shrinkage everywhere.
assert not np.any(cov_a['data'][diag_mask] ==
cov_b['data'][diag_mask])
assert not np.any(cov_a['data'][diag_mask] ==
cov_b['data'][diag_mask])
logliks = [c['loglik'] for c in covs]
assert np.diff(logliks).max() <= 0 # descending order
methods = ['empirical', 'ledoit_wolf', 'oas', 'shrunk', 'shrinkage']
if rank == 'full':
methods.extend(['factor_analysis', 'pca'])
with catch_logging() as log:
cov3 = compute_covariance(epochs, method=methods,
method_params=method_params, projs=None,
return_estimators=True, rank=rank,
verbose=True)
log = log.getvalue().split('\n')
if rank is None:
assert ' Setting small MAG eigenvalues to zero (without PCA)' in log
assert 'Reducing data rank from 10 -> 7' in log
else:
assert 'Reducing' not in log
method_names = [cov['method'] for cov in cov3]
best_bounds = [-45, -35]
bounds = [-55, -45] if rank == 'full' else best_bounds
for method in set(methods) - {'empirical', 'shrunk'}:
this_lik = cov3[method_names.index(method)]['loglik']
assert bounds[0] < this_lik < bounds[1]
this_lik = cov3[method_names.index('shrunk')]['loglik']
assert best_bounds[0] < this_lik < best_bounds[1]
this_lik = cov3[method_names.index('empirical')]['loglik']
bounds = [-110, -100] if rank == 'full' else best_bounds
assert bounds[0] < this_lik < bounds[1]
assert_equal({c['method'] for c in cov3}, set(methods))
cov4 = compute_covariance(epochs, method=methods,
method_params=method_params, projs=None,
return_estimators=False, rank=rank)
assert cov3[0]['method'] == cov4['method'] # ordering
# invalid prespecified method
pytest.raises(ValueError, compute_covariance, epochs, method='pizza')
# invalid scalings
pytest.raises(ValueError, compute_covariance, epochs, method='shrunk',
scalings=dict(misc=123))