Skip to content

atmosphere.py bug fix on get_relative_airmass airmass  #607

Closed

Description

@jramirezpr

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))))

Activity

  1. mikofski commented on Oct 18, 2018

    @mikofski
    Member

    Hi @jramirezpr , thanks for reporting your issue. 😄
    Can you please execute

    import pvlib
    pvlib.atmosphere.get_relative_airmass(zenith=60.0, model='kastenyoung1989')

    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.9942928525292494 and no traceback.

  2. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    The error seems to be when zenith>90, since it filters the entry to NaN and you get a problem with np.cos

  3. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    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

  4. cwhanse commented on Oct 18, 2018

    @cwhanse
    Member

    @jramirezpr why do you want to calculate air mass when zenith>90?

  5. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    @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

  6. cwhanse commented on Oct 18, 2018

    @cwhanse
    Member

    @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))

  7. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    @cwhanse no, I get
    RuntimeWarning: invalid value encountered in cos
    am = (1.0 / (np.cos(zenith_rad) +

  8. cwhanse commented on Oct 18, 2018

    @cwhanse
    Member

    @jramirezpr if that is the warning you see, then the cause is passing np.nan in the airmass_absolute argument on line 1917 of pvsystem.py.

  9. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    @cwhanse it is basically the same reason, (passing a nan) except on line 222.

  10. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    @cwhanse (it is in the get_relative_airmass function,after the zeniths greater than 90 have been filtered with nan)

  11. cwhanse commented on Oct 18, 2018

    @cwhanse
    Member
  12. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    @cwhanse 0.6.0-py_1

  13. cwhanse commented on Oct 18, 2018

    @cwhanse
    Member

    numpy version?

  14. jramirezpr commented on Oct 18, 2018

    @jramirezpr
    Author

    @cwhanse numpy 1.15.1

  15. cwhanse commented on Oct 18, 2018

    @cwhanse
    Member

    Could you post your code? I can't reproduce that warning.

  16. 7 remaining items

  17. cwhanse commented on Oct 19, 2018

    @cwhanse
    Member

    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 :)

  18. mikofski commented on Oct 19, 2018

    @mikofski
    Member

    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

  19. jramirezpr commented on Oct 19, 2018

    @jramirezpr
    Author
  20. wholmgren commented on Oct 19, 2018

    @wholmgren
    Member

    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.

  21. jramirezpr commented on Oct 22, 2018

    @jramirezpr
    Author

    @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?

  22. cwhanse commented on Oct 22, 2018

    @cwhanse
    Member

    #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.

  23. wholmgren commented on Oct 22, 2018

    @wholmgren
    Member

    @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

  24. jramirezpr commented on Oct 23, 2018

    @jramirezpr
    Author

    @wholmgren Thank you, I'll try this out.

  25. jramirezpr commented on Oct 23, 2018

    @jramirezpr
    Author

    @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)

    image
    I'm going to silence them for now, but thought you might want to know.

  26. cwhanse commented on Oct 23, 2018

    @cwhanse
    Member

    @jramirezpr thank you , appreciate this!

  27. mikofski commented on Oct 23, 2018

    @mikofski
    Member

    can this issue be closed now?

  28. cwhanse commented on Oct 23, 2018

    @cwhanse
    Member

    Hold it for a bit while I look at the F1, F2 warnings @jramirezpr posted. I'll close.

  29. cwhanse commented on Oct 23, 2018

    @cwhanse
    Member

    Warnings are from impolite handling of np.nan in the perez function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions