From 1c459d3e4e39cc2bf36327d410224ed46970a1b1 Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Tue, 9 Jun 2026 10:50:12 +0100 Subject: [PATCH 1/7] Add return_components to isotropic --- pvlib/irradiance.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 50f02426de..b2bd3c4076 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -595,7 +595,7 @@ def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None): return diffuse_irrad -def isotropic(surface_tilt, dhi): +def isotropic(surface_tilt, dhi, return_components=False): r''' Determine diffuse irradiance from the sky on a tilted surface using the isotropic sky model. @@ -619,11 +619,27 @@ def isotropic(surface_tilt, dhi): dhi : numeric Diffuse horizontal irradiance, must be >=0. See :term:`dhi`. + return_components : bool, default `False` + If `False`, ``sky_diffuse`` is returned. + If `True`, ``diffuse_components`` is returned. + For this model, return_components does not add more information, + but it is included for consistency with the other sky diffuse models. + Returns ------- - diffuse : numeric + numeric, OrderedDict, or DataFrame + Return type controlled by ``return_components`` argument. + If `False`, ``sky_diffuse`` is returned. + If `True`, ``diffuse_components`` is returned. + + sky_diffuse : numeric The sky diffuse component of the solar radiation. [Wm⁻²] + diffuse_components : OrderedDict (array input) or DataFrame (Series input) + Keys/columns are: + * poa_sky_diffuse: Total sky diffuse + * poa_isotropic + References ---------- .. [1] Loutzenhiser P.G. et al. "Empirical validation of models to @@ -638,7 +654,17 @@ def isotropic(surface_tilt, dhi): ''' sky_diffuse = dhi * (1 + tools.cosd(surface_tilt)) * 0.5 - return sky_diffuse + if return_components: + diffuse_components = OrderedDict() + diffuse_components['poa_sky_diffuse'] = sky_diffuse + diffuse_components['poa_isotropic'] = sky_diffuse + + if isinstance(sky_diffuse, pd.Series): + diffuse_components = pd.DataFrame(diffuse_components) + + return diffuse_components + else: + return sky_diffuse def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith, From 4148c5327371fda1653a3599e29bf9f96199341e Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Wed, 17 Jun 2026 11:36:52 +0100 Subject: [PATCH 2/7] Change OrderedDict to dict --- pvlib/irradiance.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index b2bd3c4076..6a4238ddf0 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -627,7 +627,7 @@ def isotropic(surface_tilt, dhi, return_components=False): Returns ------- - numeric, OrderedDict, or DataFrame + numeric, Dict, or DataFrame Return type controlled by ``return_components`` argument. If `False`, ``sky_diffuse`` is returned. If `True`, ``diffuse_components`` is returned. @@ -635,7 +635,7 @@ def isotropic(surface_tilt, dhi, return_components=False): sky_diffuse : numeric The sky diffuse component of the solar radiation. [Wm⁻²] - diffuse_components : OrderedDict (array input) or DataFrame (Series input) + diffuse_components : Dict (array input) or DataFrame (Series input) Keys/columns are: * poa_sky_diffuse: Total sky diffuse * poa_isotropic @@ -655,9 +655,10 @@ def isotropic(surface_tilt, dhi, return_components=False): sky_diffuse = dhi * (1 + tools.cosd(surface_tilt)) * 0.5 if return_components: - diffuse_components = OrderedDict() - diffuse_components['poa_sky_diffuse'] = sky_diffuse - diffuse_components['poa_isotropic'] = sky_diffuse + diffuse_components = { + 'poa_sky_diffuse': sky_diffuse, + 'poa_isotropic': sky_diffuse + } if isinstance(sky_diffuse, pd.Series): diffuse_components = pd.DataFrame(diffuse_components) From f3e69b3eb4e23199e75d6cf7af7e2413d05ee2a9 Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Wed, 17 Jun 2026 12:06:11 +0100 Subject: [PATCH 3/7] Add tests for isotropic with return_components=True --- pvlib/irradiance.py | 2 +- tests/test_irradiance.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 6a4238ddf0..82b144cbe9 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -631,7 +631,7 @@ def isotropic(surface_tilt, dhi, return_components=False): Return type controlled by ``return_components`` argument. If `False`, ``sky_diffuse`` is returned. If `True`, ``diffuse_components`` is returned. - + sky_diffuse : numeric The sky diffuse component of the solar radiation. [Wm⁻²] diff --git a/tests/test_irradiance.py b/tests/test_irradiance.py index a416636ae9..ce7878fdbc 100644 --- a/tests/test_irradiance.py +++ b/tests/test_irradiance.py @@ -168,6 +168,32 @@ def test_isotropic_series(irrad_data): assert_allclose(result, [0, 35.728402, 104.601328, 54.777191], atol=1e-4) +def test_isotropic_components(irrad_data): + keys = ['poa_sky_diffuse', 'poa_isotropic'] + expected = pd.DataFrame(np.array( + [[0, 35.728402, 104.601328, 54.777191], + [0, 35.728402, 104.601328, 54.777191]]).T, + columns=keys, + index=irrad_data.index + ) + # pandas + result = irradiance.isotropic( + 40, irrad_data['dhi'], return_components=True) + assert_frame_equal(result, expected, check_less_precise=4) + # numpy + result = irradiance.isotropic( + 40, irrad_data['dhi'].values, return_components=True) + for key in keys: + assert_allclose(result[key], expected[key], atol=1e-4) + assert isinstance(result, dict) + # scalar + result = irradiance.isotropic( + 40, irrad_data['dhi'].values[-1], return_components=True) + for key in keys: + assert_allclose(result[key], expected[key].iloc[-1], atol=1e-4) + assert isinstance(result, dict) + + def test_klucher_series_float(): # klucher inputs surface_tilt, surface_azimuth = 40.0, 180.0 From 97a34f61bee1f70811933302a587d286588ba56b Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Mon, 22 Jun 2026 15:43:59 +0100 Subject: [PATCH 4/7] Add what's new entry --- docs/sphinx/source/whatsnew/v0.15.3.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.15.3.rst b/docs/sphinx/source/whatsnew/v0.15.3.rst index 87ded069ee..7f0c087fa0 100644 --- a/docs/sphinx/source/whatsnew/v0.15.3.rst +++ b/docs/sphinx/source/whatsnew/v0.15.3.rst @@ -18,6 +18,8 @@ Bug fixes Enhancements ~~~~~~~~~~~~ +* Add support for diffuse irradiance components to :py:func:`pvlib.irradiance.isotropic` + when ``return_components=True``. (:issue:`2750`, :pull:`2787`) Documentation From dcd202c0706e4ecb9deed59186b1e79e87eac5af Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Wed, 24 Jun 2026 12:20:36 +0100 Subject: [PATCH 5/7] Add support for 'return_components' --- pvlib/irradiance.py | 78 +++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index cb411b061b..bf01ace615 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -281,7 +281,8 @@ def get_total_irradiance(surface_tilt, surface_azimuth, dni, ghi, dhi, dni_extra=None, airmass=None, albedo=0.25, surface_type=None, model='isotropic', - model_perez='allsitescomposite1990'): + model_perez='allsitescomposite1990', + diffuse_components=False): r""" Determine total in-plane irradiance and its beam, sky diffuse and ground reflected components, using the specified sky diffuse irradiance model. @@ -332,10 +333,15 @@ def get_total_irradiance(surface_tilt, surface_azimuth, ``'perez-driesse'``. model_perez : str, default 'allsitescomposite1990' Used only if ``model='perez'``. See :py:func:`~pvlib.irradiance.perez`. + diffuse_components : bool, default False + If `True`, returns values for the different diffuse irradiance + components available from the selected model + (e.g., isotropic, circumsolar, horizon brightening). + If `False`, only the total diffuse irradiance is returned. Returns ------- - total_irrad : OrderedDict or DataFrame + total_irrad : Dict or DataFrame Contains keys/columns ``'poa_global', 'poa_direct', 'poa_diffuse', 'poa_sky_diffuse', 'poa_ground_diffuse'``. [Wm⁻²] @@ -353,7 +359,7 @@ def get_total_irradiance(surface_tilt, surface_azimuth, poa_sky_diffuse = get_sky_diffuse( surface_tilt, surface_azimuth, solar_zenith, solar_azimuth, dni, ghi, dhi, dni_extra=dni_extra, airmass=airmass, model=model, - model_perez=model_perez) + model_perez=model_perez, return_components=diffuse_components) poa_ground_diffuse = get_ground_diffuse(surface_tilt, ghi, albedo, surface_type) @@ -366,7 +372,8 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth, dni, ghi, dhi, dni_extra=None, airmass=None, model='isotropic', - model_perez='allsitescomposite1990'): + model_perez='allsitescomposite1990', + return_components=False): r""" Determine in-plane sky diffuse irradiance component using the specified sky diffuse irradiance model. @@ -408,11 +415,20 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, ``'perez-driesse'``. model_perez : str, default 'allsitescomposite1990' Used only if ``model='perez'``. See :py:func:`~pvlib.irradiance.perez`. + return_components : bool, default False + If `True`, returns values for the different diffuse irradiance + components available from the selected model + (e.g., isotropic, circumsolar, horizon brightening). + If `False`, only the total diffuse irradiance is returned. Returns ------- - poa_sky_diffuse : numeric - Sky diffuse irradiance in the plane of array. [Wm⁻²] + numeric, Dict, or DataFrame + Return type controlled by ``return_components`` argument. + If `False`, total sky diffuse irradiance in the plane of array + is returned (numeric). [Wm⁻²] + If `True`, the different diffuse components are returned + (Dict or DataFrame). [Wm⁻²] Raises ------ @@ -443,16 +459,19 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, raise ValueError(f'dni_extra is required for model {model}') if model == 'isotropic': - sky = isotropic(surface_tilt, dhi) + sky = isotropic(surface_tilt, dhi, return_components=return_components) elif model == 'klucher': sky = klucher(surface_tilt, surface_azimuth, dhi, ghi, - solar_zenith, solar_azimuth) + solar_zenith, solar_azimuth, + return_components=return_components) elif model == 'haydavies': sky = haydavies(surface_tilt, surface_azimuth, dhi, dni, dni_extra, - solar_zenith, solar_azimuth) + solar_zenith, solar_azimuth, + return_components=return_components) elif model == 'reindl': sky = reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra, - solar_zenith, solar_azimuth) + solar_zenith, solar_azimuth, + return_components=return_components) elif model == 'king': sky = king(surface_tilt, dhi, ghi, solar_zenith) elif model == 'perez': @@ -460,11 +479,12 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, airmass = atmosphere.get_relative_airmass(solar_zenith) sky = perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra, solar_zenith, solar_azimuth, airmass, - model=model_perez) + model=model_perez, return_components=return_components) elif model == 'perez-driesse': # perez_driesse will calculate its own airmass if needed sky = perez_driesse(surface_tilt, surface_azimuth, dhi, dni, dni_extra, - solar_zenith, solar_azimuth, airmass) + solar_zenith, solar_azimuth, airmass, + return_components=return_components) else: raise ValueError(f'invalid model selection {model}') @@ -488,7 +508,7 @@ def poa_components(aoi, dni, poa_sky_diffuse, poa_ground_diffuse): Direct normal irradiance, as measured from a TMY file or calculated with a clearsky model. See :term:`dni`. [Wm⁻²] - poa_sky_diffuse : numeric + poa_sky_diffuse : numeric, Dict or DataFrame Diffuse irradiance in the plane of the modules, as calculated by a diffuse irradiance translation function. [Wm⁻²] @@ -499,7 +519,7 @@ def poa_components(aoi, dni, poa_sky_diffuse, poa_ground_diffuse): Returns ------- - irrads : OrderedDict or DataFrame + irrads : Dict or DataFrame Contains the following keys: * ``poa_global`` : Total in-plane irradiance. [Wm⁻²] @@ -508,22 +528,38 @@ def poa_components(aoi, dni, poa_sky_diffuse, poa_ground_diffuse): * ``poa_sky_diffuse`` : In-plane diffuse irradiance from sky. [Wm⁻²] * ``poa_ground_diffuse`` : In-plane diffuse irradiance from ground. [Wm⁻²] + + If ``poa_sky_diffuse`` is a Dict or DataFrame, ``irrads`` will + contain additional keys for each of the diffuse components returned by + the selected diffuse irradiance model. Notes ------ Negative beam irradiation due to AOI > 90° or AOI < 0° is set to zero. ''' + if isinstance(poa_sky_diffuse, dict): + sky_components = poa_sky_diffuse.copy() + total_poa_sky_diffuse = sky_components.pop('poa_sky_diffuse') + elif isinstance(poa_sky_diffuse, pd.DataFrame): + sky_components = poa_sky_diffuse.to_dict(orient='series') + total_poa_sky_diffuse = sky_components.pop('poa_sky_diffuse') + else: + sky_components = {} + total_poa_sky_diffuse = poa_sky_diffuse + poa_direct = np.maximum(dni * np.cos(np.radians(aoi)), 0) - poa_diffuse = poa_sky_diffuse + poa_ground_diffuse + poa_diffuse = total_poa_sky_diffuse + poa_ground_diffuse poa_global = poa_direct + poa_diffuse - irrads = OrderedDict() - irrads['poa_global'] = poa_global - irrads['poa_direct'] = poa_direct - irrads['poa_diffuse'] = poa_diffuse - irrads['poa_sky_diffuse'] = poa_sky_diffuse - irrads['poa_ground_diffuse'] = poa_ground_diffuse + irrads = { + 'poa_global': poa_global, + 'poa_direct': poa_direct, + 'poa_diffuse': poa_diffuse, + 'poa_sky_diffuse': total_poa_sky_diffuse, + 'poa_ground_diffuse': poa_ground_diffuse, + **sky_components + } if isinstance(poa_direct, pd.Series): irrads = pd.DataFrame(irrads) From 722f6fd27651cae943291b23f46cd6f1f1af374a Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Mon, 29 Jun 2026 12:03:02 +0100 Subject: [PATCH 6/7] Add tests --- pvlib/irradiance.py | 2 +- tests/test_irradiance.py | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index bf01ace615..cec3267ff7 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -528,7 +528,7 @@ def poa_components(aoi, dni, poa_sky_diffuse, poa_ground_diffuse): * ``poa_sky_diffuse`` : In-plane diffuse irradiance from sky. [Wm⁻²] * ``poa_ground_diffuse`` : In-plane diffuse irradiance from ground. [Wm⁻²] - + If ``poa_sky_diffuse`` is a Dict or DataFrame, ``irrads`` will contain additional keys for each of the diffuse components returned by the selected diffuse irradiance model. diff --git a/tests/test_irradiance.py b/tests/test_irradiance.py index f4fe6ea547..2c3c080d6c 100644 --- a/tests/test_irradiance.py +++ b/tests/test_irradiance.py @@ -536,6 +536,28 @@ def test_get_total_irradiance(irrad_data, ephem_data, dni_et, 'poa_ground_diffuse'] +def test_get_total_irradiance_diffuse_components(irrad_data, ephem_data, + dni_et, relative_airmass): + models = ['perez', 'perez-driesse'] + + for model in models: + total = irradiance.get_total_irradiance( + 32, 180, + ephem_data['apparent_zenith'], ephem_data['azimuth'], + dni=irrad_data['dni'], ghi=irrad_data['ghi'], + dhi=irrad_data['dhi'], + dni_extra=dni_et, airmass=relative_airmass, + model=model, + surface_type='urban', + diffuse_components=True) + + assert total.columns.tolist() == ['poa_global', 'poa_direct', + 'poa_diffuse', 'poa_sky_diffuse', + 'poa_ground_diffuse', + 'poa_isotropic', 'poa_circumsolar', + 'poa_horizon'] + + @pytest.mark.parametrize('model', ['isotropic', 'klucher', 'haydavies', 'reindl', 'king', 'perez', 'perez-driesse']) @@ -625,6 +647,59 @@ def test_poa_components(irrad_data, ephem_data, dni_et, relative_airmass): assert_frame_equal(out, expected) +def test_poa_components_diffuse_components_perez(irrad_data, ephem_data, + dni_et, relative_airmass): + aoi = irradiance.aoi(40, 180, ephem_data['apparent_zenith'], + ephem_data['azimuth']) + gr_sand = irradiance.get_ground_diffuse(40, irrad_data['ghi'], + surface_type='sand') + diff_perez = irradiance.perez( + 40, 180, irrad_data['dhi'], irrad_data['dni'], dni_et, + ephem_data['apparent_zenith'], ephem_data['azimuth'], relative_airmass, + return_components=True) + out = irradiance.poa_components( + aoi, irrad_data['dni'], diff_perez, gr_sand) + expected = pd.DataFrame(np.array( + [[0., -0., 0., 0., + 0., 0., 0., 0.], + [35.19456561, 0., 35.19456561, 31.4635077, + 3.73105791, 26.841386, 0.000000, 4.622122], + [956.18253696, 798.31939281, 157.86314414, 109.08433162, + 48.77881252, 41.621826, 61.619987, 5.842518], + [90.99624896, 33.50143401, 57.49481495, 45.45978964, + 12.03502531, 31.726961, 4.479664, 9.253165]]), + columns=['poa_global', 'poa_direct', 'poa_diffuse', 'poa_sky_diffuse', + 'poa_ground_diffuse', 'poa_isotropic', 'poa_circumsolar', + 'poa_horizon'], + index=irrad_data.index) + assert_frame_equal(out, expected) + + +def test_poa_components_diffuse_components_isotropic(irrad_data, ephem_data, + dni_et, relative_airmass): + aoi = irradiance.aoi(40, 180, ephem_data['apparent_zenith'], + ephem_data['azimuth']) + gr_sand = irradiance.get_ground_diffuse(40, irrad_data['ghi'], + surface_type='sand') + diff_isotropic = irradiance.isotropic( + 40, irrad_data['dhi'], return_components=True) + out = irradiance.poa_components( + aoi, irrad_data['dni'], diff_isotropic, gr_sand) + expected = pd.DataFrame(np.array( + [[0., -0., 0., 0., + 0., 0.], + [39.459460, 0.000000, 39.459460, 35.728402, + 3.731058, 35.728402], + [951.699533, 798.319393, 153.380140, 104.601328, + 48.778813, 104.601328], + [100.313650, 33.501434, 66.812216, 54.777191, + 12.035025, 54.777191]]), + columns=['poa_global', 'poa_direct', 'poa_diffuse', 'poa_sky_diffuse', + 'poa_ground_diffuse', 'poa_isotropic'], + index=irrad_data.index) + assert_frame_equal(out, expected) + + @pytest.mark.parametrize('pressure,expected', [ (93193, [[830.46567, 0.79742, 0.93505], [676.18340, 0.63782, 3.02102]]), From 2eb64ca73508e806bcf4da1a61ef6b6b0196d2cc Mon Sep 17 00:00:00 2001 From: cbcrespo Date: Wed, 1 Jul 2026 13:16:31 +0100 Subject: [PATCH 7/7] Raise error if return_components=True used with king or klucher --- pvlib/irradiance.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index cec3267ff7..3ea5b55832 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -338,6 +338,8 @@ def get_total_irradiance(surface_tilt, surface_azimuth, components available from the selected model (e.g., isotropic, circumsolar, horizon brightening). If `False`, only the total diffuse irradiance is returned. + This option is not available for the ``'klucher'`` and + ``'king'`` models. Returns ------- @@ -420,6 +422,8 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, components available from the selected model (e.g., isotropic, circumsolar, horizon brightening). If `False`, only the total diffuse irradiance is returned. + This option is not available for the ``'klucher'`` and + ``'king'`` models. Returns ------- @@ -454,6 +458,10 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, model = model.lower() + if return_components and model in {'klucher', 'king'}: + raise ValueError('return_components is not supported for' + f' model {model}') + if dni_extra is None and model in {'haydavies', 'reindl', 'perez', 'perez-driesse'}: raise ValueError(f'dni_extra is required for model {model}') @@ -462,8 +470,7 @@ def get_sky_diffuse(surface_tilt, surface_azimuth, sky = isotropic(surface_tilt, dhi, return_components=return_components) elif model == 'klucher': sky = klucher(surface_tilt, surface_azimuth, dhi, ghi, - solar_zenith, solar_azimuth, - return_components=return_components) + solar_zenith, solar_azimuth) elif model == 'haydavies': sky = haydavies(surface_tilt, surface_azimuth, dhi, dni, dni_extra, solar_zenith, solar_azimuth,