コード例 #1
0
def filter_by_tile():
    """
    Splits the input data tables into 16 tiles, avoiding overlap regions.

    Uses the spatial extent of the `maxvars` spreadsheet to figure out
    where the bounds of the tiles are.

    Only returns data pertaining to our 1202 variables.

    Returns
    -------
    tile_tables : list of atpy.Table
        A list of the variable star photometry tables 
        corresponding to each tile.
    tile_spreadsheets : list of atpy.Table
        A list of the variable star variability spreadsheets
        corresponding to each table.
        
    """

    vp = variables_photometry

    max_ra = maxvars.RA.max()
    min_ra = maxvars.RA.min()
    max_dec = maxvars.DEC.max()
    min_dec = maxvars.DEC.min()

    tile_size_ra = (max_ra - min_ra) / 4
    tile_size_dec = (max_dec - min_dec) / 4

    tile_tables = []
    tile_spreadsheets = []
    
    for ra_i in range(4):

        for dec_j in range(4):

            tile_min_ra = min_ra + tile_size_ra*ra_i + tile_size_ra/10
            tile_max_ra = min_ra + tile_size_ra*(ra_i+1) - tile_size_ra/10

            tile_min_dec = min_dec + tile_size_dec*dec_j + tile_size_dec/10
            tile_max_dec = min_dec + tile_size_dec*(dec_j+1) - tile_size_dec/10

            tile_photometry = vp.where(
                (vp.RA > tile_min_ra) & (vp.RA < tile_max_ra) &
                (vp.DEC > tile_min_dec) & (vp.DEC < tile_max_dec) )

            tile_spreadsheet = ukvar_spread.where(
                (ukvar_spread.RA > tile_min_ra) & 
                (ukvar_spread.RA < tile_max_ra) &
                (ukvar_spread.DEC > tile_min_dec) & 
                (ukvar_spread.DEC < tile_max_dec) )

            tile_tables.append(tile_photometry)
            tile_spreadsheets.append(tile_spreadsheet)

    return tile_tables, tile_spreadsheets
コード例 #2
0
def t_table3_variability_nonperiodics_bymegeathclass(write=False):
    """
    Generates Table 3, which also comes in three pieces.

    Only non-periodic stars; has many of the same columns as Table 2.

    Current columns:
      N_j, N_h, N_k : three integers
      Delta-J, H, K: three floats
      Delta-J-H, J-K, H-K: three floats
      Color slopes (JH, HK, JHK): three floats
      Stetson : one float
      Stetson_choice : one string
      Data quality : int (0, 1, 2) corresponding to subjective/auto/strict

    Parameters
    ----------
    write : bool, optional (default False)
        Write to disk? Either way, this function returns an ATpy table.

    """

    table = astropy.table.Table()
    table.table_name = "Table 3"

    nonperiodics = ukvar_spread.where(ukvar_spread.periodic == 0)
    megeath_class_by_nonperiodics = make_megeath_class_column()[ukvar_spread.periodic == 0]

    # Do some stuff where we blank out color slopes that are no good
    jhk_slope_column = nonperiodics.jhk_slope
    jhk_slope_error = nonperiodics.jhk_slope_err
    jhk_slope_column[~np.in1d(nonperiodics.SOURCEID, jhk_slope_reference.SOURCEID)] = np.nan
    jhk_slope_error[~np.in1d(nonperiodics.SOURCEID, jhk_slope_reference.SOURCEID)] = np.nan

    jjh_slope_column = nonperiodics.jjh_slope
    jjh_slope_error = nonperiodics.jjh_slope_err
    jjh_slope_column[~np.in1d(nonperiodics.SOURCEID, jh_slope_reference.SOURCEID)] = np.nan
    jjh_slope_error[~np.in1d(nonperiodics.SOURCEID, jh_slope_reference.SOURCEID)] = np.nan

    khk_slope_column = nonperiodics.khk_slope
    khk_slope_error = nonperiodics.khk_slope_err
    khk_slope_column[~np.in1d(nonperiodics.SOURCEID, hk_slope_reference.SOURCEID)] = np.nan
    khk_slope_error[~np.in1d(nonperiodics.SOURCEID, hk_slope_reference.SOURCEID)] = np.nan

    columns_data_and_formats = [
        ('ONCvar ID', nonperiodics.UKvar_ID, '%i'),
        ('N_J', nonperiodics.N_j, '%i'),
        ('N_H', nonperiodics.N_h, '%i'),
        ('N_K', nonperiodics.N_k, '%i'),
        ('J mag range (robust)', nonperiodics.j_ranger, '%.3f'),
        ('H mag range (robust)', nonperiodics.h_ranger, '%.3f'),
        ('K mag range (robust)', nonperiodics.k_ranger, '%.3f'),
        ('J-H range (robust)', nonperiodics.jmh_ranger, '%.3f'),
        ('H-K range (robust)', nonperiodics.hmk_ranger, '%.3f'),
        ('(J-H), (H-K) color slope', jhk_slope_column, '%.3f'),
        ('jhk_slope_error', jhk_slope_error, '%.3f'),
        ('J, (J-H) color slope', jjh_slope_column, '%.3f'),
        ('jjh_slope_error', jjh_slope_error, '%.3f'),
        ('K, (H-K) color slope', khk_slope_column, '%.3f'),
        ('khk_slope_error', khk_slope_error, '%.3f'),
        ('Stetson Variability Index', nonperiodics.Stetson, '%.3f'),
        ('Bands used to compute Stetson', nonperiodics.Stetson_choice, '%s'),
        ('Data quality flag', nonperiodics.autovar + nonperiodics.strict, '%i'),
        ('Class', megeath_class_by_nonperiodics, '%s')
        ]

    # Now split it into three pieces and compute medians!
    column_to_format = {}
    for column, data, format in columns_data_and_formats:
        table[column] = data
        column_to_format[column] = format

    if write:
        table.write(output_directory+"AJ_table_5.txt", format='ascii.basic', delimiter="&", formats=column_to_format)

    return table
