Esempio n. 1
0
def prepare_for_varysfh(inps, outfile):
    """
    Prepare a default varysfh inputfile
    """
    # get completeness mags for mag limits
    if inps.offset is None:
        logger.info('finding completeness fraction from fake file')
        inps.comp_mag1, inps.comp_mag2 = limiting_mag(inps.fake_file,
                                                      inps.comp_frac)

    # get Av, dmod, mTRGB, photsys
    msfh = rsp.match.utils.MatchSFH(inps.sfh_file)
    inps.Av = msfh.Av
    inps.dmod = msfh.dmod
    angst_target = \
        difflib.get_close_matches(inps.target.upper(),
                                  angst_data.targets)[0].replace('-', '_')
    try:
        target_row = angst_data.__getattribute__(angst_target)
        inps.trgb = target_row['%s,%s' % (inps.filter1, inps.filter2)]['mTRGB']
        if inps.photsys is None:
            inps.photsys = angst_data.get_item(angst_target, 'camera').lower()
            if inps.photsys == 'acs':
                inps.photsys = 'acs_wfc'
    except AttributeError:
        logger.error('{} not found in angst tables, \
                     using M=-4 to find mTRGB'.format(angst_target))
        inps.trgb = rsp.astronomy_utils.Mag2mag(-4., inps.filter2, inps.photsys,
                                                dmod=inps.dmod, Av=inps.Av)

    # get observered number of RGB and AGB stars
    mag1, mag2 = np.loadtxt(inps.matchphot, unpack=True)

    if inps.mag_faint is None:
        logger.info('assuming faint mag offset of 2')
        inps.offset = 2.
    else:
        inps.offset = inps.trgb - inps.mag_faint

    rgbs, agbs = rgb_agb_regions(inps.offset, inps.trgb_exclude, inps.trgb,
                                 mag2, mag_faint=inps.mag_faint,
                                 mag_bright=inps.mag_bright,
                                 col_min=inps.col_min, mag1=mag1,
                                 col_max=inps.col_max)

    inps.nrgbs = len(rgbs)
    inps.nagbs = len(agbs)

    # convert match SFH to trilegal AMR
    gal_inp = prepare_galaxy_inputfile(inps)

    inps.__dict__.update(gal_inp)
    inps.write_params(outfile)
Esempio n. 2
0
def prepare_data_table(inputs):
    if hasattr(inputs, 'Mtrgb'):
        mtrgb = inputs.Mtrgb
    else:
        mtrgb = np.nan
    if not hasattr(inputs, 'ir_trgb'):
        inputs.ir_trgb = rsp.astronomy_utils.Mag2mag(inputs.Mtrgb, inputs.ir_filter2,
                                              inputs.photsys, dmod=inputs.dmod,
                                              Av=inputs.Av)
    if not hasattr(inputs, 'opt_trgb'):
        inputs.opt_trgb = rsp.astronomy_utils.Mag2mag(inputs.Mtrgb, inputs.opt_filter2,
                                               inputs.photsys, dmod=inputs.dmod,
                                               Av=inputs.Av)
    fmt = '%s %i %i %i %i %.2f %.2f %.2f %.2f \n'
    header = '# opt: F814W ir: F160W Mtrgb: %.2f dmod: %.2f Av: %.1f \n'
    header += '# opt, ir: color_min (%.1f, %.1f) trgb (%.2f, %.2f) '
    header += 'offsets (%.1f, %.1f) trgb exclude (%.1f, %.1f) \n'
    header += '# target nopt_rgb nopt_agb nir_rgb nir_agb opt_max ir_max'
    header += ' opt_min ir_min \n'

    out = open('phat_b21_data.dat', 'w')
    out.write(header % (mtrgb, inputs.dmod, inputs.Av,
                        inputs.opt_color_min, inputs.ir_color_min,
                        inputs.opt_trgb, inputs.ir_trgb, inputs.offsets[0], inputs.offsets[1],
                        inputs.trgb_excludes[0], inputs.trgb_excludes[1]))

    opt_files, ir_files = load_data_files(inputs)
    for i in range(len(opt_files)):
        opt_gal = rsp.Galaxy(opt_files[i], filetype=inputs.data_ftype, angst=False,
                             hla=False, filter1=inputs.opt_filter1,
                             filter2=inputs.opt_filter2)
        ir_gal = rsp.Galaxy(ir_files[i], filetype=inputs.data_ftype, angst=False,
                            hla=False, filter1=inputs.ir_filter1,
                            filter2=inputs.ir_filter2)
        opt_color_cut, = np.nonzero((opt_gal.color) > inputs.opt_color_min)
        ir_color_cut, = np.nonzero((ir_gal.color) > inputs.ir_color_min)
        ir_mag = ir_gal.mag2[ir_color_cut]
        opt_mag = opt_gal.mag2[opt_color_cut]
        opt_rgb, ir_rgb, opt_agb, ir_agb = \
            rgb_agb_regions(opt_gal, inputs.offsets, inputs.trgb_excludes,
                            inputs.opt_trgb, inputs.ir_trgb, opt_mag, ir_mag)
        out.write(fmt % (opt_files[i].split('.')[0], len(opt_rgb), len(opt_agb),
                         len(ir_rgb), len(ir_agb), opt_gal.mag2.max(),
                         ir_gal.mag2.max(), opt_gal.mag2.min(),
                         ir_gal.mag2.min()))