def vars_match(primary_table=WUVARS_allvars_f):
    """ 
    A function that matches our variables table to all the other tables!

    Takes about 15 seconds (2/13/13).
    """

    return tablemate_core.tablemater(primary_table, tables)
def vars_match():
    """ 
    A function that matches our variables table to all the other tables!

    Takes about 15 seconds (2/13/13).
    """

    return tablemate_core.tablemater( Rice_2013_vars, tables)
def vars_match(primary_table=WUVARS_allvars_f):
    """ 
    A function that matches our variables table to all the other tables!

    Takes about 15 seconds (2/13/13).
    """

    return tablemate_core.tablemater( primary_table, tables)
Example #4
0
def match_chandra_to_ukirt():
    """ 
    A function that performs an "inverse" cross-match between 
    X-ray selected sources from Chandra/Getman2002, and our UKIRT stars.

    """

    # Produces a table of cross-match IDs and indices.
    mated_chandra = tablemater(Getman_2002, q2_wfcam_stars)

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    # in approximate english: "the stats table, where you take the row
    # handed to you by the mated table, but only where there's a match"
    # Q2
    ax.hist(q2_stars.Stetson[mated_chandra.where(
        mated_chandra['WFCAM_q2_stars_index'] != -1)['WFCAM_q2_stars_index']],
            range=[0, 20],
            bins=60,
            color='b',
            label="Q=2")

    ax.set_xlabel("Stetson Index")
    ax.set_ylabel(
        "Number of stars which are in both UKIRT(Q=2) and Chandra/ACIS")
    ax.set_title("Variability of X-ray sources from Getman et al. 2002")

    fig_range = plt.figure()
    ax_range = fig_range.add_subplot(1, 1, 1)

    # in approximate english: "the stats table, where you take the row
    # handed to you by the mated table, but only where there's a match"
    # Q2
    ax_range.hist(q2_stars.k_ranger[mated_chandra.where(
        mated_chandra['WFCAM_q2_stars_index'] != -1)['WFCAM_q2_stars_index']],
                  range=[0, 2],
                  bins=20,
                  color='b',
                  label="Q=2")

    ax_range.set_xlabel(r"$\Delta K$ (mag)")
    ax_range.set_ylabel(
        "Number of stars which are in both UKIRT(Q=2) and Chandra/ACIS")
    ax_range.set_title("Variability of YSOs from Getman et al. 2002")

    return mated_chandra
def match_chandra_to_ukirt():
    """ 
    A function that performs an "inverse" cross-match between 
    X-ray selected sources from Chandra/Getman2002, and our UKIRT stars.

    """

    # Produces a table of cross-match IDs and indices.
    mated_chandra = tablemater(Getman_2002, q2_wfcam_stars)

    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)

    # in approximate english: "the stats table, where you take the row 
    # handed to you by the mated table, but only where there's a match"
    # Q2
    ax.hist( 
        q2_stars.Stetson[ 
            mated_chandra.where(mated_chandra['WFCAM_q2_stars_index'] != -1)['WFCAM_q2_stars_index'] 
            ], 
        range=[0,20], bins=60, color='b', label="Q=2"
        )

    ax.set_xlabel("Stetson Index")
    ax.set_ylabel("Number of stars which are in both UKIRT(Q=2) and Chandra/ACIS")
    ax.set_title("Variability of X-ray sources from Getman et al. 2002")

    fig_range = plt.figure()
    ax_range = fig_range.add_subplot(1,1,1)

    # in approximate english: "the stats table, where you take the row 
    # handed to you by the mated table, but only where there's a match"
    # Q2
    ax_range.hist( 
        q2_stars.k_ranger[ 
            mated_chandra.where(mated_chandra['WFCAM_q2_stars_index'] != -1)['WFCAM_q2_stars_index'] 
            ], 
        range=[0,2], bins=20, color='b', label="Q=2"
        )

    ax_range.set_xlabel(r"$\Delta K$ (mag)")
    ax_range.set_ylabel("Number of stars which are in both UKIRT(Q=2) and Chandra/ACIS")
    ax_range.set_title("Variability of YSOs from Getman et al. 2002")

    return mated_chandra
