How to use the mne.datasets.sample function in mne

To help you get started, we’ve selected a few mne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mne-tools / mne-python / examples / testing / test_bem_commands.py View on Github external
# -*- coding: utf-8 -*-
import os
from os import path as op
import shutil
import warnings
from nose.tools import assert_true

from mne.commands import mne_watershed_bem
from mne.utils import (run_tests_if_main, _TempDir, ArgvSetter)
from mne.datasets import sample


subjects_dir = op.join(sample.data_path(download=False), 'subjects')

warnings.simplefilter('always')


def check_usage(module, force_help=False):
    """Helper to ensure we print usage"""
    args = ('--help',) if force_help else ()
    with ArgvSetter(args) as out:
        try:
            module.run()
        except SystemExit:
            pass
        assert_true('Usage: ' in out.stdout.getvalue())


def test_watershed_bem():
github mne-tools / mne-python / tutorials / raw / plot_30_annotate_raw.py View on Github external
.. contents:: Page contents
   :local:
   :depth: 1

As usual we'll start by importing the modules we need, loading some
:ref:`example data `, and (since we won't actually analyze the
raw data in this tutorial) cropping the :class:`~mne.io.Raw` object to just 60
seconds before loading it into RAM to save memory:
"""

import os
from datetime import timedelta
import mne

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
                                    'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.crop(tmax=60).load_data()

###############################################################################
# :class:`~mne.Annotations` in MNE-Python are a way of storing short strings of
# information about temporal spans of a :class:`~mne.io.Raw` object. Below the
# surface, :class:`~mne.Annotations` are :class:`list-like ` objects,
# where each element comprises three pieces of information: an ``onset`` time
# (in seconds), a ``duration`` (also in seconds), and a ``description`` (a text
# string). Additionally, the :class:`~mne.Annotations` object itself also keeps
# track of ``orig_time``, which is a `POSIX timestamp`_ denoting a real-world
# time relative to which the annotation onsets should be interpreted.
#
#
github mne-tools / mne-python / examples / inverse / plot_read_source_space.py View on Github external
This example visualizes a source space mesh used by a forward operator.
"""
# Author: Alexandre Gramfort 
#
# License: BSD (3-clause)


import os.path as op

import mne
from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()
subjects_dir = op.join(data_path, 'subjects')
fname = op.join(subjects_dir, 'sample', 'bem', 'sample-oct-6-src.fif')

patch_stats = True  # include high resolution source space
src = mne.read_source_spaces(fname, patch_stats=patch_stats)

# Plot the 3D source space (high sampling)
src.plot(subjects_dir=subjects_dir)
github mne-tools / mne-python / examples / simulation / plot_simulate_evoked_data.py View on Github external
# License: BSD (3-clause)

import numpy as np
import matplotlib.pyplot as plt

import mne
from mne.datasets import sample
from mne.time_frequency import fit_iir_model_raw
from mne.viz import plot_sparse_source_estimates
from mne.simulation import simulate_sparse_stc, simulate_evoked

print(__doc__)

###############################################################################
# Load real data as templates
data_path = sample.data_path()

raw = mne.io.read_raw_fif(data_path + '/MEG/sample/sample_audvis_raw.fif')
proj = mne.read_proj(data_path + '/MEG/sample/sample_audvis_ecg-proj.fif')
raw.info['projs'] += proj
raw.info['bads'] = ['MEG 2443', 'EEG 053']  # mark bad channels

fwd_fname = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif'
ave_fname = data_path + '/MEG/sample/sample_audvis-no-filter-ave.fif'
cov_fname = data_path + '/MEG/sample/sample_audvis-cov.fif'

fwd = mne.read_forward_solution(fwd_fname)
fwd = mne.pick_types_forward(fwd, meg=True, eeg=True, exclude=raw.info['bads'])
cov = mne.read_cov(cov_fname)
info = mne.io.read_info(ave_fname)

label_names = ['Aud-lh', 'Aud-rh']
github mne-tools / mne-python / tutorials / source-modeling / plot_object_source_estimate.py View on Github external
.. contents::
    :local:

Let's get ourselves an idea of what a :class:`mne.SourceEstimate` really
is. We first set up the environment and load some data:
"""

import os

from mne import read_source_estimate
from mne.datasets import sample

print(__doc__)

# Paths to example data
sample_dir_raw = sample.data_path()
sample_dir = os.path.join(sample_dir_raw, 'MEG', 'sample')
subjects_dir = os.path.join(sample_dir_raw, 'subjects')

fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')

###############################################################################
# Load and inspect example data
# -----------------------------
#
# This data set contains source estimation data from an audio visual task. It
# has been mapped onto the inflated cortical surface representation obtained
# from :ref:`FreeSurfer `
# using the dSPM method. It highlights a noticeable peak in the auditory
# cortices.
#
# Let's see how it looks like.
github mne-tools / mne-python / examples / io / plot_read_events.py View on Github external
Read events from a file. For a more detailed discussion of events in
MNE-Python, see :ref:`tut-events-vs-annotations` and :ref:`tut-event-arrays`.
"""
# Authors: Alexandre Gramfort 
#          Chris Holdgraf 
#
# License: BSD (3-clause)

