brandon-rhodes / pyephem

Scientific-grade astronomy routines for Python
Other
782 stars 121 forks source link

Moon phase and illumination #252

Open dmoore19 opened 1 year ago

dmoore19 commented 1 year ago

I'm trying to figure out the best way to calculate the phase of the moon, This is what I have:

if phase < 0.125:
            phase_name = "New Moon"
        elif phase < 0.25:
            phase_name = "Waxing Crescent"
        elif phase < 0.375:
            phase_name = "First Quarter"
        elif phase < 0.5:
            phase_name = "Waxing Gibbous"
        elif phase < 0.625:
            phase_name = "Full Moon"
        elif phase < 0.75:
            phase_name = "Waning Gibbous"
        elif phase < 0.875:
            phase_name = "Last Quarter"
        else:
            phase_name = "Waning Crescent"

But it is not matching up with trusted web sites with the same location and day.

Also trying to figure out how to get illumination percentage. Not sure. Thanks in advance.

brandon-rhodes commented 1 year ago

The first step that I would take would be computing the number with another library, and comparing those two numbers first. For example, this routine would return a number you could compare with your numbers from PyEphem:

https://rhodesmill.org/skyfield/almanac.html#phases-of-the-moon