mirror of
https://github.com/AllenDowney/AstronomicalData.git
synced 2026-07-28 14:47:02 -07:00
761 KiB
761 KiB
In [1]:
# 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 python-wgetIn [2]:
import os
from wget import download
filename = 'gd1_merged.hdf5'
path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'
if not os.path.exists(filename):
print(download(path+filename))In [3]:
import pandas as pd
selected = pd.read_hdf(filename, 'selected')In [4]:
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 [5]:
plt.figure(figsize=(10,2.5))
plot_second_selection(selected)In [6]:
# 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 [7]:
# Solution
# plt.gca().tick_params(top=True, right=True)In [8]:
plt.rcParams['font.size']Out [8]:
10.0
In [9]:
plt.rcParams['font.size'] = 14In [10]:
plt.style.availableOut [10]:
['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 [11]:
import os
filename = 'az-paper-twocol.mplstyle'
path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'
if not os.path.exists(filename):
print(download(path+filename))In [ ]:
In [ ]:
In [12]:
plt.rcParams['text.usetex'] = TrueIn [13]:
import os
filename = 'gd1_dataframe.hdf5'
path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'
if not os.path.exists(filename):
print(download(path+filename))In [14]:
import pandas as pd
centerline = pd.read_hdf(filename, 'centerline')In [15]:
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 [16]:
import numpy as np
vertices = np.transpose([pm1_rect, pm2_rect])
verticesOut [16]:
array([[-8.9, -2.2],
[-8.9, 1. ],
[-6.9, 1. ],
[-6.9, -2.2]])In [17]:
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 [18]:
plt.rcParams['text.usetex'] = False
plt.style.use('default')
plot_proper_motion(centerline)In [19]:
import os
filename = 'gd1_candidates.hdf5'
path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'
if not os.path.exists(filename):
print(download(path+filename))In [20]:
import pandas as pd
filename = 'gd1_candidates.hdf5'
candidate_df = pd.read_hdf(filename, 'candidate_df')In [21]:
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 [22]:
plot_first_selection(candidate_df)In [23]:
import pandas as pd
filename = 'gd1_merged.hdf5'
merged = pd.read_hdf(filename, 'merged')In [24]:
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 [25]:
plot_cmd(merged)In [26]:
import os
filename = 'gd1_polygon.hdf5'
path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'
if not os.path.exists(filename):
print(download(path+filename))In [27]:
coords_df = pd.read_hdf(filename, 'coords_df')
coords = coords_df.to_numpy()
coordsOut [27]:
array([[ 0.21505376, 17.5481972 ],
[ 0.38978495, 18.94628403],
[ 0.53763441, 19.90286976],
[ 0.70340502, 20.60191317],
[ 0.82885305, 21.30095659],
[ 0.66308244, 21.52170714],
[ 0.43010753, 20.78587196],
[ 0.27329749, 19.71891096],
[ 0.17473118, 18.68874172],
[ 0.17473118, 17.95290655]])In [28]:
# Solution
#poly = Polygon(coords, closed=True,
# facecolor='C1', alpha=0.4)
#plt.gca().add_patch(poly)In [29]:
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 [30]:
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 [ ]:
