Skyfield at PyCon Canada 2015 Sprints

My Jupyter Notebook on playing around with Skyfield Python Library.

Published: | Updated: | Tags: , and

Skyfield is an pure Python astronomy package that makes it easy to get positions for planets and Earth satellites.

It's open source on GitHub by Brandon Rhodes and you can install with pip from the CheeseShop.


from itertools import izip_longest

from skyfield import api # Skyfield Python Library

import requests # The *Best* HTTP Library for Python

latitude, longitude = 43.659583, -79.397222

req = requests.get('http://celestrak.com/NORAD/elements/stations.txt')
content = req.content

space_stations_data = []

# http://stackoverflow.com/a/16289922
def grouper(n, iterable, fillvalue=None):
    """Collect data into fixed-length chunks or blocks."""
    args = [iter(iterable)] * n
    return izip_longest(fillvalue=fillvalue, *args)

for i, g in enumerate(grouper(3, content.splitlines(), ''), 1):
    space_stations_data += ['\n'.join(g)]

# Load the data where things objects are located.
eph = api.load('de421.bsp')

# Get the current time in fancy method.
julian_date = api.now()

# I want information for earth's prespective.
earth = eph['earth']

# I'm currently located at the Bahen Centre at UofT.
bahne = earth.topos(latitude, longitude)

space_stations = []

# Iterate over the list of space stations from NORAD.
for station in space_stations_data:
    # Get the name of the space station.
    name = station.splitlines()[0].strip()

    # Getting data from NORAD of the location of the Space Stations.
    data = earth.satellite(station)

    # This is my position, time and what I want to observe.
    space_stations += [{'name': name,
                  'position': bahne.at(utc=julian_date.utc).observe(data)}]

station = space_stations[0]

ra, dec, distance = station.get('position').radec()

print(ra.hstr())
print(dec.dstr())
print(distance)

05h 55m 30.19s
-14deg 55' 18.8"
7.77944e-05 au