예제 #1
0
def read_results(runs):
    results, models = [], []
    for run in runs:
        res, pr, mod = bread.read_pickles(run, model_file=run.replace('_mcmc','_model'))
        results.append(res)
        models.append(mod)
    return results, models
예제 #2
0
                        'dust2': ["Cassisi et al. (2008)"]}
    real_cal="results/ggc_ngc1851_1432787257_mcmc"
    real_uncal="results/ggc_ngc1851_uncal_tightprior_1433448554_mcmc"

    real_cal = "results/real_specphot_otherjitter.NGC1851.calTrue_5699610_1441238007_mcmc"
    real_uncal = "results/real_specphot_otherjitter.NGC1851.calFalse_5699625_1441238175_mcmc"

    real_cal = "results/real_specphot_mtrim_llnoise_v2.NGC1851.calTrue_5912384_1445132251_mcmc"
    real_uncal = "results/real_specphot_mtrim_llnoise_v2.NGC1851.calFalse_5912391_1445132211_mcmc"
    
    real_phot = "results/real_photonly.NGC1851.calTrue_1441258499_mcmc"

    
    resfiles = [real_cal, real_uncal]#, real_phot]
    clr = ['green', 'orange', 'red']
    results = [bread.read_pickles(rfile, model_file=rfile.replace('mcmc','model'))[0]
               for rfile in resfiles]
    obsdat = results[0]['obs']
    showpars = np.array(['mass', 'tage', 'zmet', 'dust2'])
    parlims = np.array([[0.4, 4],
                        [5, 11],
                        [-1.3, -0.75],
                        [0, 0.5]])
    parlims = np.array(4 * [[None, None]])
    npar = len(showpars)

    fig = pl.figure()
    
    gs = gridspec.GridSpec(npar, npar)
    for i, p1 in enumerate(showpars):
        dax = pl.subplot(gs[i,i])
예제 #3
0
if __name__ == "__main__":

    bcolor='green'
    if len(sys.argv) > 1:
        resfile=sys.argv[1]
        try:
            bcolor = sys.argv[2]
        except:
            pass
    else:
        resfile = 'results/ggc_mock.u0.t1.0_z0.0_a0.5_1426268715_mcmc'
    model_file = resfile.replace('_mcmc','_model')
    pcolor='orange'
    nsample = 10
    
    res, pr, mod = bread.read_pickles(resfile, model_file=model_file)
    obsdat = res['obs']
    
    # Get samples and component spectra
    fsamples = np.random.uniform(0,1,nsample)
    thetas, start, samples = theta_samples(res, samples=fsamples, start=0.75, thin=1)
    fwave, _, _, fspecvecs = comp_samples_fullspec(thetas, mod, obsdat,
                                                   sps=sps, gp=None)
    mwave, mospec, mounc, specvecs = comp_samples(thetas, mod, obsdat,
                                                  sps=sps, gp=gp)
    pwave, mosed, mosed_unc, pvecs = comp_samples_phot(thetas, mod, obsdat, sps=sps)

    # Get truth spectrum and sed
    # THERE IS NO TRUTH
    
    # Get calibration vector    
예제 #4
0
    results, models = read_results(runs)
    noiseless_run = 'results/ggc_mock_specphot_linear.u0.t12.0_z0.0_a0.5_5313542_1432675345_mcmc'
    bcolor = 'maroon'

    if as_hist:
        hfig, haxes = pl.subplots(2,2)
        for j, (res, mod) in enumerate(zip(results, models)):
            samples, pord = hist_samples(res, mod, pnames, thin=thin,
                                         start=sfraction)
            for i, (ax, name) in enumerate(zip(haxes.flatten(), pnames)):
                ax.hist(samples[:,i], bins=kwargs.get("bins", 50),
                        histtype="stepfilled",
                        color=kwargs.get("color", bcolor),
                        alpha=kwargs.get("alpha",0.3))
        
        res, pr, mod = bread.read_pickles(noiseless_run,
                                          model_file=noiseless_run.replace('_mcmc','_model'))
        samples, pord = hist_samples(res, mod, pnames, thin=thin,
                                     start=sfraction)
        truths = [res['obs']['mock_params'][k] for k in pord]
        for i, (ax, name) in enumerate(zip(haxes.flatten(), pnames)):
            ax.hist(samples[:,i], bins=kwargs.get("bins", 50),
                    histtype="stepfilled",
                    color=bcolor,
                    alpha=kwargs.get("alpha",0.3))
            ax.axvline(truths[i], color=kwargs.get('truth_color','k'),
                       label='Mock Truth')
            ax.set_xlabel(name, fontsize=8)
            ax.set_yticklabels([])
            pl.setp(ax.get_xticklabels(), fontsize=8)

        hfig.show()
