def test_hmf_consistency(): """test consistency of m_cut and n_avg""" power_params = defaults.power_params.copy() power_params.camb['maxkh'] = 5000. power_params.camb['kmax'] = 100. power_params.camb['npoints'] = 1000 C = CosmoPie(defaults.cosmology.copy(),'jdem') P = mps.MatterPower(C,power_params) C.set_power(P) mf_params = defaults.hmf_params.copy() mf_params['log10_min_mass'] = 4 mf_params['n_grid'] = 5000 mf = hmf.ST_hmf(C,mf_params) zs = np.arange(0.2,1.21,1.) z_fine = np.linspace(0.0,3.,4000) geo1 = FullSkyGeo(zs,C,z_fine) nz_matchers = np.zeros(4,dtype=object) nz_lsst_params = defaults.nz_params_lsst.copy() nz_matchers[0] = NZLSST(z_fine,nz_lsst_params) nz_wfirst_params = defaults.nz_params_wfirst_gal.copy() nz_wfirst_params['z_cut'] = 0.2 nz_wfirst_params['smooth_sigma'] = 0.03 nz_matchers[1] = NZWFirst(nz_wfirst_params) nz_matchers[2] = NZWFirstEff(nz_wfirst_params) nz_matchers[3] = NZCandel(nz_wfirst_params) for itr in range(0,nz_matchers.size): m_cuts = nz_matchers[itr].get_M_cut(mf,geo1) nz_got = nz_matchers[itr].get_nz(geo1) nz_hmf = mf.n_avg(m_cuts,z_fine) assert np.allclose(nz_got,nz_hmf/C.h**3)
def __init__(self, params): """some setup to make an actual geo""" #d = np.loadtxt('camb_m_pow_l.dat') #k = d[:,0] #P = d[:,1] self.C = CosmoPie(defaults.cosmology.copy(), p_space='jdem') self.zs = np.array([.01, 1.01]) self.z_fine = np.arange(0.0005, np.max(self.zs), 0.002) self.poly_params = defaults.polygon_params.copy() self.poly_geo = pg.PolygonGeo(self.zs, params['thetas'], params['phis'], params['theta_in'], params['phi_in'], self.C, self.z_fine, params['l_max_poly'], self.poly_params) if params['do_pp_geo1']: self.pp_geo1 = PolygonPixelGeo(self.zs, params['thetas'], params['phis'], params['theta_in'], params['phi_in'], self.C, self.z_fine, params['l_max_poly'], params['res_choose1']) if params['do_pp_geo2']: self.pp_geo2 = PolygonPixelGeo(self.zs, params['thetas'], params['phis'], params['theta_in'], params['phi_in'], self.C, self.z_fine, params['l_max_poly'], params['res_choose2']) if params['do_RectGeo']: self.r_geo = RectGeo(self.zs, params['r_thetas'], params['r_phis'], self.C, self.z_fine) self.params = params
def util_set(): """get set of things needed for tests""" omega_s = 0.02 power_params = defaults.power_params.copy() C = CosmoPie(defaults.cosmology.copy(), p_space='jdem') P_in = mps.MatterPower(C, power_params) C.set_power(P_in) len_params = defaults.lensing_params.copy() len_params['z_bar'] = 1.0 len_params['sigma'] = 0.4 len_params['l_min'] = 30 len_params['l_max'] = 3000 len_params['n_l'] = 1000 len_params['n_gal'] = 118000000 * 6. z_test_res1 = 0.001 zs_test1 = np.arange(0.0005, 2., z_test_res1) dC_ddelta1 = ShearPower(C, zs_test1, omega_s, len_params, mode='dc_ddelta') sp1 = ShearPower(C, zs_test1, omega_s, len_params, mode='power') ls = sp1.l_starts z_min1 = 0.8 z_max1 = 1.0 # r_min1 = C.D_comov(z_min1) # r_max1 = C.D_comov(z_max1) z_min2 = 1.6 z_max2 = 1.8 # r_min2 = C.D_comov(z_min2) # r_max2 = C.D_comov(z_max2) QShear1_1 = QShear(dC_ddelta1, z_min1, z_max1) QShear1_2 = QShear(dC_ddelta1, z_min2, z_max2) ss_1 = Cll_q_q(sp1, QShear1_1, QShear1_2).Cll() return [C, dC_ddelta1, QShear1_1, QShear1_2, ss_1, ls, sp1]
def test_alm_match1(): """Test that alm matches an exact answer retrieved from mathematica""" AVG_TOLERANCE = 10e-8 MAX_TOLERANCE = 10e-7 ZERO_TOLERANCE = 10e-8 test_base = './test_inputs/sph1/' alm_math = np.loadtxt(test_base+'alm_mathematica.dat') lm_table = np.loadtxt(test_base+'lm_table.dat') zs = np.array([.1,.2,.3]) z_fine = np.arange(0.01,0.3,0.001) Theta = [np.pi/4,np.pi/2.] Phi = [0,np.pi/3.+np.sqrt(2.)/100.] C = CosmoPie(cosmology=defaults.cosmology.copy(),p_space='jdem') geo1 = RectGeo(zs,Theta,Phi,C,z_fine) alm_py = np.zeros_like(alm_math) for i in range(0,lm_table.shape[0]): alm_py[i] = geo1.a_lm(lm_table[i,0],lm_table[i,1])# sph.a_lm(geo1,lm_table[i,0],lm_table[i,1]) alm_math1 = alm_math[alm_math>0] alm_py1 = alm_py[alm_math>0] avg_diff = np.average(abs(alm_math1-alm_py1)/alm_math1) max_diff = np.max(abs(alm_math1-alm_py1)/alm_math1) if any(alm_math==0): zero_max_diff = np.max(alm_py1[alm_math==0.]) else: zero_max_diff = 0. print("n nonzero",alm_math1.size) print("avg,max diff:",avg_diff,max_diff) assert avg_diff<AVG_TOLERANCE assert max_diff<MAX_TOLERANCE assert zero_max_diff<ZERO_TOLERANCE
def test_cosmolike_agreement(): """test agreement with cosmolike""" base_dir = './' input_dir = base_dir+'test_inputs/cosmolike_1/' cosmo_results = np.loadtxt(input_dir+'cov_results_7.dat') cosmo_shear = np.loadtxt(input_dir+'shear_shear_cosmo_3.dat') cosmo_nz = np.loadtxt(input_dir+'n_z_2.dat') camb_params = defaults.camb_params.copy() camb_params['force_sigma8'] = True camb_params['leave_h'] = False camb_params['npoints'] = 1000 camb_params['minkh'] = 1.1e-4 camb_params['maxkh'] = 100. camb_params['kmax'] = 1. camb_params['pivot_scalar'] = 0.05 power_params = defaults.power_params.copy() power_params.camb = camb_params RTOL = 3.*10**-2 ATOL = 10**-10 cosmology_cosmolike = { 'Omegab' :0.04868,#fixed 'Omegabh2':0.02204858372,#calculated 'Omegach2':0.12062405128,#calculated 'Omegamh2':0.142672635, 'OmegaL' :0.685,#fixed 'OmegaLh2':0.310256,#calculated 'Omegam' :.315, #fixed 'H0' :67.3, 'sigma8' :.829,#fixed 'h' :0.673,#fixed 'Omegak' :0.0,#fixed 'Omegakh2':0.0, 'Omegar' :0.0,#fixed 'Omegarh2':0.0, 'ns' :0.9603,#fixed 'tau' :0.067, 'Yp' :None, 'As' :2.143*10**-9, 'LogAs' :np.log(2.143*10**-9), 'w' :-1., 'de_model':'constant_w', 'mnu' :0. } C = CosmoPie(cosmology_cosmolike,p_space='basic') lmin_cosmo = 20 lmax_cosmo = 5000 n_b = 20 area_cosmo = 1000. #deg^2 fsky_cosmo = area_cosmo/41253. #41253 deg^2/sky n_gal_cosmo = 10.*(180**2/np.pi**2)*3600 #gal/rad^2 sigma_e_cosmo = 0.27*np.sqrt(2) tomo_bins_cosmo = 4 # amin_cosmo = 0.2 n_s = sigma_e_cosmo**2/(2*n_gal_cosmo) print("n_s",n_s) #format input results lbin_cosmo_1 = cosmo_results[:,0] # lbin_cosmo_2 = cosmo_results[:,1] # lmid_cosmo_1 = cosmo_results[:,2] # lmid_cosmo_2 = cosmo_results[:,3] zbin_cosmo_1 = cosmo_results[:,4] zbin_cosmo_2 = cosmo_results[:,5] zbin_cosmo_3 = cosmo_results[:,6] zbin_cosmo_4 = cosmo_results[:,7] c_g_cosmo_in = cosmo_results[:,8] c_ssc_cosmo_in = cosmo_results[:,9] c_g_cosmo = np.zeros((tomo_bins_cosmo,tomo_bins_cosmo,tomo_bins_cosmo,tomo_bins_cosmo),dtype=object) c_ssc_cosmo = np.zeros((tomo_bins_cosmo,tomo_bins_cosmo,tomo_bins_cosmo,tomo_bins_cosmo),dtype=object) itr = 0 while itr<lbin_cosmo_1.size: zs = np.array([int(zbin_cosmo_1[itr]),int(zbin_cosmo_2[itr]),int(zbin_cosmo_3[itr]),int(zbin_cosmo_4[itr])]) loc_mat1 = np.zeros((n_b,n_b)) loc_mat2 = np.zeros((n_b,n_b)) for l1 in range(0,n_b): for l2 in range(0,n_b): loc_mat1[l1,l2] = c_g_cosmo_in[itr] loc_mat2[l1,l2] = c_ssc_cosmo_in[itr] itr+=1 c_g_cosmo[zs[0],zs[1],zs[2],zs[3]] = loc_mat1 c_ssc_cosmo[zs[0],zs[1],zs[2],zs[3]] = loc_mat2 n_side = int(spp.binom(tomo_bins_cosmo+1,2)) c_g_cosmo_flat = np.zeros((n_side*n_b,n_side*n_b)) c_ssc_cosmo_flat = np.zeros((n_side*n_b,n_side*n_b)) itr1 = 0 #sanity check formatting of input results from cosmolike for i1 in range(tomo_bins_cosmo): for i2 in range(i1,tomo_bins_cosmo): itr2 = 0 for i3 in range(tomo_bins_cosmo): for i4 in range(i3,tomo_bins_cosmo): assert np.all(c_g_cosmo[i1,i2,i3,i4]==c_g_cosmo[i3,i4,i1,i2].T) assert np.all(c_g_cosmo[i1,i2,i3,i4]==c_g_cosmo[i1,i2,i4,i3].T) assert np.all(c_g_cosmo[i1,i2,i3,i4]==c_g_cosmo[i2,i1,i3,i4].T) assert np.all(c_g_cosmo[i1,i2,i3,i4]==c_g_cosmo[i2,i1,i4,i3].T) assert np.all(c_ssc_cosmo[i1,i2,i3,i4]==c_ssc_cosmo[i3,i4,i1,i2].T) assert np.all(c_ssc_cosmo[i1,i2,i3,i4]==c_ssc_cosmo[i1,i2,i4,i3].T) assert np.all(c_ssc_cosmo[i1,i2,i3,i4]==c_ssc_cosmo[i2,i1,i3,i4].T) assert np.all(c_ssc_cosmo[i1,i2,i3,i4]==c_ssc_cosmo[i2,i1,i4,i3].T) c_g_cosmo_flat[itr1:itr1+n_b,itr2:itr2+n_b] = c_g_cosmo[i1,i2,i3,i4] c_ssc_cosmo_flat[itr1:itr1+n_b,itr2:itr2+n_b] = c_ssc_cosmo[i1,i2,i3,i4] if itr2!=itr1: c_g_cosmo_flat[itr2:itr2+n_b,itr1:itr1+n_b] = c_g_cosmo_flat[itr1:itr1+n_b,itr2:itr2+n_b].T c_ssc_cosmo_flat[itr2:itr2+n_b,itr1:itr1+n_b] = c_ssc_cosmo_flat[itr1:itr1+n_b,itr2:itr2+n_b].T itr2+=n_b itr1+=n_b assert np.all(c_g_cosmo_flat==c_g_cosmo_flat.T) assert np.all(c_ssc_cosmo_flat==c_ssc_cosmo_flat.T) Cll_sh_sh_cosmo = np.zeros((tomo_bins_cosmo,tomo_bins_cosmo),dtype=object) itr = 0 for i in range(tomo_bins_cosmo): for j in range(i,tomo_bins_cosmo): Cll_sh_sh_cosmo[i,j] = cosmo_shear[:,itr+1] if not i==j: Cll_sh_sh_cosmo[j,i] = Cll_sh_sh_cosmo[i,j] itr += 1 l_starts = np.zeros(n_b) log_dl = (np.log(lmax_cosmo)-np.log(lmin_cosmo))/n_b l_mids = np.zeros(n_b) l_ends = np.zeros(n_b) dls = np.zeros(n_b) for i in range(l_mids.size): l_starts[i] = np.exp(np.log(lmin_cosmo)+i*log_dl) l_ends[i] = np.exp(np.log(lmin_cosmo)+(i+1)*log_dl) l_mids[i] = np.exp(np.log(lmin_cosmo)+(i+0.5)*log_dl) dls[i] = (np.exp(np.log(lmin_cosmo)+(i+1.)*log_dl)- np.exp(np.log(lmin_cosmo)+i*log_dl)) z_fine = cosmo_nz[:,0] n_z = cosmo_nz[:,1] #prevent going to 0 badly z_fine[0] +=0.00001 cum_n_z = cumtrapz(n_z,z_fine,initial=0.) cum_n_z = cum_n_z/cum_n_z[-1] z_bin_starts = np.zeros(tomo_bins_cosmo) # r_bins = np.zeros((tomo_bins_cosmo,2)) for i in range(0,tomo_bins_cosmo): z_bin_starts[i] = np.min(z_fine[cum_n_z>=1./tomo_bins_cosmo*i]) P_in = mps.MatterPower(C,power_params) C.set_power(P_in) #theta0 = np.pi/4. #theta1 = np.pi/2. #theta_in = np.pi/3. #phi0 = np.pi/4. #phi1 = np.pi/4.+np.pi/4.*0.5443397550644993 #phi_in = np.pi/4.+0.01 #thetas = np.array([theta0,theta1,theta1,theta0,theta0]) #phis = np.array([phi0,phi0,phi1,phi1,phi0]) z_coarse = np.hstack([z_bin_starts,2.]) #geo1 = PolygonGeo(z_coarse,thetas,phis,theta_in,phi_in,C,z_fine.copy(),40,{'n_double':30}) geo1 = CircleGeo(z_coarse,C,0.31275863997971481,100,z_fine.copy(),40,{'n_double':30}) assert np.isclose((geo1.angular_area()*180**2/np.pi**2),1000.) #r_bins = geo1.rbins z_bins = geo1.zbins len_params = defaults.lensing_params.copy() len_params['smodel'] = 'gaussian' len_params['zbar'] = 1. len_params['n_gal'] = n_gal_cosmo len_params['sigma2_e'] = sigma_e_cosmo**2 len_params['l_min'] = np.min(l_starts) len_params['l_max'] = np.max(l_ends) len_params['n_l'] = l_starts.size len_params['pmodel'] = 'halofit' #test lensing observables sp = ShearPower(C,z_fine,fsky_cosmo,len_params,mode='power') qs = np.zeros(tomo_bins_cosmo,dtype=object) for i in range(qs.size): qs[i] = QShear(sp,z_bins[i,0],z_bins[i,1]) Cll_sh_sh = np.zeros((tomo_bins_cosmo,tomo_bins_cosmo),dtype=object) ratio_means = np.zeros((tomo_bins_cosmo,tomo_bins_cosmo)) for i in range(qs.size): for j in range(qs.size): Cll_sh_sh[i,j] = Cll_q_q(sp,qs[i],qs[j]).Cll() ratio_means[i,j] = np.average(Cll_sh_sh[i,j]/Cll_sh_sh_cosmo[i,j]) assert np.allclose(Cll_sh_sh[i,j],Cll_sh_sh_cosmo[i,j],rtol=RTOL,atol=ATOL) print("average Cll ratio: ",np.average(ratio_means)) print("mse Cll: ",np.linalg.norm(np.linalg.norm(1.-Cll_sh_sh/Cll_sh_sh_cosmo))/(Cll_sh_sh.size*Cll_sh_sh[0,0].size)) c_g_flat = np.zeros_like(c_g_cosmo_flat) c_ssc_flat = np.zeros_like(c_g_cosmo_flat) #first test individually by manually building covariance matrix itr1 = 0 for i1 in range(tomo_bins_cosmo): for i2 in range(i1,tomo_bins_cosmo): itr2 = 0 for i3 in range(tomo_bins_cosmo): for i4 in range(i3,tomo_bins_cosmo): ns = np.array([0.,0.,0.,0.]) if i1==i3: ns[0] = n_s if i1==i4: ns[1] = n_s if i2==i4: ns[2] = n_s if i2==i3: ns[3] = n_s qs_in = np.array([qs[i1],qs[i2],qs[i3],qs[i4]]) c_g_flat[itr1:itr1+n_b,itr2:itr2+n_b] = np.diagflat(sp.cov_g_diag(qs_in,ns)) #c_ssc_flat[itr1:itr1+n_b,itr2:itr2+n_b] = c_ssc[i1,i2,i3,i4] if not itr2==itr1: c_g_flat[itr2:itr2+n_b,itr1:itr1+n_b] = c_g_flat[itr1:itr1+n_b,itr2:itr2+n_b].T # c_ssc_flat[itr2:itr2+n_b,itr1:itr1+n_b] = c_ssc_flat[itr1:itr1+n_b,itr2:itr2+n_b].T itr2+=n_b itr1+=n_b assert np.all(c_g_flat==c_g_flat.T) assert np.allclose(c_g_flat,c_g_cosmo_flat,atol=ATOL,rtol=RTOL) assert np.abs(1.-np.average(ratio_means))<0.01 assert np.all(c_ssc_flat==c_ssc_flat.T) #test with SWSurvey pipeline with 1000 sq deg spherical rectangle geo sw_params = {'needs_lensing':True,'cross_bins':True} observable_list = np.array(['len_shear_shear']) sw_survey = SWSurvey(geo1,'c_s',C,sw_params,observable_list=observable_list,len_params=len_params) # C_pow = sw_survey.len_pow.C_pow c_g_sw = sw_survey.get_non_SSC_sw_covar_arrays()[0] nonzero_mask = c_g_sw!=0. rat_c = c_g_cosmo_flat[nonzero_mask]/c_g_sw[nonzero_mask] # rat_m = c_g_flat[nonzero_mask]/c_g_sw[nonzero_mask] assert np.allclose(c_g_sw,c_g_flat) assert np.allclose(c_g_sw,c_g_cosmo_flat,atol=ATOL,rtol=RTOL) print("mean squared diff covariances:"+str(np.linalg.norm(1.-rat_c)/rat_c.size)) print("PASS: all assertions passed")
f_g_w0 = f_set_nopriors[0][2].get_fisher() eig_g_w0 = np.linalg.eigh(f_g_w0)[0] lihu_pars = np.array(['ns', 'Omegach2', 'Omegabh2', 'h', 'LogAs', 'w0', 'wa']) f_set_lihu_prior = np.zeros(3, dtype=object) f_set_jdem_prior = np.zeros(3, dtype=object) f_set_lihu = np.zeros(3, dtype=object) f_set_mat_jdem1 = np.zeros(3, dtype=object) for i in range(0, 3): f_set_mat_jdem1[i] = f_set[i][2].get_fisher() f_set_lihu_prior[i] = np.zeros(3, dtype=object) f_set_lihu[i] = np.zeros(3, dtype=object) f_set_jdem_prior[i] = np.zeros(3, dtype=object) C = CosmoPie(cosmo.copy(), 'jdem') f_set_mat_lihu1 = rotate_jdem_to_lihu(deepcopy(f_set_mat_jdem1), C) f_set_mat_lihu_h_prior = deepcopy(f_set_mat_lihu1) f_set_mat_lihu_h_prior[0][3, 3] += 1.e4 f_set_mat_lihu_h_prior[1][3, 3] += 1.e4 f_set_mat_lihu_h_prior[2][3, 3] += 1.e4 f_set_mat_jdem_h_prior = deepcopy( rotate_lihu_to_jdem(f_set_mat_lihu_h_prior, C)) for i in range(0, 3): f_set_lihu_prior[i][2] = fm.FisherMatrix(f_set_mat_lihu_h_prior[i], fm.REP_FISHER) f_set_lihu[i][2] = fm.FisherMatrix(f_set_mat_lihu1[i], fm.REP_FISHER) f_set_jdem_prior[i][2] = fm.FisherMatrix(f_set_mat_jdem_h_prior[i], fm.REP_FISHER) fig3 = make_standard_ellipse_plot(f_set_jdem_prior, cosmo_par_list,
time0 = time() camb_params = { 'npoints': 2000, 'minkh': 1.1e-4, 'maxkh': 1.476511342960e+02, 'kmax': 1.476511342960e+02, 'leave_h': False, 'force_sigma8': False, 'return_sigma8': False, 'accuracy': 1, 'pivot_scalar': 0.002 } print("main: building cosmology") power_params = defaults.power_params.copy() power_params.camb = camb_params C = CosmoPie(defaults.cosmology.copy(), p_space='jdem') P_lin = mps.MatterPower(C, power_params) C.set_power(P_lin) time1 = time() #x_cut = 527. #l_max = 511 #x_cut = 360 #l_max = 346 #x_cut = 150 #l_max = 139 #x_cut = 93 l_max = 84 x_cut = 5 #l_max = 20
weights=1. * totals_poly) X2, Y2 = np.meshgrid(xedges2, yedges2) ax.pcolormesh(X2, Y2, -H2, cmap='gray') ax.set_aspect('equal') #m.plot(x,y,'bo',markersize=1) ax.set_title("PolygonGeo reconstruction") pp_geo2.sp_poly.draw(m, color='red') plt.show() if do_union_demo: poly_params = defaults.polygon_params.copy() poly_params['n_double'] = 80 l_max_in = 10 zs = np.array([0.01, 1.01]) z_fine = np.arange(0.01, 1.05, 0.01) C = CosmoPie(defaults.cosmology.copy(), p_space='jdem') thetas_wfirst = np.array([ -50., -35., -35., -19., -19., -19., -15.8, -15.8, -40., -40., -55., -78., -78., -78., -55., -55., -50., -50. ]) * np.pi / 180. + np.pi / 2. phis_wfirst = np.array([ -19., -19., -11., -11., 7., 25., 25., 43., 43., 50., 50., 50., 24., 5., 5., 7., 7., -19. ]) * np.pi / 180. phi_in_wfirst = 7. / 180. * np.pi theta_in_wfirst = -35. * np.pi / 180. + np.pi / 2. phis = np.array([ -19., -19., -11., -11., 7., 25., 25., 43., 43., 50., 50., 50., 24., 5., 5., 7., 7., -19. ]) * np.pi / 180. thetas = np.array([
power_params.wmatcher['w_step'] = 0.001 prior_params = defaults.prior_fisher_params.copy() dn_params = defaults.dn_params.copy() dn_params['nz_select'] = 'LSST' dn_params['sigma0'] = 0.1 lw_param_list = np.array([{ 'dn_params': dn_params, 'n_params': n_params_lsst, 'mf_params': mf_params }]) basis_params = defaults.basis_params.copy() basis_params['n_bessel_oversample'] = 400000 #*10 #creat a CosmoPie object to manage the cosmology details print("main: begin constructing CosmoPie") C = CosmoPie(cosmo, p_space=p_space) print("main: finish constructing CosmoPie") #get the matter power spectrum and give it to the CosmoPie print("main: begin constructing MatterPower") P = MatterPower(C, power_params) print("main: finish constructing MatterPower") C.set_power(P) #create the WFIRST geometry #zs are the bounding redshifts of the tomographic bins zs = np.arange(0.2, 3.01, 0.4) zs_lsst = np.linspace(0., 1.2, 3) #z_fine are the resolution redshift slices to be integrated over z_fine = np.linspace(0.001, np.max([zs[-1], zs_lsst[-1]]), 500)
def test_full_sky(): """do some tests with a full sky geo known results""" #get dictionaries of parameters that various functions will need #cosmo = defaults.cosmology_wmap.copy() cosmo = { 'Omegabh2':0.02223, 'Omegach2':0.1153, 'Omegab' :0.04283392714316876, 'Omegac' :0.22216607285683124, 'Omegamh2':0.13752999999999999, 'OmegaL' :0.735, 'OmegaLh2':0.38145113207547166, 'Omegam' :0.265, 'H0' :72.04034509047493, 'sigma8' : 0.8269877678406697, #from the code 'h' :0.7204034509047493, 'Omegak' : 0.0, 'Omegakh2': 0.0, 'Omegar' : 0.0, 'Omegarh2': 0.0, 'ns' : 0.9608, 'tau' : 0.081, 'Yp' :0.299, 'As' : 2.464*10**-9, 'LogAs' :-19.821479791275138, 'w' :-1.0, 'de_model':'constant_w',#dark energy model 'mnu' :0.} cosmo['de_model'] = 'constant_w' cosmo['wa'] = 0. cosmo['w0'] = -1. cosmo['w'] = -1. p_space = 'jdem' camb_params = defaults.camb_params.copy() camb_params['force_sigma8'] = False camb_params['maxkh'] = 100. camb_params['kmax'] = 30. camb_params['npoints'] = 10000 camb_params['pivot_scalar'] = 0.002 power_params = defaults.power_params.copy() power_params.camb = camb_params power_params.camb['accuracy'] = 1 #prior_params = defaults.prior_fisher_params.copy() zs = np.array([0.0001,3.]) z_fine = np.linspace(0.0001,zs[-1],10000) basis_params = defaults.basis_params.copy() basis_params['n_bessel_oversample'] = 400000*10 C = CosmoPie(cosmo,p_space=p_space) l_max = 0 x_cut = 10*np.pi z_max = z_fine[-1]+0.000001 r_max = C.D_comov(z_max) k_cut = x_cut/r_max P = MatterPower(C,power_params) C.set_power(P) geo1 = FullSkyGeo(zs,C,z_fine) basis = SphBasisK(r_max,C,k_cut,basis_params,l_ceil=l_max,needs_m=True) ddbar = basis.get_ddelta_bar_ddelta_alpha(geo1,tomography=True) ns = np.arange(1,ddbar.size+1) ddbar_pred = -3./(2.*np.pi**(5./2.))*(-1)**ns/ns**2 assert np.allclose(ddbar,ddbar_pred) cov_pred = np.zeros((ns.size,ns.size)) xs = P.k*r_max P_in = P.get_matter_power(np.array([0.]),pmodel='linear')[:,0] for i1 in range(0,ns.size): for i2 in range(i1,ns.size): integrand1 = 8.*np.pi**3*(-1)**(ns[i1]+ns[i2])*ns[i1]**2*ns[i2]**2/r_max**3*np.sin(xs)**2/((ns[i1]**2*np.pi**2-xs**2)*(ns[i2]**2*np.pi**2-xs**2)) cov_pred[i1,i2] = np.trapz(integrand1*P_in,xs) if i1!=i2: cov_pred[i2,i1] = cov_pred[i1,i2] cov_got = basis.get_covar_array() var_pred = np.dot(ddbar_pred.T,np.dot(cov_pred,ddbar_pred)) var_got = basis.get_variance(geo1) assert np.all(cov_got==cov_got.T) assert np.allclose(basis.C_id[:,1],ns*np.pi/r_max) assert np.allclose(cov_pred,cov_got,atol=1.e-15,rtol=1.e-3) assert np.isclose(var_got[0,0],var_pred,atol=1.e-15,rtol=1.e-3) ddbar_got2 = basis.get_dO_I_ddelta_alpha(geo1,geo1.r_fine**2)*3./r_max**3 assert np.allclose(ddbar,ddbar_got2,rtol=1.e-3)
def test_half_sky(): """do some tests with a half sky geo known results""" #get dictionaries of parameters that various functions will need cosmo = { 'Omegabh2':0.0222, 'Omegach2':0.1153, 'Omegab' :0.04283392714316876, 'Omegac' :0.22216607285683124, 'Omegamh2':0.13752999999999999, 'OmegaL' :0.735, 'OmegaLh2':0.38145113207547166, 'Omegam' :0.265, 'H0' :72.04034509047493, 'sigma8' : 0.8269877678406697, #from the code 'h' :0.7204034509047493, 'Omegak' : 0.0, 'Omegakh2': 0.0, 'Omegar' : 0.0, 'Omegarh2': 0.0, 'ns' : 0.9608, 'tau' : 0.081, 'Yp' :0.299, 'As' : 2.464*10**-9, 'LogAs' :-19.821479791275138, 'w' :-1.0, 'de_model':'constant_w',#dark energy model 'mnu' :0.} cosmo['de_model'] = 'constant_w' cosmo['wa'] = 0. cosmo['w0'] = -1. cosmo['w'] = -1. p_space = 'jdem' camb_params = defaults.camb_params.copy() camb_params['force_sigma8'] = False camb_params['maxkh'] = 100. camb_params['kmax'] = 30. camb_params['npoints'] = 10000 camb_params['pivot_scalar'] = 0.002 power_params = defaults.power_params.copy() power_params.camb = camb_params power_params.camb['accuracy'] = 1 #prior_params = defaults.prior_fisher_params.copy() zs = np.array([0.0001,3.]) z_fine = np.linspace(0.0001,zs[-1],10000) basis_params = defaults.basis_params.copy() basis_params['n_bessel_oversample'] = 400000*10 #test with half sky using results calculated in mathematica basis_params = defaults.basis_params.copy() basis_params['n_bessel_oversample'] = 400000*10 C = CosmoPie(cosmo,p_space=p_space) l_max = 4 x_cut = 10 z_max = z_fine[-1]+0.000001 r_max = C.D_comov(z_max) k_cut = x_cut/r_max geo1 = HalfSkyGeo(zs,C,z_fine) P = MatterPower(C,power_params) P.P_lin = 1./(P.k*r_max) C.set_power(P) basis = SphBasisK(r_max,C,k_cut,basis_params,l_ceil=l_max,needs_m=False) basis2 = SphBasisK(r_max,C,k_cut,basis_params,l_ceil=l_max,needs_m=True) ddbar = basis.get_ddelta_bar_ddelta_alpha(geo1,tomography=True) ddbar2 = basis2.get_ddelta_bar_ddelta_alpha(geo1,tomography=True) ddbar_got2 = basis.get_dO_I_ddelta_alpha(geo1,geo1.r_fine**2)*3./r_max**3 #ns = np.arange(1,ddbar.size+1) cov_got = basis.get_covar_array() cov_got2 = basis2.get_covar_array() var_got = basis.get_variance(geo1) var_got2 = basis2.get_variance(geo1) cov_pred0 = np.array([[3.220393570704632e-11,-9.51309537893619e-12,9.955267964241254e-12],[-9.51309537893619e-12,5.937410951604845e-11,-1.2342996089442917e-11],[9.955267964241254e-12,-1.2342996089442917e-11,8.524795995567036e-11]]) cov_pred1 = np.array([[4.306831299006748e-11,-7.977015797357624e-12],[-7.977015797357624e-12,6.907871421795387e-11]]) cov_pred2 = np.array([[5.467066924435653e-11,-7.056047462103054e-12],[-7.056047462103054e-12,7.984696153964485e-11]]) cov_pred3 = np.array([[6.70079506270691e-11]]) cov_pred4 = np.array([[7.985214180284307e-11]]) cov_pred = np.zeros((ddbar.size,ddbar.size)) cov_pred[0:3,0:3] = cov_pred0 cov_pred[3:5,3:5] = cov_pred1 cov_pred[5:7,5:7] = cov_pred2 cov_pred[7,7] = cov_pred3 cov_pred[8,8] = cov_pred4 var_pred = np.dot(ddbar,np.dot(cov_pred,ddbar.T)) var_pred2 = np.dot(ddbar2,np.dot(cov_got2,ddbar2.T)) assert np.all(cov_got==cov_got.T) assert np.all(cov_got2==cov_got2.T) assert np.isclose(var_got[0,0],var_pred,atol=1.e-15,rtol=1.e-3) assert np.isclose(var_got2[0,0],var_pred2,atol=1.e-15,rtol=1.e-3) assert np.isclose(var_got2[0,0],var_pred,atol=1.e-15,rtol=1.e-3) assert np.allclose(cov_pred,cov_got,atol=1.e-15,rtol=1.e-3) assert np.allclose(ddbar,ddbar_got2,rtol=1.e-3,atol=1.e-15) for itr in range(0,basis.C_id.shape[0]): if basis.C_id[itr,0]>0 and np.mod(basis.C_id[itr,0],2)==0.: assert ddbar[0,itr] == 0. for itr in range(0,basis2.C_id.shape[0]): if basis2.C_id[itr,0]>0 and np.mod(basis2.C_id[itr,0],2)==0.: assert ddbar2[0,itr] == 0. elif basis2.C_id[itr,2]!=0: assert ddbar2[0,itr] == 0.
def test_rotational_invariance(): """test invariance of results under global rotations""" camb_params = { 'npoints':2000, 'minkh':1.1e-4, 'maxkh':1.476511342960e+02, 'kmax':1.476511342960e+02, 'leave_h':False, 'force_sigma8':False, 'return_sigma8':False, 'accuracy':1, 'pivot_scalar':0.002 } print("main: building cosmology") power_params = defaults.power_params.copy() power_params.camb = camb_params power_params.camb['accuracy'] = 1 power_params.camb['maxkh'] = 100. power_params.camb['kmax'] = 30. power_params.camb['npoints'] = 1000 C = CosmoPie(defaults.cosmology.copy(),p_space='jdem') P_lin = mps.MatterPower(C,power_params) C.set_power(P_lin) l_max = 23 x_cut = 30. print("main: building geometries") polygon_params = defaults.polygon_params.copy() polygon_params['n_double'] = 80 z_coarse = np.array([0.2,1.,2.,3.]) zs_lsst = np.linspace(0.,1.2,3) #z_max = np.max(z_coarse) #z_fine = np.arange(0.0001,z_max,0.0001) z_fine = np.linspace(0.001,3.,500) z_max = z_fine[-1]+0.001 print("main: building basis") basis_params = defaults.basis_params.copy() basis_params['n_bessel_oversample'] = 400000 basis_params['x_grid_size'] = 100000 r_max = C.D_comov(z_max) k_cut = x_cut/r_max basis = SphBasisK(r_max,C,k_cut,basis_params,l_ceil=l_max) geo1 = WFIRSTGeo(z_coarse,C,z_fine,l_max,polygon_params)#HalfSkyGeo(z_coarse,C,z_fine) geo2 = LSSTGeo(zs_lsst,C,z_fine,l_max,polygon_params)#HalfSkyGeo(z_coarse,C,z_fine) geo1_rot1 = AlmRotGeo(geo1,C,z_coarse,z_fine,np.array([0.,np.pi/2.,np.pi]),polygon_params['n_double']) geo1_rot2 = AlmRotGeo(geo1_rot1,C,z_coarse,z_fine,np.array([0.,np.pi/2.,np.pi]),polygon_params['n_double']) geo1_rot3 = AlmRotGeo(geo1_rot2,C,z_coarse,z_fine,np.array([0.005,1.2496,1.72]),polygon_params['n_double']) geo2_rot1 = AlmRotGeo(geo2,C,zs_lsst,z_fine,np.array([0.,np.pi/2.,np.pi]),polygon_params['n_double']) geo2_rot2 = AlmRotGeo(geo2_rot1,C,zs_lsst,z_fine,np.array([0.,np.pi/2.,np.pi]),polygon_params['n_double']) geo2_rot3 = AlmRotGeo(geo2_rot2,C,zs_lsst,z_fine,np.array([0.005,1.2496,1.72]),polygon_params['n_double']) assert np.allclose(geo1.get_alm_array(l_max),geo1_rot2.get_alm_array(l_max)) var_geo1 = basis.get_variance(geo1,k_cut_in=k_cut) var_geo1_rot1 = basis.get_variance(geo1_rot1,k_cut_in=k_cut) var_geo1_rot2 = basis.get_variance(geo1_rot2,k_cut_in=k_cut) var_geo1_rot3 = basis.get_variance(geo1_rot3,k_cut_in=k_cut) assert np.allclose(var_geo1,var_geo1_rot1,atol=1.e-20,rtol=1.e-8) assert np.allclose(var_geo1,var_geo1_rot2,atol=1.e-20,rtol=1.e-8) assert np.allclose(var_geo1,var_geo1_rot3,atol=1.e-20,rtol=1.e-8) var_geo2 = basis.get_variance(geo2,k_cut_in=k_cut) var_geo2_rot1 = basis.get_variance(geo2_rot1,k_cut_in=k_cut) var_geo2_rot2 = basis.get_variance(geo2_rot2,k_cut_in=k_cut) var_geo2_rot3 = basis.get_variance(geo2_rot3,k_cut_in=k_cut) assert np.allclose(var_geo2,var_geo2_rot1,atol=1.e-20,rtol=1.e-8) assert np.allclose(var_geo2,var_geo2_rot2,atol=1.e-20,rtol=1.e-8) assert np.allclose(var_geo2,var_geo2_rot3,atol=1.e-20,rtol=1.e-8) cosmo_par_list = np.array(['ns','Omegamh2','Omegabh2','OmegaLh2','LogAs','w']) cosmo_par_eps = np.array([0.002,0.00025,0.0001,0.00025,0.1,0.01]) nz_params_wfirst_lens = defaults.nz_params_wfirst_lens.copy() nz_params_wfirst_lens['i_cut'] = 26.3 nz_params_wfirst_lens['data_source'] = './data/CANDELS-GOODSS2.dat' nz_wfirst_lens = NZWFirstEff(nz_params_wfirst_lens) sw_params = defaults.sw_survey_params.copy() lw_params = defaults.lw_survey_params.copy() sw_observable_list = defaults.sw_observable_list.copy() lw_observable_list = defaults.lw_observable_list.copy() len_params = defaults.lensing_params.copy() mf_params = defaults.hmf_params.copy() mf_params['n_grid'] = 2000 mf_params['log10_min_mass'] = 10. n_params_lsst = defaults.nz_params_lsst_use.copy() n_params_lsst['i_cut'] = 24.1 #gold standard subset of LSST 1 year (10 year 25.3) dn_params = defaults.dn_params.copy() dn_params['nz_select'] = 'LSST' dn_params['sigma0'] = 0.1 lw_param_list = np.array([{'dn_params':dn_params,'n_params':n_params_lsst,'mf_params':mf_params}]) prior_params = defaults.prior_fisher_params.copy() sw_survey_geo1 = SWSurvey(geo1,'geo1',C,sw_params,cosmo_par_list,cosmo_par_eps,sw_observable_list,len_params,nz_wfirst_lens) sw_survey_geo1_rot1 = SWSurvey(geo1_rot1,'geo1_rot1',C,sw_params,cosmo_par_list,cosmo_par_eps,sw_observable_list,len_params,nz_wfirst_lens) sw_survey_geo1_rot2 = SWSurvey(geo1_rot2,'geo1_rot2',C,sw_params,cosmo_par_list,cosmo_par_eps,sw_observable_list,len_params,nz_wfirst_lens) sw_survey_geo1_rot3 = SWSurvey(geo1_rot3,'geo1_rot3',C,sw_params,cosmo_par_list,cosmo_par_eps,sw_observable_list,len_params,nz_wfirst_lens) survey_lw1 = LWSurvey(np.array([geo1,geo2]),'lw1',basis,C,lw_params,observable_list=lw_observable_list,param_list=lw_param_list) survey_lw1_rot1 = LWSurvey(np.array([geo1_rot1,geo2_rot1]),'lw1',basis,C,lw_params,observable_list=lw_observable_list,param_list=lw_param_list) survey_lw1_rot2 = LWSurvey(np.array([geo1_rot2,geo2_rot2]),'lw1',basis,C,lw_params,observable_list=lw_observable_list,param_list=lw_param_list) survey_lw1_rot3 = LWSurvey(np.array([geo1_rot3,geo2_rot3]),'lw1',basis,C,lw_params,observable_list=lw_observable_list,param_list=lw_param_list) SS_geo1 = SuperSurvey(np.array([sw_survey_geo1]),np.array([survey_lw1]),basis,C,prior_params,get_a=True,do_unmitigated=True,do_mitigated=True,include_sw=True) SS_geo1_rot1 = SuperSurvey(np.array([sw_survey_geo1_rot1]),np.array([survey_lw1_rot1]),basis,C,prior_params,get_a=True,do_unmitigated=True,do_mitigated=True,include_sw=True) SS_geo1_rot2 = SuperSurvey(np.array([sw_survey_geo1_rot2]),np.array([survey_lw1_rot2]),basis,C,prior_params,get_a=True,do_unmitigated=True,do_mitigated=True,include_sw=True) SS_geo1_rot3 = SuperSurvey(np.array([sw_survey_geo1_rot3]),np.array([survey_lw1_rot3]),basis,C,prior_params,get_a=True,do_unmitigated=True,do_mitigated=True,include_sw=True) for i in xrange(0,3): for j in xrange(1,3): assert np.allclose(SS_geo1.f_set_nopriors[i][j].get_covar(),SS_geo1_rot1.f_set_nopriors[i][j].get_covar(),atol=1.e-30,rtol=1.e-8) assert np.allclose(SS_geo1.f_set_nopriors[i][j].get_covar(),SS_geo1_rot2.f_set_nopriors[i][j].get_covar(),atol=1.e-30,rtol=1.e-8) assert np.allclose(SS_geo1.f_set_nopriors[i][j].get_covar(),SS_geo1_rot3.f_set_nopriors[i][j].get_covar(),atol=1.e-30,rtol=1.e-8) a_geo1 = SS_geo1.multi_f.get_a_lw() a_geo1_rot1 = SS_geo1_rot1.multi_f.get_a_lw() a_geo1_rot2 = SS_geo1_rot2.multi_f.get_a_lw() a_geo1_rot3 = SS_geo1_rot3.multi_f.get_a_lw() assert np.allclose(a_geo1[0],a_geo1_rot1[0],atol=1.e-20,rtol=1.e-8) assert np.allclose(a_geo1[1],a_geo1_rot1[1],atol=1.e-20,rtol=1.e-8) assert np.allclose(a_geo1[0],a_geo1_rot2[0],atol=1.e-20,rtol=1.e-8) assert np.allclose(a_geo1[1],a_geo1_rot2[1],atol=1.e-20,rtol=1.e-8) assert np.allclose(a_geo1[0],a_geo1_rot3[0],atol=1.e-20,rtol=1.e-8) assert np.allclose(a_geo1[1],a_geo1_rot3[1],atol=1.e-20,rtol=1.e-8) assert np.allclose(a_geo1[0],var_geo1,atol=1.e-30,rtol=1.e-13) assert np.allclose(a_geo1_rot1[0],var_geo1_rot1,atol=1.e-30,rtol=1.e-11) assert np.allclose(a_geo1_rot2[0],var_geo1_rot2,atol=1.e-30,rtol=1.e-11) assert np.allclose(a_geo1_rot3[0],var_geo1_rot3,atol=1.e-30,rtol=1.e-11) for i in xrange(0,2): for j in xrange(0,2): eig_geo1 = SS_geo1.eig_set[i][j][0] eig_geo1_rot1 = SS_geo1_rot1.eig_set[i][j][0] eig_geo1_rot2 = SS_geo1_rot2.eig_set[i][j][0] eig_geo1_rot3 = SS_geo1_rot3.eig_set[i][j][0] assert np.allclose(eig_geo1,eig_geo1_rot1) assert np.allclose(eig_geo1,eig_geo1_rot2) assert np.allclose(eig_geo1,eig_geo1_rot3)
def test_wfirst_lsst_embed(): """test embedding wfirst in lsst with geometries""" cosmo_fid = defaults.cosmology.copy() C = CosmoPie(cosmo_fid, 'jdem') l_max = 30 zs = np.array([0.01, 1.]) z_fine = np.arange(0.0001, 1.0001, 0.1) do_approximate_checks = True res_healpix_high = 8 res_healpix_low = 7 l_max_high = 30 geo_wfirst = WFIRSTGeo(zs, C, z_fine, l_max, {'n_double': 80}) geo_lsst = LSSTGeo(zs, C, z_fine, l_max, {'n_double': 80}) geo_wfirst_pp1 = WFIRSTPixelGeo(zs, C, z_fine, l_max, res_healpix_low) geo_lsst_pp1 = LSSTPixelGeo(zs, C, z_fine, l_max, res_healpix_low) geo_wfirst_pp2 = WFIRSTPixelGeo(zs, C, z_fine, l_max, res_healpix_high) geo_lsst_pp2 = LSSTPixelGeo(zs, C, z_fine, l_max, res_healpix_high) geo4 = PolygonUnionGeo(geo_lsst.geos, np.append(geo_wfirst, geo_lsst.masks)) geo5 = PolygonPixelUnionGeo(geo_lsst_pp2.geos, np.append(geo_wfirst_pp2, geo_lsst_pp2.masks)) geo6 = PolygonPixelUnionGeo(geo_lsst_pp1.geos, np.append(geo_wfirst_pp1, geo_lsst_pp1.masks)) geo7 = AlmDifferenceGeo(geo_lsst, geo_wfirst, C, zs, z_fine) print(geo4.angular_area(), geo7.angular_area()) assert np.isclose(geo4.angular_area(), geo_lsst.angular_area() - geo_wfirst.angular_area()) assert np.isclose( geo5.angular_area(), geo_lsst_pp2.angular_area() - geo_wfirst_pp2.angular_area()) assert np.isclose( geo6.angular_area(), geo_lsst_pp1.angular_area() - geo_wfirst_pp1.angular_area()) assert np.isclose(geo4.angular_area(), geo7.angular_area()) #geo4 = #WFIRSTGeo(zs,C,z_fine,l_max,{'n_double':80}) #geo5 = WFIRSTPixelGeo(zs,C,z_fine,l_max,res_healpix_high) #geo6 = WFIRSTPixelGeo(zs,C,z_fine,l_max,res_healpix_low) #assert geo4.union_mask.area()<=geo4.masks[0].angular_area() assert np.isclose(geo4.union_pos.area(), geo4.geos[0].angular_area()) assert np.isclose(geo4.angular_area(), geo4.union_pos.area() - geo4.union_mask.area()) assert geo4.angular_area() <= geo4.geos[0].angular_area() assert geo5.angular_area() <= geo5.geos[0].angular_area() assert geo6.angular_area() <= geo6.geos[0].angular_area() assert np.isclose(geo5.angular_area(), geo4.angular_area(), rtol=1.e-3, atol=1.e-3) assert np.isclose(geo6.angular_area(), geo4.angular_area(), rtol=1.e-3, atol=1.e-3) assert np.isclose(geo6.angular_area(), geo5.angular_area(), rtol=1.e-3, atol=1.e-3) alms7_0 = deepcopy(geo7.get_alm_table(8)) alms6_0 = deepcopy(geo6.get_alm_table(8)) alms5_0 = deepcopy(geo5.get_alm_table(8)) alms4_0 = deepcopy(geo4.get_alm_table(8)) alms7_array_0 = deepcopy(geo7.get_alm_array(8)) alms6_array_0 = deepcopy(geo6.get_alm_array(8)) alms5_array_0 = deepcopy(geo5.get_alm_array(8)) alms4_array_0 = deepcopy(geo4.get_alm_array(8)) alms7_1 = deepcopy(geo7.get_alm_table(10)) alms6_1 = deepcopy(geo6.get_alm_table(10)) alms5_1 = deepcopy(geo5.get_alm_table(10)) alms4_1 = deepcopy(geo4.get_alm_table(10)) alms7_array_1 = deepcopy(geo7.get_alm_array(10)) alms6_array_1 = deepcopy(geo6.get_alm_array(10)) alms5_array_1 = deepcopy(geo5.get_alm_array(10)) alms4_array_1 = deepcopy(geo4.get_alm_array(10)) alms7_array_2 = deepcopy(geo7.get_alm_array(l_max_high)) alms6_array_2 = deepcopy(geo6.get_alm_array(l_max_high)) alms5_array_2 = deepcopy(geo5.get_alm_array(l_max_high)) alms4_array_2 = deepcopy(geo4.get_alm_array(l_max_high)) alms_wfirst_array = deepcopy(geo_wfirst.get_alm_array(l_max_high)) alms_lsst_array = deepcopy(geo_lsst.get_alm_array(l_max_high)) alms_wfirst_pp1_array = deepcopy(geo_wfirst_pp1.get_alm_array(l_max_high)) alms_lsst_pp1_array = deepcopy(geo_lsst_pp1.get_alm_array(l_max_high)) alms_wfirst_pp2_array = deepcopy(geo_wfirst_pp2.get_alm_array(l_max_high)) alms_lsst_pp2_array = deepcopy(geo_lsst_pp2.get_alm_array(l_max_high)) alms7_2 = deepcopy(geo7.get_alm_table(l_max_high)) alms6_2 = deepcopy(geo6.get_alm_table(l_max_high)) alms5_2 = deepcopy(geo5.get_alm_table(l_max_high)) alms4_2 = deepcopy(geo4.get_alm_table(l_max_high)) alms7_3 = deepcopy(geo7.get_alm_table(10)) alms6_3 = deepcopy(geo6.get_alm_table(10)) alms5_3 = deepcopy(geo5.get_alm_table(10)) alms4_3 = deepcopy(geo4.get_alm_table(10)) alms7_array_3 = deepcopy(geo7.get_alm_array(10)) alms6_array_3 = deepcopy(geo6.get_alm_array(10)) alms5_array_3 = deepcopy(geo5.get_alm_array(10)) alms4_array_3 = deepcopy(geo4.get_alm_array(10)) #a few basic self consistency checks assert np.all(alms7_array_3[0] == alms7_array_1[0]) assert np.all(alms6_array_3[0] == alms6_array_1[0]) assert np.all(alms5_array_3[0] == alms5_array_1[0]) assert np.all(alms4_array_3[0] == alms4_array_1[0]) assert np.all( alms7_array_2[0][0:alms5_array_1[0].size] == alms7_array_1[0]) assert np.all( alms6_array_2[0][0:alms5_array_1[0].size] == alms6_array_1[0]) assert np.all( alms5_array_2[0][0:alms5_array_1[0].size] == alms5_array_1[0]) assert np.all( alms4_array_2[0][0:alms4_array_1[0].size] == alms4_array_1[0]) assert np.all( alms7_array_2[0][0:alms5_array_0[0].size] == alms7_array_0[0]) assert np.all( alms6_array_2[0][0:alms5_array_0[0].size] == alms6_array_0[0]) assert np.all( alms5_array_2[0][0:alms5_array_0[0].size] == alms5_array_0[0]) assert np.all( alms4_array_2[0][0:alms4_array_0[0].size] == alms4_array_0[0]) assert sorted(list(alms4_1)) == sorted(list(alms7_1)) assert sorted(list(alms4_1)) == sorted(list(alms5_1)) assert sorted(list(alms4_1)) == sorted(list(alms6_1)) assert sorted(list(alms4_2)) == sorted(list(alms5_2)) assert sorted(list(alms4_2)) == sorted(list(alms6_2)) assert sorted(list(alms4_2)) == sorted(list(alms7_2)) assert sorted(list(alms4_0)) == sorted(list(alms5_0)) assert sorted(list(alms4_0)) == sorted(list(alms6_0)) assert sorted(list(alms7_0)) == sorted(list(alms7_0)) assert sorted(list(alms4_3)) == sorted(list(alms5_3)) assert sorted(list(alms4_3)) == sorted(list(alms6_3)) assert sorted(list(alms4_3)) == sorted(list(alms7_3)) assert sorted(list(alms4_1)) == sorted(list(alms4_3)) assert sorted(list(alms5_1)) == sorted(list(alms5_3)) assert sorted(list(alms6_1)) == sorted(list(alms6_3)) assert sorted(list(alms6_1)) == sorted(list(alms7_3)) assert alms7_array_0[0].size == len(list(alms7_0)) assert alms6_array_0[0].size == len(list(alms6_0)) assert alms5_array_0[0].size == len(list(alms5_0)) assert alms4_array_0[0].size == len(list(alms4_0)) assert alms7_array_1[0].size == len(list(alms7_1)) assert alms6_array_1[0].size == len(list(alms6_1)) assert alms6_array_1[0].size == len(list(alms6_1)) assert alms5_array_1[0].size == len(list(alms5_1)) assert alms4_array_2[0].size == len(list(alms4_2)) assert alms5_array_2[0].size == len(list(alms5_2)) assert alms4_array_2[0].size == len(list(alms4_2)) assert alms7_array_3[0].size == len(list(alms7_3)) assert alms6_array_3[0].size == len(list(alms6_3)) assert alms5_array_3[0].size == len(list(alms5_3)) assert alms4_array_3[0].size == len(list(alms4_3)) #assert np.all(alms5_array_3[0]==alms5_array_1[0]) #assert np.all(alms4_array_3[0]==alms4_array_1[0]) for key in list(alms7_0): assert alms7_2[key] == alms7_0[key] for key in list(alms6_0): assert alms6_2[key] == alms6_0[key] for key in list(alms5_0): assert alms5_2[key] == alms5_0[key] for key in list(alms4_0): assert alms4_2[key] == alms4_0[key] for key in list(alms7_1): assert alms7_2[key] == alms7_1[key] assert alms7_3[key] == alms7_1[key] for key in list(alms6_1): assert alms6_2[key] == alms6_1[key] assert alms6_3[key] == alms6_1[key] for key in list(alms5_1): assert alms5_2[key] == alms5_1[key] assert alms5_3[key] == alms5_1[key] for key in list(alms4_1): assert alms4_2[key] == alms4_1[key] for itr in range(0, alms7_array_2[0].size): assert alms7_2[(alms7_array_2[1][itr], alms7_array_2[2][itr])] == alms7_array_2[0][itr] for itr in range(0, alms6_array_2[0].size): assert alms6_2[(alms6_array_2[1][itr], alms6_array_2[2][itr])] == alms6_array_2[0][itr] for itr in range(0, alms5_array_2[0].size): assert alms5_2[(alms5_array_2[1][itr], alms5_array_2[2][itr])] == alms5_array_2[0][itr] for itr in range(0, alms4_array_2[0].size): assert alms4_2[(alms4_array_2[1][itr], alms4_array_2[2][itr])] == alms4_array_2[0][itr] #check inter geo consistency if do_approximate_checks: assert np.allclose(alms5_array_2, alms4_array_2, atol=1.e-3, rtol=1.e-3) assert np.allclose(alms5_array_2, alms6_array_2, atol=5.e-3, rtol=5.e-3) assert np.allclose(alms4_array_2, alms6_array_2, atol=5.e-3, rtol=5.e-3) assert np.allclose(alms6_array_2, alms7_array_2, atol=5.e-3, rtol=5.e-3) assert np.allclose(alms5_array_2, alms7_array_2, atol=5.e-3, rtol=5.e-3) assert np.allclose(alms4_array_2, alms7_array_2) #use complete intersection assert np.allclose(alms4_array_2[0], alms_lsst_array[0] - alms_wfirst_array[0]) assert np.allclose(alms5_array_2[0], alms_lsst_pp2_array[0] - alms_wfirst_pp2_array[0]) assert np.allclose(alms6_array_2[0], alms_lsst_pp1_array[0] - alms_wfirst_pp1_array[0]) assert np.allclose(alms7_array_2[0], alms_lsst_array[0] - alms_wfirst_array[0]) pixels = get_healpix_pixelation(res_healpix_low) reconstruct4 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1], alms4_2) reconstruct5 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1], alms5_2) reconstruct6 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1], alms6_2) reconstruct7 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1], alms7_2) assert np.allclose(reconstruct4, reconstruct7) if do_approximate_checks: assert np.allclose(reconstruct4, reconstruct5, atol=4.e-2, rtol=1.e-4) assert np.allclose(reconstruct4, reconstruct6, atol=4.e-1, rtol=1.e-4) assert np.allclose(reconstruct5, reconstruct6, atol=4.e-1, rtol=1.e-4) assert np.allclose(reconstruct5, reconstruct7, atol=4.e-1, rtol=1.e-4) assert np.allclose(reconstruct6, reconstruct7, atol=4.e-1, rtol=1.e-4)
def test_rint_match_mp(): """ Test numeric integral compared to mp arbitrary precision Both the numeric and mp results should agree scipy's hypergeometric functions would fail this test because of a catastrophic loss of precision, mp works but to avoid mp dependency we just use numerical method """ print("test_rint_match_mp: begin testing numeric r integral agreement with exact (arbitrary precision) mp solution") ZERO_TOLERANCE = 10e-13 MAX_TOLERANCE = 10e-11 AVG_TOLERANCE = 10e-13 ls = np.arange(0,70) k_cut = 0.015 r_max = 4000 r1 = 100 r2 = 3000 r1_m = mp.mpf(r1) r2_m = mp.mpf(r2) mp.dps = 200 diff_tot = 0. diff_max = 0. zero_diff = 0. diff_tot2 = 0. diff_max2 = 0. zero_diff2 = 0. n_count = 0 z_count = 0 bad_count = 0 C = CosmoPie(defaults.cosmology.copy(),p_space='jdem') P_lin = mps.MatterPower(C,defaults.power_params.copy()) C.set_power(P_lin) basis = sph.SphBasisK(r_max,C,k_cut,defaults.basis_params.copy()) rints = basis.gen_R_cache(np.array([[r1,r2]])) for ll in ls: ks = jn_zeros_cut(ll,k_cut*r_max)/r_max ll_m = mp.mpf(ll) for i in range(0,ks.size): kk_m = mp.mpf(ks[i]) hyp1 = mp.hyp1f2(1.5+ll_m/2.,2.5+ll_m/2.,1.5+ll_m,-1./4*kk_m**2*r2_m**2)*r2_m**(3+ll_m) hyp2 = mp.hyp1f2(1.5+ll_m/2.,2.5+ll_m/2.,1.5+ll_m,-1./4.*kk_m**2*r1_m**2)*r1_m**(3+ll_m) r_int_exact = float(1./((3.+ll_m)*mp.gamma(1.5+ll_m))/2.**(ll_m+1.)*kk_m**ll_m*mp.sqrt(mp.pi)*(hyp1-hyp2)) r_int_compute = sph.R_int([r1,r2],ks[i],ll) #r_int_compute2 = (basis.rints[ll](r2*ks[i])-basis.rints[ll](r1*ks[i]))/ks[i]**3 r_int_compute2 = rints[(ks[i],ll)]*(r2**3-r1**3)/3. if np.abs(r_int_exact)>0.: diff = np.abs(r_int_compute-r_int_exact)/r_int_exact diff2 = np.abs(r_int_compute2-r_int_exact)/r_int_exact n_count+=1 diff_tot+=diff diff_tot2+=diff2 if diff>MAX_TOLERANCE: #print("test_rint_match_mp: error outside tolerance at l,k,numeric,mp: ",ll,ks[i],r_int_compute,r_int_exact) bad_count+=1 diff_max = max(diff_max,diff) diff_max2 = max(diff_max2,diff2) else: zero_diff+=r_int_compute zero_diff2+=r_int_compute2 z_count+=1 print("test_rint_match_mp: zero diff, n zero",zero_diff,z_count) print("test_rint_match_mp: max diff, avg diff,n",diff_max,diff_tot/n_count,n_count) print("test_rint_match_mp: max diff tolerance, avg diff tolerance",MAX_TOLERANCE,AVG_TOLERANCE) print("test_rint_match_mp: n values outside tolerance",bad_count) if z_count>0: assert ZERO_TOLERANCE>zero_diff/z_count assert ZERO_TOLERANCE>zero_diff2/z_count assert MAX_TOLERANCE>diff_max assert MAX_TOLERANCE>diff_max2 assert AVG_TOLERANCE>diff_tot/n_count assert AVG_TOLERANCE>diff_tot2/n_count print("test_rint_match_mp: finished testing numeric r integral agreement with exact (arbitrary precision) mp solution")
"""test approximate a circular geometry with PolygonGeo""" from __future__ import absolute_import, division, print_function from builtins import range import numpy as np from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt from cosmopie import CosmoPie import defaults from circle_geo import CircleGeo if __name__ == '__main__': do_plot = True cosmo_fid = defaults.cosmology.copy() C = CosmoPie(cosmo_fid, 'jdem') l_max = 2 zs = np.array([0.01, 1.]) z_fine = np.arange(0.01, 1.0001, 0.01) radius = 0.3126603700269391 n_x = 100 error_old = 10000000. error_new = 1000000. area_goal = 2098.2028581550499 do_gen = False if do_gen: radius = radius geo1 = CircleGeo(zs, C, radius, n_x, z_fine, l_max, {'n_double': 30}) if do_plot: m = Basemap(projection='moll', lon_0=0) geo1.sp_poly.draw(m, color='red')