Update documentation

This commit is contained in:
Allen Downey
2021-03-18 08:34:28 -04:00
parent 2f2d0fe7ee
commit 1683afba03
19 changed files with 421 additions and 9505 deletions

View File

@@ -129,7 +129,7 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="07_plot.html">
Visualization
7. Visualization
</a>
</li>
</ul>
@@ -243,6 +243,11 @@
Outline
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#installing-libraries">
Installing libraries
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#reload-the-data">
Reload the data
@@ -327,6 +332,24 @@ Well also see how to write the results to a CSV file.</p>
<li><p>Save data in CSV format.</p></li>
</ul>
</div>
<div class="section" id="installing-libraries">
<h2>Installing libraries<a class="headerlink" href="#installing-libraries" title="Permalink to this headline"></a></h2>
<p>If you are running this notebook on Colab, you can run the following cell to install the libraries well use.</p>
<p>If you are running this notebook on your own computer, you might have to install these libraries yourself. See the instructions in the preface.</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"># If we&#39;re running on Colab, install libraries</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">IN_COLAB</span> <span class="o">=</span> <span class="s1">&#39;google.colab&#39;</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">modules</span>
<span class="k">if</span> <span class="n">IN_COLAB</span><span class="p">:</span>
<span class="o">!</span>pip install astroquery astro-gala wget
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="reload-the-data">
<h2>Reload the data<a class="headerlink" href="#reload-the-data" title="Permalink to this headline"></a></h2>
<p>The following cells download the data from the previous lesson, if necessary, and load it into a Pandas <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>.</p>
@@ -442,9 +465,6 @@ Well also see how to write the results to a CSV file.</p>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_15_0.png" src="_images/04_select_15_0.png" />
</div>
</div>
<p>Now well make the same plot using proper motions in the ICRS frame, which are stored in columns <code class="docutils literal notranslate"><span class="pre">pmra</span></code> and <code class="docutils literal notranslate"><span class="pre">pmdec</span></code>.</p>
<div class="cell docutils container">
@@ -465,9 +485,6 @@ Well also see how to write the results to a CSV file.</p>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_17_0.png" src="_images/04_select_17_0.png" />
</div>
</div>
<p>The proper motions of the selected stars are more spread out in this frame, which is why it was preferable to do the selection in the GD-1 frame.</p>
<p>But now we can define a polygon that encloses the proper motions of these stars in ICRS, and use that polygon as a selection criterion in an ADQL query.</p>
@@ -485,11 +502,6 @@ Well also see how to write the results to a CSV file.</p>
</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>(1049, 2)
</pre></div>
</div>
</div>
</div>
<p>NOTE: If you are using an older version of Pandas, you might not have <code class="docutils literal notranslate"><span class="pre">to_numpy()</span></code>; you can use <code class="docutils literal notranslate"><span class="pre">values</span></code> instead, like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">points</span> <span class="o">=</span> <span class="n">selected_df</span><span class="p">[[</span><span class="s1">&#39;pmra&#39;</span><span class="p">,</span><span class="s1">&#39;pmdec&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">values</span>
@@ -506,11 +518,6 @@ Well also see how to write the results to a CSV file.</p>
</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>&lt;scipy.spatial.qhull.ConvexHull at 0x7fd95de628b0&gt;
</pre></div>
</div>
</div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">hull.vertices</span></code> contains the indices of the points that fall on the perimeter of the hull.</p>
<div class="cell docutils container">
@@ -519,12 +526,6 @@ Well also see how to write the results to a CSV file.</p>
</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>array([ 692, 873, 141, 303, 42, 622, 45, 83, 127, 182, 1006,
971, 967, 1001, 969, 940], dtype=int32)
</pre></div>
</div>
</div>
</div>
<p>We can use them as an index into the original array to select the corresponding rows.</p>
<div class="cell docutils container">
@@ -534,26 +535,6 @@ Well also see how to write the results to a CSV file.</p>
</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>array([[ -4.05037121, -14.75623261],
[ -3.41981085, -14.72365546],
[ -3.03521988, -14.44357135],
[ -2.26847919, -13.7140236 ],
[ -2.61172203, -13.24797471],
[ -2.73471401, -13.09054471],
[ -3.19923146, -12.5942653 ],
[ -3.34082546, -12.47611926],
[ -5.67489413, -11.16083338],
[ -5.95159272, -11.10547884],
[ -6.42394023, -11.05981295],
[ -7.09631023, -11.95187806],
[ -7.30641519, -12.24559977],
[ -7.04016696, -12.88580702],
[ -6.00347705, -13.75912098],
[ -4.42442296, -14.74641176]])
</pre></div>
</div>
</div>
</div>
<p>To plot the resulting polygon, we have to pull out the x and y coordinates.</p>
<div class="cell docutils container">
@@ -585,9 +566,6 @@ Well also see how to write the results to a CSV file.</p>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_30_0.png" src="_images/04_select_30_0.png" />
</div>
</div>
<p>So <code class="docutils literal notranslate"><span class="pre">pm_vertices</span></code> represents the polygon we want to select.
The next step is to use it as part of an ADQL query.</p>
@@ -672,11 +650,6 @@ Heres the function from Lesson 2 we used to do that.</p>
</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>&#39;135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862&#39;
</pre></div>
</div>
</div>
</div>
<p>Here are the columns we want to select.</p>
<div class="cell docutils container">
@@ -695,17 +668,6 @@ Heres the function from Lesson 2 we used to do that.</p>
</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 &lt; 1
AND bp_rp BETWEEN -0.75 AND 2
AND 1 = CONTAINS(POINT(ra, dec),
POLYGON(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))
</pre></div>
</div>
</div>
</div>
<p>But dont try to run that query.
Because it selects a larger region, there are too many stars to handle in a single query.
@@ -725,11 +687,6 @@ Using <code class="docutils literal notranslate"><span class="pre">flatten</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>&#39;[ -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176]&#39;
</pre></div>
</div>
</div>
</div>
<p>We just have to remove the brackets.</p>
<div class="cell docutils container">
@@ -739,29 +696,13 @@ Using <code class="docutils literal notranslate"><span class="pre">flatten</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>&#39; -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176&#39;
</pre></div>
</div>
</div>
</div>
<div class="section" id="exercise">
<h3>Exercise<a class="headerlink" href="#exercise" title="Permalink to this headline"></a></h3>
<p>Define <code class="docutils literal notranslate"><span class="pre">query6_base</span></code>, starting with <code class="docutils literal notranslate"><span class="pre">query5_base</span></code> and adding a new clause to select stars whose coordinates of proper motion, <code class="docutils literal notranslate"><span class="pre">pmra</span></code> and <code class="docutils literal notranslate"><span class="pre">pmdec</span></code>, fall within the polygon defined by <code class="docutils literal notranslate"><span class="pre">pm_point_list</span></code>.</p>
<div class="cell tag_hide-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">query6_base</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;SELECT </span>
<span class="si">{columns}</span><span class="s2"></span>
<span class="s2">FROM gaiadr2.gaia_source</span>
<span class="s2">WHERE parallax &lt; 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"> AND 1 = CONTAINS(POINT(pmra, pmdec),</span>
<span class="s2"> POLYGON(</span><span class="si">{pm_point_list}</span><span class="s2">))</span>
<span class="s2">&quot;&quot;&quot;</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Solution goes here</span>
</pre></div>
</div>
</div>
@@ -772,25 +713,7 @@ Using <code class="docutils literal notranslate"><span class="pre">flatten</span
<p>Use <code class="docutils literal notranslate"><span class="pre">format</span></code> to format <code class="docutils literal notranslate"><span class="pre">query6_base</span></code> and define <code class="docutils literal notranslate"><span class="pre">query6</span></code>, filling in the values of <code class="docutils literal notranslate"><span class="pre">columns</span></code>, <code class="docutils literal notranslate"><span class="pre">point_list</span></code>, and <code class="docutils literal notranslate"><span class="pre">pm_point_list</span></code>.</p>
<div class="cell tag_hide-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">query6</span> <span class="o">=</span> <span class="n">query6_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="n">pm_point_list</span><span class="o">=</span><span class="n">pm_point_list</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">query6</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 &lt; 1
AND bp_rp BETWEEN -0.75 AND 2
AND 1 = CONTAINS(POINT(ra, dec),
POLYGON(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))
AND 1 = CONTAINS(POINT(pmra, pmdec),
POLYGON( -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176))
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Solution goes here</span>
</pre></div>
</div>
</div>
@@ -805,34 +728,6 @@ WHERE parallax &lt; 1
</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
INFO: Query finished. [astroquery.utils.tap.core]
&lt;Table length=7345&gt;
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: 1615933496807O
Phase: COMPLETED
Owner: None
Output file: async_20210316182456.vot
Results: None
</pre></div>
</div>
</div>
</div>
<p>And get the results.</p>
<div class="cell docutils container">
@@ -842,11 +737,6 @@ Results: None
</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>7345
</pre></div>
</div>
</div>
</div>
<p>We call the results <code class="docutils literal notranslate"><span class="pre">candidate_table</span></code> because it contains stars that are good candidates for GD-1.</p>
<p>For the next lesson, well need <code class="docutils literal notranslate"><span class="pre">point_list</span></code> and <code class="docutils literal notranslate"><span class="pre">pm_point_list</span></code> again, so we should save them in a file.
@@ -861,12 +751,6 @@ To make one, well start with a dictionary:</p>
</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>{&#39;point_list&#39;: &#39;135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862&#39;,
&#39;pm_point_list&#39;: &#39; -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176&#39;}
</pre></div>
</div>
</div>
</div>
<p>And use it to initialize a <code class="docutils literal notranslate"><span class="pre">Series.</span></code></p>
<div class="cell docutils container">
@@ -876,13 +760,6 @@ To make one, well start with a dictionary:</p>
</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>point_list 135.306, 8.39862, 126.51, 13.4449, 163.017, 54...
pm_point_list -4.05037121,-14.75623261, -3.41981085,-14.723...
dtype: object
</pre></div>
</div>
</div>
</div>
<p>Now we can save it in the usual way.</p>
<div class="cell docutils container">
@@ -909,9 +786,6 @@ dtype: object
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_67_0.png" src="_images/04_select_67_0.png" />
</div>
</div>
<p>Here we can see why it was useful to transform these coordinates. In ICRS, it is more difficult to identity the stars near the centerline of GD-1.</p>
<p>So lets transform the results back to the GD-1 frame.
@@ -969,9 +843,6 @@ Heres the code we used to transform the coordinates and make a Pandas <code c
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_73_0.png" src="_images/04_select_73_0.png" />
</div>
</div>
<p>Were starting to see GD-1 more clearly.
We can compare this figure with this panel from Figure 1 from the original paper:</p>