コード例 #1
0
ファイル: test_ssp.py プロジェクト: rajul/mne-python
def test_compute_proj_eog():
    """Test computation of EOG SSP projectors"""
    raw = Raw(raw_fname).crop(0, 10, False)
    raw.preload_data()
    for average in [False, True]:
        n_projs_init = len(raw.info['projs'])
        projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                         bads=['MEG 2443'], average=average,
                                         avg_ref=True, no_proj=False,
                                         l_freq=None, h_freq=None,
                                         reject=None, tmax=dur_use)
        assert_true(len(projs) == (7 + n_projs_init))
        assert_true(np.abs(events.shape[0] -
                    np.sum(np.less(eog_times, dur_use))) <= 1)
        # XXX: better tests

        # This will throw a warning b/c simplefilter('always')
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                             average=average, bads=[],
                                             avg_ref=True, no_proj=False,
                                             l_freq=None, h_freq=None,
                                             tmax=dur_use)
            assert_equal(len(w), 1)
        assert_equal(projs, None)
コード例 #2
0
ファイル: test_ssp.py プロジェクト: zimine/mne-python
def test_compute_proj_eog():
    """Test computation of EOG SSP projectors."""
    raw = read_raw_fif(raw_fname).crop(0, 10)
    raw.load_data()
    for average in [False, True]:
        n_projs_init = len(raw.info['projs'])
        projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                         bads=['MEG 2443'], average=average,
                                         avg_ref=True, no_proj=False,
                                         l_freq=None, h_freq=None,
                                         reject=None, tmax=dur_use,
                                         filter_length=6000)
        assert (len(projs) == (7 + n_projs_init))
        assert (np.abs(events.shape[0] -
                np.sum(np.less(eog_times, dur_use))) <= 1)
        ssp_eog = [proj for proj in projs if proj['desc'].startswith('EOG')]
        # check that the first principal component have a certain minimum
        ssp_eog = [proj for proj in ssp_eog if 'PCA-01' in proj['desc']]
        thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
        for proj in ssp_eog:
            if 'planar' in proj['desc']:
                assert (proj['explained_var'] > thresh_planar)
            elif 'axial' in proj['desc']:
                assert (proj['explained_var'] > thresh_axial)
            elif 'eeg' in proj['desc']:
                assert (proj['explained_var'] > thresh_eeg)
        # XXX: better tests

        with pytest.warns(RuntimeWarning, match='longer'):
            projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                             average=average, bads=[],
                                             avg_ref=True, no_proj=False,
                                             l_freq=None, h_freq=None,
                                             tmax=dur_use)
        assert projs is None
コード例 #3
0
def test_compute_proj_ecg_eog_deprecation_warning():
    raw = read_raw_fif(raw_fname).crop(0, 10)
    raw.load_data()
    with pytest.warns(DeprecationWarning, match='average'):
        _, _ = compute_proj_ecg(raw)
        _, _ = compute_proj_eog(raw)
    with pytest.warns(None):
        for a in (True, False):
            _, _ = compute_proj_ecg(raw, average=a)
            _, _ = compute_proj_eog(raw, average=a)
