mirror of
https://github.com/AllenDowney/AstronomicalData.git
synced 2026-07-28 22:50:53 -07:00
721 KiB
721 KiB
Cell:
[Cell type raw - unsupported, skipped]
In [30]:
# Solution
# Some topics that might come up in this discussion:
# 1. The primary result is that the multiple stages of selection
# make it possible to separate likely candidates from the
# background more effectively than in previous work, which makes
# it possible to see the structure of GD-1 in "unprecedented detail".
# 2. The figure documents the selection process as a sequence of
# steps. Reading right-to-left, top-to-bottom, we see selection
# based on proper motion, the results of the first selection,
# selection based on color and magnitude, and the results of the
# second selection. So this figure documents the methodology and
# presents the primary result.
# 3. It's mostly black and white, with minimal use of color, so
# it will work well in print. The annotations in the bottom
# left panel guide the reader to the most important results.
# It contains enough technical detail for a professional audience,
# but most of it is also comprehensible to a more general audience.
# The two left panels have the same dimensions and their axes are
# aligned.
# 4. Since the panels represent a sequence, it might be better to
# arrange them left-to-right. The placement and size of the axis
# labels could be tweaked. The entire figure could be a little
# bigger to match the width and proportion of the caption.
# The top left panel has unnused white space (but that leaves
# space for the annotations in the bottom left).In [31]:
from os.path import basename, exists
def download(url):
filename = basename(url)
if not exists(filename):
from urllib.request import urlretrieve
local, _ = urlretrieve(url, filename)
print('Downloaded ' + local)
download('https://github.com/AllenDowney/AstronomicalData/raw/main/' +
'data/gd1_data.hdf')In [32]:
import pandas as pd
filename = 'gd1_data.hdf'
winner_df = pd.read_hdf(filename, 'winner_df')In [33]:
import matplotlib.pyplot as plt
def plot_second_selection(df):
x = df['phi1']
y = df['phi2']
plt.plot(x, y, 'ko', markersize=0.7, alpha=0.9)
plt.xlabel('$\phi_1$ [deg]')
plt.ylabel('$\phi_2$ [deg]')
plt.title('Proper motion + photometry selection', fontsize='medium')
plt.axis('equal')In [34]:
plt.figure(figsize=(10,2.5))
plot_second_selection(winner_df)In [35]:
# Solution
# plt.axvline(-55, ls='--', color='gray',
# alpha=0.4, dashes=(6,4), lw=2)
# plt.text(-60, 5.5, 'Previously\nundetected',
# fontsize='small', ha='right', va='top');
# arrowprops=dict(color='gray', shrink=0.05, width=1.5,
# headwidth=6, headlength=8, alpha=0.4)
# plt.annotate('Spur', xy=(-33, 2), xytext=(-35, 5.5),
# arrowprops=arrowprops,
# fontsize='small')
# plt.annotate('Gap', xy=(-22, -1), xytext=(-25, -5.5),
# arrowprops=arrowprops,
# fontsize='small')In [36]:
# Solution
# plt.gca().tick_params(top=True, right=True)In [37]:
plt.rcParams['font.size']Out [37]:
10.0
In [38]:
plt.rcParams['font.size'] = 14In [39]:
plt.style.availableOut [39]:
['Solarize_Light2', '_classic_test_patch', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark', 'seaborn-dark-palette', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'tableau-colorblind10']
In [ ]:
In [40]:
download('https://github.com/AllenDowney/AstronomicalData/raw/main/' +
'az-paper-twocol.mplstyle')In [ ]:
In [ ]:
In [41]:
plt.rcParams['text.usetex'] = TrueIn [42]:
plt.rcParams['text.usetex'] = False
plt.style.use('default')In [43]:
filename = 'gd1_data.hdf'
centerline_df = pd.read_hdf(filename, 'centerline_df')In [44]:
pm1_min = -8.9
pm1_max = -6.9
pm2_min = -2.2
pm2_max = 1.0
pm1_rect = [pm1_min, pm1_min, pm1_max, pm1_max]
pm2_rect = [pm2_min, pm2_max, pm2_max, pm2_min]In [45]:
import numpy as np
vertices = np.transpose([pm1_rect, pm2_rect])
verticesOut [45]:
array([[-8.9, -2.2],
[-8.9, 1. ],
[-6.9, 1. ],
[-6.9, -2.2]])In [46]:
from matplotlib.patches import Polygon
def plot_proper_motion(df):
pm1 = df['pm_phi1']
pm2 = df['pm_phi2']
plt.plot(pm1, pm2, 'ko', markersize=0.3, alpha=0.3)
poly = Polygon(vertices, closed=True,
facecolor='C1', alpha=0.4)
plt.gca().add_patch(poly)
plt.xlabel('$\mu_{\phi_1} [\mathrm{mas~yr}^{-1}]$')
plt.ylabel('$\mu_{\phi_2} [\mathrm{mas~yr}^{-1}]$')
plt.xlim(-12, 8)
plt.ylim(-10, 10)In [47]:
plot_proper_motion(centerline_df)In [48]:
filename = 'gd1_data.hdf'
candidate_df = pd.read_hdf(filename, 'candidate_df')In [49]:
def plot_first_selection(df):
x = df['phi1']
y = df['phi2']
plt.plot(x, y, 'ko', markersize=0.3, alpha=0.3)
plt.xlabel('$\phi_1$ [deg]')
plt.ylabel('$\phi_2$ [deg]')
plt.title('Proper motion selection', fontsize='medium')
plt.axis('equal')In [50]:
plot_first_selection(candidate_df)In [51]:
import matplotlib.pyplot as plt
def plot_cmd(table):
"""Plot a color magnitude diagram.
table: Table or DataFrame with photometry data
"""
y = table['g_mean_psf_mag']
x = table['g_mean_psf_mag'] - table['i_mean_psf_mag']
plt.plot(x, y, 'ko', markersize=0.3, alpha=0.3)
plt.xlim([0, 1.5])
plt.ylim([14, 22])
plt.gca().invert_yaxis()
plt.ylabel('$Magnitude (g)$')
plt.xlabel('$Color (g-i)$')In [52]:
plot_cmd(candidate_df)In [53]:
filename = 'gd1_data.hdf'
loop_df = pd.read_hdf(filename, 'loop_df')
loop_df.head()Out [53]:
| color_loop | mag_loop | |
|---|---|---|
| 0 | 0.632171 | 21.411746 |
| 1 | 0.610238 | 21.322466 |
| 2 | 0.588449 | 21.233380 |
| 3 | 0.566924 | 21.144427 |
| 4 | 0.545461 | 21.054549 |
In [54]:
# Solution
# poly = Polygon(loop_df, closed=True,
# facecolor='C1', alpha=0.4)
# plt.gca().add_patch(poly)In [55]:
shape = (2, 2)
plt.subplot2grid(shape, (0, 0))
plot_first_selection(candidate_df)
plt.subplot2grid(shape, (0, 1))
plot_proper_motion(centerline_df)
plt.subplot2grid(shape, (1, 0))
plot_second_selection(winner_df)
plt.subplot2grid(shape, (1, 1))
plot_cmd(candidate_df)
poly = Polygon(loop_df, closed=True,
facecolor='C1', alpha=0.4)
plt.gca().add_patch(poly)
plt.tight_layout()In [56]:
plt.figure(figsize=(9, 4.5))
shape = (2, 4)
plt.subplot2grid(shape, (0, 0), colspan=3)
plot_first_selection(candidate_df)
plt.subplot2grid(shape, (0, 3))
plot_proper_motion(centerline_df)
plt.subplot2grid(shape, (1, 0), colspan=3)
plot_second_selection(winner_df)
plt.subplot2grid(shape, (1, 3))
plot_cmd(candidate_df)
poly = Polygon(loop_df, closed=True,
facecolor='C1', alpha=0.4)
plt.gca().add_patch(poly)
plt.tight_layout()In [57]:
# Solution
# plt.figure(figsize=(9, 4.5))
# shape = (2, 5) # CHANGED
# plt.subplot2grid(shape, (0, 0), colspan=3)
# plot_first_selection(candidate_df)
# plt.subplot2grid(shape, (0, 3), colspan=2) # CHANGED
# plot_proper_motion(centerline_df)
# plt.subplot2grid(shape, (1, 0), colspan=3)
# plot_second_selection(winner_df)
# plt.subplot2grid(shape, (1, 3), colspan=2) # CHANGED
# plot_cmd(candidate_df)
# poly = Polygon(coords, closed=True,
# facecolor='C1', alpha=0.4)
# plt.gca().add_patch(poly)
# plt.tight_layout()In [ ]:
