Beispiel #1
0
def brown_fct(t_act_hphb, **kwargs):
    '''
    This was made to check the fct around brown98 area.
    '''
    sup_phot = kwargs['sup_phot']
    btrack = kwargs.get('btrack')
    mag1_cut = kwargs.get('mag1_cut')
    mag2_cut = kwargs.get('mag2_cut')
    frac_bulge = sup_phot['bulge_fraction'][1]  # Bulge fraction B/(B+D)

    # file locations
    file_src = '/astro/net/angst2/philrose/PHAT/paper/supporting_files/'
    if not os.path.isdir(file_src):
        file_src = '/Users/phil/research/PHAT//paper/supporting_files/'
    b98region = os.path.join(file_src, 'brown98_region_masked.reg')
    b98fits = os.path.join(file_src, 'phat_photcat_b98region.fits')

    # load b98 photometry file
    b98_phat = pyfits.open(b98fits)[1].data
    b98_ra = b98_phat.field('ra')
    b98_dec = b98_phat.field('dec')
    b98_mag1 = b98_phat.field('mag1_uvis')
    b98_mag2 = b98_phat.field('mag2_uvis')
    b98_color = b98_mag1 - b98_mag2

    # load b98 region
    ras, decs = file_io.read_reg(b98region, shape='polygon')
    foc_fov = np.column_stack((ras[0], decs[0]))

    # b98 called uv-brights stars 1 mag brighter than completeness limit
    b98_mag1_cut = mag1_cut - 1.
    b98_mag2_cut = mag2_cut - 1.
    inds1 = np.nonzero(b98_mag1 < b98_mag1_cut)[0]
    inds2 = np.nonzero(b98_mag2 < b98_mag2_cut)[0]
    b98_cut = list(set(inds1) & set(inds2))

    # load the hphb color-mag limits
    verts = get_hphb_cmd_verts(btrack, **kwargs)

    # which b98 stars are in the hphb color-mag limit
    points = np.column_stack((b98_color[b98_cut], b98_mag2[b98_cut]))
    #points = np.column_stack((b98_color,b98_mag2))
    inds = np.nonzero(nxutils.points_inside_poly(points, verts))[0]

    nhphb_foc = float(len(inds))

    rif_36_foc = 0.527
    L_T = rif_36_foc * 1.61e8 * frac_bulge  #230893.52211437
    Bt = 2.2e-11  # From Spectral Evolution of Galaxies ASSL 122 p195+
    t_hphb = nhphb_foc / (Bt * L_T)

    # hard coded expected lifetimes.
    # median time_spent_on_cmd for the three largest mass tracks
    #t_act_hphb =  2e6#1e7 # 10694600 # 994000.0
    print 'Brown Check:'
    print 'NHPHB expected:', L_T * Bt * t_act_hphb
    print 'percent msto that become x as a function of radius:'
    print 'HPHB', t_hphb / t_act_hphb * 100
    print 'nhbhbs', len(inds)
    return
Beispiel #2
0
def area_within_regs(reg_name, closed=False):
    '''
    if closed = false, I'll append the first x,y to the list.
    '''
    tot_areas = np.array([])
    ras, decs = file_io.read_reg(reg_name, shape='polygon')
    for ra, dec in zip(ras, decs):
        ra.append(ra[0])
        dec.append(dec[0])
        verts = np.column_stack((ra, dec))
        tot_areas = np.append(tot_areas, GenUtils.area(verts))
    return tot_areas
Beispiel #3
0
def points_inside_ds9_polygon(reg_name, ra_points, dec_points):
    '''
    uses read_reg
    '''
    try:
        file_io
    except NameError:
        import file_io
    radec = np.column_stack((ra_points, dec_points))
    ras, decs = file_io.read_reg(reg_name, shape='polygon')
    verts = [np.column_stack((ras[i], decs[i])) for i in range(len(ras))]
    masks = [nxutils.points_inside_poly(radec, vert) for vert in verts]

    inds = [
        np.nonzero(masks[i] - masks[i + 1])[0] for i in range(len(masks) - 1)
    ]
    return inds
