Skip to content

Commit

Permalink
Change to outside_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamRJensen committed Oct 21, 2024
1 parent 6e53fda commit ca2b8c0
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions pvanalytics/quality/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,43 @@ def _get_bounds(bounds):
bounds['ratio_bounds'][0], bounds['ratio_bounds'][1])


def _check_irrad_ratio(ratio, ghi, sza, bounds, out_of_bounds):
# unpack bounds dict
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
sza_bounds = quality.util.check_limits(
sza, lower_bound=sza_lb, upper_bound=sza_ub, inclusive_lower=True)
ghi_bounds = quality.util.check_limits(
ghi, lower_bound=ghi_lb, upper_bound=ghi_ub)

result = (
sza_bounds
& ghi_bounds
def _check_irrad_ratio(ratio, ghi, sza, bounds, outside_domain):
# LOW ZENITH
ghi_lb, ghi_ub, sza_lb, sza_ub, ratio_lb, ratio_ub = \
_get_bounds(bounds['low_zenith'])

within_domain_lz = (
quality.util.check_limits(
sza, lower_bound=sza_lb, upper_bound=sza_ub, inclusive_lower=True)
& 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)
)
result = np.where(~sza_bounds | ~ghi_bounds, out_of_bounds, result)
print(f"SZA: {sza_bounds} GHI: {ghi_bounds} Flag: {result}")
return result

flag_lz = quality.util.check_limits(
ratio, lower_bound=ratio_lb, upper_bound=ratio_ub)

# HIGH ZENITH
ghi_lb, ghi_ub, sza_lb, sza_ub, ratio_lb, ratio_ub = \
_get_bounds(bounds['high_zenith'])

within_domain_hz = (
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, inclusive_lower=True)
)

flag_hz = quality.util.check_limits(
ratio, lower_bound=ratio_lb, upper_bound=ratio_ub)

flag = flag_lz | flag_hz
within_domain = within_domain_lz | within_domain_hz
flag[~within_domain] = outside_domain
return flag


def check_irradiance_consistency_qcrad(solar_zenith, ghi, dhi, dni,
param=None, out_of_bounds=False):
param=None, outside_domain=False):
"""Check consistency of GHI, DHI and DNI using QCRad criteria.
Uses criteria given in [1]_ to validate the ratio of irradiance
Expand All @@ -315,9 +330,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.
out_of_bounds : default False
Whether a test is failed (False) or passes (True) when test conditions
are not satisfied.
outside_domain : default False
Value to return when the tests are not applicable, i.e., when the
inputs fall outside the test domain.
Returns
-------
Expand Down Expand Up @@ -352,20 +367,14 @@ def check_irradiance_consistency_qcrad(solar_zenith, ghi, dhi, dni,
bounds = param['ghi_ratio']
consistent_components = (
_check_irrad_ratio(ratio=ghi_ratio, ghi=component_sum,
sza=solar_zenith, bounds=bounds['high_zenith'],
out_of_bounds=out_of_bounds)
| _check_irrad_ratio(ratio=ghi_ratio, ghi=component_sum,
sza=solar_zenith, bounds=bounds['low_zenith'],
out_of_bounds=out_of_bounds))
sza=solar_zenith, bounds=bounds,
outside_domain=outside_domain))

bounds = param['dhi_ratio']
diffuse_ratio_limit = (
_check_irrad_ratio(ratio=dhi_ratio, ghi=ghi, sza=solar_zenith,
bounds=bounds['high_zenith'],
out_of_bounds=out_of_bounds)
| _check_irrad_ratio(ratio=dhi_ratio, ghi=ghi, sza=solar_zenith,
bounds=bounds['low_zenith'],
out_of_bounds=out_of_bounds))
bounds=bounds,
outside_domain=outside_domain))

return consistent_components, diffuse_ratio_limit

Expand Down

0 comments on commit ca2b8c0

Please sign in to comment.