solarpy.quality.bsrn_limits_flag

solarpy.quality.bsrn_limits_flag#

solarpy.quality.bsrn_limits_flag(irradiance, solar_zenith, dni_extra, limits, *, check='both', nan_flag=False)#

Flag irradiance values that fall outside the BSRN quality control limits.

Parameters:
  • irradiance (array-like of float) – Irradiance values to check [W/m²].

  • solar_zenith (array-like of float) – Solar zenith angle [degrees]. Must be the same length as irradiance.

  • dni_extra (array-like of float) – Extraterrestrial normal irradiance [W/m²]. Must be the same length as irradiance.

  • limits (str or dict) –

    Either a named limit string or a dict with keys scale, exponent, offset, and lower.

    Named limit (Long & Shi, 2008) [1], [2]:

    • "ghi-ppl" — Physically Possible Limit for GHI

    • "ghi-erl" — Extremely Rare Limit for GHI

    • "dni-ppl" — Physically Possible Limit for DNI

    • "dni-erl" — Extremely Rare Limit for DNI

    • "dhi-ppl" — Physically Possible Limit for DHI

    • "dhi-erl" — Extremely Rare Limit for DHI

  • check ({'both', 'upper', 'lower'}, optional) – Which bounds to check. Default is 'both'.

  • nan_flag (bool, optional) – Flag value to assign when irradiance is NaN. Value can be either True or False. Default is False, which does not flag NaN values as suspicious.

Returns:

flag – Boolean array of the same length as irradiance. True indicates the value failed the test (outside bounds), False indicates it passed.

Return type:

same type as irradiance

See also

bsrn_limits

Calculate the limit values without testing.

diffuse_fraction_flag

Flag measurements based on the diffuse fraction.

Examples

Test GHI measurements against the BSRN limits:

>>> import pandas as pd
>>> import numpy as np
>>> import pvlib
>>>
>>> # One year of hourly timestamps for Copenhagen
>>> times = pd.date_range("2023-01-01", periods=8760, freq="h", tz="UTC")
>>> latitude, longitude = 55.68, 12.57
>>>
>>> # Calculate solar position and extraterrestrial irradiance using pvlib
>>> solpos = pvlib.solarposition.get_solarposition(times, latitude, longitude)
>>> solar_zenith = solpos["apparent_zenith"]
>>> dni_extra = pvlib.irradiance.get_extra_radiation(times)
>>>
>>> # Create synthetic GHI: sine wave clipped to daytime
>>> rng = np.random.default_rng(seed=0)
>>> cos_sza = np.cos(np.deg2rad(solar_zenith))
>>> ghi = np.clip(900 * cos_sza + rng.standard_normal(8760) * 20, 0, None)
>>>
>>> # Run PPL and ERL tests
>>> ppl_flag = bsrn_limits_flag(ghi, solar_zenith, dni_extra, limits="ghi-ppl")
>>> erl_flag = bsrn_limits_flag(ghi, solar_zenith, dni_extra, limits="ghi-erl")

Use custom coefficients:

>>> flag = bsrn_limits_flag(ghi, solar_zenith, dni_extra,
...                         limits={"scale": 1.2, "exponent": 1.2, "offset": 50, "lower": -4})

References