示例#1
0
def plot_random_sfhs(targets='ancients'):
    '''
    plot the random sfr arrays with the data sfr arrays.
    Hard coded file locations. So read the code.
    '''
    targets = galaxy_tests.load_targets(targets)

    for target in targets:
        target = target.lower()
        # it doesn't matter which model so it is hard coded...
        sfr_file_loc = os.path.join(snap_src, 'models', 'varysfh', target,
                                    'caf09_s_nov13', 'mc')
        hmc_file_loc = os.path.join(snap_src, 'data', 'sfh_parsec')

        target = target.replace('-deep', '')
        outfile = '%s_random_sfr.png' % target
        hmc_file, = rsp.fileIO.get_files(hmc_file_loc, '%s*sfh' % target)

        sfh = sfh_tests.StarFormationHistories(hmc_file, 'match-hmc',
                                               sfr_file_loc=sfr_file_loc,
                                               sfr_file_search_fmt='*sfr')

        sfh.plot_sfh('sfr', plot_random_arrays_kw={'from_files': True},
                     outfile=outfile, zoom=True)
    return
示例#2
0
def plot_opt_hess(targets=None, fits_src='default', filter1='F606W'):
    band = 'opt'
    ylim = (0.5, -7)
    if filter1 == 'F110W':
        band = 'ir'
        fits_src = 'default'
        ylim = (-2, -8)
    targets = galaxy_tests.load_targets(targets)
    galss = rsp.Galaxies.galaxies([galaxy_tests.load_galaxy(t, band=band,
                                                           fits_src=fits_src)
                                  for t in targets])

    gals = rsp.Galaxies.galaxies(galss.select_on_key('filter1', filter1))

    gals.squish('Color', 'Mag2', 'Trgb')

    mean_trgb = np.mean(gals.Trgbs)
    offset = gals.Trgbs - np.mean(gals.Trgbs)
    gals.Mag2o = np.concatenate([g.Mag2 - offset[i] for i, g in enumerate(gals.galaxies)])
    gals.Colorso = gals.Colors + gals.Mag2s - gals.Mag2o
    galshess =  rsp.astronomy_utils.hess(gals.Colorso, gals.Mag2o, 0.1, cbinsize=0.05)

    #N, xedges, yedges = binned_statistic_2d(gals.Colors, gals.Mag2s, gals.Mag2s, 'count', bins=2000)
    fig, ax = plt.subplots()
    #im = ax.imshow(np.log10(N.T), origin='lower',
    ##                           extent=[xedges[0], xedges[-1], yedges[0],
    #                                   yedges[-1]],
    #                           aspect='auto', interpolation='nearest',
    #                           cmap=plt.cm.RdBu)

    extent = [galshess[0][0], galshess[0][-1], galshess[1][-1], galshess[1][0]]
    imshow_kw={'norm': LogNorm(vmin=None, vmax=galshess[2].max()),
               'cmap': plt.cm.gray_r, 'interpolation': 'nearest',
               'aspect': 'equal', 'extent': extent}

    ax.plot(gals.Colorso, gals.Mag2o, ',', color='black')
    ax.autoscale(False)
    ax.set_xlim(-1, 3)
    ax.set_ylim(ylim)
    #ax.imshow(galshess[2], **imshow_kw)
    ax.set_aspect(1./2.)

    ax.set_xlabel('$%s-%s$' % (filter1, gals.galaxies[0].filter2), fontsize=fontlarge)
    ax.set_ylabel('$%s$' % gals.galaxies[0].filter2, fontsize=fontlarge)
    ax.hlines(mean_trgb, *ax.get_xlim(), lw=2, color='red', zorder=100)
    #ax.hlines(mean_trgb+1.5, *ax.get_xlim(), lw=2, color='red', zorder=100)
    #for k, v in poly_dict.items():
    #    ax.plot(v[:,0], v[:,1])
    #plt.colorbar(cs)
    #plt.savefig('opt_cmd_f606w.png', dpi=150)
    return fig, ax, gals
示例#3
0
def run_match_stats(targets='ancients'):
    targets = galaxy_tests.load_targets(targets)
    hmc_file_loc = os.path.join(snap_src, 'data', 'sfh_parsec')
    cmd_file_loc = os.path.join(hmc_file_loc, 'cmd_files')
    for target in targets:
        target = target.lower()
        try:
            target = target.replace('-deep', '')
            hmc_file, = rsp.fileIO.get_files(hmc_file_loc, '%s*sfh' % target)
            cmd_file, = rsp.fileIO.get_files(cmd_file_loc, '%s*cmd' % target)
        except:
            print target, 'cmd file not found.'
            continue
        rsp.match_utils.match_stats(hmc_file, cmd_file)
    return
示例#4
0
def completeness_table(targets, comp_val, ast_kw=None, outfile='default'):
    '''
    ex: completeness_table('ancients', 0.9)
    '''
    targets = galaxy_tests.load_targets(targets)
    if outfile == 'default':
        outfile = os.path.join(snap_src + '/tables/',
                               'completeness_%.2f.dat' % comp_val)

    fmt = '%(target)s %(opt_filter1)s %(opt_filter2)s %(ir_filter1)s %(ir_filter2)s \n'
    with open(outfile, 'w') as out:
        out.write('# completeness fraction: %.2f \n' % comp_val)
        out.write('# '\
                  + fmt.replace('%(', '').replace(')s', '').replace('\'', ''))
        for target in targets:
            print target
            ast_dict = find_completeness(target, comp_val)
            ast_dict['target'] = target
            out.write(fmt % ast_dict)
    logger.info('wrote %s' % outfile)
示例#5
0
    outfname = '%s_%s_cmd.png' % (target, band)
    outfile = os.path.join(snap_src, 'plots', outfname)
    fig.savefig(outfile, dpi=150)


def add_color_cuts(filter1, ax=None, vline_kw=None):
    vline_kw = vline_kw or {}
    if ax is None:
        fig, ax = plt.subplots()
    color_cut = sfh_tests.get_color_cut(filter1)
    ax.vlines(color_cut, *ax.get_ylim(), **vline_kw)
    return ax


if __name__ == '__main__':
    targets = galaxy_tests.load_targets('ancients')
    plot_cum_sum_sfr(targets)
    [[plot_cmd_lf(target, band) for target in targets] for band in ['opt', 'ir']]


# below here was thesis spaz

def ave_galaxy_cmd(targets=None, filter1=None, filter2=None):
    if targets is None:
        targets = galaxy_tests.targets_z002()

    if filter1 is None:
        filter1 = 'F160W'

    if filter2 is None:
        filter2 = 'F110W'