コード例 #4
0
ファイル: test_ssp.py プロジェクト: sappelhoff/mne-python
def test_compute_proj_eog(average, short_raw):
    """Test computation of EOG SSP projectors."""
    raw = short_raw

    n_projs_init = len(raw.info['projs'])
    with pytest.warns(RuntimeWarning, match='Attenuation'):
        projs, events = compute_proj_eog(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         bads=['MEG 2443'],
                                         average=average,
                                         avg_ref=True,
                                         no_proj=False,
                                         l_freq=None,
                                         h_freq=None,
                                         reject=None,
                                         tmax=dur_use,
                                         filter_length=1000)
    assert (len(projs) == (7 + n_projs_init))
    assert (np.abs(events.shape[0] - np.sum(np.less(eog_times, dur_use))) <= 1)
    ssp_eog = [proj for proj in projs if proj['desc'].startswith('EOG')]
    # check that the first principal component have a certain minimum
    ssp_eog = [proj for proj in ssp_eog if 'PCA-01' in proj['desc']]
    thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
    for proj in ssp_eog:
        if 'planar' in proj['desc']:
            assert (proj['explained_var'] > thresh_planar)
        elif 'axial' in proj['desc']:
            assert (proj['explained_var'] > thresh_axial)
        elif 'eeg' in proj['desc']:
            assert (proj['explained_var'] > thresh_eeg)
    # XXX: better tests

    with pytest.warns(RuntimeWarning, match='longer'):
        projs, events = compute_proj_eog(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         average=average,
                                         bads=[],
                                         avg_ref=True,
                                         no_proj=False,
                                         l_freq=None,
                                         h_freq=None,
                                         tmax=dur_use)
    assert projs == []

    raw._data[raw.ch_names.index('EOG 061'), :] = 1.
    with pytest.warns(RuntimeWarning, match='filter.*longer than the signal'):
        projs, events = compute_proj_eog(raw=raw,
                                         tmax=dur_use,
                                         ch_name='EOG 061')
コード例 #5
0
ファイル: test_ssp.py プロジェクト: ahoejlund/mne-python
def test_compute_proj_eog():
    """Test computation of EOG SSP projectors"""
    raw = Raw(raw_fname).crop(0, 10, copy=False)
    raw.load_data()
    for average in [False, True]:
        n_projs_init = len(raw.info['projs'])
        projs, events = compute_proj_eog(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         bads=['MEG 2443'],
                                         average=average,
                                         avg_ref=True,
                                         no_proj=False,
                                         l_freq=None,
                                         h_freq=None,
                                         reject=None,
                                         tmax=dur_use,
                                         filter_length=6000)
        assert_true(len(projs) == (7 + n_projs_init))
        assert_true(
            np.abs(events.shape[0] - np.sum(np.less(eog_times, dur_use))) <= 1)
        ssp_eog = [proj for proj in projs if proj['desc'].startswith('EOG')]
        # check that the first principal component have a certain minimum
        ssp_eog = [proj for proj in ssp_eog if 'PCA-01' in proj['desc']]
        thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
        for proj in ssp_eog:
            if 'planar' in proj['desc']:
                assert_true(proj['explained_var'] > thresh_planar)
            elif 'axial' in proj['desc']:
                assert_true(proj['explained_var'] > thresh_axial)
            elif 'eeg' in proj['desc']:
                assert_true(proj['explained_var'] > thresh_eeg)
        # XXX: better tests

        # This will throw a warning b/c simplefilter('always')
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_eog(raw,
                                             n_mag=2,
                                             n_grad=2,
                                             n_eeg=2,
                                             average=average,
                                             bads=[],
                                             avg_ref=True,
                                             no_proj=False,
                                             l_freq=None,
                                             h_freq=None,
                                             tmax=dur_use)
        assert_true(len(w) >= 1)
        assert_equal(projs, None)
コード例 #6
0
ファイル: test_ssp.py プロジェクト: ahoejlund/mne-python
def test_compute_proj_parallel():
    """Test computation of ExG projectors using parallelization"""
    raw_0 = Raw(raw_fname).crop(0, 10, copy=False)
    raw_0.load_data()
    raw = raw_0.copy()
    projs, _ = compute_proj_eog(raw,
                                n_mag=2,
                                n_grad=2,
                                n_eeg=2,
                                bads=['MEG 2443'],
                                average=False,
                                avg_ref=True,
                                no_proj=False,
                                n_jobs=1,
                                l_freq=None,
                                h_freq=None,
                                reject=None,
                                tmax=dur_use,
                                filter_length=6000)
    raw_2 = raw_0.copy()
    projs_2, _ = compute_proj_eog(raw_2,
                                  n_mag=2,
                                  n_grad=2,
                                  n_eeg=2,
                                  bads=['MEG 2443'],
                                  average=False,
                                  avg_ref=True,
                                  no_proj=False,
                                  n_jobs=2,
                                  l_freq=None,
                                  h_freq=None,
                                  reject=None,
                                  tmax=dur_use,
                                  filter_length=6000)
    projs = activate_proj(projs)
    projs_2 = activate_proj(projs_2)
    projs, _, _ = make_projector(projs,
                                 raw_2.info['ch_names'],
                                 bads=['MEG 2443'])
    projs_2, _, _ = make_projector(projs_2,
                                   raw_2.info['ch_names'],
                                   bads=['MEG 2443'])
    assert_array_almost_equal(projs, projs_2, 10)
