Skip to content

Infer thresholds for detect_clearsky #1784

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 22 commits into from
Aug 2, 2023
Merged
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
43 changes: 41 additions & 2 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,30 @@ def _clear_sample_index(clear_windows, samples_per_window, align, H):
return clear_samples


def detect_clearsky(measured, clearsky, times=None, window_length=10,
mean_diff=75, max_diff=75,
def _clearsky_get_threshold(sample_interval):
"""
Returns threshold values for kwargs in detect_clearsky
"""
if (sample_interval < 1 or sample_interval > 30):
raise ValueError("sample_interval must be larger than 1 and \
smaller than 30")

data_freq = np.array([1, 5, 15, 30])

window_length = np.interp(sample_interval, data_freq, [50, 60, 90, 120])
mean_diff = np.interp(sample_interval, data_freq, [75, 75, 75, 75])
max_diff = np.interp(sample_interval, data_freq, [60, 65, 75, 90])
lower_line_length = np.interp(sample_interval, data_freq, [-45,-45,-45,-45])
upper_line_length = np.interp(sample_interval, data_freq, [80, 80, 80, 80])
var_diff = np.interp(sample_interval, data_freq, [0.005, 0.01, 0.032, 0.07])
slope_dev = np.interp(sample_interval, data_freq, [50, 60, 75, 96])

return (window_length, mean_diff, max_diff, lower_line_length,
upper_line_length, var_diff, slope_dev)


def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
window_length=10, mean_diff=75, max_diff=75,
lower_line_length=-5, upper_line_length=10,
var_diff=0.005, slope_dev=8, max_iterations=20,
return_components=False):
Expand Down Expand Up @@ -676,6 +698,9 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
times : DatetimeIndex or None, default None.
Times of measured and clearsky values. If None the index of measured
will be used.
infer_limits : bool, default 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.
Expand Down Expand Up @@ -731,6 +756,9 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
.. [1] Reno, M.J. and C.W. Hansen, "Identification of periods of clear
sky irradiance in time series of GHI measurements" Renewable Energy,
v90, p. 520-531, 2016.
.. [2] Jordan, D.C. and C. Hansen, "Clear-sky detection for PV
degradation analysis using multiple regression", Renewable Energy,
v209, p. 393-400, 2023.

Notes
-----
Expand Down Expand Up @@ -773,6 +801,17 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
sample_interval, samples_per_window = \
tools._get_sample_intervals(times, window_length)

# if infer_limits, find threshold values using the sample interval
if infer_limits:
window_length, mean_diff, max_diff, lower_line_length, \
upper_line_length, var_diff, slope_dev = \
_clearsky_get_threshold(sample_interval)

# recalculate sample_interval, samples_per_window using returned
# window_length
sample_interval, samples_per_window = \
tools._get_sample_intervals(times, window_length)

# generate matrix of integers for creating windows with indexing
H = hankel(np.arange(samples_per_window),
np.arange(samples_per_window-1, len(times)))
Expand Down