def load_rrlyrae_data(): """Load the RR Lyrae data. This will be used in several examples. """ # ---------------------------------------------------------------------- # Load data rrlyrae = fetch_rrlyrae_mags() standards = fetch_sdss_S82standards() # perform color cuts on standard stars # these come from eqns 1-4 of Sesar et al 2010, ApJ 708:717 u_g = standards["mmu_u"] - standards["mmu_g"] g_r = standards["mmu_g"] - standards["mmu_r"] r_i = standards["mmu_r"] - standards["mmu_i"] i_z = standards["mmu_i"] - standards["mmu_z"] standards = standards[ (u_g > 0.7) & (u_g < 1.35) & (g_r > -0.15) & (g_r < 0.4) & (r_i > -0.15) & (r_i < 0.22) & (i_z > -0.21) & (i_z < 0.25) ] # ---------------------------------------------------------------------- # get magnitudes and colors; split into train and test sets mags_rr = np.vstack([rrlyrae[f + "mag"] for f in "ugriz"]) colors_rr = mags_rr[:-1] - mags_rr[1:] mags_st = np.vstack([standards["mmu_" + f] for f in "ugriz"]) colors_st = mags_st[:-1] - mags_st[1:] # stack the two sets of colors together X = np.vstack((colors_st.T, colors_rr.T)) y = np.zeros(X.shape[0]) y[-colors_rr.shape[1] :] = 1 return X, y
def load_rrlyrae_data(): """Load the RR Lyrae data. This will be used in several examples. """ #---------------------------------------------------------------------- # Load data rrlyrae = fetch_rrlyrae_mags() standards = fetch_sdss_S82standards() # perform color cuts on standard stars # these come from eqns 1-4 of Sesar et al 2010, ApJ 708:717 u_g = standards['mmu_u'] - standards['mmu_g'] g_r = standards['mmu_g'] - standards['mmu_r'] r_i = standards['mmu_r'] - standards['mmu_i'] i_z = standards['mmu_i'] - standards['mmu_z'] standards = standards[(u_g > 0.7) & (u_g < 1.35) & (g_r > -0.15) & (g_r < 0.4) & (r_i > -0.15) & (r_i < 0.22) & (i_z > -0.21) & (i_z < 0.25)] #---------------------------------------------------------------------- # get magnitudes and colors; split into train and test sets mags_rr = np.vstack([rrlyrae[f + 'mag'] for f in 'ugriz']) colors_rr = mags_rr[:-1] - mags_rr[1:] mags_st = np.vstack([standards['mmu_' + f] for f in 'ugriz']) colors_st = mags_st[:-1] - mags_st[1:] # stack the two sets of colors together X = np.vstack((colors_st.T, colors_rr.T)) y = np.zeros(X.shape[0]) y[-colors_rr.shape[1]:] = 1 return X, y
more effectively show very dense scatter plots. """ # Author: Jake VanderPlas <*****@*****.**> # License: BSD # The figure produced by this code is published in the textbook # "Statistics, Data Mining, and Machine Learning in Astronomy" (2013) # For more information, see http://astroML.github.com from matplotlib import pyplot as plt from astroML.plotting import scatter_contour from astroML.datasets import fetch_sdss_S82standards #------------------------------------------------------------ # Fetch the Stripe 82 standard star catalog data = fetch_sdss_S82standards() g = data['mmu_g'] r = data['mmu_r'] i = data['mmu_i'] #------------------------------------------------------------ # plot the results ax = plt.axes() scatter_contour(g - r, r - i, threshold=200, log_counts=True, ax=ax, histogram2d_args=dict(bins=40), plot_args=dict(marker='.',
from astroML.plotting import scatter_contour from astroML.datasets import fetch_sdss_S82standards #---------------------------------------------------------------------- # This function adjusts matplotlib settings for a uniform feel in the textbook. # Note that with usetex=True, fonts are rendered with LaTeX. This may # result in an error if LaTeX is not installed on your system. In that case, # you can set usetex to False. from astroML.plotting import setup_text_plots setup_text_plots(fontsize=8, usetex=True) #------------------------------------------------------------ # Fetch the Stripe 82 standard star catalog data = fetch_sdss_S82standards() g = data['mmu_g'] r = data['mmu_r'] i = data['mmu_i'] #------------------------------------------------------------ # plot the results fig, ax = plt.subplots(figsize=(5, 3.75)) scatter_contour(g - r, r - i, threshold=200, log_counts=True, ax=ax, histogram2d_args=dict(bins=40), plot_args=dict(marker=',', linestyle='none', color='black'), contour_args=dict(cmap=plt.cm.bone)) ax.set_xlabel(r'${\rm g - r}$') ax.set_ylabel(r'${\rm r - i}$')
data_noisy = fetch_imaging_sample() # select only stars data_noisy = data_noisy[data_noisy['type'] == 6] # Get the extinction-corrected magnitudes for each band X = np.vstack([data_noisy[f + 'RawPSF'] for f in 'ugriz']).T Xerr = np.vstack([data_noisy[f + 'psfErr'] for f in 'ugriz']).T # extinction terms from Berry et al, arXiv 1111.4985 X -= (extinction_vector * data_noisy['rExtSFD'][:, None]) #---------------------------------------------------------------------- # Fetch and process the stacked imaging data data_stacked = fetch_sdss_S82standards() # cut to RA, DEC range of imaging sample RA = data_stacked['RA'] DEC = data_stacked['DEC'] data_stacked = data_stacked[(RA > 0) & (RA < 10) & (DEC > -1) & (DEC < 1)] # get stacked magnitudes for each band Y = np.vstack([data_stacked['mmu_' + f] for f in 'ugriz']).T Yerr = np.vstack([data_stacked['msig_' + f] for f in 'ugriz']).T # extinction terms from Berry et al, arXiv 1111.4985 Y -= (extinction_vector * data_stacked['A_r'][:, None]) # quality cuts
This demonstrates how to fetch and plot the colors of the SDSS Stripe 82 standard stars, both alone and with the cross-matched 2MASS colors. """ # Author: Jake VanderPlas <*****@*****.**> # License: BSD # The figure is an example from astroML: see http://astroML.github.com import numpy as np from matplotlib import pyplot as plt from astroML.datasets import fetch_sdss_S82standards from astroML.plotting import MultiAxes #------------------------------------------------------------ # Plot SDSS data alone data = fetch_sdss_S82standards() colors = np.zeros((len(data), 4)) colors[:, 0] = data['mmu_u'] - data['mmu_g'] colors[:, 1] = data['mmu_g'] - data['mmu_r'] colors[:, 2] = data['mmu_r'] - data['mmu_i'] colors[:, 3] = data['mmu_i'] - data['mmu_z'] labels = ['u-g', 'g-r', 'r-i', 'i-z'] bins = [ np.linspace(0.0, 3.5, 100), np.linspace(0, 2, 100), np.linspace(-0.2, 1.8, 100), np.linspace(-0.2, 1.0, 100)
standard stars, both alone and with the cross-matched 2MASS colors. """ # Author: Jake VanderPlas <*****@*****.**> # License: BSD # The figure is an example from astroML: see http://astroML.github.com import numpy as np from matplotlib import pyplot as plt from astroML.datasets import fetch_sdss_S82standards from astroML.plotting import MultiAxes #------------------------------------------------------------ # Plot SDSS data alone data = fetch_sdss_S82standards() colors = np.zeros((len(data), 4)) colors[:, 0] = data['mmu_u'] - data['mmu_g'] colors[:, 1] = data['mmu_g'] - data['mmu_r'] colors[:, 2] = data['mmu_r'] - data['mmu_i'] colors[:, 3] = data['mmu_i'] - data['mmu_z'] labels = ['u-g', 'g-r', 'r-i', 'i-z'] bins = [np.linspace(0.0, 3.5, 100), np.linspace(0, 2, 100), np.linspace(-0.2, 1.8, 100), np.linspace(-0.2, 1.0, 100)]
# Fetch and process the noisy imaging data data_noisy = fetch_imaging_sample() # select only stars data_noisy = data_noisy[data_noisy['type'] == 6] # Get the extinction-corrected magnitudes for each band X = np.vstack([data_noisy[f + 'RawPSF'] for f in 'ugriz']).T Xerr = np.vstack([data_noisy[f + 'psfErr'] for f in 'ugriz']).T # extinction terms from Berry et al, arXiv 1111.4985 X -= (extinction_vector * data_noisy['rExtSFD'][:, None]) #---------------------------------------------------------------------- # Fetch and process the stacked imaging data data_stacked = fetch_sdss_S82standards() # cut to RA, DEC range of imaging sample RA = data_stacked['RA'] DEC = data_stacked['DEC'] data_stacked = data_stacked[(RA > 0) & (RA < 10) & (DEC > -1) & (DEC < 1)] # get stacked magnitudes for each band Y = np.vstack([data_stacked['mmu_' + f] for f in 'ugriz']).T Yerr = np.vstack([data_stacked['msig_' + f] for f in 'ugriz']).T # extinction terms from Berry et al, arXiv 1111.4985 Y -= (extinction_vector * data_stacked['A_r'][:, None]) # quality cuts g = Y[:, 1]
from astroML.datasets import fetch_sdss_S82standards import matplotlib.pyplot as plt data_unmatched = fetch_sdss_S82standards() g_u = data_unmatched['mmu_g'] r_u = data_unmatched['mmu_r'] i_u = data_unmatched['mmu_i'] data_matched = fetch_sdss_S82standards(crossmatch_2mass=True) g_m = data_matched['mmu_g'] r_m = data_matched['mmu_r'] i_m = data_matched['mmu_i'] # Plot of the unmatched (all) stars plt.figure(figsize=[16, 9]) plt.scatter(g_u - r_u, r_u - i_u, s=4, c='black') plt.xlabel('g-r color') plt.ylabel('r-i color') plt.xlim(-2, 4) plt.ylim(-2, 4) plt.title('Non-crossmatched SDSS Data') plt.savefig('unmatched.png') plt.close() # Plot of the matched stars fig = plt.figure(figsize=[16, 9]) plt.scatter(g_m - r_m, r_m - i_m, s=4, c='black') plt.xlabel('g-r color') plt.ylabel('r-i color') plt.xlim(-2, 4) plt.ylim(-2, 4)