コード例 #7
0
def test_compute_proj_ctf():
    """Test to show that projector code completes on CTF data."""
    raw = read_raw_ctf(ctf_fname)
    raw.load_data()

    # expected channels per projector type
    n_mags = len(pick_types(raw.info, meg='mag', ref_meg=False,
                            exclude='bads'))
    n_grads = len(
        pick_types(raw.info, meg='grad', ref_meg=False, exclude='bads'))
    n_eegs = len(
        pick_types(raw.info,
                   meg=False,
                   eeg=True,
                   ref_meg=False,
                   exclude='bads'))

    # Test with and without gradient compensation
    for c in [0, 1]:
        raw.apply_gradient_compensation(c)
        for average in [False, True]:
            n_projs_init = len(raw.info['projs'])
            projs, events = compute_proj_eog(raw,
                                             n_mag=2,
                                             n_grad=2,
                                             n_eeg=2,
                                             average=average,
                                             ch_name='EEG059',
                                             avg_ref=True,
                                             no_proj=False,
                                             l_freq=None,
                                             h_freq=None,
                                             reject=None,
                                             tmax=dur_use,
                                             filter_length=6000)
            _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs)
            assert len(projs) == (5 + n_projs_init)

            projs, events = compute_proj_ecg(raw,
                                             n_mag=1,
                                             n_grad=1,
                                             n_eeg=2,
                                             average=average,
                                             ch_name='EEG059',
                                             avg_ref=True,
                                             no_proj=False,
                                             l_freq=None,
                                             h_freq=None,
                                             reject=None,
                                             tmax=dur_use,
                                             filter_length=6000)
            _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs)
            assert len(projs) == (4 + n_projs_init)
コード例 #8
0
ファイル: test_ssp.py プロジェクト: yop0/mne-python
def test_compute_proj_parallel(short_raw):
    """Test computation of ExG projectors using parallelization."""
    short_raw = short_raw.copy().pick(('eeg', 'eog')).resample(100)
    raw = short_raw.copy()
    with pytest.warns(RuntimeWarning, match='Attenuation'):
        projs, _ = compute_proj_eog(raw,
                                    n_eeg=2,
                                    bads=raw.ch_names[1:2],
                                    average=False,
                                    avg_ref=True,
                                    no_proj=False,
                                    n_jobs=1,
                                    l_freq=None,
                                    h_freq=None,
                                    reject=None,
                                    tmax=dur_use,
                                    filter_length=100)
    raw_2 = short_raw.copy()
    with pytest.warns(RuntimeWarning, match='Attenuation'):
        projs_2, _ = compute_proj_eog(raw_2,
                                      n_eeg=2,
                                      bads=raw.ch_names[1:2],
                                      average=False,
                                      avg_ref=True,
                                      no_proj=False,
                                      n_jobs=2,
                                      l_freq=None,
                                      h_freq=None,
                                      reject=None,
                                      tmax=dur_use,
                                      filter_length=100)
    projs = activate_proj(projs)
    projs_2 = activate_proj(projs_2)
    projs, _, _ = make_projector(projs,
                                 raw_2.info['ch_names'],
                                 bads=['MEG 2443'])
    projs_2, _, _ = make_projector(projs_2,
                                   raw_2.info['ch_names'],
                                   bads=['MEG 2443'])
    assert_array_almost_equal(projs, projs_2, 10)
