Exemplo n.º 1
0
def test_dics():
    """Test DICS with evoked data and single trials
    """
    raw, epochs, evoked, data_csd, noise_csd, label, forward,\
        forward_surf_ori, forward_fixed, forward_vol = _get_data()

    stc = dics(evoked, forward, noise_csd=noise_csd, data_csd=data_csd,
               label=label)

    stc.crop(0, None)
    stc_pow = np.sum(stc.data, axis=1)
    idx = np.argmax(stc_pow)
    max_stc = stc.data[idx]
    tmax = stc.times[np.argmax(max_stc)]

    # Incorrect due to limited number of epochs
    assert_true(0.04 < tmax < 0.05)
    assert_true(10 < np.max(max_stc) < 13)

    # Test picking normal orientation
    stc_normal = dics(evoked, forward_surf_ori, noise_csd, data_csd,
                      pick_ori="normal", label=label)
    stc_normal.crop(0, None)

    # The amplitude of normal orientation results should always be smaller than
    # free orientation results
    assert_true((np.abs(stc_normal.data) <= stc.data).all())

    # Test if fixed forward operator is detected when picking normal
    # orientation
    assert_raises(ValueError, dics_epochs, epochs, forward_fixed, noise_csd,
                  data_csd, pick_ori="normal")

    # Test if non-surface oriented forward operator is detected when picking
    # normal orientation
    assert_raises(ValueError, dics_epochs, epochs, forward, noise_csd,
                  data_csd, pick_ori="normal")

    # Test if volume forward operator is detected when picking normal
    # orientation
    assert_raises(ValueError, dics_epochs, epochs, forward_vol, noise_csd,
                  data_csd, pick_ori="normal")

    # Now test single trial using fixed orientation forward solution
    # so we can compare it to the evoked solution
    stcs = dics_epochs(epochs, forward_fixed, noise_csd, data_csd, reg=0.01,
                       label=label)

    # Testing returning of generator
    stcs_ = dics_epochs(epochs, forward_fixed, noise_csd, data_csd, reg=0.01,
                        return_generator=True, label=label)
    assert_array_equal(stcs[0].data, advance_iterator(stcs_).data)

    # Test whether correct number of trials was returned
    epochs.drop_bad()
    assert_true(len(epochs.events) == len(stcs))

    # Average the single trial estimates
    stc_avg = np.zeros_like(stc.data)
    for this_stc in stcs:
        stc_avg += this_stc.crop(0, None).data
    stc_avg /= len(stcs)

    idx = np.argmax(np.max(stc_avg, axis=1))
    max_stc = stc_avg[idx]
    tmax = stc.times[np.argmax(max_stc)]

    assert_true(0.045 < tmax < 0.06)  # incorrect due to limited # of epochs
    assert_true(12 < np.max(max_stc) < 18.5)