def test():
    wov = tablemate_core.osc.autovars_strict

    wov_avs = TableParameters(
        #data
        wov,
        #alias
        "WFCAM Orion",
        #full name
        "Strict automatic variables found in the WFCAM Orion monitoring survey. From 'High Amplitude and Periodic Near-Infrared Variables in the Orion Nebula Cluster' by Rice, Thomas S.; Reipurth, Bo; et al.",
        #ra_cols, dec_cols
        ['RA'], ['DEC'],
        #radec_fmt
        'decimal radians',
        #name_col
        'SOURCEID')


    return tablemate_core.tablemater(wov_avs, [
            Herbst2002, YSOVAR_NoExcess, YSOVAR_YSOs, DaRio_2010,
            DaRio_2009, Carpenter_2001, COUP_Getman2005, eso_ha])
def UKvars_match():
    
    return tablemate_core.tablemater( Rice_UKvars, tables)
dropbox_bo = os.path.expanduser("~/Dropbox/Bo_Tom/")
output_directory = dropbox_bo+"paper/publication_tables/"


# Let's grab IRAC colors from Megeath.
megeath2012_by_ukvar = index_secondary_by_primary(mated_ukvar, 
                                                  Megeath2012)
megeath2012_full_by_ukvar = index_secondary_by_primary(mated_ukvar, 
                                                       Megeath_Full)
megeath2012_all_by_ukvar = index_secondary_by_primary(mated_ukvar,
                                                      Megeath_Allgoodsources)

# XMM catalog gets matched too.
XMM_north_by_ukvar = index_secondary_by_primary(
    tablemater(Rice_UKvars, [XMM_north]), XMM_north)

# And let's make some color slope references that we like.
jhk_slope_reference = filter_color_slopes(autovars_strict, 'jhk',
                                          slope_confidence=0.5)
jh_slope_reference = filter_color_slopes(autovars_true, 'jh',
                                         slope_confidence=0.5)
hk_slope_reference = filter_color_slopes(autovars_true, 'hk',
                                         slope_confidence=0.5)

def clobber_table_write(table, filename, **kwargs):
    """ Writes a table, even if it has to clobber an older one. """

    try:
        table.write(filename, **kwargs)
    except Exception, e: 
def test():

    return tablemate_core.tablemater(
        WUVARS_maxvars_p,
        [Twomass, Gutermuth_2008, Scholz_2009, Wilking_2004, Getman_2002])
def test():


    return tablemate_core.tablemater(WUVARS_maxvars_p, [Twomass, Gutermuth_2008, Scholz_2009, Wilking_2004, Getman_2002])
