Skip to content

Commit

Permalink
Ignore missing data in clipping.levels() (#97)
Browse files Browse the repository at this point in the history
* Ignore missing data in clipping.levels()

Drop missing data (NAs) before applying the clipping filter. Series
is reindexed and NAs are filled with False before being returned.
  • Loading branch information
wfvining committed Nov 17, 2020
1 parent 6eefb0a commit 2f7e687
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pvanalytics/features/clipping.py
Expand Up @@ -79,16 +79,18 @@ def levels(ac_power, window=4, fraction_in_window=0.75,
for more information.
"""
power = ac_power.copy()
power.dropna(inplace=True)
num_bins = np.ceil(1.0 / rtol).astype(int)
flags = pd.Series(index=ac_power.index, data=False)
power_plateaus, bins = _detect_levels(ac_power, count=levels,
flags = pd.Series(index=power.index, data=False)
power_plateaus, bins = _detect_levels(power, count=levels,
num_bins=num_bins)
for lower, upper in power_plateaus:
temp = pd.Series(index=ac_power.index, data=0.0)
temp.loc[(ac_power >= lower) & (ac_power <= upper)] = 1.0
temp = pd.Series(index=power.index, data=0.0)
temp.loc[(power >= lower) & (power <= upper)] = 1.0
flags = flags | _label_clipping(temp, window=window,
frac=fraction_in_window)
return flags
return flags.reindex_like(ac_power).fillna(False)


def _daytime_powercurve(ac_power, power_quantile):
Expand Down
10 changes: 10 additions & 0 deletions pvanalytics/tests/features/test_clipping.py
Expand Up @@ -71,6 +71,16 @@ def test_levels_two_periods(quadratic, quadratic_clipped):
assert not clipped[50:].any()


def test_levels_missing_data(quadratic, quadratic_clipped):
quadratic[10:20] = np.nan
quadratic_clipped[10:20] = np.nan
assert_series_equal(
pd.Series(False, quadratic.index),
clipping.levels(quadratic, window=10)
)
assert not clipping.levels(quadratic_clipped, window=10)[10:20].any()


def test_threshold_no_clipping(quadratic):
"""In a data set with a single quadratic there is no clipping."""
quadratic.index = pd.date_range(
Expand Down

0 comments on commit 2f7e687

Please sign in to comment.