def contour(chaindir, cosmo, data, compute_param_function): C = ChainIterator(chaindir, cosmo, 'phy', data) z = numpy.arange(0, 3, 0.01) # find best model min_chi2 = numpy.min(C.chain.chain[:, 1]) model_best_index = numpy.argmin(C.chain.chain[:, 1]) print "minimum chi2 = ", min_chi2 T = C.theory(model_best_index) # compute param for this model param_best = numpy.zeros(z.shape) for i in range(z.shape[0]): param_best[i] = compute_param_function(T, z[i]) # allocate param for +- 1 sigma param_1sigma_plus = param_best.copy() param_1sigma_minus = param_best.copy() # selection of models within 1sig model_1sig_indices = numpy.where(C.chain.chain[:, 1] <= min_chi2 + 1)[0] print "number of models at 1 sig = ", model_1sig_indices.shape[0] # if too many, look only at those close to 1 sigma (this is for LCDM, there are too many) chi2_floor = min_chi2 while (model_1sig_indices.shape[0] > 3000): chi2_floor += 0.01 model_1sig_indices = numpy.where((C.chain.chain[:, 1] <= min_chi2 + 1) & (C.chain.chain[:, 1] >= chi2_floor))[0] print "number of selected models for the 1sig contour plot = ", model_1sig_indices.shape[ 0] # loop on models to find max excursion count = 0 for index in model_1sig_indices: count += 1 T = C.theory(index) for i in range(z.shape[0]): parami = compute_param_function(T, z[i]) param_1sigma_minus[i] = min(param_1sigma_minus[i], parami) param_1sigma_plus[i] = max(param_1sigma_plus[i], parami) if count % 100 == 0: print "done %d/%d" % (count, model_1sig_indices.shape[0]) # return -1sig,best,1sig return z, param_1sigma_minus, param_best, param_1sigma_plus
def contour(chaindir,cosmo,data,compute_param_function) : C=ChainIterator(chaindir,cosmo,'phy',data) z=numpy.arange(0,3,0.01) # find best model min_chi2 = numpy.min(C.chain.chain[:,1]) model_best_index = numpy.argmin(C.chain.chain[:,1]) print "minimum chi2 = ", min_chi2 T=C.theory(model_best_index) # compute param for this model param_best=numpy.zeros(z.shape) for i in range(z.shape[0]) : param_best[i]=compute_param_function(T,z[i]) # allocate param for +- 1 sigma param_1sigma_plus=param_best.copy() param_1sigma_minus=param_best.copy() # selection of models within 1sig model_1sig_indices=numpy.where(C.chain.chain[:,1]<=min_chi2+1)[0] print "number of models at 1 sig = ",model_1sig_indices.shape[0] # if too many, look only at those close to 1 sigma (this is for LCDM, there are too many) chi2_floor=min_chi2 while (model_1sig_indices.shape[0]>3000) : chi2_floor+=0.01 model_1sig_indices=numpy.where((C.chain.chain[:,1]<=min_chi2+1)&(C.chain.chain[:,1]>=chi2_floor))[0] print "number of selected models for the 1sig contour plot = ",model_1sig_indices.shape[0] # loop on models to find max excursion count=0 for index in model_1sig_indices : count+=1 T=C.theory(index) for i in range(z.shape[0]) : parami=compute_param_function(T,z[i]) param_1sigma_minus[i]=min(param_1sigma_minus[i],parami) param_1sigma_plus[i]=max(param_1sigma_plus[i],parami) if count%100==0 : print "done %d/%d"%(count,model_1sig_indices.shape[0]) # return -1sig,best,1sig return z,param_1sigma_minus,param_best,param_1sigma_plus
pylab.xlabel(C.latexname(param_2D[0])) pylab.ylabel(C.latexname(param_2D[1])) pylab.savefig(name_fig + '_2D.pdf') pylab.show() if 'True' in Plot_1D: a = 0 for datasets in datasetl: b = 0 for params in params_1D: b += 1 pylab.subplot(1, len(params_1D), b) C = cosmochain(dire + model_1D + '_' + datasets, 'auto') C = ChainIterator('chains_140411_155701', 'LCDM', 'phy', 'BBAO+CMBP') grlist = [] wlist = [] for i in range(0, C.N, 1000): T = C.theory(i) grlist.append(T.growth(10.0)) wlist.append(C.weight(i)) grlist = array(grlist) wlist = array(wlist) mn = (grlist * wlist).sum() / wlist.sum() er = sqrt((grlist**2 * wlist).sum() / wlist.sum() - mn**2) print("growth z=10/z=0 = ", mn, "+/-", er) a += 1 xx, yy = C.GetHisto(params, NormPeak=True, nbins=NBins_1D)
if 'True' in Plot_1D: a=0 for datasets in datasetl: b=0 for params in params_1D: b+=1 pylab.subplot(1,len(params_1D),b) #fname=self.get_filename(dire,model,extra,dataset) C=cosmochain(dire+ model_1D+'_'+datasets,'auto') if(True): #Compute functions= ratio of Fig 2 at z=0.57/0 dire2 = 'chains/DR12/' D=ChainIterator(dire2, 'LCDM','phy', 'CombBAOzb3') grlist=[] wlist=[] for i in range(0,D.N,1000): T=D.theory(i) #grlist.append(T.Da_z(0.57)/T.Hinv_z(0)/(1.0*N.log(1.57))) #grlist.append(T.DaOverrd(0.51)) grlist.append(T.HIOverrd(0.61)) wlist.append(D.weight(i)) grlist=array(grlist) wlist=array(wlist) mn=(grlist*wlist).sum()/wlist.sum() er=sqrt((grlist**2*wlist).sum()/wlist.sum()-mn**2) #print "H(0.0)/(1.0) \over c*ln(1.57)/D_m(0.57) = ",mn,"+/-",er
pylab.ylabel(C.latexname(param_2D[1])) pylab.savefig(name_fig+'_2D.pdf') pylab.show() if 'True' in Plot_1D: a=0 for datasets in datasetl: b=0 for params in params_1D: b+=1 pylab.subplot(1,len(params_1D),b) C=cosmochain(dire+ model_1D+'_'+datasets,'auto') C=ChainIterator('chains_140411_155701','LCDM','phy','BBAO+CMBP') grlist=[] wlist=[] for i in range(0,C.N,1000): T=C.theory(i) grlist.append(T.growth(10.0)) wlist.append(C.weight(i)) grlist=array(grlist) wlist=array(wlist) mn=(grlist*wlist).sum()/wlist.sum() er=sqrt((grlist**2*wlist).sum()/wlist.sum()-mn**2) print "growth z=10/z=0 = ",mn,"+/-",er
#!/usr/bin/env python from RunBase import * from ChainIterator import * C=ChainIterator('chains_140411_155701','LCDM','phy','BBAO+CMBP') grlist=[] wlist=[] for i in range(0,C.N,1000): T=C.theory(i) grlist.append(T.growth(10.0)) wlist.append(C.weight(i)) grlist=array(grlist) wlist=array(wlist) mn=(grlist*wlist).sum()/wlist.sum() er=sqrt((grlist**2*wlist).sum()/wlist.sum()-mn**2) print "growth z=10/z=0 = ",mn,"+/-",er
import numpy as np #from RunBase import * #from cosmich import * from ChainIterator import * if (True): #Compute functions= ratio of Fig 2 at z=0.57/0 dire2 = '/astro/u/jvazquez/work/SimpleMC/trunk/chains/' D = ChainIterator(dire2, 'FCDM', 'phy', 'Planck_15+BBAO+SN', balance=False) grlist = [] wlist = [] with open('my_data.txt', 'w') as g: for i in range(0, D.N, 2000): T = D.theory(i) z = [j for j in np.arange(-0.9, 4, 0.2)] wde = [T.w_de(j) for j in np.arange(-0.9, 4, 0.2)] ll = len(z) t = (D.weight(i), ) + tuple(z) + tuple(wde) g.write(str('%2.5e\t' * (2 * ll + 1) % (t))) g.write('\n')
modell = ['Decay', 'Decay01', 'Decay05'] dire = 'chains_SimpleMC/decay/' data = 'BBAO+Planck' extra = 'phy' z = 'z2' zval = 2.0 for model in modell: outfile = 'chains/' + model + '_' + z + '_' + extra + '_' + data fout = open(outfile + "_1.txt", 'w') formstr = '%g ' * (6) + '\n' C = ChainIterator(dire, model, extra, data, balance=False) grlist = [] wlist = [] for i in range(0, C.N, 400): T = C.theory(i) outstr = formstr % tuple([ C.weight(i), 0.5 * C.chi2(i), C.pvalue(i, 'h'), C.pvalue(i, 'Om'), C.pvalue(i, 'lambda'), T.Om_z(1.0 / (1 + zval)) ]) fout.write(outstr) fout.flush() #print C.chi2(i), C.weight(i), C.pvalue(i,'h'), T.Om_z(0.5)
import numpy as np #from RunBase import * #from cosmich import * from ChainIterator import * if(True): #Compute functions= ratio of Fig 2 at z=0.57/0 dire2 = '/astro/u/jvazquez/work/SimpleMC/trunk/chains/' D=ChainIterator(dire2, 'FCDM','phy', 'Planck_15+BBAO+SN', balance =False) grlist=[] wlist=[] with open('my_data.txt', 'w') as g: for i in range(0,D.N,2000): T=D.theory(i) z = [j for j in np.arange(-0.9,4,0.2)] wde = [T.w_de(j) for j in np.arange(-0.9,4,0.2)] ll = len(z) t = (D.weight(i),) + tuple(z) + tuple(wde) g.write(str('%2.5e\t'*(2*ll+1)%(t))) g.write('\n')