Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 2 additions & 1 deletion pvlib/spectrum/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
21 changes: 21 additions & 0 deletions tests/spectrum/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,24 @@ 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_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

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 np.all(np.isnan(out1[['global', 'extraterrestrial']]))
assert np.all(np.isnan(out2))
assert np.all(np.isnan(out3))