Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.11.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Documentation
page. (:issue:`2202`, :pull:`2226`)
* Updated :py:func:`~pvlib.irradiance.reindl` to include definitions of terms
and a new "notes" section (:issue:`2183`, :pull:`2193`)
* Clarified the error message in :py:func:`~pvlib.clearsky.detect_clearsky` when
windows contain fewer than three data points (:issue:`2005`, :pull:`2281`)

Testing
~~~~~~~
Expand Down
18 changes: 14 additions & 4 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
If True, does not use passed in kwargs (or defaults), but instead
interpolates these values from Table 1 in [2]_.
window_length : int, default 10
Length of sliding time window in minutes. Must be greater than 2
periods.
Length of sliding time window in minutes. Each window must contain at
least three data points.
mean_diff : float, default 75
Threshold value for agreement between mean values of measured
and clearsky in each interval, see Eq. 6 in [1]. [W/m2]
Expand Down Expand Up @@ -758,9 +758,13 @@ def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
Raises
------
ValueError
If measured is not a Series and times is not provided
If measured is not a Series and times is not provided.
ValueError
If a window contains less than three data points.
ValueError
If the measured data is not sufficient to fill a window.
NotImplementedError
If timestamps are not equally spaced
If timestamps are not equally spaced.

References
----------
Expand Down Expand Up @@ -812,6 +816,12 @@ def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
sample_interval, samples_per_window = \
tools._get_sample_intervals(times, window_length)

if samples_per_window < 3:
raise ValueError(f"Window of length {window_length} found"
" Each window must contain at least"
" three data points; {samples_per_window} results"
" from time interval of {sample_interval}")

# if infer_limits, find threshold values using the sample interval
if infer_limits:
window_length, mean_diff, max_diff, lower_line_length, \
Expand Down
8 changes: 7 additions & 1 deletion pvlib/tests/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,16 @@ def test_detect_clearsky_missing_index(detect_clearsky_data):

def test_detect_clearsky_not_enough_data(detect_clearsky_data):
expected, cs = detect_clearsky_data
with pytest.raises(ValueError, match='have at least'):
with pytest.raises(ValueError, match='times has only'):
clearsky.detect_clearsky(expected['GHI'], cs['ghi'], window_length=60)


def test_detect_clearsky_window_too_short(detect_clearsky_data):
expected, cs = detect_clearsky_data
with pytest.raises(ValueError, match="Window of length"):
clearsky.detect_clearsky(expected['GHI'], cs['ghi'], window_length=2)


@pytest.mark.parametrize("window_length", [5, 10, 15, 20, 25])
def test_detect_clearsky_optimizer_not_failed(
detect_clearsky_data, window_length
Expand Down