本文整理汇总了Python中mne.fixes.in1d函数的典型用法代码示例。如果您正苦于以下问题:Python in1d函数的具体用法?Python in1d怎么用?Python in1d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了in1d函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_label_in_src
def test_label_in_src():
"""Test label in src"""
src = read_source_spaces(src_fname)
label = read_label(v1_label_fname)
# construct label from source space vertices
vert_in_src = np.intersect1d(label.vertices, src[0]['vertno'], True)
where = in1d(label.vertices, vert_in_src)
pos_in_src = label.pos[where]
values_in_src = label.values[where]
label_src = Label(vert_in_src, pos_in_src, values_in_src,
hemi='lh').fill(src)
# check label vertices
vertices_status = in1d(src[0]['nearest'], label.vertices)
vertices_in = np.nonzero(vertices_status)[0]
vertices_out = np.nonzero(np.logical_not(vertices_status))[0]
assert_array_equal(label_src.vertices, vertices_in)
assert_array_equal(in1d(vertices_out, label_src.vertices), False)
# check values
value_idx = digitize(src[0]['nearest'][vertices_in], vert_in_src, True)
assert_array_equal(label_src.values, values_in_src[value_idx])
# test exception
vertices = np.append([-1], vert_in_src)
assert_raises(ValueError, Label(vertices, hemi='lh').fill, src)
开发者ID:kingjr,项目名称:decoding_challenge_cortana_2016_3rd,代码行数:27,代码来源:test_label.py
示例2: test_morph
def test_morph():
"""Test inter-subject label morphing
"""
label_orig = read_label(real_label_fname)
label_orig.subject = 'sample'
# should work for specifying vertices for both hemis, or just the
# hemi of the given label
vals = list()
for grade in [5, [np.arange(10242), np.arange(10242)], np.arange(10242)]:
label = label_orig.copy()
# this should throw an error because the label has all zero values
assert_raises(ValueError, label.morph, 'sample', 'fsaverage')
label.values.fill(1)
label = label.morph(None, 'fsaverage', 5, grade, subjects_dir, 1)
label = label.morph('fsaverage', 'sample', 5, None, subjects_dir, 2)
assert_true(np.mean(in1d(label_orig.vertices, label.vertices)) == 1.0)
assert_true(len(label.vertices) < 3 * len(label_orig.vertices))
vals.append(label.vertices)
assert_array_equal(vals[0], vals[1])
# make sure label smoothing can run
assert_equal(label.subject, 'sample')
verts = [np.arange(10242), np.arange(10242)]
for hemi in ['lh', 'rh']:
label.hemi = hemi
label.morph(None, 'fsaverage', 5, verts, subjects_dir, 2)
assert_raises(TypeError, label.morph, None, 1, 5, verts,
subjects_dir, 2)
assert_raises(TypeError, label.morph, None, 'fsaverage', 5.5, verts,
subjects_dir, 2)
with warnings.catch_warnings(record=True): # morph map could be missing
label.smooth(subjects_dir=subjects_dir) # make sure this runs
开发者ID:kingjr,项目名称:decoding_challenge_cortana_2016_3rd,代码行数:31,代码来源:test_label.py
示例3: test_morph
def test_morph():
"""Test inter-subject label morphing
"""
label_orig = read_label(real_label_fname)
label_orig.subject = 'sample'
# should work for specifying vertices for both hemis, or just the
# hemi of the given label
vals = list()
for grade in [5, [np.arange(10242), np.arange(10242)], np.arange(10242)]:
label = label_orig.copy()
# this should throw an error because the label has all zero values
assert_raises(ValueError, label.morph, 'sample', 'fsaverage')
label.values.fill(1)
label.morph(None, 'fsaverage', 5, grade, subjects_dir, 2,
copy=False)
label.morph('fsaverage', 'sample', 5, None, subjects_dir, 2,
copy=False)
assert_true(np.mean(in1d(label_orig.vertices, label.vertices)) == 1.0)
assert_true(len(label.vertices) < 3 * len(label_orig.vertices))
vals.append(label.vertices)
assert_array_equal(vals[0], vals[1])
# make sure label smoothing can run
label.morph(label.subject, 'fsaverage', 5,
[np.arange(10242), np.arange(10242)], subjects_dir, 2,
copy=False)
# subject name should be inferred now
label.smooth(subjects_dir=subjects_dir)
开发者ID:Anevar,项目名称:mne-python,代码行数:27,代码来源:test_label.py
示例4: test_morph
def test_morph():
"""Test inter-subject label morphing
"""
label_orig = read_label(real_label_fname)
label_orig.subject = "sample"
# should work for specifying vertices for both hemis, or just the
# hemi of the given label
vals = list()
for grade in [5, [np.arange(10242), np.arange(10242)], np.arange(10242)]:
label = label_orig.copy()
# this should throw an error because the label has all zero values
assert_raises(ValueError, label.morph, "sample", "fsaverage")
label.values.fill(1)
label.morph(None, "fsaverage", 5, grade, subjects_dir, 1, copy=False)
label.morph("fsaverage", "sample", 5, None, subjects_dir, 2, copy=False)
assert_true(np.mean(in1d(label_orig.vertices, label.vertices)) == 1.0)
assert_true(len(label.vertices) < 3 * len(label_orig.vertices))
vals.append(label.vertices)
assert_array_equal(vals[0], vals[1])
# make sure label smoothing can run
assert_equal(label.subject, "sample")
verts = [np.arange(10242), np.arange(10242)]
for hemi in ["lh", "rh"]:
label.hemi = hemi
label.morph(None, "fsaverage", 5, verts, subjects_dir, 2)
assert_raises(TypeError, label.morph, None, 1, 5, verts, subjects_dir, 2)
assert_raises(TypeError, label.morph, None, "fsaverage", 5.5, verts, subjects_dir, 2)
label.smooth(subjects_dir=subjects_dir) # make sure this runs
开发者ID:YoheiOseki,项目名称:mne-python,代码行数:28,代码来源:test_label.py
示例5: test_grow_labels
def test_grow_labels():
"""Test generation of circular source labels"""
seeds = [0, 50000]
# these were chosen manually in mne_analyze
should_be_in = [[49, 227], [51207, 48794]]
hemis = [0, 1]
labels = grow_labels('sample', seeds, 3, hemis, subjects_dir, n_jobs=2)
for label, seed, hemi, sh in zip(labels, seeds, hemis, should_be_in):
assert_true(np.any(label.vertices == seed))
assert_true(np.all(in1d(sh, label.vertices)))
if hemi == 0:
assert_equal(label.hemi, 'lh')
else:
assert_equal(label.hemi, 'rh')
开发者ID:Anevar,项目名称:mne-python,代码行数:15,代码来源:test_label.py
示例6: test_grow_labels
def test_grow_labels():
"""Test generation of circular source labels"""
seeds = [0, 50000]
# these were chosen manually in mne_analyze
should_be_in = [[49, 227], [51207, 48794]]
hemis = [0, 1]
names = ['aneurism', 'tumor']
labels = grow_labels('sample', seeds, 3, hemis, subjects_dir, n_jobs=2,
names=names)
tgt_names = ['aneurism-lh', 'tumor-rh']
tgt_hemis = ['lh', 'rh']
for label, seed, hemi, sh, name in zip(labels, seeds, tgt_hemis,
should_be_in, tgt_names):
assert_true(np.any(label.vertices == seed))
assert_true(np.all(in1d(sh, label.vertices)))
assert_equal(label.hemi, hemi)
assert_equal(label.name, name)
# grow labels with and without overlap
seeds = [57532, [58887, 6304]]
l01, l02 = grow_labels('fsaverage', seeds, 20, [0, 0], subjects_dir)
seeds = [57532, [58887, 6304]]
l11, l12 = grow_labels('fsaverage', seeds, 20, [0, 0], subjects_dir,
overlap=False)
# test label naming
assert_equal(l01.name, 'Label_0-lh')
assert_equal(l02.name, 'Label_1-lh')
assert_equal(l11.name, 'Label_0-lh')
assert_equal(l12.name, 'Label_1-lh')
# make sure set 1 does not overlap
overlap = np.intersect1d(l11.vertices, l12.vertices, True)
assert_array_equal(overlap, [])
# make sure both sets cover the same vertices
l0 = l01 + l02
l1 = l11 + l12
assert_array_equal(l1.vertices, l0.vertices)
开发者ID:anywave,项目名称:aw-export-fif,代码行数:40,代码来源:test_label.py
示例7: test_write_labels_to_annot
#.........这里部分代码省略.........
write_labels_to_annot([label], 'sample', 'test2', subjects_dir=tempdir)
assert_true(op.exists(dst % ('lh', 'test2')))
assert_true(op.exists(dst % ('rh', 'test2')))
# rh only
for label in labels:
if label.hemi == 'rh':
break
write_labels_to_annot([label], 'sample', 'test3', subjects_dir=tempdir)
assert_true(op.exists(dst % ('lh', 'test3')))
assert_true(op.exists(dst % ('rh', 'test3')))
# label alone
assert_raises(TypeError, write_labels_to_annot, labels[0], 'sample',
'test4', subjects_dir=tempdir)
# write left and right hemi labels with filenames:
fnames = [op.join(tempdir, hemi + '-myparc') for hemi in ['lh', 'rh']]
with warnings.catch_warnings(record=True): # specify subject_dir param
for fname in fnames:
write_labels_to_annot(labels, annot_fname=fname)
# read it back
labels2 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[0])
labels22 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[1])
labels2.extend(labels22)
names = [label.name for label in labels2]
for label in labels:
idx = names.index(label.name)
assert_labels_equal(label, labels2[idx])
# same with label-internal colors
for fname in fnames:
write_labels_to_annot(labels, 'sample', annot_fname=fname,
overwrite=True, subjects_dir=subjects_dir)
labels3 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[0])
labels33 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[1])
labels3.extend(labels33)
names3 = [label.name for label in labels3]
for label in labels:
idx = names3.index(label.name)
assert_labels_equal(label, labels3[idx])
# make sure we can't overwrite things
assert_raises(ValueError, write_labels_to_annot, labels, 'sample',
annot_fname=fnames[0], subjects_dir=subjects_dir)
# however, this works
write_labels_to_annot(labels, 'sample', annot_fname=fnames[0],
overwrite=True, subjects_dir=subjects_dir)
# label without color
labels_ = labels[:]
labels_[0] = labels_[0].copy()
labels_[0].color = None
write_labels_to_annot(labels_, 'sample', annot_fname=fnames[0],
overwrite=True, subjects_dir=subjects_dir)
# duplicate color
labels_[0].color = labels_[2].color
assert_raises(ValueError, write_labels_to_annot, labels_, 'sample',
annot_fname=fnames[0], overwrite=True,
subjects_dir=subjects_dir)
# invalid color inputs
labels_[0].color = (1.1, 1., 1., 1.)
assert_raises(ValueError, write_labels_to_annot, labels_, 'sample',
annot_fname=fnames[0], overwrite=True,
subjects_dir=subjects_dir)
# overlapping labels
labels_ = labels[:]
cuneus_lh = labels[6]
precuneus_lh = labels[50]
labels_.append(precuneus_lh + cuneus_lh)
assert_raises(ValueError, write_labels_to_annot, labels_, 'sample',
annot_fname=fnames[0], overwrite=True,
subjects_dir=subjects_dir)
# unlabeled vertices
labels_lh = [label for label in labels if label.name.endswith('lh')]
write_labels_to_annot(labels_lh[1:], 'sample', annot_fname=fnames[0],
overwrite=True, subjects_dir=subjects_dir)
labels_reloaded = read_labels_from_annot('sample', annot_fname=fnames[0],
subjects_dir=subjects_dir)
assert_equal(len(labels_lh), len(labels_reloaded))
label0 = labels_lh[0]
label1 = labels_reloaded[-1]
assert_equal(label1.name, "unknown-lh")
assert_true(np.all(in1d(label0.vertices, label1.vertices)))
# unnamed labels
labels4 = labels[:]
labels4[0].name = None
assert_raises(ValueError, write_labels_to_annot, labels4,
annot_fname=fnames[0])
开发者ID:kingjr,项目名称:decoding_challenge_cortana_2016_3rd,代码行数:101,代码来源:test_label.py
示例8: test_write_labels_to_annot
def test_write_labels_to_annot():
"""Test writing FreeSurfer parcellation from labels"""
tempdir = _TempDir()
labels = read_labels_from_annot('sample', subjects_dir=subjects_dir)
# write left and right hemi labels:
fnames = ['%s/%s-myparc' % (tempdir, hemi) for hemi in ['lh', 'rh']]
for fname in fnames:
write_labels_to_annot(labels, annot_fname=fname)
# read it back
labels2 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[0])
labels22 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[1])
labels2.extend(labels22)
names = [label.name for label in labels2]
for label in labels:
idx = names.index(label.name)
assert_labels_equal(label, labels2[idx])
# same with label-internal colors
for fname in fnames:
write_labels_to_annot(labels, annot_fname=fname, overwrite=True)
labels3 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[0])
labels33 = read_labels_from_annot('sample', subjects_dir=subjects_dir,
annot_fname=fnames[1])
labels3.extend(labels33)
names3 = [label.name for label in labels3]
for label in labels:
idx = names3.index(label.name)
assert_labels_equal(label, labels3[idx])
# make sure we can't overwrite things
assert_raises(ValueError, write_labels_to_annot, labels,
annot_fname=fnames[0])
# however, this works
write_labels_to_annot(labels, annot_fname=fnames[0], overwrite=True)
# label without color
labels_ = labels[:]
labels_[0] = labels_[0].copy()
labels_[0].color = None
write_labels_to_annot(labels_, annot_fname=fnames[0], overwrite=True)
# duplicate color
labels_[0].color = labels_[2].color
assert_raises(ValueError, write_labels_to_annot, labels_,
annot_fname=fnames[0], overwrite=True)
# invalid color inputs
labels_[0].color = (1.1, 1., 1., 1.)
assert_raises(ValueError, write_labels_to_annot, labels_,
annot_fname=fnames[0], overwrite=True)
# overlapping labels
labels_ = labels[:]
cuneus_lh = labels[6]
precuneus_lh = labels[50]
labels_.append(precuneus_lh + cuneus_lh)
assert_raises(ValueError, write_labels_to_annot, labels_,
annot_fname=fnames[0], overwrite=True)
# unlabeled vertices
labels_lh = [label for label in labels if label.name.endswith('lh')]
write_labels_to_annot(labels_lh[1:], 'sample', annot_fname=fnames[0],
overwrite=True, subjects_dir=subjects_dir)
labels_reloaded = read_labels_from_annot('sample', annot_fname=fnames[0],
subjects_dir=subjects_dir)
assert_equal(len(labels_lh), len(labels_reloaded))
label0 = labels_lh[0]
label1 = labels_reloaded[-1]
assert_equal(label1.name, "unknown-lh")
assert_true(np.all(in1d(label0.vertices, label1.vertices)))
开发者ID:XristosK,项目名称:mne-python,代码行数:80,代码来源:test_label.py
示例9: test_write_labels_to_annot
def test_write_labels_to_annot():
"""Test writing FreeSurfer parcellation from labels"""
tempdir = _TempDir()
labels = read_labels_from_annot("sample", subjects_dir=subjects_dir)
# create temporary subjects-dir skeleton
surf_dir = op.join(subjects_dir, "sample", "surf")
temp_surf_dir = op.join(tempdir, "sample", "surf")
os.makedirs(temp_surf_dir)
shutil.copy(op.join(surf_dir, "lh.white"), temp_surf_dir)
shutil.copy(op.join(surf_dir, "rh.white"), temp_surf_dir)
os.makedirs(op.join(tempdir, "sample", "label"))
# test automatic filenames
dst = op.join(tempdir, "sample", "label", "%s.%s.annot")
write_labels_to_annot(labels, "sample", "test1", subjects_dir=tempdir)
assert_true(op.exists(dst % ("lh", "test1")))
assert_true(op.exists(dst % ("rh", "test1")))
# lh only
for label in labels:
if label.hemi == "lh":
break
write_labels_to_annot([label], "sample", "test2", subjects_dir=tempdir)
assert_true(op.exists(dst % ("lh", "test2")))
assert_true(op.exists(dst % ("rh", "test2")))
# rh only
for label in labels:
if label.hemi == "rh":
break
write_labels_to_annot([label], "sample", "test3", subjects_dir=tempdir)
assert_true(op.exists(dst % ("lh", "test3")))
assert_true(op.exists(dst % ("rh", "test3")))
# label alone
assert_raises(TypeError, write_labels_to_annot, labels[0], "sample", "test4", subjects_dir=tempdir)
# write left and right hemi labels with filenames:
fnames = ["%s/%s-myparc" % (tempdir, hemi) for hemi in ["lh", "rh"]]
for fname in fnames:
write_labels_to_annot(labels, annot_fname=fname)
# read it back
labels2 = read_labels_from_annot("sample", subjects_dir=subjects_dir, annot_fname=fnames[0])
labels22 = read_labels_from_annot("sample", subjects_dir=subjects_dir, annot_fname=fnames[1])
labels2.extend(labels22)
names = [label.name for label in labels2]
for label in labels:
idx = names.index(label.name)
assert_labels_equal(label, labels2[idx])
# same with label-internal colors
for fname in fnames:
write_labels_to_annot(labels, annot_fname=fname, overwrite=True)
labels3 = read_labels_from_annot("sample", subjects_dir=subjects_dir, annot_fname=fnames[0])
labels33 = read_labels_from_annot("sample", subjects_dir=subjects_dir, annot_fname=fnames[1])
labels3.extend(labels33)
names3 = [label.name for label in labels3]
for label in labels:
idx = names3.index(label.name)
assert_labels_equal(label, labels3[idx])
# make sure we can't overwrite things
assert_raises(ValueError, write_labels_to_annot, labels, annot_fname=fnames[0])
# however, this works
write_labels_to_annot(labels, annot_fname=fnames[0], overwrite=True)
# label without color
labels_ = labels[:]
labels_[0] = labels_[0].copy()
labels_[0].color = None
write_labels_to_annot(labels_, annot_fname=fnames[0], overwrite=True)
# duplicate color
labels_[0].color = labels_[2].color
assert_raises(ValueError, write_labels_to_annot, labels_, annot_fname=fnames[0], overwrite=True)
# invalid color inputs
labels_[0].color = (1.1, 1.0, 1.0, 1.0)
assert_raises(ValueError, write_labels_to_annot, labels_, annot_fname=fnames[0], overwrite=True)
# overlapping labels
labels_ = labels[:]
cuneus_lh = labels[6]
precuneus_lh = labels[50]
labels_.append(precuneus_lh + cuneus_lh)
assert_raises(ValueError, write_labels_to_annot, labels_, annot_fname=fnames[0], overwrite=True)
# unlabeled vertices
labels_lh = [label for label in labels if label.name.endswith("lh")]
write_labels_to_annot(labels_lh[1:], "sample", annot_fname=fnames[0], overwrite=True, subjects_dir=subjects_dir)
labels_reloaded = read_labels_from_annot("sample", annot_fname=fnames[0], subjects_dir=subjects_dir)
assert_equal(len(labels_lh), len(labels_reloaded))
label0 = labels_lh[0]
label1 = labels_reloaded[-1]
assert_equal(label1.name, "unknown-lh")
assert_true(np.all(in1d(label0.vertices, label1.vertices)))
开发者ID:YoheiOseki,项目名称:mne-python,代码行数:99,代码来源:test_label.py
注:本文中的mne.fixes.in1d函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论