sN_uKamin = 35.0 nsims = 2 lcell_side_amin = np.sqrt(4.0 * np.pi) / (2 ** 13) / np.pi * 180 * 60.0 # length of lcell of the data resolution path_to_libs = "/Users/jcarron/data/flatsky_lens_simlibs/test_wPL201512" # """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" # FIXME : problem when HD_res is not LD_res. I believe this is due to an inconsistent # FIXME : pixwindow fct in covmatrices. # FIXME : some aspects like noise-levels, cg. inversion etc are very dependent on the low-ell # FIXME : interpolation scheme. Understand the best way to handle that. # """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" bins_l = np.int64(np.logspace(1.5, 4.0, 50)) bins_u = bins_l[1:] - 1 bins_l = bins_l[0 : len(bins_l) - 1] binner = jc_utils.binner(bins_l, bins_u) del bins_l, bins_u HD_shape = (2 ** HD_res, 2 ** HD_res) # resolution for CMB and lensing operation done at LD_shape = (2 ** LD_res, 2 ** LD_res) # resolution of the dat map lside = ( lcell_side_amin / 60.0 / 180.0 * np.pi * LD_shape[0] * np.ones(2) ) # pixel res always the same always at 1.7 amin. lmax_cl = 10000 cl_unl = camb.spectra_fromcambfile( "/Users/jcarron/SpyderProjects/lenscov/additional_files/planck_lensing_wp_highL_bestFit_20130627_lenspotentialCls.dat", lmax=lmax_cl, )["tt"][:] cl_len = camb.spectra_fromcambfile( "/Users/jcarron/SpyderProjects/lenscov/additional_files/planck_lensing_wp_highL_bestFit_20130627_lensedCls.dat",
def plot_cls(parfile,type = 'len',mc_sims = None,Nbins = 100): """ Plots the sims cls in comparison to input cl_len. """ assert type in ['len','unl','pp','OO'] par = imp.load_source('par',parfile) lib = {'len':par.lib_cmb_len,'unl':par.lib_cmb_unl,'pp':par.lib_pp,'OO':par.lib_OO}[type] if lib is None : print 'no such lib, returning' return input_cl = {'len':par.cl_len,'unl':par.cl_unl,'pp':par.cl_pp,'OO':par.lib_OO}[type] if not os.path.exists(par.lib_dir + '/figs') : os.mkdir(par.lib_dir + '/figs') bins_l = np.int64(np.linspace(10.,3000,Nbins)) bins_u = bins_l[1:] -1 bins_l = bins_l[0:len(bins_l)-1] binner = utils.binner(bins_l,bins_u) stats_len = utils.stats(binner.Nbins()) if mc_sims is None : mc_sims = np.arange(par.nsims) for i,idx in utils.enumerate_progress(mc_sims,label = 'test_cl::collecting cls'): sim_cl = par.lib_cmb_unl.map2cl(lib.get_sim(idx)) ell = np.arange(len(sim_cl)) stats_len.add(binner.bin_that(ell,sim_cl)) if i == 0 : cl_unb = sim_cl.copy() sig_unb = sim_cl.copy() ** 2 else : cl_unb += sim_cl sig_unb += sim_cl ** 2 cl_unb /= (i + 1.) sig_unb /= (i + 1.) sig_unb = np.sqrt(sig_unb - cl_unb ** 2) # Unbinned sigmas. cl_input_binned = binner.bin_that(np.arange(len(par.cl_len)),input_cl) prefix = '' if not hasattr(par,'prefix') else par.prefix if not os.path.exists('./figs/' + prefix) : os.mkdir('./figs/' + prefix) pp = PdfPages('./figs/' + prefix+'/cl'+type +'_vs_input. Nb'+str(Nbins)+'.pdf') pl.ioff() pl.figure('Cl ratios') pl.title('Binned cl vs input, ' +str(len(mc_sims)) + ' sims.') pl.plot(binner.bin_centers(),stats_len.mean()/cl_input_binned -1.,label = 'sim/input -1.,binned, res ' + str(par.HD_res)) pl.xlabel('$\ell$') pl.ylim(-0.05,0.05) pl.hlines([-0.001,0.001],np.min(binner.bins_l),np.max(binner.bins_r),linestyles='--',color = 'grey') pl.legend(frameon = False) pp.savefig() pl.close() pl.figure('Unbinned Cl mean') pl.title('Unbinned Cl mean') counts = par.lib_cmb_unl.get_ellcounts() ell = np.arange(len(counts)) nz = np.where(counts[0:len(input_cl)-1] > 0) pl.plot(ell[nz],cl_unb[nz]/input_cl[nz] -1.,label = 'cl sim / input -1 ') pl.plot(ell[nz], np.sqrt(1./counts[nz]/len(mc_sims)),linestyle = '--',color = 'black',label = '$\sigma $ Gauss.') pl.plot(ell[nz], -np.sqrt(1./counts[nz]/len(mc_sims)),linestyle = '--',color = 'black') pl.plot(ell[nz],- np.sqrt(2./(2*ell[nz] + 1)/len(mc_sims)),linestyle = '--',color = 'black' ) pl.plot(ell[nz], np.sqrt(2./(2*ell[nz] + 1)/len(mc_sims)),linestyle = '--',color = 'black' ) pl.hlines([0.],0.,max(ell[nz]),color = 'grey',linestyle = '--') pl.legend(frameon= False) pp.savefig() pl.close() pl.figure('Unbinned Cl variance') pl.title('Unbinned Cl variance') counts = par.lib_cmb_unl.get_ellcounts() ell = np.arange(len(counts)) nz = np.where(counts[0:len(input_cl) - 1] > 0) pl.plot(ell[nz],sig_unb[nz]/np.sqrt(2 * input_cl[nz] ** 2 / (2 * ell[nz] + 1.)) -1.,label = 'sim sig./ Gauss sig -1. ') pl.plot(ell[nz],sig_unb[nz]/np.sqrt(input_cl[nz] ** 2 / counts[nz]) -1.,label = 'incl. discrtness') pl.ylim(-1,1.) pl.hlines([0.],0.,max(ell[nz]),color = 'grey',linestyle = '--') pl.legend(frameon = False) pp.savefig() pl.close() pp.close()