Update documentation

This commit is contained in:
Allen Downey
2021-03-17 11:26:14 -04:00
parent 638a2aaf93
commit 2f2d0fe7ee
37 changed files with 1260 additions and 1382 deletions

View File

@@ -119,12 +119,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">
@@ -984,7 +984,7 @@ Results: None
<div class="section" id="id1">
<h3>Exercise<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h3>
<p>Read <a class="reference external" href="https://gea.esac.esa.int/archive/documentation/GDR2/Gaia_archive/chap_datamodel/sec_dm_main_tables/ssec_dm_gaia_source.html">the documentation</a> of this table and choose a column that looks interesting to you. Add the column name to the query and run it again. What are the units of the column you selected? What is its data type?</p>
<div class="cell docutils container">
<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>
@@ -1091,7 +1091,7 @@ The modified query should fail, but notice that you dont get much useful debu
<li><p>While you are debugging, use <code class="docutils literal notranslate"><span class="pre">TOP</span></code> to limit the number of rows in the result. That will make each test run faster, which reduces your development time.</p></li>
<li><p>Launching test queries synchronously might make them start faster, too.</p></li>
</ul>
<div class="cell docutils container">
<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>

View File

@@ -119,12 +119,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">
@@ -1541,7 +1541,7 @@ Created TAP+ (v1.2.1) - Connection:
<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 dont 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 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>
@@ -1671,7 +1671,7 @@ These are the coordinates shown in the figure from the paper, above.</p>
<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 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>

View File

@@ -119,12 +119,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">

View File

