本文整理汇总了Python中mne.io.RawArray.copy方法的典型用法代码示例。如果您正苦于以下问题:Python RawArray.copy方法的具体用法?Python RawArray.copy怎么用?Python RawArray.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.RawArray
的用法示例。
在下文中一共展示了RawArray.copy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_picks
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import copy [as 别名]
def test_filter_picks():
"""Test filtering default channel picks"""
ch_types = ['mag', 'grad', 'eeg', 'seeg', 'misc', 'stim', 'ecog']
info = create_info(ch_names=ch_types, ch_types=ch_types, sfreq=256)
raw = RawArray(data=np.zeros((len(ch_types), 1000)), info=info)
# -- Deal with meg mag grad exception
ch_types = ('misc', 'stim', 'meg', 'eeg', 'seeg', 'ecog')
# -- Filter data channels
for ch_type in ('mag', 'grad', 'eeg', 'seeg', 'ecog'):
picks = dict((ch, ch == ch_type) for ch in ch_types)
picks['meg'] = ch_type if ch_type in ('mag', 'grad') else False
raw_ = raw.copy().pick_types(**picks)
# Avoid RuntimeWarning due to Attenuation
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
raw_.filter(10, 30)
assert_true(any(['Attenuation' in str(ww.message) for ww in w]))
# -- Error if no data channel
for ch_type in ('misc', 'stim'):
picks = dict((ch, ch == ch_type) for ch in ch_types)
raw_ = raw.copy().pick_types(**picks)
assert_raises(RuntimeError, raw_.filter, 10, 30)
示例2: test_mark_flat
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import copy [as 别名]
def test_mark_flat(first_samp):
"""Test marking flat segments."""
# Test if ECG analysis will work on data that is not preloaded
n_ch, n_times = 11, 1000
data = np.random.RandomState(0).randn(n_ch, n_times)
assert not (np.diff(data, axis=-1) == 0).any() # nothing flat at first
info = create_info(n_ch, 1000., 'eeg')
info['meas_date'] = (1, 2)
# test first_samp != for gh-6295
raw = RawArray(data, info, first_samp=first_samp)
raw.info['bads'] = [raw.ch_names[-1]]
#
# First make a channel flat the whole time
#
raw_0 = raw.copy()
raw_0._data[0] = 0.
for kwargs, bads, want_times in [
# Anything < 1 will mark spatially
(dict(bad_percent=100.), [], 0),
(dict(bad_percent=99.9), [raw.ch_names[0]], n_times),
(dict(), [raw.ch_names[0]], n_times)]: # default (1)
raw_time = mark_flat(raw_0.copy(), verbose='debug', **kwargs)
want_bads = raw.info['bads'] + bads
assert raw_time.info['bads'] == want_bads
n_good_times = raw_time.get_data(reject_by_annotation='omit').shape[1]
assert n_good_times == want_times
#
# Now make a channel flat for 20% of the time points
#
raw_0 = raw.copy()
n_good_times = int(round(0.8 * n_times))
raw_0._data[0, n_good_times:] = 0.
threshold = 100 * (n_times - n_good_times) / n_times
for kwargs, bads, want_times in [
# Should change behavior at bad_percent=20
(dict(bad_percent=100), [], n_good_times),
(dict(bad_percent=threshold), [], n_good_times),
(dict(bad_percent=threshold - 1e-5), [raw.ch_names[0]], n_times),
(dict(), [raw.ch_names[0]], n_times)]:
raw_time = mark_flat(raw_0.copy(), verbose='debug', **kwargs)
want_bads = raw.info['bads'] + bads
assert raw_time.info['bads'] == want_bads
n_good_times = raw_time.get_data(reject_by_annotation='omit').shape[1]
assert n_good_times == want_times
with pytest.raises(TypeError, match='must be an instance of BaseRaw'):
mark_flat(0.)
with pytest.raises(ValueError, match='not convert string to float'):
mark_flat(raw, 'x')
示例3: test_picks_by_channels
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import copy [as 别名]
def test_picks_by_channels():
"""Test creating pick_lists."""
rng = np.random.RandomState(909)
test_data = rng.random_sample((4, 2000))
ch_names = ['MEG %03d' % i for i in [1, 2, 3, 4]]
ch_types = ['grad', 'mag', 'mag', 'eeg']
sfreq = 250.0
info = create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
_assert_channel_types(info)
raw = RawArray(test_data, info)
pick_list = _picks_by_type(raw.info)
assert_equal(len(pick_list), 3)
assert_equal(pick_list[0][0], 'mag')
pick_list2 = _picks_by_type(raw.info, meg_combined=False)
assert_equal(len(pick_list), len(pick_list2))
assert_equal(pick_list2[0][0], 'mag')
pick_list2 = _picks_by_type(raw.info, meg_combined=True)
assert_equal(len(pick_list), len(pick_list2) + 1)
assert_equal(pick_list2[0][0], 'meg')
test_data = rng.random_sample((4, 2000))
ch_names = ['MEG %03d' % i for i in [1, 2, 3, 4]]
ch_types = ['mag', 'mag', 'mag', 'mag']
sfreq = 250.0
info = create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
raw = RawArray(test_data, info)
# This acts as a set, not an order
assert_array_equal(pick_channels(info['ch_names'], ['MEG 002', 'MEG 001']),
[0, 1])
# Make sure checks for list input work.
pytest.raises(ValueError, pick_channels, ch_names, 'MEG 001')
pytest.raises(ValueError, pick_channels, ch_names, ['MEG 001'], 'hi')
pick_list = _picks_by_type(raw.info)
assert_equal(len(pick_list), 1)
assert_equal(pick_list[0][0], 'mag')
pick_list2 = _picks_by_type(raw.info, meg_combined=True)
assert_equal(len(pick_list), len(pick_list2))
assert_equal(pick_list2[0][0], 'mag')
# pick_types type check
pytest.raises(ValueError, raw.pick_types, eeg='string')
# duplicate check
names = ['MEG 002', 'MEG 002']
assert len(pick_channels(raw.info['ch_names'], names)) == 1
assert len(raw.copy().pick_channels(names)[0][0]) == 1
示例4: test_crop
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import copy [as 别名]
def test_crop():
"""Test cropping raw files
"""
# split a concatenated file to test a difficult case
raw = concatenate_raws([Raw(f) for f in [fif_fname, fif_fname]])
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))
示例5: test_annotations
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import copy [as 别名]
def test_annotations():
"""Test annotation class."""
raw = read_raw_fif(fif_fname)
onset = np.array(range(10))
duration = np.ones(10)
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
raw2 = raw.copy()
orig_time = (meas_date[0] + meas_date[1] * 0.000001 +
raw2.first_samp / raw2.info['sfreq'])
annot = Annotations(onset, duration, description, orig_time)
assert_true(' segments' in repr(annot))
raw2.annotations = annot
assert_array_equal(raw2.annotations.onset, onset)
concatenate_raws([raw, raw2])
raw.annotations.delete(-1) # remove boundary annotations
raw.annotations.delete(-1)
assert_array_almost_equal(onset + 20., raw.annotations.onset, decimal=2)
assert_array_equal(annot.duration, raw.annotations.duration)
assert_array_equal(raw.annotations.description, np.repeat('test', 10))
# Test combining with RawArray and orig_times
data = np.random.randn(2, 1000) * 10e-12
sfreq = 100.
info = create_info(ch_names=['MEG1', 'MEG2'], ch_types=['grad'] * 2,
sfreq=sfreq)
info['meas_date'] = 0
raws = []
for i, fs in enumerate([12300, 100, 12]):
raw = RawArray(data.copy(), info, first_samp=fs)
ants = Annotations([1., 2.], [.5, .5], 'x', fs / sfreq)
raw.annotations = ants
raws.append(raw)
raw = RawArray(data.copy(), info)
raw.annotations = Annotations([1.], [.5], 'x', None)
raws.append(raw)
raw = concatenate_raws(raws)
boundary_idx = np.where(raw.annotations.description == 'BAD boundary')[0]
assert_equal(len(boundary_idx), 3)
raw.annotations.delete(boundary_idx)
boundary_idx = np.where(raw.annotations.description == 'EDGE boundary')[0]
assert_equal(len(boundary_idx), 3)
raw.annotations.delete(boundary_idx)
assert_array_equal(raw.annotations.onset, [1., 2., 11., 12., 21., 22.,
31.])
raw.annotations.delete(2)
assert_array_equal(raw.annotations.onset, [1., 2., 12., 21., 22., 31.])
raw.annotations.append(5, 1.5, 'y')
assert_array_equal(raw.annotations.onset, [1., 2., 12., 21., 22., 31., 5])
assert_array_equal(raw.annotations.duration, [.5, .5, .5, .5, .5, .5, 1.5])
assert_array_equal(raw.annotations.description, ['x', 'x', 'x', 'x', 'x',
'x', 'y'])
# Test concatenating annotations with and without orig_time.
raw = read_raw_fif(fif_fname)
last_time = raw.last_samp / raw.info['sfreq']
raw2 = raw.copy()
raw.annotations = Annotations([45.], [3], 'test', raw.info['meas_date'])
raw2.annotations = Annotations([2.], [3], 'BAD', None)
raw = concatenate_raws([raw, raw2])
raw.annotations.delete(-1) # remove boundary annotations
raw.annotations.delete(-1)
assert_array_almost_equal(raw.annotations.onset, [45., 2. + last_time],
decimal=2)