Skip to content

Commit 4915df8

Browse files
committed
use inferred wind length in detect clearsky check fix 2542
1 parent f80a498 commit 4915df8

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

docs/sphinx/source/whatsnew/v0.13.1.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Deprecations
1616

1717
Bug fixes
1818
~~~~~~~~~
19-
19+
* Fix :py:func:`~pvlib.clearsky.detect_clearsky` to use inferred window length when
20+
``infer_limits=True``. (:issue:`2542`, :pull:`2550`)
2021

2122
Enhancements
2223
~~~~~~~~~~~~
@@ -74,3 +75,4 @@ Contributors
7475
* Rodrigo Amaro e Silva (:ghuser:`ramaroesilva`)
7576
* Kevin Anderson (:ghuser:`kandersolar`)
7677
* Mikaella Brewer (:ghuser:`brwerx`)
78+
* Will Holmgren (:ghuser:`wholmgren`)

pvlib/clearsky.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -818,23 +818,23 @@ def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
818818
sample_interval, samples_per_window = \
819819
tools._get_sample_intervals(times, window_length)
820820

821-
if samples_per_window < 3:
822-
raise ValueError(f"Samples per window of {samples_per_window}"
823-
" found. Each window must contain at least 3 data"
824-
" points."
825-
f" Window length of {window_length} found; increase"
826-
f" window length to {3*sample_interval} or longer.")
827-
828821
# if infer_limits, find threshold values using the sample interval
829822
if infer_limits:
830823
window_length, mean_diff, max_diff, lower_line_length, \
831824
upper_line_length, var_diff, slope_dev = \
832825
_clearsky_get_threshold(sample_interval)
833826

834827
# recalculate samples_per_window using returned window_length
835-
_, samples_per_window = \
828+
sample_interval, samples_per_window = \
836829
tools._get_sample_intervals(times, window_length)
837830

831+
if samples_per_window < 3:
832+
raise ValueError(f"Samples per window of {samples_per_window}"
833+
" found. Each window must contain at least 3 data"
834+
" points."
835+
f" Window length of {window_length} found; increase"
836+
f" window length to {3*sample_interval} or longer.")
837+
838838
# check that we have enough data to produce a nonempty hankel matrix
839839
if len(times) < samples_per_window:
840840
raise ValueError(f"times has only {len(times)} entries, but it must \

tests/test_clearsky.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,14 @@ def test_detect_clearsky_window_too_short(detect_clearsky_data):
688688
clearsky.detect_clearsky(expected['GHI'], cs['ghi'], window_length=2)
689689

690690

691+
def test_detect_clearsky_infer_checks(detect_clearsky_threshold_data):
692+
# GH 2542
693+
expected, cs = detect_clearsky_threshold_data
694+
expected = expected.resample('10min').mean()
695+
cs = cs.resample('10min').mean()
696+
clearsky.detect_clearsky(expected['GHI'], cs['ghi'], infer_limits=True)
697+
698+
691699
@pytest.mark.parametrize("window_length", [5, 10, 15, 20, 25])
692700
def test_detect_clearsky_optimizer_not_failed(
693701
detect_clearsky_data, window_length

0 commit comments

Comments
 (0)