Python PyEphem – Calculate the position of Saturn

In this post we will be creating a Python script that will calculate the position of planet Saturn in the sky for a given date and location, to achieve this we will be using the PyEphem library which is able to perform high-precision astronomy computations.

To install the PyEphem library run the following command.

pip install ephem

Our example will take the latitude and longitude coordinates of a given observer location. In this case our location will be the Big Ben tower in London, the coordinates for which are.

'51.5007'  #latitude of Big Ben (degrees)
'-0.1246'  #longitude of Big Ben (degrees)

See the snippet of Python code below where we utilize the PyEphem library to calculate the position of the planet Saturn in the sky for a given date and location.

We begin by setting up an observer object for the Big Ben tower, defining its latitude and longitude coordinates. We then create an object for Saturn and calculate its position in the sky.

The position of Saturn is returned as an altitude and azimuth.

import ephem

obs = ephem.Observer() = '51.5007'
obs.lon = '-0.1246' 
obs.elevation = 0 = '2023/1/30 17:00:00'

saturn = ephem.Saturn(obs)


print("Altitude:", saturn.alt)

At the time of writing this the following is returned to output.

Azimuth: 234:29:41.0
Altitude: 8:27:01.2

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply