<jupyter_start><jupyter_text>NSFfigures for the grant proposal<jupyter_code>%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib
from astropy.table import Table
from scipy.optimize import curve_fit

from scipy.stats import binned_statistic_2d

matplotlib.rcParams.update({'font.size':18})
matplotlib.rcParams.update({'font.family':'serif'})

ftype = '.pdf'
Gfile = '../data/kepler_dr2_1arcsec.fits' # from http://gaia-kepler.fun, thanks to M. Bedell
data = Table.read(Gfile, format='fits')
gaia = data.to_pandas()
print(gaia.shape)

rot_file = '../data/Table_Periodic.txt'
rot = pd.read_csv(rot_file)
df = pd.merge(rot, gaia, right_on='kepid', left_on='KID')
print(df.shape)

ok = np.where(np.isfinite(df[u'parallax']) & # this is basically the same as the TGAS file...
              (df[u'parallax_error'] < 0.1) &
              (df[u'r_modality_flag'] == 1) & 
              (df[u'r_result_flag'] == 1) &
              np.isfinite(df[u'bp_rp']) & 
              (df[u'phot_bp_mean_flux_error']/df[u'phot_bp_mean_flux'] < 0.01) & 
              (df[u'phot_rp_mean_flux_error']/df[u'phot_rp_mean_flux'] < 0.01) & 
              (df[u'phot_g_mean_flux_error']/df[u'phot_g_mean_flux'] < 0.01))[0]
print(ok.shape)<jupyter_output>(195830, 101)
(33538, 112)
(30305,)<jupyter_text>We can re-make the key figure very simply after applying sensible selection cuts (`ok = ` above)<jupyter_code># cm = plt.cm.get_cmap('Spectral_r')
cm = plt.cm.RdBu_r


fig, ax1 = plt.subplots(figsize=(8,7))

plt.scatter(df[u'bp_rp'].values[ok], 
            df[u'phot_g_mean_mag'].values[ok] - 5. * np.log10(df[u'r_est'].values[ok])  + 5, 
            c=(df[u'Prot'].values[ok]), alpha=0.7, s=2, cmap=cm)

plt.clim(3, 55)
plt.ylim(11,0)
plt.xlim(.5,2.7)
plt.xlabel('$G_{BP} - G_{RP}$ (mag)')
plt.ylabel('$M_G$ (mag)')

cb = plt.colorbar()
cb.set_label('P$_{rot}$ (days)')
plt.savefig('../figures/NSF_cmd1'+ftype, dpi=300, bbox_inches='tight', pad_inches=0.25)
cm = plt.cm.RdBu_r

plt.figure(figsize=(8,7))


plt.scatter(df[u'bp_rp'].values[ok], 
            df[u'phot_g_mean_mag'].values[ok] - 5. * np.log10(df[u'r_est'].values[ok]) + 5, 
            c=(df[u'Prot'].values[ok]), 
            alpha=0.75, s=40, cmap=cm, edgecolors='k', lw=0)

plt.clim(3, 45)

plt.ylim(7.52, 6)
plt.xlim(1.3, 1.7)

plt.xlabel('$G_{BP} - G_{RP}$ (mag)')
plt.ylabel('$M_G$ (mag)')

cb = plt.colorbar()
cb.set_label('P$_{rot}$ (days)')

# put 2 lines down: the running medians of stars w/ Prot =[0,10], and medians of stars w/ Prot=[20,50]

mg1 = np.zeros(9, dtype=np.float)
mg2 = np.zeros(9, dtype=np.float)
for k in range(9):
    cb1 = np.where((df[u'bp_rp'].values[ok] >= 1.3+k*0.05) & 
                   (df[u'bp_rp'].values[ok] < 1.3+(k+1)*0.05) & 
                   (df[u'Prot'].values[ok] > 0) & 
                   (df[u'Prot'].values[ok] < 20))[0]
    
    cb2 = np.where((df[u'bp_rp'].values[ok] >= 1.3+k*0.05) & 
                   (df[u'bp_rp'].values[ok] < 1.3+(k+1)*0.05) & 
                   (df[u'Prot'].values[ok] > 40) & 
                   (df[u'Prot'].values[ok] < 75))[0]
    mg1[k] = np.nanmedian(df[u'phot_g_mean_mag'].values[ok][cb1] - 5. * np.log10(df[u'r_est'].values[ok][cb1]) + 5)
    mg2[k] = np.nanmedian(df[u'phot_g_mean_mag'].values[ok][cb2] - 5. * np.log10(df[u'r_est'].values[ok][cb2]) + 5)

plt.plot(np.arange(1.3, 1.75, 0.05), mg2, c='r', lw=6, alpha=0.6, label='P$_{rot} >$40d')
plt.plot(np.arange(1.3, 1.75, 0.05), mg1, c='b', lw=6, alpha=0.6, label='P$_{rot} <$20d')

plt.legend(loc='upper right', fontsize=12)

plt.savefig('../figures/NSF_cmd2'+ftype, dpi=300, bbox_inches='tight', pad_inches=0.25)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21041273266792554, 'fraction_numerical': 0.050445103857566766, 'mean_word_length': 3.6176836861768367, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '283221', 'license': 'MIT', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1633, 'n_words': 250, 'path': 'notebooks/NSF_figs.ipynb', 'repo_name': 'jradavenport/gaia2_kep_rot', 'size': '3707'}