From ca2b8c08fdb2d898c04ccf0d59ea14dff9029abf Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Mon, 21 Oct 2024 02:18:52 +0200 Subject: [PATCH] Change to outside_domain --- pvanalytics/quality/irradiance.py | 69 +++++++++++++++++-------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/pvanalytics/quality/irradiance.py b/pvanalytics/quality/irradiance.py index 33707140..4f7a6647 100644 --- a/pvanalytics/quality/irradiance.py +++ b/pvanalytics/quality/irradiance.py @@ -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 @@ -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 ------- @@ -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