コード例 #3
0
def t_table2_variability_periods_periodics_bymegeathclass(write=False):
    """
    Generates Table 2, which comes in three pieces.

    Note that we're only using periodic stars here!

    TODO: add in flags for whether a given star has valid
          J, H, or K data, respectively

    Current columns:
    N_j, N_h, N_k : three integers
      Delta-J, H, K: three floats
      Delta-J-H, J-K, H-K: three floats
      Color slopes (JH, HK, JHK): three floats
      Stetson : one float
      Stetson_choice : one string
      Period : one float
      Data quality : int (0, 1, 2) corresponding to subjective/auto/strict


    Parameters
    ----------
    write : bool, optional (default False)
        Write to disk? Either way, this function returns an ATpy table.
      
    """

    table = astropy.table.Table()
    table.table_name = "Table 2"

    periodics = ukvar_spread.where(ukvar_spread.periodic != 0)
    periodic_periods = ukvar_periods[ukvar_spread.periodic != 0]
    megeath_class_by_periodics = make_megeath_class_column()[ukvar_spread.periodic != 0]

    # Do some stuff where we blank out color slopes that are no good
    jhk_slope_column = periodics.jhk_slope
    jhk_slope_error = periodics.jhk_slope_err
    jhk_slope_column[~np.in1d(periodics.SOURCEID,
                              jhk_slope_reference.SOURCEID)] = np.nan
    jhk_slope_error[~np.in1d(periodics.SOURCEID,
                             jhk_slope_reference.SOURCEID)] = np.nan

    jjh_slope_column = periodics.jjh_slope
    jjh_slope_error = periodics.jjh_slope_err
    jjh_slope_column[~np.in1d(periodics.SOURCEID,
                              jh_slope_reference.SOURCEID)] = np.nan
    jjh_slope_error[~np.in1d(periodics.SOURCEID,
                             jh_slope_reference.SOURCEID)] = np.nan

    khk_slope_column = periodics.khk_slope
    khk_slope_error = periodics.khk_slope_err
    khk_slope_column[~np.in1d(periodics.SOURCEID,
                              hk_slope_reference.SOURCEID)] = np.nan
    khk_slope_error[~np.in1d(periodics.SOURCEID,
                             hk_slope_reference.SOURCEID)] = np.nan

    columns_data_and_formats = [
        ('ONCvar ID', periodics.UKvar_ID, '%i'),
        ('N_J', periodics.N_j, '%i'),
        ('N_H', periodics.N_h, '%i'),
        ('N_K', periodics.N_k, '%i'),
        ('J mag range (robust)', periodics.j_ranger, '%.3f'),
        ('H mag range (robust)', periodics.h_ranger, '%.3f'),
        ('K mag range (robust)', periodics.k_ranger, '%.3f'),
        ('J-H range (robust)', periodics.jmh_ranger, '%.3f'),
        ('H-K range (robust)', periodics.hmk_ranger, '%.3f'),
        ('(J-H), (H-K) color slope', jhk_slope_column, '%.3f'),
        ('jhk_slope_error', jhk_slope_error, '%.3f'),
        ('J, (J-H) color slope', jjh_slope_column, '%.3f'),
        ('jjh_slope_error', jjh_slope_error, '%.3f'),
        ('K, (H-K) color slope', khk_slope_column, '%.3f'),
        ('khk_slope_error', khk_slope_error, '%.3f'),
        ('Stetson Variability Index', periodics.Stetson, '%.3f'),
        ('Bands used to compute Stetson', periodics.Stetson_choice, '%s'),
        ('Best-fit period', periodic_periods, '%.4f'),
        ('Data quality flag', periodics.autovar + periodics.strict, '%i'),
        ('Class', megeath_class_by_periodics, '%s')
    ]

    column_to_format = {}
    for column, data, format in columns_data_and_formats:
        table[column] = data
        column_to_format[column] = format


    if write:
        table.write(output_directory+"AJ_table_4.txt", format='ascii.basic', delimiter="&", formats=column_to_format)

    return table
