Beispiel #1
0
def test_duplicate_events():
    """Test the function check_events when the paradigm contains
    duplicate events.

    """
    events = duplicate_events_paradigm()
    # Check that a warning is given to the user
    with pytest.warns(UserWarning, match="Duplicated events were detected."):
        ttype, onset, duration, modulation = check_events(events)
    assert_array_equal(ttype, ['c0', 'c0', 'c0', 'c1', 'c1'])
    assert_array_equal(onset, [10, 30, 70, 10, 30])
    assert_array_equal(duration, [1., 1., 1., 1., 1.])
    # Modulation was updated
    assert_array_equal(modulation, [1, 1, 2, 1, 1])
Beispiel #2
0
def test_check_events():
    """Test the function which tests that the events
    data describes a valid experimental paradigm.
    """
    events = basic_paradigm()
    # Errors checkins
    # Missing onset
    missing_onset = events.drop(columns=['onset'])
    with pytest.raises(ValueError,
                       match='The provided events data has no onset column.'):
        check_events(missing_onset)
    # Missing duration
    missing_duration = events.drop(columns=['duration'])
    with pytest.raises(ValueError,
                       match='The provided events data has no duration column.'):
        check_events(missing_duration)
    # Warnings checkins
    # Missing trial type
    with pytest.warns(UserWarning,
                      match="'trial_type' column not found"):
        ttype, onset, duration, modulation = check_events(events)
    # Check that missing trial type yields a 'dummy' array
    assert_array_equal(ttype, np.repeat('dummy', len(events)))
    # Check that missing modulation yields an array one ones
    assert_array_equal(modulation, np.ones(len(events)))
    # Modulation is provided
    events['modulation'] = np.ones(len(events))
    with pytest.warns(UserWarning,
                      match="'modulation' column found in the given events data."):
        check_events(events)
    # An unexpected field is provided
    events = events.drop(columns=['modulation'])
    events['foo'] = np.zeros(len(events))
    with pytest.warns(UserWarning,
                      match="Unexpected key `foo` in events will be ignored."):
        ttype2, onset2, duration2, modulation2 = check_events(events)
    assert_array_equal(ttype, ttype2)
    assert_array_equal(onset, onset2)
    assert_array_equal(duration, duration2)
    assert_array_equal(modulation, modulation2)
Beispiel #3
0
def test_check_events():
    """Test the function which tests that the events
    data describes a valid experimental paradigm.
    """
    events = basic_paradigm()
    # Errors checkins
    # Wrong type
    with pytest.raises(TypeError,
                       match="Events should be a Pandas DataFrame."):
        check_events([])
    # Missing onset
    missing_onset = events.drop(columns=['onset'])
    with pytest.raises(ValueError,
                       match='The provided events data has no onset column.'):
        check_events(missing_onset)

    # Missing duration
    missing_duration = events.drop(columns=['duration'])
    with pytest.raises(ValueError,
                       match='The provided events data has '
                       'no duration column.'):
        check_events(missing_duration)

    # Duration wrong type
    wrong_duration = events.copy()
    wrong_duration['duration'] = 'foo'
    with pytest.raises(ValueError, match="Could not cast duration to float"):
        check_events(wrong_duration)

    # Warnings checkins
    # Missing trial type
    missing_ttype = events.drop(columns=['trial_type'])
    with pytest.warns(UserWarning, match="'trial_type' column not found"):
        ttype, onset, duration, modulation = check_events(missing_ttype)

    # Check that missing trial type yields a 'dummy' array
    assert len(np.unique(ttype)) == 1
    assert ttype[0] == 'dummy'

    ttype, onset, duration, modulation = check_events(events)

    # Check that given trial type is right
    assert_array_equal(ttype,
                       ['c0', 'c0', 'c0', 'c1', 'c1', 'c1', 'c2', 'c2', 'c2'])

    # Check that missing modulation yields an array one ones
    assert_array_equal(modulation, np.ones(len(events)))

    # Modulation is provided
    events['modulation'] = np.ones(len(events))
    _, _, _, mod = check_events(events)
    assert_array_equal(mod, events['modulation'])

    # An unexpected field is provided
    events = events.drop(columns=['modulation'])
    events['foo'] = np.zeros(len(events))
    with pytest.warns(UserWarning,
                      match="Unexpected column `foo` in events data."):
        ttype2, onset2, duration2, modulation2 = check_events(events)
    assert_array_equal(ttype, ttype2)
    assert_array_equal(onset, onset2)
    assert_array_equal(duration, duration2)
    assert_array_equal(modulation, modulation2)