Example #1
0
def test_compute_proj_ecg():
    """Test computation of ECG SSP projectors"""
    raw = Raw(raw_fname).crop(0, 10, False)
    raw.preload_data()
    for average in [False, True]:
        # For speed, let's not filter here (must also not reject then)
        projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
                                         ch_name='MEG 1531', bads=['MEG 2443'],
                                         average=average, avg_ref=True,
                                         no_proj=True, l_freq=None,
                                         h_freq=None, reject=None,
                                         tmax=dur_use, qrs_threshold=0.5)
        assert_true(len(projs) == 7)
        # heart rate at least 0.5 Hz, but less than 3 Hz
        assert_true(events.shape[0] > 0.5 * dur_use and
                    events.shape[0] < 3 * dur_use)
        # XXX: better tests

        # without setting a bad channel, this should throw a warning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
                                             ch_name='MEG 1531', bads=[],
                                             average=average, avg_ref=True,
                                             no_proj=True, l_freq=None,
                                             h_freq=None, tmax=dur_use)
            assert_equal(len(w), 1)
        assert_equal(projs, None)
Example #2
0
def test_compute_proj_ecg(short_raw, average):
    """Test computation of ECG SSP projectors."""
    raw = short_raw

    # For speed, let's not filter here (must also not reject then)
    with pytest.warns(RuntimeWarning, match='Attenuation'):
        projs, events = compute_proj_ecg(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         ch_name='MEG 1531',
                                         bads=['MEG 2443'],
                                         average=average,
                                         avg_ref=True,
                                         no_proj=True,
                                         l_freq=None,
                                         h_freq=None,
                                         reject=None,
                                         tmax=dur_use,
                                         qrs_threshold=0.5,
                                         filter_length=1000)
    assert len(projs) == 7
    # heart rate at least 0.5 Hz, but less than 3 Hz
    assert (events.shape[0] > 0.5 * dur_use and events.shape[0] < 3 * dur_use)
    ssp_ecg = [proj for proj in projs if proj['desc'].startswith('ECG')]
    # check that the first principal component have a certain minimum
    ssp_ecg = [proj for proj in ssp_ecg if 'PCA-01' in proj['desc']]
    thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
    for proj in ssp_ecg:
        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

    # without setting a bad channel, this should throw a warning
    with pytest.warns(RuntimeWarning, match='No good epochs found'):
        projs, events, drop_log = compute_proj_ecg(
            raw,
            n_mag=2,
            n_grad=2,
            n_eeg=2,
            ch_name='MEG 1531',
            bads=[],
            average=average,
            avg_ref=True,
            no_proj=True,
            l_freq=None,
            h_freq=None,
            tmax=dur_use,
            return_drop_log=True,
            # XXX can be removed once
            # XXX https://github.com/mne-tools/mne-python/issues/9273
            # XXX has been resolved:
            qrs_threshold=1e-15)
    assert projs == []
    assert len(events) == len(drop_log)
Example #3
0
def test_compute_proj_ecg():
    """Test computation of ECG SSP projectors."""
    raw = read_raw_fif(raw_fname).crop(0, 10)
    raw.load_data()
    for average in [False, True]:
        # For speed, let's not filter here (must also not reject then)
        projs, events = compute_proj_ecg(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         ch_name='MEG 1531',
                                         bads=['MEG 2443'],
                                         average=average,
                                         avg_ref=True,
                                         no_proj=True,
                                         l_freq=None,
                                         h_freq=None,
                                         reject=None,
                                         tmax=dur_use,
                                         qrs_threshold=0.5,
                                         filter_length=6000)
        assert len(projs) == 7
        # heart rate at least 0.5 Hz, but less than 3 Hz
        assert_true(events.shape[0] > 0.5 * dur_use
                    and events.shape[0] < 3 * dur_use)
        ssp_ecg = [proj for proj in projs if proj['desc'].startswith('ECG')]
        # check that the first principal component have a certain minimum
        ssp_ecg = [proj for proj in ssp_ecg if 'PCA-01' in proj['desc']]
        thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
        for proj in ssp_ecg:
            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

        # without setting a bad channel, this should throw a warning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events, drop_log = compute_proj_ecg(raw,
                                                       n_mag=2,
                                                       n_grad=2,
                                                       n_eeg=2,
                                                       ch_name='MEG 1531',
                                                       bads=[],
                                                       average=average,
                                                       avg_ref=True,
                                                       no_proj=True,
                                                       l_freq=None,
                                                       h_freq=None,
                                                       tmax=dur_use,
                                                       return_drop_log=True)
        assert len(w) >= 1
        assert projs is None
        assert len(events) == len(drop_log)