コード例 #4
0
import matplotlib.pyplot as plt
import astropy.table

import plot3
from variables_data_filterer import source_photometry
from tablemate_comparisons import ukvar_spread, ukvar_periods
from table_maker import make_megeath_class_column, megeath2012_by_ukvar

megeath_class_column = make_megeath_class_column()

path = os.path.expanduser("~/Dropbox/Bo_Tom/aux_catalogs/dipper_counting/")

aatau_ids = np.sort(np.loadtxt(path+'periodic_sub20days_AATau_analogs.txt'))

# this only works if ukvar_spread['UKvar_ID'] is monotonically increasing
aatau_spread = ukvar_spread.where(np.in1d(ukvar_spread['UKvar_ID'], aatau_ids))
aatau_periods = ukvar_periods[np.in1d(ukvar_spread['UKvar_ID'], aatau_ids)]
aatau_classes = megeath_class_column[np.in1d(ukvar_spread['UKvar_ID'], aatau_ids)]


aatau_megeath = megeath2012_by_ukvar.where(np.in1d(ukvar_spread['UKvar_ID'], aatau_ids))

# things to compute:
# 1. number of AA Taus, versus total number of periodic variables

num_aataus = len(aatau_spread)
num_variables = len(ukvar_spread)
num_periodics = np.sum(~np.isnan(ukvar_periods))

print "There are {0} total variables, and {1} total periodic variables.".format(num_variables, num_periodics)
print "Of these, {0} are AA Taus (periodic 'dippers').".format(num_aataus)
コード例 #5
0
def f_magnitude_hists_by_class(threepanels=True, onepanels=False):
    """
    Makes a series of multipanel histograms of variability.
    Uses "strict" sources only for these.
    
    """

    megeath_class_column = make_megeath_class_column()
    
    strict_protostars = ukvar_spread.where(
        (ukvar_spread.strict == 1) & (megeath_class_column == 'P'))

    strict_disks = ukvar_spread.where(
        (ukvar_spread.strict == 1) & (megeath_class_column == 'D'))

    strict_nondisks = ukvar_spread.where(
        (ukvar_spread.strict == 1) & (megeath_class_column == 'ND'))

    print "Protostars: %d, Disks: %d, Nondisks: %d" % (
        len(strict_protostars), len(strict_disks), len(strict_nondisks) )

    # Let's test the J mag aspect of this, and then define some dicts or forloops to iterate through all "5" bands.

    names = ['J mag', 'H mag', 'K mag', '(J-H) color', '(H-K) color']
    bands = ['j', 'h', 'k', 'jmh', 'hmk']
    text_xposition = [0.375, 0.375, 0.375, 0.275, 0.275]

    figs = []

    hist_kwargs = {'range':(0,2), 'bins':20}

    if threepanels:
        for b, n, x in zip(bands, names, text_xposition):

            j_fig = plt.figure(figsize=(5,6))
            figs.append(j_fig)

            jsub1 = plt.subplot(3,1,1)
            jsub1.hist(strict_protostars['%s_ranger' % b], color=color_dict['protostar'], 
                       **hist_kwargs)
            jsub1.text(x, 0.65, "protostars \n"
                       r"median $\Delta %s: $%.2f \pm %.2f$" % (
                    n.replace(' ', '$ '), 
                    np.median(strict_protostars['%s_ranger' % b]),
                    rb.mad(strict_protostars['%s_ranger' % b])),
                       transform = jsub1.transAxes)

            jsub2 = plt.subplot(3,1,2, sharex=jsub1)
            jsub2.hist(strict_disks['%s_ranger' % b], color=color_dict['disk'], **hist_kwargs)
            jsub2.text(x, 0.65, "disks \n"
                       r"median $\Delta %s: $%.2f \pm %.2f$" % (
                    n.replace(' ', '$ '), 
                    np.median(strict_disks['%s_ranger' % b]),
                    rb.mad(strict_disks['%s_ranger' % b])),
                       transform = jsub2.transAxes)

            jsub3 = plt.subplot(3,1,3, sharex=jsub1)
            jsub3.hist(strict_nondisks['%s_ranger' % b], color=color_dict['nondisk'], 
                       **hist_kwargs)
            jsub3.text(x, 0.65, "non-disks \n"
                       r"median $\Delta %s: $%.2f \pm %.2f$" % (
                    n.replace(' ', '$ '), 
                    np.median(strict_nondisks['%s_ranger' % b]),
                    rb.mad(strict_nondisks['%s_ranger' % b])),
                       transform = jsub3.transAxes)

            jsub1.set_title("%s range for $Q=2$ variables"%n)
            jsub3.set_xlabel(r"$\Delta %s (outlier-proof)" % 
                             n.replace(' ', '$ '))


    if onepanels:

        fig = plt.figure()
        figs.append(fig)
        
        plt.hist(strict_nondisks['k_ranger'], 
                 color=color_dict['nondisk'], hatch='/', label='Megeath Non-disks',
                 **hist_kwargs)
        plt.hist(strict_disks['k_ranger'], 
                 color=color_dict['disk'], alpha=0.5, hatch='\\', label='Megeath Disks',
                 **hist_kwargs)
        plt.hist(strict_protostars['k_ranger'], 
                 color=color_dict['protostar'], hatch='--', label='Megeath Protostars',
                 **hist_kwargs)

        plt.title("K magnitude range (robust) for pristine-data variables")
        plt.xlabel(r"$\Delta K$ magnitude (outlier-proof)")

        plt.legend()

            
    plt.show()
    return figs
