本文整理汇总了Python中mne.io.Raw.save方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.save方法的具体用法?Python Raw.save怎么用?Python Raw.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.Raw
的用法示例。
在下文中一共展示了Raw.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_split_files
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_split_files():
"""Test writing and reading of split raw files
"""
tempdir = _TempDir()
raw_1 = Raw(fif_fname, preload=True)
assert_allclose(raw_1.info['buffer_size_sec'], 10., atol=1e-2) # samp rate
split_fname = op.join(tempdir, 'split_raw.fif')
raw_1.save(split_fname, buffer_size_sec=1.0, split_size='10MB')
raw_2 = Raw(split_fname)
assert_allclose(raw_2.info['buffer_size_sec'], 1., atol=1e-2) # samp rate
data_1, times_1 = raw_1[:, :]
data_2, times_2 = raw_2[:, :]
assert_array_equal(data_1, data_2)
assert_array_equal(times_1, times_2)
# test the case where the silly user specifies the split files
fnames = [split_fname]
fnames.extend(sorted(glob.glob(op.join(tempdir, 'split_raw-*.fif'))))
with warnings.catch_warnings(record=True):
warnings.simplefilter('always')
raw_2 = Raw(fnames)
data_2, times_2 = raw_2[:, :]
assert_array_equal(data_1, data_2)
assert_array_equal(times_1, times_2)
示例2: test_save
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_save():
""" Test saving raw"""
tempdir = _TempDir()
raw = Raw(fif_fname, preload=False)
# can't write over file being read
assert_raises(ValueError, raw.save, fif_fname)
raw = Raw(fif_fname, preload=True)
# can't overwrite file without overwrite=True
assert_raises(IOError, raw.save, fif_fname)
# test abspath support and annotations
annot = Annotations([10], [10], ['test'], raw.info['meas_date'])
raw.annotations = annot
new_fname = op.join(op.abspath(op.curdir), 'break-raw.fif')
raw.save(op.join(tempdir, new_fname), overwrite=True)
new_raw = Raw(op.join(tempdir, new_fname), preload=False)
assert_raises(ValueError, new_raw.save, new_fname)
assert_array_equal(annot.onset, new_raw.annotations.onset)
assert_array_equal(annot.duration, new_raw.annotations.duration)
assert_array_equal(annot.description, new_raw.annotations.description)
assert_equal(annot.orig_time, new_raw.annotations.orig_time)
# make sure we can overwrite the file we loaded when preload=True
new_raw = Raw(op.join(tempdir, new_fname), preload=True)
new_raw.save(op.join(tempdir, new_fname), overwrite=True)
os.remove(new_fname)
示例3: test_preload_modify
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_preload_modify():
"""Test preloading and modifying data
"""
tempdir = _TempDir()
for preload in [False, True, 'memmap.dat']:
raw = Raw(fif_fname, preload=preload)
nsamp = raw.last_samp - raw.first_samp + 1
picks = pick_types(raw.info, meg='grad', exclude='bads')
data = rng.randn(len(picks), nsamp // 2)
try:
raw[picks, :nsamp // 2] = data
except RuntimeError as err:
if not preload:
continue
else:
raise err
tmp_fname = op.join(tempdir, 'raw.fif')
raw.save(tmp_fname, overwrite=True)
raw_new = Raw(tmp_fname)
data_new, _ = raw_new[picks, :nsamp / 2]
assert_allclose(data, data_new)
示例4: test_subject_info
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_subject_info():
"""Test reading subject information
"""
tempdir = _TempDir()
raw = Raw(fif_fname)
raw.crop(0, 1, False)
assert_true(raw.info['subject_info'] is None)
# fake some subject data
keys = ['id', 'his_id', 'last_name', 'first_name', 'birthday', 'sex',
'hand']
vals = [1, 'foobar', 'bar', 'foo', (1901, 2, 3), 0, 1]
subject_info = dict()
for key, val in zip(keys, vals):
subject_info[key] = val
raw.info['subject_info'] = subject_info
out_fname = op.join(tempdir, 'test_subj_info_raw.fif')
raw.save(out_fname, overwrite=True)
raw_read = Raw(out_fname)
for key in keys:
assert_equal(subject_info[key], raw_read.info['subject_info'][key])
raw_read.anonymize()
assert_true(raw_read.info.get('subject_info') is None)
out_fname_anon = op.join(tempdir, 'test_subj_info_anon_raw.fif')
raw_read.save(out_fname_anon, overwrite=True)
raw_read = Raw(out_fname_anon)
assert_true(raw_read.info.get('subject_info') is None)
示例5: perform_detrending
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def perform_detrending(fname_raw, save=True):
from mne.io import Raw
from numpy import poly1d, polyfit
fnraw = get_files_from_list(fname_raw)
# loop across all filenames
for fname in fnraw:
# read data in
raw = Raw(fname, preload=True)
# get channels
picks = mne.pick_types(raw.info, meg='mag', ref_meg=True, eeg=False, stim=False,
eog=False, exclude='bads')
xval = np.arange(raw._data.shape[1])
# loop over all channels
for ipick in picks:
coeff = polyfit(xval, raw._data[ipick, :], deg=1)
trend = poly1d(coeff)
raw._data[ipick, :] -= trend(xval)
# save detrended data
if save:
fnout = fname_raw[:fname_raw.rfind('-raw.fif')] + ',dt-raw.fif'
raw.save(fnout, overwrite=True)
return raw
示例6: test_subject_info
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_subject_info():
"""Test reading subject information
"""
tempdir = _TempDir()
raw = Raw(fif_fname).crop(0, 1, False)
assert_true(raw.info['subject_info'] is None)
# fake some subject data
keys = ['id', 'his_id', 'last_name', 'first_name', 'birthday', 'sex',
'hand']
vals = [1, 'foobar', 'bar', 'foo', (1901, 2, 3), 0, 1]
subject_info = dict()
for key, val in zip(keys, vals):
subject_info[key] = val
raw.info['subject_info'] = subject_info
out_fname = op.join(tempdir, 'test_subj_info_raw.fif')
raw.save(out_fname, overwrite=True)
raw_read = Raw(out_fname)
for key in keys:
assert_equal(subject_info[key], raw_read.info['subject_info'][key])
assert_equal(raw.info['meas_date'], raw_read.info['meas_date'])
raw.anonymize()
raw.save(out_fname, overwrite=True)
raw_read = Raw(out_fname)
for this_raw in (raw, raw_read):
assert_true(this_raw.info.get('subject_info') is None)
assert_equal(this_raw.info['meas_date'], [0, 0])
assert_equal(raw.info['file_id']['secs'], 0)
assert_equal(raw.info['meas_id']['secs'], 0)
# When we write out with raw.save, these get overwritten with the
# new save time
assert_true(raw_read.info['file_id']['secs'] > 0)
assert_true(raw_read.info['meas_id']['secs'] > 0)
示例7: filter_data
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def filter_data(subject, l_freq=l_freq, h_freq=h_freq, n_freq=n_freq,
save=True, n_jobs=1):
"""Filter the data.
params:
subject : str
the subject id to be loaded
l_freq : int
the low frequency to filter
h_freq : int
the high frequency to filter
n_freq : int
the notch filter frequency
save : bool
save the filtered data
n_jobs : int
The number of CPUs to use in parallel.
"""
raw = Raw(maxfiltered_folder + "%s_data_mc_raw_tsss.fif" % subject,
preload=True)
if n_freq is not None:
raw.notch_filter(n_freq, n_jobs=n_jobs)
raw.filter(l_freq, h_freq, n_jobs=n_jobs)
if save is True:
raw.save(save_folder + "%s_filtered_data_mc_raw_tsss.fif" % subject,
overwrite=True)
示例8: test_compute_proj_raw
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_compute_proj_raw():
"""Test SSP computation on raw"""
# Test that the raw projectors work
raw_time = 2.5 # Do shorter amount for speed
raw = Raw(raw_fname, preload=True).crop(0, raw_time, False)
for ii in (0.25, 0.5, 1, 2):
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw, duration=ii - 0.1, stop=raw_time,
n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(w) == 1)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, raw.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
raw.info['projs'] += projs
raw.save(op.join(tempdir, 'foo_%d_raw.fif' % ii), overwrite=True)
# Test that purely continuous (no duration) raw projection works
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw, duration=None, stop=raw_time,
n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(w) == 1)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, raw.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
raw.info['projs'] += projs
raw.save(op.join(tempdir, 'foo_rawproj_continuous_raw.fif'))
# test resampled-data projector, upsampling instead of downsampling
# here to save an extra filtering (raw would have to be LP'ed to be equiv)
raw_resamp = cp.deepcopy(raw)
raw_resamp.resample(raw.info['sfreq'] * 2, n_jobs=2)
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw_resamp, duration=None, stop=raw_time,
n_grad=1, n_mag=1, n_eeg=0)
projs = activate_proj(projs)
proj_new, _, _ = make_projector(projs, raw.ch_names, bads=[])
assert_array_almost_equal(proj_new, proj, 4)
# test with bads
raw.load_bad_channels(bads_fname) # adds 2 bad mag channels
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw, n_grad=0, n_mag=0, n_eeg=1)
# test that bad channels can be excluded
proj, nproj, U = make_projector(projs, raw.ch_names,
bads=raw.ch_names)
assert_array_almost_equal(proj, np.eye(len(raw.ch_names)))
示例9: test_proj
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_proj():
"""Test SSP proj operations
"""
tempdir = _TempDir()
for proj in [True, False]:
raw = Raw(fif_fname, preload=False, proj=proj)
assert_true(all(p['active'] == proj for p in raw.info['projs']))
data, times = raw[0:2, :]
data1, times1 = raw[0:2]
assert_array_equal(data, data1)
assert_array_equal(times, times1)
# test adding / deleting proj
if proj:
assert_raises(ValueError, raw.add_proj, [],
{'remove_existing': True})
assert_raises(ValueError, raw.del_proj, 0)
else:
projs = deepcopy(raw.info['projs'])
n_proj = len(raw.info['projs'])
raw.del_proj(0)
assert_true(len(raw.info['projs']) == n_proj - 1)
raw.add_proj(projs, remove_existing=False)
assert_true(len(raw.info['projs']) == 2 * n_proj - 1)
raw.add_proj(projs, remove_existing=True)
assert_true(len(raw.info['projs']) == n_proj)
# test apply_proj() with and without preload
for preload in [True, False]:
raw = Raw(fif_fname, preload=preload, proj=False)
data, times = raw[:, 0:2]
raw.apply_proj()
data_proj_1 = np.dot(raw._projector, data)
# load the file again without proj
raw = Raw(fif_fname, preload=preload, proj=False)
# write the file with proj. activated, make sure proj has been applied
raw.save(op.join(tempdir, 'raw.fif'), proj=True, overwrite=True)
raw2 = Raw(op.join(tempdir, 'raw.fif'), proj=False)
data_proj_2, _ = raw2[:, 0:2]
assert_allclose(data_proj_1, data_proj_2)
assert_true(all(p['active'] for p in raw2.info['projs']))
# read orig file with proj. active
raw2 = Raw(fif_fname, preload=preload, proj=True)
data_proj_2, _ = raw2[:, 0:2]
assert_allclose(data_proj_1, data_proj_2)
assert_true(all(p['active'] for p in raw2.info['projs']))
# test that apply_proj works
raw.apply_proj()
data_proj_2, _ = raw[:, 0:2]
assert_allclose(data_proj_1, data_proj_2)
assert_allclose(data_proj_2, np.dot(raw._projector, data_proj_2))
示例10: test_hpi_info
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_hpi_info():
"""Test getting HPI info
"""
tempdir = _TempDir()
temp_name = op.join(tempdir, "temp_raw.fif")
for fname in (chpi_fif_fname, sss_fif_fname):
raw = Raw(fname, allow_maxshield="yes")
assert_true(len(raw.info["hpi_subsystem"]) > 0)
raw.save(temp_name, overwrite=True)
raw_2 = Raw(temp_name, allow_maxshield="yes")
assert_equal(len(raw_2.info["hpi_subsystem"]), len(raw.info["hpi_subsystem"]))
示例11: test_clean_eog_ecg
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_clean_eog_ecg():
"""Test mne clean_eog_ecg"""
check_usage(mne_clean_eog_ecg)
tempdir = _TempDir()
raw = Raw([raw_fname, raw_fname, raw_fname])
raw.info['bads'] = ['MEG 2443']
use_fname = op.join(tempdir, op.basename(raw_fname))
raw.save(use_fname)
with ArgvSetter(('-i', use_fname, '--quiet')):
mne_clean_eog_ecg.run()
fnames = glob.glob(op.join(tempdir, '*proj.fif'))
assert_true(len(fnames) == 2) # two projs
fnames = glob.glob(op.join(tempdir, '*-eve.fif'))
assert_true(len(fnames) == 3) # raw plus two projs
示例12: test_hpi_info
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_hpi_info():
"""Test getting HPI info
"""
tempdir = _TempDir()
temp_name = op.join(tempdir, 'temp_raw.fif')
for fname in (chpi_fif_fname, sss_fif_fname):
with warnings.catch_warnings(record=True):
warnings.simplefilter('always')
raw = Raw(fname, allow_maxshield=True)
assert_true(len(raw.info['hpi_subsystem']) > 0)
raw.save(temp_name, overwrite=True)
with warnings.catch_warnings(record=True):
warnings.simplefilter('always')
raw_2 = Raw(temp_name, allow_maxshield=True)
assert_equal(len(raw_2.info['hpi_subsystem']),
len(raw.info['hpi_subsystem']))
示例13: test_save
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_save():
""" Test saving raw"""
raw = Raw(fif_fname, preload=False)
# can't write over file being read
assert_raises(ValueError, raw.save, fif_fname)
raw = Raw(fif_fname, preload=True)
# can't overwrite file without overwrite=True
assert_raises(IOError, raw.save, fif_fname)
# test abspath support
new_fname = op.join(op.abspath(op.curdir), 'break.fif')
raw.save(op.join(tempdir, new_fname), overwrite=True)
new_raw = Raw(op.join(tempdir, new_fname), preload=False)
assert_raises(ValueError, new_raw.save, new_fname)
# make sure we can overwrite the file we loaded when preload=True
new_raw = Raw(op.join(tempdir, new_fname), preload=True)
new_raw.save(op.join(tempdir, new_fname), overwrite=True)
os.remove(new_fname)
示例14: merge_fif_from_eo_ec
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def merge_fif_from_eo_ec(Subj_ID):
from mne.io import Raw
import pandas as pd
from table_handling import get_eo_ec_by_name
from params import main_path
Subj_ID_ec = Subj_ID + ' CLOSED'
Subj_ID_eo = Subj_ID + ' OPEN'
eo_ec_table_fname = main_path + 'Aut_gamma_EO_EC_Timing.xls'
suffix_open = '_rest_open_raw_tsss_mc_trans.fif'
suffix_closed = '_rest_closed_raw_tsss_mc_trans.fif'
suffix_merged = '_rest_raw_tsss_mc_trans.fif'
filename_ec = main_path + 'MEG/' + Subj_ID + '/' + Subj_ID + suffix_closed
filename_eo = main_path + 'MEG/' + Subj_ID + '/' + Subj_ID + suffix_open
filename_merged = main_path + 'MEG/' + Subj_ID + '/' + Subj_ID + suffix_merged
if Subj_ID[0] == 'K':
sheetname = 'Control'
elif Subj_ID[0] == 'R':
sheetname = 'ASD'
eo_ec_table = pd.read_excel(eo_ec_table_fname, skiprows=[1], sheetname=sheetname)
idx_Subj_ID_ec = eo_ec_table.Subj_ID == Subj_ID_ec
idx_Subj_ID_eo = eo_ec_table.Subj_ID == Subj_ID_eo
first_samp_ec = eo_ec_table[idx_Subj_ID_ec]['#f'].get_values()[0]
first_samp_eo = eo_ec_table[idx_Subj_ID_eo]['#f'].get_values()[0]
raw_eo = Raw(filename_eo)
raw_ec = Raw(filename_ec)
ec_length = round(raw_ec.times[-1], 0)
raw_ec.append(raw_eo)
raw_ec.save(filename_merged, overwrite=True)
# lCondStart, lCondEnd, first_samp, cond = \
# get_eo_ec_by_name(Subj_ID_ec, 'ec')
lCondStart_eo, lCondEnd_eo, _, _ = \
get_eo_ec_by_name(Subj_ID_eo, 'eo')
lCondStart_eo = [time + ec_length - first_samp_eo + first_samp_ec for time in lCondStart_eo]
lCondEnd_eo = [time + ec_length - first_samp_eo + first_samp_ec for time in lCondEnd_eo]
print 'EO start times : {}'.format(lCondStart_eo)
print 'EO end times : {}'.format(lCondEnd_eo)
print 'Merged file length: {} seconds'.format(round(raw_ec.times[-1], 0))
return
示例15: test_output_formats
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import save [as 别名]
def test_output_formats():
"""Test saving and loading raw data using multiple formats
"""
formats = ["short", "int", "single", "double"]
tols = [1e-4, 1e-7, 1e-7, 1e-15]
# let's fake a raw file with different formats
raw = Raw(fif_fname, preload=True)
raw.crop(0, 1, copy=False)
temp_file = op.join(tempdir, "raw.fif")
for ii, (format, tol) in enumerate(zip(formats, tols)):
# Let's test the overwriting error throwing while we're at it
if ii > 0:
assert_raises(IOError, raw.save, temp_file, format=format)
raw.save(temp_file, format=format, overwrite=True)
raw2 = Raw(temp_file)
raw2_data = raw2[:, :][0]
assert_allclose(raw2_data, raw._data, rtol=tol, atol=1e-25)
assert_true(raw2.orig_format == format)