mirror of
https://github.com/AllenDowney/AstronomicalData.git
synced 2026-07-28 14:47:02 -07:00
893 KiB
893 KiB
In [3]:
# If we're running on Colab, install libraries
import sys
IN_COLAB = 'google.colab' in sys.modules
if IN_COLAB:
!pip install astroquery astro-gala pyia
!mkdir dataIn [ ]:
In [4]:
import os
filename = 'gd1_merged.hdf5'
if not os.path.exists(filename):
!wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_merged.hdf5--2020-10-05 10:24:55-- https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_merged.hdf5 Resolving github.com (github.com)... 140.82.112.4 Connecting to github.com (github.com)|140.82.112.4|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_merged.hdf5 [following] --2020-10-05 10:24:56-- https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_merged.hdf5 Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.116.133 Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.116.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2006352 (1.9M) [application/octet-stream] Saving to: ‘gd1_merged.hdf5’ gd1_merged.hdf5 100%[===================>] 1.91M 6.14MB/s in 0.3s 2020-10-05 10:24:56 (6.14 MB/s) - ‘gd1_merged.hdf5’ saved [2006352/2006352]
In [5]:
import pandas as pd
selected = pd.read_hdf(filename, 'selected')In [6]:
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 [7]:
plt.figure(figsize=(10,2.5))
plot_second_selection(selected)In [8]:
# 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 [9]:
# Solution
# plt.gca().tick_params(top=True, right=True)In [10]:
import matplotlib as mpl
mpl.rcParams['font.size']Out [10]:
10.0
In [11]:
mpl.rcParams['font.size'] = 14In [12]:
plt.style.availableOut [12]:
['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 [13]:
plt.style.use('fivethirtyeight')In [14]:
import os
filename = 'az-paper-twocol.mplstyle'
if not os.path.exists(filename):
!wget https://github.com/AllenDowney/AstronomicalData/raw/main/az-paper-twocol.mplstyleIn [15]:
plt.style.use('./az-paper-twocol.mplstyle')In [16]:
mpl.rcParams['text.usetex'] = TrueIn [17]:
import os
filename = 'gd1_dataframe.hdf5'
if not os.path.exists(filename):
!wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_dataframe.hdf5In [18]:
import pandas as pd
centerline = pd.read_hdf(filename, 'centerline')In [19]:
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 [20]:
import numpy as np
vertices = np.transpose([pm1_rect, pm2_rect])
verticesOut [20]:
array([[-8.9, -2.2],
[-8.9, 1. ],
[-6.9, 1. ],
[-6.9, -2.2]])In [21]:
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 [22]:
mpl.rcParams['text.usetex'] = False
plt.style.use('default')
plot_proper_motion(centerline)In [23]:
import os
filename = 'gd1_candidates.hdf5'
if not os.path.exists(filename):
!wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_candidates.hdf5In [24]:
import pandas as pd
filename = 'gd1_candidates.hdf5'
candidate_df = pd.read_hdf(filename, 'candidate_df')In [25]:
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 [26]:
plot_first_selection(candidate_df)In [27]:
import pandas as pd
filename = 'gd1_merged.hdf5'
merged = pd.read_hdf(filename, 'merged')In [28]:
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('$g_0$')
plt.xlabel('$(g-i)_0$')In [29]:
plot_cmd(merged)In [30]:
import os
filename = 'gd1_polygon.hdf5'
if not os.path.exists(filename):
!wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_polygon.hdf5In [31]:
coords_df = pd.read_hdf(filename, 'coords_df')
coords = coords_df.to_numpy()
coordsOut [31]:
array([[ 0.26433692, 18.21044886],
[ 0.38530466, 19.09345107],
[ 0.52867384, 19.82928624],
[ 0.63172043, 20.34437086],
[ 0.72580645, 20.89624724],
[ 0.66756272, 21.3745401 ],
[ 0.49283154, 21.33774834],
[ 0.35394265, 20.41795438],
[ 0.24193548, 19.57174393],
[ 0.18369176, 18.35761589]])In [32]:
# Solution
#poly = Polygon(coords, closed=True,
# facecolor='C1', alpha=0.4)
#plt.gca().add_patch(poly)In [33]:
shape = (2, 2)
plt.subplot2grid(shape, (0, 0))
plot_first_selection(candidate_df)
plt.subplot2grid(shape, (0, 1))
plot_proper_motion(centerline)
plt.subplot2grid(shape, (1, 0))
plot_second_selection(selected)
plt.subplot2grid(shape, (1, 1))
plot_cmd(merged)
poly = Polygon(coords, closed=True,
facecolor='C1', alpha=0.4)
plt.gca().add_patch(poly)
plt.tight_layout()In [34]:
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)
plt.subplot2grid(shape, (1, 0), colspan=3)
plot_second_selection(selected)
plt.subplot2grid(shape, (1, 3))
plot_cmd(merged)
poly = Polygon(coords, closed=True,
facecolor='C1', alpha=0.4)
plt.gca().add_patch(poly)
plt.tight_layout()In [ ]:
