{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 2\n", "\n", "This is the second in a series of notebooks related to astronomy data.\n", "\n", "As a running example, we are replicating parts of the analysis in a recent paper, \"[Off the beaten path: Gaia reveals GD-1 stars outside of the main stream](https://arxiv.org/abs/1805.00425)\" by Adrian M. Price-Whelan and Ana Bonaca.\n", "\n", "In the first notebook, we wrote ADQL queries and used them to select and download data from the Gaia server.\n", "\n", "In this notebook, we'll pick up where we left off and write a query to select stars from the region of the sky where we expect GD-1 to be." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Outline\n", "\n", "We'll start with an example that does a \"cone search\"; that is, it selects stars that appear in a circular region of the sky.\n", "\n", "Then, to select stars in the vicinity of GD-1, we'll:\n", "\n", "* Use `Quantity` objects to represent measurements with units.\n", "\n", "* Use the `Gala` library to convert coordinates from one frame to another.\n", "\n", "* Use the ADQL keywords `POLYGON`, `CONTAINS`, and `POINT` to select stars that fall within a polygonal region.\n", "\n", "* Submit a query and download the results.\n", "\n", "* Store the results in a FITS file.\n", "\n", "After completing this lesson, you should be able to\n", "\n", "* Use Python string formatting to compose more complex ADQL queries.\n", "\n", "* Work with coordinates and other quantities that have units.\n", "\n", "* Download the results of a query and store them in a file." ] }, { "cell_type": "markdown", "metadata": { "tags": [ "remove-cell" ] }, "source": [ "## Installing libraries\n", "\n", "If you are running this notebook on Colab, you can run the following cell to install Astroquery and the other libraries we'll use.\n", "\n", "If you are running this notebook on your own computer, you might have to install these libraries yourself. See the instructions in the preface." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "# If we're running on Colab, install libraries\n", "\n", "import sys\n", "IN_COLAB = 'google.colab' in sys.modules\n", "\n", "if IN_COLAB:\n", " !pip install astroquery astro-gala pyia" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Selecting a region" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One of the most common ways to restrict a query is to select stars in a particular region of the sky.\n", "\n", "For example, here's a query from the [Gaia archive documentation](https://gea.esac.esa.int/archive-help/adql/examples/index.html) that selects \"all the objects ... in a circular region centered at (266.41683, -29.00781) with a search radius of 5 arcmin (0.08333 deg).\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "query = \"\"\"\n", "SELECT \n", "TOP 10 source_id\n", "FROM gaiadr2.gaia_source\n", "WHERE 1=CONTAINS(\n", " POINT(ra, dec),\n", " CIRCLE(266.41683, -29.00781, 0.08333333))\n", "\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This query uses three keywords that are specific to ADQL (not SQL):\n", "\n", "* `POINT`: a location in [ICRS coordinates](https://en.wikipedia.org/wiki/International_Celestial_Reference_System), specified in degrees of right ascension and declination.\n", "\n", "* `CIRCLE`: a circle where the first two values are the coordinates of the center and the third is the radius in degrees.\n", "\n", "* `CONTAINS`: a function that returns `1` if a `POINT` is contained in a shape and `0` otherwise.\n", "\n", "Here is the [documentation of `CONTAINS`](http://www.ivoa.net/documents/ADQL/20180112/PR-ADQL-2.1-20180112.html#tth_sEc4.2.12).\n", "\n", "A query like this is called a cone search because it selects stars in a cone.\n", "\n", "Here's how we run it." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created TAP+ (v1.2.1) - Connection:\n", "\tHost: gea.esac.esa.int\n", "\tUse HTTPS: True\n", "\tPort: 443\n", "\tSSL Port: 443\n", "Created TAP+ (v1.2.1) - Connection:\n", "\tHost: geadata.esac.esa.int\n", "\tUse HTTPS: True\n", "\tPort: 443\n", "\tSSL Port: 443\n" ] }, { "data": { "text/html": [ "Table length=10\n", "
| source_id |
|---|
| int64 |
| 4057468321929794432 |
| 4057468287575835392 |
| 4057482027171038976 |
| 4057470349160630656 |
| 4057470039924301696 |
| 4057469868125641984 |
| 4057468351995073024 |
| 4057469661959554560 |
| 4057470520960672640 |
| 4057470555320409600 |