Beispiel #1
0
def test_stale_values_diff_handles_negatives(data_with_negatives):
    """stale_values_diff works with negative values.

    Notes
    -----
    Copyright (c) 2019 SolarArbiter. See the file
    LICENSES/SOLARFORECASTARBITER_LICENSE at the top level directory
    of this distribution and at `<https://github.com/pvlib/
    pvanalytics/blob/master/LICENSES/SOLARFORECASTARBITER_LICENSE>`_
    for more information.

    """
    res = gaps.stale_values_diff(data_with_negatives, window=3, mark='end')
    assert_series_equal(
        res, pd.Series([False, False, True, True, False, False, False]))
    res = gaps.stale_values_diff(data_with_negatives,
                                 window=3,
                                 atol=1e-3,
                                 mark='end')
    assert_series_equal(
        res, pd.Series([False, False, True, True, True, True, True]))
    res = gaps.stale_values_diff(data_with_negatives,
                                 window=3,
                                 atol=1e-5,
                                 mark='end')
    assert_series_equal(
        res, pd.Series([False, False, True, True, True, False, False]))
    res = gaps.stale_values_diff(data_with_negatives,
                                 window=3,
                                 atol=2e-5,
                                 mark='end')
    assert_series_equal(
        res, pd.Series([False, False, True, True, True, True, True]))
Beispiel #2
0
def test_stale_values_diff_raises_error(stale_data):
    """stale_values_diff raises a ValueError for 'window' < 2.

    Notes
    -----
    Copyright (c) 2019 SolarArbiter. See the file
    LICENSES/SOLARFORECASTARBITER_LICENSE at the top level directory
    of this distribution and at `<https://github.com/pvlib/
    pvanalytics/blob/master/LICENSES/SOLARFORECASTARBITER_LICENSE>`_
    for more information.

    """
    with pytest.raises(ValueError):
        gaps.stale_values_diff(stale_data, window=1)
Beispiel #3
0
def test_stale_values_diff_mark_tail(stale_data):
    """When mark='tail' (the default), every point in the window except
    the first is marked stale."""
    assert_series_equal(
        pd.Series(
            [False, False, True, True, True, True, True, True, False, False]),
        gaps.stale_values_diff(stale_data, window=4))
Beispiel #4
0
def test_stale_values_diff(stale_data):
    """stale_values_diff properly identifies stuck values.

    Notes
    -----
    Copyright (c) 2019 SolarArbiter. See the file
    LICENSES/SOLARFORECASTARBITER_LICENSE at the top level directory
    of this distribution and at `<https://github.com/pvlib/
    pvanalytics/blob/master/LICENSES/SOLARFORECASTARBITER_LICENSE>`_
    for more information.

    """
    res0 = gaps.stale_values_diff(stale_data, mark='end')
    res1 = gaps.stale_values_diff(stale_data, window=3, mark='end')
    res2 = gaps.stale_values_diff(stale_data, rtol=1e-8, window=2, mark='end')
    res3 = gaps.stale_values_diff(stale_data, window=7, mark='end')
    res4 = gaps.stale_values_diff(stale_data, window=8, mark='end')
    res5 = gaps.stale_values_diff(stale_data, rtol=1e-8, window=4, mark='end')
    res6 = gaps.stale_values_diff(stale_data[1:], window=3, mark='end')
    res7 = gaps.stale_values_diff(stale_data[1:8], window=3, mark='end')
    assert_series_equal(
        res0,
        pd.Series([
            False, False, False, False, False, False, True, True, False, False
        ]))
    assert_series_equal(
        res1,
        pd.Series(
            [False, False, False, True, True, True, True, True, False, False]))
    assert_series_equal(
        res2,
        pd.Series(
            [False, False, True, True, True, False, False, True, False,
             False]))
    assert_series_equal(
        res3,
        pd.Series([
            False, False, False, False, False, False, False, True, False, False
        ]))
    assert not all(res4)
    assert_series_equal(
        res5,
        pd.Series([
            False, False, False, False, True, False, False, False, False, False
        ]))
    assert_series_equal(
        res6,
        pd.Series(
            index=stale_data[1:].index,
            data=[False, False, True, True, True, True, True, False, False]))
    assert_series_equal(
        res7,
        pd.Series(index=stale_data[1:8].index,
                  data=[False, False, True, True, True, True, True]))
Beispiel #5
0
data['value_normalized'].plot()
data.loc[data["stale_data_mask"], "value_normalized"].plot(ls='', marker='.')
plt.legend(labels=["AC Power", "Inserted Stale Data"])
plt.xlabel("Date")
plt.ylabel("Normalized AC Power")
plt.tight_layout()
plt.show()

# %%
# Now, we use :py:func:`pvanalytics.quality.gaps.stale_values_diff` to
# identify stale values in data. We visualize the detected stale periods
# graphically. Please note that nighttime periods generally contain consecutive
# repeating 0 values, which are flagged by
# :py:func:`pvanalytics.quality.gaps.stale_values_diff`.

stale_data_mask = gaps.stale_values_diff(data['value_normalized'])
data['value_normalized'].plot()
data.loc[stale_data_mask, "value_normalized"].plot(ls='', marker='.')
plt.legend(labels=["AC Power", "Detected Stale Data"])
plt.xlabel("Date")
plt.ylabel("Normalized AC Power")
plt.tight_layout()
plt.show()

# %%
# Now, we use :py:func:`pvanalytics.quality.gaps.stale_values_round` to
# identify stale values in data, using rounded data. This function yields
# similar results as :py:func:`pvanalytics.quality.gaps.stale_values_diff`,
# except it looks for consecutive repeating data that has been rounded to
# a settable decimals place.
# Please note that nighttime periods generally
Beispiel #6
0
def test_stale_values_diff_mark_all(stale_data):
    """When mark='all' the full window is marked stale"""
    assert_series_equal(
        pd.Series(
            [False, True, True, True, True, True, True, True, False, False]),
        gaps.stale_values_diff(stale_data, window=4, mark='all'))
Beispiel #7
0
def test_stale_values_diff_raises_error_for_bad_mark(stale_data):
    """Passing mark not in ['all', 'end', 'tail'] raises a ValueError."""
    with pytest.raises(ValueError):
        gaps.stale_values_diff(stale_data, mark='head')