Ejemplo n.º 1
0
def test_add_bem_n_jobs(n_jobs, monkeypatch):
    """Test add_bem with n_jobs."""
    if n_jobs == 1:  # in one case, do at init -- in the other, pass in
        use_subjects_dir = None
    else:
        use_subjects_dir = subjects_dir
    report = Report(subjects_dir=use_subjects_dir)
    # implicitly test that subjects_dir is correctly preserved here
    monkeypatch.setattr(report_mod, '_BEM_VIEWS', ('axial', ))
    if use_subjects_dir is not None:
        use_subjects_dir = None
    report.add_bem(subject='sample',
                   title='sample',
                   tags=('sample', ),
                   decim=15,
                   n_jobs=n_jobs,
                   subjects_dir=subjects_dir)
    assert len(report.html) == 1
    imgs = np.array([
        plt.imread(BytesIO(base64.b64decode(b)), 'png')
        for b in re.findall(r'data:image/png;base64,(\S*)">', report.html[0])
    ])
    assert imgs.ndim == 4  # images, h, w, rgba
    assert len(imgs) == 6
    imgs.shape = (len(imgs), -1)
    norms = np.linalg.norm(imgs, axis=-1)
    # should have down-up-down shape
    corr = np.corrcoef(norms, np.hanning(len(imgs)))[0, 1]
    assert 0.778 < corr < 0.80
Ejemplo n.º 2
0
def test_render_mri(renderer, tmpdir):
    """Test rendering MRI for mne report."""
    tempdir = str(tmpdir)
    trans_fname_new = op.join(tempdir, 'temp-trans.fif')
    for a, b in [[trans_fname, trans_fname_new]]:
        shutil.copyfile(a, b)
    report = Report(info_fname=raw_fname,
                    subject='sample', subjects_dir=subjects_dir)
    report.parse_folder(data_path=tempdir, mri_decim=30, pattern='*')
    fname = op.join(tempdir, 'report.html')
    report.save(fname, open_browser=False)
    html = Path(fname).read_text(encoding='utf-8')
    assert 'data-mne-tags=" bem "' in html
    assert repr(report)
    report.add_bem(subject='sample', title='extra', tags=('foo',),
                   subjects_dir=subjects_dir, decim=30)
    report.save(fname, open_browser=False, overwrite=True)
    html = Path(fname).read_text(encoding='utf-8')
    assert 'data-mne-tags=" bem "' in html
    assert 'data-mne-tags=" foo "' in html