本文整理汇总了Python中mne.io.Raw.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.copy方法的具体用法?Python Raw.copy怎么用?Python Raw.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.Raw
的用法示例。
在下文中一共展示了Raw.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_calculate_chpi_positions
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_calculate_chpi_positions():
"""Test calculation of cHPI positions
"""
trans, rot, t = head_pos_to_trans_rot_t(read_head_pos(pos_fname))
with warnings.catch_warnings(record=True):
raw = Raw(chpi_fif_fname, allow_maxshield=True, preload=True)
t -= raw.first_samp / raw.info['sfreq']
quats = _calculate_chpi_positions(raw, verbose='debug')
trans_est, rot_est, t_est = head_pos_to_trans_rot_t(quats)
_compare_positions((trans, rot, t), (trans_est, rot_est, t_est), 0.003)
# degenerate conditions
raw_no_chpi = Raw(test_fif_fname)
assert_raises(RuntimeError, _calculate_chpi_positions, raw_no_chpi)
raw_bad = raw.copy()
for d in raw_bad.info['dig']:
if d['kind'] == FIFF.FIFFV_POINT_HPI:
d['coord_frame'] = 999
break
assert_raises(RuntimeError, _calculate_chpi_positions, raw_bad)
raw_bad = raw.copy()
for d in raw_bad.info['dig']:
if d['kind'] == FIFF.FIFFV_POINT_HPI:
d['r'] = np.ones(3)
raw_bad.crop(0, 1., copy=False)
with warnings.catch_warnings(record=True): # bad pos
with catch_logging() as log_file:
_calculate_chpi_positions(raw_bad, verbose=True)
# ignore HPI info header and [done] footer
for line in log_file.getvalue().strip().split('\n')[4:-1]:
assert_true('0/5 good' in line)
示例2: test_calculate_chpi_positions
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_calculate_chpi_positions():
"""Test calculation of cHPI positions
"""
trans, rot, t = get_chpi_positions(pos_fname)
with warnings.catch_warnings(record=True):
raw = Raw(raw_fif_fname, allow_maxshield=True, preload=True)
t -= raw.first_samp / raw.info['sfreq']
trans_est, rot_est, t_est = _calculate_chpi_positions(raw, verbose='debug')
_compare_positions((trans, rot, t), (trans_est, rot_est, t_est))
# degenerate conditions
raw_no_chpi = Raw(test_fif_fname)
assert_raises(RuntimeError, _calculate_chpi_positions, raw_no_chpi)
raw_bad = raw.copy()
for d in raw_bad.info['dig']:
if d['kind'] == FIFF.FIFFV_POINT_HPI:
d['coord_frame'] = 999
break
assert_raises(RuntimeError, _calculate_chpi_positions, raw_bad)
raw_bad = raw.copy()
for d in raw_bad.info['dig']:
if d['kind'] == FIFF.FIFFV_POINT_HPI:
d['r'] = np.ones(3)
raw_bad.crop(0, 1., copy=False)
tempdir = _TempDir()
log_file = op.join(tempdir, 'temp_log.txt')
set_log_file(log_file, overwrite=True)
try:
_calculate_chpi_positions(raw_bad)
finally:
set_log_file()
with open(log_file, 'r') as fid:
for line in fid:
assert_true('0/5 acceptable' in line)
示例3: test_calculate_chpi_positions
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_calculate_chpi_positions():
"""Test calculation of cHPI positions
"""
trans, rot, t = get_chpi_positions(pos_fname)
with warnings.catch_warnings(record=True):
raw = Raw(raw_fif_fname, allow_maxshield=True, preload=True)
t -= raw.first_samp / raw.info['sfreq']
trans_est, rot_est, t_est = _calculate_chpi_positions(raw, verbose='debug')
_compare_positions((trans, rot, t), (trans_est, rot_est, t_est))
# degenerate conditions
raw_no_chpi = Raw(test_fif_fname)
assert_raises(RuntimeError, _calculate_chpi_positions, raw_no_chpi)
raw_bad = raw.copy()
for d in raw_bad.info['dig']:
if d['kind'] == FIFF.FIFFV_POINT_HPI:
d['coord_frame'] = 999
break
assert_raises(RuntimeError, _calculate_chpi_positions, raw_bad)
raw_bad = raw.copy()
for d in raw_bad.info['dig']:
if d['kind'] == FIFF.FIFFV_POINT_HPI:
d['r'] = np.ones(3)
raw_bad.crop(0, 1., copy=False)
with catch_logging() as log_file:
_calculate_chpi_positions(raw_bad)
for line in log_file.getvalue().split('\n')[:-1]:
assert_true('0/5 acceptable' in line)
示例4: test_calculate_chpi_positions
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_calculate_chpi_positions():
"""Test calculation of cHPI positions
"""
trans, rot, t = head_pos_to_trans_rot_t(read_head_pos(pos_fname))
raw = Raw(chpi_fif_fname, allow_maxshield="yes", preload=True)
t -= raw.first_samp / raw.info["sfreq"]
quats = _calculate_chpi_positions(raw, verbose="debug")
trans_est, rot_est, t_est = head_pos_to_trans_rot_t(quats)
_compare_positions((trans, rot, t), (trans_est, rot_est, t_est), 0.003)
# degenerate conditions
raw_no_chpi = Raw(test_fif_fname)
assert_raises(RuntimeError, _calculate_chpi_positions, raw_no_chpi)
raw_bad = raw.copy()
for d in raw_bad.info["dig"]:
if d["kind"] == FIFF.FIFFV_POINT_HPI:
d["coord_frame"] = 999
break
assert_raises(RuntimeError, _calculate_chpi_positions, raw_bad)
raw_bad = raw.copy()
for d in raw_bad.info["dig"]:
if d["kind"] == FIFF.FIFFV_POINT_HPI:
d["r"] = np.ones(3)
raw_bad.crop(0, 1.0, copy=False)
with warnings.catch_warnings(record=True): # bad pos
with catch_logging() as log_file:
_calculate_chpi_positions(raw_bad, verbose=True)
# ignore HPI info header and [done] footer
for line in log_file.getvalue().strip().split("\n")[4:-1]:
assert_true("0/5 good" in line)
# half the rate cuts off cHPI coils
with warnings.catch_warnings(record=True): # uint cast suggestion
raw.resample(300.0, npad="auto")
assert_raises_regex(RuntimeError, "above the", _calculate_chpi_positions, raw)
示例5: test_add_channels
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_add_channels():
"""Test raw splitting / re-appending channel types
"""
raw = Raw(test_fif_fname).crop(0, 1, copy=False).load_data()
raw_nopre = Raw(test_fif_fname, preload=False)
raw_eeg_meg = raw.copy().pick_types(meg=True, eeg=True)
raw_eeg = raw.copy().pick_types(meg=False, eeg=True)
raw_meg = raw.copy().pick_types(meg=True, eeg=False)
raw_stim = raw.copy().pick_types(meg=False, eeg=False, stim=True)
raw_new = raw_meg.copy().add_channels([raw_eeg, raw_stim])
assert_true(
all(ch in raw_new.ch_names
for ch in list(raw_stim.ch_names) + list(raw_meg.ch_names))
)
raw_new = raw_meg.copy().add_channels([raw_eeg])
assert_true(ch in raw_new.ch_names for ch in raw.ch_names)
assert_array_equal(raw_new[:, :][0], raw_eeg_meg[:, :][0])
assert_array_equal(raw_new[:, :][1], raw[:, :][1])
assert_true(all(ch not in raw_new.ch_names for ch in raw_stim.ch_names))
# Now test errors
raw_badsf = raw_eeg.copy()
raw_badsf.info['sfreq'] = 3.1415927
raw_eeg.crop(.5, copy=False)
assert_raises(AssertionError, raw_meg.add_channels, [raw_nopre])
assert_raises(RuntimeError, raw_meg.add_channels, [raw_badsf])
assert_raises(AssertionError, raw_meg.add_channels, [raw_eeg])
assert_raises(ValueError, raw_meg.add_channels, [raw_meg])
assert_raises(AssertionError, raw_meg.add_channels, raw_badsf)
示例6: test_hilbert
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_hilbert():
"""Test computation of analytic signal using hilbert
"""
raw = Raw(fif_fname, preload=True)
picks_meg = pick_types(raw.info, meg=True, exclude='bads')
picks = picks_meg[:4]
raw_filt = raw.copy()
raw_filt.filter(10, 20)
raw_filt_2 = raw_filt.copy()
raw2 = raw.copy()
raw3 = raw.copy()
raw.apply_hilbert(picks)
raw2.apply_hilbert(picks, envelope=True, n_jobs=2)
# Test custom n_fft
raw_filt.apply_hilbert(picks)
raw_filt_2.apply_hilbert(picks, n_fft=raw_filt_2.n_times + 1000)
assert_equal(raw_filt._data.shape, raw_filt_2._data.shape)
assert_allclose(raw_filt._data[:, 50:-50], raw_filt_2._data[:, 50:-50],
atol=1e-13, rtol=1e-2)
assert_raises(ValueError, raw3.apply_hilbert, picks,
n_fft=raw3.n_times - 100)
env = np.abs(raw._data[picks, :])
assert_allclose(env, raw2._data[picks, :], rtol=1e-2, atol=1e-13)
示例7: test_resample
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_resample():
"""Test resample (with I/O and multiple files)
"""
tempdir = _TempDir()
raw = Raw(fif_fname).crop(0, 3, False)
raw.preload_data()
raw_resamp = raw.copy()
sfreq = raw.info['sfreq']
# test parallel on upsample
raw_resamp.resample(sfreq * 2, n_jobs=2)
assert_equal(raw_resamp.n_times, len(raw_resamp.times))
raw_resamp.save(op.join(tempdir, 'raw_resamp-raw.fif'))
raw_resamp = Raw(op.join(tempdir, 'raw_resamp-raw.fif'), preload=True)
assert_equal(sfreq, raw_resamp.info['sfreq'] / 2)
assert_equal(raw.n_times, raw_resamp.n_times / 2)
assert_equal(raw_resamp._data.shape[1], raw_resamp.n_times)
assert_equal(raw._data.shape[0], raw_resamp._data.shape[0])
# test non-parallel on downsample
raw_resamp.resample(sfreq, n_jobs=1)
assert_equal(raw_resamp.info['sfreq'], sfreq)
assert_equal(raw._data.shape, raw_resamp._data.shape)
assert_equal(raw.first_samp, raw_resamp.first_samp)
assert_equal(raw.last_samp, raw.last_samp)
# upsampling then downsampling doubles resampling error, but this still
# works (hooray). Note that the stim channels had to be sub-sampled
# without filtering to be accurately preserved
# note we have to treat MEG and EEG+STIM channels differently (tols)
assert_allclose(raw._data[:306, 200:-200],
raw_resamp._data[:306, 200:-200],
rtol=1e-2, atol=1e-12)
assert_allclose(raw._data[306:, 200:-200],
raw_resamp._data[306:, 200:-200],
rtol=1e-2, atol=1e-7)
# now check multiple file support w/resampling, as order of operations
# (concat, resample) should not affect our data
raw1 = raw.copy()
raw2 = raw.copy()
raw3 = raw.copy()
raw4 = raw.copy()
raw1 = concatenate_raws([raw1, raw2])
raw1.resample(10)
raw3.resample(10)
raw4.resample(10)
raw3 = concatenate_raws([raw3, raw4])
assert_array_equal(raw1._data, raw3._data)
assert_array_equal(raw1._first_samps, raw3._first_samps)
assert_array_equal(raw1._last_samps, raw3._last_samps)
assert_array_equal(raw1._raw_lengths, raw3._raw_lengths)
assert_equal(raw1.first_samp, raw3.first_samp)
assert_equal(raw1.last_samp, raw3.last_samp)
assert_equal(raw1.info['sfreq'], raw3.info['sfreq'])
示例8: test_cov_estimation_on_raw
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_cov_estimation_on_raw():
"""Test estimation from raw (typically empty room)"""
tempdir = _TempDir()
raw = Raw(raw_fname, preload=True)
cov_mne = read_cov(erm_cov_fname)
# The pure-string uses the more efficient numpy-based method, the
# the list gets triaged to compute_covariance (should be equivalent
# but use more memory)
for method in ('empirical', ['empirical']):
cov = compute_raw_covariance(raw, tstep=None, method=method)
assert_equal(cov.ch_names, cov_mne.ch_names)
assert_equal(cov.nfree, cov_mne.nfree)
assert_snr(cov.data, cov_mne.data, 1e4)
cov = compute_raw_covariance(raw, method=method) # tstep=0.2 (default)
assert_equal(cov.nfree, cov_mne.nfree - 119) # cutoff some samples
assert_snr(cov.data, cov_mne.data, 1e2)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
raw_pick = raw.copy().pick_channels(
[raw.ch_names[pick] for pick in picks])
raw_pick.info.normalize_proj()
cov = compute_raw_covariance(raw_pick, picks=picks, tstep=None,
method=method)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 1e4)
cov = compute_raw_covariance(raw_pick, picks=picks, method=method)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 90) # cutoff samps
# make sure we get a warning with too short a segment
raw_2 = Raw(raw_fname).crop(0, 1, copy=False)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov = compute_raw_covariance(raw_2, method=method)
assert_true(any('Too few samples' in str(ww.message) for ww in w))
# no epochs found due to rejection
assert_raises(ValueError, compute_raw_covariance, raw, tstep=None,
method='empirical', reject=dict(eog=200e-6))
# but this should work
cov = compute_raw_covariance(raw.copy().crop(0, 10., copy=False),
tstep=None, method=method,
reject=dict(eog=1000e-6))
示例9: test_crop
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_crop():
"""Test cropping raw files
"""
# split a concatenated file to test a difficult case
raw = Raw([fif_fname, fif_fname], preload=False)
split_size = 10. # in seconds
sfreq = raw.info['sfreq']
nsamp = (raw.last_samp - raw.first_samp + 1)
# do an annoying case (off-by-one splitting)
tmins = np.r_[1., np.round(np.arange(0., nsamp - 1, split_size * sfreq))]
tmins = np.sort(tmins)
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp - 1]))
tmaxs /= sfreq
tmins /= sfreq
raws = [None] * len(tmins)
for ri, (tmin, tmax) in enumerate(zip(tmins, tmaxs)):
raws[ri] = raw.copy().crop(tmin, tmax, copy=False)
all_raw_2 = concatenate_raws(raws, preload=False)
assert_equal(raw.first_samp, all_raw_2.first_samp)
assert_equal(raw.last_samp, all_raw_2.last_samp)
assert_array_equal(raw[:, :][0], all_raw_2[:, :][0])
tmins = np.round(np.arange(0., nsamp - 1, split_size * sfreq))
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp - 1]))
tmaxs /= sfreq
tmins /= sfreq
# going in revere order so the last fname is the first file (need it later)
raws = [None] * len(tmins)
for ri, (tmin, tmax) in enumerate(zip(tmins, tmaxs)):
raws[ri] = raw.copy().crop(tmin, tmax, copy=False)
# test concatenation of split file
all_raw_1 = concatenate_raws(raws, preload=False)
all_raw_2 = raw.copy().crop(0, None, copy=False)
for ar in [all_raw_1, all_raw_2]:
assert_equal(raw.first_samp, ar.first_samp)
assert_equal(raw.last_samp, ar.last_samp)
assert_array_equal(raw[:, :][0], ar[:, :][0])
# test shape consistency of cropped raw
data = np.zeros((1, 1002001))
info = create_info(1, 1000)
raw = RawArray(data, info)
for tmin in range(0, 1001, 100):
raw1 = raw.copy().crop(tmin=tmin, tmax=tmin + 2, copy=False)
assert_equal(raw1[:][0].shape, (1, 2001))
示例10: test_cross_talk
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_cross_talk():
"""Test Maxwell filter cross-talk cancellation"""
raw = Raw(raw_fname, allow_maxshield='yes').crop(0., 1., copy=False)
raw.info['bads'] = bads
sss_ctc = Raw(sss_ctc_fname)
raw_sss = maxwell_filter(raw, cross_talk=ctc_fname,
origin=mf_head_origin, regularize=None,
bad_condition='ignore')
assert_meg_snr(raw_sss, sss_ctc, 275.)
py_ctc = raw_sss.info['proc_history'][0]['max_info']['sss_ctc']
assert_true(len(py_ctc) > 0)
assert_raises(ValueError, maxwell_filter, raw, cross_talk=raw)
assert_raises(ValueError, maxwell_filter, raw, cross_talk=raw_fname)
mf_ctc = sss_ctc.info['proc_history'][0]['max_info']['sss_ctc']
del mf_ctc['block_id'] # we don't write this
assert_equal(object_diff(py_ctc, mf_ctc), '')
raw_ctf = Raw(fname_ctf_raw)
assert_raises(ValueError, maxwell_filter, raw_ctf) # cannot fit headshape
raw_sss = maxwell_filter(raw_ctf, origin=(0., 0., 0.04))
_assert_n_free(raw_sss, 68)
raw_sss = maxwell_filter(raw_ctf, origin=(0., 0., 0.04), ignore_ref=True)
_assert_n_free(raw_sss, 70)
raw_missing = raw.copy().crop(0, 0.1).load_data().pick_channels(
[raw.ch_names[pi] for pi in pick_types(raw.info, meg=True,
exclude=())[3:]])
with warnings.catch_warnings(record=True) as w:
maxwell_filter(raw_missing, cross_talk=ctc_fname)
assert_equal(len(w), 1)
assert_true('Not all cross-talk channels in raw' in str(w[0].message))
# MEG channels not in cross-talk
assert_raises(RuntimeError, maxwell_filter, raw_ctf, origin=(0., 0., 0.04),
cross_talk=ctc_fname)
示例11: test_raw_copy
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_raw_copy():
"""Test Raw copy
"""
raw = Raw(fif_fname, preload=True)
data, _ = raw[:, :]
copied = raw.copy()
copied_data, _ = copied[:, :]
assert_array_equal(data, copied_data)
assert_equal(sorted(raw.__dict__.keys()), sorted(copied.__dict__.keys()))
raw = Raw(fif_fname, preload=False)
data, _ = raw[:, :]
copied = raw.copy()
copied_data, _ = copied[:, :]
assert_array_equal(data, copied_data)
assert_equal(sorted(raw.__dict__.keys()), sorted(copied.__dict__.keys()))
示例12: test_io_complex
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_io_complex():
"""Test IO with complex data types
"""
rng = np.random.RandomState(0)
tempdir = _TempDir()
dtypes = [np.complex64, np.complex128]
raw = Raw(fif_fname, preload=True)
picks = np.arange(5)
start, stop = raw.time_as_index([0, 5])
data_orig, _ = raw[picks, start:stop]
for di, dtype in enumerate(dtypes):
imag_rand = np.array(1j * rng.randn(data_orig.shape[0], data_orig.shape[1]), dtype)
raw_cp = raw.copy()
raw_cp._data = np.array(raw_cp._data, dtype)
raw_cp._data[picks, start:stop] += imag_rand
# this should throw an error because it's complex
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
raw_cp.save(op.join(tempdir, "raw.fif"), picks, tmin=0, tmax=5, overwrite=True)
# warning gets thrown on every instance b/c simplifilter('always')
assert_equal(len(w), 1)
raw2 = Raw(op.join(tempdir, "raw.fif"))
raw2_data, _ = raw2[picks, :]
n_samp = raw2_data.shape[1]
assert_allclose(raw2_data[:, :n_samp], raw_cp._data[picks, :n_samp])
# with preloading
raw2 = Raw(op.join(tempdir, "raw.fif"), preload=True)
raw2_data, _ = raw2[picks, :]
n_samp = raw2_data.shape[1]
assert_allclose(raw2_data[:, :n_samp], raw_cp._data[picks, :n_samp])
示例13: test_make_eeg_layout
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_make_eeg_layout():
""" Test creation of EEG layout """
tmp_name = 'foo'
lout_name = 'test_raw'
lout_orig = read_layout(kind=lout_name, path=lout_path)
info = Raw(fif_fname).info
layout = make_eeg_layout(info)
layout.save(op.join(tempdir, tmp_name + '.lout'))
lout_new = read_layout(kind=tmp_name, path=tempdir, scale=False)
assert_array_equal(lout_new.kind, tmp_name)
assert_allclose(layout.pos, lout_new.pos, atol=0.1)
assert_array_equal(lout_orig.names, lout_new.names)
# Test input validation
assert_raises(ValueError, make_eeg_layout, info, radius=-0.1)
assert_raises(ValueError, make_eeg_layout, info, radius=0.6)
assert_raises(ValueError, make_eeg_layout, info, width=-0.1)
assert_raises(ValueError, make_eeg_layout, info, width=1.1)
assert_raises(ValueError, make_eeg_layout, info, height=-0.1)
assert_raises(ValueError, make_eeg_layout, info, height=1.1)
bad_info = info.copy()
bad_info['dig'] = None
assert_raises(RuntimeError, make_eeg_layout, bad_info)
bad_info['dig'] = []
assert_raises(RuntimeError, make_eeg_layout, bad_info)
示例14: test_ica_rank_reduction
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_ica_rank_reduction():
"""Test recovery ICA rank reduction"""
# Most basic recovery
raw = Raw(raw_fname).crop(0.5, stop, copy=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())
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)
示例15: test_annotations
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import copy [as 别名]
def test_annotations():
"""Test annotation class."""
raw = Raw(fif_fname)
onset = np.array(range(10))
duration = np.ones(10) + raw.first_samp
description = np.repeat('test', 10)
dt = datetime.utcnow()
meas_date = raw.info['meas_date']
# Test time shifts.
for orig_time in [None, dt, meas_date[0], meas_date]:
annot = Annotations(onset, duration, description, orig_time)
assert_raises(ValueError, Annotations, onset, duration, description[:9])
assert_raises(ValueError, Annotations, [onset, 1], duration, description)
assert_raises(ValueError, Annotations, onset, [duration, 1], description)
# Test combining annotations with concatenate_raws
annot = Annotations(onset, duration, description, dt)
sfreq = raw.info['sfreq']
raw2 = raw.copy()
raw2.annotations = annot
concatenate_raws([raw, raw2])
assert_array_equal(annot.onset, raw.annotations.onset)
assert_array_equal(annot.duration, raw.annotations.duration)
raw2.annotations = Annotations(onset, duration * 2, description, None)
last_samp = raw.last_samp - 1
concatenate_raws([raw, raw2])
onsets = np.concatenate([onset,
onset + (last_samp - raw.first_samp) / sfreq])
assert_array_equal(raw.annotations.onset, onsets)
assert_array_equal(raw.annotations.onset[:10], onset)
assert_array_equal(raw.annotations.duration[:10], duration)
assert_array_equal(raw.annotations.duration[10:], duration * 2)
assert_array_equal(raw.annotations.description, np.repeat('test', 20))