def match_xmm_to_ukirt():
    """ 
    A function that performs an "inverse" cross-match between 
    X-ray selected sources from XMM, and our UKIRT stars.

    """

    # Produces a table of cross-match IDs and indices.
    mated_xmm = tablemater(XMM_north, ukirt_list)
    
    mated_c1 =  tablemater(XMM_north_c1, ukirt_list)
    mated_c2 =  tablemater(XMM_north_c2, ukirt_list)
    mated_c3 =  tablemater(XMM_north_c3, ukirt_list)

    mated_list = [mated_xmm, mated_c1, mated_c2, mated_c3]

    # What kinds of plots do we want?
    # Histogram of S, for each xray category (incl. "all")
    fig = plt.figure()

    uks_i = 'UKIRT_autocan_strict_allstars_index'
    uks_d = autocan_strict

    uka_i = 'UKIRT_autocan_true_allstars_index'
    uka_d = autocan_true

    s1 = plt.subplot(4,1,1)
    s2 = plt.subplot(4,1,2)
    s3 = plt.subplot(4,1,3)
    s4 = plt.subplot(4,1,4)

    subplot_list = [s1, s2, s3, s4]
    name_list = ["all XMM sources",
                 "Class 1 XMM sources",
                 "Class 2 XMM sources",
                 "Class 3 XMM sources"]

    for s, m, name in zip(subplot_list, mated_list, name_list):
        # in approximate english: "the stats table, where you take the row 
        # handed to you by the mated table, but only where there's a match"
        try:
            # AUTO
            s.hist( 
                uka_d.Stetson[ 
                    m.where(m[uka_i] != -1)[uka_i] 
                    ], 
                range=[0,5], bins=20, color='0.7', label="1-band pristine"
                )
        except: pass
        try:
            # STRICT
            s.hist( 
                uks_d.Stetson[ 
                    m.where(m[uks_i] != -1)[uks_i] 
                    ], 
                range=[0,5], bins=20, color='0.2', label="3-band pristine"
                )
        except: pass

        # annotate each subplot so they're readable
        if s == s1:
            s.text(0.35, 0.75, name, transform=s.transAxes)
        else:
            s.text(0.65, 0.75, name, transform=s.transAxes)
        

    s1.set_title("Histogram: Stetson indices of X-ray-selected stars in ONC")
    s1.legend()
    s4.set_xlabel("Stetson Index")
    plt.show()


    # Now, I want to print out some stats relevant to what we want.
    # Think of how "official_star_counter" works.

    # For each group, print the stuff.

    for s, m, name in zip(subplot_list, mated_list, name_list):
        # Median S and MAD?
        auto_stetson = uka_d.Stetson[m.where(m[uka_i] != -1)[uka_i]]
        strict_stetson = uks_d.Stetson[m.where(m[uks_i] != -1)[uks_i]]

        print ("%s Median Stetson for Q=1+2: %.3f +- %.2f" % 
               (name, np.median(auto_stetson), rb.mad(auto_stetson)))
        print "N = %d" % len(auto_stetson)        
        print ("%s Median Stetson for Q=2: %.3f +- %.2f" % 
               (name, np.median(strict_stetson), rb.mad(strict_stetson)))
        print "N = %d" % len(strict_stetson)        
        
    for s, m, name in zip(subplot_list, mated_list, name_list):
        # Median Delta Mag (and MAD)?
#        auto_delta = uka_d.[m.where(m[uka_i] != -1)[uka_i]]# doesn't quite work
        strict_delta = uks_d.k_range[m.where(m[uks_i] != -1)[uks_i]]

        print ("%s Median delta-K (max-min) for strict-stars: %.3f +- %.2f" % 
               (name, np.median(strict_delta), rb.mad(strict_delta)))
        print "N = %d" % len(strict_delta)


        # What fraction have good periods? Not answerable right now.

    return mated_xmm, mated_c1, mated_c2, mated_c3
