From 651318e6b59f4ece3e01645faaa969ffd51a7b9a Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Mon, 12 Jun 2023 10:35:31 -0400 Subject: [PATCH 1/4] rename parameter, and docstring cleanup --- pvlib/spectrum/mismatch.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pvlib/spectrum/mismatch.py b/pvlib/spectrum/mismatch.py index a7e7cf0851..f6c8e08200 100644 --- a/pvlib/spectrum/mismatch.py +++ b/pvlib/spectrum/mismatch.py @@ -239,8 +239,9 @@ def integrate(e): return smm -def spectral_factor_firstsolar(pw, airmass_absolute, module_type=None, - coefficients=None, min_pw=0.1, max_pw=8): +def spectral_factor_firstsolar(precipitable_water, airmass_absolute, + module_type=None, coefficients=None, + min_pw=0.1, max_pw=8): r""" Spectral mismatch modifier based on precipitable water and absolute (pressure-adjusted) airmass. @@ -277,21 +278,13 @@ def spectral_factor_firstsolar(pw, airmass_absolute, module_type=None, Parameters ---------- - pw : array-like + precipitable_water : numeric atmospheric precipitable water. [cm] - airmass_absolute : array-like + airmass_absolute : numeric absolute (pressure-adjusted) airmass. [unitless] - min_pw : float, default 0.1 - minimum atmospheric precipitable water. Any pw value lower than min_pw - is set to min_pw to avoid model divergence. [cm] - - max_pw : float, default 8 - maximum atmospheric precipitable water. Any pw value higher than max_pw - is set to NaN to avoid model divergence. [cm] - - module_type : None or string, default None + module_type : str, optional a string specifying a cell type. Values of 'cdte', 'monosi', 'xsi', 'multisi', and 'polysi' (can be lower or upper case). If provided, module_type selects default coefficients for the following modules: @@ -307,7 +300,7 @@ def spectral_factor_firstsolar(pw, airmass_absolute, module_type=None, Manufacturer 2 Model C from [3]_. The spectral response (SR) of CIGS and a-Si modules used to derive coefficients can be found in [4]_ - coefficients : None or array-like, default None + coefficients : array-like, optional Allows for entry of user-defined spectral correction coefficients. Coefficients must be of length 6. Derivation of coefficients requires use of SMARTS and PV module quantum @@ -317,6 +310,14 @@ def spectral_factor_firstsolar(pw, airmass_absolute, module_type=None, modules with very similar quantum efficiency should be similar, in most cases limiting the need for module specific coefficients. + min_pw : float, default 0.1 + minimum atmospheric precipitable water. Any pw value lower than min_pw + is set to min_pw to avoid model divergence. [cm] + + max_pw : float, default 8 + maximum atmospheric precipitable water. Any pw value higher than max_pw + is set to NaN to avoid model divergence. [cm] + Returns ------- modifier: array-like @@ -347,7 +348,7 @@ def spectral_factor_firstsolar(pw, airmass_absolute, module_type=None, # *** Pw *** # Replace Pw Values below 0.1 cm with 0.1 cm to prevent model from # diverging" - pw = np.atleast_1d(pw) + pw = np.atleast_1d(precipitable_water) pw = pw.astype('float64') if np.min(pw) < min_pw: pw = np.maximum(pw, min_pw) From f17c309a271d59027c4bb7c9b5091770713422cd Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Mon, 12 Jun 2023 10:36:56 -0400 Subject: [PATCH 2/4] whatsnew --- docs/sphinx/source/whatsnew/v0.9.6.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index 889f456e0c..b7ce3f631b 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -10,6 +10,9 @@ Breaking Changes * Modified the ``surface_azimuth`` parameter in :py:func:`pvlib.iotools.get_pvgis_hourly` to conform to the pvlib azimuth convention (counterclockwise from north). Previously 0 degrees represented south. (:issue:`1724`, :pull:`1739`) +* For consistency with the rest of pvlib, the ``pw`` parameter is renamed to + ``precipitable_water`` in :py:func:`pvlib.spectrum.spectral_factor_firstsolar`. + (:pull:`1768`) * For consistency with the rest of pvlib, the ``tilt`` parameter is renamed to ``surface_tilt`` in :py:func:`pvlib.soiling.hsu`. (:issue:`1717`, :pull:`1738`) From 799b8efb0370e4bea378cac8960f4fefae2390cc Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Thu, 15 Jun 2023 09:59:49 -0400 Subject: [PATCH 3/4] edits from review --- docs/sphinx/source/whatsnew/v0.9.6.rst | 2 +- pvlib/spectrum/mismatch.py | 31 ++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index b7ce3f631b..3ec9bf9f9b 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -10,7 +10,7 @@ Breaking Changes * Modified the ``surface_azimuth`` parameter in :py:func:`pvlib.iotools.get_pvgis_hourly` to conform to the pvlib azimuth convention (counterclockwise from north). Previously 0 degrees represented south. (:issue:`1724`, :pull:`1739`) -* For consistency with the rest of pvlib, the ``pw`` parameter is renamed to +* For consistency with the rest of pvlib, the ``pw`` parameters are renamed to ``precipitable_water`` in :py:func:`pvlib.spectrum.spectral_factor_firstsolar`. (:pull:`1768`) * For consistency with the rest of pvlib, the ``tilt`` parameter is renamed diff --git a/pvlib/spectrum/mismatch.py b/pvlib/spectrum/mismatch.py index f6c8e08200..3319ee12cd 100644 --- a/pvlib/spectrum/mismatch.py +++ b/pvlib/spectrum/mismatch.py @@ -241,7 +241,8 @@ def integrate(e): def spectral_factor_firstsolar(precipitable_water, airmass_absolute, module_type=None, coefficients=None, - min_pw=0.1, max_pw=8): + min_precipitable_water=0.1, + max_precipitable_water=8): r""" Spectral mismatch modifier based on precipitable water and absolute (pressure-adjusted) airmass. @@ -310,18 +311,20 @@ def spectral_factor_firstsolar(precipitable_water, airmass_absolute, modules with very similar quantum efficiency should be similar, in most cases limiting the need for module specific coefficients. - min_pw : float, default 0.1 - minimum atmospheric precipitable water. Any pw value lower than min_pw - is set to min_pw to avoid model divergence. [cm] + min_precipitable_water : float, default 0.1 + minimum atmospheric precipitable water. Any ``precipitable_water`` + value lower than ``min_precipitable_water`` + is set to ``min_precipitable_water`` to avoid model divergence. [cm] - max_pw : float, default 8 - maximum atmospheric precipitable water. Any pw value higher than max_pw - is set to NaN to avoid model divergence. [cm] + max_precipitable_water : float, default 8 + maximum atmospheric precipitable water. Any ``precipitable_water`` + value greater than ``max_precipitable_water`` + is set to ``np.nan`` to avoid model divergence. [cm] Returns ------- modifier: array-like - spectral mismatch factor (unitless) which is can be multiplied + spectral mismatch factor (unitless) which can be multiplied with broadband irradiance reaching a module's cells to estimate effective irradiance, i.e., the irradiance that is converted to electrical current. @@ -350,14 +353,14 @@ def spectral_factor_firstsolar(precipitable_water, airmass_absolute, # diverging" pw = np.atleast_1d(precipitable_water) pw = pw.astype('float64') - if np.min(pw) < min_pw: - pw = np.maximum(pw, min_pw) - warn(f'Exceptionally low pw values replaced with {min_pw} cm to ' - 'prevent model divergence') + if np.min(pw) < min_precipitable_water: + pw = np.maximum(pw, min_precipitable_water) + warn('Exceptionally low pw values replaced with ' + f'{min_precipitable_water} cm to prevent model divergence') # Warn user about Pw data that is exceptionally high - if np.max(pw) > max_pw: - pw[pw > max_pw] = np.nan + if np.max(pw) > max_precipitable_water: + pw[pw > max_precipitable_water] = np.nan warn('Exceptionally high pw values replaced by np.nan: ' 'check input data.') From e06a8890a8f50e9ef4d1fe86307a551a7a85db50 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Thu, 15 Jun 2023 10:54:57 -0400 Subject: [PATCH 4/4] update tests --- pvlib/tests/test_spectrum.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pvlib/tests/test_spectrum.py b/pvlib/tests/test_spectrum.py index 444e45733c..23a7c837ee 100644 --- a/pvlib/tests/test_spectrum.py +++ b/pvlib/tests/test_spectrum.py @@ -243,7 +243,8 @@ def test_spectral_factor_firstsolar_range(): expected = np.array([0.96080878, 1.03055092, np.nan]) assert_allclose(out, expected, atol=1e-3) with pytest.warns(UserWarning, match='Exceptionally high pw values'): - out = spectrum.spectral_factor_firstsolar(6, 1.5, max_pw=5, + out = spectrum.spectral_factor_firstsolar(6, 1.5, + max_precipitable_water=5, module_type='monosi') with pytest.warns(UserWarning, match='Exceptionally low pw values'): out = spectrum.spectral_factor_firstsolar(np.array([0, 3, 8]), @@ -252,7 +253,8 @@ def test_spectral_factor_firstsolar_range(): expected = np.array([0.96080878, 1.03055092, 1.04932727]) assert_allclose(out, expected, atol=1e-3) with pytest.warns(UserWarning, match='Exceptionally low pw values'): - out = spectrum.spectral_factor_firstsolar(0.2, 1.5, min_pw=1, + out = spectrum.spectral_factor_firstsolar(0.2, 1.5, + min_precipitable_water=1, module_type='monosi')