Additional Python Resources

On this site is a compendium of links and resources for helping you develop your skills in Python, and to apply those to several astronomical projects – identifying asteroids, working with astronomical images, and using ephemeris data to locate asteroids, comets and planets in the sky. There are resources here that include major catalogs of Asteroids, Python notebooks for simulating orbits of solar system objects, and NASA ephemeris databases to enable new solar system research.

I have divided this into sections, and provide links and tips for getting started below.

Getting Started in Python

Maybe you have already been exposed to Python, but if not, there are many helpful introductions to the language, and lots of materials available to help you learn. Most computers and all MacOS systems have Python built in. However one system that is highly regarded and complete in all of its packages is known as the Anaconda Python installation. I highly recommend this as it makes for a smooth experience, and has very nice and advanced looking notebooks for visualizing what you are doing. We will be using this distribution both in our Undergraduate Astronomy Institute, and later at the ZTF bootcamp. The Anaconda Python distribution is available at

Once you have this installed, you can use the guide from Marla Geha from Yale to help you learn more about Python. This includes some image processing exercises, using data both from her short course at Yale-NUS College in Singapore and also from the HST archive. These resources are all available at the Yale-NUS August Short Course site.  Her Pre-course Python guide – marla.geha.python.exercises.Precoursework_1 will help guide you through some of the introductory Python exercises.  She also has a Research Methods site at Yale that has a number of very useful Python exercises – this is available at

There are two ways to run Python – File Mode: by creating a .py file one can run it in a command line mode with a command like python; Notebook Mode: by creating a Python notebook, one can run the notebook using “ipython” or interactive python. These files will end in the prefix ipynb, can also be run with ipython file.ipynb.  Within a notebook you will see input and output commands. A short example is below. These sections of a notebook are known as “cells” and can be run by highlighting the cell (here labelled In [4]) and punching the “Play button” on the top of the window (the triangle pointing right). The results will show up immediately below in the cell labelled Out (here Out [4] which prints out a table).


Sometimes on the site github you will find python notebooks. These are a bit hard to figure out at first, but can be run by punching in the inputs into a new notebook, after visualizing the notebook using something called nbviewer. This program is available at and can be used by pasting in the URL of the github python notebook; nbviewer will render the file into a comprehensible format for you, and enable you a chance to experiment with it.

Additional guides and links to Python are below:

Marla’s Yale-NUS Python exercises:

I highly recomment this source for learning Python:  

Guide from ipython describing the “notebook” – a very useful tool for visualizing code in Python:

A basic bouncing ball program for Python – a good starting point:

You can learn about basic Python tables and plotting in this guide:

You can learn how to work with Astronomy fits images and make a ‘tricolor’ image in Python out of three monochrome images with this tutorial:

A good setup guide for getting started with the package known asastropy:

Additional Python Packages 

The standard Python distribution from Anaconda has numpy (the numerical package) but may lack some of the other packages you will need for working with astronomy data in Python. These packages include astropy – the astronomy python package; pyfits – a package for handling FITS formatted astronomy images; and ephem – an ephemeris package for Python. To install these packages, you will download a big file with an ending like .tar.gz, and move it to the part in your anaconda distribution where packages are stored. This is a directory just below your main directory “anaconda” called anaconda/pkgs. Store the .tar.gz file in this directory anaconda/pkgs, and then unpack it using the commands gunzip and tar. You can “gunzip” the files with a command like gunzip file.tar.gz, and unpack them using a command like tar -xvf file.tar. This will separate all the files you will need. Then change into the directory for the package (for pyfits, I have a directory called pkgs/pyfits-3.3), and once in that directory you can install the package with the command ipython install.

Main package download sites are at these locations:

Astropy –