Example #4
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)
Example #5
0
def test_compute_proj_ecg():
    """Test computation of ECG SSP projectors"""
    raw = Raw(raw_fname).crop(0, 10, False)
    raw.preload_data()
    for average in [False, True]:
        # For speed, let's not filter here (must also not reject then)
        projs, events = compute_proj_ecg(raw,
                                         n_mag=2,
                                         n_grad=2,
                                         n_eeg=2,
                                         ch_name='MEG 1531',
                                         bads=['MEG 2443'],
                                         average=average,
                                         avg_ref=True,
                                         no_proj=True,
                                         l_freq=None,
                                         h_freq=None,
                                         reject=None,
                                         tmax=dur_use,
                                         qrs_threshold=0.5)
        assert_true(len(projs) == 7)
        # heart rate at least 0.5 Hz, but less than 3 Hz
        assert_true(events.shape[0] > 0.5 * dur_use
                    and events.shape[0] < 3 * dur_use)
        # XXX: better tests

        # without setting a bad channel, this should throw a warning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_ecg(raw,
                                             n_mag=2,
                                             n_grad=2,
                                             n_eeg=2,
                                             ch_name='MEG 1531',
                                             bads=[],
                                             average=average,
                                             avg_ref=True,
                                             no_proj=True,
                                             l_freq=None,
                                             h_freq=None,
                                             tmax=dur_use)
            assert_equal(len(w), 1)
        assert_equal(projs, None)
Example #6
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)
Example #7
0
def test_compute_proj_ecg():
    """Test computation of ECG 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]:
        # For speed, let's not filter here (must also not reject then)
        projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
                                         ch_name='MEG 1531', bads=['MEG 2443'],
                                         average=average, avg_ref=True,
                                         no_proj=True, l_freq=None,
                                         h_freq=None, reject=None,
                                         tmax=dur_use, qrs_threshold=0.5,
                                         filter_length=6000)
        assert_true(len(projs) == 7)
        # heart rate at least 0.5 Hz, but less than 3 Hz
        assert_true(events.shape[0] > 0.5 * dur_use and
                    events.shape[0] < 3 * dur_use)
        ssp_ecg = [proj for proj in projs if proj['desc'].startswith('ECG')]
        # check that the first principal component have a certain minimum
        ssp_ecg = [proj for proj in ssp_ecg if 'PCA-01' in proj['desc']]
        thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
        for proj in ssp_ecg:
            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

        # without setting a bad channel, this should throw a warning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            projs, events = compute_proj_ecg(raw, n_mag=2, n_grad=2, n_eeg=2,
                                             ch_name='MEG 1531', bads=[],
                                             average=average, avg_ref=True,
                                             no_proj=True, l_freq=None,
                                             h_freq=None, tmax=dur_use)
        assert_true(len(w) >= 1)
        assert_equal(projs, None)
Example #8
0
def test_compute_proj_ecg():
    """Test computation of ECG SSP projectors."""
    raw = read_raw_fif(raw_fname).crop(0, 10)
    raw.load_data()
    for average in [False, True]:
        # For speed, let's not filter here (must also not reject then)
        projs, events = compute_proj_ecg(
            raw, n_mag=2, n_grad=2, n_eeg=2, ch_name='MEG 1531',
            bads=['MEG 2443'], average=average, avg_ref=True, no_proj=True,
            l_freq=None, h_freq=None, reject=None, tmax=dur_use,
            qrs_threshold=0.5, filter_length=6000)
        assert len(projs) == 7
        # heart rate at least 0.5 Hz, but less than 3 Hz
        assert (events.shape[0] > 0.5 * dur_use and
                events.shape[0] < 3 * dur_use)
        ssp_ecg = [proj for proj in projs if proj['desc'].startswith('ECG')]
        # check that the first principal component have a certain minimum
        ssp_ecg = [proj for proj in ssp_ecg if 'PCA-01' in proj['desc']]
        thresh_eeg, thresh_axial, thresh_planar = .9, .3, .1
        for proj in ssp_ecg:
            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

        # without setting a bad channel, this should throw a warning
        with pytest.warns(RuntimeWarning, match='No good epochs found'):
            projs, events, drop_log = compute_proj_ecg(
                raw, n_mag=2, n_grad=2, n_eeg=2, ch_name='MEG 1531', bads=[],
                average=average, avg_ref=True, no_proj=True, l_freq=None,
                h_freq=None, tmax=dur_use, return_drop_log=True)
        assert projs is None
        assert len(events) == len(drop_log)
Example #9
0
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)
Example #10
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)