当前位置: 首页>>代码示例>>Python>>正文


Python Raw._data方法代码示例

本文整理汇总了Python中mne.io.Raw._data方法的典型用法代码示例。如果您正苦于以下问题:Python Raw._data方法的具体用法?Python Raw._data怎么用?Python Raw._data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mne.io.Raw的用法示例。


在下文中一共展示了Raw._data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_memmap

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import _data [as 别名]
def test_memmap():
    fname='ec_rest_before_tsss_mc_rsl.fif'
    raw = Raw(fname, preload=False)
    raw.preload_data() #  data becomes numpy.float64
    data_shape = raw._data.shape

    tmpdir = mkdtemp(dir='/Users/cjb/tmp')
    mmap_fname = opj(tmpdir, 'raw_data.dat')

    fp = np.memmap(mmap_fname, dtype='float64', mode='w+',
                   shape=data_shape)

    print('Contents of raw._data:')
    print(raw._data[0][:10])
    print('Contents of memmap:')
    print(fp[0][:10])

    fp[:] = raw._data[:]
    print('Contents of memmap after assignment:')
    print(fp[0][:10])

    # delete numpy array and the memmap writer
    del raw._data
    del fp

    raw._data = np.memmap(mmap_fname, dtype='float64', mode='r+',
                          shape=data_shape)
    print('Contents of raw._data after loading from memmap:')
    print(raw._data[0][:10])


    raw.filter(None,40)
    print('Contents of raw._data after filtering:')
    print(raw._data[0][:10])
开发者ID:cjayb,项目名称:memory_profiling,代码行数:36,代码来源:np_memmap_raw.py

示例2: test_preload_memmap

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import _data [as 别名]
def test_preload_memmap():
    tmpdir = mkdtemp(dir="/Users/cjb/tmp")
    mmap_fname = opj(tmpdir, "raw_data.dat")

    # fname='ec_rest_before_tsss_mc_rsl.fif'
    data_path = sample.data_path(download=False)
    fname = data_path + "/MEG/sample/sample_audvis_raw.fif"

    raw = Raw(fname, preload=False)
    # """This function actually preloads the data"""
    # data_buffer = mmap_fname
    # raw._data = raw._read_segment(data_buffer=data_buffer)[0]
    # assert len(raw._data) == raw.info['nchan']
    # raw.preload = True
    # raw.close()
    raw.preload_data(data_buffer=mmap_fname)
    data_shape = raw._data.shape

    print("Contents of raw._data after reading from fif:")
    print(type(raw._data))
    print(raw._data[100][:5])

    del raw._data
    raw._data = np.memmap(mmap_fname, dtype="float64", mode="c", shape=data_shape)

    print("Contents of raw._data after RE-loading:")
    print(type(raw._data))
    print(raw._data[100][:5])

    raw.filter(None, 40)
    print("Contents of raw._data after filtering:")
    print(type(raw._data))
    print(raw._data[100][:5])

    # PROBLEM: Now the filtered data are IN MEMORY, but as a memmap
    # What if I'd like to continue from here using it as an ndarray?

    del raw._data

    rmtree(tmpdir, ignore_errors=True)
开发者ID:cjayb,项目名称:memory_profiling,代码行数:42,代码来源:mne_preload_raw.py

