Astronomical Data in Python: Notebooks

Contents

Astronomical Data in Python: Notebooks#

Allen Downey

This is self-study material: the workshop is not offered live now, but the notebooks are maintained and run on Colab.

Astronomical Data in Python is an introduction to tools and practices for working with astronomical data. Topics covered include:

  • Writing queries that select and download data from a database.

  • Using data stored in an Astropy Table or Pandas DataFrame.

  • Working with coordinates and other quantities with units.

  • Storing data in various formats.

  • Performing database join operations that combine data from multiple tables.

  • Visualizing data and preparing publication-quality figures.

As a running example, we will replicate part of the analysis in a 2018 paper, “Off the beaten path: Gaia reveals GD-1 stars outside of the main stream” by Adrian M. Price-Whelan and Ana Bonaca.

This material was developed in collaboration with The Carpentries and the Astronomy Curriculum Development Committee, and supported by funding from the American Institute of Physics through the American Astronomical Society. It became the Data Carpentry lesson Foundations of Astronomical Data Science, which The Carpentries retired in 2026. The lesson pages remain online, and they include notes for instructors, but these notebooks are the version that is maintained.

I am grateful for contributions from the members of the committee – Azalee Bostroem, Rodolfo Montez, and Phil Rosenfield – and from Erin Becker, Brett Morris and Adrian Price-Whelan.

Level: intermediate. You should be familiar with basic Python, including lists, dictionaries, and functions, but not necessarily Astropy or Pandas; and with astronomy at the undergraduate level.

Length: seven notebooks, about 20 hours in total.

The notebooks#

The pages on this site show the notebooks with solutions. To do the exercises, run the versions with blanks on Colab:

  1. Queries: connecting to the Gaia archive and writing ADQL queries. Exercises on Colab

  2. Coordinates and units: Quantity objects, coordinate frames, and selecting stars in a region of the sky. Exercises on Colab

  3. Proper motion: transforming to the GD-1 frame and selecting stars by proper motion with Pandas. Exercises on Colab

  4. Transformation and selection: doing the proper-motion selection as part of the query. Exercises on Colab

  5. Joining tables: combining Gaia data with Pan-STARRS photometry. Exercises on Colab

  6. Photometry: a color-magnitude diagram and a second round of selection. Run on Colab

  7. Visualization: a publication-quality figure with several panels. Exercises on Colab

The notebooks query the Gaia archive, which limits anonymous users to queries of one minute and 50,000 rows; Notebook 1 explains how to register and log in. The code and the data files are in the GitHub repository, which explains how to run the notebooks on your own computer.

See also my other workshops.

The code is available under the MIT License. The text is available under the Creative Commons Attribution 4.0 International License.