pvlib-python: pvsystem.Array.get_irradiance raises an error if solar_zenith is passed as a float
Bug Description
pvsystem.get_irradiance
documentation says solar_zenith can be passed as a float or a Series. However, if dni_extra
is not defined and solar_zenith
is passed as float, then solar_zenith.index
is not defined and the call to irradiance.get_extra_irradiance
with solar_zenith.index
as an argument fails.
To Reproduce
Steps to reproduce the behavior:
test_sys = pvsystem.PVSystem()
test_sys.get_irradiance(0.0, 0.0, 0.0, 0.0, 0.0)
Error message
AttributeError: 'float' object has no attribute 'index'
Expected behavior Return a DataFrame containing the irradiance components, as specified in the documentation.
Possible solutions
- Ask for datetime if
dni_extra
is not passed as argument - Remove float from supported types for
solar_zenith
Versions:
pvlib.__version__
: 0.9.0pandas.__version__
: 1.3.3- python: 3.9
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15 (7 by maintainers)
*must be a Series with a DatetimeIndex.
I also like @kanderso-nrel’s suggestion in https://github.com/pvlib/pvlib-python/issues/1338#issuecomment-967232590
Most or all of the bottom layer functions work with scalars and I think that’s important. May be less so for the classes, but still desirable.
@kanderso-nrel You are right in pointing out that the invoked function is
Array.get_irradiance
, but it’s not possible to instantiate a simple Array witharray=pvsystem.Array()
, as a mount needs to be defined. That’s why I used the wrapperPVSystem.get_irradiance
in my simple example for reproducing the bug.About the use case, I passed scalars whereas I was exploring the module and testing it in a Jupyter notebook, without making real calculations. I can imagine it’s not a typical use case but I believe that if the documentation says it is a supported case, then it should really be 😃
Quibble: technically it is
Array.get_irradiance
(notPVSystem.get_irradiance
) that calculatesdni_extra
if it is missing:https://github.com/pvlib/pvlib-python/blob/90013a5ce43611c43224b3a2f3ef72f54ad527af/pvlib/pvsystem.py#L1468-L1469
I think I also lean towards option 3. I think changing that condition to
dni_extra is None and hasattr(solar_zenith, 'index')
would result inValueError: dni_extra is required for model haydavies
, which seems ok to me.Just curious, what’s the use case for passing scalars? I personally can’t recall a case where I’ve used anything other than Series.
You could perhaps just use the solar constant as
dni_extra
when all else fails. Then you don’t need to raise anything.