Beispiel #4
0
def main(**kwargs):
    ast_file = kwargs.get('ast_file')
    ast = load_ast_file(ast_file)
    from params import PHAT_DIR_EXTRA3
    contour = PHAT_DIR_EXTRA3 + 'contours_v3.reg'
    cras, cdecs = file_io.read_reg(contour)
    outverts = np.column_stack((cras[-1], cdecs[-1]))

    rec1 = recovered_asts(ast['mag1in'], ast['mag1out'])
    rec2 = recovered_asts(ast['mag2in'], ast['mag2out'])

    # quality cut on all asts
    qc1 = quality_cut(ast['sharp1'], ast['snr1'], ast['crowd1'], ast['round1'],
                      **kwargs)

    qc2 = quality_cut(ast['sharp2'], ast['snr2'], ast['crowd2'], ast['round2'],
                      **kwargs)

    qcd = list(set(qc1) & set(qc2))
    inds = points_inside_ds9_polygon(contour, ast['ra'], ast['dec'])
    comp_corr_file = open(kwargs.get('comp_file'), 'w')
    comp_corr_file.write('# region (0=in) mags comp_frac \n')
    comp_data_file = open(kwargs.get('comp_data'), 'w')
    print 'comp correction file:', kwargs.get('comp_file')
    print 'comp data file:', comp_data_file
    single = kwargs.get('single')
    kwargs['ast_file_ext'] = '_' + kwargs.get('comp_file').replace(
        '.dat', '').split('_')[-1]
    if single == False:
        qc1 = qcd
        qc2 = qcd
        kwargs['ast_file_ext'] += '_dd'
        color_range = (-0.7, 0.5)
        ast_color = ast['mag1in'] - ast['mag2in']
        color_inds = np.nonzero((ast_color > color_range[0])
                                & (ast_color < color_range[1]))[0]

    Rinds1s, Rinds2s, Bins, Frac1s, Frac2s = [], [], [], [], []
    Rhist1s, Rhist2s, Qhist1s, Qhist2s = [], [], [], []
    comp_data_file.write(
        '# Region comp50mag1 comp50mag2 comp90mag1 comp90mag2\n')
    print '# Region comp50mag1 comp50mag2 comp90mag1 comp90mag2'
    for i in range(len(inds)):
        # in each annulus, passed qc, recovered
        if single == False:
            Rinds1 = list(
                set(rec1) & set(qc1) & set(inds[i]) & set(color_inds))
            Rinds2 = list(
                set(rec2) & set(qc2) & set(inds[i]) & set(color_inds))
            # REWRITING INDS OF I FOR THIS COLOR RANGE.
            inds[i] = list(set(inds[i]) & set(color_inds))
        else:
            Rinds1 = list(set(rec1) & set(qc1) & set(inds[i]))
            Rinds2 = list(set(rec2) & set(qc2) & set(inds[i]))

        hist_range = (18.34, 28.)
        # use hist_bin_optimization to get this value
        #spacing = 0.04
        spacing = 0.2
        Rhist1, Rbins1 = np.histogram(ast['mag1in'][Rinds1],
                                      bins=np.arange(hist_range[0],
                                                     hist_range[1], spacing))
        Rhist2, Rbins2 = np.histogram(ast['mag2in'][Rinds2],
                                      bins=np.arange(hist_range[0],
                                                     hist_range[1], spacing))
        Qhist1, Qbins1 = np.histogram(ast['mag1in'][inds[i]],
                                      bins=np.arange(hist_range[0],
                                                     hist_range[1], spacing))
        Qhist2, Qbins2 = np.histogram(ast['mag2in'][inds[i]],
                                      bins=np.arange(hist_range[0],
                                                     hist_range[1], spacing))

        # need to be float...
        frac1 = np.array(map(float, Qhist1)) / np.array(map(float, Rhist1))
        frac2 = np.array(map(float, Qhist2)) / np.array(map(float, Rhist2))

        c_lim1 = GenUtils.closest_match(0.5, 1 / frac1)
        c_lim2 = GenUtils.closest_match(0.5, 1 / frac2)
        c_lim1a = GenUtils.closest_match(0.90, 1 / frac1)
        c_lim2a = GenUtils.closest_match(0.90, 1 / frac2)

        if i == 0:
            inmag1 = c_lim1
            inmag2 = c_lim2
            [comp_corr_file.write('%.2f ' % bin) for bin in Rbins1]
            comp_corr_file.write('\n')
        else:
            print 1. / frac1[inmag1], 1. / frac2[inmag2]
            comp_data_file.write(
                '# inner mag limit corresponds to 50 percent completeness \n# 275: %.3f \n# 336: %.3f \n'
                % (1. / frac1[inmag1], 1. / frac2[inmag2]))

        comp_corr_file.write('F336W %i ' % i)
        [comp_corr_file.write('%.8f ' % frac) for frac in frac1]
        comp_corr_file.write('\nF275W %i ' % i)
        [comp_corr_file.write('%.8f ' % frac) for frac in frac2]
        comp_corr_file.write('\n')

        # for Table1 need comp50,98 index 0 to be inner ring.
        comp50mag1 = Rbins1[c_lim1]
        comp50mag2 = Rbins1[c_lim2]
        comp92mag1 = Rbins1[c_lim1a]
        comp92mag2 = Rbins1[c_lim2a]

        comp_data_file.write(
            '%i %.1f %.1f %.1f %.1f\n' %
            (i, comp50mag1, comp50mag2, comp92mag1, comp92mag2))
        print '%i %.1f %.1f %.1f %.1f' % (i, comp50mag1, comp50mag2,
                                          comp92mag1, comp92mag2)

        Rinds1s.append(Rinds1)
        Rinds2s.append(Rinds2)
        Bins.append(Rbins1)
        Frac1s.append(frac1)
        Frac2s.append(frac2)
        Rhist1s.append(Rhist1)
        Rhist2s.append(Rhist2)
        Qhist1s.append(Qhist1)
        Qhist2s.append(Qhist2)

    ax1, ax2 = ast_completeness_plot(Bins, Frac1s, Frac2s, **kwargs)
    ast_diff_plot(ast, Rinds1s, Rinds2s, inds, **kwargs)
    ast_hist_plot(Bins, Rhist1s, Qhist1s, Rhist2s, Qhist2s, **kwargs)

    comp_corr_file.close()
    comp_data_file.close()