示例3: filter

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import _data [as 别名]
def filter(l_freq, h_freq, picks=None, filter_length='10s',
           l_trans_bandwidth=0.5, h_trans_bandwidth=0.5, n_jobs=1,
           method='fft', iir_params=None, verbose=None):
    """Filter a subset of channels.
    Applies a zero-phase low-pass, high-pass, band-pass, or band-stop
    filter to the channels selected by "picks". The data of the Raw
    object is modified inplace.
    The Raw object has to be constructed using preload=True (or string).
    l_freq and h_freq are the frequencies below which and above which,
    respectively, to filter out of the data. Thus the uses are:
        * ``l_freq < h_freq``: band-pass filter
        * ``l_freq > h_freq``: band-stop filter
        * ``l_freq is not None and h_freq is None``: high-pass filter
        * ``l_freq is None and h_freq is not None``: low-pass filter
    If n_jobs > 1, more memory is required as "len(picks) * n_times"
    additional time points need to be temporarily stored in memory.
    raw.info['lowpass'] and raw.info['highpass'] are only updated
    with picks=None.
    Parameters
    ----------
    l_freq : float | None
        Low cut-off frequency in Hz. If None the data are only low-passed.
    h_freq : float | None
        High cut-off frequency in Hz. If None the data are only
        high-passed.
    picks : array-like of int | None
        Indices of channels to filter. If None only the data (MEG/EEG)
        channels will be filtered.
    filter_length : str (Default: '10s') | int | None
        Length of the filter to use. If None or "len(x) < filter_length",
        the filter length used is len(x). Otherwise, if int, overlap-add
        filtering with a filter of the specified length in samples) is
        used (faster for long signals). If str, a human-readable time in
        units of "s" or "ms" (e.g., "10s" or "5500ms") will be converted
        to the shortest power-of-two length at least that duration.
        Not used for 'iir' filters.
    l_trans_bandwidth : float
        Width of the transition band at the low cut-off frequency in Hz
        (high pass or cutoff 1 in bandpass). Not used if 'order' is
        specified in iir_params.
    h_trans_bandwidth : float
        Width of the transition band at the high cut-off frequency in Hz
        (low pass or cutoff 2 in bandpass). Not used if 'order' is
        specified in iir_params.
    n_jobs : int | str
        Number of jobs to run in parallel. Can be 'cuda' if scikits.cuda
        is installed properly, CUDA is initialized, and method='fft'.
    method : str
        'fft' will use overlap-add FIR filtering, 'iir' will use IIR
        forward-backward filtering (via filtfilt).
    iir_params : dict | None
        Dictionary of parameters to use for IIR filtering.
        See mne.filter.construct_iir_filter for details. If iir_params
        is None and method="iir", 4th order Butterworth will be used.
    verbose : bool, str, int, or None
        If not None, override default verbose level (see mne.verbose).
        Defaults to raw.verbose.
    See Also
    --------
    mne.Epochs.savgol_filter
    """
    fname='ec_rest_before_tsss_mc_rsl.fif'
    raw = Raw(fname, preload=False)
    raw.preload_data() #  data becomes numpy.float64

    if verbose is None:
        verbose = raw.verbose
    fs = float(raw.info['sfreq'])
    if l_freq == 0:
        l_freq = None
    if h_freq is not None and h_freq > (fs / 2.):
        h_freq = None
    if l_freq is not None and not isinstance(l_freq, float):
        l_freq = float(l_freq)
    if h_freq is not None and not isinstance(h_freq, float):
        h_freq = float(h_freq)

    if not raw.preload:
        raise RuntimeError('Raw data needs to be preloaded to filter. Use '
                           'preload=True (or string) in the constructor.')
    if picks is None:
        if 'ICA ' in ','.join(raw.ch_names):
            pick_parameters = dict(misc=True, ref_meg=False)
        else:
            pick_parameters = dict(meg=True, eeg=True, ref_meg=False)
        picks = pick_types(raw.info, exclude=[], **pick_parameters)
        # let's be safe.
        if len(picks) < 1:
            raise RuntimeError('Could not find any valid channels for '
                               'your Raw object. Please contact the '
                               'MNE-Python developers.')

        # update info if filter is applied to all data channels,
        # and it's not a band-stop filter
        if h_freq is not None:
            if (l_freq is None or l_freq < h_freq) and \
               (raw.info["lowpass"] is None or
               h_freq < raw.info['lowpass']):
                    raw.info['lowpass'] = h_freq
        if l_freq is not None:
#.........这里部分代码省略.........
开发者ID:cjayb,项目名称:memory_profiling,代码行数:103,代码来源:memprof_filter_alone.py


注:本文中的mne.io.Raw._data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。