Skip to content
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

Add out_of_bounds parameter to irradiance QC tests #214

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions docs/whatsnew/0.2.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

Enhancements
~~~~~~~~~~~~
* Added optional keyword `outside_domain` to
:py:func:`~pvanalytics.quality.irradiance.check_irradiance_consistency_qcrad`.
(:pull:`214`)


Bug Fixes
Expand All @@ -26,3 +29,4 @@ Testing

Contributors
~~~~~~~~~~~~
* Adam R. Jensen (:ghuser:`AdamRJensen`)
61 changes: 44 additions & 17 deletions pvanalytics/quality/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,24 @@ def _get_bounds(bounds):


def _check_irrad_ratio(ratio, ghi, sza, bounds):
# unpack bounds dict
# unpack bounds
ghi_lb, ghi_ub, sza_lb, sza_ub, ratio_lb, ratio_ub = _get_bounds(bounds)
# for zenith set inclusive_lower to handle edge cases, e.g., zenith=0
return (

within_domain = (
quality.util.check_limits(
sza, lower_bound=sza_lb, upper_bound=sza_ub, inclusive_lower=True)
& quality.util.check_limits(
ghi, lower_bound=ghi_lb, upper_bound=ghi_ub)
& quality.util.check_limits(
ratio, lower_bound=ratio_lb, upper_bound=ratio_ub)
ghi, lower_bound=ghi_lb, upper_bound=ghi_ub, inclusive_lower=True)
)

flag = within_domain & quality.util.check_limits(
ratio, lower_bound=ratio_lb, upper_bound=ratio_ub)

return flag, within_domain


def check_irradiance_consistency_qcrad(solar_zenith, ghi, dhi, dni,
param=None):
param=None, outside_domain=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "r" to the line below so that the math equations render.

