7

I'm looking for a simple API that will allow me to get positions of planets and the moon for a given date, location and time.
Does anyone know an API like that?
Any suggestions or alternatives would be appreciated.

1 Answers1

5

Astropy is one option:

from astropy.time import Time
from astropy.coordinates import solar_system_ephemeris, EarthLocation
from astropy.coordinates import get_body, get_moon
from astropy.coordinates import SkyCoord, EarthLocation, AltAz
from astropy import units as u
import time;

t = Time("2019-08-11 11:00", scale="utc")
loc = EarthLocation(lat=38.2464000*u.deg, lon=274.236400*u.deg, height=0*u.m)

with solar_system_ephemeris.set('jpl'):
  moon = get_body('moon', t, loc)

altazframe = AltAz(obstime=t, location=loc, pressure=0)
moonaz=moon.transform_to(altazframe)

print(moonaz.alt.degree,moonaz.az.degree)

If you want a library you can ship with a product, you'll want something much smaller. I am actually working on a library converted to many different languages to do just that. Only the JavaScript version has a working Alt Az example, but it should be easy to convert to other languages (and will be eventually).

Greg Miller
  • 5,857
  • 1
  • 14
  • 31