Exemplo n.º 1
0
def test_rsp_eventrelated():

    rsp, info = nk.rsp_process(nk.rsp_simulate(duration=30, random_state=42))
    epochs = nk.epochs_create(rsp,
                              events=[5000, 10000, 15000],
                              epochs_start=-0.1,
                              epochs_end=1.9)
    rsp_eventrelated = nk.rsp_eventrelated(epochs)

    # Test rate features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Rate_Min"]) < np.array(
            rsp_eventrelated["RSP_Rate_Mean"]))

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Rate_Mean"]) < np.array(
            rsp_eventrelated["RSP_Rate_Max"]))

    # Test amplitude features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Min"]) < np.array(
            rsp_eventrelated["RSP_Amplitude_Mean"]))

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Mean"]) < np.array(
            rsp_eventrelated["RSP_Amplitude_Max"]))

    assert len(rsp_eventrelated["Label"]) == 3
Exemplo n.º 2
0
def test_rsp_eventrelated():

    rsp, info = nk.rsp_process(nk.rsp_simulate(duration=20))
    epochs = nk.epochs_create(rsp,
                              events=[5000, 10000, 15000],
                              epochs_start=-0.1,
                              epochs_end=1.9)
    rsp_eventrelated = nk.rsp_eventrelated(epochs)

    # Test rate features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Rate_Min"]) < np.array(
            rsp_eventrelated["RSP_Rate_Mean"]))

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Rate_Mean"]) < np.array(
            rsp_eventrelated["RSP_Rate_Max"]))

    # Test amplitude features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Min"]) < np.array(
            rsp_eventrelated["RSP_Amplitude_Mean"]))

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Mean"]) < np.array(
            rsp_eventrelated["RSP_Amplitude_Max"]))

    assert all(elem in [
        "RSP_Rate_Max", "RSP_Rate_Min", "RSP_Rate_Mean", "RSP_Rate_Max_Time",
        "RSP_Rate_Min_Time", "RSP_Amplitude_Max", "RSP_Amplitude_Min",
        "RSP_Amplitude_Mean", "RSP_Phase", "RSP_PhaseCompletion", "Label"
    ] for elem in np.array(rsp_eventrelated.columns.values, dtype=str))
Exemplo n.º 3
0
def test_rsp_eventrelated():

    rsp, info = nk.rsp_process(nk.rsp_simulate(duration=30, random_state=42))
    epochs = nk.epochs_create(rsp,
                              events=[5000, 10000, 15000],
                              epochs_start=-0.1,
                              epochs_end=1.9)
    rsp_eventrelated = nk.rsp_eventrelated(epochs)

    # Test rate features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Rate_Min"]) < np.array(
            rsp_eventrelated["RSP_Rate_Mean"]))

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Rate_Mean"]) < np.array(
            rsp_eventrelated["RSP_Rate_Max"]))

    # Test amplitude features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Min"]) < np.array(
            rsp_eventrelated["RSP_Amplitude_Mean"]))

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Mean"]) < np.array(
            rsp_eventrelated["RSP_Amplitude_Max"]))

    assert len(rsp_eventrelated["Label"]) == 3

    # Test warning on missing columns
    with pytest.warns(nk.misc.NeuroKitWarning,
                      match=r".*does not have an `RSP_Amplitude`.*"):
        first_epoch_key = list(epochs.keys())[0]
        first_epoch_copy = epochs[first_epoch_key].copy()
        del first_epoch_copy["RSP_Amplitude"]
        nk.rsp_eventrelated({**epochs, first_epoch_key: first_epoch_copy})

    with pytest.warns(nk.misc.NeuroKitWarning,
                      match=r".*does not have an `RSP_Phase`.*"):
        first_epoch_key = list(epochs.keys())[0]
        first_epoch_copy = epochs[first_epoch_key].copy()
        del first_epoch_copy["RSP_Phase"]
        nk.rsp_eventrelated({**epochs, first_epoch_key: first_epoch_copy})