How to use the mne.io 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-biomag-group-demo / scripts / results / demos / plot_tsss_analysis.py View on Github external
# Configuration

subjects_dir = op.join(study_path, 'subjects')

subject = "sub003"
subject_dir = op.join(meg_dir, subject)
st_duration = 1

###############################################################################
# Continuous data
raw_fname = op.join(study_path, 'ds117', subject, 'MEG', 'run_01_raw.fif')
raw_filt_fname = op.join(subject_dir,
                         'run_01_filt_tsss_%d_raw.fif' % st_duration)

raw = mne.io.read_raw_fif(raw_fname)
raw_filt = mne.io.read_raw_fif(raw_filt_fname)

###############################################################################
# Filtering :ref:`sphx_glr_auto_scripts_04-python_filtering.py`.
raw.plot_psd(n_fft=8192, average=False, xscale='log', show=False)
raw_filt.plot_psd(n_fft=8192, average=False, xscale='log')

###############################################################################
# Events :ref:`sphx_glr_auto_scripts_02-extract_events.py`.
# Epochs :ref:`sphx_glr_auto_scripts_06-make_epochs.py`.
eve_fname = op.join(subject_dir, 'run_01-eve.fif')
epo_fname = op.join(subject_dir, '%s-tsss_%d-epo.fif' % (subject, st_duration))

events = mne.read_events(eve_fname)
fig = mne.viz.plot_events(events, show=False)
fig.suptitle('Events from run 01')
github mne-tools / mne-biomag-group-demo / scripts / results / plot_analysis_14.py View on Github external
###############################################################################
# Configuration

subjects_dir = op.join(study_path, 'subjects')

subject = "sub%03d" % int(14)
subject_dir = op.join(meg_dir, subject)

###############################################################################
# Continuous data
raw_fname = op.join(study_path, 'ds117', subject, 'MEG', 'run_01_raw.fif')
raw_filt_fname = op.join(subject_dir,
                         'run_01_filt_sss_highpass-%sHz_raw.fif' % l_freq)
raw = mne.io.read_raw_fif(raw_fname)
raw_filt = mne.io.read_raw_fif(raw_filt_fname)

###############################################################################
# Filtering :ref:`sphx_glr_auto_scripts_02-python_filtering.py`.
raw.plot_psd(n_fft=2048, n_overlap=1024)
raw_filt.plot_psd()

###############################################################################
# Events :ref:`sphx_glr_auto_scripts_03-run_extract_events.py`.
# Epochs :ref:`sphx_glr_auto_scripts_05-make_epochs.py`.
eve_fname = op.join(subject_dir, 'run_01_filt_sss-eve.fif')
epo_fname = op.join(subject_dir,
                    '%s_highpass-%sHz-epo.fif' % (subject, l_freq))

events = mne.read_events(eve_fname)
fig = mne.viz.plot_events(events, show=False)
fig.suptitle('Events from run 01')
github mne-tools / mne-python / examples / realtime / plot_ftclient_rt_average.py View on Github external
import os.path as op
import subprocess

import mne
from mne.viz import plot_events
from mne.realtime import FieldTripClient, RtEpochs
from mne.utils import running_subprocess

import matplotlib.pyplot as plt

print(__doc__)

# user should provide info and list of bad channels because
# FieldTrip header object does not provide them
data_path = mne.datasets.sample.data_path()
info = mne.io.read_info(op.join(data_path, 'MEG', 'sample',
                                'sample_audvis_raw.fif'))

# select the left-auditory condition
event_id, tmin, tmax = 1, -0.2, 0.5

# user must provide list of bad channels because
# FieldTrip header object does not provide that
bads = ['MEG 2443', 'EEG 053']

_, ax = plt.subplots(2, 1, figsize=(8, 8))  # create subplots

speedup = 10
command = ["neuromag2ft", "--file",
           "{}/MEG/sample/sample_audvis_raw.fif".format(data_path),
           "--speed", str(speedup)]