Exemplo n.º 2
0
def test_dics():
    """Test DICS with evoked data and single trials."""
    raw, epochs, evoked, data_csd, noise_csd, label, forward,\
        forward_surf_ori, forward_fixed, forward_vol = _get_data()
    epochs.crop(0, None)
    reg = 0.5  # Heavily regularize due to low SNR

    for real_filter in (True, False):
        stc = dics(evoked, forward, noise_csd=noise_csd, data_csd=data_csd,
                   label=label, real_filter=real_filter, reg=reg)
        stc_pow = np.sum(stc.data, axis=1)
        idx = np.argmax(stc_pow)
        max_stc = stc.data[idx]
        tmax = stc.times[np.argmax(max_stc)]

        # Incorrect due to limited number of epochs
        assert 0.04 < tmax < 0.06
        assert 3. < np.max(max_stc) < 6.

    # Test picking normal orientation
    stc_normal = dics(evoked, forward_surf_ori, noise_csd, data_csd,
                      pick_ori="normal", label=label, real_filter=True,
                      reg=reg)
    assert stc_normal.data.min() < 0  # this doesn't take abs
    stc_normal = dics(evoked, forward_surf_ori, noise_csd, data_csd,
                      pick_ori="normal", label=label, reg=reg)
    assert stc_normal.data.min() >= 0  # this does take abs

    # The amplitude of normal orientation results should always be smaller than
    # free orientation results
    assert (np.abs(stc_normal.data) <= stc.data).all()

    # Test if fixed forward operator is detected when picking normal
    # orientation
    raises(ValueError, dics_epochs, epochs, forward_fixed, noise_csd, data_csd,
           pick_ori="normal")

    # Test if non-surface oriented forward operator is detected when picking
    # normal orientation
    raises(ValueError, dics_epochs, epochs, forward, noise_csd, data_csd,
           pick_ori="normal")

    # Test if volume forward operator is detected when picking normal
    # orientation
    raises(ValueError, dics_epochs, epochs, forward_vol, noise_csd, data_csd,
           pick_ori="normal")

    # Now test single trial using fixed orientation forward solution
    # so we can compare it to the evoked solution
    stcs = dics_epochs(epochs, forward_fixed, noise_csd, data_csd, label=label)

    # Testing returning of generator
    stcs_ = dics_epochs(epochs, forward_fixed, noise_csd, data_csd,
                        return_generator=True, label=label)
    assert_array_equal(stcs[0].data, advance_iterator(stcs_).data)

    # Test whether correct number of trials was returned
    epochs.drop_bad()
    assert len(epochs.events) == len(stcs)

    # Average the single trial estimates
    stc_avg = np.zeros_like(stc.data)
    for this_stc in stcs:
        stc_avg += this_stc.data
    stc_avg /= len(stcs)

    idx = np.argmax(np.max(stc_avg, axis=1))
    max_stc = stc_avg[idx]
    tmax = stc.times[np.argmax(max_stc)]

    assert 0.120 < tmax < 0.150  # incorrect due to limited #
    assert 12 < np.max(max_stc) < 18.5
def test_dics():
    """Test DICS with evoked data and single trials
    """
    raw, epochs, evoked, data_csd, noise_csd, label, forward,\
        forward_surf_ori, forward_fixed, forward_vol = _get_data()

    stc = dics(evoked,
               forward,
               noise_csd=noise_csd,
               data_csd=data_csd,
               label=label)

    stc.crop(0, None)
    stc_pow = np.sum(stc.data, axis=1)
    idx = np.argmax(stc_pow)
    max_stc = stc.data[idx]
    tmax = stc.times[np.argmax(max_stc)]

    # Incorrect due to limited number of epochs
    assert_true(0.04 < tmax < 0.05)
    assert_true(10 < np.max(max_stc) < 13)

    # Test picking normal orientation
    stc_normal = dics(evoked,
                      forward_surf_ori,
                      noise_csd,
                      data_csd,
                      pick_ori="normal",
                      label=label)
    stc_normal.crop(0, None)

    # The amplitude of normal orientation results should always be smaller than
    # free orientation results
    assert_true((np.abs(stc_normal.data) <= stc.data).all())

    # Test if fixed forward operator is detected when picking normal
    # orientation
    assert_raises(ValueError,
                  dics_epochs,
                  epochs,
                  forward_fixed,
                  noise_csd,
                  data_csd,
                  pick_ori="normal")

    # Test if non-surface oriented forward operator is detected when picking
    # normal orientation
    assert_raises(ValueError,
                  dics_epochs,
                  epochs,
                  forward,
                  noise_csd,
                  data_csd,
                  pick_ori="normal")

    # Test if volume forward operator is detected when picking normal
    # orientation
    assert_raises(ValueError,
                  dics_epochs,
                  epochs,
                  forward_vol,
                  noise_csd,
                  data_csd,
                  pick_ori="normal")

    # Now test single trial using fixed orientation forward solution
    # so we can compare it to the evoked solution
    stcs = dics_epochs(epochs,
                       forward_fixed,
                       noise_csd,
                       data_csd,
                       reg=0.01,
                       label=label)

    # Testing returning of generator
    stcs_ = dics_epochs(epochs,
                        forward_fixed,
                        noise_csd,
                        data_csd,
                        reg=0.01,
                        return_generator=True,
                        label=label)
    assert_array_equal(stcs[0].data, advance_iterator(stcs_).data)

    # Test whether correct number of trials was returned
    epochs.drop_bad_epochs()
    assert_true(len(epochs.events) == len(stcs))

    # Average the single trial estimates
    stc_avg = np.zeros_like(stc.data)
    for this_stc in stcs:
        stc_avg += this_stc.crop(0, None).data
    stc_avg /= len(stcs)

    idx = np.argmax(np.max(stc_avg, axis=1))
    max_stc = stc_avg[idx]
    tmax = stc.times[np.argmax(max_stc)]

    assert_true(0.045 < tmax < 0.06)  # incorrect due to limited # of epochs
    assert_true(12 < np.max(max_stc) < 18.5)
