Ejemplo n.º 1
0
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag

    parser = get_optparser(__file__)
    subjects_dir = mne.get_config('SUBJECTS_DIR')

    parser.add_option('-o',
                      '--overwrite',
                      dest='overwrite',
                      action='store_true',
                      help='Overwrite previously computed surface')
    parser.add_option('-s',
                      '--subject',
                      dest='subject',
                      help='The name of the subject',
                      type='str')
    parser.add_option('-f',
                      '--force',
                      dest='force',
                      action='store_true',
                      help='Force creation of the surface even if it has '
                      'some topological defects.')
    parser.add_option("-d",
                      "--subjects-dir",
                      dest="subjects_dir",
                      help="Subjects directory",
                      default=subjects_dir)
    parser.add_option("-n",
                      "--no-decimate",
                      dest="no_decimate",
                      help="Disable medium and sparse decimations "
                      "(dense only)",
                      action='store_true')
    _add_verbose_flag(parser)
    options, args = parser.parse_args()

    subject = vars(options).get('subject', os.getenv('SUBJECT'))
    subjects_dir = options.subjects_dir
    if subject is None or subjects_dir is None:
        parser.print_help()
        sys.exit(1)
    make_scalp_surfaces(subject=subject,
                        subjects_dir=subjects_dir,
                        force=options.force,
                        overwrite=options.overwrite,
                        no_decimate=options.no_decimate,
                        verbose=options.verbose)
Ejemplo n.º 2
0
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag

    parser = get_optparser(__file__)

    parser.add_option('--bem',
                      dest='bem_fname',
                      help='The name of the file containing the '
                      'triangulations of the BEM surfaces and the '
                      'conductivities of the compartments. The standard '
                      'ending for this file is -bem.fif.',
                      metavar="FILE")
    parser.add_option('--sol',
                      dest='bem_sol_fname',
                      help='The name of the resulting file containing BEM '
                      'solution (geometry matrix). It uses the linear '
                      'collocation approach. The file should end with '
                      '-bem-sof.fif.',
                      metavar='FILE',
                      default=None)
    _add_verbose_flag(parser)

    options, args = parser.parse_args()
    bem_fname = options.bem_fname
    bem_sol_fname = options.bem_sol_fname
    verbose = True if options.verbose is not None else False

    if bem_fname is None:
        parser.print_help()
        sys.exit(1)

    if bem_sol_fname is None:
        base, _ = os.path.splitext(bem_fname)
        bem_sol_fname = base + '-sol.fif'

    bem_model = mne.read_bem_surfaces(bem_fname,
                                      patch_stats=False,
                                      verbose=verbose)
    bem_solution = mne.make_bem_solution(bem_model, verbose=verbose)
    mne.write_bem_solution(bem_sol_fname, bem_solution)
