Skip to content

Remove out-of-range warnings from pvlib.spectrum.spectral_factor_firstsolar #2512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.13.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Enhancements
~~~~~~~~~~~~
* Add :py:func:`pvlib.iotools.get_nasa_power` to retrieve data from NASA POWER free API.
(:pull:`2500`)
* :py:func:`pvlib.spectrum.spectral_factor_firstsolar` no longer emits warnings
when airmass and precipitable water values fall out of range. (:pull:`2512`)

Documentation
~~~~~~~~~~~~~
Expand Down Expand Up @@ -51,3 +53,4 @@ Contributors
* Ioannis Sifnaios (:ghuser:`IoannisSifnaios`)
* Rajiv Daxini (:ghuser:`RDaxini`)
* Omar Bahamida (:ghuser:`OmarBahamida`)
* Kevin Anderson (:ghuser:`kandersolar`)
26 changes: 7 additions & 19 deletions pvlib/spectrum/mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,15 @@ def spectral_factor_firstsolar(precipitable_water, airmass_absolute,
"""
pw = np.atleast_1d(precipitable_water)
pw = pw.astype('float64')
if np.min(pw) < min_precipitable_water:
pw = np.maximum(pw, min_precipitable_water)
warn('Low precipitable water values replaced with '
f'{min_precipitable_water} cm in the calculation of spectral '
'mismatch.')

if np.max(pw) > max_precipitable_water:
pw[pw > max_precipitable_water] = np.nan
warn('High precipitable water values replaced with np.nan in '
'the calculation of spectral mismatch.')
pw = np.maximum(pw, min_precipitable_water)
pw[pw > max_precipitable_water] = np.nan

airmass_absolute = np.minimum(airmass_absolute, max_airmass_absolute)

if np.min(airmass_absolute) < min_airmass_absolute:
airmass_absolute = np.maximum(airmass_absolute, min_airmass_absolute)
warn('Low airmass values replaced with 'f'{min_airmass_absolute} in '
'the calculation of spectral mismatch.')
# pvlib.atmosphere.get_absolute_airmass(1,
# pvlib.atmosphere.alt2pres(4340)) = 0.58 Elevation of
# Mina Pirquita, Argentian = 4340 m. Highest elevation city with
# population over 50,000.
# pvlib.atmosphere.get_absolute_airmass(1,
# pvlib.atmosphere.alt2pres(4340)) = 0.58 Elevation of
# Mina Pirquita, Argentian = 4340 m. Highest elevation city with
# population over 50,000.
airmass_absolute = np.maximum(airmass_absolute, min_airmass_absolute)

_coefficients = {}
_coefficients['cdte'] = (
Expand Down
20 changes: 3 additions & 17 deletions tests/spectrum/test_mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def test_spectral_factor_firstsolar_low_airmass():
m_eq58 = spectrum.spectral_factor_firstsolar(1, 0.58, 'monosi')
m_lt58 = spectrum.spectral_factor_firstsolar(1, 0.1, 'monosi')
assert_allclose(m_eq58, m_lt58)
with pytest.warns(UserWarning, match='Low airmass values replaced'):
_ = spectrum.spectral_factor_firstsolar(1, 0.1, 'monosi')


def test_spectral_factor_firstsolar_range():
Expand All @@ -122,23 +120,11 @@ def test_spectral_factor_firstsolar_range():
module_type='monosi')
expected = np.array([0.96080878, 1.03055092, np.nan])
assert_allclose(out, expected, atol=1e-3)
with pytest.warns(UserWarning, match='High precipitable water values '
'replaced'):
out = spectrum.spectral_factor_firstsolar(6, 1.5,
max_precipitable_water=5,
module_type='monosi')
with pytest.warns(UserWarning, match='Low precipitable water values '
'replaced'):
out = spectrum.spectral_factor_firstsolar(np.array([0, 3, 8]),
np.array([1, 3, 5]),
module_type='monosi')
out = spectrum.spectral_factor_firstsolar(np.array([0, 3, 8]),
np.array([1, 3, 5]),
module_type='monosi')
expected = np.array([0.96080878, 1.03055092, 1.04932727])
assert_allclose(out, expected, atol=1e-3)
with pytest.warns(UserWarning, match='Low precipitable water values '
'replaced'):
out = spectrum.spectral_factor_firstsolar(0.2, 1.5,
min_precipitable_water=1,
module_type='monosi')


@pytest.mark.parametrize('airmass,expected', [
Expand Down
Loading