def match_spitzer_to_ukirt():
    """ 
    A function that performs an "inverse" cross-match between 
    mid-IR selected sources from Spitzer/Megeath2012, and our UKIRT stars.

    """

    # Produces a table of cross-match IDs and indices.
    mated_spitzer = tablemater(Megeath2012, ukirt_list)
    
    # Clearly, we need to update this to use slices of the Megeath table
    # filtered on Class.
    mated_P =  tablemater(Megeath_P, ukirt_list)
    mated_D =  tablemater(Megeath_D, ukirt_list)
    mated_ND = tablemater(Megeath_ND, ukirt_list)

    mated_list = [mated_P, mated_D, mated_ND]

    # What kinds of plots do we want?
    # Histogram of S, for each IR category
    fig = plt.figure()

    uks_i = 'UKIRT_autocan_strict_allstars_index'
    uks_d = autocan_strict

    uka_i = 'UKIRT_autocan_true_allstars_index'
    uka_d = autocan_true

    s1 = plt.subplot(3,1,1)
    s2 = plt.subplot(3,1,2)
    s3 = plt.subplot(3,1,3)

    subplot_list = [s1, s2, s3]
    name_list = ["Spitzer Protostars",
                 "Spitzer Disked sources",
                 "Spitzer Non-Disked sources"]

    for s, m, name in zip(subplot_list, mated_list, name_list):
        # in approximate english: "the stats table, where you take the row 
        # handed to you by the mated table, but only where there's a match"
        try:
            # AUTO
            s.hist( 
                uka_d.Stetson[ 
                    m.where(m[uka_i] != -1)[uka_i] 
                    ], 
                range=[0,5], bins=20, color='0.7', label="Q=1"
                )
        except: pass
        array_in_question = uka_d.Stetson[ 
                    m.where(m[uka_i] != -1)[uka_i] 
                    ]
        print len(array_in_question[array_in_question>5])
        try:
            # STRICT
            s.hist( 
                uks_d.Stetson[ 
                    m.where(m[uks_i] != -1)[uks_i] 
                    ], 
                range=[0,5], bins=20, color='0.2', label="Q=2"
                )
        except: pass

        # Calculate medians.
        auto_stetson = uka_d.Stetson[m.where(m[uka_i] != -1)[uka_i]]
        strict_stetson = uks_d.Stetson[m.where(m[uks_i] != -1)[uks_i]]

        print ("%s Median Stetson for Q=1+2: %.3f +- %.2f" % 
               (name, np.median(auto_stetson), rb.mad(auto_stetson)))
        print "N = %d" % len(auto_stetson)
        print ("%s Median Stetson for Q=2: %.3f +- %.2f" % 
               (name, np.median(strict_stetson), rb.mad(strict_stetson)))
        print "N = %d" % len(strict_stetson)
        
        # annotate each subplot so they're readable
        if s == s1:
            xtext = 0.65
        else:
            xtext = 0.5
            
        s.text(xtext, 0.75,
               "%s\nMedian S: %.2f$\pm$%.2f" % (name, np.median(auto_stetson),
                                                rb.mad(auto_stetson)),
               transform=s.transAxes)
        

    s1.set_title("Histogram: Stetson indices of Spitzer-selected stars in ONC")
    s1.legend(loc="upper left")
    s3.set_xlabel("Stetson Index")
    plt.show()


    # Now, I want to print out some stats relevant to what we want.
    # Think of how "official_star_counter" works.

    # For each group, print the stuff.

    print ""
    for s, m, name in zip(subplot_list, mated_list, name_list):
        # Mean Delta Mag (and sigmas)?
        auto_delta = uka_d.k_ranger[m.where(m[uka_i] != -1)[uka_i]]# doesn't quite work
        strict_delta = uks_d.k_ranger[m.where(m[uks_i] != -1)[uks_i]]

        print ("%s Median delta-K (max-min) for Q=2: %.3f +- %.2f" % 
               (name, np.median(strict_delta), rb.mad(strict_delta)))
        print ("%s Median delta-K (max-min) for Q=1+2: %.3f +- %.2f" % 
               (name, np.median(auto_delta), rb.mad(auto_delta)))


        # What fraction have good periods? Not answerable right now.

    # Finally, let's make a plot of S vs alpha_irac.
    fig2 = plt.figure()

    # define the Stetson column and the alpha_irac column
    m = mated_spitzer

    meg_i = 'Megeath2012_index'
    meg_d = Megeath2012.data

    auto_alpha_irac = meg_d.alpha[m.where(
            m[uka_i] != -1)[meg_i] ]
    strict_alpha_irac = meg_d.alpha[m.where(
            m[uks_i] != -1)[meg_i] ]

    auto_stetson = uka_d.Stetson[m.where(m[uka_i] != -1)[uka_i]]
    strict_stetson = uks_d.Stetson[m.where(m[uks_i] != -1)[uks_i]]

    plt.plot( auto_alpha_irac, auto_stetson, 'o', color='0.7', label="Q=1")
    plt.plot( strict_alpha_irac, strict_stetson, 'o', color='0.2', label="Q=2")
        
    plt.legend()

    plt.xlabel(r"Spectral index $\alpha_{IRAC}$", fontsize=18)
    plt.ylabel("Stetson Index", fontsize=18)

    plt.title(r"Stetson vs $\alpha$ for Spitzer-selected sources")

    plt.semilogy()

    plt.show()

    return mated_spitzer, mated_P, mated_D, fig, fig2