Skip to content

Commit 3fbd34a

Browse files
authored
Merge branch 'main' into nsrdb_goes_v4
2 parents 8f5ae98 + 922cc96 commit 3fbd34a

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/sphinx/source/whatsnew/v0.12.1.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Enhancements
2626
Documentation
2727
~~~~~~~~~~~~~
2828
* Add a supporting reference to :py:func:`pvlib.atmosphere.get_relative_airmass` (:issue:`2390`, :pull:`2424`)
29+
* Documented how `np.nan` values are handled by :py:func:`~pvlib.spectrum.average_photon_energy`
30+
(:issue:`2423`, :pull:`2426`)
2931

3032
Testing
3133
~~~~~~~
@@ -38,4 +40,5 @@ Maintenance
3840
Contributors
3941
~~~~~~~~~~~~
4042
* Cliff Hansen (:ghuser:`cwhanse`)
41-
* Will Hobbs (:ghuser:`williamhobbs`)
43+
* Rajiv Daxini (:ghuser:`RDaxini`)
44+
* Will Hobbs (:ghuser:`williamhobbs`)

pvlib/spectrum/irradiance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def average_photon_energy(spectra):
138138
ape : numeric or pandas.Series
139139
Average Photon Energy [eV].
140140
Note: returns ``np.nan`` in the case of all-zero spectral irradiance
141-
input.
141+
input, or where one or more spectral irradiance values is
142+
``np.nan``.
142143
143144
Notes
144145
-----

tests/spectrum/test_irradiance.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,24 @@ def test_average_photon_energy_zero_irr():
130130
expected_2 = np.nan
131131
assert_allclose(out_1, expected_1, atol=1e-3)
132132
assert_allclose(out_2, expected_2, atol=1e-3)
133+
134+
135+
def test_average_photon_energy_nan_irr():
136+
# test for handling NaN input
137+
138+
spectra_df_nan = spectrum.get_reference_spectra().T
139+
spectra_df_nan.loc["global", 315.0] = np.nan
140+
spectra_df_nan.loc['extraterrestrial', :] = np.nan
141+
142+
spectra_series_nan = spectrum.get_reference_spectra()['global']
143+
spectra_series_singlenan = spectra_series_nan.copy()
144+
spectra_series_singlenan.loc[315.0] = np.nan
145+
spectra_series_allnan = spectra_series_nan*np.nan
146+
147+
out1 = spectrum.average_photon_energy(spectra_df_nan)
148+
out2 = spectrum.average_photon_energy(spectra_series_singlenan)
149+
out3 = spectrum.average_photon_energy(spectra_series_allnan)
150+
151+
assert np.all(np.isnan(out1[['global', 'extraterrestrial']]))
152+
assert np.all(np.isnan(out2))
153+
assert np.all(np.isnan(out3))

0 commit comments

Comments
 (0)