ApJdataFrames 008: Luhman2012

Title: THE DISK POPULATION OF THE UPPER SCORPIUS ASSOCIATION
Authors: K. L. Luhman and E. E. Mamajek

Data is from this paper:
http://iopscience.iop.org/0004-637X/758/1/31/article#apj443828t1


In [1]:
import warnings
warnings.filterwarnings("ignore")

In [2]:
from astropy.io import ascii

In [3]:
import pandas as pd

Table 1 - VOTable with all source properties


In [4]:
tbl1 = ascii.read("http://iopscience.iop.org/0004-637X/758/1/31/suppdata/apj443828t1_mrt.txt")


Downloading http://iopscience.iop.org/0004-637X/758/1/31/suppdata/apj443828t1_mrt.txt [Done]

In [5]:
tbl1.columns


Out[5]:
<TableColumns names=('Name','OtherNames','SpType','r_SpType','Adopt','3.6mag','e_3.6mag','f_3.6mag','4.5mag','e_4.5mag','f_4.5mag','5.8mag','e_5.8mag','f_5.8mag','8.0mag','e_8.0mag','f_8.0mag','24mag','e_24mag','f_24mag','W1mag','e_W1mag','f_W1mag','W2mag','e_W2mag','f_W2mag','W3mag','e_W3mag','f_W3mag','W4mag','e_W4mag','f_W4mag','Exc4.5','Exc8.0','Exc24','ExcW2','ExcW3','ExcW4','DiskType')>

In [6]:
tbl1[0:5]


Out[6]:
<Table masked=True length=5>
NameOtherNamesSpTyper_SpTypeAdopt3.6mage_3.6magf_3.6mag4.5mage_4.5magf_4.5mag5.8mage_5.8magf_5.8mag8.0mage_8.0magf_8.0mag24mage_24magf_24magW1mage_W1magf_W1magW2mage_W2magf_W2magW3mage_W3magf_W3magW4mage_W4magf_W4magExc4.5Exc8.0Exc24ExcW2ExcW3ExcW4DiskType
magmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmagmag
string224string344string184string104string64float64float64string40float64float64string40float64float64string40float64float64string40float64float64string40float64float64string40float64float64string40float64float64string40float64float64string40string8string8string16string16string16string16string128
2MASS J15321033-2158004HD 138343,HIP 76071B9V1B9V----out7.050.02------out7.120.03--7.090.04--7.020.03--7.060.02--7.090.02--7.130.11--NNNNNN--
2MASS J15350863-2532397--M5.52M5.5----out----out----out----out----out13.370.03--13.140.03------false----nodet------N------
2MASS J15351610-2544030HD 138813,HIP 76310A0V1A0V----out7.150.02------out7.160.03--4.080.04--7.140.03--7.180.02--6.720.02--4.230.02--NNYNYYdebris/ev trans
2MASS J15354856-2958551RX J1535.8-2958M43M4----out----out----out----out----out9.180.02--8.840.02--7.090.02--5.150.03--------YYYfull
2MASS J15355111-2021008--M82M8----out----out----out----out----out13.450.03--13.080.04------nodet----nodet------N------

In [7]:
len(tbl1)


Out[7]:
863

Cross match with SIMBAD


In [8]:
from astroquery.simbad import Simbad
import astropy.coordinates as coord
import astropy.units as u

In [9]:
customSimbad = Simbad()
customSimbad.add_votable_fields('otype', 'sptype')

In [10]:
query_list = tbl1["Name"].data.data
result = customSimbad.query_objects(query_list, verbose=True)

In [11]:
result[0:3]