コード例 #9
0
def test_compute_proj_eog():
    """Test computation of EOG SSP projectors"""
    raw = Raw(raw_fname).crop(0, 10, False)
    raw.preload_data()
    for average in [False, True]:
        n_projs_init = len(raw.info['projs'])
        projs, events = compute_proj_eog(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         bads=['MEG 2443'],
                                         average=average,
                                         avg_ref=True,
                                         no_proj=False,
                                         l_freq=None,
                                         h_freq=None,
                                         reject=None,
                                         tmax=dur_use)
        assert_true(len(projs) == (7 + n_projs_init))
        assert_true(
            np.abs(events.shape[0] - np.sum(np.less(eog_times, dur_use))) <= 1)
        # XXX: better tests

        # This will throw a warning b/c simplefilter('always')
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_eog(raw,
                                             n_mag=2,
                                             n_grad=2,
                                             n_eeg=2,
                                             average=average,
                                             bads=[],
                                             avg_ref=True,
                                             no_proj=False,
                                             l_freq=None,
                                             h_freq=None,
                                             tmax=dur_use)
            assert_equal(len(w), 1)
        assert_equal(projs, None)
コード例 #10
0
ファイル: test_ssp.py プロジェクト: jmontoyam/mne-python
def test_compute_proj_eog():
    """Test computation of EOG SSP projectors."""
    raw = read_raw_fif(raw_fname, add_eeg_ref=False).crop(0, 10, copy=False)
    raw.load_data()
    for average in [False, True]:
        n_projs_init = len(raw.info['projs'])
        projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                         bads=['MEG 2443'], average=average,
                                         avg_ref=True, no_proj=False,
                                         l_freq=None, h_freq=None,
                                         reject=None, tmax=dur_use,
                                         filter_length=6000)
        assert_true(len(projs) == (7 + n_projs_init))
        assert_true(np.abs(events.shape[0] -
                    np.sum(np.less(eog_times, dur_use))) <= 1)
        ssp_eog = [proj for proj in projs if proj['desc'].startswith('EOG')]
        # check that the first principal component have a certain minimum
        ssp_eog = [proj for proj in ssp_eog if 'PCA-01' in proj['desc']]
        thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
        for proj in ssp_eog:
            if 'planar' in proj['desc']:
                assert_true(proj['explained_var'] > thresh_planar)
            elif 'axial' in proj['desc']:
                assert_true(proj['explained_var'] > thresh_axial)
            elif 'eeg' in proj['desc']:
                assert_true(proj['explained_var'] > thresh_eeg)
        # XXX: better tests

        # This will throw a warning b/c simplefilter('always')
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                             average=average, bads=[],
                                             avg_ref=True, no_proj=False,
                                             l_freq=None, h_freq=None,
                                             tmax=dur_use)
        assert_true(len(w) >= 1)
        assert_equal(projs, None)
コード例 #11
0
ファイル: test_ssp.py プロジェクト: EmanuelaLiaci/mne-python
def test_compute_proj_parallel():
    """Test computation of ExG projectors using parallelization"""
    raw_0 = Raw(raw_fname).crop(0, 10, copy=False)
    raw_0.load_data()
    raw = raw_0.copy()
    projs, _ = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                bads=['MEG 2443'], average=False,
                                avg_ref=True, no_proj=False, n_jobs=1,
                                l_freq=None, h_freq=None, reject=None,
                                tmax=dur_use)
    raw_2 = raw_0.copy()
    projs_2, _ = compute_proj_eog(raw_2, n_mag=2, n_grad=2, n_eeg=2,
                                  bads=['MEG 2443'], average=False,
                                  avg_ref=True, no_proj=False, n_jobs=2,
                                  l_freq=None, h_freq=None, reject=None,
                                  tmax=dur_use)
    projs = activate_proj(projs)
    projs_2 = activate_proj(projs_2)
    projs, _, _ = make_projector(projs, raw_2.info['ch_names'],
                                 bads=['MEG 2443'])
    projs_2, _, _ = make_projector(projs_2, raw_2.info['ch_names'],
                                   bads=['MEG 2443'])
    assert_array_almost_equal(projs, projs_2, 10)