コード例 #6
0
def f_color_slopes_and_periods(title1="K, H-K color slope distributions: "
                               "Periodic vs Non-Periodic",
                               title2="Color slopes versus periods, "
                               "for periodic stars"):
    """
    Generates two figures relating K, H-K color slopes with periods.
    
    a) two-panel histogram (purple/yellow) of color slopes for periodic 
       vs nonperiodic stars.
    b) Scatter plot of color slope versus period, for stars with 
       well-defined color-slopes and periods.

    """

    selection = np.in1d(ukvar_spread.SOURCEID, hk_filled.SOURCEID)

    color_periodics = ukvar_spread.where(selection & 
                                         (ukvar_spread.periodic > 0))
    color_periods = ukvar_periods[selection & (ukvar_spread.periodic > 0)]

    color_nonperiodics = ukvar_spread.where(selection & 
                                            (ukvar_spread.periodic == 0))

    # Fig 1 is the double histogram.
    fig1 = plt.figure()
    sub1 = plt.subplot(2,1,1)

    sub1.hist(np.degrees(np.arctan(color_periodics.khk_slope)), 
              range=[-90, 90], bins=36, color='m')
    plt.text(-45,4, "K, H-K color slopes for Periodic stars")
    sub1.set_title(title1)

    sub2 = plt.subplot(2,1,2, sharex=sub1)

    sub2.hist(np.degrees(np.arctan(color_nonperiodics.khk_slope)), 
              range=[-90, 90], bins=36, color='y')
    plt.text(-45,4, "K, H-K color slopes for Non-Periodic stars")
    
    sub2.set_xlabel("K, H-K color slope (degrees)")
    sub2.set_xlim(-90,90)
    sub2.set_xticks([-90,-45,0,45,90])

    # Fig 2 is the scatterplot.
    fig2 = plt.figure()

    plt.plot(color_periods, 
              np.degrees(np.arctan(color_periodics.khk_slope)), 'ko')

    plt.xlabel("Period, days")
    plt.ylabel("K, H-K color slope (degrees)")

    plt.ylim(-90, 90)
    plt.yticks([-90, -45, 0, 45, 90])
    plt.gca().set_yticks(np.arange(-90, 90, 15), minor=True)

    plt.text(30,-60, "Disk activity")
    plt.text(30,60, "Dust (A_V)")

    plt.title(title2)

    plt.show()

    return fig1, fig2
コード例 #7
0
    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


# crude copy
ukvar_spread = ukvar_s.where(ukvar_s.SOURCEID > 0)

ukvar_spread.add_column('Period', ukvar_periods)

# Let's do question two first.

# so... disk selection works like this:
# if 
#    (J-H) > 1.714*(H-K) 
# then it's a "photosphere"
# if 
#    (J-H) < 1.714*(H-K) and (J-H) > 1.714*(H-K)-0.614 
# then it's a "disk"
# if
#    (J-H) > 1.714*(H-K)-0.614 
# then it's an "extreme disk".