Python : Tracking Satellites

I have to add the PyEphm library into my Python setup on the Raspberry Pi, but look  at bit of sample code I found at :

Note how readable this code is !
Tip of the hat to “jboone”.

It’s not like the FORTRAN you may have endured in school, or the C and Pascal* I grew up with.  (Not that C is a bad thing)

import math
import time
from datetime import datetime
import ephem
degrees_per_radian = 180.0 / math.pi
home = ephem.Observer()
home.lon = '-122.63'   # +E = '45.56'      # +N
home.elevation = 80 # meters
# Always get the latest ISS TLE data from:
iss = ephem.readtle('ISS',
    '1 25544U 98067A   11290.51528320  .00016717  00000-0  10270-3 0  9006',
    '2 25544  51.6378 264.9380 0016170 337.7557  22.2896 15.60833726 20019'
while True: = datetime.utcnow()
    print('iss: altitude %4.1f deg, azimuth %5.1f deg' % (iss.alt * degrees_per_radian, * degrees_per_radian))

Basically, we’re telling the computer a bit about where we live (you’ll need to edit this), then a bit about characteristics of the satellite we want to keep tabs on. 

While in a loop, the script prints out the heading and elevation where you need to point your telescope / antennas.
The real magic happens in the “compute” function (or is it a method) .  If you haven’t programmed in a while, the print command has some formatting in it to keep the numbers from having excessive leading zeros and lots of junk behind the decimal point.  Keeps the printouts neat that way.

Note that most all the math is hidden from view.  100% of the hairy scary stuff like vectors and trig are hidden.  We just have to call the right functions and the Python library does the rest.

iss: altitude 78.1 deg, azimuth 249.8 deg
iss: altitude 79.1 deg, azimuth 250.7 deg
iss: altitude 80.2 deg, azimuth 251.7 deg
iss: altitude 81.2 deg, azimuth 253.0 deg
iss: altitude 82.2 deg, azimuth 254.7 deg
iss: altitude 83.3 deg, azimuth 256.9 deg
iss: altitude 84.3 deg, azimuth 259.9 deg

I’m excited to try this out later on for the RPi.



*Pascal is bad.