コード例 #12
0
ファイル: test_ssp.py プロジェクト: JohnGriffiths/mne-python
def test_compute_proj_ctf():
    """Test to show that projector code completes on CTF data."""
    raw = read_raw_ctf(ctf_fname, preload=True)

    # expected channels per projector type
    mag_picks = pick_types(
        raw.info, meg='mag', ref_meg=False, exclude='bads')[::10]
    n_mags = len(mag_picks)
    grad_picks = pick_types(raw.info, meg='grad', ref_meg=False,
                            exclude='bads')[::10]
    n_grads = len(grad_picks)
    eeg_picks = pick_types(raw.info, meg=False, eeg=True, ref_meg=False,
                           exclude='bads')[2::3]
    n_eegs = len(eeg_picks)
    ref_picks = pick_types(raw.info, meg=False, ref_meg=True)
    raw.pick(np.sort(np.concatenate(
        [mag_picks, grad_picks, eeg_picks, ref_picks])))
    del mag_picks, grad_picks, eeg_picks, ref_picks

    # Test with and without gradient compensation
    raw.apply_gradient_compensation(0)
    n_projs_init = len(raw.info['projs'])
    with pytest.warns(RuntimeWarning, match='Attenuation'):
        projs, _ = compute_proj_eog(
            raw, n_mag=2, n_grad=2, n_eeg=2, average=True, ch_name='EEG059',
            avg_ref=True, no_proj=False, l_freq=None, h_freq=None,
            reject=None, tmax=dur_use, filter_length=1000)
    _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs)
    assert len(projs) == (5 + n_projs_init)

    raw.apply_gradient_compensation(1)
    with pytest.warns(RuntimeWarning, match='Attenuation'):
        projs, _ = compute_proj_ecg(
            raw, n_mag=1, n_grad=1, n_eeg=2, average=True, ch_name='EEG059',
            avg_ref=True, no_proj=False, l_freq=None, h_freq=None,
            reject=None, tmax=dur_use, filter_length=1000)
    _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs)
    assert len(projs) == (4 + n_projs_init)
コード例 #13
0
ファイル: test_ssp.py プロジェクト: SherazKhan/mne-python
def test_compute_proj_ctf():
    """Test to show that projector code completes on CTF data."""
    raw = read_raw_ctf(ctf_fname)
    raw.load_data()

    # expected channels per projector type
    n_mags = len(pick_types(raw.info, meg='mag', ref_meg=False,
                            exclude='bads'))
    n_grads = len(pick_types(raw.info, meg='grad', ref_meg=False,
                             exclude='bads'))
    n_eegs = len(pick_types(raw.info, meg=False, eeg=True, ref_meg=False,
                            exclude='bads'))

    # Test with and without gradient compensation
    for c in [0, 1]:
        raw.apply_gradient_compensation(c)
        for average in [False, True]:
            n_projs_init = len(raw.info['projs'])
            projs, events = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
                                             average=average,
                                             ch_name='EEG059',
                                             avg_ref=True, no_proj=False,
                                             l_freq=None, h_freq=None,
                                             reject=None, tmax=dur_use,
                                             filter_length=6000)
            _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs)
            assert len(projs) == (5 + n_projs_init)

            projs, events = compute_proj_ecg(raw, n_mag=1, n_grad=1, n_eeg=2,
                                             average=average,
                                             ch_name='EEG059',
                                             avg_ref=True, no_proj=False,
                                             l_freq=None, h_freq=None,
                                             reject=None, tmax=dur_use,
                                             filter_length=6000)
            _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs)
            assert len(projs) == (4 + n_projs_init)