import matplotlib.pyplot as plt
import mne
from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()
fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'

###############################################################################
# Reading events
# --------------
#
# Below we'll read in an events file. We suggest that this file end in
# ``-eve.fif``. Note that we can read in the entire events file, or only
# events corresponding to particular event types with the ``include`` and
# ``exclude`` parameters.

events_1 = mne.read_events(fname, include=1)
events_1_2 = mne.read_events(fname, include=[1, 2])
events_not_4_32 = mne.read_events(fname, exclude=[4, 32])

###############################################################################
github mne-tools / mne-python / examples / preprocessing / plot_interpolate_bad_channels.py View on Github external
----------
.. [1] Perrin, F., Pernier, J., Bertrand, O. and Echallier, JF. (1989)
       Spherical splines for scalp potential and current density mapping.
       Electroencephalography and Clinical Neurophysiology, Feb; 72(2):184-7.
"""
# Authors: Denis A. Engemann 
#          Mainak Jas 
#
# License: BSD (3-clause)

import mne
from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()

fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
evoked = mne.read_evokeds(fname, condition='Left Auditory',
                          baseline=(None, 0))

# plot with bads
evoked.plot(exclude=[], time_unit='s')

# compute interpolation (also works with Raw and Epochs objects)
evoked.interpolate_bads(reset_bads=False, verbose=False)

# plot interpolated (previous bads)
evoked.plot(exclude=[], time_unit='s')
github mne-tools / mne-python / tutorials / preprocessing / plot_30_filtering_resampling.py View on Github external
.. contents:: Page contents
   :local:
   :depth: 2

We begin as always by importing the necessary Python modules and loading some
:ref:`example data `. We'll also crop the data to 60 seconds
(to save memory on the documentation server):
"""

import os
import numpy as np
import matplotlib.pyplot as plt
import mne

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
                                    'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file)
raw.crop(0, 60).load_data()  # use just 60 seconds of data, to save memory

###############################################################################
# Background on filtering
# ^^^^^^^^^^^^^^^^^^^^^^^
#
# A filter removes or attenuates parts of a signal. Usually, filters act on
# specific *frequency ranges* of a signal — for example, suppressing all
# frequency components above or below a certain cutoff value. There are *many*
# ways of designing digital filters; see :ref:`disc-filtering` for a longer
# discussion of the various approaches to filtering physiological signals in
# MNE-Python.
#
github mne-tools / mne-python / examples / inverse / plot_mixed_source_space_inverse.py View on Github external
evoked dataset.
"""
# Author: Annalisa Pascarella 
#
# License: BSD (3-clause)

import os.path as op
import matplotlib.pyplot as plt

from nilearn import plotting

import mne
from mne.minimum_norm import make_inverse_operator, apply_inverse

# Set dir
data_path = mne.datasets.sample.data_path()
subject = 'sample'
data_dir = op.join(data_path, 'MEG', subject)
subjects_dir = op.join(data_path, 'subjects')
bem_dir = op.join(subjects_dir, subject, 'bem')

# Set file names
fname_mixed_src = op.join(bem_dir, '%s-oct-6-mixed-src.fif' % subject)
fname_aseg = op.join(subjects_dir, subject, 'mri', 'aseg.mgz')

fname_model = op.join(bem_dir, '%s-5120-bem.fif' % subject)
fname_bem = op.join(bem_dir, '%s-5120-bem-sol.fif' % subject)

fname_evoked = data_dir + '/sample_audvis-ave.fif'
fname_trans = data_dir + '/sample_audvis_raw-trans.fif'
fname_fwd = data_dir + '/sample_audvis-meg-oct-6-mixed-fwd.fif'
fname_cov = data_dir + '/sample_audvis-shrunk-cov.fif'
github pelednoam / mmvt / src / preproc / examples / eeg.py View on Github external
def calc_mne_python_sample_data(args):
    import mne
    mne_sample_data_fol = mne.datasets.sample.data_path()
    trans_fname = op.join(mne_sample_data_fol, 'MEG', 'sample', 'sample_audvis_raw-trans.fif')

    args = eeg.read_cmd_args(dict(
        subject=args.subject,
        mri_subject=args.mri_subject,
        function='read_sensors_layout,calc_evokes',
        # atlas='laus250',
        trans_fname=trans_fname,
        contrast='audvis',
        task='audvis',
        fname_format='{subject}_audvis-{ana_type}.{file_type}',
        fname_format_cond='{subject}_audvis_{cond}-{ana_type}.{file_type}',
        conditions=['LA', 'RA'],
        read_events_from_file=True,
        t_min=-0.2, t_max=0.5,
        extract_mode=['mean_flip'],#, 'mean', 'pca_flip'],