ApJdataFrames
001: Luhman2003Title
: A Census of the Young Cluster IC 348
Authors
: Luhman K.L., Stauffer J.R., Muench A.A., Rieke G.H., Lada E.A., Bouvier J., Lada C.J.
Data is from this paper: http://iopscience.iop.org/0004-637X/593/2/1093/
In [1]:
%pylab inline
import seaborn as sns
sns.set_context("notebook", font_scale=1.5)
import warnings
warnings.filterwarnings("ignore")
We're skipping Table 1 because it is an observing log.
Since this table is formatted in the CDS
format, it is easiest to take advantage of the Astropy
functionality, ascii.read
, which automatically detects the header formatting. We will also take advantage of the fact that ascii.read
can accept a url as an argument, so we won't have to actually save the data locally. Let's hope ApJ doesn't change their web link though.
In [2]:
from astropy.io import ascii
In [3]:
#!curl -o ../data/Luhman2003/Luhman2003_Table2.txt http://iopscience.iop.org/0004-637X/593/2/1093/fulltext/datafile2.txt
In [4]:
data = ascii.read("http://iopscience.iop.org/0004-637X/593/2/1093/fulltext/datafile2.txt")
In [5]:
data[0:2]
Out[5]:
In [6]:
print data.colnames
I am using seaborn (imported as sns
), to set nice-looking figure deafaults.
In [7]:
cmap = sns.palettes.cubehelix_palette(start=0.2, rot=0.7,as_cmap=True)
sns.palplot(sns.palettes.cubehelix_palette(start=0.2, rot=0.7))
In [8]:
plt.figure(figsize=(4.5, 9))
plt.scatter(data['I-Z'].data, data['H-K'].data + data['Kmag'].data, c=data['AJ'].data, cmap=cmap)
plt.xlim(0, 1.2)
plt.ylim(18.5, 9.5)
cbar = plt.colorbar()
cbar.set_label('$A_J$')
plt.xlabel("$I-Z$")
plt.ylabel("$H$")
Out[8]:
This table is not formatted as CDS. Instead it is just raw $\LaTeX$, with no header columns. So I will have to assign the column names manually, which I copy and paste and parse by hand. Then I use pandas (imported as pd
) to read the tab-separated file (sep='\t'
).
In [9]:
import pandas as pd
In [10]:
col_names = ["ID","RA","Dec","SpectralType","Ref","ForegroundEvidence","R-I","I","I-Z","J-H","H-Ks","Ks"]
tbl3 = pd.read_csv('http://iopscience.iop.org/0004-637X/593/2/1093/fulltext/57692.tb3.txt', sep='\t',
header=None, na_values='\ldots', names=col_names)
In [11]:
tbl3.head()
Out[11]:
In [12]:
plt.figure(figsize=(4.5, 9))
plt.scatter(data['I-Z'].data, data['H-K'].data + data['Kmag'].data, c=data['AJ'].data, cmap=cmap, label='Members')
plt.plot(tbl3['I-Z'], tbl3['H-Ks']+tbl3['Ks'], 'rs', label='Foreground')
plt.xlim(0, 1.2)
plt.ylim(18.5, 9.5)
cbar = plt.colorbar()
cbar.set_label('$A_J$')
plt.xlabel("$I-Z$")
plt.ylabel("$H$")
plt.legend(loc='lower left')
Out[12]:
In [13]:
col_names = ["ID","RA","Dec","SpectralType","Ref","R-I","I","I-Z","J-H","H-Ks","Ks"]
tbl4 = pd.read_csv('http://iopscience.iop.org/0004-637X/593/2/1093/fulltext/57692.tb4.txt', sep='\t',
header=None, na_values='\ldots', names=col_names)
In [14]:
tbl4.head()
Out[14]:
In [15]:
plt.figure(figsize=(4.5, 9))
plt.scatter(data['I-Z'].data, data['H-K'].data + data['Kmag'].data, c=data['AJ'].data, cmap=cmap, label='Members')
plt.plot(tbl3['I-Z'], tbl3['H-Ks']+tbl3['Ks'], 'r.', label='Foreground')
plt.plot(tbl4['I-Z'], tbl4['H-Ks']+tbl3['Ks'], 'bs', label='Background')
plt.xlim(0, 1.2)
plt.ylim(18.5, 9.5)
cbar = plt.colorbar()
cbar.set_label('$A_J$')
plt.xlabel("$I-Z$")
plt.ylabel("$H$")
plt.legend(loc='lower left')
Out[15]:
In [16]:
tbl8 = pd.read_csv("http://iopscience.iop.org/0004-637X/593/2/1093/fulltext/57692.tb8.txt",
names = ["Spectral_Type", "Teff"],
sep = '\t')
tbl8
Out[16]:
Covert string spectral type to numerical type.
In [17]:
import gully_custom
tbl8["SpT"] = gully_custom.specType(tbl8.Spectral_Type)
In [18]:
sns.lmplot("SpT", "Teff", tbl8)
Out[18]:
In [19]:
tbl2 = data.to_pandas()
! mkdir ../data/Luhman2003
In [30]:
for tbl, outname in zip([tbl2, tbl3, tbl4, tbl8], "tbl2, tbl3, tbl4, tbl8".split(", ")):
tbl.to_csv("../data/Luhman2003/"+outname+".csv", sep='\t', index=False)
The end.