"""Check consistency of GHI, DHI and DNI using QCRad criteria.

Uses criteria given in [1]_ to validate the ratio of irradiance
Expand All @@ -309,6 +312,9 @@ def check_irradiance_consistency_qcrad(solar_zenith, ghi, dhi, dni,
value is a dict with keys 'zenith_bounds', 'ghi_bounds', and
'ratio_bounds' and value is an ordered pair [lower, upper]
of float.
outside_domain : default False
Value to return when the tests are not applicable, i.e., when the
inputs fall outside the test domain.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inputs fall outside the test domain.
irradiance or zenith values fall outside the test domain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @kandersolar was against listing the specifics. I somewhat agree, as "irradiance values outside the test domain" might be confused as to above/below the threshold. Not a strong feeling though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'm OK with "data" instead of "inputs".


Returns
-------
Expand All @@ -319,6 +325,15 @@ def check_irradiance_consistency_qcrad(solar_zenith, ghi, dhi, dni,

Notes
-----
The QCRad algorithm checks that the input GHI is consistent with the
component sum :math:`DNI \times \cos \( zenith \) + DHI` of input DNI and
DHI, and that the ratio :math:`\frac{DHI}{GHI}` is reasonable.

In these two parts, the ``ghi_bounds`` are applied differently. In the
components test, the bounds are applied to the component sum of diffuse and
direct irradiance, whereas in the diffuse ratio test the bounds are applied
to the measured ``ghi``.

Copyright (c) 2019 SolarArbiter. See the file
LICENSES/SOLARFORECASTARBITER_LICENSE at the top level directory
of this distribution and at `<https://github.com/pvlib/
Expand All @@ -341,18 +356,30 @@ def check_irradiance_consistency_qcrad(solar_zenith, ghi, dhi, dni,
dhi_ratio = dhi / ghi

bounds = param['ghi_ratio']
consistent_components = (
_check_irrad_ratio(ratio=ghi_ratio, ghi=component_sum,
sza=solar_zenith, bounds=bounds['high_zenith'])
| _check_irrad_ratio(ratio=ghi_ratio, ghi=component_sum,
sza=solar_zenith, bounds=bounds['low_zenith']))
flag_lz, within_domain_lz = _check_irrad_ratio(
ratio=ghi_ratio, ghi=component_sum, sza=solar_zenith,
bounds=bounds['low_zenith'])
flag_hz, within_domain_hz = _check_irrad_ratio(
ratio=ghi_ratio, ghi=component_sum, sza=solar_zenith,
bounds=bounds['high_zenith'])

consistent_components = ((flag_lz & within_domain_lz) |
(flag_hz & within_domain_hz))
consistent_components[~(within_domain_lz | within_domain_hz)] = \
outside_domain

bounds = param['dhi_ratio']
diffuse_ratio_limit = (
_check_irrad_ratio(ratio=dhi_ratio, ghi=ghi, sza=solar_zenith,
bounds=bounds['high_zenith'])
| _check_irrad_ratio(ratio=dhi_ratio, ghi=ghi, sza=solar_zenith,
bounds=bounds['low_zenith']))
flag_lz, within_domain_lz = _check_irrad_ratio(
ratio=dhi_ratio, ghi=ghi, sza=solar_zenith,
bounds=bounds['low_zenith'])
flag_hz, within_domain_hz = _check_irrad_ratio(
ratio=dhi_ratio, ghi=ghi, sza=solar_zenith,
bounds=bounds['high_zenith'])
within_domain_hz = within_domain_lz | within_domain_hz
diffuse_ratio_limit = ((flag_lz & within_domain_lz) |
(flag_hz & within_domain_hz))
diffuse_ratio_limit[~(within_domain_lz | within_domain_hz)] = \
outside_domain

return consistent_components, diffuse_ratio_limit

Expand Down
51 changes: 35 additions & 16 deletions pvanalytics/tests/quality/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ def irradiance_qcrad():
output = pd.DataFrame(
columns=['ghi', 'dhi', 'dni', 'solar_zenith', 'dni_extra',
'ghi_limit_flag', 'dhi_limit_flag', 'dni_limit_flag',
'consistent_components', 'diffuse_ratio_limit'],
data=np.array([[-100, 100, 100, 30, 1370, 0, 1, 1, 0, 0],
[100, -100, 100, 30, 1370, 1, 0, 1, 0, 0],
[100, 100, -100, 30, 1370, 1, 1, 0, 0, 1],
[1000, 100, 900, 0, 1370, 1, 1, 1, 1, 1],
[1000, 200, 800, 15, 1370, 1, 1, 1, 1, 1],
[1000, 200, 800, 60, 1370, 0, 1, 1, 0, 1],
[1000, 300, 850, 80, 1370, 0, 0, 1, 0, 1],
[1000, 500, 800, 90, 1370, 0, 0, 1, 0, 1],
[500, 100, 1100, 0, 1370, 1, 1, 1, 0, 1],
[1000, 300, 1200, 0, 1370, 1, 1, 1, 0, 1],
[500, 600, 100, 60, 1370, 1, 1, 1, 0, 0],
[500, 600, 400, 80, 1370, 0, 0, 1, 0, 0],
[500, 500, 300, 80, 1370, 0, 0, 1, 1, 1],
[0, 0, 0, 93, 1370, 1, 1, 1, 0, 0]]))
'consistent_components', 'diffuse_ratio_limit',
'consistent_components_outside_domain',
'diffuse_ratio_limit_outside_domain',
],
data=np.array([[-100, 100, 100, 30, 1370, 0, 1, 1, 0, 0, 0, 1],
[100, -100, 100, 30, 1370, 1, 0, 1, 0, 0, 1, 0],
[100, 100, -100, 30, 1370, 1, 1, 0, 0, 1, 1, 1],
[1000, 100, 900, 0, 1370, 1, 1, 1, 1, 1, 1, 1],
[1000, 200, 800, 15, 1370, 1, 1, 1, 1, 1, 1, 1],
[1000, 200, 800, 60, 1370, 0, 1, 1, 0, 1, 0, 1],
[1000, 300, 850, 80, 1370, 0, 0, 1, 0, 1, 0, 1],
[1000, 500, 800, 90, 1370, 0, 0, 1, 0, 1, 0, 1],
[500, 100, 1100, 0, 1370, 1, 1, 1, 0, 1, 0, 1],
[1000, 300, 1200, 0, 1370, 1, 1, 1, 0, 1, 0, 1],
[500, 600, 100, 60, 1370, 1, 1, 1, 0, 0, 0, 0],
[500, 600, 400, 80, 1370, 0, 0, 1, 0, 0, 0, 0],
[500, 500, 300, 80, 1370, 0, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 93, 1370, 1, 1, 1, 0, 0, 1, 1],
[100, 100, 0, 95, 1370, 0, 0, 1, 0, 0, 1, 1],
]))
dtypes = ['float64', 'float64', 'float64', 'float64', 'float64',
'bool', 'bool', 'bool', 'bool', 'bool']
'bool', 'bool', 'bool', 'bool', 'bool', 'bool', 'bool']
for (col, typ) in zip(output.columns, dtypes):
output[col] = output[col].astype(typ)
return output
Expand Down Expand Up @@ -179,6 +184,20 @@ def test_check_irradiance_consistency_qcrad(irradiance_qcrad):
check_names=False)


def test_check_irradiance_consistency_qcrad_outside_domain(irradiance_qcrad):
expected = irradiance_qcrad
cons_comp, diffuse = irradiance.check_irradiance_consistency_qcrad(
expected['solar_zenith'], expected['ghi'],
expected['dhi'], expected['dni'],
outside_domain=True)
assert_series_equal(cons_comp,
expected['consistent_components_outside_domain'],
check_names=False)
assert_series_equal(diffuse,
expected['diffuse_ratio_limit_outside_domain'],
check_names=False)


@pytest.fixture
def times():
"""One hour of times at 10 minute frequency.
Expand Down
Loading