def main(): import os,sys import glob import json import numpy as np import matplotlib matplotlib.use('Agg') import os import json import numpy as np import nibabel as nib os.environ['ETS_TOOLKIT'] = 'qt4' os.environ['QT_API'] = 'pyqt5' import pyvista from pyvista.utilities import xvfb pyvista.OFF_SCREEN=True xvfb.start_xvfb() from mne.viz import set_3d_backend set_3d_backend('pyvista') # grab config with open('config.json','r') as config_f: config = json.load(config_f) # set up paths and variables freesurfer='./output' cortexmap='./cortexmap' colormap = config['colormap'] min_percentile = config['min_percentile'] max_percentile = config['max_percentile'] threshold = np.float(config['threshold']) measureFiles = np.unique([ f.split('h.')[1] for f in os.listdir('./'+cortexmap+'/func') if f.split('h.')[1] != 'goodvertex.func.gii' ]) surface = config['surface'] hemi=["lh","rh"] #### set up other inputs #### # set outdir outdir = 'images' # generate output directory if not already there if os.path.isdir(outdir): print("directory exits") else: print("making output directory") os.mkdir(outdir) for h in hemi: for i in measureFiles: print('generating image for %s.%s' %(h,i)) if surface == 'midthickness': generateMeasureOverlayImage(freesurfer,h,'midthickness.very_inflated',i,colormap,min_percentile,max_percentile,threshold,outdir,'cortexmap') else: generateMeasureOverlayImage(freesurfer,h,surface,i,colormap,min_percentile,max_percentile,threshold,outdir,'cortexmap')
def test_set_3d_backend_bad(monkeypatch, tmp_path): """Test that the error emitted when a bad backend name is used.""" match = "Allowed values are 'pyvistaqt' and 'notebook'" with pytest.raises(ValueError, match=match): set_3d_backend('invalid') # gh-9607 def fail(x): raise ModuleNotFoundError(x) monkeypatch.setattr('mne.viz.backends.renderer._reload_backend', fail) monkeypatch.setattr('mne.viz.backends.renderer.MNE_3D_BACKEND', None) match = 'Could not load any valid 3D.*\npyvistaqt: .*' assert get_3d_backend() is None with pytest.raises(RuntimeError, match=match): _get_renderer()