def calc_C_matrices(Npix = 32, #pixels field_width = 120., #arcmin z0 = 0.5, nz_a = 2, nz_b = 1.5, zlim = (0,3), ngal_arcmin=20, compute=True, filename='C_calc.npz'): dpix = field_width/Npix n_z = lambda z: z**nz_a * numpy.exp(-(z/z0)**nz_b) ngal = ngal_arcmin*dpix**2 if compute: Om_range = (0.1,0.3,0.5) s8_range = (0.6,0.8,1.0) C = numpy.zeros((3,3,Npix**2,Npix**2)) for i,Om in enumerate(Om_range): for j,s8 in enumerate(s8_range): xi = xi_plus(n_z, zlim, Nz=20, Or=0, Om=Om, sigma8=s8) C[i,j] = compute_correlation_matrix(xi, Npix = Npix, dpix = dpix, ngal = ngal, sigma = sigma, whiten=True) evals,evecs = compute_KL(C[1,1]) numpy.savez(filename, C=C, Om_range=Om_range, s8_range=s8_range, evals=evals, evecs=evecs) else: X = numpy.load(filename) C = X['C'] Om_range = X['Om_range'] s8_range = X['s8_range'] evals = X['evals'] evecs = X['evecs'] return C,Om_range,s8_range,evals,evecs
def shear_correlation_matrix(sigma, RArange, DECrange, Ngal, n_z = zdist, whiten = True, cosmo=None, **kwargs): """ Compute the correlation matrix based on the COSMOS geometry Parameters ---------- sigma : float intrinsic ellipticity in each pixel RArange : float array, size = NRA + 1 RA bin edges DECrange : float array, size = NDEC + 1 DEC bin edges Ngal : integer array, shape = (NRA, NDEC) number of galaxies in each bin. This can be determined using the routine `shear_mask_vector` z0, nz_a, nz_b : float specify the galaxy redshift distribution: n(z) ~ z^a * exp[-(z/z0)^b] cosmo : cosmology object if unspecified, a Cosmology object will be initialized from kwargs Returns ------- C : the theoretical covariance matrix of the COSMOS data """ xi = xi_plus(n_z, Nz=20, cosmo=cosmo, **kwargs) dpix1 = 60. * (RArange[1] - RArange[0]) dpix2 = 60. * (DECrange[1] - DECrange[0]) Npix1 = len(RArange) - 1 Npix2 = len(DECrange) - 1 #compute correlation, no shot noise if (Npix1 == Npix2) and (dpix1 == dpix2): C = compute_correlation_matrix(xi, Npix=Npix1, dpix=dpix1, ngal=1, sigma=0, whiten=False) else: C = compute_correlation_matrix_nonsquare(xi, Npix1=Npix1, dpix1=dpix1, Npix2=Npix2, dpix2=dpix2, ngal=1, sigma=0, whiten=False) Ngal = Ngal.reshape(Npix1 * Npix2) i_zero = np.where(Ngal==0)[0] Ngal[i_zero] = 1 noise_squared_diag = sigma**2 / Ngal.reshape(Npix1*Npix2) Ngal[i_zero] = 0 #add shot noise C.flat[::Npix1 * Npix2 + 1] += noise_squared_diag #zero-out correlation matrix where there is no data C[i_zero] = 0 C[:,i_zero] = 0 if whiten: noise_inv = noise_squared_diag**-0.5 C *= noise_inv[:,None] C *= noise_inv return C