Exemplo n.º 4
0
def test_dics():
    """Test DICS with evoked data and single trials."""
    raw, epochs, evoked, data_csd, noise_csd, label, forward,\
        forward_surf_ori, forward_fixed, forward_vol = _get_data()
    epochs.crop(0, None)
    reg = 0.5  # Heavily regularize due to low SNR

    for real_filter in (True, False):
        stc = dics(evoked,
                   forward,
                   noise_csd=noise_csd,
                   data_csd=data_csd,
                   label=label,
                   real_filter=real_filter,
                   reg=reg)
        stc_pow = np.sum(stc.data, axis=1)
        idx = np.argmax(stc_pow)
        max_stc = stc.data[idx]
        tmax = stc.times[np.argmax(max_stc)]

        # Incorrect due to limited number of epochs
        assert 0.04 < tmax < 0.06
        assert 3. < np.max(max_stc) < 6.

    # Test picking normal orientation
    stc_normal = dics(evoked,
                      forward_surf_ori,
                      noise_csd,
                      data_csd,
                      pick_ori="normal",
                      label=label,
                      real_filter=True,
                      reg=reg)
    assert stc_normal.data.min() < 0  # this doesn't take abs
    stc_normal = dics(evoked,
                      forward_surf_ori,
                      noise_csd,
                      data_csd,
                      pick_ori="normal",
                      label=label,
                      reg=reg)
    assert stc_normal.data.min() >= 0  # this does take abs

    # The amplitude of normal orientation results should always be smaller than
    # free orientation results
    assert (np.abs(stc_normal.data) <= stc.data).all()

    # Test if fixed forward operator is detected when picking normal
    # orientation
    raises(ValueError,
           dics_epochs,
           epochs,
           forward_fixed,
           noise_csd,
           data_csd,
           pick_ori="normal")

    # Test if non-surface oriented forward operator is detected when picking
    # normal orientation
    raises(ValueError,
           dics_epochs,
           epochs,
           forward,
           noise_csd,
           data_csd,
           pick_ori="normal")

    # Test if volume forward operator is detected when picking normal
    # orientation
    raises(ValueError,
           dics_epochs,
           epochs,
           forward_vol,
           noise_csd,
           data_csd,
           pick_ori="normal")

    # Now test single trial using fixed orientation forward solution
    # so we can compare it to the evoked solution
    stcs = dics_epochs(epochs, forward_fixed, noise_csd, data_csd, label=label)

    # Testing returning of generator
    stcs_ = dics_epochs(epochs,
                        forward_fixed,
                        noise_csd,
                        data_csd,
                        return_generator=True,
                        label=label)
    assert_array_equal(stcs[0].data, advance_iterator(stcs_).data)

    # Test whether correct number of trials was returned
    epochs.drop_bad()
    assert len(epochs.events) == len(stcs)

    # Average the single trial estimates
    stc_avg = np.zeros_like(stc.data)
    for this_stc in stcs:
        stc_avg += this_stc.data
    stc_avg /= len(stcs)

    idx = np.argmax(np.max(stc_avg, axis=1))
    max_stc = stc_avg[idx]
    tmax = stc.times[np.argmax(max_stc)]

    assert 0.120 < tmax < 0.150  # incorrect due to limited #
    assert 12 < np.max(max_stc) < 18.5