@@ -57,7 +57,7 @@
<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="Joining Tables" href="05_join.html" />
<link rel="next" title="5. Joining Tables" href="05_join.html" />
<link rel="prev" title="3. Proper Motion" href="03_motion.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -119,12 +119,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">
@@ -352,7 +352,6 @@ Well also see how to write the results to a CSV file.</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">centerline_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;centerline_df&#39;</span><span class="p">)</span>
<span class="n">selected_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;selected_df&#39;</span><span class="p">)</span>
</pre></div>
@@ -508,7 +507,7 @@ Well also see how to write the results to a CSV file.</p>
</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 0x7f712e3b6dc0&gt;
<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>
@@ -776,8 +775,8 @@ Using <code class="docutils literal notranslate"><span class="pre">flatten</span
<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="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>
@@ -826,10 +825,10 @@ source_id int64 Unique source identifier (unique within a particular
dec float64 deg Declination
pmra float64 mas / yr Proper motion in right ascension direction
pmdec float64 mas / yr Proper motion in declination direction
Jobid: 1615824245107O
Jobid: 1615933496807O
Phase: COMPLETED
Owner: None
Output file: async_20210315120405.vot
Output file: async_20210316182456.vot
Results: None
</pre></div>
</div>
@@ -850,6 +849,50 @@ Results: None
</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.
There are several ways we could do that, but since we are already storing data in an HDF file, lets do the same with these variables.</p>
<p>Weve seen how to save a <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code> in an HDF file.
We can do the same thing with a Pandas <code class="docutils literal notranslate"><span class="pre">Series</span></code>.
To make one, well start with a dictionary:</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">d</span> <span class="o">=</span> <span class="nb">dict</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="n">d</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;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">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">point_series</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">Series</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="n">point_series</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>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">
<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">&#39;gd1_data.hdf&#39;</span>
<span class="n">point_series</span><span class="o">.</span><span class="n">to_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;point_series&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="section" id="plotting-one-more-time">
@@ -867,7 +910,7 @@ Results: None
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_62_0.png" src="_images/04_select_62_0.png" />
<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>
@@ -927,7 +970,7 @@ Heres the code we used to transform the coordinates and make a Pandas <code c
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/04_select_68_0.png" src="_images/04_select_68_0.png" />
<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.
@@ -985,7 +1028,7 @@ We can compare this figure with this panel from Figure 1 from the original paper
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="03_motion.html" title="previous page">3. Proper Motion</a>
<a class='right-next' id="next-link" href="05_join.html" title="next page">Joining Tables</a>
<a class='right-next' id="next-link" href="05_join.html" title="next page">5. Joining Tables</a>
</div>
<footer class="footer mt-5 mt-md-0">

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Joining Tables &#8212; Astronomical Data in Python</title>
<title>5. Joining Tables &#8212; Astronomical Data in Python</title>
<link rel="stylesheet" href="_static/css/index.d431a4ee1c1efae0e38bdfebc22debff.css">
@@ -57,7 +57,7 @@
<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="Photometry" href="06_photo.html" />
<link rel="next" title="6. Photometry" href="06_photo.html" />
<link rel="prev" title="4. Transformation and Selection" href="04_select.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -119,12 +119,12 @@
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">
@@ -267,6 +267,11 @@
<a class="reference internal nav-link" href="#adding-the-best-neighbor-table">
Adding the best neighbor table
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#adding-the-pan-starrs-table">
Adding the Pan-STARRS table
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#exercise">
@@ -302,19 +307,19 @@
Saving the DataFrame
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#csv">
CSV
</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-practice">
Best practice
<a class="reference internal nav-link" href="#csv">
CSV
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#best-practices">
Best practices
</a>
</li>
</ul>
@@ -329,7 +334,7 @@
<div>
<div class="section" id="joining-tables">
<h1>Joining Tables<a class="headerlink" href="#joining-tables" title="Permalink to this headline"></a></h1>
<h1>5. Joining Tables<a class="headerlink" href="#joining-tables" title="Permalink to this headline"></a></h1>
<p>This is the fifth in a series of notebooks related to astronomy data.</p>
<p>As a continuing example, we will replicate part of the analysis in a recent paper, “<a class="reference external" href="https://arxiv.org/abs/1805.00425">Off the beaten path: Gaia reveals GD-1 stars outside of the main stream</a>” by Adrian M. Price-Whelan and Ana Bonaca.</p>
<p>Picking up where we left off, the next step in the analysis is to select candidate stars based on photometry data.
@@ -380,16 +385,38 @@ We use this variable to select stars with <code class="docutils literal notransl
Heres the metadata for <code class="docutils literal notranslate"><span class="pre">panstarrs1_best_neighbour</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">meta</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">load_table</span><span class="p">(</span><span class="s1">&#39;gaiadr2.panstarrs1_best_neighbour&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">meta</span><span class="p">)</span>
<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">meta</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">load_table</span><span class="p">(</span><span class="s1">&#39;gaiadr2.panstarrs1_best_neighbour&#39;</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>Retrieving table &#39;gaiadr2.panstarrs1_best_neighbour&#39;
<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
Retrieving table &#39;gaiadr2.panstarrs1_best_neighbour&#39;
Parsing table &#39;gaiadr2.panstarrs1_best_neighbour&#39;...
Done.
TAP Table name: gaiadr2.gaiadr2.panstarrs1_best_neighbour
</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="nb">print</span><span class="p">(</span><span class="n">meta</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>TAP Table name: gaiadr2.gaiadr2.panstarrs1_best_neighbour
Description: Pan-STARRS1 BestNeighbour table lists each matched Gaia object with its
best neighbour in the external catalogue.
There are 1327157 objects in the filtered version of Pan-STARRS1 used
@@ -442,9 +469,7 @@ gaia_astrometric_params
</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="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_async</span><span class="p">(</span><span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">)</span>
<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">query</span><span class="o">=</span><span class="n">query</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -463,7 +488,7 @@ gaia_astrometric_params
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=5</i>
<table id="table140056651686048" class="table-striped table-bordered table-condensed">
<table id="table140104392580448" class="table-striped table-bordered table-condensed">
<thead><tr><th>source_id</th><th>number_of_neighbours</th><th>number_of_mates</th><th>original_ext_source_id</th></tr></thead>
<thead><tr><th>int64</th><th>int32</th><th>int16</th><th>int64</th></tr></thead>
<tr><td>6745938972433480704</td><td>1</td><td>0</td><td>69742925668851205</td></tr>
@@ -480,7 +505,6 @@ gaia_astrometric_params
<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">meta</span> <span class="o">=</span> <span class="n">Gaia</span><span class="o">.</span><span class="n">load_table</span><span class="p">(</span><span class="s1">&#39;gaiadr2.panstarrs1_original_valid&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">meta</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -488,7 +512,18 @@ gaia_astrometric_params
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Retrieving table &#39;gaiadr2.panstarrs1_original_valid&#39;
Parsing table &#39;gaiadr2.panstarrs1_original_valid&#39;...
Done.
TAP Table name: gaiadr2.gaiadr2.panstarrs1_original_valid
</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="nb">print</span><span class="p">(</span><span class="n">meta</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>TAP Table name: gaiadr2.gaiadr2.panstarrs1_original_valid
Description: The Panoramic Survey Telescope and Rapid Response System (Pan-STARRS) is
a system for wide-field astronomical imaging developed and operated by
the Institute for Astronomy at the University of Hawaii. Pan-STARRS1
@@ -638,7 +673,7 @@ quality_flag
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=5</i>
<table id="table140056430617648" class="table-striped table-bordered table-condensed">
<table id="table140104844641184" class="table-striped table-bordered table-condensed">
<thead><tr><th>obj_id</th><th>g_mean_psf_mag</th><th>i_mean_psf_mag</th></tr></thead>
<thead><tr><th></th><th></th><th>mag</th></tr></thead>
<thead><tr><th>int64</th><th>float64</th><th>float64</th></tr></thead>
@@ -700,16 +735,20 @@ As a starting place, lets go all the way back to the cone search from Lesson
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=5</i>
<table id="table140056430283888" 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>3322773965056065536</td><td>88.78178020183375</td><td>7.334936530583141</td><td>0.2980633722108194</td><td>-2.5057036964736907</td></tr>
<tr><td>3322773758899157120</td><td>88.83227057144585</td><td>7.325577341429926</td><td>--</td><td>--</td></tr>
<tr><td>3322774068134271104</td><td>88.8206092188033</td><td>7.353158142762173</td><td>-1.1065462654445488</td><td>-1.5260889445858044</td></tr>
<tr><td>3322773930696320512</td><td>88.80843339290348</td><td>7.334853162299928</td><td>2.6074384482375215</td><td>-0.9292104395445717</td></tr>
<tr><td>3322774377374425728</td><td>88.86806108182265</td><td>7.371287731275939</td><td>3.9555477866915383</td><td>-3.8676624830902435</td></tr>
<div class="output text_html"><i>Table length=10</i>
<table id="table140104380877264" 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>
<p>Now we can start adding features.
@@ -770,7 +809,7 @@ WHERE 1=CONTAINS(
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=594</i>
<table id="table140056701852160" class="table-striped table-bordered table-condensed">
<table id="table140104380909264" 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>
@@ -826,7 +865,7 @@ The join operation requires two clauses:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">USING</span><span class="p">(</span><span class="n">source_id</span><span class="p">)</span>
</pre></div>
</div>
<p>Now that theres more than one table involved, we cant use simple column names any more; we have to use <em>qualified</em> column names.
<p>Now that theres more than one table involved, we cant use simple column names any more; we have to use <strong>qualified column names</strong>.
In other words, we have to specify which table each column is in.
Heres the complete query, including the columns we want from the Gaia and best neighbor tables.</p>
<div class="cell docutils container">
@@ -848,7 +887,7 @@ Heres the complete query, including the columns we want from the Gaia and bes
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>SELECT
gaia.source_id, gaia.ra, gaia.dec, gaia.pmra, gaia.pmdec
gaia.source_id, gaia.ra, gaia.dec, gaia.pmra, gaia.pmdec, best.best_neighbour_multiplicity, best.number_of_mates
FROM gaiadr2.gaia_source AS gaia
JOIN gaiadr2.panstarrs1_best_neighbour AS best
ON gaia.source_id = best.source_id
@@ -880,30 +919,30 @@ WHERE 1=CONTAINS(
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=490</i>
<table id="table140056430457136" 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>3322773965056065536</td><td>88.78178020183375</td><td>7.334936530583141</td><td>0.2980633722108194</td><td>-2.5057036964736907</td></tr>
<tr><td>3322774068134271104</td><td>88.8206092188033</td><td>7.353158142762173</td><td>-1.1065462654445488</td><td>-1.5260889445858044</td></tr>
<tr><td>3322773930696320512</td><td>88.80843339290348</td><td>7.334853162299928</td><td>2.6074384482375215</td><td>-0.9292104395445717</td></tr>
<tr><td>3322774377374425728</td><td>88.86806108182265</td><td>7.371287731275939</td><td>3.9555477866915383</td><td>-3.8676624830902435</td></tr>
<tr><td>3322773724537891456</td><td>88.81308602813434</td><td>7.32488574492059</td><td>51.34995462741039</td><td>-33.078133430952086</td></tr>
<tr><td>3322773724537891328</td><td>88.81570329208743</td><td>7.3223019772324855</td><td>1.9389988498951845</td><td>0.3110526931576576</td></tr>
<tr><td>3322773930696321792</td><td>88.8050736770331</td><td>7.332371472206583</td><td>2.264014834476311</td><td>1.0772755505138008</td></tr>
<tr><td>3322773724537890944</td><td>88.81241651540533</td><td>7.327864052479726</td><td>-0.36003627434304625</td><td>-6.393939291541333</td></tr>
<tr><td>3322773930696322176</td><td>88.80128682574824</td><td>7.334292036448643</td><td>--</td><td>--</td></tr>
<tr><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td></tr>
<tr><td>3322962359501481088</td><td>88.85037722908271</td><td>7.402162717053584</td><td>2.058216493648542</td><td>-2.249255322558584</td></tr>
<tr><td>3322962393861228544</td><td>88.82108234976155</td><td>7.4044425496203</td><td>-0.916760881643629</td><td>-1.1113319053861441</td></tr>
<tr><td>3322955831151254912</td><td>88.74620347799508</td><td>7.342728619145855</td><td>0.1559833902071379</td><td>-1.750598455959734</td></tr>
<tr><td>3322962118983356032</td><td>88.76109637722949</td><td>7.380564308268047</td><td>--</td><td>--</td></tr>
<tr><td>3322963527732585984</td><td>88.78813701704823</td><td>7.456696889759524</td><td>1.1363354614104264</td><td>-2.46251296961979</td></tr>
<tr><td>3322961775385969024</td><td>88.79723215862369</td><td>7.359756552906535</td><td>2.121021366548921</td><td>-6.605711792572964</td></tr>
<tr><td>3322962084625312512</td><td>88.78286756313868</td><td>7.384598632215225</td><td>-0.09350717810996487</td><td>1.3495903680571226</td></tr>
<tr><td>3322962939322692608</td><td>88.73289357818679</td><td>7.407688975612043</td><td>-0.11002934783569704</td><td>1.002126813991455</td></tr>
<tr><td>3322963459013111808</td><td>88.80348931842845</td><td>7.438699901204871</td><td>0.800833828337078</td><td>-3.3780655466364626</td></tr>
<tr><td>3322962015904143872</td><td>88.74740822271643</td><td>7.387057037713974</td><td>-0.7201178533250112</td><td>0.5565841272341593</td></tr>
<table id="table140104380908352" 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><th>best_neighbour_multiplicity</th><th>number_of_mates</th></tr></thead>
<thead><tr><th></th><th>deg</th><th>deg</th><th>mas / yr</th><th>mas / yr</th><th></th><th></th></tr></thead>
<thead><tr><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>int16</th><th>int16</th></tr></thead>
<tr><td>3322773965056065536</td><td>88.78178020183375</td><td>7.334936530583141</td><td>0.2980633722108194</td><td>-2.5057036964736907</td><td>1</td><td>0</td></tr>
<tr><td>3322774068134271104</td><td>88.8206092188033</td><td>7.353158142762173</td><td>-1.1065462654445488</td><td>-1.5260889445858044</td><td>1</td><td>0</td></tr>
<tr><td>3322773930696320512</td><td>88.80843339290348</td><td>7.334853162299928</td><td>2.6074384482375215</td><td>-0.9292104395445717</td><td>1</td><td>0</td></tr>
<tr><td>3322774377374425728</td><td>88.86806108182265</td><td>7.371287731275939</td><td>3.9555477866915383</td><td>-3.8676624830902435</td><td>1</td><td>0</td></tr>
<tr><td>3322773724537891456</td><td>88.81308602813434</td><td>7.32488574492059</td><td>51.34995462741039</td><td>-33.078133430952086</td><td>1</td><td>0</td></tr>
<tr><td>3322773724537891328</td><td>88.81570329208743</td><td>7.3223019772324855</td><td>1.9389988498951845</td><td>0.3110526931576576</td><td>1</td><td>0</td></tr>
<tr><td>3322773930696321792</td><td>88.8050736770331</td><td>7.332371472206583</td><td>2.264014834476311</td><td>1.0772755505138008</td><td>1</td><td>0</td></tr>
<tr><td>3322773724537890944</td><td>88.81241651540533</td><td>7.327864052479726</td><td>-0.36003627434304625</td><td>-6.393939291541333</td><td>1</td><td>0</td></tr>
<tr><td>3322773930696322176</td><td>88.80128682574824</td><td>7.334292036448643</td><td>--</td><td>--</td><td>1</td><td>0</td></tr>
<tr><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td></tr>
<tr><td>3322962359501481088</td><td>88.85037722908271</td><td>7.402162717053584</td><td>2.058216493648542</td><td>-2.249255322558584</td><td>1</td><td>0</td></tr>
<tr><td>3322962393861228544</td><td>88.82108234976155</td><td>7.4044425496203</td><td>-0.916760881643629</td><td>-1.1113319053861441</td><td>1</td><td>0</td></tr>
<tr><td>3322955831151254912</td><td>88.74620347799508</td><td>7.342728619145855</td><td>0.1559833902071379</td><td>-1.750598455959734</td><td>1</td><td>0</td></tr>
<tr><td>3322962118983356032</td><td>88.76109637722949</td><td>7.380564308268047</td><td>--</td><td>--</td><td>1</td><td>0</td></tr>
<tr><td>3322963527732585984</td><td>88.78813701704823</td><td>7.456696889759524</td><td>1.1363354614104264</td><td>-2.46251296961979</td><td>1</td><td>0</td></tr>
<tr><td>3322961775385969024</td><td>88.79723215862369</td><td>7.359756552906535</td><td>2.121021366548921</td><td>-6.605711792572964</td><td>1</td><td>0</td></tr>
<tr><td>3322962084625312512</td><td>88.78286756313868</td><td>7.384598632215225</td><td>-0.09350717810996487</td><td>1.3495903680571226</td><td>1</td><td>0</td></tr>
<tr><td>3322962939322692608</td><td>88.73289357818679</td><td>7.407688975612043</td><td>-0.11002934783569704</td><td>1.002126813991455</td><td>1</td><td>0</td></tr>
<tr><td>3322963459013111808</td><td>88.80348931842845</td><td>7.438699901204871</td><td>0.800833828337078</td><td>-3.3780655466364626</td><td>1</td><td>0</td></tr>
<tr><td>3322962015904143872</td><td>88.74740822271643</td><td>7.387057037713974</td><td>-0.7201178533250112</td><td>0.5565841272341593</td><td>1</td><td>0</td></tr>
</table></div></div>
</div>
<p>Notice that this result has fewer rows than the previous result.
@@ -911,12 +950,15 @@ Thats because there are sources in the Gaia table with no corresponding sourc
<p>By default, the result of the join only includes rows where the same <code class="docutils literal notranslate"><span class="pre">source_id</span></code> appears in both tables.
This default is called an “inner” join because the results include only the intersection of the two tables.
<a class="reference external" href="https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/">You can read about the other kinds of join here</a>.</p>
</div>
<div class="section" id="adding-the-pan-starrs-table">
<h2>Adding the Pan-STARRS table<a class="headerlink" href="#adding-the-pan-starrs-table" title="Permalink to this headline"></a></h2>
<div class="section" id="exercise">
<h3>Exercise<a class="headerlink" href="#exercise" title="Permalink to this headline"></a></h3>
<p>Now were ready to bring in the Pan-STARRS table. Starting with the previous query, add a second <code class="docutils literal notranslate"><span class="pre">JOIN</span></code> clause that joins with <code class="docutils literal notranslate"><span class="pre">gaiadr2.panstarrs1_original_valid</span></code>, gives it the abbreviated name <code class="docutils literal notranslate"><span class="pre">ps</span></code>, and matches <code class="docutils literal notranslate"><span class="pre">original_ext_source_id</span></code> from the best neighbor table with <code class="docutils literal notranslate"><span class="pre">obj_id</span></code> from the Pan-STARRS table.</p>
<p>Add <code class="docutils literal notranslate"><span class="pre">g_mean_psf_mag</span></code> and <code class="docutils literal notranslate"><span class="pre">i_mean_psf_mag</span></code> to the column list, and run the query.
The result should contain 490 rows and 9 columns.</p>
<div class="cell docutils container">
<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>
@@ -935,7 +977,7 @@ The result should contain 490 rows and 9 columns.</p>
</div>
</div>
</div>
<div class="cell docutils container">
<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>
@@ -947,8 +989,8 @@ The result should contain 490 rows and 9 columns.</p>
<span class="s1">&#39;best.best_neighbour_multiplicity&#39;</span><span class="p">,</span>
<span class="s1">&#39;best.number_of_mates&#39;</span><span class="p">,</span>
<span class="s1">&#39;ps.g_mean_psf_mag&#39;</span><span class="p">,</span>
<span class="s1">&#39;ps.i_mean_psf_mag&#39;</span><span class="p">,</span>
<span class="p">]</span>
<span class="s1">&#39;ps.i_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">columns</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">column_list</span><span class="p">)</span>
<span class="n">query</span> <span class="o">=</span> <span class="n">query_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>
@@ -971,7 +1013,7 @@ WHERE 1=CONTAINS(
</div>
</div>
</div>
<div class="cell docutils container">
<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>
@@ -985,7 +1027,7 @@ WHERE 1=CONTAINS(
</div>
</div>
</div>
<div class="cell docutils container">
<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>
@@ -996,7 +1038,7 @@ WHERE 1=CONTAINS(
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=490</i>
<table id="table140056700852112" class="table-striped table-bordered table-condensed">
<table id="table140104380910896" 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><th>best_neighbour_multiplicity</th><th>number_of_mates</th><th>g_mean_psf_mag</th><th>i_mean_psf_mag</th></tr></thead>
<thead><tr><th></th><th>deg</th><th>deg</th><th>mas / yr</th><th>mas / yr</th><th></th><th></th><th></th><th>mag</th></tr></thead>
<thead><tr><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>int16</th><th>int16</th><th>float64</th><th>float64</th></tr></thead>
@@ -1026,25 +1068,70 @@ WHERE 1=CONTAINS(
</div>
<div class="section" id="selecting-by-coordinates-and-proper-motion">
<h2>Selecting by coordinates and proper motion<a class="headerlink" href="#selecting-by-coordinates-and-proper-motion" title="Permalink to this headline"></a></h2>
<p>Now lets bring in the <code class="docutils literal notranslate"><span class="pre">WHERE</span></code> clause from the previous notebook, which selects sources based on <code class="docutils literal notranslate"><span class="pre">parallax</span></code>, <code class="docutils literal notranslate"><span class="pre">bp_rp</span></code>, sky coordinates, and proper motion.
Rather than rewrite the code we use to generate the query, we can start with a copy of the complete query:</p>
<p>Now lets bring in the <code class="docutils literal notranslate"><span class="pre">WHERE</span></code> clause from the previous lesson, which selects sources based on parallax, BP-RP color, sky coordinates, and proper motion.</p>
<p>Heres <code class="docutils literal notranslate"><span class="pre">query6_base</span></code> from 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">query6</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">SELECT </span>
<span class="s2">source_id, ra, dec, pmra, pmdec</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></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(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))</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( -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))</span>
<span class="s2"> POLYGON(</span><span class="si">{pm_point_list}</span><span class="s2">))</span>
<span class="s2">&quot;&quot;&quot;</span>
</pre></div>
</div>
</div>
</div>
<p>Lets reload the Pandas <code class="docutils literal notranslate"><span class="pre">Series</span></code> that contains <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 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">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">point_series</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;point_series&#39;</span><span class="p">)</span>
<span class="n">point_series</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>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 assemble the query.</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">&#39;source_id, ra, dec, pmra, pmdec&#39;</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_series</span><span class="p">[</span><span class="s1">&#39;point_list&#39;</span><span class="p">],</span>
<span class="n">pm_point_list</span><span class="o">=</span><span class="n">point_series</span><span class="p">[</span><span class="s1">&#39;pm_point_list&#39;</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))
</pre></div>
</div>
</div>
</div>
<p>Again, lets run it to make sure we are starting with a working query.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
@@ -1067,7 +1154,7 @@ Rather than rewrite the code we use to generate the query, we can start with a c
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=7345</i>
<table id="table140056430282592" class="table-striped table-bordered table-condensed">
<table id="table140104380909120" 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>
@@ -1096,10 +1183,10 @@ Rather than rewrite the code we use to generate the query, we can start with a c
<div class="section" id="id2">
<h3>Exercise<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h3>
<p>Create a new query base called <code class="docutils literal notranslate"><span class="pre">query7_base</span></code> that combines the <code class="docutils literal notranslate"><span class="pre">WHERE</span></code> clauses from the previous query with the <code class="docutils literal notranslate"><span class="pre">JOIN</span></code> clauses for the best neighbor and Pan-STARRS tables.
Format the query base using the <code class="docutils literal notranslate"><span class="pre">columns</span></code> from the previous query, and call the result <code class="docutils literal notranslate"><span class="pre">query7</span></code>.</p>
Format the query base using the column names in <code class="docutils literal notranslate"><span class="pre">column_list</span></code>, and call the result <code class="docutils literal notranslate"><span class="pre">query7</span></code>.</p>
<p>Hint: Make sure you use qualified column names everywhere!</p>
<p>Run your query and download the results. The table you get should have 3725 rows and 9 columns.</p>
<div class="cell docutils container">
<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>
@@ -1114,19 +1201,23 @@ Format the query base using the <code class="docutils literal notranslate"><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(gaia.ra, gaia.dec), </span>
<span class="s2"> POLYGON(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))</span>
<span class="s2"> POLYGON(</span><span class="si">{point_list}</span><span class="s2">))</span>
<span class="s2"> AND 1 = CONTAINS(POINT(gaia.pmra, gaia.pmdec),</span>
<span class="s2"> 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))</span>
<span class="s2"> POLYGON(</span><span class="si">{pm_point_list}</span><span class="s2">))</span>
<span class="s2">&quot;&quot;&quot;</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<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">query7</span> <span class="o">=</span> <span class="n">query7_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">columns</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">column_list</span><span class="p">)</span>
<span class="n">query7</span> <span class="o">=</span> <span class="n">query7_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_series</span><span class="p">[</span><span class="s1">&#39;point_list&#39;</span><span class="p">],</span>
<span class="n">pm_point_list</span><span class="o">=</span><span class="n">point_series</span><span class="p">[</span><span class="s1">&#39;pm_point_list&#39;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">query7</span><span class="p">)</span>
</pre></div>
</div>
@@ -1149,7 +1240,7 @@ WHERE parallax &lt; 1
</div>
</div>
</div>
<div class="cell docutils container">
<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>
@@ -1163,7 +1254,7 @@ WHERE parallax &lt; 1
</div>
</div>
</div>
<div class="cell docutils container">
<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>
@@ -1174,7 +1265,7 @@ WHERE parallax &lt; 1
</div>
<div class="cell_output docutils container">
<div class="output text_html"><i>Table length=3725</i>
<table id="table140056433090464" class="table-striped table-bordered table-condensed">
<table id="table140104308204640" 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><th>best_neighbour_multiplicity</th><th>number_of_mates</th><th>g_mean_psf_mag</th><th>i_mean_psf_mag</th></tr></thead>
<thead><tr><th></th><th>deg</th><th>deg</th><th>mas / yr</th><th>mas / yr</th><th></th><th></th><th></th><th>mag</th></tr></thead>
<thead><tr><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>int16</th><th>int16</th><th>float64</th><th>float64</th></tr></thead>
@@ -1294,6 +1385,7 @@ dtype: float64
</div>
<div class="section" id="transforming-coordinates">
<h2>Transforming coordinates<a class="headerlink" href="#transforming-coordinates" title="Permalink to this headline"></a></h2>
<p>Heres the function weve used to transform the results from ICRS to GD-1 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="kn">import</span> <span class="nn">astropy.units</span> <span class="k">as</span> <span class="nn">u</span>
@@ -1330,6 +1422,7 @@ dtype: float64
</div>
</div>
</div>
<p>Now can transform the result from the last query.</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">candidate_df</span> <span class="o">=</span> <span class="n">make_dataframe</span><span class="p">(</span><span class="n">results</span><span class="p">)</span>
@@ -1337,9 +1430,12 @@ dtype: float64
</div>
</div>
</div>
<p>And see how it looks.</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">x</span> <span class="o">=</span> <span class="n">candidate_df</span><span class="p">[</span><span class="s1">&#39;phi1&#39;</span><span class="p">]</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">candidate_df</span><span class="p">[</span><span class="s1">&#39;phi1&#39;</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">candidate_df</span><span class="p">[</span><span class="s1">&#39;phi2&#39;</span><span class="p">]</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;ko&#39;</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
@@ -1349,14 +1445,15 @@ dtype: float64
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/05_join_70_0.png" src="_images/05_join_70_0.png" />
<img alt="_images/05_join_78_0.png" src="_images/05_join_78_0.png" />
</div>
</div>
<p>The result is similar to what we saw in the previous lesson, except that have fewer stars now, because we did not find photometry data for all of the candidate sources.</p>
</div>
<div class="section" id="saving-the-dataframe">
<h2>Saving the DataFrame<a class="headerlink" href="#saving-the-dataframe" title="Permalink to this headline"></a></h2>
<p>Lets save this <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code> so we can pick up where we left off without running this query again.</p>
<p>The HDF file should already exist, so well add <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> to it.</p>
<p>Lets save this <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code> so we can pick up where we left off without running this query again.
The HDF file should already exist, so well add <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> to 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">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
@@ -1377,16 +1474,22 @@ dtype: float64
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>2.575897216796875
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>5.574869155883789
</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 used database <code class="docutils literal notranslate"><span class="pre">JOIN</span></code> operations to select photometry data for the stars weve identified as candidates to be in GD-1.</p>
<p>In the next notebook, well use this data for a second round of selection, identifying stars that have photometry data consistent with GD-1.</p>
<p>But before you go on, you might be interested in another file format, CSV.</p>
</div>
<div class="section" id="csv">
<h2>CSV<a class="headerlink" href="#csv" title="Permalink to this headline"></a></h2>
<p>Pandas can write a variety of other formats, <a class="reference external" href="https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html">which you can read about here</a>.</p>
<p>We wont cover all of them, but one other important one is <a class="reference external" href="https://en.wikipedia.org/wiki/Comma-separated_values">CSV</a>, which stands for “comma-separated values”.</p>
<p>Pandas can write a variety of other formats, <a class="reference external" href="https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html">which you can read about here</a>.
We wont cover all of them, but one other important one is <a class="reference external" href="https://en.wikipedia.org/wiki/Comma-separated_values">CSV</a>, which stands for “comma-separated values”.</p>
<p>CSV is a plain-text format that can be read and written by pretty much any tool that works with data. In that sense, it is the “least common denominator” of data formats.</p>
<p>However, it has an important limitation: some information about the data gets lost in translation, notably the data types. If you read a CSV file from someone else, you might need some additional information to make sure you are getting it right.</p>
<p>Also, CSV files tend to be big, and slow to read and write.</p>
@@ -1406,7 +1509,7 @@ dtype: float64
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>1.238297462463379
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.7606849670410156
</pre></div>
</div>
</div>
@@ -1430,11 +1533,11 @@ dtype: float64
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>,source_id,ra,dec,pmra,pmdec,phi1,phi2,pm_phi1,pm_phi2
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>,source_id,ra,dec,pmra,pmdec,best_neighbour_multiplicity,number_of_mates,g_mean_psf_mag,i_mean_psf_mag,phi1,phi2,pm_phi1,pm_phi2
0,635559124339440000,137.58671691646745,19.1965441084838,-3.770521900009566,-12.490481778113859,-59.63048941944402,-1.2164852515042963,-7.361362712597496,-0.592632882064492
0,635860218726658176,138.5187065217173,19.09233926905897,-5.941679495793577,-11.346409129876392,1,0,17.8978004455566,17.5174007415771,-59.247329893833296,-2.016078400820631,-7.527126084640531,1.7487794924176672
1,635860218726658176,138.5187065217173,19.09233926905897,-5.941679495793577,-11.346409129876392,-59.247329893833296,-2.016078400820631,-7.527126084640531,1.7487794924176672
1,635674126383965568,138.8428741026386,19.031798198627634,-3.8970011609340207,-12.702779525389634,1,0,19.2873001098633,17.6781005859375,-59.13339098769217,-2.306900745179831,-7.560607655557415,-0.7417999555980248
</pre></div>
</div>
</div>
@@ -1479,6 +1582,10 @@ dtype: float64
<th>dec</th>
<th>pmra</th>
<th>pmdec</th>
<th>best_neighbour_multiplicity</th>
<th>number_of_mates</th>
<th>g_mean_psf_mag</th>
<th>i_mean_psf_mag</th>
<th>phi1</th>
<th>phi2</th>
<th>pm_phi1</th>
@@ -1488,40 +1595,52 @@ dtype: float64
<tbody>
<tr>
<th>0</th>
<td>635559124339440000</td>
<td>137.586717</td>
<td>19.196544</td>
<td>-3.770522</td>
<td>-12.490482</td>
<td>-59.630489</td>
<td>-1.216485</td>
<td>-7.361363</td>
<td>-0.592633</td>
</tr>
<tr>
<th>1</th>
<td>635860218726658176</td>
<td>138.518707</td>
<td>19.092339</td>
<td>-5.941679</td>
<td>-11.346409</td>
<td>1</td>
<td>0</td>
<td>17.8978</td>
<td>17.517401</td>
<td>-59.247330</td>
<td>-2.016078</td>
<td>-7.527126</td>
<td>1.748779</td>
</tr>
<tr>
<th>2</th>
<th>1</th>
<td>635674126383965568</td>
<td>138.842874</td>
<td>19.031798</td>
<td>-3.897001</td>
<td>-12.702780</td>
<td>1</td>
<td>0</td>
<td>19.2873</td>
<td>17.678101</td>
<td>-59.133391</td>
<td>-2.306901</td>
<td>-7.560608</td>
<td>-0.741800</td>
</tr>
<tr>
<th>2</th>
<td>635535454774983040</td>
<td>137.837752</td>
<td>18.864007</td>
<td>-4.335041</td>
<td>-14.492309</td>
<td>1</td>
<td>0</td>
<td>16.9238</td>
<td>16.478100</td>
<td>-59.785300</td>
<td>-1.594569</td>
<td>-9.357536</td>
<td>-1.218492</td>
</tr>
</tbody>
</table>
</div></div></div>
@@ -1557,6 +1676,10 @@ dtype: float64
<th>dec</th>
<th>pmra</th>
<th>pmdec</th>
<th>best_neighbour_multiplicity</th>
<th>number_of_mates</th>
<th>g_mean_psf_mag</th>
<th>i_mean_psf_mag</th>
<th>phi1</th>
<th>phi2</th>
<th>pm_phi1</th>
@@ -1567,55 +1690,62 @@ dtype: float64
<tr>
<th>0</th>
<td>0</td>
<td>635559124339440000</td>
<td>137.586717</td>
<td>19.196544</td>
<td>-3.770522</td>
<td>-12.490482</td>
<td>-59.630489</td>
<td>-1.216485</td>
<td>-7.361363</td>
<td>-0.592633</td>
</tr>
<tr>
<th>1</th>
<td>1</td>
<td>635860218726658176</td>
<td>138.518707</td>
<td>19.092339</td>
<td>-5.941679</td>
<td>-11.346409</td>
<td>1</td>
<td>0</td>
<td>17.8978</td>
<td>17.517401</td>
<td>-59.247330</td>
<td>-2.016078</td>
<td>-7.527126</td>
<td>1.748779</td>
</tr>
<tr>
<th>2</th>
<td>2</td>
<th>1</th>
<td>1</td>
<td>635674126383965568</td>
<td>138.842874</td>
<td>19.031798</td>
<td>-3.897001</td>
<td>-12.702780</td>
<td>1</td>
<td>0</td>
<td>19.2873</td>
<td>17.678101</td>
<td>-59.133391</td>
<td>-2.306901</td>
<td>-7.560608</td>
<td>-0.741800</td>
</tr>
<tr>
<th>2</th>
<td>2</td>
<td>635535454774983040</td>
<td>137.837752</td>
<td>18.864007</td>
<td>-4.335041</td>
<td>-14.492309</td>
<td>1</td>
<td>0</td>
<td>16.9238</td>
<td>16.478100</td>
<td>-59.785300</td>
<td>-1.594569</td>
<td>-9.357536</td>
<td>-1.218492</td>
</tr>
</tbody>
</table>
</div></div></div>
</div>
<p>Notice that the index in <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> has become an unnamed column in <code class="docutils literal notranslate"><span class="pre">read_back_csv</span></code>. The Pandas functions for writing and reading CSV files provide options to avoid that problem, but this is an example of the kind of thing that can go wrong with CSV files.</p>
</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 used database <code class="docutils literal notranslate"><span class="pre">JOIN</span></code> operations to select photometry data for the stars weve identified as candidates to be in GD-1.</p>
<p>In the next notebook, well use this data for a second round of selection, identifying stars that have photometry data consistent with GD-1.</p>
</div>
<div class="section" id="best-practice">
<h2>Best practice<a class="headerlink" href="#best-practice" title="Permalink to this headline"></a></h2>
<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>Use <code class="docutils literal notranslate"><span class="pre">JOIN</span></code> operations to combine data from multiple tables in a databased, using some kind of identifier to match up records from one table with records from another.</p></li>
<li><p>This is another example of a practice we saw in the previous notebook, moving the computation to the data.</p></li>
@@ -1654,7 +1784,7 @@ dtype: float64
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="04_select.html" title="previous page">4. Transformation and Selection</a>
<a class='right-next' id="next-link" href="06_photo.html" title="next page">Photometry</a>
<a class='right-next' id="next-link" href="06_photo.html" title="next page">6. Photometry</a>
</div>
<footer class="footer mt-5 mt-md-0">

View File

@@ -117,12 +117,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">
@@ -525,7 +525,7 @@ The size of the file is about 750 KB, so thats not too bad.</p>
<span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="cell docutils container">
<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>
@@ -1011,7 +1011,7 @@ dtype: float64
<h3>Exercise<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<p>Optional Challenge: Do both joins in one query.</p>
<p>Theres an <a class="reference external" href="https://github.com/smoh/Getting-started-with-Gaia/blob/master/gaia-adql-snippets.md">example here</a> you could start with.</p>
<div class="cell docutils container">
<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>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Photometry &#8212; Astronomical Data in Python</title>
<title>6. Photometry &#8212; Astronomical Data in Python</title>
<link rel="stylesheet" href="_static/css/index.d431a4ee1c1efae0e38bdfebc22debff.css">
@@ -58,7 +58,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Visualization" href="07_plot.html" />
<link rel="prev" title="Joining Tables" href="05_join.html" />
<link rel="prev" title="5. Joining Tables" href="05_join.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -119,12 +119,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">
@@ -273,16 +273,6 @@
Save the polygon
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#reloading-the-data">
Reloading the data
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#merging-photometry-data">
Merging photometry data
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#selecting-based-on-photometry">
Selecting based on photometry
@@ -315,7 +305,7 @@
<div>
<div class="section" id="photometry">
<h1>Photometry<a class="headerlink" href="#photometry" title="Permalink to this headline"></a></h1>
<h1>6. Photometry<a class="headerlink" href="#photometry" title="Permalink to this headline"></a></h1>
<p>This is the sixth in a series of notebooks related to astronomy data.</p>
<p>As a continuing example, we will replicate part of the analysis in a recent paper, “<a class="reference external" href="https://arxiv.org/abs/1805.00425">Off the beaten path: Gaia reveals GD-1 stars outside of the main stream</a>” by Adrian M. Price-Whelan and Ana Bonaca.</p>
<p>In the previous lesson we downloaded photometry data from Pan-STARRS, which is available from the same server weve been using to get Gaia data.</p>
@@ -330,7 +320,6 @@ The following figure from the paper is a color-magnitude diagram showing the sta
<ol class="simple">
<li><p>Well reload the data from the previous notebook and make a color-magnitude diagram.</p></li>
<li><p>Well use an isochrone computed by MIST to specify a polygonal region in the color-magnitude diagram and select the stars inside it.</p></li>
<li><p>Then well merge the photometry data with the list of candidate stars, storing the result in a Pandas <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>.</p></li>
</ol>
<p>After completing this lesson, you should be able to</p>
<ul class="simple">
@@ -346,7 +335,7 @@ The following figure from the paper is a color-magnitude diagram showing the sta
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">wget</span> <span class="kn">import</span> <span class="n">download</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_photo.fits&#39;</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">filepath</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/AllenDowney/AstronomicalData/raw/main/data/&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
@@ -355,12 +344,11 @@ The following figure from the paper is a color-magnitude diagram showing the sta
</div>
</div>
</div>
<p>Now we can read the data back into an Astropy <code class="docutils literal notranslate"><span class="pre">Table</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="kn">from</span> <span class="nn">astropy.table</span> <span class="kn">import</span> <span class="n">Table</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">photo_table</span> <span class="o">=</span> <span class="n">Table</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
<span class="n">candidate_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;candidate_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -415,12 +403,12 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<p>Heres what the results look like.</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">plot_cmd</span><span class="p">(</span><span class="n">photo_table</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_14_0.png" src="_images/06_photo_14_0.png" />
<img alt="_images/06_photo_13_0.png" src="_images/06_photo_13_0.png" />
</div>
</div>
<p>Our figure does not look exactly like the one in the paper because we are working with a smaller region of the sky, so we dont have as many stars. But we can see an overdense region in the lower left that contains stars with the photometry we expect for GD-1.</p>
@@ -629,13 +617,13 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<p>Now we can plot it on the color-magnitude diagram 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">plot_cmd</span><span class="p">(</span><span class="n">photo_table</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">color_g_i</span><span class="p">,</span> <span class="n">mag_g</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_44_0.png" src="_images/06_photo_44_0.png" />
<img alt="_images/06_photo_43_0.png" src="_images/06_photo_43_0.png" />
</div>
</div>
<p>The theoretical isochrone passes through the overdense region where we expect to find stars in GD-1.</p>
@@ -710,7 +698,6 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<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">&#39;gd1_isochrone.hdf5&#39;</span>
<span class="n">iso_df</span><span class="o">.</span><span class="n">to_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;iso_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
@@ -798,13 +785,13 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<p>Heres what the isochrone looks like on the color-magnitude diagram.</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">plot_cmd</span><span class="p">(</span><span class="n">photo_table</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">iso_df</span><span class="p">[</span><span class="s1">&#39;color_g_i&#39;</span><span class="p">],</span> <span class="n">iso_df</span><span class="p">[</span><span class="s1">&#39;mag_g&#39;</span><span class="p">]);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_54_0.png" src="_images/06_photo_54_0.png" />
<img alt="_images/06_photo_53_0.png" src="_images/06_photo_53_0.png" />
</div>
</div>
<p>In the bottom half of the figure, the isochrone passes through the overdense region where the stars are likely to belong to GD-1.</p>
@@ -912,7 +899,7 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<p>Heres what these boundaries look like:</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">plot_cmd</span><span class="p">(</span><span class="n">photo_table</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">left_color</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;left color&#39;</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">right_color</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;right color&#39;</span><span class="p">)</span>
@@ -922,7 +909,7 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_64_0.png" src="_images/06_photo_64_0.png" />
<img alt="_images/06_photo_63_0.png" src="_images/06_photo_63_0.png" />
</div>
</div>
</div>
@@ -982,13 +969,13 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<p>Heres what the loop looks like.</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">plot_cmd</span><span class="p">(</span><span class="n">photo_table</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">color_loop</span><span class="p">,</span> <span class="n">mag_loop</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_72_0.png" src="_images/06_photo_72_0.png" />
<img alt="_images/06_photo_71_0.png" src="_images/06_photo_71_0.png" />
</div>
</div>
<p>To make a <code class="docutils literal notranslate"><span class="pre">Polygon</span></code>, it will be convenient to put <code class="docutils literal notranslate"><span class="pre">color_loop</span></code> and <code class="docutils literal notranslate"><span class="pre">mag_loop</span></code> into a <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>:</p>
@@ -997,9 +984,62 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">loop_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">()</span>
<span class="n">loop_df</span><span class="p">[</span><span class="s1">&#39;color_loop&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">color_loop</span>
<span class="n">loop_df</span><span class="p">[</span><span class="s1">&#39;mag_loop&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mag_loop</span>
<span class="n">loop_df</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_html"><div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>color_loop</th>
<th>mag_loop</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0.632171</td>
<td>21.411746</td>
</tr>
<tr>
<th>1</th>
<td>0.610238</td>
<td>21.322466</td>
</tr>
<tr>
<th>2</th>
<td>0.588449</td>
<td>21.233380</td>
</tr>
<tr>
<th>3</th>
<td>0.566924</td>
<td>21.144427</td>
</tr>
<tr>
<th>4</th>
<td>0.545461</td>
<td>21.054549</td>
</tr>
</tbody>
</table>
</div></div></div>
</div>
<p>Now we can pass <code class="docutils literal notranslate"><span class="pre">loop_df</span></code> to <code class="docutils literal notranslate"><span class="pre">Polygon</span></code>:</p>
<div class="cell docutils container">
@@ -1012,7 +1052,7 @@ The input can be an Astropy <code class="docutils literal notranslate"><span cla
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;matplotlib.patches.Polygon at 0x7fe98cd29400&gt;
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;matplotlib.patches.Polygon at 0x7fd8a96084f0&gt;
</pre></div>
</div>
</div>
@@ -1053,255 +1093,23 @@ So it is important to record the polygon as part of the data analysis pipeline.<
<p>Heres how we can save it in an HDF file.</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">&#39;gd1_polygon.hdf5&#39;</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">loop_df</span><span class="o">.</span><span class="n">to_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;loop_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="reloading-the-data">
<h2>Reloading the data<a class="headerlink" href="#reloading-the-data" title="Permalink to this headline"></a></h2>
<p>Now we need to combine the photometry data with the list of candidate stars we identified in a previous notebook. The following cell downloads 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">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">wget</span> <span class="kn">import</span> <span class="n">download</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_candidates.hdf5&#39;</span>
<span class="n">filepath</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/AllenDowney/AstronomicalData/raw/main/data/&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">download</span><span class="p">(</span><span class="n">filepath</span><span class="o">+</span><span class="n">filename</span><span class="p">))</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="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">candidate_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;candidate_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> is the Pandas DataFrame that contains the results from Lesson 4, which selects stars likely to be in GD-1 based on proper motion. It also includes position and proper motion transformed to the ICRS frame.</p>
</div>
<div class="section" id="merging-photometry-data">
<h2>Merging photometry data<a class="headerlink" href="#merging-photometry-data" title="Permalink to this headline"></a></h2>
<p>Before we select stars based on photometry data, we have to solve two problems:</p>
<ol class="simple">
<li><p>We only have Pan-STARRS data for some stars in <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code>.</p></li>
<li><p>Even for the stars where we have Pan-STARRS data in <code class="docutils literal notranslate"><span class="pre">photo_table</span></code>, some photometry data is missing.</p></li>
</ol>
<p>We will solve these problems in two step:</p>
<ol class="simple">
<li><p>Well merge the data from <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> and <code class="docutils literal notranslate"><span class="pre">photo_table</span></code> into a single Pandas <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>.</p></li>
<li><p>Well use Pandas functions to deal with missing data.</p></li>
</ol>
<p><code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> is already a <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>, but <code class="docutils literal notranslate"><span class="pre">results</span></code> is an Astropy <code class="docutils literal notranslate"><span class="pre">Table</span></code>. Lets convert it to Pandas:</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">photo_df</span> <span class="o">=</span> <span class="n">photo_table</span><span class="o">.</span><span class="n">to_pandas</span><span class="p">()</span>
<span class="k">for</span> <span class="n">colname</span> <span class="ow">in</span> <span class="n">photo_df</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">colname</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>source_id
g_mean_psf_mag
i_mean_psf_mag
</pre></div>
</div>
</div>
</div>
<p>Now we want to combine <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> and <code class="docutils literal notranslate"><span class="pre">photo_df</span></code> into a single table, using <code class="docutils literal notranslate"><span class="pre">source_id</span></code> to match up the rows.</p>
<p>You might recognize this task; its the same as the JOIN operation in ADQL/SQL.</p>
<p>Pandas provides a function called <code class="docutils literal notranslate"><span class="pre">merge</span></code> that does what we want. Heres 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">merged</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">,</span>
<span class="n">photo_df</span><span class="p">,</span>
<span class="n">on</span><span class="o">=</span><span class="s1">&#39;source_id&#39;</span><span class="p">)</span>
<span class="n">merged</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_html"><div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>source_id</th>
<th>ra</th>
<th>dec</th>
<th>pmra</th>
<th>pmdec</th>
<th>parallax</th>
<th>radial_velocity</th>
<th>phi1</th>
<th>phi2</th>
<th>pm_phi1</th>
<th>pm_phi2</th>
<th>g_mean_psf_mag</th>
<th>i_mean_psf_mag</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>635860218726658176</td>
<td>138.518707</td>
<td>19.092339</td>
<td>-5.941679</td>
<td>-11.346409</td>
<td>0.307456</td>
<td>NaN</td>
<td>-59.247330</td>
<td>-2.016078</td>
<td>-7.527126</td>
<td>1.748779</td>
<td>17.8978</td>
<td>17.517401</td>
</tr>
<tr>
<th>1</th>
<td>635674126383965568</td>
<td>138.842874</td>
<td>19.031798</td>
<td>-3.897001</td>
<td>-12.702780</td>
<td>0.779463</td>
<td>NaN</td>
<td>-59.133391</td>
<td>-2.306901</td>
<td>-7.560608</td>
<td>-0.741800</td>
<td>19.2873</td>
<td>17.678101</td>
</tr>
<tr>
<th>2</th>
<td>635535454774983040</td>
<td>137.837752</td>
<td>18.864007</td>
<td>-4.335041</td>
<td>-14.492309</td>
<td>0.314514</td>
<td>NaN</td>
<td>-59.785300</td>
<td>-1.594569</td>
<td>-9.357536</td>
<td>-1.218492</td>
<td>16.9238</td>
<td>16.478100</td>
</tr>
<tr>
<th>3</th>
<td>635497276810313600</td>
<td>138.044516</td>
<td>19.009471</td>
<td>-7.172931</td>
<td>-12.291499</td>
<td>0.425404</td>
<td>NaN</td>
<td>-59.557744</td>
<td>-1.682147</td>
<td>-9.000831</td>
<td>2.334407</td>
<td>19.9242</td>
<td>18.334000</td>
</tr>
<tr>
<th>4</th>
<td>635614168640132864</td>
<td>139.592197</td>
<td>18.807956</td>
<td>-3.309603</td>
<td>-13.708905</td>
<td>0.583382</td>
<td>NaN</td>
<td>-58.938113</td>
<td>-3.024192</td>
<td>-8.062762</td>
<td>-1.869082</td>
<td>16.1516</td>
<td>14.666300</td>
</tr>
</tbody>
</table>
</div></div></div>
</div>
<p>The first argument is the “left” table, the second argument is the “right” table, and the keyword argument <code class="docutils literal notranslate"><span class="pre">on='source_id'</span></code> specifies a column to use to match up the rows.</p>
<p>The result is a <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code> that contains the same number of rows as <code class="docutils literal notranslate"><span class="pre">photo_df</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="nb">len</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">photo_df</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">merged</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>(7346, 3724, 3724)
</pre></div>
</div>
</div>
</div>
<p>And it contains all columns from both tables.</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">for</span> <span class="n">colname</span> <span class="ow">in</span> <span class="n">merged</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">colname</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>source_id
ra
dec
pmra
pmdec
parallax
radial_velocity
phi1
phi2
pm_phi1
pm_phi2
g_mean_psf_mag
i_mean_psf_mag
</pre></div>
</div>
</div>
</div>
<p><strong>Detail</strong> You might notice that Pandas also provides a function called <code class="docutils literal notranslate"><span class="pre">join</span></code>; it does almost the same thing, but the interface is slightly different. We think <code class="docutils literal notranslate"><span class="pre">merge</span></code> is a little easier to use, so thats what we chose. Its also more consistent with JOIN in SQL, so if you learn how to use <code class="docutils literal notranslate"><span class="pre">pd.merge</span></code>, you are also learning how to use SQL JOIN.</p>
<p>Also, someone might ask why we have to use Pandas to do this join; why didnt we do it in ADQL. The answer is that we could have done that, but since we already have the data we need, we should probably do the computation locally rather than make another round trip to the Gaia server.</p>
</div>
<div class="section" id="selecting-based-on-photometry">
<h2>Selecting based on photometry<a class="headerlink" href="#selecting-based-on-photometry" title="Permalink to this headline"></a></h2>
<p>Now lets see how many of these points are inside the polygon we chose.</p>
<p>Well put color and magnitude data from <code class="docutils literal notranslate"><span class="pre">merged</span></code> into a new <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>:</p>
<p>Now lets see how many of the candidate stars are inside the polygon we chose.
Well put color and magnitude data from <code class="docutils literal notranslate"><span class="pre">candidate_df</span></code> into a new <code class="docutils literal notranslate"><span class="pre">DataFrame</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">points</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">()</span>
<span class="n">points</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">merged</span><span class="p">[</span><span class="s1">&#39;g_mean_psf_mag&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="n">merged</span><span class="p">[</span><span class="s1">&#39;i_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">points</span><span class="p">[</span><span class="s1">&#39;mag&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">merged</span><span class="p">[</span><span class="s1">&#39;g_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">points</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">candidate_df</span><span class="p">[</span><span class="s1">&#39;g_mean_psf_mag&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="n">candidate_df</span><span class="p">[</span><span class="s1">&#39;i_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">points</span><span class="p">[</span><span class="s1">&#39;mag&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">candidate_df</span><span class="p">[</span><span class="s1">&#39;g_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">points</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
@@ -1390,8 +1198,7 @@ i_mean_psf_mag
<p>Now we can use <code class="docutils literal notranslate"><span class="pre">inside</span></code> as a mask to select stars that fall inside the polygon.</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">selected2</span> <span class="o">=</span> <span class="n">merged</span><span class="p">[</span><span class="n">inside</span><span class="p">]</span>
<span class="n">points2</span> <span class="o">=</span> <span class="n">points</span><span class="p">[</span><span class="n">inside</span><span class="p">]</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">winner_df</span> <span class="o">=</span> <span class="n">candidate_df</span><span class="p">[</span><span class="n">inside</span><span class="p">]</span>
</pre></div>
</div>
</div>
@@ -1399,16 +1206,18 @@ i_mean_psf_mag
<p>Lets make a color-magnitude plot one more time, highlighting the selected stars with green markers.</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">plot_cmd</span><span class="p">(</span><span class="n">photo_table</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">color_g_i</span><span class="p">,</span> <span class="n">mag_g</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">color_loop</span><span class="p">,</span> <span class="n">mag_loop</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">points2</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">],</span> <span class="n">points2</span><span class="p">[</span><span class="s1">&#39;mag&#39;</span><span class="p">],</span> <span class="s1">&#39;g.&#39;</span><span class="p">);</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">winner_df</span><span class="p">[</span><span class="s1">&#39;g_mean_psf_mag&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="n">winner_df</span><span class="p">[</span><span class="s1">&#39;i_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">winner_df</span><span class="p">[</span><span class="s1">&#39;g_mean_psf_mag&#39;</span><span class="p">]</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;go&#39;</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_106_0.png" src="_images/06_photo_106_0.png" />
<img alt="_images/06_photo_92_0.png" src="_images/06_photo_92_0.png" />
</div>
</div>
<p>It looks like the selected stars are, in fact, inside the polygon, which means they have photometry data consistent with GD-1.</p>
@@ -1417,9 +1226,8 @@ i_mean_psf_mag
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mf">2.5</span><span class="p">))</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">selected2</span><span class="p">[</span><span class="s1">&#39;phi1&#39;</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">selected2</span><span class="p">[</span><span class="s1">&#39;phi2&#39;</span><span class="p">]</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">winner_df</span><span class="p">[</span><span class="s1">&#39;phi1&#39;</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">winner_df</span><span class="p">[</span><span class="s1">&#39;phi2&#39;</span><span class="p">]</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;ko&#39;</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="mf">0.7</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.9</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;ra (degree GD1)&#39;</span><span class="p">)</span>
@@ -1430,7 +1238,7 @@ i_mean_psf_mag
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/06_photo_108_0.png" src="_images/06_photo_108_0.png" />
<img alt="_images/06_photo_94_0.png" src="_images/06_photo_94_0.png" />
</div>
</div>
<p>This example includes two new Matplotlib commands:</p>
@@ -1442,54 +1250,42 @@ i_mean_psf_mag
</div>
<div class="section" id="write-the-data">
<h2>Write the data<a class="headerlink" href="#write-the-data" title="Permalink to this headline"></a></h2>
<p>Finally, lets write the merged DataFrame to a file.</p>
<p>Finally, lets write the selected stars to a file.</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">&#39;gd1_merged.hdf5&#39;</span>
<span class="n">merged</span><span class="o">.</span><span class="n">to_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;merged&#39;</span><span class="p">)</span>
<span class="n">selected2</span><span class="o">.</span><span class="n">to_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;selected2&#39;</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">winner_df</span><span class="o">.</span><span class="n">to_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;winner_df&#39;</span><span class="p">)</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="o">!</span>ls -lh gd1_merged.hdf5
<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 stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-rw-rw-r-- 1 downey downey 1.1M Dec 29 11:51 gd1_merged.hdf5
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>2.512819290161133
</pre></div>
</div>
</div>
</div>
<p>If you are using Windows, <code class="docutils literal notranslate"><span class="pre">ls</span></code> might not work; in that case, try:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>!dir gd1_merged.hdf5
</pre></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 lesson, we worked with three datasets:</p>
<ul class="simple">
<li><p>The list of candidate stars from Gaia,</p></li>
<li><p>The photometry data from Pan-STARRS, and</p></li>
<li><p>An isochrone computed by MIST.</p></li>
</ul>
<p>We drew a color-magnitude diagram and used it to identify stars we think are likely to be in GD-1.</p>
<p>We used the isochrone to define a polygon that includes those stars.</p>
<p>Then we used a Pandas <code class="docutils literal notranslate"><span class="pre">merge</span></code> operation to combine Gaia and Pan-STARRS data into a single <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>.</p>
<p>Plotting the results, we have a clear picture of GD-1, similar to Figure 1 in the original paper.</p>
<p>In this lesson, we used photometry data from Pan-STARRS to draw a color-magnitude diagram.
We used an isochrone to define a polygon and select stars we think are likely to be in GD-1. Plotting the results, we have a clearer picture of GD-1, similar to Figure 1 in the original paper.</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>Matplotlib provides operations for working with points, polygons, and other geometric entities, so its not just for making figures.</p></li>
<li><p>If you want to perform something like a database <code class="docutils literal notranslate"><span class="pre">JOIN</span></code> operation with data that is in a Pandas <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>, you can use the <code class="docutils literal notranslate"><span class="pre">join</span></code> or <code class="docutils literal notranslate"><span class="pre">merge</span></code> function. In many cases, <code class="docutils literal notranslate"><span class="pre">merge</span></code> is easier to use because the arguments are more like SQL.</p></li>
<li><p>Use Matplotlib options to control the size and aspect ratio of figures to make them easier to interpret. In this example, we scaled the axes so the size of a degree is equal along both axes.</p></li>
<li><p>Be sure to record every element of the data analysis pipeline that would be needed to replicate the results.</p></li>
<li><p>Record every element of the data analysis pipeline that would be needed to replicate the results.</p></li>
</ul>
</div>
</div>
@@ -1522,7 +1318,7 @@ i_mean_psf_mag
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="05_join.html" title="previous page">Joining Tables</a>
<a class='left-prev' id="prev-link" href="05_join.html" title="previous page">5. Joining Tables</a>
<a class='right-next' id="next-link" href="07_plot.html" title="next page">Visualization</a>
</div>

View File

@@ -57,7 +57,7 @@
<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="prev" title="Photometry" href="06_photo.html" />
<link rel="prev" title="6. Photometry" href="06_photo.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -118,12 +118,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1 current active">
@@ -404,7 +404,7 @@
<li><p>In the design of this figure, can you identify 1-2 choices the authors made that you think are effective? Think about big-picture elements, like the number of panels and how they are arranged, as well as details like the choice of typeface.</p></li>
<li><p>Can you identify 1-2 elements that could be improved, or that you might have done differently?</p></li>
</ol>
<div class="cell docutils container">
<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>
@@ -450,7 +450,7 @@
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">wget</span> <span class="kn">import</span> <span class="n">download</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_merged.hdf5&#39;</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/AllenDowney/AstronomicalData/raw/main/data/&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
@@ -463,7 +463,7 @@
<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">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">selected2</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;selected2&#39;</span><span class="p">)</span>
<span class="n">winner_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;winner_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -491,7 +491,7 @@
<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">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mf">2.5</span><span class="p">))</span>
<span class="n">plot_second_selection</span><span class="p">(</span><span class="n">selected2</span><span class="p">)</span>
<span class="n">plot_second_selection</span><span class="p">(</span><span class="n">winner_df</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -702,6 +702,15 @@
</div>
<p>You might have to install a package that contains the fonts LaTeX needs. On some systems, the packages <code class="docutils literal notranslate"><span class="pre">texlive-latex-extra</span></code> or <code class="docutils literal notranslate"><span class="pre">cm-super</span></code> might be what you need. <a class="reference external" href="https://stackoverflow.com/questions/11354149/python-unable-to-render-tex-in-matplotlib">See here for more help with this</a>.</p>
<p>In case you are curious, <code class="docutils literal notranslate"><span class="pre">cm</span></code> stands for <a class="reference external" href="https://en.wikipedia.org/wiki/Computer_Modern">Computer Modern</a>, the font LaTeX uses to typeset math.</p>
<p>Before we go on, lets put things back where we found them.</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">plt</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s1">&#39;text.usetex&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">plt</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">use</span><span class="p">(</span><span class="s1">&#39;default&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="multiple-panels">
<h2>Multiple panels<a class="headerlink" href="#multiple-panels" title="Permalink to this headline"></a></h2>
@@ -720,21 +729,7 @@
<p>To make the panel in the upper right, we have to reload <code class="docutils literal notranslate"><span class="pre">centerline_df</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="kn">import</span> <span class="nn">os</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_dataframe.hdf5&#39;</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/AllenDowney/AstronomicalData/raw/main/data/&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">download</span><span class="p">(</span><span class="n">path</span><span class="o">+</span><span class="n">filename</span><span class="p">))</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="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">centerline_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;centerline_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
@@ -802,10 +797,7 @@
<p>Heres what the new version of the figure looks like. Weve changed the labels on the axes to be consistent with the paper.</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">plt</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s1">&#39;text.usetex&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">plt</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">use</span><span class="p">(</span><span class="s1">&#39;default&#39;</span><span class="p">)</span>
<span class="n">plot_proper_motion</span><span class="p">(</span><span class="n">centerline_df</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_proper_motion</span><span class="p">(</span><span class="n">centerline_df</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -819,23 +811,7 @@
<p>Now lets work on the panel in the upper left. We have to reload <code class="docutils literal notranslate"><span class="pre">candidates</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="kn">import</span> <span class="nn">os</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_candidates.hdf5&#39;</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/AllenDowney/AstronomicalData/raw/main/data/&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">download</span><span class="p">(</span><span class="n">path</span><span class="o">+</span><span class="n">filename</span><span class="p">))</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="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_candidates.hdf5&#39;</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">candidate_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;candidate_df&#39;</span><span class="p">)</span>
</pre></div>
</div>
@@ -867,25 +843,13 @@
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/07_plot_61_0.png" src="_images/07_plot_61_0.png" />
<img alt="_images/07_plot_60_0.png" src="_images/07_plot_60_0.png" />
</div>
</div>
</div>
<div class="section" id="lower-right">
<h2>Lower right<a class="headerlink" href="#lower-right" title="Permalink to this headline"></a></h2>
<p>For the figure in the lower right, we need to reload the merged <code class="docutils literal notranslate"><span class="pre">DataFrame</span></code>, which contains data from Gaia and photometry data from Pan-STARRS.</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">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_merged.hdf5&#39;</span>
<span class="n">merged</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;merged&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<p>From the previous notebook, heres the function that plots the color-magnitude diagram.</p>
<p>For the figure in the lower right, well use this function to plots the color-magnitude diagram.</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">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
@@ -910,35 +874,22 @@
</div>
</div>
</div>
<p>And heres what it looks like.</p>
<p>Heres what it looks like.</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">plot_cmd</span><span class="p">(</span><span class="n">merged</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/07_plot_67_0.png" src="_images/07_plot_67_0.png" />
</div>
</div>
<p>The following cell downloads an HDF file that contains the polygon we used to select starts in the color-magnitude diagram, if it doesnt already exist.</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">os</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_polygon.hdf5&#39;</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/AllenDowney/AstronomicalData/raw/main/data/&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">download</span><span class="p">(</span><span class="n">path</span><span class="o">+</span><span class="n">filename</span><span class="p">))</span>
</pre></div>
</div>
<img alt="_images/07_plot_64_0.png" src="_images/07_plot_64_0.png" />
</div>
</div>
<p>And heres how we read it back.</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">loop_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;loop_df&#39;</span><span class="p">)</span>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;gd1_data.hdf&#39;</span>
<span class="n">loop_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_hdf</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;loop_df&#39;</span><span class="p">)</span>
<span class="n">loop_df</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
</div>
@@ -1033,10 +984,10 @@
<span class="n">plot_proper_motion</span><span class="p">(</span><span class="n">centerline_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot2grid</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="n">plot_second_selection</span><span class="p">(</span><span class="n">selected2</span><span class="p">)</span>
<span class="n">plot_second_selection</span><span class="p">(</span><span class="n">winner_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot2grid</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="n">plot_cmd</span><span class="p">(</span><span class="n">merged</span><span class="p">)</span>
<span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">poly</span> <span class="o">=</span> <span class="n">Polygon</span><span class="p">(</span><span class="n">loop_df</span><span class="p">,</span> <span class="n">closed</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">facecolor</span><span class="o">=</span><span class="s1">&#39;C1&#39;</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.4</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">poly</span><span class="p">)</span>
@@ -1046,7 +997,7 @@
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/07_plot_75_0.png" src="_images/07_plot_75_0.png" />
<img alt="_images/07_plot_70_0.png" src="_images/07_plot_70_0.png" />
</div>
</div>
<p>We use <a class="reference external" href="https://matplotlib.org/3.3.1/tutorials/intermediate/tight_layout_guide.html"><code class="docutils literal notranslate"><span class="pre">plt.tight_layout</span></code></a> at the end, which adjusts the sizes of the panels to make sure the titles and axis labels dont overlap.</p>
@@ -1071,10 +1022,10 @@
<span class="n">plot_proper_motion</span><span class="p">(</span><span class="n">centerline_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot2grid</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">colspan</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="n">plot_second_selection</span><span class="p">(</span><span class="n">selected2</span><span class="p">)</span>
<span class="n">plot_second_selection</span><span class="p">(</span><span class="n">winner_df</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot2grid</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="n">plot_cmd</span><span class="p">(</span><span class="n">merged</span><span class="p">)</span>
<span class="n">plot_cmd</span><span class="p">(</span><span class="n">candidate_df</span><span class="p">)</span>
<span class="n">poly</span> <span class="o">=</span> <span class="n">Polygon</span><span class="p">(</span><span class="n">loop_df</span><span class="p">,</span> <span class="n">closed</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">facecolor</span><span class="o">=</span><span class="s1">&#39;C1&#39;</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.4</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">poly</span><span class="p">)</span>
@@ -1084,14 +1035,14 @@
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/07_plot_78_0.png" src="_images/07_plot_78_0.png" />
<img alt="_images/07_plot_73_0.png" src="_images/07_plot_73_0.png" />
</div>
</div>
<p>This is looking more and more like the figure in the paper.</p>
<div class="section" id="id4">
<h3>Exercise<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<p>In this example, the ratio of the widths of the panels is 3:1. How would you adjust it if you wanted the ratio to be 3:2?</p>
<div class="cell docutils container">
<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>
@@ -1105,10 +1056,10 @@
<span class="c1"># plot_proper_motion(centerline_df)</span>
<span class="c1"># plt.subplot2grid(shape, (1, 0), colspan=3)</span>
<span class="c1"># plot_second_selection(selected2)</span>
<span class="c1"># plot_second_selection(winner_df)</span>
<span class="c1"># plt.subplot2grid(shape, (1, 3), colspan=2) # CHANGED</span>
<span class="c1"># plot_cmd(merged)</span>
<span class="c1"># plot_cmd(candidate_df)</span>
<span class="c1"># poly = Polygon(coords, closed=True, </span>
<span class="c1"># facecolor=&#39;C1&#39;, alpha=0.4)</span>
<span class="c1"># plt.gca().add_patch(poly)</span>
@@ -1164,7 +1115,7 @@
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="06_photo.html" title="previous page">Photometry</a>
<a class='left-prev' id="prev-link" href="06_photo.html" title="previous page">6. Photometry</a>
</div>
<footer class="footer mt-5 mt-md-0">

View File

@@ -118,12 +118,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

BIN
_images/04_select_67_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
_images/04_select_73_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
_images/05_join_78_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
_images/06_photo_13_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
_images/06_photo_43_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
_images/06_photo_53_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
_images/06_photo_63_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
_images/06_photo_71_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
_images/06_photo_92_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
_images/06_photo_94_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 150 KiB

BIN
_images/07_plot_60_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
_images/07_plot_64_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
_images/07_plot_70_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

BIN
_images/07_plot_73_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

View File

@@ -990,7 +990,11 @@
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"# Solution\n",
@@ -1178,7 +1182,11 @@
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"# Solution\n",

View File

@@ -1499,7 +1499,11 @@
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [
{
"data": {
@@ -1734,7 +1738,11 @@
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [
{
"data": {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -430,7 +430,11 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"# Solution\n",
@@ -1308,7 +1312,11 @@
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"# Solution\n",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -117,12 +117,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">

View File

@@ -2,5 +2,5 @@
# Project: Python
# Version:
# The remainder of this file is compressed using zlib.
<EFBFBD><EFBFBD>N<EFBFBD>0 <0C><>}
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> q<><71> M*lp<6C><70>ƬAi\<5C>T<EFBFBD><=M<>J<EFBFBD>T<EFBFBD><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>v<EFBFBD><14><1D>|P<><50>*X,<2C><><EFBFBD><EFBFBD><0E><>e<0E><>K<EFBFBD>ϊ<EFBFBD><CF8A><EFBFBD><EFBFBD><EFBFBD>Iz<49>_<><5F><14><>ʀ<1E>U<EFBFBD>nu<18><>h(h<><68><A<><41>9<EFBFBD><39>ZtpiVl<56>G<EFBFBD>UH<55> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>9<0E>C<EFBFBD>cb<63><62>N|<7C>N<EFBFBD>2b<32>e<EFBFBD><65><EFBFBD><EFBFBD>I<EFBFBD>M<<3C>{<7B><><EFBFBD>Q"<22><><EFBFBD>E[S<>Ĺ2<16>X6\<5C><0F>5<EFBFBD>ň<><1F>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m<EFBFBD><6D><1D><>a&<26><><EFBFBD><EFBFBD><EFBFBD>R<EFBFBD>+i`'<27><><EFBFBD>ֲ<0F>`^pXQ<58><51><EFBFBD>yF<>ˬ!5<>l<EFBFBD><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Tg<54><67><EFBFBD>t<EFBFBD><74>x<EFBFBD><78><EFBFBD>(]U<>"3v<33><76>/<2F><05>?<3F>L<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD>N<EFBFBD>0E<><45><EFBFBD><EFBFBD><EFBFBD>F)} <20><>h U*<2A><><EFBFBD><EFBFBD>xh<78>O<>]<5D><><EFBFBD>ؙF<D899>Q%v<>3<EFBFBD>d|<7C><><EFBFBD>:<3A><><EFBFBD><07><><EFBFBD><EFBFBD><EFBFBD><14> +<2B><><1A><><EFBFBD>'<27><><EFBFBD><EFBFBD>DM<44><4D><EFBFBD><EFBFBD>#<23><>] <09>i<EFBFBD>V<06> <20><>7<EFBFBD>C<EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD>f<EFBFBD>Y<><59><EFBFBD><73><D4A1>@<40>j.<<1A>C&<26><><EFBFBD>y '<27><> <20><><EFBFBD>@:<3A><12>?<16><>t~<7E><11><><12><><EFBFBD><EFBFBD> <0E>hRO^ 2ꆕ0<EA8695><EFBFBD><7F><EFBFBD>
<EFBFBD>9<17><>2<EFBFBD>KS<4B><53><EFBFBD>Eu/:Cy5F<35>~<7E><>,<2C><>J<15><><EFBFBD>z<EFBFBD><7A>3<><33><EFBFBD>G<>Z]Kk$<24>ƻ>4<><a|<7C><><EFBFBD><EFBFBD>5<EFBFBD><35>&<26>#e<>)}-<2D>ɮ<><C9AE> oI<EFBFBD>

View File

@@ -122,12 +122,12 @@
</li>
<li class="toctree-l1">
<a class="reference internal" href="05_join.html">
Joining Tables
5. Joining Tables
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="06_photo.html">
Photometry
6. Photometry
</a>
</li>
<li class="toctree-l1">

File diff suppressed because one or more lines are too long