<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Gaia
Real data!
gully
Sept 14, 2016
Outline
Step1:  1. Retrieve existing catalogs
Retrieve Data file from here
Step2:  2. Read in the Gaia data
Step3:  This takes a finite amount of RAM, but should be fine for modern laptops.
Step4:  Match
Step5:  Forced to match to nearest neighbor
Step6:  ... yielding some redundancies in cross matching
Step7:  112 out of 862 have Gaia parallaxes... that seems high for some reason?
<ASSISTANT_TASK:>
Python Code:
#! cat /Users/gully/.ipython/profile_default/startup/start.ipy
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
import pandas as pd
from astropy import units as u
from astropy.coordinates import SkyCoord
Explanation: Gaia
Real data!
gully
Sept 14, 2016
Outline:
More exploring
Import these first-- I auto import them every time!:
End of explanation
d1 = pd.read_csv('../../ApJdataFrames/data/Luhman2012/tbl1_plusSimbad.csv') #local version
d1 = d1[~d1.RA.isnull()]
d1.columns
c1 = SkyCoord(d1.RA.values, d1.DEC.values, unit=(u.hourangle, u.deg), frame='icrs')
Explanation: 1. Retrieve existing catalogs
Retrieve Data file from here:
https://github.com/BrownDwarf/ApJdataFrames/blob/master/data/Luhman2012/tbl1_plusSimbad.csv
End of explanation
df_list = []
Explanation: 2. Read in the Gaia data
End of explanation
for i in range(16):
    df_list.append(pd.read_csv('../data/TgasSource_000-000-{:03d}.csv'.format(i)))
tt = pd.concat(df_list, ignore_index=True)
plt.figure(figsize=(10,4))
ax = sns.jointplot(tt.ra, tt.dec, kind='hex', size=8)
ax.ax_joint.plot(c1.ra.deg, c1.dec.deg, '.', alpha=0.5)
cg = SkyCoord(tt.ra.values, tt.dec.values, unit=(u.deg, u.deg), frame='icrs')
Explanation: This takes a finite amount of RAM, but should be fine for modern laptops.
End of explanation
idx, d2d, blah = c1.match_to_catalog_sky(cg)
vec_units = d2d.to(u.arcsecond)
vec = vec_units.value
bins = np.arange(0, 4, 0.2)
sns.distplot(vec, bins=bins, kde=False),
plt.xlim(0,4)
plt.xlabel('match separation (arcsec)')
Explanation: Match
End of explanation
len(set(idx)), idx.shape[0]
Explanation: Forced to match to nearest neighbor
End of explanation
tt_sub = tt.iloc[idx]
tt_sub = tt_sub.reset_index()
tt_sub = tt_sub.drop('index', axis=1)
d1 = d1.reset_index()
d1 = d1.drop('index', axis=1)
x1 = pd.concat([d1, tt_sub], axis=1)
x1.shape
col_order = d1.columns.values.tolist() + tt_sub.columns.values.tolist()
x1 = x1[col_order]
x0 = x1.copy()
x0['xmatch_sep_as'] = vec
x0['Gaia_match'] = vec < 2.0 #Fairly liberal, 1.0 might be better.
plt.figure(figsize=(8,4))
bins = np.arange(2, 14, 0.2)
sns.distplot(x0.parallax[x0.Gaia_match], bins=bins)
#sns.distplot(1.0/(x0.parallax[x0.Gaia_match]/1000.0))
plt.xlabel('Parallax (mas)')
plt.savefig('../results/luhman_mamajek2012.png', dpi=300)
x0.Gaia_match.sum(), len(d1)
Explanation: ... yielding some redundancies in cross matching
End of explanation
plt.figure(figsize=(10,4))
ax = sns.jointplot(tt.ra, tt.dec, kind='hex', size=8, xlim=(230,255), ylim=(-40,-10))
ax.ax_joint.plot(c1.ra.deg, c1.dec.deg, '.', alpha=0.5)
ax.ax_joint.scatter(x0.ra[x0.Gaia_match], x0.dec[x0.Gaia_match], 
                    s=x0.parallax[x0.Gaia_match]**3*0.2, c='r',alpha=0.5)
Explanation: 112 out of 862 have Gaia parallaxes... that seems high for some reason?
End of explanation
<END_TASK>