示例#1
0
def lldetect_events(d, sfx):
    """Performs line-length transform on data, then detects events in data and identifies start/stop times and channels
       involved.

               Takes 1d/2d list (L) of data, performs line-length transform on it and detects events on transformed data.
               Returns start & stop times of detected events and channels involved in the form of 2d lists.

               Parameters
               ----------
               d : list of float values
                   EEG data to be detected for events
               sfx : int
                   sampling frequency of data

               Returns
               -------
               ets : 2d list of start and stop times of detected events
                   each row is 1 event
                   column 0 is start times
                   column 1 is stop times
               ech : 1d list of strings which hold channel #s involved in event
                   each string is 1 event
                   each element in each string is the number of the channel involved
               """
    transformed_data = lltransform(d, sfx)
    prc = 99.9  # percentile needed for lleventdetector.py
    mel = 100  # minimum event length in milliseconds, needed for lleventdetector.py
    ets, ech = lleventdetector(transformed_data, sfx, prc, mel)
    return ets, ech
def test_lleventdetector_2(example_eeg_data):
    # should return correct channels for EON/EOFF
    expected_ch = ['3,', '3,']
    l = example_eeg_data[2]
    sfx = example_eeg_data[1]
    actual = lleventdetector(l, sfx, 99.9, 3)
    assert actual[1] == expected_ch
def test_lleventdetector_4(example_eeg_data):
    # tests edge case 1 for channels
    l = example_eeg_data[2]
    l[4][0:4] = 40000
    sfx = example_eeg_data[1]
    actual = lleventdetector(l, sfx, 99.9, 3)
    expected_ch = ['4,', '3,', '3,']
    assert actual[1] == expected_ch
def test_lleventdetector_9(example_eeg_data):
    # tests deleting short events channels
    l = example_eeg_data[2]
    sfx = example_eeg_data[1]
    minimum_event_time = 16
    actual = lleventdetector(l, sfx, 99.9, minimum_event_time)
    expected_ch = ['3,']
    assert expected_ch == actual[1]
def test_lleventdetector_6(example_eeg_data):
    # tests edge case 2 for channels
    l = example_eeg_data[2]
    end = len(l[0])
    l[1][end - 4:end] = 40000
    sfx = example_eeg_data[1]
    actual = lleventdetector(l, sfx, 99.9, 3)
    expected_ch = ['3,', '3,', '1,']
    assert actual[1] == expected_ch
def test_lleventdetector_1(example_eeg_data):
    # should return correct time stamps for EON/EOFF
    expected_ts = np.column_stack(([1344, 4156], [1351, 4180]))
    l = example_eeg_data[2]
    sfx = example_eeg_data[1]
    actual = lleventdetector(l, sfx, 99.9, 3)
    if np.size(actual[0]) == np.size(expected_ts):
        assert [a == b for a, b in zip(list(actual[0]), list(expected_ts))]
    else:
        assert False
def test_lleventdetector_11(example_eeg_data):
    # tests that ech merges events correctly
    l = example_eeg_data[2]
    end = len(l[0])
    l[1][end - 4:end] = 40000
    l[2][end - 3] = 40000
    sfx = example_eeg_data[1]
    actual = lleventdetector(l, sfx, 99.9, 3)
    expected_ch = ['3,', '3,', '1,2,']
    assert expected_ch == actual[1]
def test_lleventdetector_3(example_eeg_data):
    # tests edge case 1 for time stamps
    l = example_eeg_data[2]
    l[4][0:4] = 40000
    sfx = example_eeg_data[1]
    expected_ts = np.column_stack([[10, 13], [1344, 1355], [4159, 4180]])
    actual = lleventdetector(l, sfx, 99.9, 3)
    if np.size(actual[0]) == np.size(expected_ts):
        assert [a == b for a, b in zip(list(actual[0]), list(expected_ts))]
    else:
        assert False
def test_lleventdetector_8(example_eeg_data):
    # tests deleting short events time stamps
    l = example_eeg_data[2]
    sfx = example_eeg_data[1]
    minimum_event_time = 16
    actual = lleventdetector(l, sfx, 99.9, minimum_event_time)
    expected_ts = np.column_stack([[4156, 4180]])
    if np.size(actual[0]) == np.size(expected_ts):
        assert [a == b for a, b in zip(list(actual[0]), list(expected_ts))]
    else:
        assert False
def test_lleventdetector_10(example_eeg_data):
    # test that error is raised when EON and EOFF lengths are different
    l = example_eeg_data[2]
    end = len(l[0])
    sfx = example_eeg_data[1]
    l[1][end - 1] = 40000
    minimum_event_time = 1
    with pytest.raises(
            RuntimeError,
            match='eON and eOFF are different lengths, check your code.'):
        actual = lleventdetector(l, sfx, 99.9, minimum_event_time)
        raise RuntimeError(
            'eON and eOFF are different lengths, check your code.')
def test_lleventdetector_5(example_eeg_data):
    # tests edge case 2 for time stamps
    l = example_eeg_data[2]
    end = len(l[0])
    l[1][end - 4:end] = 40000
    sfx = example_eeg_data[1]
    actual = lleventdetector(l, sfx, 99.9, 3)
    expected_ts = np.column_stack([[1344., 1350.], [4159., 4180.],
                                   [5126., 5130.]])
    if np.size(actual[0]) == np.size(expected_ts):
        assert [a == b for a, b in zip(list(actual[0]), list(expected_ts))]
    else:
        assert False