PyEphem high precision astronomy in Python

less than 1 minute read

PyEphem brings functionality for Python that the NAIF SPICE package has for C, FORTRAN, IDL, and MATLAB. Specifically, performing high-precision astronomical calculations. AstroPy has more comprehensive astronomical functions.

PyEphem local sunrise & sunset

    import ephem
    import datetime

    Boston=ephem.Observer()
    # lat/lon must be strings
    Boston.lat='42.3462'
    Boston.lon='-71.0978'
    Boston.date = datetime.datetime.now()

    sun = ephem.Sun()

    print("Next sunrise in Boston will be: ",ephem.localtime(Boston.next_rising(sun)))
    print("Next sunset in Boston will be: ",ephem.localtime(Boston.next_setting(sun)))

Notes

  • elevation is NOT considered by PyEphem, modeled after XEphem for sunrise / sunset, and there aren’t any plans to do so. Thus, if your sunrise/sunset observer is above Earth, you must add additional calculations.

Leave a comment