Skip to content

Correct slope calculation in clearsky.detect_clearsky #1242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.9.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ Bug fixes
calling :py:func:`~pvlib.pvsystem.calcparams_cec`. (:issue:`1215`, :pull:`1216`)
* Corrected methodology error in :py:func:`~pvlib.scaling.wvm`. Tracks with
fix in PVLib for MATLAB. (:issue:`1206`, :pull:`1213`)
* Corrected an error affecting :py:func:`~pvlib.clearsky.detect_clearsky`
when data time step is not one minute. Error was introduced in v0.8.1.
(:issue:`1241`, :pull:`1242`)

Testing
~~~~~~~
Expand Down
11 changes: 6 additions & 5 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,18 @@ def _calc_stats(data, samples_per_window, sample_interval, H):
# shift to get forward difference, .diff() is backward difference instead
data_diff = data.diff().shift(-1)
data_slope = data_diff / sample_interval
data_slope_nstd = _slope_nstd_windowed(data, H, samples_per_window)
data_slope_nstd = _slope_nstd_windowed(data_slope.values[:-1], data, H,
samples_per_window, sample_interval)
data_slope_nstd = data_slope_nstd

return data_mean, data_max, data_slope_nstd, data_slope


def _slope_nstd_windowed(data, H, samples_per_window):
def _slope_nstd_windowed(slopes, data, H, samples_per_window, sample_interval):
with np.errstate(divide='ignore', invalid='ignore'):
raw = np.diff(data)
raw = raw[H[:-1, ]].std(ddof=1, axis=0) / data.values[H].mean(axis=0)
return _to_centered_series(raw, data.index, samples_per_window)
nstd = slopes[H[:-1, ]].std(ddof=1, axis=0) \
/ data.values[H].mean(axis=0)
return _to_centered_series(nstd, data.index, samples_per_window)


def _max_diff_windowed(data, H, samples_per_window):
Expand Down
11 changes: 11 additions & 0 deletions pvlib/tests/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,17 @@ def test_detect_clearsky_window(detect_clearsky_data):
check_dtype=False, check_names=False)


def test_detect_clearsky_time_interval(detect_clearsky_data):
expected, cs = detect_clearsky_data
u = np.arange(0, len(cs), 2)
cs2 = cs.iloc[u]
expected2 = expected.iloc[u]
clear_samples = clearsky.detect_clearsky(
expected2['GHI'], cs2['ghi'], window_length=6)
assert_series_equal(expected2['Clear or not'], clear_samples,
check_dtype=False, check_names=False)


def test_detect_clearsky_arrays(detect_clearsky_data):
expected, cs = detect_clearsky_data
clear_samples = clearsky.detect_clearsky(
Expand Down