def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option('--input', dest='input_fname', help='Input data file name', metavar='filename') parser.add_option('--mrk', dest='mrk_fname', help='MEG Marker file name', metavar='filename') parser.add_option('--elp', dest='elp_fname', help='Headshape points file name', metavar='filename') parser.add_option('--hsp', dest='hsp_fname', help='Headshape file name', metavar='filename') parser.add_option('--stim', dest='stim', help='Colon Separated Stimulus Trigger Channels', metavar='chs') parser.add_option('--slope', dest='slope', help='Slope direction', metavar='slope') parser.add_option('--stimthresh', dest='stimthresh', default=1, help='Threshold value for trigger channels', metavar='value') parser.add_option('--output', dest='out_fname', help='Name of the resulting fiff file', metavar='filename') parser.add_option('--debug', dest='debug', action='store_true', default=False, help='Set logging level for terminal output to debug') options, args = parser.parse_args() if options.debug: mne.set_log_level('debug') input_fname = options.input_fname if input_fname is None: with ETSContext(): mne.gui.kit2fiff() sys.exit(0) hsp_fname = options.hsp_fname elp_fname = options.elp_fname mrk_fname = options.mrk_fname stim = options.stim slope = options.slope stimthresh = options.stimthresh out_fname = options.out_fname if isinstance(stim, str): stim = map(int, stim.split(':')) raw = read_raw_kit(input_fname=input_fname, mrk=mrk_fname, elp=elp_fname, hsp=hsp_fname, stim=stim, slope=slope, stimthresh=stimthresh) raw.save(out_fname) raw.close()
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", default=None, help="Subjects directory") parser.add_option("-s", "--subject", dest="subject", default=None, help="Subject name") parser.add_option("-f", "--fiff", dest="inst", default=None, help="FIFF file with digitizer data for coregistration") parser.add_option("-t", "--tabbed", dest="tabbed", action="store_true", default=False, help="Option for small screens: Combine " "the data source panel and the coregistration panel " "into a single panel with tabs.") parser.add_option("--no-guess-mri", dest="guess_mri_subject", action='store_false', default=True, help="Prevent the GUI from automatically guessing and " "changing the MRI subject when a new head shape source " "file is selected.") options, args = parser.parse_args() with ETSContext(): mne.gui.coregistration(options.tabbed, inst=options.inst, subject=options.subject, subjects_dir=options.subjects_dir, guess_mri_subject=options.guess_mri_subject) if is_main: sys.exit(0)
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", default=None, help="Subjects directory") parser.add_option("-s", "--subject", dest="subject", default=None, help="Subject name") parser.add_option("-f", "--fiff", dest="inst", default=None, help="FIFF file with digitizer data for coregistration") parser.add_option("-t", "--tabbed", dest="tabbed", action="store_true", default=False, help="Option for small screens: Combine " "the data source panel and the coregistration panel " "into a single panel with tabs.") parser.add_option("--no-guess-mri", dest="guess_mri_subject", action='store_false', default=True, help="Prevent the GUI from automatically guessing and " "changing the MRI subject when a new head shape source " "file is selected.") parser.add_option("--head-opacity", type=float, default=1., dest="head_opacity", help="The opacity of the head surface, in the range " "[0, 1].") parser.add_option("--low-res-head", action='store_true', default=False, dest="low_res_head", help="Default to using a low-resolution head surface.") parser.add_option('--verbose', action='store_true', dest='verbose', help='Turn on verbose mode.') options, args = parser.parse_args() with ETSContext(): mne.gui.coregistration(options.tabbed, inst=options.inst, subject=options.subject, subjects_dir=options.subjects_dir, guess_mri_subject=options.guess_mri_subject, head_opacity=options.head_opacity, head_high_res=not options.low_res_head, verbose=options.verbose) if is_main: sys.exit(0)
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", default=None, help="Subjects directory") parser.add_option("-s", "--subject", dest="subject", default=None, help="Subject name") parser.add_option("-f", "--fiff", dest="inst", default=None, help="FIFF file with digitizer data for coregistration") parser.add_option("-t", "--tabbed", dest="tabbed", action="store_true", default=False, help="Option for small screens: Combine " "the data source panel and the coregistration panel " "into a single panel with tabs.") options, args = parser.parse_args() with ETSContext(): mne.gui.coregistration(options.tabbed, inst=options.inst, subject=options.subject, subjects_dir=options.subjects_dir) if is_main: sys.exit(0)
def _run(subjects_dir, subject, force, overwrite, no_decimate, verbose=None): this_env = copy.copy(os.environ) subjects_dir = get_subjects_dir(subjects_dir, raise_error=True) this_env['SUBJECTS_DIR'] = subjects_dir this_env['SUBJECT'] = subject if 'FREESURFER_HOME' not in this_env: raise RuntimeError('The FreeSurfer environment needs to be set up ' 'for this script') incomplete = 'warn' if force else 'raise' subj_path = op.join(subjects_dir, subject) if not op.exists(subj_path): raise RuntimeError('%s does not exist. Please check your subject ' 'directory path.' % subj_path) mri = 'T1.mgz' if op.exists(op.join(subj_path, 'mri', 'T1.mgz')) else 'T1' logger.info('1. Creating a dense scalp tessellation with mkheadsurf...') def check_seghead(surf_path=op.join(subj_path, 'surf')): surf = None for k in ['lh.seghead', 'lh.smseghead']: this_surf = op.join(surf_path, k) if op.exists(this_surf): surf = this_surf break return surf my_seghead = check_seghead() if my_seghead is None: run_subprocess(['mkheadsurf', '-subjid', subject, '-srcvol', mri], env=this_env) surf = check_seghead() if surf is None: raise RuntimeError('mkheadsurf did not produce the standard output ' 'file.') dense_fname = '{0}/{1}/bem/{1}-head-dense.fif'.format( subjects_dir, subject) logger.info('2. Creating %s ...' % dense_fname) _check_file(dense_fname, overwrite) surf = mne.bem._surfaces_to_bem( [surf], [mne.io.constants.FIFF.FIFFV_BEM_SURF_ID_HEAD], [1], incomplete=incomplete)[0] mne.write_bem_surfaces(dense_fname, surf) levels = 'medium', 'sparse' tris = [] if no_decimate else [30000, 2500] if os.getenv('_MNE_TESTING_SCALP', 'false') == 'true': tris = [len(surf['tris'])] # don't actually decimate for ii, (n_tri, level) in enumerate(zip(tris, levels), 3): logger.info('%i. Creating %s tessellation...' % (ii, level)) logger.info('%i.1 Decimating the dense tessellation...' % ii) with ETSContext(): points, tris = mne.decimate_surface(points=surf['rr'], triangles=surf['tris'], n_triangles=n_tri) dec_fname = dense_fname.replace('dense', level) logger.info('%i.2 Creating %s' % (ii, dec_fname)) _check_file(dec_fname, overwrite) dec_surf = mne.bem._surfaces_to_bem( [dict(rr=points, tris=tris)], [mne.io.constants.FIFF.FIFFV_BEM_SURF_ID_HEAD], [1], rescale=False, incomplete=incomplete) mne.write_bem_surfaces(dec_fname, dec_surf)
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", default=None, help="Subjects directory") parser.add_option("-s", "--subject", dest="subject", default=None, help="Subject name") parser.add_option("-f", "--fiff", dest="inst", default=None, help="FIFF file with digitizer data for coregistration") parser.add_option("-t", "--tabbed", dest="tabbed", action="store_true", default=False, help="Option for small screens: Combine " "the data source panel and the coregistration panel " "into a single panel with tabs.") parser.add_option("--no-guess-mri", dest="guess_mri_subject", action='store_false', default=None, help="Prevent the GUI from automatically guessing and " "changing the MRI subject when a new head shape source " "file is selected.") parser.add_option("--head-opacity", type=float, default=None, dest="head_opacity", help="The opacity of the head surface, in the range " "[0, 1].") parser.add_option("--high-res-head", action='store_true', default=False, dest="high_res_head", help="Use a high-resolution head surface.") parser.add_option("--low-res-head", action='store_true', default=False, dest="low_res_head", help="Use a low-resolution head surface.") parser.add_option('--trans', dest='trans', default=None, help='Head<->MRI transform FIF file ("-trans.fif")') parser.add_option('--project-eeg', dest='project_eeg', action='store_true', default=None, help="Project EEG electrodes to the head surface (" "for visualization purposes only)") parser.add_option('--orient-to-surface', action='store_true', default=None, dest='orient_to_surface', help='Orient points to the surface.') parser.add_option('--scale-by-distance', action='store_true', default=None, dest='scale_by_distance', help='Scale points by distance from the surface.') parser.add_option('--mark-inside', action='store_true', default=None, dest='mark_inside', help='Mark points inside the head using a different ' 'color.') parser.add_option('--interaction', type=str, default=None, dest='interaction', help='Interaction style to use, can be "trackball" or ' '"terrain".') parser.add_option('--scale', type=float, default=None, dest='scale', help='Scale factor for the scene.') parser.add_option('--simple-rendering', action='store_false', dest='advanced_rendering', help='Use simplified OpenGL rendering') parser.add_option('--verbose', action='store_true', dest='verbose', help='Turn on verbose mode.') options, args = parser.parse_args() if options.low_res_head: if options.high_res_head: raise ValueError("Can't specify --high-res-head and " "--low-res-head at the same time.") head_high_res = False elif options.high_res_head: head_high_res = True else: head_high_res = None # expanduser allows ~ for --subjects-dir subjects_dir = options.subjects_dir if subjects_dir is not None: subjects_dir = op.expanduser(subjects_dir) trans = options.trans if trans is not None: trans = op.expanduser(trans) try: import faulthandler faulthandler.enable() except ImportError: pass # old Python2 with ETSContext(): mne.gui.coregistration( options.tabbed, inst=options.inst, subject=options.subject, subjects_dir=subjects_dir, guess_mri_subject=options.guess_mri_subject, head_opacity=options.head_opacity, head_high_res=head_high_res, trans=trans, scrollable=True, project_eeg=options.project_eeg, orient_to_surface=options.orient_to_surface, scale_by_distance=options.scale_by_distance, mark_inside=options.mark_inside, interaction=options.interaction, scale=options.scale, advanced_rendering=options.advanced_rendering, verbose=options.verbose) if is_main: sys.exit(0)
def _run(subjects_dir, subject, force, overwrite, no_decimate, verbose=None): this_env = copy.copy(os.environ) this_env['SUBJECTS_DIR'] = subjects_dir this_env['SUBJECT'] = subject if 'SUBJECTS_DIR' not in this_env: raise RuntimeError('The environment variable SUBJECTS_DIR should ' 'be set') if not op.isdir(subjects_dir): raise RuntimeError('subjects directory %s not found, specify using ' 'the environment variable SUBJECTS_DIR or ' 'the command line option --subjects-dir') if 'MNE_ROOT' not in this_env: raise RuntimeError('MNE_ROOT environment variable is not set') if 'FREESURFER_HOME' not in this_env: raise RuntimeError('The FreeSurfer environment needs to be set up ' 'for this script') force = '--force' if force else '--check' subj_path = op.join(subjects_dir, subject) if not op.exists(subj_path): raise RuntimeError('%s does not exist. Please check your subject ' 'directory path.' % subj_path) if op.exists(op.join(subj_path, 'mri', 'T1.mgz')): mri = 'T1.mgz' else: mri = 'T1' logger.info('1. Creating a dense scalp tessellation with mkheadsurf...') def check_seghead(surf_path=op.join(subj_path, 'surf')): for k in ['/lh.seghead', '/lh.smseghead']: surf = surf_path + k if op.exists(surf_path + k) else None if surf is not None: break return surf my_seghead = check_seghead() if my_seghead is None: run_subprocess(['mkheadsurf', '-subjid', subject, '-srcvol', mri], env=this_env) surf = check_seghead() if surf is None: raise RuntimeError('mkheadsurf did not produce the standard output ' 'file.') dense_fname = '{0}/{1}/bem/{1}-head-dense.fif'.format(subjects_dir, subject) logger.info('2. Creating %s ...' % dense_fname) _check_file(dense_fname, overwrite) run_subprocess(['mne_surf2bem', '--surf', surf, '--id', '4', force, '--fif', dense_fname], env=this_env) levels = 'medium', 'sparse' my_surf = mne.read_bem_surfaces(dense_fname)[0] tris = [] if no_decimate else [30000, 2500] if os.getenv('_MNE_TESTING_SCALP', 'false') == 'true': tris = [len(my_surf['tris'])] # don't actually decimate for ii, (n_tri, level) in enumerate(zip(tris, levels), 3): logger.info('%i. Creating %s tessellation...' % (ii, level)) logger.info('%i.1 Decimating the dense tessellation...' % ii) with ETSContext(): points, tris = mne.decimate_surface(points=my_surf['rr'], triangles=my_surf['tris'], n_triangles=n_tri) other_fname = dense_fname.replace('dense', level) logger.info('%i.2 Creating %s' % (ii, other_fname)) _check_file(other_fname, overwrite) tempdir = _TempDir() surf_fname = tempdir + '/tmp-surf.surf' # convert points to meters, make mne_analyze happy mne.write_surface(surf_fname, points * 1e3, tris) # XXX for some reason --check does not work here. try: run_subprocess(['mne_surf2bem', '--surf', surf_fname, '--id', '4', '--force', '--fif', other_fname], env=this_env) finally: del tempdir
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", default=None, help="Subjects directory") parser.add_option("-s", "--subject", dest="subject", default=None, help="Subject name") parser.add_option("-f", "--fiff", dest="inst", default=None, help="FIFF file with digitizer data for coregistration") parser.add_option("-t", "--tabbed", dest="tabbed", action="store_true", default=False, help="Option for small screens: Combine " "the data source panel and the coregistration panel " "into a single panel with tabs.") parser.add_option("--no-guess-mri", dest="guess_mri_subject", action='store_false', default=None, help="Prevent the GUI from automatically guessing and " "changing the MRI subject when a new head shape source " "file is selected.") parser.add_option("--head-opacity", type=float, default=None, dest="head_opacity", help="The opacity of the head surface, in the range " "[0, 1].") parser.add_option("--high-res-head", action='store_true', default=False, dest="high_res_head", help="Use a high-resolution head surface.") parser.add_option("--low-res-head", action='store_true', default=False, dest="low_res_head", help="Use a low-resolution head surface.") parser.add_option('--trans', dest='trans', default=None, help='Head<->MRI transform FIF file ("-trans.fif")') parser.add_option('--project-eeg', dest='project_eeg', action='store_true', default=False, help="Project EEG electrodes to the head surface") parser.add_option('--verbose', action='store_true', dest='verbose', help='Turn on verbose mode.') options, args = parser.parse_args() if options.low_res_head: if options.high_res_head: raise ValueError("Can't specify --high-res-head and " "--low-res-head at the same time.") head_high_res = False elif options.high_res_head: head_high_res = True else: head_high_res = None # expanduser allows ~ for --subjects-dir subjects_dir = options.subjects_dir if subjects_dir is not None: subjects_dir = op.expanduser(subjects_dir) trans = options.trans if trans is not None: trans = op.expanduser(trans) with ETSContext(): mne.gui.coregistration(options.tabbed, inst=options.inst, subject=options.subject, subjects_dir=subjects_dir, guess_mri_subject=options.guess_mri_subject, head_opacity=options.head_opacity, head_high_res=head_high_res, trans=trans, scrollable=True, project_eeg=options.project_eeg, verbose=options.verbose) if is_main: sys.exit(0)