本文整理汇总了Python中mne.io.Raw.crop方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.crop方法的具体用法?Python Raw.crop怎么用?Python Raw.crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.Raw
的用法示例。
在下文中一共展示了Raw.crop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_chpi_subtraction
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_chpi_subtraction():
"""Test subtraction of cHPI signals"""
raw = Raw(chpi_fif_fname, allow_maxshield='yes', preload=True)
with catch_logging() as log:
filter_chpi(raw, include_line=False, verbose=True)
assert_true('5 cHPI' in log.getvalue())
# MaxFilter doesn't do quite as well as our algorithm with the last bit
raw.crop(0, 16, copy=False)
raw_c = Raw(sss_hpisubt_fname, preload=True).crop(0, 16, copy=False)
raw_c.pick_types(meg=True, eeg=True, eog=True, ecg=True, stim=True,
misc=True, copy=False) # remove cHPI status chans
assert_meg_snr(raw, raw_c, 143, 624)
# Degenerate cases
raw_nohpi = Raw(test_fif_fname, preload=True)
assert_raises(RuntimeError, filter_chpi, raw_nohpi)
# When MaxFliter downsamples, like::
# $ maxfilter -nosss -ds 2 -f test_move_anon_raw.fif \
# -o test_move_anon_ds2_raw.fif
# it can strip out some values of info, which we emulate here:
raw = Raw(chpi_fif_fname, allow_maxshield='yes')
raw.crop(0, 1, copy=False).load_data()
raw.resample(600., npad='auto')
raw.info['buffer_size_sec'] = np.float64(2.)
raw.info['lowpass'] = 200.
del raw.info['maxshield']
del raw.info['hpi_results'][0]['moments']
del raw.info['hpi_subsystem']['event_channel']
with catch_logging() as log:
filter_chpi(raw, verbose=True)
assert_true('2 cHPI' in log.getvalue())
示例2: test_chpi_subtraction
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_chpi_subtraction():
"""Test subtraction of cHPI signals"""
raw = Raw(chpi_fif_fname, allow_maxshield="yes", preload=True)
with catch_logging() as log:
filter_chpi(raw, include_line=False, verbose=True)
assert_true("5 cHPI" in log.getvalue())
# MaxFilter doesn't do quite as well as our algorithm with the last bit
raw.crop(0, 16, copy=False)
# remove cHPI status chans
raw_c = Raw(sss_hpisubt_fname).crop(0, 16, copy=False).load_data()
raw_c.pick_types(meg=True, eeg=True, eog=True, ecg=True, stim=True, misc=True)
assert_meg_snr(raw, raw_c, 143, 624)
# Degenerate cases
raw_nohpi = Raw(test_fif_fname, preload=True)
assert_raises(RuntimeError, filter_chpi, raw_nohpi)
# When MaxFliter downsamples, like::
# $ maxfilter -nosss -ds 2 -f test_move_anon_raw.fif \
# -o test_move_anon_ds2_raw.fif
# it can strip out some values of info, which we emulate here:
raw = Raw(chpi_fif_fname, allow_maxshield="yes")
with warnings.catch_warnings(record=True): # uint cast suggestion
raw = raw.crop(0, 1).load_data().resample(600.0, npad="auto")
raw.info["buffer_size_sec"] = np.float64(2.0)
raw.info["lowpass"] = 200.0
del raw.info["maxshield"]
del raw.info["hpi_results"][0]["moments"]
del raw.info["hpi_subsystem"]["event_channel"]
with catch_logging() as log:
filter_chpi(raw, verbose=True)
assert_true("2 cHPI" in log.getvalue())
示例3: test_subject_info
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [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)
示例4: test_spatiotemporal_maxwell
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_spatiotemporal_maxwell():
"""Test spatiotemporal (tSSS) processing"""
# Load raw testing data
with warnings.catch_warnings(record=True): # maxshield
raw = Raw(raw_fname, allow_maxshield=True)
# Create coils
picks = pick_types(raw.info)
# Test that window is less than length of data
assert_raises(ValueError, maxwell_filter, raw, st_dur=1000.)
# Check both 4 and 10 seconds because Elekta handles them differently
# This is to ensure that std/non-std tSSS windows are correctly handled
st_durs = [4., 10.]
for st_dur in st_durs:
# Load tSSS data depending on st_dur and get data
tSSS_fname = op.join(data_path, 'SSS', 'test_move_anon_raw_' +
'spatiotemporal_%0ds_sss.fif' % st_dur)
with warnings.catch_warnings(record=True): # maxshield, naming
tsss_bench = Raw(tSSS_fname, allow_maxshield=True)
# Because Elekta's tSSS sometimes(!) lumps the tail window of data
# onto the previous buffer if it's shorter than st_dur, we have to
# crop the data here to compensate for Elekta's tSSS behavior.
if st_dur == 10.:
tsss_bench.crop(0, st_dur, copy=False)
tsss_bench_data = tsss_bench[picks, :][0]
del tsss_bench
# Test sss computation at the standard head origin. Same cropping issue
# as mentioned above.
if st_dur == 10.:
raw_tsss = maxwell_filter(raw.crop(0, st_dur), st_dur=st_dur)
else:
raw_tsss = maxwell_filter(raw, st_dur=st_dur)
assert_allclose(raw_tsss[picks][0], tsss_bench_data,
rtol=1e-12, atol=1e-4, err_msg='Spatiotemporal (tSSS) '
'maxwell filtered data at standard origin incorrect.')
# Confirm SNR is above 500. Single precision is part of discrepancy
bench_rms = np.sqrt(np.mean(tsss_bench_data * tsss_bench_data, axis=1))
error = raw_tsss[picks][0] - tsss_bench_data
error_rms = np.sqrt(np.mean(error * error, axis=1))
assert_true(np.mean(bench_rms / error_rms) >= 500,
'SNR (%0.1f) < 500' % np.mean(bench_rms / error_rms))
# Confirm we didn't modify other channels (like EEG chs)
non_picks = np.setdiff1d(np.arange(len(raw.ch_names)), picks)
assert_allclose(raw[non_picks, 0:raw_tsss.n_times][0],
raw_tsss[non_picks, 0:raw_tsss.n_times][0])
# Degenerate cases
assert_raises(ValueError, maxwell_filter, raw, st_dur=10., st_corr=0.)
示例5: test_spatiotemporal_maxwell
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_spatiotemporal_maxwell():
"""Test Maxwell filter (tSSS) spatiotemporal processing"""
# Load raw testing data
raw = Raw(raw_fname, allow_maxshield='yes')
# Test that window is less than length of data
assert_raises(ValueError, maxwell_filter, raw, st_duration=1000.)
# Check both 4 and 10 seconds because Elekta handles them differently
# This is to ensure that std/non-std tSSS windows are correctly handled
st_durations = [4., 10.]
tols = [325., 200.]
for st_duration, tol in zip(st_durations, tols):
# Load tSSS data depending on st_duration and get data
tSSS_fname = op.join(sss_path,
'test_move_anon_st%0ds_raw_sss.fif' % st_duration)
tsss_bench = Raw(tSSS_fname)
# Because Elekta's tSSS sometimes(!) lumps the tail window of data
# onto the previous buffer if it's shorter than st_duration, we have to
# crop the data here to compensate for Elekta's tSSS behavior.
if st_duration == 10.:
tsss_bench.crop(0, st_duration, copy=False)
# Test sss computation at the standard head origin. Same cropping issue
# as mentioned above.
if st_duration == 10.:
raw_tsss = maxwell_filter(raw.crop(0, st_duration),
origin=mf_head_origin,
st_duration=st_duration, regularize=None,
bad_condition='ignore')
else:
raw_tsss = maxwell_filter(raw, st_duration=st_duration,
origin=mf_head_origin, regularize=None,
bad_condition='ignore', verbose=True)
raw_tsss_2 = maxwell_filter(raw, st_duration=st_duration,
origin=mf_head_origin, regularize=None,
bad_condition='ignore', st_fixed=False,
verbose=True)
assert_meg_snr(raw_tsss, raw_tsss_2, 100., 1000.)
assert_equal(raw_tsss.estimate_rank(), 140)
assert_equal(raw_tsss_2.estimate_rank(), 140)
assert_meg_snr(raw_tsss, tsss_bench, tol)
py_st = raw_tsss.info['proc_history'][0]['max_info']['max_st']
assert_true(len(py_st) > 0)
assert_equal(py_st['buflen'], st_duration)
assert_equal(py_st['subspcorr'], 0.98)
# Degenerate cases
assert_raises(ValueError, maxwell_filter, raw, st_duration=10.,
st_correlation=0.)
示例6: test_chpi_subtraction
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_chpi_subtraction():
"""Test subtraction of cHPI signals"""
raw = Raw(chpi_fif_fname, allow_maxshield='yes', preload=True)
filter_chpi(raw, include_line=False)
# MaxFilter doesn't do quite as well as our algorithm with the last bit
raw.crop(0, 16, copy=False)
raw_c = Raw(sss_hpisubt_fname, preload=True).crop(0, 16, copy=False)
raw_c.pick_types(meg=True, eeg=True, eog=True, ecg=True, stim=True,
misc=True, copy=False) # remove cHPI status chans
assert_meg_snr(raw, raw_c, 143, 624)
# Degenerate cases
raw_nohpi = Raw(test_fif_fname, preload=True)
assert_raises(RuntimeError, filter_chpi, raw_nohpi)
示例7: test_crop
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_crop():
"""Test cropping raw files
"""
# split a concatenated file to test a difficult case
raw = Raw([fif_fname, fif_fname], preload=False)
split_size = 10. # in seconds
sfreq = raw.info['sfreq']
nsamp = (raw.last_samp - raw.first_samp + 1)
# do an annoying case (off-by-one splitting)
tmins = np.r_[1., np.round(np.arange(0., nsamp - 1, split_size * sfreq))]
tmins = np.sort(tmins)
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp - 1]))
tmaxs /= sfreq
tmins /= sfreq
raws = [None] * len(tmins)
for ri, (tmin, tmax) in enumerate(zip(tmins, tmaxs)):
raws[ri] = raw.crop(tmin, tmax, True)
all_raw_2 = concatenate_raws(raws, preload=False)
assert_equal(raw.first_samp, all_raw_2.first_samp)
assert_equal(raw.last_samp, all_raw_2.last_samp)
assert_array_equal(raw[:, :][0], all_raw_2[:, :][0])
tmins = np.round(np.arange(0., nsamp - 1, split_size * sfreq))
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp - 1]))
tmaxs /= sfreq
tmins /= sfreq
# going in revere order so the last fname is the first file (need it later)
raws = [None] * len(tmins)
for ri, (tmin, tmax) in enumerate(zip(tmins, tmaxs)):
raws[ri] = raw.copy()
raws[ri].crop(tmin, tmax, False)
# test concatenation of split file
all_raw_1 = concatenate_raws(raws, preload=False)
all_raw_2 = raw.crop(0, None, True)
for ar in [all_raw_1, all_raw_2]:
assert_equal(raw.first_samp, ar.first_samp)
assert_equal(raw.last_samp, ar.last_samp)
assert_array_equal(raw[:, :][0], ar[:, :][0])
# test shape consistency of cropped raw
data = np.zeros((1, 1002001))
info = create_info(1, 1000)
raw = RawArray(data, info)
for tmin in range(0, 1001, 100):
raw1 = raw.crop(tmin=tmin, tmax=tmin + 2, copy=True)
assert_equal(raw1[:][0].shape, (1, 2001))
示例8: test_cov_estimation_on_raw
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_cov_estimation_on_raw():
"""Test estimation from raw (typically empty room)"""
tempdir = _TempDir()
raw = Raw(raw_fname, preload=False)
cov_mne = read_cov(erm_cov_fname)
cov = compute_raw_covariance(raw, tstep=None)
assert_equal(cov.ch_names, cov_mne.ch_names)
assert_equal(cov.nfree, cov_mne.nfree)
assert_snr(cov.data, cov_mne.data, 1e4)
cov = compute_raw_covariance(raw) # tstep=0.2 (default)
assert_equal(cov.nfree, cov_mne.nfree - 119) # cutoff some samples
assert_snr(cov.data, cov_mne.data, 1e2)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
cov = compute_raw_covariance(raw, picks=picks, tstep=None)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 1e4)
cov = compute_raw_covariance(raw, picks=picks)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 90) # cutoff samps
# make sure we get a warning with too short a segment
raw_2 = raw.crop(0, 1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov = compute_raw_covariance(raw_2)
assert_true(any('Too few samples' in str(ww.message) for ww in w))
示例9: test_cross_talk
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_cross_talk():
"""Test Maxwell filter cross-talk cancellation"""
raw = Raw(raw_fname, allow_maxshield='yes').crop(0., 1., False)
raw.info['bads'] = bads
sss_ctc = Raw(sss_ctc_fname)
raw_sss = maxwell_filter(raw, cross_talk=ctc_fname,
origin=mf_head_origin, regularize=None,
bad_condition='ignore')
assert_meg_snr(raw_sss, sss_ctc, 275.)
py_ctc = raw_sss.info['proc_history'][0]['max_info']['sss_ctc']
assert_true(len(py_ctc) > 0)
assert_raises(ValueError, maxwell_filter, raw, cross_talk=raw)
assert_raises(ValueError, maxwell_filter, raw, cross_talk=raw_fname)
mf_ctc = sss_ctc.info['proc_history'][0]['max_info']['sss_ctc']
del mf_ctc['block_id'] # we don't write this
assert_equal(object_diff(py_ctc, mf_ctc), '')
raw_ctf = Raw(fname_ctf_raw)
assert_raises(ValueError, maxwell_filter, raw_ctf) # cannot fit headshape
raw_sss = maxwell_filter(raw_ctf, origin=(0., 0., 0.04))
_assert_n_free(raw_sss, 68)
raw_sss = maxwell_filter(raw_ctf, origin=(0., 0., 0.04), ignore_ref=True)
_assert_n_free(raw_sss, 70)
raw_missing = raw.crop(0, 0.1, copy=True).load_data().pick_channels(
[raw.ch_names[pi] for pi in pick_types(raw.info, meg=True,
exclude=())[3:]])
with warnings.catch_warnings(record=True) as w:
maxwell_filter(raw_missing, cross_talk=ctc_fname)
assert_equal(len(w), 1)
assert_true('Not all cross-talk channels in raw' in str(w[0].message))
# MEG channels not in cross-talk
assert_raises(RuntimeError, maxwell_filter, raw_ctf, origin=(0., 0., 0.04),
cross_talk=ctc_fname)
示例10: test_cov_estimation_on_raw_segment
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_cov_estimation_on_raw_segment():
"""Test estimation from raw on continuous recordings (typically empty room)
"""
tempdir = _TempDir()
raw = Raw(raw_fname, preload=False)
cov = compute_raw_data_covariance(raw)
cov_mne = read_cov(erm_cov_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
assert_true(linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro') < 1e-4)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
cov = compute_raw_data_covariance(raw, picks=picks)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_true(linalg.norm(cov.data - cov_mne.data[picks][:, picks],
ord='fro') / linalg.norm(cov.data, ord='fro') < 1e-4)
# make sure we get a warning with too short a segment
raw_2 = raw.crop(0, 1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov = compute_raw_data_covariance(raw_2)
assert_true(len(w) == 1)
示例11: test_spatiotemporal_maxwell
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_spatiotemporal_maxwell():
"""Test Maxwell filter (tSSS) spatiotemporal processing"""
# Load raw testing data
with warnings.catch_warnings(record=True): # maxshield
raw = Raw(raw_fname, allow_maxshield=True)
# Test that window is less than length of data
assert_raises(ValueError, maxwell_filter, raw, st_duration=1000.0)
# Check both 4 and 10 seconds because Elekta handles them differently
# This is to ensure that std/non-std tSSS windows are correctly handled
st_durations = [4.0, 10.0]
tols = [325.0, 200.0]
for st_duration, tol in zip(st_durations, tols):
# Load tSSS data depending on st_duration and get data
tSSS_fname = op.join(sss_path, "test_move_anon_st%0ds_raw_sss.fif" % st_duration)
tsss_bench = Raw(tSSS_fname)
# Because Elekta's tSSS sometimes(!) lumps the tail window of data
# onto the previous buffer if it's shorter than st_duration, we have to
# crop the data here to compensate for Elekta's tSSS behavior.
if st_duration == 10.0:
tsss_bench.crop(0, st_duration, copy=False)
# Test sss computation at the standard head origin. Same cropping issue
# as mentioned above.
if st_duration == 10.0:
raw_tsss = maxwell_filter(
raw.crop(0, st_duration),
origin=mf_head_origin,
st_duration=st_duration,
regularize=None,
bad_condition="ignore",
)
else:
raw_tsss = maxwell_filter(
raw, st_duration=st_duration, origin=mf_head_origin, regularize=None, bad_condition="ignore"
)
assert_meg_snr(raw_tsss, tsss_bench, tol)
py_st = raw_tsss.info["proc_history"][0]["max_info"]["max_st"]
assert_true(len(py_st) > 0)
assert_equal(py_st["buflen"], st_duration)
assert_equal(py_st["subspcorr"], 0.98)
# Degenerate cases
assert_raises(ValueError, maxwell_filter, raw, st_duration=10.0, st_correlation=0.0)
示例12: test_output_formats
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [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)
示例13: test_crop
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_crop():
"""Test cropping raw files
"""
# split a concatenated file to test a difficult case
raw = Raw([fif_fname, fif_fname], preload=False)
split_size = 10.0 # in seconds
sfreq = raw.info["sfreq"]
nsamp = raw.last_samp - raw.first_samp + 1
# do an annoying case (off-by-one splitting)
tmins = np.r_[1.0, np.round(np.arange(0.0, nsamp - 1, split_size * sfreq))]
tmins = np.sort(tmins)
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp - 1]))
tmaxs /= sfreq
tmins /= sfreq
raws = [None] * len(tmins)
for ri, (tmin, tmax) in enumerate(zip(tmins, tmaxs)):
raws[ri] = raw.crop(tmin, tmax, True)
all_raw_2 = concatenate_raws(raws, preload=False)
assert_equal(raw.first_samp, all_raw_2.first_samp)
assert_equal(raw.last_samp, all_raw_2.last_samp)
assert_array_equal(raw[:, :][0], all_raw_2[:, :][0])
tmins = np.round(np.arange(0.0, nsamp - 1, split_size * sfreq))
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp - 1]))
tmaxs /= sfreq
tmins /= sfreq
# going in revere order so the last fname is the first file (need it later)
raws = [None] * len(tmins)
for ri, (tmin, tmax) in enumerate(zip(tmins, tmaxs)):
raws[ri] = raw.copy()
raws[ri].crop(tmin, tmax, False)
# test concatenation of split file
all_raw_1 = concatenate_raws(raws, preload=False)
all_raw_2 = raw.crop(0, None, True)
for ar in [all_raw_1, all_raw_2]:
assert_equal(raw.first_samp, ar.first_samp)
assert_equal(raw.last_samp, ar.last_samp)
assert_array_equal(raw[:, :][0], ar[:, :][0])
示例14: split_fif_into_eo_ec
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def split_fif_into_eo_ec(fif_file, lCondStart, lCondEnd, first_samp, cond):
# import mne
import os
from nipype.utils.filemanip import split_filename as split_f
from mne.io import Raw
subj_path, basename, ext = split_f(fif_file)
# raw1 = raw.crop(tmin=10, tmax=30)
# print("I did smth")
# --------------- Delete later ----------------------- #
subj_name = subj_path[-5:]
results_dir = subj_path[:-6]
results_dir += '2016'
subj_path = results_dir + '/' + subj_name
if not os.path.exists(subj_path):
os.makedirs(subj_path)
########################################################
print(fif_file)
Raw_fif = Raw(fif_file, preload=True)
# first_samp_time = Raw_fif.index_as_time(Raw_fif.first_samp)
lRaw_cond = []
# print("I did smth")
if cond == 'eo':
eo_ec_split_fif = subj_path + '/' + basename + '_eo'
elif cond == 'ec':
eo_ec_split_fif = subj_path + '/' + basename + '_ec'
for i in range(len(lCondStart)):
tmin = lCondStart[i] - first_samp
tmax = lCondEnd[i] - first_samp
# To make sure, that my eo-ec time intervals are inside the recording
if i == 0:
tmin += 0.5
if i == range(len(lCondStart))[-1]:
tmax -= 0.5
####################################
# print("tmin = ")
# print(tmin)
# print("tmax = ")
# print(tmax)
fif_cropped = Raw_fif.crop(tmin=tmin, tmax=tmax)
cropped_filename = eo_ec_split_fif + '_' + str(i) + ext
fif_cropped.save(cropped_filename, overwrite=True)
lRaw_cond.append(fif_cropped)
Raw_cond = lRaw_cond[0]
Raw_cond.append(lRaw_cond[1:])
print(eo_ec_split_fif)
eo_ec_split_fif = eo_ec_split_fif + ext
Raw_cond.save(eo_ec_split_fif, overwrite=True)
return eo_ec_split_fif
示例15: test_subject_info
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import crop [as 别名]
def test_subject_info():
"""Test reading subject information
"""
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)