예제 #1
0
def test_get_inst_data():
    """Test _get_inst_data."""
    raw = read_raw_fif(fname_raw)
    raw.crop(tmax=1.)
    assert_equal(_get_inst_data(raw), raw._data)
    raw.pick_channels(raw.ch_names[:2])

    epochs = _segment_raw(raw, 0.5)
    assert_equal(_get_inst_data(epochs), epochs._data)

    evoked = epochs.average()
    assert_equal(_get_inst_data(evoked), evoked.data)

    evoked.crop(tmax=0.1)
    picks = list(range(2))
    freqs = np.array([50., 55.])
    n_cycles = 3
    tfr = tfr_morlet(evoked, freqs, n_cycles, return_itc=False, picks=picks)
    assert_equal(_get_inst_data(tfr), tfr.data)

    assert_raises(TypeError, _get_inst_data, 'foo')
예제 #2
0
def test_get_inst_data():
    """Test _get_inst_data."""
    raw = read_raw_fif(fname_raw)
    raw.crop(tmax=1.)
    assert_equal(_get_inst_data(raw), raw._data)
    raw.pick_channels(raw.ch_names[:2])

    epochs = _segment_raw(raw, 0.5)
    assert_equal(_get_inst_data(epochs), epochs._data)

    evoked = epochs.average()
    assert_equal(_get_inst_data(evoked), evoked.data)

    evoked.crop(tmax=0.1)
    picks = list(range(2))
    freqs = np.array([50., 55.])
    n_cycles = 3
    tfr = tfr_morlet(evoked, freqs, n_cycles, return_itc=False, picks=picks)
    assert_equal(_get_inst_data(tfr), tfr.data)

    pytest.raises(TypeError, _get_inst_data, 'foo')
예제 #3
0
def make_csd_rest_approx(raw,
                         frequencies,
                         events=None,
                         event_id=None,
                         tmin=None,
                         tmax=None,
                         n_jobs=1,
                         n_cycles=7.,
                         decim=4,
                         segment_length=1.):
    '''Approximate CSD for continuous signals by segmenting and computing CSD
    on segments.

    This function is not used in the "Three time NO" paper - it servers as a
    comparison.

    Parameters
    ----------
    raw : mne Raw object
        Instance of Raw object to use in CSD computation.
    frequencies : list of float
        List of frequencies to compute CSD for.
    events :
        Events array in mne format. Optional.
    event_id :
        Events to use in segmenting. Optional.
    tmin :
        Time start. If ``events`` was passed then ``tmin`` is with respect to
        each event onset.
    tmax :
        Time end. If ``events`` was passed then ``tmax`` is with respect to
        each event onset.
    n_jobs :
        Number of jobs to use. Defaults to 1.
    n_cycles :
        Number of cycles to use when computing cross spectral density. Defaults
        to 7.
    decim :
        Decimation factor in time of the cross spectral density result.
        Defaults to 4.
    segment_length : float
        Length of segments to which the signal of interest is divided. Defaults
        to 1.
    '''
    from mne.epochs import _segment_raw

    events, tmin, tmax = _deal_with_csd_inputs(tmin, tmax, events, event_id)
    sfreq = raw.info['sfreq']

    windows_list = list()
    for event_idx in range(events.shape[0]):
        event_onset = events[event_idx, 0] / sfreq
        this_tmin = event_onset + tmin
        this_tmax = event_onset + tmax
        raw_crop = raw.copy().crop(this_tmin, this_tmax)
        windows = _segment_raw(raw_crop,
                               segment_length=segment_length,
                               preload=True,
                               verbose=False)
        if len(windows._data) > 0:
            windows_list.append(windows)

    windows_list = mne.concatenate_epochs(windows_list)

    return mne.time_frequency.csd_morlet(windows_list,
                                         frequencies=frequencies,
                                         n_jobs=n_jobs,
                                         n_cycles=n_cycles,
                                         verbose=False,
                                         decim=decim)