Ejemplo n.º 1
0
def test_signal_binarize():

    signal = np.cos(np.linspace(start=0, stop=20, num=1000))
    binary = nk.signal_binarize(signal)
    assert len(binary) == 1000

    binary = nk.signal_binarize(list(signal))
    assert len(binary) == 1000
Ejemplo n.º 2
0
def test_signal_plot():

    # Test with array
    signal = nk.signal_simulate(duration=10, sampling_rate=1000)
    nk.signal_plot(signal, sampling_rate=1000)
    fig = plt.gcf()
    for ax in fig.get_axes():
        handles, labels = ax.get_legend_handles_labels()
    assert labels == ['Signal']
    assert len(labels) == len(handles) == len([signal])
    assert ax.get_xlabel() == 'Time (s)'
    plt.close(fig)

    # Test with dataframe
    data = pd.DataFrame({
        "Signal2":
        np.cos(np.linspace(start=0, stop=20, num=1000)),
        "Signal3":
        np.sin(np.linspace(start=0, stop=20, num=1000)),
        "Signal4":
        nk.signal_binarize(np.cos(np.linspace(start=0, stop=40, num=1000)))
    })
    nk.signal_plot(data, sampling_rate=None)
    fig = plt.gcf()
    for ax in fig.get_axes():
        handles, labels = ax.get_legend_handles_labels()
    assert labels == list(data.columns.values)
    assert len(labels) == len(handles) == len(data.columns)
    assert ax.get_xlabel() == 'Samples'
    plt.close(fig)

    # Test with list
    signal = nk.signal_binarize(nk.signal_simulate(duration=10))
    phase = nk.signal_phase(signal, method="percents")
    nk.signal_plot([signal, phase])
    fig = plt.gcf()
    for ax in fig.get_axes():
        handles, labels = ax.get_legend_handles_labels()
    assert labels == ['Signal1', 'Signal2']
    assert len(labels) == len(handles) == len([signal, phase])
    assert ax.get_xlabel() == 'Samples'
    plt.close(fig)