You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
atmosphere.py bug fix on get_relative_airmass airmass #607
Describe the bug
A clear and concise description of what the bug is.
on conda download, line 222 problem with cos fix
comment out line 216
z = np.where(zenith > 90, np.nan, zenith)
and add an absolute valie on line 223
... +np.absolute (90 - z)) ** - 1.6364))))
I think I will do that, I guess there is no airmass formula for nighttime because the function is mostly auxiliary for the rest of PV analysis and so it doesn’t expect those values to be inputted?
I vote not to silence it, let the user decide to silence it. IMO pvlib is a toolbox not production, so it should raise all warnings and exceptions
@mikofski I agree with the spirit of this but I in practice I think it's more complicated. numpy warnings are often emitted for valid inputs due to well-understood implementation details. log(0), exp(very big number), cos(nan), etc. I think pvlib should implement things in a way that the warnings are not emitted or selectively silence them in with blocks where necessary. This way users are more likely to think twice when they do see a warning. That's the core of this issue, at least so far as I understand it.
I guess there is no airmass formula for nighttime because the function is mostly auxiliary for the rest of PV analysis and so it doesn’t expect those values to be inputted?
@jramirezpr Airmass is not defined when zenith is greater than ~90 degrees, so the function returns nan. The function emits this warning because it sets the nans before the calculating the airmass.
#608 prevents a numpy warning when am=np.nan that is due to pvlib statement sequence. Unless we can reproduce what is causing the numpy warning on np.cos(np.nan) for @jramirezpr, I don't see any action to take on this issue.
@cwhanse on a similar note, i found some more warnings when changing the model to perez
C:\Users\Guest\Anaconda3\lib\site-packages\pvlib\irradiance.py:1150: RuntimeWarning: invalid value encountered in maximum
F1 = np.maximum(F1, 0)
C:\Users\Guest\Anaconda3\lib\site-packages\pvlib\irradiance.py:1153: RuntimeWarning: invalid value encountered in maximum
F2 = np.maximum(F2, 0)
C:\Users\Guest\Anaconda3\lib\site-packages\pvlib\irradiance.py:1167: RuntimeWarning: invalid value encountered in maximum
sky_diffuse = np.maximum(dhi * (term1 + term2 + term3), 0)
I'm going to silence them for now, but thought you might want to know.
Activity
mikofski commentedon Oct 18, 2018
Hi @jramirezpr , thanks for reporting your issue. 😄
Can you please execute
and post here either the output or the traceback ? Also please output
pvlib.__version__and your version of Python.I'm using conda (Python-3.7) and the latest version of pvlib (0.6.0+27.g3077923) and I get
1.9942928525292494and no traceback.jramirezpr commentedon Oct 18, 2018
The error seems to be when zenith>90, since it filters the entry to NaN and you get a problem with np.cos
jramirezpr commentedon Oct 18, 2018
Hi @mikofski Im using conda python 3.7 And version of pvlib is 0.6.0-py_1; updated the potential fix on my original comment
cwhanse commentedon Oct 18, 2018
@jramirezpr why do you want to calculate air mass when zenith>90?
jramirezpr commentedon Oct 18, 2018
@cwhanse I'm running the example on the documentation https://wholmgren-pvlib-python-new.readthedocs.io/en/extras/introexamples.html and some of the zeniths in solpos['apparent_zenith'] are greater than 90, I realize that the model is for daytimes but i want the code to run without warnings
cwhanse commentedon Oct 18, 2018
@jramirezpr I'm having trouble duplicating your issue. Is this the warning you get?
RuntimeWarning: invalid value encountered in maximum
spectral_loss = np.maximum(0, np.polyval(am_coeff, airmass_absolute))
jramirezpr commentedon Oct 18, 2018
@cwhanse no, I get
RuntimeWarning: invalid value encountered in cos
am = (1.0 / (np.cos(zenith_rad) +
cwhanse commentedon Oct 18, 2018
@jramirezpr if that is the warning you see, then the cause is passing
np.nanin theairmass_absoluteargument on line 1917 ofpvsystem.py.jramirezpr commentedon Oct 18, 2018
@cwhanse it is basically the same reason, (passing a nan) except on line 222.
jramirezpr commentedon Oct 18, 2018
@cwhanse (it is in the get_relative_airmass function,after the zeniths greater than 90 have been filtered with nan)
cwhanse commentedon Oct 18, 2018
jramirezpr commentedon Oct 18, 2018
@cwhanse 0.6.0-py_1
cwhanse commentedon Oct 18, 2018
numpy version?
jramirezpr commentedon Oct 18, 2018
@cwhanse numpy 1.15.1
cwhanse commentedon Oct 18, 2018
Could you post your code? I can't reproduce that warning.
7 remaining items
cwhanse commentedon Oct 19, 2018
We could silence this warning
RuntimeWarning: invalid value encountered in maximum
spectral_loss = np.maximum(0, np.polyval(am_coeff, airmass_absolute))
Tomorrow is code day for me :)
mikofski commentedon Oct 19, 2018
I vote not to silence it, let the user decide to silence it. IMO pvlib is a toolbox not production, so it should raise all warnings and exceptions
jramirezpr commentedon Oct 19, 2018
wholmgren commentedon Oct 19, 2018
@mikofski I agree with the spirit of this but I in practice I think it's more complicated. numpy warnings are often emitted for valid inputs due to well-understood implementation details. log(0), exp(very big number), cos(nan), etc. I think pvlib should implement things in a way that the warnings are not emitted or selectively silence them in
withblocks where necessary. This way users are more likely to think twice when they do see a warning. That's the core of this issue, at least so far as I understand it.@jramirezpr Airmass is not defined when zenith is greater than ~90 degrees, so the function returns nan. The function emits this warning because it sets the nans before the calculating the airmass.
jramirezpr commentedon Oct 22, 2018
@wholmgren so should it be better to filter out the times for which the zenith is out of range? Or does it not really matter?
cwhanse commentedon Oct 22, 2018
#608 prevents a numpy warning when
am=np.nanthat is due to pvlib statement sequence. Unless we can reproduce what is causing the numpy warning onnp.cos(np.nan)for @jramirezpr, I don't see any action to take on this issue.wholmgren commentedon Oct 22, 2018
@jramirezpr here are some examples of how to avoid similar numpy warnings:
use out and where kwarg in calculation: https://github.com/pvlib/pvlib-python/blob/master/pvlib/pvsystem.py#L916-L920
use the errstate context manager: https://github.com/pvlib/pvlib-python/blob/master/pvlib/pvsystem.py#L2658
let us know if one of these approaches works for you
jramirezpr commentedon Oct 23, 2018
@wholmgren Thank you, I'll try this out.
jramirezpr commentedon Oct 23, 2018
@cwhanse on a similar note, i found some more warnings when changing the model to perez
C:\Users\Guest\Anaconda3\lib\site-packages\pvlib\irradiance.py:1150: RuntimeWarning: invalid value encountered in maximum
F1 = np.maximum(F1, 0)
C:\Users\Guest\Anaconda3\lib\site-packages\pvlib\irradiance.py:1153: RuntimeWarning: invalid value encountered in maximum
F2 = np.maximum(F2, 0)
C:\Users\Guest\Anaconda3\lib\site-packages\pvlib\irradiance.py:1167: RuntimeWarning: invalid value encountered in maximum
sky_diffuse = np.maximum(dhi * (term1 + term2 + term3), 0)
I'm going to silence them for now, but thought you might want to know.
cwhanse commentedon Oct 23, 2018
@jramirezpr thank you , appreciate this!
mikofski commentedon Oct 23, 2018
can this issue be closed now?
jramirezpr commentedon Oct 23, 2018
cwhanse commentedon Oct 23, 2018
Hold it for a bit while I look at the F1, F2 warnings @jramirezpr posted. I'll close.
cwhanse commentedon Oct 23, 2018
Warnings are from impolite handling of
np.nanin theperezfunction.