本文整理汇总了Python中mne.io.RawArray.pick_types方法的典型用法代码示例。如果您正苦于以下问题:Python RawArray.pick_types方法的具体用法?Python RawArray.pick_types怎么用?Python RawArray.pick_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.RawArray
的用法示例。
在下文中一共展示了RawArray.pick_types方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_picks
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import pick_types [as 别名]
def test_filter_picks():
"""Test filtering default channel picks"""
ch_types = ['mag', 'grad', 'eeg', 'seeg', 'misc', 'stim']
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')
# -- Filter data channels
for ch_type in ('mag', 'grad', 'eeg', 'seeg'):
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.pick_types(copy=True, **picks)
# Avoid RuntimeWarning due to Attenuation
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
raw_.filter(10, 30)
assert_true(len(w) == 1)
# -- Error if no data channel
for ch_type in ('misc', 'stim'):
picks = dict((ch, ch == ch_type) for ch in ch_types)
raw_ = raw.pick_types(copy=True, **picks)
assert_raises(RuntimeError, raw_.filter, 10, 30)
示例2: main
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import pick_types [as 别名]
def main():
print "Using MNE", mne.__version__
opts = parse_args()
verbose = opts.debug
# constants
sfreq = 100.0
class_labels = {'left':2, 'right':3}
# files
train_fname = "data/custom/bci4/train/ds1g.txt"
test_fname = "data/custom/bci4/test/ds1g.txt"
#train_fname = "data/custom/bci4/active_train/ds1b.txt"
#test_fname = "data/custom/bci4/active_test/ds1b.txt"
#################
# LOAD DATA
eval_start = time.clock()
# load train data from training file
[train_nparray, train_info] = file_to_nparray(train_fname, sfreq=sfreq, verbose=verbose)
end = time.clock()
print "train dataset", train_fname, "loaded in ", str(end - eval_start),"seconds"
eval_start = time.clock()
# load test data from test file
[test_nparray, test_info] = file_to_nparray(test_fname, sfreq=sfreq, verbose=verbose)
end = time.clock()
print "test dataset", test_fname, "loaded in ", str(end - eval_start),"seconds"
total_start = time.clock()
##################
# CLASSIFY DATA
# pick a subset of total electrodes, or else just get all of the channels of type 'eeg'
picks = getPicks('motor16') or pick_types(train_info, eeg=True)
# hyperparam 1
bandpass_filters = get_bandpass_ranges()
# hyperparam 2
epoch_bounds = get_window_ranges()
# extract X,y from train data
train_raw = RawArray(train_nparray, train_info, verbose=verbose)
train_events = mne.find_events(train_raw, shortest_event=0, consecutive=True, verbose=verbose)
train_epochs = Epochs(raw=train_raw, events=train_events, event_id=class_labels,
tmin=-0.5, tmax=3.5, proj=False, picks=picks, baseline=None,
preload=True, add_eeg_ref=False, verbose=verbose)
train_X = train_epochs.get_data()
train_y = train_epochs.events[:, -1] - 2 # convert classes [2,3] to [0,1]
# extract X,y from test data
test_raw = RawArray(test_nparray, test_info, verbose=verbose)
test_events = mne.find_events(test_raw, shortest_event=0, consecutive=True, verbose=verbose)
test_epochs = Epochs(raw=test_raw, events=test_events, event_id=class_labels,
tmin=-0.5, tmax=3.5, proj=False, picks=picks, baseline=None,
preload=True, add_eeg_ref=False, verbose=verbose)
test_X = test_epochs.get_data()
test_y = test_epochs.events[:, -1] - 2 # convert classes [2,3] to [0,1]
# custom grid search
estimator = CSPEstimator(bandpass_filters=bandpass_filters,
epoch_bounds=epoch_bounds,
num_spatial_filters=6,
class_labels=class_labels,
sfreq=sfreq,
picks=picks,
num_votes=6,
consecutive=True)
estimator.fit(train_X,train_y)
#
print "-------------------------------------------"
score = estimator.score(test_X,test_y)
print "-------------------------------------------"
print "average estimator score",score
print
# print
print "-------------------------------------------"
print
print "training run time", round(time.clock() - total_start,1),"sec"
#exit()
# just a pause here to allow visual inspection of top classifiers picked by grid search
time.sleep(15)
# now we go into predict mode, in which we are going over the test data using sliding windows
# this is a simulation of what would happen if we were in "online" mode with live data
# for each window, a prediction is given by the ensemble of top classifiers
# next to this, we see the actual labels from the real data (i.e. the y vector)
print "-------------------------------------------"
print "PREDICT"
print
#.........这里部分代码省略.........