Pyphem –  (see tutorial at

Pyfits – – note: many features of this package are now in Astropy.

Orbital Elements and Ephemeris Data

For solar system work, one of the first steps is computing the ephemeris data for an object. This can be done using JPL’s Horizons Database, perhaps the best site for this with absolutely accurate data. You can access that database on the web at the site: or You can also see a very complete guides to orbits at the site  and some interesting simulations at .

Many planetarium programs enable asteroids, spacecraft and comets to be simulated in their orbits. A few of the most common ones are listed below:

An astronomical object is specified by its orbital elements. Those can be found at the JPL Horizons site at Each astronomical object can be completely specified by a set of orbital elements. Those are described below in brief. More details can be found on the web site linked above.

VERY COOL Sites with a LOT of interesting stuff.

For anyone who has read this far, and would like to really push the envelope, I have found a number of sites with what look like amazing resources for asteroid, and outer solar system work. I would be very excited to see students work with these sites and help get their various databases and Python notebooks working. They include vast databases of near earth asteroids, amazing solar system orbit simulators and much more! – a cool database of asteroid orbital elements – what looks like an amazing resource for asteroid research  – nice notebook for teaching about orbits – could be adapted for other uses. – nice document for working in astropy with coordinates.  – more amazing astronomy stuff from Brandon Rhodes. – an interesting site for an interactive Kepler’s Law demonstration. Again can be modified for some more advanced purposes. – a site showing code for simulation of orbits in Python. Very cool! – a compendium of python programs including some simulations for astronomy. – a nice example of orbit simulation with a very simple program and the package vpython. Works! – guide for importing ephemeris data into the Celestia program.

Orbital Elements Information — From the NASA horizons site: 


Orbital elements below are available as fixed-format ASCII tables. Asteroid elements are available as Keplerian elements while comet elements use perihelion distance and time of perihelion passage instead of semimajor axis and mean anomaly. See thetable column headings description below. Magnitude parameters, H and G, are included in the asteroid tables. If you need other parameters, you should use thesmall-body search engine, mentioned above.

(The files above were updated on 2015-Feb-11 02:32 -0800.)

Sample Asteroid File Header for an Orbital Elements File

Num   Name              Epoch      a          e        i         w        Node        M         H    G  Ref

—— —————– —– ———- ———- ——— ——— ——— ———– —– —- ———-

     1 Ceres             55400  2.7653485 0.07913825  10.58682  72.58981  80.39320 113.4104434  3.34 0.12 JPL 30

     2 Pallas            55400  2.7721532 0.23099956  34.84090 310.15094 173.12950 96.1482660  4.13 0.11 JPL 25

     3 Juno              55400  2.6700912 0.25498122  12.98211 248.10807 169.91138 32.0960832  5.33 0.32 JPL 86

Sample Comet File Header for an Orbital Elements File

Num  Name                                     Epoch      q           e        i         w        Node         Tp       Ref

——————————————- ——- ———– ———- ——— ——— ——— ————– ————

  1P/Halley                                   49400  0.58597811 0.96714291 162.26269 111.33249  58.42008 19860205.89532 JPL J863/77

  2P/Encke                                    55460  0.33586872 0.84833156  11.78308 186.54970 334.56582 20100806.50196 JPL K105/1

  3D/Biela                                    -9480  0.87907300 0.75129900  13.21640 221.65880 250.66900 18321126.61520 IAUCAT03

ASCII File Column Headings




Number assigned to the asteroid or comet. Numbers are only assigned to secure short-period (<200 year) comets.



Name given to the numbered asteroid or comet.



Unnumbered asteroid’s preliminary designation.



Epoch of the elements represented as the Modified Julian Date (MJD), which is defined as the Julian date – 2400000.5.



Semimajor axis of the orbit (asteroids only).



Perihelion distance (comets only).



Eccentricity of the orbit.



Inclination of the orbit with respect to the J2000 ecliptic plane.



Argument of perihelion (J2000-Ecliptic).



Longitude of the ascending node (J2000-Ecliptic).



Mean anomaly at epoch (asteroids only).



Time of perihelion passage (comets only), formatted as a calendar date (YYYYMMDD.DDD) where “YYYY” is the year, “MM” is the numeric month, and “DD.DDD” is the day and day fraction.



Absolute magnitude (asteroids only).



Magnitude slope parameter (asteroids only).



Orbit solution reference.

Leave a Reply