Skip to content

Change refraction correction limit in ephemeris solar position algorithm #2524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AdamRJensen
Copy link
Member

@AdamRJensen AdamRJensen commented Aug 1, 2025

  • Closes Incorrect refraction elevation cutoff in ephemeris solar position algorithm #2323
  • I am familiar with the contributing guidelines
  • Tests added
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

The refraction correction used by the Sandia empheris solar position algorithm sets refraction to zero above 85 degree elevation. This limit does not seem to configured in the reference, rather is is 90 degrees. Therefore, I propose that we change this to follow the reference. The 85 degree limit may come from the NOAA solar position algorithm which claims to use the Hughes refraction algorithm although deviating slightly from the original reference.

Refract[(Elevation > 5) & (Elevation <= 85)] = (
58.1/TanEl - 0.07/(TanEl**3) + 8.6e-05/(TanEl**5))

From "Engineering Astronomy" by Grver W. Hughes, Sandia Laboratories

  • Interval -0.575 to 5 is inclusive both ends
Image

Sun-Pointing Programs and Their Accuracy - John C. Zimmerman

Grover Hughes developed a series of equations to correct for the' refraction errors. Input data for the correction are the ground level temperature (OF) and pressure (millibars) at the observation point. The algorithm for the refraction correction is included in the latter part of Appendix D and is marked for identification.

Image

NOAA

Image

@AdamRJensen AdamRJensen added this to the v0.13.1 milestone Aug 1, 2025
@AdamRJensen AdamRJensen added the bug label Aug 1, 2025
@AdamRJensen AdamRJensen marked this pull request as ready for review August 2, 2025 13:05
Copy link
Contributor

@echedey-ls echedey-ls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three thingies:

  • You've got some nice references that are not currently in the docstring: https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.solarposition.ephemeris.html I suggest adding at least the most relevant one. I'm aware ephemeris may be superseded soon (quoting Kevin and Kevin, yet again)

  • If you want to leave another hint for users that may find a difference, you can add to the docstring:

    .. versionchanged:: 0.13.1
    
       Refraction correction between 85º and 90º now correctly follows known references [...]_.
    
  • I love that y'all have looked through all the details of the SPA algorithms and are fixing small incoherences. Could #2323 be in scope of this PR? I won't object if not. But for the sake of having the most 1-to-1 implementation somewhere...

Comment on lines +9 to +11
* Change refraction for solar elevation angles between 85 and 90
degrees to be calculated rather than set to 0 in
:py:func:`~pvlib.solarposition.ephemeris`. (:pull:`2524`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this qualifies more like a bugfix rather than a Breaking Change - I don't see how my code would not run after this update.

@cwhanse
Copy link
Member

cwhanse commented Aug 2, 2025

As far as we can determine, setting refraction to 0. at elevation > 85 was a choice made some years ago by staff at our PV lab. The ephemeris code here is a port to python of Matlab code, which itself was a port from a BASIC program. We don't know why they did it. There's no meaningful impact of sun position, refraction adjustment at 85 is 0.003 degrees, and at 90 its 0. I don't know that I'd describe this as a bug but I don't care if you decide that's appropriate.

Grover Hughes' notes containing this algorithm are not published anywhere. We pass around a pdf containing a scan.

@kandersolar
Copy link
Member

@adriesse
Copy link
Member

adriesse commented Aug 6, 2025

I read some comments about removing this function in the near future. Perhaps the effort to change it now (ever so minimally) can be spared?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect refraction elevation cutoff in ephemeris solar position algorithm
5 participants