4
$\begingroup$

Just wondering, does anyone know a good way to calculate latitude and longitude of the moon relative to the earth with PyEphem? I've kinda hit a wall trying to figure it out...

Thanks, Pete

$\endgroup$

1 Answer 1

2
$\begingroup$

Use equatorial coordinates given in Right Ascension for longitude and Declination for latitude as projected on celestial sphere. So you would do something along the lines of:

import ephem
m = ephem.Moon('2003/08/27', epoch=ephem.J2000)
print('%s %s' % (m.a_ra, m.a_dec))

This is explained in more detail in PyEphem Coordinate Transformations. Note that J2000 is already an assumed epoch and you can simply provide the time since epoch to replace '2003/08/27' in the example and omit the second parameter. Equatorial coordinate system is also already assumed when printing out RA/Dec. And if you want to transform RA/Lon and Dec/Lat to XYZ coordinates for a location on Earth's celestial sphere using Python, you'll continue with something like:

import math

x = math.cos(m.dec) * math.cos(m.ra)
y = math.cos(m.dec) * math.sin(m.ra)
z = math.sin(m.dec)

Refer to the second part of Brandon Rhodes' answer to Getting J2000 XYZ coordinates for a location on earth in Python for more info on the latter part.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.