Description
Is your feature request related to a problem? Please describe.
pvlib.spectrum.average_photon_energy
docs indicate np.nan
is returned for all-zero input
How nan
values are handled when supplied as an input is neither documented nor tested.
Three examples:
import numpy as np
import pandas as pd
from pvlib.spectrum import average_photon_energy as calcape
test_all_nan = pd.DataFrame({100: [np.nan], 500: [np.nan], 1000: [np.nan]})
test_one_nan = pd.DataFrame({100: [1e-19], 500: [1e2], 1000: [np.nan]})
test_zero_nan = pd.DataFrame({100: [1e-19], 500: [1e2], 1000: [10]})
ape1 = calcape(test_all_nan)
ape2 = calcape(test_one_nan)
ape3 = calcape(test_zero_nan)
print(ape1, ape2, ape3)
0 NaN
dtype: float64 0 NaN
dtype: float64 0 2.3557
dtype: float64
In the case >= 1 nan
value, ape=nan.
I was just handling a large spectral irradiance dataset and it took me a minute to realise that the reason for the resultant APE values being far fewer than the input spectral distributions was that there were occasional nan
values dotted around for individual wavelengths at certain times throughout the year.
Describe the solution you'd like
Should the docs explain this behaviour and should the tests cover this? Is the current behaviour correct?
All-nan irradiance implies non-existence (different from zero) so it seems to make sense to return a nan
value. In the case of nan
at a single or even a few wavelengths seems more like a data quality issue. I lean towards leaving the behaviour as is, but documenting it. If documented, the user can then decide how to handle the nan-value cases, e.g. using a filling method. Seems out of scope for the function to offer this functionality. If documented, I think tests are required(?)