コード例 #1
0
def plot_lf_with_stages(target, trilegal_output):
    outfile_dir = snap_src + '/models/varysfh/match-hmc/'
    vSFH, vsfh_kws = sfh_tests.prepare_vsfh_run([target], ['cmd_input_CAF09_S_NOV13.dat'], 50,
                                                 vsfh_kw={'outfile_loc': outfile_dir,
                                                          'extra_str': ''},
                                                          default_kw=None)
    pl = sfh_tests.Plotting(vSFH[0])
    cols = color_scheme
    cols.append('#9966cc')
    del cols[2]
    del cols[3]
    kw = {'trilegal_output': trilegal_output,
          'narratio': False,
          'add_stage_lfs': 'all',
          'plot_data': False,
          'plot_models': False,
          'cols': cols,
          'stage_lf_kw': {'lw': 3, 'label': translate_model_name('nov13')}}
    ax1, ax2 = pl.compare_to_gal(target, **kw)
    lims = load_plot_limits()
    row = lims[np.nonzero(lims['target'] == target)[0]]
    for ax, band in zip([ax1, ax2], ['opt', 'ir']):
        ax.set_xlim(row['%s_cmdmin' % band], row['%s_cmdmax' % band])
        ax.set_ylim(row['%s_lfmin' % band], row['%s_lfmax' % band])


    base_dir = snap_src + '/models/varysfh/match-hmc'
    model = 'caf09_s_nov13'
    file_loc = os.path.join(base_dir, target, model, 'mc')
    best_tri_out, = rsp.fileIO.get_files(file_loc, '*opt_best*')
    filter1 = sfh_tests.get_filter1(target)
    sgal = rsp.Galaxies.simgalaxy(best_tri_out, filter1=filter1,
                                  filter2='F814W')

    return ax1, ax2
コード例 #2
0
def all_stats(targets, cmd_inputs, nsfhs, outfile_dir="default", extra_str="", default_kw=None):
    vSFHs, vsfh_kws = sfh_tests_multi_proc.prepare_vsfh_run(
        targets, cmd_inputs, nsfhs, vsfh_kw={"outfile_loc": outfile_dir, "extra_str": extra_str}, default_kw=default_kw
    )
    chi2_files = stats.write_chi2_table(targets, cmd_inputs, outfile_loc=outfile_dir, extra_str=extra_str)
    narratio_files = rsp.fileIO.get_files(outfile_dir, "*narratio*dat")
    chi2_dicts = stats.result2dict(chi2_files)
    stats.narratio_table(narratio_files)
    # axs = stats.chi2plot(chi2_dicts, outfile_loc=outfile_dir)
    axs = stats.chi2plot2(chi2_dicts, outfile_loc=outfile_dir)
    chi2_files = stats.write_chi2_table(
        targets, cmd_inputs, outfile_loc=outfile_dir, extra_str=extra_str, just_gauss=True
    )
    pl = [sfh_tests_multi_proc.Plotting(v) for v in vSFHs]
    _ = [pl[i].compare_to_gal(extra_str=extra_str) for i in range(len(pl))]
    # plt.close('all')
    return
コード例 #3
0
def lf_figs(targets, cmd_inputs, nsfhs, outfile_dir='default', extra_str='',
            default_kw=None, comp_corr=False, example=True):
    import os
    if comp_corr is True:
        table_file = 'comp_corr'
    else:
        table_file = 'default'
    vSFHs, vsfh_kws = sfh_tests.prepare_vsfh_run(targets, cmd_inputs, nsfhs,
                                                 vsfh_kw={'outfile_loc': outfile_dir,
                                                          'extra_str': extra_str,
                                                          'table_file': table_file},
                                                 default_kw=default_kw)

    if comp_corr is True:
        extra_str += '_comp'

    for i in range(len(vSFHs)):
        pl = sfh_tests.Plotting(vSFHs[i])
        pl.compare_to_gal(extra_str=extra_str,
                          completeness_correction=comp_corr)
        # example LF from the model
    if example is True:
        for i in range(len(vSFHs)):
            pl = sfh_tests.Plotting(vSFHs[i])
            best = rsp.fileIO.get_files(os.path.join(outfile_dir, vSFHs[i].target,
                                                      vSFHs[i].agb_mod, 'mc'),
                                         '*best.dat')
            if len(best) == 0:
                continue
            pl.compare_to_gal(narratio=False, add_stage_lfs='all',
                              extra_str='no_data', plot_data=False,
                              completeness_correction=comp_corr,
                              plot_models=False,
                              trilegal_output=best[0])

    return
コード例 #4
0
def main(targets, cmd_inputs, nsfhs, dry_run=False, comp_corr=False):
    '''
    calls sfh_tests_multi_proc.sfh_tests_multi_proc in most basic way possible
    for up to 2 * available processors. Target & cmd_inputs are distributed and
    nsfhs are all done per processor. So with 12 processors, you can do up to
    24 target and cmd_inputs in one call, or code something better for a change.
    '''
    clients = parallel.Client()
    clients.block = False

    clients[:].execute('cd ~/research/TP-AGBcalib/code/TPAGB-calib/')
    clients[:].execute('import sfh_tests')

    if comp_corr is True:
        table_file = 'comp_corr'
    else:
        table_file = 'default'
    vSFHs, vsfh_kws = sfh_tests.prepare_vsfh_run(targets, cmd_inputs, nsfhs,
                                                 dry_run=dry_run,
                                                 table_file=table_file)

    if dry_run is True:
        timeout = 10
    else:
        timeout = 900

    # find a better way to run this all at once, what if I need three times
    # through?
    nprocs = len(clients)
    nvsfhs = len(vSFHs)
    ntimes = np.min([nprocs, nvsfhs])
    ndiff = np.abs(nvsfhs - nprocs)

    if ndiff > nprocs:
        print 'need a for loop, too many processes code code code man'
        import sys
        sys.exit()

    print 'calling first set'
    res = [clients[i].apply(caller, vSFHs[i], vsfh_kws,)
           for i in range(ntimes)]

    while False in [r.ready() for r in res]:
        print 'waiting on first set'
        time.sleep(timeout)
        print 'checking first set...'

    print 'writing first set'
    [vSFHs[i].write_results(res[i].result) for i in range(ntimes)]

    print 'calling second set'
    res2 = [clients[i].apply(caller, vSFHs[i+ntimes], vsfh_kws,)
            for i in range(ndiff)]

    while False in [r.ready() for r in res2]:
        print 'waiting on second set'
        time.sleep(timeout)
        print 'checking second set...'

    print 'writing second set'
    [vSFHs[i+ntimes].write_results(res2[i].result) for i in range(ndiff)]

    print 'done.'