Out[11]:
<Table masked=True length=3>
MAIN_IDRADECRA_PRECDEC_PRECCOO_ERR_MAJACOO_ERR_MINACOO_ERR_ANGLECOO_QUALCOO_WAVELENGTHCOO_BIBCODEOTYPESP_TYPESP_QUALSP_NATURESP_BIBCODE
"h:m:s""d:m:s"masmasdeg
objectstring104string104int16int16float32float32int16string8string8objectobjectobjectstring8string8object
HD 13834315 32 10.3328-21 58 00.560997.7305.34090AO2007A&A...474..653VStarB9VC1988MSS...C04....0H
2MASS J15350863-253239715 35 08.640-25 32 39.737760.00060.00045BN2003yCat.2246....0CStar
HD 13881315 35 16.1054-25 44 03.006995.3604.47090AO2007A&A...474..653VStarA0VC1988MSS...C04....0H

In [12]:
print "There were {} sources queried, and {} sources found.".format(len(query_list), len(result))
if len(query_list) == len(result):
    print "Hooray!  Everything matched"
else:
    print "Which ones were not found?"


There were 863 sources queried, and 862 sources found.
Which ones were not found?

In [13]:
def add_input_column_to_simbad_result(self, input_list, verbose=False):
    """
    Adds 'INPUT' column to the result of a Simbad query

    Parameters
    ----------
    object_names : sequence of strs
            names of objects from most recent query
    verbose : boolean, optional
        When `True`, verbose output is printed

    Returns
    -------
    table : `~astropy.table.Table`
        Query results table
    """
    error_string = self.last_parsed_result.error_raw
    fails = []

    for error in error_string.split("\n"):
        start_loc = error.rfind(":")+2
        fail = error[start_loc:]
        fails.append(fail)

    successes = [s for s in input_list if s not in fails]
    if verbose:
        out_message = "There were {} successful Simbad matches and {} failures."
        print out_message.format(len(successes), len(fails))

    self.last_parsed_result.table["INPUT"] = successes

    return self.last_parsed_result.table

In [14]:
result_fix = add_input_column_to_simbad_result(customSimbad, query_list, verbose=True)


There were 862 successful Simbad matches and 1 failures.
Failures are:  [u'Oph J1622-2405 B']

In [17]:
tbl1_pd = tbl1.to_pandas()
result_pd = result_fix.to_pandas()
tbl1_plusSimbad = pd.merge(tbl1_pd, result_pd, how="left", left_on="Name", right_on="INPUT")

Save the data table locally.


In [19]:
tbl1_plusSimbad.head()


Out[19]:
Name OtherNames SpType r_SpType Adopt 3.6mag e_3.6mag f_3.6mag 4.5mag e_4.5mag ... COO_ERR_ANGLE COO_QUAL COO_WAVELENGTH COO_BIBCODE OTYPE SP_TYPE SP_QUAL SP_NATURE SP_BIBCODE INPUT
0 2MASS J15321033-2158004 HD 138343,HIP 76071 B9V 1 B9V NaN NaN out 7.05 0.02 ... 90 A O 2007A&A...474..653V Star B9V C 1988MSS...C04....0H 2MASS J15321033-2158004
1 2MASS J15350863-2532397 NaN M5.5 2 M5.5 NaN NaN out NaN NaN ... 45 B N 2003yCat.2246....0C Star 2MASS J15350863-2532397
2 2MASS J15351610-2544030 HD 138813,HIP 76310 A0V 1 A0V NaN NaN out 7.15 0.02 ... 90 A O 2007A&A...474..653V Star A0V C 1988MSS...C04....0H 2MASS J15351610-2544030
3 2MASS J15354856-2958551 RX J1535.8-2958 M4 3 M4 NaN NaN out NaN NaN ... 90 B I 2003yCat.2246....0C ** M4 D 2000A&A...356..541K 2MASS J15354856-2958551
4 2MASS J15355111-2021008 NaN M8 2 M8 NaN NaN out NaN NaN ... 17 B N 2003yCat.2246....0C Star 2MASS J15355111-2021008

5 rows × 56 columns


In [20]:
! mkdir ../data/Luhman2012/


mkdir: ../data/Luhman2012/: File exists

In [22]:
tbl1_plusSimbad.to_csv("../data/Luhman2012/tbl1_plusSimbad.csv", index=False)

The end