本文整理汇总了Python中mne.Epochs.plot方法的典型用法代码示例。如果您正苦于以下问题:Python Epochs.plot方法的具体用法?Python Epochs.plot怎么用?Python Epochs.plot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.Epochs
的用法示例。
在下文中一共展示了Epochs.plot方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_array_raw
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
def test_array_raw():
"""Test creating raw from array
"""
import matplotlib.pyplot as plt
# creating
raw = Raw(fif_fname).crop(2, 5, copy=False)
data, times = raw[:, :]
sfreq = raw.info['sfreq']
ch_names = [(ch[4:] if 'STI' not in ch else ch)
for ch in raw.info['ch_names']] # change them, why not
# del raw
types = list()
for ci in range(102):
types.extend(('grad', 'grad', 'mag'))
types.extend(['stim'] * 9)
types.extend(['eeg'] * 60)
# wrong length
assert_raises(ValueError, create_info, ch_names, sfreq, types)
# bad entry
types.append('foo')
assert_raises(KeyError, create_info, ch_names, sfreq, types)
types[-1] = 'eog'
# default type
info = create_info(ch_names, sfreq)
assert_equal(info['chs'][0]['kind'], _kind_dict['misc'][0])
# use real types
info = create_info(ch_names, sfreq, types)
raw2 = _test_raw_reader(RawArray, test_preloading=False,
data=data, info=info)
data2, times2 = raw2[:, :]
assert_allclose(data, data2)
assert_allclose(times, times2)
assert_true('RawArray' in repr(raw2))
# filtering
picks = pick_types(raw2.info, misc=True, exclude='bads')[:4]
assert_equal(len(picks), 4)
raw_lp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_lp.filter(0., 4.0 - 0.25, picks=picks, n_jobs=2)
raw_hp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_hp.filter(8.0 + 0.25, None, picks=picks, n_jobs=2)
raw_bp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_bp.filter(4.0 + 0.25, 8.0 - 0.25, picks=picks)
raw_bs = raw2.copy()
with warnings.catch_warnings(record=True):
raw_bs.filter(8.0 + 0.25, 4.0 - 0.25, picks=picks, n_jobs=2)
data, _ = raw2[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
bs_data, _ = raw_bs[picks, :]
sig_dec = 11
assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec)
assert_array_almost_equal(data, bp_data + bs_data, sig_dec)
# plotting
raw2.plot()
raw2.plot_psd()
plt.close('all')
# epoching
events = find_events(raw2, stim_channel='STI 014')
events[:, 2] = 1
assert_true(len(events) > 2)
epochs = Epochs(raw2, events, 1, -0.2, 0.4, preload=True)
epochs.plot_drop_log()
with warnings.catch_warnings(record=True): # deprecation
warnings.simplefilter('always')
epochs.plot()
evoked = epochs.average()
evoked.plot()
plt.close('all')
示例2: Epochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
###############################################################################
# Read in raw data and prepare for epoching
raw_fname = op.join(study_path, 'ds117', subject, 'MEG', 'run_01_sss.fif')
raw = mne.io.read_raw_fif(raw_fname, preload=True, add_eeg_ref=False)
picks = mne.pick_types(raw.info, meg=True, exclude='bads')
events = mne.find_events(raw, stim_channel='STI101', consecutive='increasing',
mask=4352, mask_type='not_and', min_duration=0.003,
verbose=True)
###############################################################################
# First, we don't highpass filter and only baseline. Note how it creates a
# spatially varying distortation of the time-domain signal in the form
# of "fanning"
raw.filter(None, 40, **filter_params)
evoked = Epochs(raw, events, event_id=event_ids, picks=picks,
baseline=(None, 0)).average()
evoked.plot()
evoked.plot_topomap()
###############################################################################
# Next, we highpass filter (but no lowpass filter as we have already done it)
# but don't baseline. Now, the late effects in the topography are no longer
# visible and the "fanning" has disappeared.
raw.filter(1, None, l_trans_bandwidth=0.5, **filter_params)
evoked = Epochs(raw, events, event_id=event_ids, picks=picks,
baseline=None).average()
evoked.plot()
evoked.plot_topomap()
示例3: test_array
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
def test_array():
"""Test creating raw from array
"""
# creating
raw = Raw(fif_fname).crop(2, 5, copy=False)
data, times = raw[:, :]
sfreq = raw.info['sfreq']
ch_names = [(ch[4:] if 'STI' not in ch else ch)
for ch in raw.info['ch_names']] # change them, why not
#del raw
types = list()
for ci in range(102):
types.extend(('grad', 'grad', 'mag'))
types.extend(['stim'] * 9)
types.extend(['eeg'] * 60)
# wrong length
assert_raises(ValueError, create_info, ch_names, sfreq, types)
# bad entry
types.append('foo')
assert_raises(KeyError, create_info, ch_names, sfreq, types)
types[-1] = 'eog'
info = create_info(ch_names, sfreq, types)
raw2 = RawArray(data, info)
data2, times2 = raw2[:, :]
assert_allclose(data, data2)
assert_allclose(times, times2)
# saving
temp_fname = op.join(tempdir, 'raw.fif')
raw2.save(temp_fname)
raw3 = Raw(temp_fname)
data3, times3 = raw3[:, :]
assert_allclose(data, data3)
assert_allclose(times, times3)
# filtering
picks = pick_types(raw2.info, misc=True, exclude='bads')[:4]
assert_equal(len(picks), 4)
raw_lp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_lp.filter(0., 4.0 - 0.25, picks=picks, n_jobs=2)
raw_hp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_hp.filter(8.0 + 0.25, None, picks=picks, n_jobs=2)
raw_bp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_bp.filter(4.0 + 0.25, 8.0 - 0.25, picks=picks)
raw_bs = raw2.copy()
with warnings.catch_warnings(record=True):
raw_bs.filter(8.0 + 0.25, 4.0 - 0.25, picks=picks, n_jobs=2)
data, _ = raw2[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
bs_data, _ = raw_bs[picks, :]
sig_dec = 11
assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec)
assert_array_almost_equal(data, bp_data + bs_data, sig_dec)
# plotting
import matplotlib
matplotlib.use('Agg') # for testing don't use X server
raw2.plot()
raw2.plot_psds()
# epoching
events = find_events(raw2, stim_channel='STI 014')
events[:, 2] = 1
assert_true(len(events) > 2)
epochs = Epochs(raw2, events, 1, -0.2, 0.4, preload=True)
epochs.plot_drop_log()
epochs.plot()
evoked = epochs.average()
evoked.plot()
示例4: test_array_raw
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
def test_array_raw():
"""Test creating raw from array
"""
import matplotlib.pyplot as plt
# creating
raw = read_raw_fif(fif_fname).crop(2, 5)
data, times = raw[:, :]
sfreq = raw.info["sfreq"]
ch_names = [(ch[4:] if "STI" not in ch else ch) for ch in raw.info["ch_names"]] # change them, why not
# del raw
types = list()
for ci in range(101):
types.extend(("grad", "grad", "mag"))
types.extend(["ecog", "seeg", "hbo"]) # really 3 meg channels
types.extend(["stim"] * 9)
types.extend(["eeg"] * 60)
# wrong length
assert_raises(ValueError, create_info, ch_names, sfreq, types)
# bad entry
types.append("foo")
assert_raises(KeyError, create_info, ch_names, sfreq, types)
types[-1] = "eog"
# default type
info = create_info(ch_names, sfreq)
assert_equal(info["chs"][0]["kind"], _kind_dict["misc"][0])
# use real types
info = create_info(ch_names, sfreq, types)
raw2 = _test_raw_reader(RawArray, test_preloading=False, data=data, info=info, first_samp=2 * data.shape[1])
data2, times2 = raw2[:, :]
assert_allclose(data, data2)
assert_allclose(times, times2)
assert_true("RawArray" in repr(raw2))
assert_raises(TypeError, RawArray, info, data)
# filtering
picks = pick_types(raw2.info, misc=True, exclude="bads")[:4]
assert_equal(len(picks), 4)
raw_lp = raw2.copy()
raw_lp.filter(
None,
4.0,
h_trans_bandwidth=4.0,
filter_length="auto",
picks=picks,
n_jobs=2,
phase="zero",
fir_window="hamming",
)
raw_hp = raw2.copy()
raw_hp.filter(
16.0,
None,
l_trans_bandwidth=4.0,
filter_length="auto",
picks=picks,
n_jobs=2,
phase="zero",
fir_window="hamming",
)
raw_bp = raw2.copy()
raw_bp.filter(
8.0,
12.0,
l_trans_bandwidth=4.0,
h_trans_bandwidth=4.0,
filter_length="auto",
picks=picks,
phase="zero",
fir_window="hamming",
)
raw_bs = raw2.copy()
raw_bs.filter(
16.0,
4.0,
l_trans_bandwidth=4.0,
h_trans_bandwidth=4.0,
filter_length="auto",
picks=picks,
n_jobs=2,
phase="zero",
fir_window="hamming",
)
data, _ = raw2[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
bs_data, _ = raw_bs[picks, :]
sig_dec = 15
assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec)
assert_array_almost_equal(data, bp_data + bs_data, sig_dec)
# plotting
raw2.plot()
raw2.plot_psd(tmax=np.inf)
plt.close("all")
# epoching
events = find_events(raw2, stim_channel="STI 014")
events[:, 2] = 1
#.........这里部分代码省略.........
示例5: test_array_raw
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
def test_array_raw():
"""Test creating raw from array."""
import matplotlib.pyplot as plt
# creating
raw = read_raw_fif(fif_fname).crop(2, 5)
data, times = raw[:, :]
sfreq = raw.info['sfreq']
ch_names = [(ch[4:] if 'STI' not in ch else ch)
for ch in raw.info['ch_names']] # change them, why not
# del raw
types = list()
for ci in range(101):
types.extend(('grad', 'grad', 'mag'))
types.extend(['ecog', 'seeg', 'hbo']) # really 3 meg channels
types.extend(['stim'] * 9)
types.extend(['eeg'] * 60)
# wrong length
assert_raises(ValueError, create_info, ch_names, sfreq, types)
# bad entry
types.append('foo')
assert_raises(KeyError, create_info, ch_names, sfreq, types)
types[-1] = 'eog'
# default type
info = create_info(ch_names, sfreq)
assert_equal(info['chs'][0]['kind'], _kind_dict['misc'][0])
# use real types
info = create_info(ch_names, sfreq, types)
raw2 = _test_raw_reader(RawArray, test_preloading=False,
data=data, info=info, first_samp=2 * data.shape[1])
data2, times2 = raw2[:, :]
assert_allclose(data, data2)
assert_allclose(times, times2)
assert_true('RawArray' in repr(raw2))
assert_raises(TypeError, RawArray, info, data)
# filtering
picks = pick_types(raw2.info, misc=True, exclude='bads')[:4]
assert_equal(len(picks), 4)
raw_lp = raw2.copy()
kwargs = dict(fir_design='firwin', picks=picks)
raw_lp.filter(None, 4.0, h_trans_bandwidth=4., n_jobs=2, **kwargs)
raw_hp = raw2.copy()
raw_hp.filter(16.0, None, l_trans_bandwidth=4., n_jobs=2, **kwargs)
raw_bp = raw2.copy()
raw_bp.filter(8.0, 12.0, l_trans_bandwidth=4., h_trans_bandwidth=4.,
**kwargs)
raw_bs = raw2.copy()
raw_bs.filter(16.0, 4.0, l_trans_bandwidth=4., h_trans_bandwidth=4.,
n_jobs=2, **kwargs)
data, _ = raw2[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
bs_data, _ = raw_bs[picks, :]
sig_dec = 15
assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec)
assert_array_almost_equal(data, bp_data + bs_data, sig_dec)
# plotting
raw2.plot()
raw2.plot_psd(tmax=np.inf, average=True, n_fft=1024, spatial_colors=False)
plt.close('all')
# epoching
events = find_events(raw2, stim_channel='STI 014')
events[:, 2] = 1
assert_true(len(events) > 2)
epochs = Epochs(raw2, events, 1, -0.2, 0.4, preload=True)
epochs.plot_drop_log()
epochs.plot()
evoked = epochs.average()
evoked.plot(time_unit='s')
assert_equal(evoked.nave, len(events) - 1)
plt.close('all')
# complex data
rng = np.random.RandomState(0)
data = rng.randn(1, 100) + 1j * rng.randn(1, 100)
raw = RawArray(data, create_info(1, 1000., 'eeg'))
assert_allclose(raw._data, data)
# Using digital montage to give MNI electrode coordinates
n_elec = 10
ts_size = 10000
Fs = 512.
elec_labels = [str(i) for i in range(n_elec)]
elec_coords = np.random.randint(60, size=(n_elec, 3)).tolist()
electrode = np.random.rand(n_elec, ts_size)
dig_ch_pos = dict(zip(elec_labels, elec_coords))
mon = channels.DigMontage(dig_ch_pos=dig_ch_pos)
info = create_info(elec_labels, Fs, 'ecog', montage=mon)
raw = RawArray(electrode, info)
raw.plot_psd(average=False) # looking for inexistent layout
raw.plot_psd_topo()
示例6: test_array_raw
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
def test_array_raw():
"""Test creating raw from array
"""
import matplotlib.pyplot as plt
# creating
raw = read_raw_fif(fif_fname, add_eeg_ref=False).crop(2, 5)
data, times = raw[:, :]
sfreq = raw.info['sfreq']
ch_names = [(ch[4:] if 'STI' not in ch else ch)
for ch in raw.info['ch_names']] # change them, why not
# del raw
types = list()
for ci in range(101):
types.extend(('grad', 'grad', 'mag'))
types.extend(['ecog', 'seeg', 'hbo']) # really 3 meg channels
types.extend(['stim'] * 9)
types.extend(['eeg'] * 60)
# wrong length
assert_raises(ValueError, create_info, ch_names, sfreq, types)
# bad entry
types.append('foo')
assert_raises(KeyError, create_info, ch_names, sfreq, types)
types[-1] = 'eog'
# default type
info = create_info(ch_names, sfreq)
assert_equal(info['chs'][0]['kind'], _kind_dict['misc'][0])
# use real types
info = create_info(ch_names, sfreq, types)
raw2 = _test_raw_reader(RawArray, test_preloading=False,
data=data, info=info, first_samp=2 * data.shape[1])
data2, times2 = raw2[:, :]
assert_allclose(data, data2)
assert_allclose(times, times2)
assert_true('RawArray' in repr(raw2))
assert_raises(TypeError, RawArray, info, data)
# filtering
picks = pick_types(raw2.info, misc=True, exclude='bads')[:4]
assert_equal(len(picks), 4)
raw_lp = raw2.copy()
raw_lp.filter(None, 4.0, h_trans_bandwidth=4.,
filter_length='auto', picks=picks, n_jobs=2, phase='zero',
fir_window='hamming')
raw_hp = raw2.copy()
raw_hp.filter(16.0, None, l_trans_bandwidth=4.,
filter_length='auto', picks=picks, n_jobs=2, phase='zero',
fir_window='hamming')
raw_bp = raw2.copy()
raw_bp.filter(8.0, 12.0, l_trans_bandwidth=4.,
h_trans_bandwidth=4., filter_length='auto', picks=picks,
phase='zero', fir_window='hamming')
raw_bs = raw2.copy()
raw_bs.filter(16.0, 4.0, l_trans_bandwidth=4., h_trans_bandwidth=4.,
filter_length='auto', picks=picks, n_jobs=2, phase='zero',
fir_window='hamming')
data, _ = raw2[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
bs_data, _ = raw_bs[picks, :]
sig_dec = 15
assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec)
assert_array_almost_equal(data, bp_data + bs_data, sig_dec)
# plotting
raw2.plot()
raw2.plot_psd()
plt.close('all')
# epoching
events = find_events(raw2, stim_channel='STI 014')
events[:, 2] = 1
assert_true(len(events) > 2)
epochs = Epochs(raw2, events, 1, -0.2, 0.4, preload=True,
add_eeg_ref=False)
epochs.plot_drop_log()
epochs.plot()
evoked = epochs.average()
evoked.plot()
assert_equal(evoked.nave, len(events) - 1)
plt.close('all')
# complex data
rng = np.random.RandomState(0)
data = rng.randn(1, 100) + 1j * rng.randn(1, 100)
raw = RawArray(data, create_info(1, 1000., 'eeg'))
assert_allclose(raw._data, data)
示例7: test_array_raw
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
def test_array_raw():
"""Test creating raw from array
"""
import matplotlib.pyplot as plt
# creating
raw = Raw(fif_fname).crop(2, 5, copy=False)
data, times = raw[:, :]
sfreq = raw.info["sfreq"]
ch_names = [(ch[4:] if "STI" not in ch else ch) for ch in raw.info["ch_names"]] # change them, why not
# del raw
types = list()
for ci in range(102):
types.extend(("grad", "grad", "mag"))
types.extend(["stim"] * 9)
types.extend(["eeg"] * 60)
# wrong length
assert_raises(ValueError, create_info, ch_names, sfreq, types)
# bad entry
types.append("foo")
assert_raises(KeyError, create_info, ch_names, sfreq, types)
types[-1] = "eog"
# default type
info = create_info(ch_names, sfreq)
assert_equal(info["chs"][0]["kind"], _kind_dict["misc"][0])
# use real types
info = create_info(ch_names, sfreq, types)
raw2 = _test_raw_reader(RawArray, test_preloading=False, data=data, info=info)
data2, times2 = raw2[:, :]
assert_allclose(data, data2)
assert_allclose(times, times2)
assert_true("RawArray" in repr(raw2))
# filtering
picks = pick_types(raw2.info, misc=True, exclude="bads")[:4]
assert_equal(len(picks), 4)
raw_lp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_lp.filter(0.0, 4.0 - 0.25, picks=picks, n_jobs=2)
raw_hp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_hp.filter(8.0 + 0.25, None, picks=picks, n_jobs=2)
raw_bp = raw2.copy()
with warnings.catch_warnings(record=True):
raw_bp.filter(4.0 + 0.25, 8.0 - 0.25, picks=picks)
raw_bs = raw2.copy()
with warnings.catch_warnings(record=True):
raw_bs.filter(8.0 + 0.25, 4.0 - 0.25, picks=picks, n_jobs=2)
data, _ = raw2[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
bs_data, _ = raw_bs[picks, :]
sig_dec = 11
assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec)
assert_array_almost_equal(data, bp_data + bs_data, sig_dec)
# plotting
raw2.plot()
raw2.plot_psd()
plt.close("all")
# epoching
events = find_events(raw2, stim_channel="STI 014")
events[:, 2] = 1
assert_true(len(events) > 2)
epochs = Epochs(raw2, events, 1, -0.2, 0.4, preload=True)
epochs.plot_drop_log()
epochs.plot()
evoked = epochs.average()
evoked.plot()
plt.close("all")
示例8: Epochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import plot [as 别名]
verbose=True)
evoked_before = Epochs(raw, events, event_id=event_ids, picks=picks).average()
###############################################################################
# Then Maxfiltered and SSS'd data.
raw = mne.io.read_raw_fif(raw_fname_in, preload=True, add_eeg_ref=False)
raw_sss = mne.io.read_raw_fif(sss_fname_in, preload=True, add_eeg_ref=False)
raw.info['bads'] = bads
raw_sss.info['bads'] = bads
raw = maxwell_filter(raw, calibration=cal, cross_talk=ctc)
raw.filter(1, 40, **filter_params)
raw_sss.filter(1, 40, **filter_params)
evoked_after = Epochs(raw, events, event_id=event_ids, picks=picks).average()
evoked_sss = Epochs(raw_sss, events, event_id=event_ids, picks=picks).average()
###############################################################################
# Plotting
ylim = dict(grad=(-100, 100), mag=(-400, 400))
evoked_before.plot(spatial_colors=True, ylim=ylim,
titles={'grad': 'Gradiometers before SSS',
'mag': 'Magnetometers before SSS'})
evoked_after.plot(spatial_colors=True, ylim=ylim,
titles={'grad': 'SSS gradiometers',
'mag': 'SSS magnetometers'})
evoked_sss.plot(spatial_colors=True, ylim=ylim,
titles={'grad': 'Maxfilter (TM) gradiometers',
'mag': 'Maxfilter (TM) magnetometers'})