本文整理汇总了Python中mne.report.Report.add_slider_to_section方法的典型用法代码示例。如果您正苦于以下问题:Python Report.add_slider_to_section方法的具体用法?Python Report.add_slider_to_section怎么用?Python Report.add_slider_to_section使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.report.Report
的用法示例。
在下文中一共展示了Report.add_slider_to_section方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_slider_to_section
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
def test_add_slider_to_section():
"""Test adding a slider with a series of images to mne report."""
tempdir = _TempDir()
from matplotlib import pyplot as plt
report = Report(info_fname=raw_fname,
subject='sample', subjects_dir=subjects_dir)
section = 'slider_section'
figs = list()
figs.append(plt.figure())
plt.plot([1, 2, 3])
plt.close('all')
figs.append(plt.figure())
plt.plot([3, 2, 1])
plt.close('all')
report.add_slider_to_section(figs, section=section)
report.save(op.join(tempdir, 'report.html'), open_browser=False)
assert_raises(NotImplementedError, report.add_slider_to_section,
[figs, figs])
assert_raises(ValueError, report.add_slider_to_section, figs, ['wug'])
assert_raises(TypeError, report.add_slider_to_section, figs, 'wug')
# need at least 2
assert_raises(ValueError, report.add_slider_to_section, figs[:1], 'wug')
# Smoke test that SVG w/unicode can be added
report = Report()
fig, ax = plt.subplots()
ax.set_xlabel(u'μ')
report.add_slider_to_section([fig] * 2, image_format='svg')
示例2: test_remove
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
def test_remove():
"""Test removing figures from a report."""
r = Report()
fig1, fig2 = _get_example_figures()
r.add_figs_to_section(fig1, 'figure1', 'mysection')
r.add_slider_to_section([fig1, fig2], title='figure1',
section='othersection')
r.add_figs_to_section(fig2, 'figure1', 'mysection')
r.add_figs_to_section(fig2, 'figure2', 'mysection')
# Test removal by caption
r2 = copy.deepcopy(r)
removed_index = r2.remove(caption='figure1')
assert removed_index == 2
assert len(r2.html) == 3
assert r2.html[0] == r.html[0]
assert r2.html[1] == r.html[1]
assert r2.html[2] == r.html[3]
# Test restricting to section
r2 = copy.deepcopy(r)
removed_index = r2.remove(caption='figure1', section='othersection')
assert removed_index == 1
assert len(r2.html) == 3
assert r2.html[0] == r.html[0]
assert r2.html[1] == r.html[2]
assert r2.html[2] == r.html[3]
# Test removal of empty sections
r2 = copy.deepcopy(r)
r2.remove(caption='figure1', section='othersection')
assert r2.sections == ['mysection']
assert r2._sectionvars == {'mysection': 'report_mysection'}
示例3: test_add_slider_to_section
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
def test_add_slider_to_section():
"""Test adding a slider with a series of images to mne report."""
tempdir = _TempDir()
from matplotlib import pyplot as plt
report = Report(info_fname=raw_fname,
subject='sample', subjects_dir=subjects_dir)
section = 'slider_section'
figs = list()
figs.append(plt.figure())
plt.plot([1, 2, 3])
plt.close('all')
figs.append(plt.figure())
plt.plot([3, 2, 1])
plt.close('all')
report.add_slider_to_section(figs, section=section)
report.save(op.join(tempdir, 'report.html'), open_browser=False)
assert_raises(NotImplementedError, report.add_slider_to_section,
[figs, figs])
assert_raises(ValueError, report.add_slider_to_section, figs, ['wug'])
assert_raises(TypeError, report.add_slider_to_section, figs, 'wug')
示例4: test_add_slider_to_section
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
def test_add_slider_to_section():
"""Test adding a slider with a series of images to mne report."""
tempdir = _TempDir()
report = Report(info_fname=raw_fname,
subject='sample', subjects_dir=subjects_dir)
section = 'slider_section'
figs = _get_example_figures()
report.add_slider_to_section(figs, section=section)
report.save(op.join(tempdir, 'report.html'), open_browser=False)
pytest.raises(NotImplementedError, report.add_slider_to_section,
[figs, figs])
pytest.raises(ValueError, report.add_slider_to_section, figs, ['wug'])
pytest.raises(TypeError, report.add_slider_to_section, figs, 'wug')
# need at least 2
pytest.raises(ValueError, report.add_slider_to_section, figs[:1], 'wug')
# Smoke test that SVG w/unicode can be added
report = Report()
fig, ax = plt.subplots()
ax.set_xlabel(u'μ')
report.add_slider_to_section([fig] * 2, image_format='svg')
示例5: parsing
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
meg_path = data_path + '/MEG/sample'
subjects_dir = data_path + '/subjects'
evoked_fname = meg_path + '/sample_audvis-ave.fif'
###############################################################################
# Do standard folder parsing (this can take a couple of minutes):
report = Report(image_format='png', subjects_dir=subjects_dir,
info_fname=evoked_fname, subject='sample', raw_psd=True)
report.parse_folder(meg_path)
###############################################################################
# Add a custom section with an evoked slider:
# Load the evoked data
evoked = read_evokeds(evoked_fname, condition='Left Auditory',
baseline=(None, 0), verbose=False)
evoked.crop(0, .2)
times = evoked.times[::4]
# Create a list of figs for the slider
figs = list()
for t in times:
figs.append(evoked.plot_topomap(t, vmin=-300, vmax=300, res=100,
show=False))
plt.close(figs[-1])
report.add_slider_to_section(figs, times, 'Evoked Response',
image_format='svg')
# to save report
# report.save('foobar.html', True)
示例6: gen_html_report
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
#.........这里部分代码省略.........
else:
this_evoked = mne.read_evokeds(fname_evoked, name)
figs = this_evoked.plot_joint(
times, show=False, ts_args=dict(**time_kwargs),
topomap_args=dict(outlines='head', **time_kwargs))
if not isinstance(figs, (list, tuple)):
figs = [figs]
captions = ('%s<br>%s["%s"] (N=%d)'
% (section, analysis, name,
this_evoked.nave))
captions = [captions] + [None] * (len(figs) - 1)
report.add_figs_to_section(
figs, captions, section=section,
image_format='png')
print('%5.1f sec' % ((time.time() - t0),))
#
# Source estimation
#
section = 'Source estimation'
if p.report_params.get('source', False):
t0 = time.time()
print((' %s ... ' % section).ljust(ljust), end='')
sources = p.report_params['source']
if not isinstance(sources, (list, tuple)):
sources = [sources]
for source in sources:
assert isinstance(source, dict)
analysis = source['analysis']
name = source['name']
times = source.get('times', [0.1, 0.2])
# Load the inverse
inv_dir = op.join(p.work_dir, subj, p.inverse_dir)
fname_inv = op.join(inv_dir,
safe_inserter(source['inv'], subj))
fname_evoked = op.join(inv_dir, '%s_%d%s_%s_%s-ave.fif'
% (analysis, p.lp_cut, p.inv_tag,
p.eq_tag, subj))
if not op.isfile(fname_inv):
print(' Missing inv: %s'
% op.basename(fname_inv), end='')
elif not op.isfile(fname_evoked):
print(' Missing evoked: %s'
% op.basename(fname_evoked), end='')
else:
inv = mne.minimum_norm.read_inverse_operator(fname_inv)
this_evoked = mne.read_evokeds(fname_evoked, name)
title = ('%s<br>%s["%s"] (N=%d)'
% (section, analysis, name, this_evoked.nave))
stc = mne.minimum_norm.apply_inverse(
this_evoked, inv,
lambda2=source.get('lambda2', 1. / 9.),
method=source.get('method', 'dSPM'))
stc = abs(stc)
# get clim using the reject_tmin <->reject_tmax
stc_crop = stc.copy().crop(
p.reject_tmin, p.reject_tmax)
clim = source.get('clim', dict(kind='percent',
lims=[82, 90, 98]))
out = mne.viz._3d._limits_to_control_points(
clim, stc_crop.data, 'viridis',
transparent=True) # dummy cmap
if isinstance(out[0], (list, tuple, np.ndarray)):
clim = out[0] # old MNE
else:
clim = out[1] # new MNE (0.17+)
clim = dict(kind='value', lims=clim)
if not isinstance(stc, mne.SourceEstimate):
print('Only surface source estimates currently '
'supported')
else:
subjects_dir = mne.utils.get_subjects_dir(
p.subjects_dir, raise_error=True)
with mlab_offscreen():
brain = stc.plot(
hemi=source.get('hemi', 'split'),
views=source.get('views', ['lat', 'med']),
size=source.get('size', (800, 600)),
colormap=source.get('colormap', 'viridis'),
transparent=source.get('transparent',
True),
foreground='k', background='w',
clim=clim, subjects_dir=subjects_dir,
)
imgs = list()
for t in times:
brain.set_time(t)
imgs.append(
trim_bg(brain.screenshot(), 255))
brain.close()
captions = ['%2.3f sec' % t for t in times]
report.add_slider_to_section(
imgs, captions=captions, section=section,
title=title, image_format='png')
print('%5.1f sec' % ((time.time() - t0),))
else:
print(' %s skipped' % section)
report_fname = get_report_fnames(p, subj)[0]
report.save(report_fname, open_browser=False, overwrite=True)
示例7: BSD
# 需要导入模块: from mne.report import Report [as 别名]
# 或者: from mne.report.Report import add_slider_to_section [as 别名]
# Authors: Teon Brooks <[email protected]
#
# License: BSD (3-clause)
from mne.report import Report
from mne.datasets import sample
from mne import read_evokeds
from matplotlib import pyplot as plt
report = Report()
path = sample.data_path()
fname = path + '/MEG/sample/sample_audvis-ave.fif'
# Load the evoked data
evoked = read_evokeds(fname, condition='Left Auditory',
baseline=(None, 0), verbose=False)
evoked.crop(0, .2)
times = evoked.times[::4]
# Create a list of figs for the slider
figs = list()
for time in times:
figs.append(evoked.plot_topomap(time, vmin=-300, vmax=300,
res=100, show=False))
plt.close(figs[-1])
report.add_slider_to_section(figs, times, 'Evoked Response')
# # to save report
# report.save('foobar.html', True)