Ejemplo n.º 3
0
def run():
    """Run command."""
    import matplotlib.pyplot as plt
    from mne.commands.utils import get_optparser, _add_verbose_flag

    parser = get_optparser(__file__, usage='usage: %prog raw [options]')

    parser.add_option("--raw", dest="raw_in",
                      help="Input raw FIF file (can also be specified "
                      "directly as an argument without the --raw prefix)",
                      metavar="FILE")
    parser.add_option("--proj", dest="proj_in",
                      help="Projector file", metavar="FILE",
                      default='')
    parser.add_option("--eve", dest="eve_in",
                      help="Events file", metavar="FILE",
                      default='')
    parser.add_option("-d", "--duration", dest="duration", type="float",
                      help="Time window for plotting (sec)",
                      default=10.0)
    parser.add_option("-t", "--start", dest="start", type="float",
                      help="Initial start time for plotting",
                      default=0.0)
    parser.add_option("-n", "--n_channels", dest="n_channels", type="int",
                      help="Number of channels to plot at a time",
                      default=20)
    parser.add_option("-o", "--order", dest="group_by",
                      help="Order to use for grouping during plotting "
                      "('type' or 'original')", default='type')
    parser.add_option("-p", "--preload", dest="preload",
                      help="Preload raw data (for faster navigaton)",
                      default=False, action="store_true")
    parser.add_option("-s", "--show_options", dest="show_options",
                      help="Show projection options dialog",
                      default=False)
    parser.add_option("--allowmaxshield", dest="maxshield",
                      help="Allow loading MaxShield processed data",
                      action="store_true")
    parser.add_option("--highpass", dest="highpass", type="float",
                      help="Display high-pass filter corner frequency",
                      default=-1)
    parser.add_option("--lowpass", dest="lowpass", type="float",
                      help="Display low-pass filter corner frequency",
                      default=-1)
    parser.add_option("--filtorder", dest="filtorder", type="int",
                      help="Display filtering IIR order (or 0 to use FIR)",
                      default=4)
    parser.add_option("--clipping", dest="clipping",
                      help="Enable trace clipping mode, either 'clamp' or "
                      "'transparent'", default=None)
    parser.add_option("--filterchpi", dest="filterchpi",
                      help="Enable filtering cHPI signals.", default=None,
                      action="store_true")
    _add_verbose_flag(parser)
    options, args = parser.parse_args()

    if len(args):
        raw_in = args[0]
    else:
        raw_in = options.raw_in
    duration = options.duration
    start = options.start
    n_channels = options.n_channels
    group_by = options.group_by
    preload = options.preload
    show_options = options.show_options
    proj_in = options.proj_in
    eve_in = options.eve_in
    maxshield = options.maxshield
    highpass = options.highpass
    lowpass = options.lowpass
    filtorder = options.filtorder
    clipping = options.clipping
    filterchpi = options.filterchpi
    verbose = options.verbose

    if raw_in is None:
        parser.print_help()
        sys.exit(1)

    raw = mne.io.read_raw_fif(raw_in, preload=preload,
                              allow_maxshield=maxshield)
    if len(proj_in) > 0:
        projs = mne.read_proj(proj_in)
        raw.info['projs'] = projs
    if len(eve_in) > 0:
        events = mne.read_events(eve_in)
    else:
        events = None

    if filterchpi:
        if not preload:
            raise RuntimeError(
                'Raw data must be preloaded for chpi, use --preload')
        raw = mne.chpi.filter_chpi(raw)

    highpass = None if highpass < 0 or filtorder < 0 else highpass
    lowpass = None if lowpass < 0 or filtorder < 0 else lowpass
    raw.plot(duration=duration, start=start, n_channels=n_channels,
             group_by=group_by, show_options=show_options, events=events,
             highpass=highpass, lowpass=lowpass, filtorder=filtorder,
             clipping=clipping, verbose=verbose)
    plt.show(block=True)
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag

    parser = get_optparser(__file__)

    parser.add_option("-s",
                      "--subject",
                      dest="subject",
                      help="Subject name (required)",
                      default=None)
    parser.add_option("-d",
                      "--subjects-dir",
                      dest="subjects_dir",
                      help="Subjects directory",
                      default=None)
    parser.add_option("-o",
                      "--overwrite",
                      dest="overwrite",
                      help="Write over existing files",
                      action="store_true")
    parser.add_option("-v",
                      "--volume",
                      dest="volume",
                      help="Defaults to T1",
                      default='T1')
    parser.add_option("-a",
                      "--atlas",
                      dest="atlas",
                      help="Specify the --atlas option for mri_watershed",
                      default=False,
                      action="store_true")
    parser.add_option("-g",
                      "--gcaatlas",
                      dest="gcaatlas",
                      help="Specify the --brain_atlas option for "
                      "mri_watershed",
                      default=False,
                      action="store_true")
    parser.add_option("-p",
                      "--preflood",
                      dest="preflood",
                      help="Change the preflood height",
                      default=None)
    parser.add_option("--copy",
                      dest="copy",
                      help="Use copies instead of symlinks for surfaces",
                      action="store_true")
    parser.add_option("-t",
                      "--T1",
                      dest="T1",
                      help="Whether or not to pass the -T1 flag "
                      "(can be true, false, 0, or 1). "
                      "By default it takes the same value as gcaatlas.",
                      default=None)
    parser.add_option("-b",
                      "--brainmask",
                      dest="brainmask",
                      help="The filename for the brainmask output file "
                      "relative to the "
                      "$SUBJECTS_DIR/$SUBJECT/bem/watershed/ directory.",
                      default="ws")
    _add_verbose_flag(parser)

    options, args = parser.parse_args()

    if options.subject is None:
        parser.print_help()
        sys.exit(1)

    subject = options.subject
    subjects_dir = options.subjects_dir
    overwrite = options.overwrite
    volume = options.volume
    atlas = options.atlas
    gcaatlas = options.gcaatlas
    preflood = options.preflood
    copy = options.copy
    brainmask = options.brainmask
    T1 = options.T1
    if T1 is not None:
        T1 = T1.lower()
        _check_option("--T1", T1, ('true', 'false', '0', '1'))
        T1 = T1 in ('true', '1')
    verbose = options.verbose

    make_watershed_bem(subject=subject,
                       subjects_dir=subjects_dir,
                       overwrite=overwrite,
                       volume=volume,
                       atlas=atlas,
                       gcaatlas=gcaatlas,
                       preflood=preflood,
                       copy=copy,
                       T1=T1,
                       brainmask=brainmask,
                       verbose=verbose)
