mirror of
https://github.com/AllenDowney/AstronomicalData.git
synced 2025-12-25 20:34:30 -08:00
2156 lines
84 KiB
HTML
2156 lines
84 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>2. Coordinates and Units — Astronomical Data in Python</title>
|
||
|
||
<link rel="stylesheet" href="_static/css/index.d431a4ee1c1efae0e38bdfebc22debff.css">
|
||
|
||
|
||
<link rel="stylesheet"
|
||
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
|
||
<link rel="preload" as="font" type="font/woff2" crossorigin
|
||
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
|
||
<link rel="preload" as="font" type="font/woff2" crossorigin
|
||
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
|
||
|
||
|
||
|
||
<link rel="stylesheet"
|
||
href="_static/vendor/open-sans_all/1.44.1/index.css">
|
||
<link rel="stylesheet"
|
||
href="_static/vendor/lato_latin-ext/1.44.1/index.css">
|
||
|
||
|
||
<link rel="stylesheet" href="_static/sphinx-book-theme.bfb7730f9caf2ec0b46a44615585038c.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
|
||
|
||
<link rel="preload" as="script" href="_static/js/index.30270b6e4c972e43c488.js">
|
||
|
||
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||
<script src="_static/jquery.js"></script>
|
||
<script src="_static/underscore.js"></script>
|
||
<script src="_static/doctools.js"></script>
|
||
<script src="_static/language_data.js"></script>
|
||
<script src="_static/togglebutton.js"></script>
|
||
<script src="_static/clipboard.min.js"></script>
|
||
<script src="_static/copybutton.js"></script>
|
||
<script >var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
|
||
<script src="_static/sphinx-book-theme.be0a4a0c39cd630af62a2fcf693f3f06.js"></script>
|
||
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
|
||
<script async="async" src="https://unpkg.com/thebelab@latest/lib/index.js"></script>
|
||
<script >
|
||
const thebe_selector = ".thebe"
|
||
const thebe_selector_input = "pre"
|
||
const thebe_selector_output = ".output"
|
||
</script>
|
||
<script async="async" src="_static/sphinx-thebe.js"></script>
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
<link rel="next" title="3. Proper Motion" href="03_motion.html" />
|
||
<link rel="prev" title="1. Queries" href="01_query.html" />
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<meta name="docsearch:language" content="en" />
|
||
|
||
|
||
|
||
</head>
|
||
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
|
||
|
||
|
||
<div class="container-xl">
|
||
<div class="row">
|
||
|
||
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
|
||
|
||
<div class="navbar-brand-box">
|
||
<a class="navbar-brand text-wrap" href="index.html">
|
||
|
||
|
||
<h1 class="site-logo" id="site-title">Astronomical Data in Python</h1>
|
||
|
||
</a>
|
||
</div>
|
||
|
||
<form class="bd-search d-flex align-items-center" action="search.html" method="get">
|
||
<i class="icon fas fa-search"></i>
|
||
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
|
||
</form>
|
||
|
||
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
|
||
<ul class="nav sidenav_l1">
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="README.html">
|
||
Astronomical Data in Python
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
<ul class="current nav sidenav_l1">
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="01_query.html">
|
||
1. Queries
|
||
</a>
|
||
</li>
|
||
<li class="toctree-l1 current active">
|
||
<a class="current reference internal" href="#">
|
||
2. Coordinates and Units
|
||
</a>
|
||
</li>
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="03_motion.html">
|
||
3. Proper Motion
|
||
</a>
|
||
</li>
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="04_select.html">
|
||
4. Transformation and Selection
|
||
</a>
|
||
</li>
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="05_join.html">
|
||
Joining Tables
|
||
</a>
|
||
</li>
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="06_photo.html">
|
||
Photometry
|
||
</a>
|
||
</li>
|
||
<li class="toctree-l1">
|
||
<a class="reference internal" href="07_plot.html">
|
||
Visualization
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
|
||
</nav>
|
||
|
||
<!-- To handle the deprecated key -->
|
||
|
||
<div class="navbar_extra_footer">
|
||
Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
|
||
|
||
<div class="row topbar fixed-top container-xl">
|
||
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show">
|
||
</div>
|
||
<div class="col pl-2 topbar-main">
|
||
|
||
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
|
||
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
|
||
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
|
||
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
|
||
<i class="fas fa-bars"></i>
|
||
<i class="fas fa-arrow-left"></i>
|
||
<i class="fas fa-arrow-up"></i>
|
||
</button>
|
||
|
||
<div class="dropdown-buttons-trigger">
|
||
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
|
||
class="fas fa-download"></i></button>
|
||
|
||
|
||
<div class="dropdown-buttons">
|
||
<!-- ipynb file if we had a myst markdown file -->
|
||
|
||
<!-- Download raw file -->
|
||
<a class="dropdown-buttons" href="_sources/02_coords.ipynb"><button type="button"
|
||
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
|
||
data-placement="left">.ipynb</button></a>
|
||
<!-- Download PDF via print -->
|
||
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
|
||
onClick="window.print()" data-toggle="tooltip" data-placement="left">.pdf</button>
|
||
</div>
|
||
|
||
</div>
|
||
<!-- Source interaction buttons -->
|
||
|
||
<div class="dropdown-buttons-trigger">
|
||
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
|
||
aria-label="Connect with source repository"><i class="fab fa-github"></i></button>
|
||
<div class="dropdown-buttons sourcebuttons">
|
||
<a class="repository-button"
|
||
href="https://github.com/AllenDowney/AstronomicalData"><button type="button" class="btn btn-secondary topbarbtn"
|
||
data-toggle="tooltip" data-placement="left" title="Source repository"><i
|
||
class="fab fa-github"></i>repository</button></a>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<!-- Full screen (wrap in <a> to have style consistency -->
|
||
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
|
||
data-placement="bottom" onclick="toggleFullScreen()" title="Fullscreen mode"><i
|
||
class="fas fa-expand"></i></button></a>
|
||
|
||
<!-- Launch buttons -->
|
||
|
||
<div class="dropdown-buttons-trigger">
|
||
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
|
||
aria-label="Launch interactive content"><i class="fas fa-rocket"></i></button>
|
||
<div class="dropdown-buttons">
|
||
|
||
<a class="binder-button" href="https://mybinder.org/v2/gh/AllenDowney/AstronomicalData/master?urlpath=tree/02_coords.ipynb"><button type="button"
|
||
class="btn btn-secondary topbarbtn" title="Launch Binder" data-toggle="tooltip"
|
||
data-placement="left"><img class="binder-button-logo"
|
||
src="_static/images/logo_binder.svg"
|
||
alt="Interact on binder">Binder</button></a>
|
||
|
||
|
||
|
||
<a class="colab-button" href="https://colab.research.google.com/github/AllenDowney/AstronomicalData/blob/master/02_coords.ipynb"><button type="button" class="btn btn-secondary topbarbtn"
|
||
title="Launch Colab" data-toggle="tooltip" data-placement="left"><img class="colab-button-logo"
|
||
src="_static/images/logo_colab.png"
|
||
alt="Interact on Colab">Colab</button></a>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<!-- Table of contents -->
|
||
<div class="d-none d-md-block col-md-2 bd-toc show">
|
||
|
||
<div class="tocsection onthispage pt-5 pb-3">
|
||
<i class="fas fa-list"></i> Contents
|
||
</div>
|
||
<nav id="bd-toc-nav">
|
||
<ul class="nav section-nav flex-column">
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#outline">
|
||
Outline
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#working-with-units">
|
||
Working with Units
|
||
</a>
|
||
<ul class="nav section-nav flex-column">
|
||
<li class="toc-h3 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#exercise">
|
||
Exercise
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#selecting-a-region">
|
||
Selecting a Region
|
||
</a>
|
||
<ul class="nav section-nav flex-column">
|
||
<li class="toc-h3 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#id1">
|
||
Exercise
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#getting-gd-1-data">
|
||
Getting GD-1 Data
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#transforming-coordinates">
|
||
Transforming coordinates
|
||
</a>
|
||
<ul class="nav section-nav flex-column">
|
||
<li class="toc-h3 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#id2">
|
||
Exercise
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#selecting-a-rectangle">
|
||
Selecting a rectangle
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#defining-a-polygon">
|
||
Defining a polygon
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#assembling-the-query">
|
||
Assembling the query
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#saving-results">
|
||
Saving results
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#summary">
|
||
Summary
|
||
</a>
|
||
</li>
|
||
<li class="toc-h2 nav-item toc-entry">
|
||
<a class="reference internal nav-link" href="#best-practices">
|
||
Best practices
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
|
||
</nav>
|
||
|
||
</div>
|
||
</div>
|
||
<div id="main-content" class="row">
|
||
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
|
||
|
||
<div>
|
||
|
||
<div class="section" id="coordinates-and-units">
|
||
<h1>2. Coordinates and Units<a class="headerlink" href="#coordinates-and-units" title="Permalink to this headline">¶</a></h1>
|
||
<p>In the previous lesson, we wrote ADQL queries and used them to select and download data from the Gaia server.</p>
|
||
<p>In this lesson, we’ll pick up where we left off and write a query to select stars from a particular region of the sky.</p>
|
||
<div class="section" id="outline">
|
||
<h2>Outline<a class="headerlink" href="#outline" title="Permalink to this headline">¶</a></h2>
|
||
<p>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.</p>
|
||
<p>Then, to select stars in the vicinity of GD-1, we’ll:</p>
|
||
<ul class="simple">
|
||
<li><p>Use <code class="docutils literal notranslate"><span class="pre">Quantity</span></code> objects to represent measurements with units.</p></li>
|
||
<li><p>Use Astropy to convert coordinates from one frame to another.</p></li>
|
||
<li><p>Use the ADQL keywords <code class="docutils literal notranslate"><span class="pre">POLYGON</span></code>, <code class="docutils literal notranslate"><span class="pre">CONTAINS</span></code>, and <code class="docutils literal notranslate"><span class="pre">POINT</span></code> to select stars that fall within a polygonal region.</p></li>
|
||
<li><p>Submit a query and download the results.</p></li>
|
||
<li><p>Store the results in a FITS file.</p></li>
|
||
</ul>
|
||
<p>After completing this lesson, you should be able to</p>
|
||
<ul class="simple">
|
||
<li><p>Use Python string formatting to compose more complex ADQL queries.</p></li>
|
||
<li><p>Work with coordinates and other quantities that have units.</p></li>
|
||
<li><p>Download the results of a query and store them in a file.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="working-with-units">
|
||
<h2>Working with Units<a class="headerlink" href="#working-with-units" title="Permalink to this headline">¶</a></h2>
|
||
<p>The measurements we will work with are physical quantities, which means that they have two parts, a value and a unit.
|
||
For example, the coordinate <span class="math notranslate nohighlight">\(30^{\circ}\)</span> has value 30 and its units are degrees.</p>
|
||
<p>Until recently, most scientific computation was done with values only; units were left out of the program altogether, <a class="reference external" href="https://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure">often with catastrophic results</a>.</p>
|
||
<p>Astropy provides tools for including units explicitly in computations, which makes it possible to detect errors before they cause disasters.</p>
|
||
<p>To use Astropy units, we import them like this:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">astropy.units</span> <span class="k">as</span> <span class="nn">u</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p><code class="docutils literal notranslate"><span class="pre">u</span></code> is an object that contains most common units and all SI units.</p>
|
||
<p>You can use <code class="docutils literal notranslate"><span class="pre">dir</span></code> to list them, but you should also <a class="reference external" href="https://docs.astropy.org/en/stable/units/">read the documentation</a>.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="nb">dir</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>['A',
|
||
'AA',
|
||
'AB',
|
||
'ABflux',
|
||
'ABmag',
|
||
'AU',
|
||
'Angstrom',
|
||
'B',
|
||
'Ba',
|
||
'Barye',
|
||
'Bi',
|
||
'Biot',
|
||
'Bol',
|
||
'Bq',
|
||
'C',
|
||
'Celsius',
|
||
'Ci',
|
||
'CompositeUnit',
|
||
'D',
|
||
'Da',
|
||
'Dalton',
|
||
'Debye',
|
||
'Decibel',
|
||
'DecibelUnit',
|
||
'Dex',
|
||
'DexUnit',
|
||
'EA',
|
||
'EAU',
|
||
'EB',
|
||
'EBa',
|
||
'EC',
|
||
'ED',
|
||
'EF',
|
||
'EG',
|
||
'EGal',
|
||
'EH',
|
||
'EHz',
|
||
'EJ',
|
||
'EJy',
|
||
'EK',
|
||
'EL',
|
||
'EN',
|
||
'EOhm',
|
||
'EP',
|
||
'EPa',
|
||
'ER',
|
||
'ERy',
|
||
'ES',
|
||
'ESt',
|
||
'ET',
|
||
'EV',
|
||
'EW',
|
||
'EWb',
|
||
'Ea',
|
||
'Eadu',
|
||
'Earcmin',
|
||
'Earcsec',
|
||
'Eau',
|
||
'Eb',
|
||
'Ebarn',
|
||
'Ebeam',
|
||
'Ebin',
|
||
'Ebit',
|
||
'Ebyte',
|
||
'Ecd',
|
||
'Echan',
|
||
'Ecount',
|
||
'Ect',
|
||
'Ed',
|
||
'Edeg',
|
||
'Edyn',
|
||
'EeV',
|
||
'Eerg',
|
||
'Eg',
|
||
'Eh',
|
||
'EiB',
|
||
'Eib',
|
||
'Eibit',
|
||
'Eibyte',
|
||
'Ek',
|
||
'El',
|
||
'Elm',
|
||
'Elx',
|
||
'Elyr',
|
||
'Em',
|
||
'Emag',
|
||
'Emin',
|
||
'Emol',
|
||
'Eohm',
|
||
'Epc',
|
||
'Eph',
|
||
'Ephoton',
|
||
'Epix',
|
||
'Epixel',
|
||
'Erad',
|
||
'Es',
|
||
'Esr',
|
||
'Eu',
|
||
'Evox',
|
||
'Evoxel',
|
||
'Eyr',
|
||
'F',
|
||
'Farad',
|
||
'Fr',
|
||
'Franklin',
|
||
'FunctionQuantity',
|
||
'FunctionUnitBase',
|
||
'G',
|
||
'GA',
|
||
'GAU',
|
||
'GB',
|
||
'GBa',
|
||
'GC',
|
||
'GD',
|
||
'GF',
|
||
'GG',
|
||
'GGal',
|
||
'GH',
|
||
'GHz',
|
||
'GJ',
|
||
'GJy',
|
||
'GK',
|
||
'GL',
|
||
'GN',
|
||
'GOhm',
|
||
'GP',
|
||
'GPa',
|
||
'GR',
|
||
'GRy',
|
||
'GS',
|
||
'GSt',
|
||
'GT',
|
||
'GV',
|
||
'GW',
|
||
'GWb',
|
||
'Ga',
|
||
'Gadu',
|
||
'Gal',
|
||
'Garcmin',
|
||
'Garcsec',
|
||
'Gau',
|
||
'Gauss',
|
||
'Gb',
|
||
'Gbarn',
|
||
'Gbeam',
|
||
'Gbin',
|
||
'Gbit',
|
||
'Gbyte',
|
||
'Gcd',
|
||
'Gchan',
|
||
'Gcount',
|
||
'Gct',
|
||
'Gd',
|
||
'Gdeg',
|
||
'Gdyn',
|
||
'GeV',
|
||
'Gerg',
|
||
'Gg',
|
||
'Gh',
|
||
'GiB',
|
||
'Gib',
|
||
'Gibit',
|
||
'Gibyte',
|
||
'Gk',
|
||
'Gl',
|
||
'Glm',
|
||
'Glx',
|
||
'Glyr',
|
||
'Gm',
|
||
'Gmag',
|
||
'Gmin',
|
||
'Gmol',
|
||
'Gohm',
|
||
'Gpc',
|
||
'Gph',
|
||
'Gphoton',
|
||
'Gpix',
|
||
'Gpixel',
|
||
'Grad',
|
||
'Gs',
|
||
'Gsr',
|
||
'Gu',
|
||
'Gvox',
|
||
'Gvoxel',
|
||
'Gyr',
|
||
'H',
|
||
'Henry',
|
||
'Hertz',
|
||
'Hz',
|
||
'IrreducibleUnit',
|
||
'J',
|
||
'Jansky',
|
||
'Joule',
|
||
'Jy',
|
||
'K',
|
||
'Kayser',
|
||
'Kelvin',
|
||
'KiB',
|
||
'Kib',
|
||
'Kibit',
|
||
'Kibyte',
|
||
'L',
|
||
'L_bol',
|
||
'L_sun',
|
||
'LogQuantity',
|
||
'LogUnit',
|
||
'Lsun',
|
||
'MA',
|
||
'MAU',
|
||
'MB',
|
||
'MBa',
|
||
'MC',
|
||
'MD',
|
||
'MF',
|
||
'MG',
|
||
'MGal',
|
||
'MH',
|
||
'MHz',
|
||
'MJ',
|
||
'MJy',
|
||
'MK',
|
||
'ML',
|
||
'MN',
|
||
'MOhm',
|
||
'MP',
|
||
'MPa',
|
||
'MR',
|
||
'MRy',
|
||
'MS',
|
||
'MSt',
|
||
'MT',
|
||
'MV',
|
||
'MW',
|
||
'MWb',
|
||
'M_bol',
|
||
'M_e',
|
||
'M_earth',
|
||
'M_jup',
|
||
'M_jupiter',
|
||
'M_p',
|
||
'M_sun',
|
||
'Ma',
|
||
'Madu',
|
||
'MagUnit',
|
||
'Magnitude',
|
||
'Marcmin',
|
||
'Marcsec',
|
||
'Mau',
|
||
'Mb',
|
||
'Mbarn',
|
||
'Mbeam',
|
||
'Mbin',
|
||
'Mbit',
|
||
'Mbyte',
|
||
'Mcd',
|
||
'Mchan',
|
||
'Mcount',
|
||
'Mct',
|
||
'Md',
|
||
'Mdeg',
|
||
'Mdyn',
|
||
'MeV',
|
||
'Mearth',
|
||
'Merg',
|
||
'Mg',
|
||
'Mh',
|
||
'MiB',
|
||
'Mib',
|
||
'Mibit',
|
||
'Mibyte',
|
||
'Mjup',
|
||
'Mjupiter',
|
||
'Mk',
|
||
'Ml',
|
||
'Mlm',
|
||
'Mlx',
|
||
'Mlyr',
|
||
'Mm',
|
||
'Mmag',
|
||
'Mmin',
|
||
'Mmol',
|
||
'Mohm',
|
||
'Mpc',
|
||
'Mph',
|
||
'Mphoton',
|
||
'Mpix',
|
||
'Mpixel',
|
||
'Mrad',
|
||
'Ms',
|
||
'Msr',
|
||
'Msun',
|
||
'Mu',
|
||
'Mvox',
|
||
'Mvoxel',
|
||
'Myr',
|
||
'N',
|
||
'NamedUnit',
|
||
'Newton',
|
||
'Ohm',
|
||
'P',
|
||
'PA',
|
||
'PAU',
|
||
'PB',
|
||
'PBa',
|
||
'PC',
|
||
'PD',
|
||
'PF',
|
||
'PG',
|
||
'PGal',
|
||
'PH',
|
||
'PHz',
|
||
'PJ',
|
||
'PJy',
|
||
'PK',
|
||
'PL',
|
||
'PN',
|
||
'POhm',
|
||
'PP',
|
||
'PPa',
|
||
'PR',
|
||
'PRy',
|
||
'PS',
|
||
'PSt',
|
||
'PT',
|
||
'PV',
|
||
'PW',
|
||
'PWb',
|
||
'Pa',
|
||
'Padu',
|
||
'Parcmin',
|
||
'Parcsec',
|
||
'Pascal',
|
||
'Pau',
|
||
'Pb',
|
||
'Pbarn',
|
||
'Pbeam',
|
||
'Pbin',
|
||
'Pbit',
|
||
'Pbyte',
|
||
'Pcd',
|
||
'Pchan',
|
||
'Pcount',
|
||
'Pct',
|
||
'Pd',
|
||
'Pdeg',
|
||
'Pdyn',
|
||
'PeV',
|
||
'Perg',
|
||
'Pg',
|
||
'Ph',
|
||
'PiB',
|
||
'Pib',
|
||
'Pibit',
|
||
'Pibyte',
|
||
'Pk',
|
||
'Pl',
|
||
'Plm',
|
||
'Plx',
|
||
'Plyr',
|
||
'Pm',
|
||
'Pmag',
|
||
'Pmin',
|
||
'Pmol',
|
||
'Pohm',
|
||
'Ppc',
|
||
'Pph',
|
||
'Pphoton',
|
||
'Ppix',
|
||
'Ppixel',
|
||
'Prad',
|
||
'PrefixUnit',
|
||
'Ps',
|
||
'Psr',
|
||
'Pu',
|
||
'Pvox',
|
||
'Pvoxel',
|
||
'Pyr',
|
||
'Quantity',
|
||
'QuantityInfo',
|
||
'QuantityInfoBase',
|
||
'R',
|
||
'R_earth',
|
||
'R_jup',
|
||
'R_jupiter',
|
||
'R_sun',
|
||
'Rayleigh',
|
||
'Rearth',
|
||
'Rjup',
|
||
'Rjupiter',
|
||
'Rsun',
|
||
'Ry',
|
||
'S',
|
||
'ST',
|
||
'STflux',
|
||
'STmag',
|
||
'Siemens',
|
||
'SpecificTypeQuantity',
|
||
'St',
|
||
'Sun',
|
||
'T',
|
||
'TA',
|
||
'TAU',
|
||
'TB',
|
||
'TBa',
|
||
'TC',
|
||
'TD',
|
||
'TF',
|
||
'TG',
|
||
'TGal',
|
||
'TH',
|
||
'THz',
|
||
'TJ',
|
||
'TJy',
|
||
'TK',
|
||
'TL',
|
||
'TN',
|
||
'TOhm',
|
||
'TP',
|
||
'TPa',
|
||
'TR',
|
||
'TRy',
|
||
'TS',
|
||
'TSt',
|
||
'TT',
|
||
'TV',
|
||
'TW',
|
||
'TWb',
|
||
'Ta',
|
||
'Tadu',
|
||
'Tarcmin',
|
||
'Tarcsec',
|
||
'Tau',
|
||
'Tb',
|
||
'Tbarn',
|
||
'Tbeam',
|
||
'Tbin',
|
||
'Tbit',
|
||
'Tbyte',
|
||
'Tcd',
|
||
'Tchan',
|
||
'Tcount',
|
||
'Tct',
|
||
'Td',
|
||
'Tdeg',
|
||
'Tdyn',
|
||
'TeV',
|
||
'Terg',
|
||
'Tesla',
|
||
'Tg',
|
||
'Th',
|
||
'TiB',
|
||
'Tib',
|
||
'Tibit',
|
||
'Tibyte',
|
||
'Tk',
|
||
'Tl',
|
||
'Tlm',
|
||
'Tlx',
|
||
'Tlyr',
|
||
'Tm',
|
||
'Tmag',
|
||
'Tmin',
|
||
'Tmol',
|
||
'Tohm',
|
||
'Torr',
|
||
'Tpc',
|
||
'Tph',
|
||
'Tphoton',
|
||
'Tpix',
|
||
'Tpixel',
|
||
'Trad',
|
||
'Ts',
|
||
'Tsr',
|
||
'Tu',
|
||
'Tvox',
|
||
'Tvoxel',
|
||
'Tyr',
|
||
'Unit',
|
||
'UnitBase',
|
||
'UnitConversionError',
|
||
'UnitTypeError',
|
||
'UnitsError',
|
||
'UnitsWarning',
|
||
'UnrecognizedUnit',
|
||
'V',
|
||
'Volt',
|
||
'W',
|
||
'Watt',
|
||
'Wb',
|
||
'Weber',
|
||
'YA',
|
||
'YAU',
|
||
'YB',
|
||
'YBa',
|
||
'YC',
|
||
'YD',
|
||
'YF',
|
||
'YG',
|
||
'YGal',
|
||
'YH',
|
||
'YHz',
|
||
'YJ',
|
||
'YJy',
|
||
'YK',
|
||
'YL',
|
||
'YN',
|
||
'YOhm',
|
||
'YP',
|
||
'YPa',
|
||
'YR',
|
||
'YRy',
|
||
'YS',
|
||
'YSt',
|
||
'YT',
|
||
'YV',
|
||
'YW',
|
||
'YWb',
|
||
'Ya',
|
||
'Yadu',
|
||
'Yarcmin',
|
||
'Yarcsec',
|
||
'Yau',
|
||
'Yb',
|
||
'Ybarn',
|
||
'Ybeam',
|
||
'Ybin',
|
||
'Ybit',
|
||
'Ybyte',
|
||
'Ycd',
|
||
'Ychan',
|
||
'Ycount',
|
||
'Yct',
|
||
'Yd',
|
||
'Ydeg',
|
||
'Ydyn',
|
||
'YeV',
|
||
'Yerg',
|
||
'Yg',
|
||
'Yh',
|
||
'Yk',
|
||
'Yl',
|
||
'Ylm',
|
||
'Ylx',
|
||
'Ylyr',
|
||
'Ym',
|
||
'Ymag',
|
||
'Ymin',
|
||
'Ymol',
|
||
'Yohm',
|
||
'Ypc',
|
||
'Yph',
|
||
'Yphoton',
|
||
'Ypix',
|
||
'Ypixel',
|
||
'Yrad',
|
||
'Ys',
|
||
'Ysr',
|
||
'Yu',
|
||
'Yvox',
|
||
'Yvoxel',
|
||
'Yyr',
|
||
'ZA',
|
||
'ZAU',
|
||
'ZB',
|
||
'ZBa',
|
||
'ZC',
|
||
'ZD',
|
||
'ZF',
|
||
'ZG',
|
||
'ZGal',
|
||
'ZH',
|
||
'ZHz',
|
||
'ZJ',
|
||
'ZJy',
|
||
'ZK',
|
||
'ZL',
|
||
'ZN',
|
||
'ZOhm',
|
||
'ZP',
|
||
'ZPa',
|
||
'ZR',
|
||
'ZRy',
|
||
'ZS',
|
||
'ZSt',
|
||
'ZT',
|
||
'ZV',
|
||
'ZW',
|
||
'ZWb',
|
||
'Za',
|
||
'Zadu',
|
||
'Zarcmin',
|
||
'Zarcsec',
|
||
'Zau',
|
||
'Zb',
|
||
'Zbarn',
|
||
'Zbeam',
|
||
'Zbin',
|
||
'Zbit',
|
||
'Zbyte',
|
||
'Zcd',
|
||
'Zchan',
|
||
'Zcount',
|
||
'Zct',
|
||
'Zd',
|
||
'Zdeg',
|
||
'Zdyn',
|
||
'ZeV',
|
||
'Zerg',
|
||
'Zg',
|
||
'Zh',
|
||
'Zk',
|
||
'Zl',
|
||
'Zlm',
|
||
'Zlx',
|
||
'Zlyr',
|
||
'Zm',
|
||
'Zmag',
|
||
'Zmin',
|
||
'Zmol',
|
||
'Zohm',
|
||
'Zpc',
|
||
'Zph',
|
||
'Zphoton',
|
||
'Zpix',
|
||
'Zpixel',
|
||
'Zrad',
|
||
'Zs',
|
||
'Zsr',
|
||
'Zu',
|
||
'Zvox',
|
||
'Zvoxel',
|
||
'Zyr',
|
||
'__builtins__',
|
||
'__cached__',
|
||
'__doc__',
|
||
'__file__',
|
||
'__loader__',
|
||
'__name__',
|
||
'__package__',
|
||
'__path__',
|
||
'__spec__',
|
||
'a',
|
||
'aA',
|
||
'aAU',
|
||
'aB',
|
||
'aBa',
|
||
'aC',
|
||
'aD',
|
||
'aF',
|
||
'aG',
|
||
'aGal',
|
||
'aH',
|
||
'aHz',
|
||
'aJ',
|
||
'aJy',
|
||
'aK',
|
||
'aL',
|
||
'aN',
|
||
'aOhm',
|
||
'aP',
|
||
'aPa',
|
||
'aR',
|
||
'aRy',
|
||
'aS',
|
||
'aSt',
|
||
'aT',
|
||
'aV',
|
||
'aW',
|
||
'aWb',
|
||
'aa',
|
||
'aadu',
|
||
'aarcmin',
|
||
'aarcsec',
|
||
'aau',
|
||
'ab',
|
||
'abA',
|
||
'abC',
|
||
'abampere',
|
||
'abarn',
|
||
'abcoulomb',
|
||
'abeam',
|
||
'abin',
|
||
'abit',
|
||
'abyte',
|
||
'acd',
|
||
'achan',
|
||
'acount',
|
||
'act',
|
||
'ad',
|
||
'add_enabled_equivalencies',
|
||
'add_enabled_units',
|
||
'adeg',
|
||
'adu',
|
||
'adyn',
|
||
'aeV',
|
||
'aerg',
|
||
'ag',
|
||
'ah',
|
||
'ak',
|
||
'al',
|
||
'allclose',
|
||
'alm',
|
||
'alx',
|
||
'alyr',
|
||
'am',
|
||
'amag',
|
||
'amin',
|
||
'amol',
|
||
'amp',
|
||
'ampere',
|
||
'angstrom',
|
||
'annum',
|
||
'aohm',
|
||
'apc',
|
||
'aph',
|
||
'aphoton',
|
||
'apix',
|
||
'apixel',
|
||
'arad',
|
||
'arcmin',
|
||
'arcminute',
|
||
'arcsec',
|
||
'arcsecond',
|
||
'asr',
|
||
'astronomical_unit',
|
||
'astrophys',
|
||
'attoBarye',
|
||
'attoDa',
|
||
'attoDalton',
|
||
'attoDebye',
|
||
'attoFarad',
|
||
'attoGauss',
|
||
'attoHenry',
|
||
'attoHertz',
|
||
'attoJansky',
|
||
'attoJoule',
|
||
'attoKayser',
|
||
'attoKelvin',
|
||
'attoNewton',
|
||
'attoOhm',
|
||
'attoPascal',
|
||
'attoRayleigh',
|
||
'attoSiemens',
|
||
'attoTesla',
|
||
'attoVolt',
|
||
'attoWatt',
|
||
'attoWeber',
|
||
'attoamp',
|
||
'attoampere',
|
||
'attoannum',
|
||
'attoarcminute',
|
||
'attoarcsecond',
|
||
'attoastronomical_unit',
|
||
'attobarn',
|
||
'attobarye',
|
||
'attobit',
|
||
'attobyte',
|
||
'attocandela',
|
||
'attocoulomb',
|
||
'attocount',
|
||
'attoday',
|
||
'attodebye',
|
||
'attodegree',
|
||
'attodyne',
|
||
'attoelectronvolt',
|
||
'attofarad',
|
||
'attogal',
|
||
'attogauss',
|
||
'attogram',
|
||
'attohenry',
|
||
'attohertz',
|
||
'attohour',
|
||
'attohr',
|
||
'attojansky',
|
||
'attojoule',
|
||
'attokayser',
|
||
'attolightyear',
|
||
'attoliter',
|
||
'attolumen',
|
||
'attolux',
|
||
'attometer',
|
||
'attominute',
|
||
'attomole',
|
||
'attonewton',
|
||
'attoparsec',
|
||
'attopascal',
|
||
'attophoton',
|
||
'attopixel',
|
||
'attopoise',
|
||
'attoradian',
|
||
'attorayleigh',
|
||
'attorydberg',
|
||
'attosecond',
|
||
'attosiemens',
|
||
'attosteradian',
|
||
'attostokes',
|
||
'attotesla',
|
||
'attovolt',
|
||
'attovoxel',
|
||
'attowatt',
|
||
'attoweber',
|
||
'attoyear',
|
||
'au',
|
||
'avox',
|
||
'avoxel',
|
||
'ayr',
|
||
'b',
|
||
'bar',
|
||
'barn',
|
||
'barye',
|
||
'beam',
|
||
'beam_angular_area',
|
||
'becquerel',
|
||
'bin',
|
||
'binary_prefixes',
|
||
'bit',
|
||
'bol',
|
||
'brightness_temperature',
|
||
'byte',
|
||
'cA',
|
||
'cAU',
|
||
'cB',
|
||
'cBa',
|
||
'cC',
|
||
'cD',
|
||
'cF',
|
||
'cG',
|
||
'cGal',
|
||
'cH',
|
||
'cHz',
|
||
'cJ',
|
||
'cJy',
|
||
'cK',
|
||
'cL',
|
||
'cN',
|
||
'cOhm',
|
||
'cP',
|
||
'cPa',
|
||
'cR',
|
||
'cRy',
|
||
'cS',
|
||
'cSt',
|
||
'cT',
|
||
'cV',
|
||
'cW',
|
||
'cWb',
|
||
'ca',
|
||
'cadu',
|
||
'candela',
|
||
'carcmin',
|
||
'carcsec',
|
||
'cau',
|
||
'cb',
|
||
'cbarn',
|
||
'cbeam',
|
||
'cbin',
|
||
'cbit',
|
||
'cbyte',
|
||
'ccd',
|
||
'cchan',
|
||
'ccount',
|
||
'cct',
|
||
'cd',
|
||
'cdeg',
|
||
'cdyn',
|
||
'ceV',
|
||
'centiBarye',
|
||
'centiDa',
|
||
'centiDalton',
|
||
'centiDebye',
|
||
'centiFarad',
|
||
'centiGauss',
|
||
'centiHenry',
|
||
'centiHertz',
|
||
'centiJansky',
|
||
'centiJoule',
|
||
'centiKayser',
|
||
'centiKelvin',
|
||
'centiNewton',
|
||
'centiOhm',
|
||
'centiPascal',
|
||
'centiRayleigh',
|
||
'centiSiemens',
|
||
'centiTesla',
|
||
'centiVolt',
|
||
'centiWatt',
|
||
'centiWeber',
|
||
'centiamp',
|
||
'centiampere',
|
||
'centiannum',
|
||
'centiarcminute',
|
||
'centiarcsecond',
|
||
'centiastronomical_unit',
|
||
'centibarn',
|
||
'centibarye',
|
||
'centibit',
|
||
'centibyte',
|
||
'centicandela',
|
||
'centicoulomb',
|
||
'centicount',
|
||
'centiday',
|
||
'centidebye',
|
||
'centidegree',
|
||
'centidyne',
|
||
'centielectronvolt',
|
||
'centifarad',
|
||
'centigal',
|
||
'centigauss',
|
||
'centigram',
|
||
'centihenry',
|
||
'centihertz',
|
||
'centihour',
|
||
'centihr',
|
||
'centijansky',
|
||
'centijoule',
|
||
'centikayser',
|
||
'centilightyear',
|
||
'centiliter',
|
||
'centilumen',
|
||
'centilux',
|
||
'centimeter',
|
||
'centiminute',
|
||
'centimole',
|
||
'centinewton',
|
||
'centiparsec',
|
||
'centipascal',
|
||
'centiphoton',
|
||
'centipixel',
|
||
'centipoise',
|
||
'centiradian',
|
||
'centirayleigh',
|
||
'centirydberg',
|
||
'centisecond',
|
||
'centisiemens',
|
||
'centisteradian',
|
||
'centistokes',
|
||
'centitesla',
|
||
'centivolt',
|
||
'centivoxel',
|
||
'centiwatt',
|
||
'centiweber',
|
||
'centiyear',
|
||
'cerg',
|
||
'cg',
|
||
'cgs',
|
||
'ch',
|
||
'chan',
|
||
'ck',
|
||
'cl',
|
||
'clm',
|
||
'clx',
|
||
'clyr',
|
||
'cm',
|
||
'cmag',
|
||
'cmin',
|
||
'cmol',
|
||
'cohm',
|
||
'core',
|
||
'coulomb',
|
||
'count',
|
||
'cpc',
|
||
'cph',
|
||
'cphoton',
|
||
'cpix',
|
||
'cpixel',
|
||
'crad',
|
||
'cs',
|
||
'csr',
|
||
'ct',
|
||
'cu',
|
||
'curie',
|
||
'cvox',
|
||
'cvoxel',
|
||
'cy',
|
||
'cycle',
|
||
'cyr',
|
||
'd',
|
||
'dA',
|
||
'dAU',
|
||
'dB',
|
||
'dBa',
|
||
'dC',
|
||
'dD',
|
||
'dF',
|
||
'dG',
|
||
'dGal',
|
||
'dH',
|
||
'dHz',
|
||
'dJ',
|
||
'dJy',
|
||
'dK',
|
||
'dL',
|
||
'dN',
|
||
'dOhm',
|
||
'dP',
|
||
'dPa',
|
||
'dR',
|
||
'dRy',
|
||
'dS',
|
||
'dSt',
|
||
...]
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>To create a quantity, we multiply a value by a unit.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">angle</span> <span class="o">=</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
<span class="nb">type</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>astropy.units.quantity.Quantity
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>The result is a <code class="docutils literal notranslate"><span class="pre">Quantity</span></code> object.
|
||
Jupyter knows how to display <code class="docutils literal notranslate"><span class="pre">Quantities</span></code> like this:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">angle</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_latex math notranslate nohighlight">
|
||
\[10 \; \mathrm{{}^{\circ}}\]</div>
|
||
</div>
|
||
</div>
|
||
<p>Quantities provide a method called <code class="docutils literal notranslate"><span class="pre">to</span></code> that converts to other units. For example, we can compute the number of arcminutes in <code class="docutils literal notranslate"><span class="pre">angle</span></code>:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">angle_arcmin</span> <span class="o">=</span> <span class="n">angle</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">u</span><span class="o">.</span><span class="n">arcmin</span><span class="p">)</span>
|
||
<span class="n">angle_arcmin</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_latex math notranslate nohighlight">
|
||
\[600 \; \mathrm{{}^{\prime}}\]</div>
|
||
</div>
|
||
</div>
|
||
<p>If you add quantities, Astropy converts them to compatible units, if possible:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">angle</span> <span class="o">+</span> <span class="mi">30</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">arcmin</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_latex math notranslate nohighlight">
|
||
\[10.5 \; \mathrm{{}^{\circ}}\]</div>
|
||
</div>
|
||
</div>
|
||
<p>If the units are not compatible, you get an error.
|
||
For example:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">angle</span> <span class="o">+</span> <span class="mi">5</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">second</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>causes a <code class="docutils literal notranslate"><span class="pre">UnitConversionError</span></code>.</p>
|
||
<div class="section" id="exercise">
|
||
<h3>Exercise<a class="headerlink" href="#exercise" title="Permalink to this headline">¶</a></h3>
|
||
<p>Create a quantity that represents 5 <a class="reference external" href="https://en.wikipedia.org/wiki/Minute_and_second_of_arc">arcminutes</a> and assign it to a variable called <code class="docutils literal notranslate"><span class="pre">radius</span></code>.</p>
|
||
<p>Then convert it to degrees.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">## Solution</span>
|
||
|
||
<span class="n">radius</span> <span class="o">=</span> <span class="mi">5</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">arcmin</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">radius</span><span class="p">)</span>
|
||
|
||
<span class="n">radius</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">u</span><span class="o">.</span><span class="n">degree</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>5.0 arcmin
|
||
</pre></div>
|
||
</div>
|
||
<div class="output text_latex math notranslate nohighlight">
|
||
\[0.083333333 \; \mathrm{{}^{\circ}}\]</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="selecting-a-region">
|
||
<h2>Selecting a Region<a class="headerlink" href="#selecting-a-region" title="Permalink to this headline">¶</a></h2>
|
||
<p>One of the most common ways to restrict a query is to select stars in a particular region of the sky.
|
||
For example, here’s a query from the <a class="reference external" href="https://gea.esac.esa.int/archive-help/adql/examples/index.html">Gaia archive documentation</a> that selects objects in a circular region centered at (88.8, 7.4) with a search radius of 5 arcmin (0.08333 deg).</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">query_cone</span> <span class="o">=</span> <span class="s2">"""SELECT </span>
|
||
<span class="s2">TOP 10 </span>
|
||
<span class="s2">source_id</span>
|
||
<span class="s2">FROM gaiadr2.gaia_source</span>
|
||
<span class="s2">WHERE 1=CONTAINS(</span>
|
||
<span class="s2"> POINT(ra, dec),</span>
|
||
<span class="s2"> CIRCLE(88.8, 7.4, 0.08333333))</span>
|
||
<span class="s2">"""</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>This query uses three keywords that are specific to ADQL (not SQL):</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">POINT</span></code>: a location in <a class="reference external" href="https://en.wikipedia.org/wiki/International_Celestial_Reference_System">ICRS coordinates</a>, specified in degrees of right ascension and declination.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">CIRCLE</span></code>: a circle where the first two values are the coordinates of the center and the third is the radius in degrees.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">CONTAINS</span></code>: a function that returns <code class="docutils literal notranslate"><span class="pre">1</span></code> if a <code class="docutils literal notranslate"><span class="pre">POINT</span></code> is contained in a shape and <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise.</p></li>
|
||
</ul>
|
||
<p>Here is the <a class="reference external" href="http://www.ivoa.net/documents/ADQL/20180112/PR-ADQL-2.1-20180112.html#tth_sEc4.2.12">documentation of <code class="docutils literal notranslate"><span class="pre">CONTAINS</span></code></a>.</p>
|
||
<p>A query like this is called a cone search because it selects stars in a cone.
|
||
Here’s how we run it.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">astroquery.gaia</span> <span class="kn">import</span> <span class="n">Gaia</span>
|
||
|
||
<span class="n">job</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">launch_job</span><span class="p">(</span><span class="n">query_cone</span><span class="p">)</span>
|
||
<span class="n">job</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Created TAP+ (v1.2.1) - Connection:
|
||
Host: gea.esac.esa.int
|
||
Use HTTPS: True
|
||
Port: 443
|
||
SSL Port: 443
|
||
Created TAP+ (v1.2.1) - Connection:
|
||
Host: geadata.esac.esa.int
|
||
Use HTTPS: True
|
||
Port: 443
|
||
SSL Port: 443
|
||
</pre></div>
|
||
</div>
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><astroquery.utils.tap.model.job.Job at 0x7f277785fa30>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">results</span> <span class="o">=</span> <span class="n">job</span><span class="o">.</span><span class="n">get_results</span><span class="p">()</span>
|
||
<span class="n">results</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_html"><i>Table length=10</i>
|
||
<table id="table139807485721280" class="table-striped table-bordered table-condensed">
|
||
<thead><tr><th>source_id</th></tr></thead>
|
||
<thead><tr><th>int64</th></tr></thead>
|
||
<tr><td>3322773965056065536</td></tr>
|
||
<tr><td>3322773758899157120</td></tr>
|
||
<tr><td>3322774068134271104</td></tr>
|
||
<tr><td>3322773930696320512</td></tr>
|
||
<tr><td>3322774377374425728</td></tr>
|
||
<tr><td>3322773724537891456</td></tr>
|
||
<tr><td>3322773724537891328</td></tr>
|
||
<tr><td>3322773930696321792</td></tr>
|
||
<tr><td>3322773724537890944</td></tr>
|
||
<tr><td>3322773930696322176</td></tr>
|
||
</table></div></div>
|
||
</div>
|
||
<div class="section" id="id1">
|
||
<h3>Exercise<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
|
||
<p>When you are debugging queries like this, you can use <code class="docutils literal notranslate"><span class="pre">TOP</span></code> to limit the size of the results, but then you still don’t know how big the results will be.</p>
|
||
<p>An alternative is to use <code class="docutils literal notranslate"><span class="pre">COUNT</span></code>, which asks for the number of rows that would be selected, but it does not return them.</p>
|
||
<p>In the previous query, replace <code class="docutils literal notranslate"><span class="pre">TOP</span> <span class="pre">10</span> <span class="pre">source_id</span></code> with <code class="docutils literal notranslate"><span class="pre">COUNT(source_id)</span></code> and run the query again. How many stars has Gaia identified in the cone we searched?</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Solution</span>
|
||
|
||
<span class="n">query</span> <span class="o">=</span> <span class="s2">"""SELECT </span>
|
||
<span class="s2">COUNT(source_id)</span>
|
||
<span class="s2">FROM gaiadr2.gaia_source</span>
|
||
<span class="s2">WHERE 1=CONTAINS(</span>
|
||
<span class="s2"> POINT(ra, dec),</span>
|
||
<span class="s2"> CIRCLE(88.8, 7.4, 0.08333333))</span>
|
||
<span class="s2">"""</span>
|
||
|
||
<span class="n">job</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">launch_job</span><span class="p">(</span><span class="n">query</span><span class="p">)</span>
|
||
<span class="n">results</span> <span class="o">=</span> <span class="n">job</span><span class="o">.</span><span class="n">get_results</span><span class="p">()</span>
|
||
<span class="n">results</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_html"><i>Table length=1</i>
|
||
<table id="table139808112576400" class="table-striped table-bordered table-condensed">
|
||
<thead><tr><th>count</th></tr></thead>
|
||
<thead><tr><th>int64</th></tr></thead>
|
||
<tr><td>594</td></tr>
|
||
</table></div></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="getting-gd-1-data">
|
||
<h2>Getting GD-1 Data<a class="headerlink" href="#getting-gd-1-data" title="Permalink to this headline">¶</a></h2>
|
||
<p>From the Price-Whelan and Bonaca paper, we will try to reproduce Figure 1, which includes this representation of stars likely to belong to GD-1:</p>
|
||
<img alt="https://github.com/datacarpentry/astronomy-python/raw/gh-pages/fig/gd1-4.png" src="https://github.com/datacarpentry/astronomy-python/raw/gh-pages/fig/gd1-4.png" />
|
||
<p>The axes of this figure are defined so the x-axis is aligned with the stars in GD-1, and the y-axis is perpendicular.</p>
|
||
<ul class="simple">
|
||
<li><p>Along the x-axis (<span class="math notranslate nohighlight">\(\phi_1\)</span>) the figure extends from -100 to 20 degrees.</p></li>
|
||
<li><p>Along the y-axis (<span class="math notranslate nohighlight">\(\phi_2\)</span>) the figure extends from about -8 to 4 degrees.</p></li>
|
||
</ul>
|
||
<p>Ideally, we would select all stars from this rectangle, but there are more than 10 million of them, so</p>
|
||
<ul class="simple">
|
||
<li><p>That would be difficult to work with,</p></li>
|
||
<li><p>As anonymous Gaia users, we are limited to 3 million rows in a single query, and</p></li>
|
||
<li><p>While we are developing and testing code, it will be faster to work with a smaller dataset.</p></li>
|
||
</ul>
|
||
<p>So we’ll start by selecting stars in a smaller rectangle near the center of GD-1, from -55 to -45 degrees <span class="math notranslate nohighlight">\(\phi_1\)</span> and -8 to 4 degrees <span class="math notranslate nohighlight">\(\phi_2\)</span>.</p>
|
||
<p>But first we let’s see how to represent these coordinates with Astropy.</p>
|
||
</div>
|
||
<div class="section" id="transforming-coordinates">
|
||
<h2>Transforming coordinates<a class="headerlink" href="#transforming-coordinates" title="Permalink to this headline">¶</a></h2>
|
||
<p>Astropy provides a <code class="docutils literal notranslate"><span class="pre">SkyCoord</span></code> object that represents sky coordinates relative to a specified frame.</p>
|
||
<p>The following example creates a <code class="docutils literal notranslate"><span class="pre">SkyCoord</span></code> object that represents the approximate coordinates of <a class="reference external" href="http://simbad.u-strasbg.fr/simbad/sim-basic?Ident=Betelgeuse">Betelgeuse</a> (alf Ori) in the ICRS frame.</p>
|
||
<p><a class="reference external" href="https://www.iers.org/IERS/EN/Science/ICRS/ICRS.html">ICRS</a> is the
|
||
“International Celestial Reference System”, adopted in 1997 by the International Astronomical Union.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">astropy.coordinates</span> <span class="kn">import</span> <span class="n">SkyCoord</span>
|
||
|
||
<span class="n">ra</span> <span class="o">=</span> <span class="mf">88.8</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
<span class="n">dec</span> <span class="o">=</span> <span class="mf">7.4</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
<span class="n">coord_icrs</span> <span class="o">=</span> <span class="n">SkyCoord</span><span class="p">(</span><span class="n">ra</span><span class="o">=</span><span class="n">ra</span><span class="p">,</span> <span class="n">dec</span><span class="o">=</span><span class="n">dec</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="s1">'icrs'</span><span class="p">)</span>
|
||
|
||
<span class="n">coord_icrs</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><SkyCoord (ICRS): (ra, dec) in deg
|
||
(88.8, 7.4)>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p><code class="docutils literal notranslate"><span class="pre">SkyCoord</span></code> provides a function that transforms to other frames.
|
||
For example, we can transform <code class="docutils literal notranslate"><span class="pre">coords_icrs</span></code> to Galactic coordinates like this:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">coord_galactic</span> <span class="o">=</span> <span class="n">coord_icrs</span><span class="o">.</span><span class="n">transform_to</span><span class="p">(</span><span class="s1">'galactic'</span><span class="p">)</span>
|
||
<span class="n">coord_galactic</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><SkyCoord (Galactic): (l, b) in deg
|
||
(199.79693102, -8.95591653)>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Notice that in the Galactic frame, the coordinates are called <code class="docutils literal notranslate"><span class="pre">l</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code>, not <code class="docutils literal notranslate"><span class="pre">ra</span></code> and <code class="docutils literal notranslate"><span class="pre">dec</span></code>.</p>
|
||
<p>To transform to and from GD-1 coordinates, we’ll use a frame defined by <a class="reference external" href="https://gala-astro.readthedocs.io/en/latest/">Gala</a>, which is an Astropy-affiliated library that provides tools for galactic dynamics.</p>
|
||
<p>Gala provides <a class="reference external" href="https://gala-astro.readthedocs.io/en/latest/_modules/gala/coordinates/gd1.html"><code class="docutils literal notranslate"><span class="pre">GD1Koposov10</span></code></a>, which is “a Heliocentric spherical coordinate system defined by the orbit of the GD-1 stream”.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">gala.coordinates</span> <span class="kn">import</span> <span class="n">GD1Koposov10</span>
|
||
|
||
<span class="n">gd1_frame</span> <span class="o">=</span> <span class="n">GD1Koposov10</span><span class="p">()</span>
|
||
<span class="n">gd1_frame</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><GD1Koposov10 Frame>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>We can use it to find the coordinates of Betelgeuse in the GD-1 frame, like this:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">coord_gd1</span> <span class="o">=</span> <span class="n">coord_icrs</span><span class="o">.</span><span class="n">transform_to</span><span class="p">(</span><span class="n">gd1_frame</span><span class="p">)</span>
|
||
<span class="n">coord_gd1</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><SkyCoord (GD1Koposov10): (phi1, phi2) in deg
|
||
(-94.97222038, 34.5813813)>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Notice that the coordinates are called <code class="docutils literal notranslate"><span class="pre">phi1</span></code> and <code class="docutils literal notranslate"><span class="pre">phi2</span></code>.
|
||
These are the coordinates shown in the figure from the paper, above.</p>
|
||
<div class="section" id="id2">
|
||
<h3>Exercise<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
|
||
<p>Let’s find the location of GD-1 in ICRS coordinates.</p>
|
||
<ol class="simple">
|
||
<li><p>Create a <code class="docutils literal notranslate"><span class="pre">SkyCoord</span></code> object at 0°, 0° in the GD-1 frame.</p></li>
|
||
<li><p>Transform it to the ICRS frame.</p></li>
|
||
</ol>
|
||
<p>Hint: Because ICRS is built into Astropy, you can specify it by name, <code class="docutils literal notranslate"><span class="pre">icrs</span></code> (as we did with <code class="docutils literal notranslate"><span class="pre">galactic</span></code>).</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Solution</span>
|
||
|
||
<span class="n">origin_gd1</span> <span class="o">=</span> <span class="n">SkyCoord</span><span class="p">(</span><span class="mi">0</span><span class="o">*</span><span class="n">u</span><span class="o">.</span><span class="n">degree</span><span class="p">,</span> <span class="mi">0</span><span class="o">*</span><span class="n">u</span><span class="o">.</span><span class="n">degree</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="n">gd1_frame</span><span class="p">)</span>
|
||
|
||
<span class="c1"># OR</span>
|
||
|
||
<span class="n">origin_gd1</span> <span class="o">=</span> <span class="n">SkyCoord</span><span class="p">(</span><span class="n">phi1</span><span class="o">=</span><span class="mi">0</span><span class="o">*</span><span class="n">u</span><span class="o">.</span><span class="n">degree</span><span class="p">,</span>
|
||
<span class="n">phi2</span><span class="o">=</span><span class="mi">0</span><span class="o">*</span><span class="n">u</span><span class="o">.</span><span class="n">degree</span><span class="p">,</span>
|
||
<span class="n">frame</span><span class="o">=</span><span class="n">gd1_frame</span><span class="p">)</span>
|
||
|
||
<span class="c1"># Note: because ICRS is built into Astropy, </span>
|
||
<span class="c1"># we can identify it by string name</span>
|
||
<span class="n">origin_gd1</span><span class="o">.</span><span class="n">transform_to</span><span class="p">(</span><span class="s1">'icrs'</span><span class="p">)</span>
|
||
|
||
<span class="c1"># More formally, we could instantiate it</span>
|
||
<span class="kn">from</span> <span class="nn">astropy.coordinates</span> <span class="kn">import</span> <span class="n">ICRS</span>
|
||
<span class="n">icrs_frame</span> <span class="o">=</span> <span class="n">ICRS</span><span class="p">()</span>
|
||
<span class="n">origin_gd1</span><span class="o">.</span><span class="n">transform_to</span><span class="p">(</span><span class="n">icrs_frame</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><SkyCoord (ICRS): (ra, dec) in deg
|
||
(200., 59.4504341)>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Notice that the origin of the GD-1 frame maps to <code class="docutils literal notranslate"><span class="pre">ra=200</span></code>, exactly, in ICRS. That’s by design.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="selecting-a-rectangle">
|
||
<h2>Selecting a rectangle<a class="headerlink" href="#selecting-a-rectangle" title="Permalink to this headline">¶</a></h2>
|
||
<p>Now we’ll use these coordinate transformations to define a rectangle in the GD-1 frame and transform it to ICRS.</p>
|
||
<p>The following variables define the boundaries of the rectangle in <span class="math notranslate nohighlight">\(\phi_1\)</span> and <span class="math notranslate nohighlight">\(\phi_2\)</span>.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">phi1_min</span> <span class="o">=</span> <span class="o">-</span><span class="mi">55</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
<span class="n">phi1_max</span> <span class="o">=</span> <span class="o">-</span><span class="mi">45</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
<span class="n">phi2_min</span> <span class="o">=</span> <span class="o">-</span><span class="mi">8</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
<span class="n">phi2_max</span> <span class="o">=</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">degree</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>To create a rectangle, we’ll use the following function, which takes the lower and upper bounds as parameters.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">make_rectangle</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">y2</span><span class="p">):</span>
|
||
<span class="sd">"""Return the corners of a rectangle."""</span>
|
||
<span class="n">xs</span> <span class="o">=</span> <span class="p">[</span><span class="n">x1</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">x1</span><span class="p">]</span>
|
||
<span class="n">ys</span> <span class="o">=</span> <span class="p">[</span><span class="n">y1</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">y1</span><span class="p">]</span>
|
||
<span class="k">return</span> <span class="n">xs</span><span class="p">,</span> <span class="n">ys</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>The return value is a tuple containing a list of coordinates in <code class="docutils literal notranslate"><span class="pre">phi1</span></code> followed by a list of coordinates in <code class="docutils literal notranslate"><span class="pre">phi2</span></code>.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">phi1_rect</span><span class="p">,</span> <span class="n">phi2_rect</span> <span class="o">=</span> <span class="n">make_rectangle</span><span class="p">(</span>
|
||
<span class="n">phi1_min</span><span class="p">,</span> <span class="n">phi1_max</span><span class="p">,</span> <span class="n">phi2_min</span><span class="p">,</span> <span class="n">phi2_max</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p><code class="docutils literal notranslate"><span class="pre">phi1_rect</span></code> and <code class="docutils literal notranslate"><span class="pre">phi2_rect</span></code> contains the coordinates of the corners of a rectangle in the GD-1 frame.</p>
|
||
<p>In order to use them in a Gaia query, we have to convert them to ICRS. First we’ll put them into a <code class="docutils literal notranslate"><span class="pre">SkyCoord</span></code> object.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">corners</span> <span class="o">=</span> <span class="n">SkyCoord</span><span class="p">(</span><span class="n">phi1</span><span class="o">=</span><span class="n">phi1_rect</span><span class="p">,</span> <span class="n">phi2</span><span class="o">=</span><span class="n">phi2_rect</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="n">gd1_frame</span><span class="p">)</span>
|
||
<span class="n">corners</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><SkyCoord (GD1Koposov10): (phi1, phi2) in deg
|
||
[(-55., -8.), (-55., 4.), (-45., 4.), (-45., -8.), (-55., -8.)]>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Now we can use <code class="docutils literal notranslate"><span class="pre">transform_to</span></code> to convert to ICRS coordinates.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">corners_icrs</span> <span class="o">=</span> <span class="n">corners</span><span class="o">.</span><span class="n">transform_to</span><span class="p">(</span><span class="s1">'icrs'</span><span class="p">)</span>
|
||
<span class="n">corners_icrs</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><SkyCoord (ICRS): (ra, dec) in deg
|
||
[(146.27533314, 19.26190982), (135.42163944, 25.87738723),
|
||
(141.60264825, 34.3048303 ), (152.81671045, 27.13611254),
|
||
(146.27533314, 19.26190982)]>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Notice that a rectangle in one coordinate system is not necessarily a rectangle in another. In this example, the result is a (non-rectangular) polygon.</p>
|
||
</div>
|
||
<div class="section" id="defining-a-polygon">
|
||
<h2>Defining a polygon<a class="headerlink" href="#defining-a-polygon" title="Permalink to this headline">¶</a></h2>
|
||
<p>In order to use this polygon as part of an ADQL query, we have to convert it to a string with a comma-separated list of coordinates, as in this example:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||
<span class="sd">POLYGON(143.65, 20.98, </span>
|
||
<span class="sd"> 134.46, 26.39, </span>
|
||
<span class="sd"> 140.58, 34.85, </span>
|
||
<span class="sd"> 150.16, 29.01)</span>
|
||
<span class="sd">"""</span>
|
||
</pre></div>
|
||
</div>
|
||
<p><code class="docutils literal notranslate"><span class="pre">SkyCoord</span></code> provides <code class="docutils literal notranslate"><span class="pre">to_string</span></code>, which produces a list of strings.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">t</span> <span class="o">=</span> <span class="n">corners_icrs</span><span class="o">.</span><span class="n">to_string</span><span class="p">()</span>
|
||
<span class="n">t</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>['146.275 19.2619',
|
||
'135.422 25.8774',
|
||
'141.603 34.3048',
|
||
'152.817 27.1361',
|
||
'146.275 19.2619']
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>We can use the Python string function <code class="docutils literal notranslate"><span class="pre">join</span></code> to join <code class="docutils literal notranslate"><span class="pre">t</span></code> into a single string (with spaces between the pairs):</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">s</span> <span class="o">=</span> <span class="s1">' '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
|
||
<span class="n">s</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'146.275 19.2619 135.422 25.8774 141.603 34.3048 152.817 27.1361 146.275 19.2619'
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>That’s almost what we need, but we have to replace the spaces with commas.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">s</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619'
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>The following function combines these steps.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">skycoord_to_string</span><span class="p">(</span><span class="n">skycoord</span><span class="p">):</span>
|
||
<span class="sd">"""Convert SkyCoord to string."""</span>
|
||
<span class="n">t</span> <span class="o">=</span> <span class="n">skycoord</span><span class="o">.</span><span class="n">to_string</span><span class="p">()</span>
|
||
<span class="n">s</span> <span class="o">=</span> <span class="s1">' '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="n">s</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span> <span class="s1">', '</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Here’s how we use it.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">point_list</span> <span class="o">=</span> <span class="n">skycoord_to_string</span><span class="p">(</span><span class="n">corners_icrs</span><span class="p">)</span>
|
||
<span class="n">point_list</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619'
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="assembling-the-query">
|
||
<h2>Assembling the query<a class="headerlink" href="#assembling-the-query" title="Permalink to this headline">¶</a></h2>
|
||
<p>Now we’re ready to assemble the query.
|
||
We need <code class="docutils literal notranslate"><span class="pre">columns</span></code> again (as we saw in the previous lesson).</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">columns</span> <span class="o">=</span> <span class="s1">'source_id, ra, dec, pmra, pmdec, parallax'</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>And here’s the query base we used in the previous lesson:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">query3_base</span> <span class="o">=</span> <span class="s2">"""SELECT </span>
|
||
<span class="s2">TOP 10 </span>
|
||
<span class="si">{columns}</span><span class="s2"></span>
|
||
<span class="s2">FROM gaiadr2.gaia_source</span>
|
||
<span class="s2">WHERE parallax < 1</span>
|
||
<span class="s2"> AND bp_rp BETWEEN -0.75 AND 2</span>
|
||
<span class="s2">"""</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Now we’ll add a <code class="docutils literal notranslate"><span class="pre">WHERE</span></code> clause to select stars in the polygon we defined.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">query4_base</span> <span class="o">=</span> <span class="s2">"""SELECT</span>
|
||
<span class="s2">TOP 10</span>
|
||
<span class="si">{columns}</span><span class="s2"></span>
|
||
<span class="s2">FROM gaiadr2.gaia_source</span>
|
||
<span class="s2">WHERE parallax < 1</span>
|
||
<span class="s2"> AND bp_rp BETWEEN -0.75 AND 2 </span>
|
||
<span class="s2"> AND 1 = CONTAINS(POINT(ra, dec), </span>
|
||
<span class="s2"> POLYGON(</span><span class="si">{point_list}</span><span class="s2">))</span>
|
||
<span class="s2">"""</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>The query base contains format specifiers for <code class="docutils literal notranslate"><span class="pre">columns</span></code> and <code class="docutils literal notranslate"><span class="pre">point_list</span></code>.</p>
|
||
<p>We’ll use <code class="docutils literal notranslate"><span class="pre">format</span></code> to fill in these values.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">query4</span> <span class="o">=</span> <span class="n">query4_base</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">columns</span><span class="p">,</span>
|
||
<span class="n">point_list</span><span class="o">=</span><span class="n">point_list</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">query4</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>SELECT
|
||
TOP 10
|
||
source_id, ra, dec, pmra, pmdec
|
||
FROM gaiadr2.gaia_source
|
||
WHERE parallax < 1
|
||
AND bp_rp BETWEEN -0.75 AND 2
|
||
AND 1 = CONTAINS(POINT(ra, dec),
|
||
POLYGON(146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619))
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>As always, we should take a minute to proof-read the query before we launch it.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">job</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">launch_job_async</span><span class="p">(</span><span class="n">query4</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">job</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>INFO: Query finished. [astroquery.utils.tap.core]
|
||
<Table length=10>
|
||
name dtype unit description
|
||
--------- ------- -------- ------------------------------------------------------------------
|
||
source_id int64 Unique source identifier (unique within a particular Data Release)
|
||
ra float64 deg Right ascension
|
||
dec float64 deg Declination
|
||
pmra float64 mas / yr Proper motion in right ascension direction
|
||
pmdec float64 mas / yr Proper motion in declination direction
|
||
Jobid: 1615815873808O
|
||
Phase: COMPLETED
|
||
Owner: None
|
||
Output file: async_20210315094433.vot
|
||
Results: None
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Here are the results.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">results</span> <span class="o">=</span> <span class="n">job</span><span class="o">.</span><span class="n">get_results</span><span class="p">()</span>
|
||
<span class="n">results</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_html"><i>Table length=10</i>
|
||
<table id="table139807251332016" class="table-striped table-bordered table-condensed">
|
||
<thead><tr><th>source_id</th><th>ra</th><th>dec</th><th>pmra</th><th>pmdec</th></tr></thead>
|
||
<thead><tr><th></th><th>deg</th><th>deg</th><th>mas / yr</th><th>mas / yr</th></tr></thead>
|
||
<thead><tr><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>
|
||
<tr><td>637987125186749568</td><td>142.48301935991023</td><td>21.75771616932985</td><td>-2.5168384683875766</td><td>2.941813096629439</td></tr>
|
||
<tr><td>638285195917112960</td><td>142.25452941346344</td><td>22.476168171141378</td><td>2.6627020143457996</td><td>-12.165984395577347</td></tr>
|
||
<tr><td>638073505568978688</td><td>142.64528557468074</td><td>22.16693224953078</td><td>18.30674739454163</td><td>-7.950659620550862</td></tr>
|
||
<tr><td>638086386175786752</td><td>142.57739430926034</td><td>22.22791951401365</td><td>0.9877856720147953</td><td>-2.584105480335548</td></tr>
|
||
<tr><td>638049655615392384</td><td>142.58913564478618</td><td>22.110783166677418</td><td>0.24443878227817095</td><td>-4.941079187010136</td></tr>
|
||
<tr><td>638267565075964032</td><td>141.81762228999614</td><td>22.375696125322275</td><td>-3.413174589660796</td><td>1.8838892877285924</td></tr>
|
||
<tr><td>638028902333511168</td><td>143.18339801317677</td><td>22.2512465812369</td><td>7.848511762712128</td><td>-21.391145547787154</td></tr>
|
||
<tr><td>638085767700610432</td><td>142.9347319464589</td><td>22.46244080823965</td><td>-3.6585960944321476</td><td>-12.486419770278376</td></tr>
|
||
<tr><td>638299863230178304</td><td>142.26769745823267</td><td>22.640183776884836</td><td>-1.8168370892218297</td><td>1.0537342990941316</td></tr>
|
||
<tr><td>637973067758974208</td><td>142.89551292869012</td><td>21.612824100339875</td><td>-8.645166256559063</td><td>-44.41164172204947</td></tr>
|
||
</table></div></div>
|
||
</div>
|
||
<p>Finally, we can remove <code class="docutils literal notranslate"><span class="pre">TOP</span> <span class="pre">10</span></code> run the query again.</p>
|
||
<p>The result is bigger than our previous queries, so it will take a little longer.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">query5_base</span> <span class="o">=</span> <span class="s2">"""SELECT</span>
|
||
<span class="si">{columns}</span><span class="s2"></span>
|
||
<span class="s2">FROM gaiadr2.gaia_source</span>
|
||
<span class="s2">WHERE parallax < 1</span>
|
||
<span class="s2"> AND bp_rp BETWEEN -0.75 AND 2 </span>
|
||
<span class="s2"> AND 1 = CONTAINS(POINT(ra, dec), </span>
|
||
<span class="s2"> POLYGON(</span><span class="si">{point_list}</span><span class="s2">))</span>
|
||
<span class="s2">"""</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">query5</span> <span class="o">=</span> <span class="n">query5_base</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">columns</span><span class="p">,</span>
|
||
<span class="n">point_list</span><span class="o">=</span><span class="n">point_list</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">query5</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>SELECT
|
||
source_id, ra, dec, pmra, pmdec
|
||
FROM gaiadr2.gaia_source
|
||
WHERE parallax < 1
|
||
AND bp_rp BETWEEN -0.75 AND 2
|
||
AND 1 = CONTAINS(POINT(ra, dec),
|
||
POLYGON(146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619))
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">job</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">launch_job_async</span><span class="p">(</span><span class="n">query5</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">job</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>INFO: Query finished. [astroquery.utils.tap.core]
|
||
<Table length=140339>
|
||
name dtype unit description
|
||
--------- ------- -------- ------------------------------------------------------------------
|
||
source_id int64 Unique source identifier (unique within a particular Data Release)
|
||
ra float64 deg Right ascension
|
||
dec float64 deg Declination
|
||
pmra float64 mas / yr Proper motion in right ascension direction
|
||
pmdec float64 mas / yr Proper motion in declination direction
|
||
Jobid: 1615815886707O
|
||
Phase: COMPLETED
|
||
Owner: None
|
||
Output file: async_20210315094446.vot
|
||
Results: None
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">results</span> <span class="o">=</span> <span class="n">job</span><span class="o">.</span><span class="n">get_results</span><span class="p">()</span>
|
||
<span class="nb">len</span><span class="p">(</span><span class="n">results</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>140339
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>There are more than 100,000 stars in this polygon, but that’s a manageable size to work with.</p>
|
||
</div>
|
||
<div class="section" id="saving-results">
|
||
<h2>Saving results<a class="headerlink" href="#saving-results" title="Permalink to this headline">¶</a></h2>
|
||
<p>This is the set of stars we’ll work with in the next step. But since we have a substantial dataset now, this is a good time to save it.</p>
|
||
<p>Storing the data in a file means we can shut down this notebook and pick up where we left off without running the previous query again.</p>
|
||
<p>Astropy <code class="docutils literal notranslate"><span class="pre">Table</span></code> objects provide <code class="docutils literal notranslate"><span class="pre">write</span></code>, which writes the table to disk.</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">filename</span> <span class="o">=</span> <span class="s1">'gd1_results.fits'</span>
|
||
<span class="n">results</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>Because the filename ends with <code class="docutils literal notranslate"><span class="pre">fits</span></code>, the table is written in the <a class="reference external" href="https://en.wikipedia.org/wiki/FITS">FITS format</a>, which preserves the metadata associated with the table.</p>
|
||
<p>If the file already exists, the <code class="docutils literal notranslate"><span class="pre">overwrite</span></code> argument causes it to be overwritten.</p>
|
||
<p>We can use <code class="docutils literal notranslate"><span class="pre">getsize</span></code> to confirm that the file exists and check the size:</p>
|
||
<div class="cell docutils container">
|
||
<div class="cell_input docutils container">
|
||
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">getsize</span>
|
||
|
||
<span class="n">MB</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span>
|
||
<span class="n">getsize</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="o">/</span> <span class="n">MB</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="cell_output docutils container">
|
||
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>5.36407470703125
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="summary">
|
||
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
|
||
<p>In this notebook, we composed more complex queries to select stars within a polygonal region of the sky. Then we downloaded the results and saved them in a FITS file.</p>
|
||
<p>In the next notebook, we’ll reload the data from this file and replicate the next step in the analysis, using proper motion to identify stars likely to be in GD-1.</p>
|
||
</div>
|
||
<div class="section" id="best-practices">
|
||
<h2>Best practices<a class="headerlink" href="#best-practices" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>For measurements with units, use <code class="docutils literal notranslate"><span class="pre">Quantity</span></code> objects that represent units explicitly and check for errors.</p></li>
|
||
<li><p>Use the <code class="docutils literal notranslate"><span class="pre">format</span></code> function to compose queries; code written this way is easier to read and less error-prone.</p></li>
|
||
<li><p>Develop queries incrementally: start with something simple, test it, and add a little bit at a time.</p></li>
|
||
<li><p>Once you have a query working, save the data in a local file. If you shut down the notebook and come back to it later, you can reload the file; you don’t have to run the query again.</p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<script type="text/x-thebe-config">
|
||
{
|
||
requestKernel: true,
|
||
binderOptions: {
|
||
repo: "binder-examples/jupyter-stacks-datascience",
|
||
ref: "master",
|
||
},
|
||
codeMirrorConfig: {
|
||
theme: "abcdef",
|
||
mode: "python"
|
||
},
|
||
kernelOptions: {
|
||
kernelName: "python3",
|
||
path: "./."
|
||
},
|
||
predefinedOutput: true
|
||
}
|
||
</script>
|
||
<script>kernelName = 'python3'</script>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class='prev-next-bottom'>
|
||
|
||
<a class='left-prev' id="prev-link" href="01_query.html" title="previous page">1. Queries</a>
|
||
<a class='right-next' id="next-link" href="03_motion.html" title="next page">3. Proper Motion</a>
|
||
|
||
</div>
|
||
<footer class="footer mt-5 mt-md-0">
|
||
<div class="container">
|
||
<p>
|
||
|
||
By Allen B. Downey<br/>
|
||
|
||
© Copyright 2020.<br/>
|
||
</p>
|
||
</div>
|
||
</footer>
|
||
</main>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<script src="_static/js/index.30270b6e4c972e43c488.js"></script>
|
||
|
||
|
||
|
||
</body>
|
||
</html> |