with running_subprocess(command, after='kill',
github pelednoam / mmvt / src / examples / hcp / analyze_hcp.py View on Github external
def analyze_rest(subject, args, hcp_params, run_index=0, calc_rest_from_raw=False, calc_rest_from_epochs=True):
    flags = {}
    if not op.isfile(meg.RAW):
        raw = read_raw_data(run_index, hcp_params, 1, 60)
        raw.save(meg.RAW)
    else:
        raw = mne.io.read_raw_fif(meg.RAW)
    meg.COR = op.join(op.join(HCP_DIR, 'hcp-meg', subject, '{}-head_mri-trans.fif'.format(subject)))
    epo_fname = meg.EPO.format(cond='all')
    evo_fname = meg.EVO.format(cond='all')
    if not op.isfile(epo_fname) or not op.isfile(evo_fname):
        epochs = hcp.read_epochs(run_index=run_index, **hcp_params)
        evoked = epochs.average()
        epochs.save(epo_fname)
        mne.write_evokeds(evo_fname, evoked)
    else:
        epochs = mne.read_epochs(epo_fname)
    meg.calc_fwd_inv_wrapper(subject, args)
    args.snr = 1.0  # use smaller SNR for raw data
    # args.overwrite_labels_data = True
    # args.n_jobs = 1
    if calc_rest_from_raw:
        meg.calc_labels_avg_for_rest_wrapper(args, raw)
github mne-tools / mne-biomag-group-demo / scripts / results / plot_analysis_18.py View on Github external
###############################################################################
# Configuration

subjects_dir = op.join(study_path, 'subjects')

subject = "sub%03d" % int(18)
subject_dir = op.join(meg_dir, subject)

###############################################################################
# Continuous data
raw_fname = op.join(study_path, 'ds117', subject, 'MEG', 'run_01_raw.fif')
raw_filt_fname = op.join(subject_dir,
                         'run_01_filt_sss_highpass-%sHz_raw.fif' % l_freq)
raw = mne.io.read_raw_fif(raw_fname)
raw_filt = mne.io.read_raw_fif(raw_filt_fname)

###############################################################################
# Filtering :ref:`sphx_glr_auto_scripts_02-python_filtering.py`.
raw.plot_psd(n_fft=2048, n_overlap=1024)
raw_filt.plot_psd()

###############################################################################
# Events :ref:`sphx_glr_auto_scripts_03-run_extract_events.py`.
# Epochs :ref:`sphx_glr_auto_scripts_05-make_epochs.py`.
eve_fname = op.join(subject_dir, 'run_01_filt_sss-eve.fif')
epo_fname = op.join(subject_dir,
                    '%s_highpass-%sHz-epo.fif' % (subject, l_freq))

events = mne.read_events(eve_fname)
fig = mne.viz.plot_events(events, show=False)
fig.suptitle('Events from run 01')
github alexandrebarachant / pyRiemann / examples / ERP / classify_MEG.py View on Github external
print(__doc__)

data_path = sample.data_path()

###############################################################################
# Set parameters and read data
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
tmin, tmax = -0.2, 0.5
event_id = dict(aud_l=1, vis_l=3)

# Setup for reading the raw data
raw = io.Raw(raw_fname, preload=True)
raw.filter(2, None, method='iir')  # replace baselining with high-pass
events = mne.read_events(event_fname)

raw.info['bads'] = ['MEG 2443']  # set bad channels
picks = mne.pick_types(raw.info, meg='grad', eeg=False, stim=False, eog=False,
                       exclude='bads')

# Read epochs
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=False,
                    picks=picks, baseline=None, preload=True)

labels = epochs.events[:, -1]
evoked = epochs.average()

###############################################################################
# Decoding in sensor space using a MDM
github TNTLFreiburg / braindecode / braindecode / datasets / bcic_iv_2a.py View on Github external
# correct nan values

        data = raw_gdf.get_data()

        for i_chan in range(data.shape[0]):
            # first set to nan, than replace nans by nanmean.
            this_chan = data[i_chan]
            data[i_chan] = np.where(
                this_chan == np.min(this_chan), np.nan, this_chan
            )
            mask = np.isnan(data[i_chan])
            chan_mean = np.nanmean(data[i_chan])
            data[i_chan, mask] = chan_mean

        gdf_events = mne.events_from_annotations(raw_gdf)
        raw_gdf = mne.io.RawArray(data, raw_gdf.info, verbose="WARNING")
        # remember gdf events
        raw_gdf.info["gdf_events"] = gdf_events
        return raw_gdf
github pelednoam / mmvt / src / preproc / meg.py View on Github external
def load_raw(bad_channels=[], l_freq=None, h_freq=None):
    # read the data
    raw_fname, raw_exist = locating_file(RAW, glob_pattern='*raw.fif')
    if not raw_exist:
        return None
    raw = mne.io.read_raw_fif(raw_fname, preload=True)
    if not op.isfile(INFO):
        utils.save(raw.info, INFO)
    if len(bad_channels) > 0:
        raw.info['bads'] = args.bad_channels
    if l_freq or h_freq:
        raw = raw.filter(l_freq, h_freq)
    return raw
github mne-tools / mne-python / examples / connectivity / plot_cwt_sensor_connectivity.py View on Github external
import mne
from mne import io
from mne.connectivity import spectral_connectivity, seed_target_indices
from mne.datasets import sample
from mne.time_frequency import AverageTFR

print(__doc__)

###############################################################################
# Set parameters
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'

# Setup for reading the raw data
raw = io.read_raw_fif(raw_fname)
events = mne.read_events(event_fname)

# Add a bad channel
raw.info['bads'] += ['MEG 2443']

# Pick MEG gradiometers
picks = mne.pick_types(raw.info, meg='grad', eeg=False, stim=False, eog=True,
                       exclude='bads')

# Create epochs for left-visual condition
event_id, tmin, tmax = 3, -0.2, 0.5
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
                    baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6),
                    preload=True)

# Use 'MEG 2343' as seed
github pierreablin / picard / _downloads / plot_ica_eeg.py View on Github external
import numpy as np
import matplotlib.pyplot as plt
import mne
from mne.datasets import sample
from sklearn.decomposition import PCA

from picard import picard

print(__doc__)

###############################################################################
# Generate sample EEG data
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'

raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.filter(1, 40, n_jobs=1)  # 1Hz high pass is often helpful for fitting ICA

picks = mne.pick_types(raw.info, meg=False, eeg=True, eog=False,
                       stim=False, exclude='bads')

random_state = 0
data = raw[picks, :][0]
data = data[:, ::2]  # decimate a bit

# Center
data -= np.mean(data, axis=1, keepdims=True)

# Apply PCA for dimension reduction and whitenning.

n_components = 30
pca = PCA(n_components=n_components, whiten=True, svd_solver='full')