Moon phase data correct only for waxing crescent/gibbous
See original GitHub issueI have a problem trying to get Moon Phase information from Skyfield 1.11. I want to replicate the results I get correctly from PyEphem using this (simplified) code:
def moonphase(date):
# returns the moon's elongation (angle to the sun)
obs = ephem.Observer()
obs.date = date
m = ephem.Moon()
m.compute(date+0.5)
#phase = int(round(m.elong.norm*180/math.pi)) # moon phase (0:new to 180:full to 360:new degrees)
phase = m.elong.norm+0.0 # moon phase as float (0:new to π:full to 2π:new)
return phase
PyEphem gives me values from 0 to π in the WAXING phase and from π to 2π in the WANING phase. However Skyfield gives me only values from 0 to π in both WAXING and WANING phases. Attached here are the results (in degrees) I get from Skyfield for selected dates while calculating a Nautical Almanac for 2019: phase_angle.zip
I am using this kind of code in Skyfield:
eph = load('de421.bsp') # ephemeris
def moonphase(d):
# returns the moon's elongation (angle to the sun)
t12 = ts.utc(d.year, d.month, d.day, 12, 0, 0) # moon phase is calculated at noon
phase_angle = almanac.phase_angle(eph, 'moon', t12)
elong = phase_angle.radians
if elong >= 0 and elong <= math.pi:
phase = math.pi - phase_angle.radians
if elong > math.pi:
phase = (3 * math.pi) - phase_angle.radians # ??????
print d, phase_angle.degrees # FOR DEBUGGING ONLY
return phase
For example, the ‘phase’ results are correct between NEW MOON on 6th Jan 2019 up to FULL MOON on 21 Jan 2019. During this time phase_angle.degrees goes from 180 to zero (assumed correct) but then till the next NEW MOON on 4th. Feb 2019 it goes from zero to 180 again (assumed incorrect)… I expected it to go from 360 to 180 degrees.
In other words, the Skyfield value range is 0 to π instead of 0 to 2π.
Do I understand correctly that phase_angle should be able to return a value in radians between 0 and 2π?
Kind thanks in appreciation of your time & effort to look into this!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:17 (7 by maintainers)
Top GitHub Comments
@brandon-rhodes gave it a test and it works great. Thanks!
Yes, you can close this thread as I have implemented “before or after Full Moon” as indication of the angle. I didn’t think it is incorrect - I thought that Skyfield left out important information in providing an angle that’s only between 0 and π instead of between 0 and 2π. So the suggestion (from barrycarter) to add a flag ‘angle increasing’ or ‘angle decreasing’ I think is very appropriate.
I haven’t looked at ReportLab - I continued using LaTeX that the original developer, Enno Rodegerdts, chose. I have one open issue with pdflatex (included in MiKTeX) that I’ll pick up with them directly. But thanks for the suggestion. I’ll also look into the navigational stars in the latest PyEphem. Thanks!
The PyEphem output PDFs are already published online here: https://www.thenauticalalmanac.com/ I am in touch with the site owner and my name is mentioned very kindly there too. He does some clever post-processing before publishing. I’ve just finished the Skyfield version, so I expect it will be published when we’re sure the data is okay.
By the way, the moon image was fun to create. I overlaid a semi-transparent shadow onto the moon. First I simply deleted the black pixels from a moon image and the result was hilarious: a “hairy” moon (due to moonshine). I then wrote code to place transparent pixels outside a circle, carefully positioning it over the moon, which is almost a circle. Finally I thought maybe it looks better without the moon, so I included a parameter in config.py to replace it with the original data in that table location.
Thanks for your helpful comments!
P.S. My comment about Skyfield performance… clearly PyEphem uses different algorithms, but do you perhaps see a way to make the following methods execute faster?
and
… should I enter this as a new thread?