Ejemplo n.º 5
0
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag

    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')
    _add_verbose_flag(parser)

    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)
    import faulthandler
    faulthandler.enable()
    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)
Ejemplo n.º 6
0
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag

    parser = get_optparser(__file__)

    parser.add_option("-p",
                      "--path",
                      dest="path",
                      help="Path to folder who MNE-Report must be created")
    parser.add_option("-i",
                      "--info",
                      dest="info_fname",
                      help="File from which info dictionary is to be read",
                      metavar="FILE")
    parser.add_option("-c",
                      "--cov",
                      dest="cov_fname",
                      help="File from which noise covariance is to be read",
                      metavar="FILE")
    parser.add_option("--bmin",
                      dest="bmin",
                      help="Time at which baseline correction starts for "
                      "evokeds",
                      default=None)
    parser.add_option("--bmax",
                      dest="bmax",
                      help="Time at which baseline correction stops for "
                      "evokeds",
                      default=None)
    parser.add_option("-d",
                      "--subjects-dir",
                      dest="subjects_dir",
                      help="The subjects directory")
    parser.add_option("-s",
                      "--subject",
                      dest="subject",
                      help="The subject name")
    parser.add_option("--no-browser",
                      dest="no_browser",
                      action='store_false',
                      help="Do not open MNE-Report in browser")
    parser.add_option("--overwrite",
                      dest="overwrite",
                      action='store_false',
                      help="Overwrite html report if it already exists")
    parser.add_option("-j",
                      "--jobs",
                      dest="n_jobs",
                      help="Number of jobs to"
                      " run in parallel")
    parser.add_option("-m",
                      "--mri-decim",
                      type="int",
                      dest="mri_decim",
                      default=2,
                      help="Integer factor used to decimate "
                      "BEM plots")
    parser.add_option("--image-format",
                      type="str",
                      dest="image_format",
                      default='png',
                      help="Image format to use "
                      "(can be 'png' or 'svg')")
    _add_verbose_flag(parser)

    options, args = parser.parse_args()
    path = options.path
    if path is None:
        parser.print_help()
        sys.exit(1)
    info_fname = options.info_fname
    cov_fname = options.cov_fname
    subjects_dir = options.subjects_dir
    subject = options.subject
    image_format = options.image_format
    mri_decim = int(options.mri_decim)
    verbose = True if options.verbose is not None else False
    open_browser = False if options.no_browser is not None else True
    overwrite = True if options.overwrite is not None else False
    n_jobs = int(options.n_jobs) if options.n_jobs is not None else 1

    bmin = float(options.bmin) if options.bmin is not None else None
    bmax = float(options.bmax) if options.bmax is not None else None
    # XXX: this means (None, None) cannot be specified through command line
    if bmin is None and bmax is None:
        baseline = None
    else:
        baseline = (bmin, bmax)

    t0 = time.time()
    report = Report(info_fname,
                    subjects_dir=subjects_dir,
                    subject=subject,
                    baseline=baseline,
                    cov_fname=cov_fname,
                    verbose=verbose,
                    image_format=image_format)
    report.parse_folder(path,
                        verbose=verbose,
                        n_jobs=n_jobs,
                        mri_decim=mri_decim)
    log_elapsed(time.time() - t0, verbose=verbose)
    report.save(open_browser=open_browser, overwrite=overwrite)
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag
    parser = get_optparser(__file__)

    parser.add_option('-s',
                      '--subject',
                      dest='subject',
                      help='Subject name (required)',
                      default=None)
    parser.add_option('--src',
                      dest='fname',
                      help='Output file name. Use a name <dir>/<name>-src.fif',
                      metavar='FILE',
                      default=None)
    parser.add_option('--morph',
                      dest='subject_to',
                      help='morph the source space to this subject',
                      default=None)
    parser.add_option('--surf',
                      dest='surface',
                      help='The surface to use. (default to white)',
                      default='white',
                      type='string')
    parser.add_option('--spacing',
                      dest='spacing',
                      help='Specifies the approximate grid spacing of the '
                      'source space in mm. (default to 7mm)',
                      default=None,
                      type='int')
    parser.add_option('--ico',
                      dest='ico',
                      help='use the recursively subdivided icosahedron '
                      'to create the source space.',
                      default=None,
                      type='int')
    parser.add_option('--oct',
                      dest='oct',
                      help='use the recursively subdivided octahedron '
                      'to create the source space.',
                      default=None,
                      type='int')
    parser.add_option('-d',
                      '--subjects-dir',
                      dest='subjects_dir',
                      help='Subjects directory',
                      default=None)
    parser.add_option('-n',
                      '--n-jobs',
                      dest='n_jobs',
                      help='The number of jobs to run in parallel '
                      '(default 1). Requires the joblib package. '
                      'Will use at most 2 jobs'
                      ' (one for each hemisphere).',
                      default=1,
                      type='int')
    parser.add_option('-o',
                      '--overwrite',
                      dest='overwrite',
                      help='to write over existing files',
                      default=None,
                      action="store_true")
    _add_verbose_flag(parser)

    options, args = parser.parse_args()

    if options.subject is None:
        parser.print_help()
        sys.exit(1)

    subject = options.subject
    subject_to = options.subject_to
    fname = options.fname
    subjects_dir = options.subjects_dir
    spacing = options.spacing
    ico = options.ico
    oct = options.oct
    surface = options.surface
    n_jobs = options.n_jobs
    verbose = True if options.verbose is not None else False
    overwrite = True if options.overwrite is not None else False

    # Parse source spacing option
    spacing_options = [ico, oct, spacing]
    n_options = len([x for x in spacing_options if x is not None])
    if n_options > 1:
        raise ValueError('Only one spacing option can be set at the same time')
    elif n_options == 0:
        # Default to oct6
        use_spacing = 'oct6'
    elif n_options == 1:
        if ico is not None:
            use_spacing = "ico" + str(ico)
        elif oct is not None:
            use_spacing = "oct" + str(oct)
        elif spacing is not None:
            use_spacing = spacing
    # Generate filename
    if fname is None:
        if subject_to is None:
            fname = subject + '-' + str(use_spacing) + '-src.fif'
        else:
            fname = (subject_to + '-' + subject + '-' + str(use_spacing) +
                     '-src.fif')
    else:
        if not (fname.endswith('_src.fif') or fname.endswith('-src.fif')):
            fname = fname + "-src.fif"
    # Create source space
    src = mne.setup_source_space(subject=subject,
                                 spacing=use_spacing,
                                 surface=surface,
                                 subjects_dir=subjects_dir,
                                 n_jobs=n_jobs,
                                 verbose=verbose)
    # Morph source space if --morph is set
    if subject_to is not None:
        src = mne.morph_source_spaces(src,
                                      subject_to=subject_to,
                                      subjects_dir=subjects_dir,
                                      surf=surface,
                                      verbose=verbose)

    # Save source space to file
    src.save(fname=fname, overwrite=overwrite)
