Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
# Try loading mne
try:
import mne
except ImportError:
raise ImportError(
"NeuroKit error: mne_data(): the 'mne' module is required for this function to run. ",
"Please install it first (`pip install mne`).",
)
old_verbosity_level = mne.set_log_level(verbose="WARNING", return_old_level=True)
if what in ["raw", "filt-0-40_raw"]:
path = mne.datasets.sample.data_path()
path += '/MEG/sample/sample_audvis_' + what + '.fif'
data = mne.io.read_raw_fif(path, preload=True)
data = data.pick_types(meg=False, eeg=True)
mne.set_log_level(old_verbosity_level)
return data
###############################################################################
# Configuration
subjects_dir = op.join(study_path, 'subjects')
subject = "sub%03d" % int(6)
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')
from library.config import study_path, meg_dir, ylim, l_freq
###############################################################################
# Configuration
subjects_dir = op.join(study_path, 'subjects')
subject = "sub%03d" % int(6)
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)
from mne_features.univariate import compute_spect_slope
from mne_features.utils import power_spectrum
print(__doc__)
###############################################################################
# Let us import the data using MNE-Python and epoch it:
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'
tmin, tmax = -0.2, 0.5
event_id = dict(aud_l=1, vis_l=3)
# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.filter(.5, None, fir_design='firwin')
###############################################################################
# Estimate the slope (and the intercept) of the PSD. We use here a single
# MEG channel during the full recording to estimate the slope and the
# intercept.
data, _ = raw[0, :2048]
# data = epochs.get_data()[0, 1, :].reshape((1, -1))
sfreq = raw.info['sfreq']
# Compute the (one-sided) PSD using FFT. The ``mask`` variable allows to
# select only the part of the PSD which corresponds to frequencies between
# 0.1Hz and 40Hz (the data used in this example is already low-pass filtered
# at 40Hz).
psd, freqs = power_spectrum(sfreq, data)
def analyze_meg(subject, seizure_time, seizure_len):
raw, evoked = None, None
meg_raw_fnames = [op.join(MEG_ROOT, 'nmr01209_6213848_07', 'nmr01209_6213848_07_Resting_eeg_meg_ica-raw.fif'),
op.join(MEG_DIR, subject, 'nmr01209_6213848_07_Resting_eeg_meg_ica-raw.fif')]
meg_raw_fname = [f for f in meg_raw_fnames if op.isfile(f)][0]
# empty_room_fname = '/space/megraid/77/MEG/noise/no_name/'
meg_raw_fname_seizure = op.join(MEG_DIR, subject, '{}_meg_seizure-raw.fif'.format(subject))
meg_evoked_fname = op.join(MEG_DIR, subject, '{}_meg_seizure-ave.fif'.format(subject))
eeg_evoked_fname = op.join(MEG_DIR, subject, '{}_eeg_seizure-ave.fif'.format(subject))
meeg_evoked_fname = op.join(MEG_DIR, subject, '{}_meeg_seizure-ave.fif'.format(subject))
if not op.isfile(meg_raw_fname_seizure):
raw = mne.io.read_raw_fif(meg_raw_fname)
raw.set_eeg_reference('average', projection=True) # set EEG average reference
raw = raw.crop(seizure_time-2, seizure_time+seizure_len)
raw.save(meg_raw_fname_seizure)
# raw.plot(block=True)
# raw.plot(butterfly=True, group_by='position')
meg.read_sensors_layout(subject, info=raw.info, overwrite_sensors=False)
eeg.read_sensors_layout(subject, info=raw.info, overwrite_sensors=False)
if not op.isfile(meg_evoked_fname) or not op.isfile(eeg_evoked_fname) or not op.isfile(meeg_evoked_fname):
if raw is None:
raw = mne.io.read_raw_fif(meg_raw_fname_seizure)
evoked = mne.EvokedArray(raw.get_data(), raw.info, comment='seizure')
meeg_evoked = evoked.pick_types(meg=True, eeg=True)
mne.write_evokeds(meeg_evoked_fname, meeg_evoked)
eog_event_fname : str
name of EOG event file required.
eog : bool
Reject or not EOG artifacts.
ecg : bool
Reject or not ECG artifacts.
ecg_event_fname : str
name of ECG event file required.
in_path : str
Path where all the files are.
"""
if not eog and not ecg:
raise Exception("EOG and ECG cannot be both disabled")
# Reading fif File
raw_in = mne.io.read_raw_fif(in_fif_fname)
if in_fif_fname.endswith('_raw.fif') or in_fif_fname.endswith('-raw.fif'):
prefix = in_fif_fname[:-8]
else:
prefix = in_fif_fname[:-4]
if out_fif_fname is None:
out_fif_fname = prefix + '_clean_ecg_eog_raw.fif'
if ecg_proj_fname is None:
ecg_proj_fname = prefix + '_ecg-proj.fif'
if eog_proj_fname is None:
eog_proj_fname = prefix + '_eog-proj.fif'
if ecg_event_fname is None:
ecg_event_fname = prefix + '_ecg-eve.fif'
if eog_event_fname is None:
eog_event_fname = prefix + '_eog-eve.fif'
from library.config import study_path, meg_dir, ylim, l_freq
###############################################################################
# Configuration
subjects_dir = op.join(study_path, 'subjects')
subject = "sub%03d" % int(11)
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)
from library.config import study_path, meg_dir, ylim, l_freq
###############################################################################
# Configuration
subjects_dir = op.join(study_path, 'subjects')
subject = "sub%03d" % int(12)
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)
from mne.viz import plot_compare_evokeds
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'
event_id = {'Aud/L': 1, 'Aud/R': 2, 'Vis/L': 3, 'Vis/R': 4}
tmin = -0.2
tmax = 0.5
# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.filter(1, 30, fir_design='firwin')
events = mne.read_events(event_fname)
###############################################################################
# Read epochs for the channel of interest
# ---------------------------------------
picks = mne.pick_types(raw.info, meg='mag', eog=True)
reject = dict(mag=4e-12, eog=150e-6)
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=None, reject=reject, preload=True)
epochs.drop_channels(['EOG 061'])
epochs.equalize_event_counts(event_id)
bids_basename = make_bids_basename(subject=subject,
session=session,
task=config.get_task(),
acquisition=config.acq,
run=None,
processing=config.proc,
recording=config.rec,
space=config.space,
prefix=deriv_path,
suffix='emptyroom_filt_raw.fif')
extra_params = dict()
if not config.use_maxwell_filter and config.allow_maxshield:
extra_params['allow_maxshield'] = config.allow_maxshield
raw_er_filtered = mne.io.read_raw_fif(bids_basename, preload=True,
**extra_params)
fig = raw_er_filtered.plot_psd(show=False)
return fig