-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Describe the bug
detect_clearsky should use inferred window length when comparing to samples_per_window. Instead it uses the input window_length (default window_length=10). Relevant lines are linked below. Note that samples_per_window and the raise are before the if infer_limits block.
To Reproduce
import numpy as np
import pandas as pd
import pvlib
start = '2024-01-01'
end = '2025-01-01'
freq = '10min'
times = pd.date_range(start=start, end=end, freq=freq)
x1 = pd.Series(np.random.rand(len(times)), index=times)
x2 = pd.Series(np.random.rand(len(times)), index=times)
# works if we change window_length, even though it'll be overriden
pvlib.clearsky.detect_clearsky(x1, x2, infer_limits=True, window_length=30)
# fails
pvlib.clearsky.detect_clearsky(x1, x2, infer_limits=True)$ python detect_clearsky_infer_bug.py
Traceback (most recent call last):
File "/home/wilhol/code/pvlib-python/detect_clearsky_infer_bug.py", line 17, in <module>
pvlib.clearsky.detect_clearsky(x1, x2, infer_limits=True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/wilhol/code/pvlib-python/pvlib/clearsky.py", line 822, in detect_clearsky
raise ValueError(f"Samples per window of {samples_per_window}"
...<3 lines>...
f" window length to {3*sample_interval} or longer.")
ValueError: Samples per window of 1 found. Each window must contain at least 3 data points. Window length of 10 found; increase window length to 30.0 or longer.
Expected behavior
samples_per_window and associated check should be calculated with respect to the inferred window length, if it exists.
Versions:
pvlib.__version__: 0.13.0
Additional context
#2281 introduced the sample window check in an effort to make an error less mysterious. I think it was simply inserted a little too early in the function.