From 250016cf7887b27f0dff73a9165fcd9c5c947017 Mon Sep 17 00:00:00 2001 From: RDaxini Date: Tue, 1 Apr 2025 16:57:39 -0600 Subject: [PATCH 1/8] docs: tentative wording --- pvlib/spectrum/irradiance.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pvlib/spectrum/irradiance.py b/pvlib/spectrum/irradiance.py index c03c99872d..9e84d72320 100644 --- a/pvlib/spectrum/irradiance.py +++ b/pvlib/spectrum/irradiance.py @@ -138,7 +138,8 @@ def average_photon_energy(spectra): ape : numeric or pandas.Series Average Photon Energy [eV]. Note: returns ``np.nan`` in the case of all-zero spectral irradiance - input. + input, or where one or more spectral irradiance values equal + ``np.nan``. Notes ----- From 1ff8c5fae95a923f2778319e67ded88d3270797c Mon Sep 17 00:00:00 2001 From: RDaxini Date: Tue, 1 Apr 2025 17:18:14 -0600 Subject: [PATCH 2/8] test: single+all nan (series+df) --- tests/spectrum/test_irradiance.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/spectrum/test_irradiance.py b/tests/spectrum/test_irradiance.py index df792c0668..311811edf5 100644 --- a/tests/spectrum/test_irradiance.py +++ b/tests/spectrum/test_irradiance.py @@ -130,3 +130,25 @@ def test_average_photon_energy_zero_irr(): expected_2 = np.nan assert_allclose(out_1, expected_1, atol=1e-3) assert_allclose(out_2, expected_2, atol=1e-3) + +def test_average_photon_energy_nan_irr(): + # test for handling NaN input + + spectra_df_nan = spectrum.get_reference_spectra().T + spectra_df_singlenan = spectra_df_nan.copy() + spectra_df_singlenan.loc["global", 315.0] = np.nan + spectra_df_allnan = spectra_df_nan * np.nan + + spectra_series_nan = spectrum.get_reference_spectra()['global'] + spectra_series_singlenan = spectra_series_nan.copy() + spectra_series_singlenan.loc[315.0] = np.nan + spectra_series_allnan = spectra_series_nan*np.nan + + out = [ + spectrum.average_photon_energy(spectra_df_singlenan), + spectrum.average_photon_energy(spectra_df_allnan), + spectrum.average_photon_energy(spectra_series_singlenan), + spectrum.average_photon_energy(spectra_series_allnan) + ] + + assert all(np.isnan(out)) \ No newline at end of file From 0f519c5be6cf6ea55e571ab92728763e6919af88 Mon Sep 17 00:00:00 2001 From: RDaxini Date: Tue, 1 Apr 2025 17:20:44 -0600 Subject: [PATCH 3/8] insert blank line --- tests/spectrum/test_irradiance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/spectrum/test_irradiance.py b/tests/spectrum/test_irradiance.py index 311811edf5..c79b61673e 100644 --- a/tests/spectrum/test_irradiance.py +++ b/tests/spectrum/test_irradiance.py @@ -143,7 +143,7 @@ def test_average_photon_energy_nan_irr(): spectra_series_singlenan = spectra_series_nan.copy() spectra_series_singlenan.loc[315.0] = np.nan spectra_series_allnan = spectra_series_nan*np.nan - + out = [ spectrum.average_photon_energy(spectra_df_singlenan), spectrum.average_photon_energy(spectra_df_allnan), @@ -151,4 +151,4 @@ def test_average_photon_energy_nan_irr(): spectrum.average_photon_energy(spectra_series_allnan) ] - assert all(np.isnan(out)) \ No newline at end of file + assert all(np.isnan(out)) From 200af6364d1c3287620e0f8937a2bfc5b6dd847e Mon Sep 17 00:00:00 2001 From: RDaxini Date: Tue, 1 Apr 2025 17:26:54 -0600 Subject: [PATCH 4/8] fix test assert statement --- tests/spectrum/test_irradiance.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/spectrum/test_irradiance.py b/tests/spectrum/test_irradiance.py index c79b61673e..46ede8ea4c 100644 --- a/tests/spectrum/test_irradiance.py +++ b/tests/spectrum/test_irradiance.py @@ -131,6 +131,7 @@ def test_average_photon_energy_zero_irr(): assert_allclose(out_1, expected_1, atol=1e-3) assert_allclose(out_2, expected_2, atol=1e-3) + def test_average_photon_energy_nan_irr(): # test for handling NaN input @@ -144,11 +145,11 @@ def test_average_photon_energy_nan_irr(): spectra_series_singlenan.loc[315.0] = np.nan spectra_series_allnan = spectra_series_nan*np.nan - out = [ + output = [ spectrum.average_photon_energy(spectra_df_singlenan), spectrum.average_photon_energy(spectra_df_allnan), spectrum.average_photon_energy(spectra_series_singlenan), spectrum.average_photon_energy(spectra_series_allnan) ] - assert all(np.isnan(out)) + assert (all(np.isnan(out)) for out in output) From 895454d905e0250d123b250c5e5b982879920d61 Mon Sep 17 00:00:00 2001 From: RDaxini Date: Tue, 1 Apr 2025 17:38:19 -0600 Subject: [PATCH 5/8] fix tests --- tests/spectrum/test_irradiance.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/spectrum/test_irradiance.py b/tests/spectrum/test_irradiance.py index 46ede8ea4c..36ca5da463 100644 --- a/tests/spectrum/test_irradiance.py +++ b/tests/spectrum/test_irradiance.py @@ -136,20 +136,19 @@ def test_average_photon_energy_nan_irr(): # test for handling NaN input spectra_df_nan = spectrum.get_reference_spectra().T - spectra_df_singlenan = spectra_df_nan.copy() - spectra_df_singlenan.loc["global", 315.0] = np.nan - spectra_df_allnan = spectra_df_nan * np.nan + spectra_df_nan.loc["global", 315.0] = np.nan + spectra_df_nan.loc['extraterrestrial', :] = np.nan spectra_series_nan = spectrum.get_reference_spectra()['global'] spectra_series_singlenan = spectra_series_nan.copy() spectra_series_singlenan.loc[315.0] = np.nan spectra_series_allnan = spectra_series_nan*np.nan - output = [ - spectrum.average_photon_energy(spectra_df_singlenan), - spectrum.average_photon_energy(spectra_df_allnan), - spectrum.average_photon_energy(spectra_series_singlenan), - spectrum.average_photon_energy(spectra_series_allnan) - ] + out1 = spectrum.average_photon_energy(spectra_df_nan) + out2 = spectrum.average_photon_energy(spectra_series_singlenan) + out3 = spectrum.average_photon_energy(spectra_series_allnan) - assert (all(np.isnan(out)) for out in output) + assert np.all(np.isnan(out1['global'])) + assert np.all(np.isnan(out1['extraterrestrial'])) + assert np.all(np.isnan(out2)) + assert np.all(np.isnan(out3)) From d67b93969bc8d82ca2ac75b3b5e29144980caa16 Mon Sep 17 00:00:00 2001 From: RDaxini Date: Tue, 1 Apr 2025 17:39:16 -0600 Subject: [PATCH 6/8] combine assert out1 lines --- tests/spectrum/test_irradiance.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/spectrum/test_irradiance.py b/tests/spectrum/test_irradiance.py index 36ca5da463..59ce66b269 100644 --- a/tests/spectrum/test_irradiance.py +++ b/tests/spectrum/test_irradiance.py @@ -148,7 +148,6 @@ def test_average_photon_energy_nan_irr(): out2 = spectrum.average_photon_energy(spectra_series_singlenan) out3 = spectrum.average_photon_energy(spectra_series_allnan) - assert np.all(np.isnan(out1['global'])) - assert np.all(np.isnan(out1['extraterrestrial'])) + assert np.all(np.isnan(out1[['global', 'extraterrestrial']])) assert np.all(np.isnan(out2)) assert np.all(np.isnan(out3)) From df8079e3152f41f674651da3b056ef2b8f4f1aa0 Mon Sep 17 00:00:00 2001 From: RDaxini Date: Fri, 4 Apr 2025 11:09:13 -0600 Subject: [PATCH 7/8] equal->is --- pvlib/spectrum/irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/spectrum/irradiance.py b/pvlib/spectrum/irradiance.py index 9e84d72320..fc3440cd19 100644 --- a/pvlib/spectrum/irradiance.py +++ b/pvlib/spectrum/irradiance.py @@ -138,7 +138,7 @@ def average_photon_energy(spectra): ape : numeric or pandas.Series Average Photon Energy [eV]. Note: returns ``np.nan`` in the case of all-zero spectral irradiance - input, or where one or more spectral irradiance values equal + input, or where one or more spectral irradiance values is ``np.nan``. Notes From 14773c00a84bef8d6e8b8efa4be30ef9540d0ec8 Mon Sep 17 00:00:00 2001 From: RDaxini Date: Fri, 4 Apr 2025 11:19:26 -0600 Subject: [PATCH 8/8] Update v0.12.1.rst --- docs/sphinx/source/whatsnew/v0.12.1.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.12.1.rst b/docs/sphinx/source/whatsnew/v0.12.1.rst index 9f35593e18..290965e634 100644 --- a/docs/sphinx/source/whatsnew/v0.12.1.rst +++ b/docs/sphinx/source/whatsnew/v0.12.1.rst @@ -19,6 +19,8 @@ Enhancements Documentation ~~~~~~~~~~~~~ * Add a supporting reference to :py:func:`pvlib.atmosphere.get_relative_airmass` (:issue:`2390`, :pull:`2424`) +* Documented how `np.nan` values are handled by :py:func:`~pvlib.spectrum.average_photon_energy` + (:issue:`2423`, :pull:`2426`) Testing ~~~~~~~ @@ -31,3 +33,4 @@ Maintenance Contributors ~~~~~~~~~~~~ * Cliff Hansen (:ghuser:`cwhanse`) +* Rajiv Daxini (:ghuser:`RDaxini`)