def run():
    """Run command."""
    from mne.commands.utils import get_optparser, _add_verbose_flag

    parser = get_optparser(__file__)

    parser.add_option("-s",
                      "--subject",
                      dest="subject",
                      help="Subject name (required)",
                      default=None)
    parser.add_option("--model",
                      dest="model",
                      help="Output file name. Use a name <dir>/<name>-bem.fif",
                      default=None,
                      type='string')
    parser.add_option('--ico',
                      dest='ico',
                      help='The surface ico downsampling to use, e.g. '
                      ' 5=20484, 4=5120, 3=1280. If None, no subsampling'
                      ' is applied.',
                      default=None,
                      type='int')
    parser.add_option('--brainc',
                      dest='brainc',
                      help='Defines the brain compartment conductivity. '
                      'The default value is 0.3 S/m.',
                      default=0.3,
                      type='float')
    parser.add_option('--skullc',
                      dest='skullc',
                      help='Defines the skull compartment conductivity. '
                      'The default value is 0.006 S/m.',
                      default=None,
                      type='float')
    parser.add_option('--scalpc',
                      dest='scalpc',
                      help='Defines the scalp compartment conductivity. '
                      'The default value is 0.3 S/m.',
                      default=None,
                      type='float')
    parser.add_option('--homog',
                      dest='homog',
                      help='Use a single compartment model (brain only) '
                      'instead a three layer one (scalp, skull, and '
                      ' brain). If this flag is specified, the options '
                      '--skullc and --scalpc are irrelevant.',
                      default=None,
                      action="store_true")
    parser.add_option('-d',
                      '--subjects-dir',
                      dest='subjects_dir',
                      help='Subjects directory',
                      default=None)
    _add_verbose_flag(parser)
    options, args = parser.parse_args()

    if options.subject is None:
        parser.print_help()
        sys.exit(1)

    subject = options.subject
    fname = options.model
    subjects_dir = options.subjects_dir
    ico = options.ico
    brainc = options.brainc
    skullc = options.skullc
    scalpc = options.scalpc
    homog = True if options.homog is not None else False
    verbose = True if options.verbose is not None else False
    # Parse conductivity option
    if homog is True:
        if skullc is not None:
            warn('Trying to set the skull conductivity for a single layer '
                 'model. To use a 3 layer model, do not set the --homog flag.')
        if scalpc is not None:
            warn('Trying to set the scalp conductivity for a single layer '
                 'model. To use a 3 layer model, do not set the --homog flag.')
        # Single layer
        conductivity = [brainc]
    else:
        if skullc is None:
            skullc = 0.006
        if scalpc is None:
            scalpc = 0.3
        conductivity = [brainc, skullc, scalpc]
    # Create source space
    bem_model = mne.make_bem_model(subject,
                                   ico=ico,
                                   conductivity=conductivity,
                                   subjects_dir=subjects_dir,
                                   verbose=verbose)
    # Generate filename
    if fname is None:
        n_faces = list(str(len(surface['tris'])) for surface in bem_model)
        fname = subject + '-' + '-'.join(n_faces) + '-bem.fif'
    else:
        if not (fname.endswith('-bem.fif') or fname.endswith('_bem.fif')):
            fname = fname + "-bem.fif"
            # Save to subject's directory
    subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
    fname = os.path.join(subjects_dir, subject, "bem", fname)
    # Save source space to file
    mne.write_bem_surfaces(fname, bem_model)