예제 #5
0
        resfile = sys.argv[1]
        try:
            basecolor = sys.argv[2]
        except:
            pass
        try:
            suptitle = sys.argv[3]
        except:
            pass
    else:
        resfile = 'results/ggc_mock_photonly.c0.t9.0_z0.0_a0.5_1430274922_mcmc'
    model_file = resfile.replace('_mcmc', '_model')
    pointcolor = 'orange'
    nsample = 10

    res, pr, mod = bread.read_pickles(resfile, model_file=model_file)
    obsdat = res['obs']

    # Get samples and component spectra
    fsamples = np.random.uniform(0, 1, nsample)
    thetas, start, samples = theta_samples(res,
                                           samples=fsamples,
                                           start=0.75,
                                           thin=1)
    fwave, mospec, mounc, specvecs = comp_samples_fullspec(thetas,
                                                           mod,
                                                           obsdat,
                                                           sps=sps,
                                                           gp=None)
    pwave, mosed, mosed_unc, pvecs = comp_samples_phot(thetas,
                                                       mod,
예제 #6
0
    if len(sys.argv) > 1:
        resfile=sys.argv[1]
    else:
        resfile = 'results/ggc_mock.u0.t1.0_z0.0_a0.5_1426268715_mcmc'        
    model_file = resfile.replace('_mcmc','_model')

    showpars_phys = ['mass', 'tage', 'zmet', 'dust2', 'zred', 'sigma_smooth']
    showpars_cal = ['poly_coeffs_1', 'poly_coeffs_2', 'spec_norm', 'low_level_amplitude',
                    'gp_length', 'gp_amplitude', 'gp_jitter', 'gp_jitter_add',
                    'phot_jitter']

    showpars_pc = ['mass', 'tage', 'dust2', 'zmet', 'gp_length'
                   'spec_norm', 'poly_coeffs_1', 'poly_coeffs_2']
    
    result, pr, model = bread.read_pickles(resfile, model_file=model_file)
    ns = result['chain'].shape[0] * result['chain'].shape[1]
    start = int(result['chain'].shape[1]*0.75)
    start = 0
    thin = 20
    
    #sys.exit()
    try:
        efig = bread.param_evol(result, showpars=showpars_phys+showpars_cal)
        efig.savefig(resfile.replace('_mcmc','.pevol.pdf'))
        pl.close(efig)
    except(IndexError):
        print('not enough parameters to show in pevol plot')
    try:
        tfig = bread.subtriangle(result, showpars=showpars_phys,
                                 start=start, thin=thin)
예제 #7
0
    #       rdir+'b192-g242.020.nocal_1405677518.sampler01']
    #res = [rdir+'b192-g242.225.cal_1407376313.sampler01']
    #res = [rdir+'b192-g242.225.cal_1407608570.sampler01']
    #res = [rdir+'b192-g242.225.cal_1409443437.sampler01']
    res = [#rdir+'b192-g242.225.cal_1407608570.sampler01']
           #rdir+'b192-g242.225.cal_1409443437.sampler01']
           #rdir+'b192-g242.225.cal_1409477803.sampler01',
           #rdir+'b192-g242.225.cal_1409534549.sampler01',
           rdir+'b192-g242.225.cal_1412345250.sampler01']
    inlog = True

    name = ['B192 cal.', 'B192 no cal.']
    
    for i,r in enumerate(res):
        sf, mf = r+'_mcmc', r+'_model'
        result, pr, model = diagnostics.read_pickles(sf, model_file = mf)
        result['model'] = model
        #best = np.argmin([p.fun for p in powell_guesses])
        #result['optimizer_results'] = pr[best]
        of = result['run_params']['outfile'].split('/')[-1]
        of = of.replace('.','_')
        ns = result['chain'].shape[0] * result['chain'].shape[1]
        sample = [int(s * ns) for s in samples]

        gfig = gp_figure(result, samples=sample, inlog=inlog)
        gfig.axes[0].set_yscale('log')
        gfig.savefig('gp_figure.png')
        
        
        sfig = spec_figure(result, samples=sample,
                        linewidth = 0.5, xlim = (3650, 7300),
예제 #8
0
    if len(sys.argv) > 1:
        specphot = sys.argv[1]
        try:
            bcolor = sys.argv[2]
        except:
            pass
        try:
            suptitle = sys.argv[3]
        except:
            suptitle = ''
    else:
        specphot = 'results/ggc_mock_specphot_linear.u0.t9.0_z0.0_a0.5_5280432_1431898211_mcmc'
    resfiles = [specphot]
    clr = [bcolor]
    results = [
        bread.read_pickles(rfile, model_file=rfile.replace('mcmc', 'model'))[0]
        for rfile in resfiles
    ]
    obsdat = results[0]['obs']
    showpars = np.array([
        'dust2', 'gp_jitter', 'gp_length', 'gp_amplitude', 'spec_norm',
        'poly_coeffs_1', 'poly_coeffs_2'
    ])
    parlims = np.array([[0.0, 1.5], [None, None], [100, 1000], [0, 0.5],
                        [-1, 1], [-10, 10], [-10, 10]])
    npar = len(showpars)

    fig = pl.figure(figsize=(10, 8))

    gs = gridspec.GridSpec(npar, npar)
    for i, p1 in enumerate(showpars):
예제 #9
0
    sps.params['logzsol'] = 0.0
else:
    # we are using MILES with better optical resolution
    sps.params['sigma_smooth'] = 0.0
    halpha = (w > 6556) & (w < 6573)
    sps.params['zmet'] = 4
    sps.params['logzsol'] = 0.0

ns = 40
Cha = np.zeros(ns)
gtage = np.random.uniform(7.0, 14.0, ns)
gtau = np.random.uniform(0.1, 10.0, ns)

mcmc_filename = os.getenv('APPS')+'/prospector_alpha/results/dtau_intmet/dtau_intmet_0181_15268_1424608305_mcmc'
model_filename = os.getenv('APPS')+'/prospector_alpha/results/dtau_intmet/dtau_intmet_0181_15268_1424608305_model'
sample_results, powell_results, model = read_results.read_pickles(mcmc_filename, model_file=model_filename,inmod=None)

# set redshift
sample_results['model'].params['zred'] = np.atleast_1d(0.00)

#params = sample_results['model'].params
#print 1/0
#for kk,nn in params.iteritems():
#    if kk in sps.params.all_params:
#        if kk == 'zmet':
#            vv = np.abs(nn - (np.arange( len(sps.zlegend))+1)).argmin()+1
#        else:
#            vv = nn.copy()
#        sps.params[kk] = vv

#get the spectrum with neb for a variety of neb parameters, compute line luminosity