Skip to content

Commit 41d6022

Browse files
authored
use inferred window length in detect clearsky check (#2550)
* use inferred wind length in detect clearsky check fix 2542 * lint * lint
1 parent 5bb2871 commit 41d6022

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

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
~~~~~~~~~~~~
@@ -78,3 +79,4 @@ Contributors
7879
* Rodrigo Amaro e Silva (:ghuser:`ramaroesilva`)
7980
* Kevin Anderson (:ghuser:`kandersolar`)
8081
* Mikaella Brewer (:ghuser:`brwerx`)
82+
* Will Holmgren (:ghuser:`wholmgren`)

pvlib/clearsky.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -818,22 +818,31 @@ 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:
830-
window_length, mean_diff, max_diff, lower_line_length, \
831-
upper_line_length, var_diff, slope_dev = \
832-
_clearsky_get_threshold(sample_interval)
823+
(
824+
window_length,
825+
mean_diff,
826+
max_diff,
827+
lower_line_length,
828+
upper_line_length,
829+
var_diff,
830+
slope_dev,
831+
) = _clearsky_get_threshold(sample_interval)
833832

834833
# recalculate samples_per_window using returned window_length
835-
_, samples_per_window = \
836-
tools._get_sample_intervals(times, window_length)
834+
sample_interval, samples_per_window = tools._get_sample_intervals(
835+
times, window_length
836+
)
837+
838+
if samples_per_window < 3:
839+
raise ValueError(
840+
f"Samples per window of {samples_per_window}"
841+
" found. Each window must contain at least 3 data"
842+
" points."
843+
f" Window length of {window_length} found. Increase"
844+
f" window length to {3 * sample_interval} or longer."
845+
)
837846

838847
# check that we have enough data to produce a nonempty hankel matrix
839848
if len(times) < samples_per_window:

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)