def dnilensdz(z,spec): if spec=="magic": nlens_total=0.25 # is my normalisation factor okay? return nlens_total*cosmo_functions.comoving_distance(z)**2/ cosmo_functions.results.hubble_parameter(z)/normalisation_factor_lenses elif spec=="LSST": ngal=40 z0=0.3 return ngal*1/(2*z0)*(z/z0)**2*np.exp(-z/z0)
def size_of_covmatrix(ls, ell_index, clustering_bin_number): l = ls[ell_index] boundaries = bin_boundaries(clustering_bin_number) upperlimits = [ 2 * np.pi * cosmo_functions.comoving_distance(minz) / 10 * H0 / 100 for minz in boundaries[:-1] ] index = 0 while (index < clustering_bin_number): if l < upperlimits[index]: return clustering_bin_number + 10 - index else: index = index + 1 return 10
def Wkgal_lensing(chi,i): # i is the ith redshift bin, starting at 0!!! zmin=boundaries_sources[i] zmax=boundaries_sources[i+1] z=cosmo_functions.redshift(chi) if(z>zmax): return 0 if(z<zmin): zsources=np.linspace(zmin,zmax,10) else: zsources=np.linspace(z,zmax,10) integrand=[dnsource_dz(z)*Wk(chi,cosmo_functions.comoving_distance(z)) for z in zsources] # print("integran dis",integrand) # plt.plot(zsources,integrand,'o') # plt.show() # print( 1/number_of_sources_between_zs(zmin,zmax)) # print("integral should be",integrate.simps(integrand,zsources)) # print ("answer should be",1/number_of_sources_between_zs(zmin,zmax),"times",integrate.simps(integrand,zsources),"equals",1/number_of_sources_between_zs(zmin,zmax) *integrate.simps(integrand,zsources)) return 1/number_of_sources_between_zs(zmin,zmax) *integrate.simps(integrand,zsources) #number of sources should be 2.6 by definition no?
def Cls(spec, ls, resolution, number_of_clustering_bins, experiment=None): if spec[0] == "shear": shears = ["shear_" + str(i) for i in range(0, source_bins)] shear_powerspectra = np.zeros((source_bins, source_bins, len(ls))) Ws = np.zeros( (source_bins, resolution) ) #want to evaluate the redshift kernel FOR EACH SOURCE BIN AT EACH Z SAMPLE #set up the Ws by evaluating at each z zs = np.linspace(0.01, 4, resolution) chis = cosmo_functions.comoving_distance(zs) for i in range(0, source_bins): Ws[i, :] = lensing_kernels.W(shears[i], chis, number_of_clustering_bins) for i in range(0, source_bins): Ws1 = Ws[i] for j in range(0, source_bins): Ws2 = Ws[j] if j >= i: shear_powerspectra[i, j] = shear_powerspectra[j, i] = Cls_limber( ls, Ws1, Ws2, Plin, chis, zs) return shear_powerspectra elif spec[0] == "clustering": N_field = N_fields(number_of_clustering_bins) bini_powerspectra = np.zeros((N_field, len(ls))) z_bin_boundaries = bin_boundaries(number_of_clustering_bins) redshift_bin = spec[1] zmin = z_bin_boundaries[redshift_bin] zmax = z_bin_boundaries[redshift_bin + 1] galaxy_bias = 0.95 / cosmo_functions.D_growth_norm1_z0( cosmo_functions.z2a((zmin + zmax) / 2)) zs = np.linspace(zmin, zmax, resolution) chis = cosmo_functions.comoving_distance(zs) W_clustering = np.zeros(len(chis)) normalisation = integrate.simps( [lensing_kernels.dnilensdz(z, experiment) for z in zs], zs) W_clustering = galaxy_bias * lensing_kernels.W( "density_" + str(redshift_bin + 1), chis, number_of_clustering_bins, experiment) / normalisation Ws = np.zeros((source_bins, resolution)) for i in range(0, source_bins): if (zmin < lensing_kernels.boundaries_sources[i + 1] ): #want the lenses to be BEHIND the clustering galaxies Ws[i, :] = lensing_kernels.W("shear_" + str(i), chis, number_of_clustering_bins) bini_powerspectra[number_of_clustering_bins + i, :] = Cls_limber( ls, W_clustering, Ws[i], Plin, chis, zs) bini_powerspectra[redshift_bin, :] = Cls_limber( ls, W_clustering, W_clustering, Plin, chis, zs) return bini_powerspectra else: print("spec problem; spec is", spec) return
def Cls_fnlderivatives(redshift_bin, ls, zresolution_clusteringbins, number_of_clustering_bins, experiment): N_field = N_fields(number_of_clustering_bins) bini_powerspectrafnlderivs = np.zeros((N_field, len(ls))) z_bin_boundaries = bin_boundaries(number_of_clustering_bins) zmin = z_bin_boundaries[redshift_bin] zmax = z_bin_boundaries[redshift_bin + 1] galaxy_bias = 0.95 / cosmo_functions.D_growth_norm1_z0( cosmo_functions.z2a((zmin + zmax) / 2)) zs = np.linspace(zmin, zmax, zresolution_clusteringbins) chis = cosmo_functions.comoving_distance(zs) W_clustering = np.zeros(len(chis)) normalisation = integrate.simps( [lensing_kernels.dnilensdz(z, experiment) for z in zs], zs) W_clustering = galaxy_bias * lensing_kernels.W( "density_" + str(redshift_bin + 1), chis, number_of_clustering_bins, experiment) / normalisation Ws = np.zeros((source_bins, zresolution_clusteringbins)) Cl_fnlderivs = np.zeros(len(ls)) fnl_factors = np.zeros((len(chis), len(ls))) for z_index in range(0, len(chis)): for l_index in range(0, len(ls)): k = (ls[l_index] + 1 / 2) / chis[z_index] fnl_factors[z_index, l_index] = cosmo_functions.fnl_bias_factor( k, chis[z_index]) for ell_index, l in enumerate(ls): Ks = (l + 1 / 2) / chis integrand = [ 2 * W_clustering[k] * W_clustering[k] * Plin(zs[k], (l + 1 / 2) / chis[k]) / chis[k]**2 * 1 / galaxy_bias * 1 / Ks[k]**2 * (galaxy_bias - 1) * fnl_factors[k, ell_index] for k in range(0, len(chis)) ] Cl_fnlderivs[ell_index] = (integrate.simps(integrand, chis)) bini_powerspectrafnlderivs[redshift_bin, :] = Cl_fnlderivs for i in range(0, source_bins): if (zmin < lensing_kernels.boundaries_sources[i + 1] ): #want the lenses to be BEHIND the clustering galaxies Ws[i, :] = lensing_kernels.W("shear_" + str(i), chis, number_of_clustering_bins) Cl_fnlderivs = np.zeros(len(ls)) for ell_index, l in enumerate(ls): Ks = (l + 1 / 2) / chis integrand = [ Ws[i, k] * W_clustering[k] * Plin(zs[k], (l + 1 / 2) / chis[k]) / chis[k]**2 * 1 / galaxy_bias * 1 / Ks[k]**2 * (galaxy_bias - 1) * fnl_factors[k, ell_index] for k in range(0, len(chis)) ] Cl_fnlderivs[ell_index] = (integrate.simps(integrand, chis)) bini_powerspectrafnlderivs[number_of_clustering_bins + i, :] = Cl_fnlderivs return bini_powerspectrafnlderivs
def WCMB(chi): chi_CMB=cosmo_functions.comoving_distance(1100) chi_S=chi_CMB #want to return CMB lensing efficiency kernel; see eg eq 4 of 1607.01761 return 3/2*(H0/c)**2*omegam*chi/cosmo_functions.a(chi)*(1-chi/chi_S)
def Wkgal_lensing_workingforarrays(chis,i): # i is the ith redshift bin, starting at 0!!! #this might be sort of hard. chis=np.atleast_1d(chis) answer=np.zeros(len(chis)) integrand=np.zeros((len(chis),10)) zmin=boundaries_sources[i] zmax=boundaries_sources[i+1] zs=cosmo_functions.redshift(chis) answer[zs>zmax]=0 density=1/number_of_sources_between_zs(zmin,zmax) zsources=np.zeros((len(zs),10)) for i in range(0,len(zs)): if zs[i]<zmin: zsources[i,:]=np.linspace(zmin,zmax,10) else: zsources[i,:]=np.linspace(zs[i],zmax,10) integrand[zs<zmax,:]=dnsource_dz(zsources[zs<zmax,:])*Wk(chis[zs<zmax,np.newaxis],cosmo_functions.comoving_distance(zsources[zs<zmax,:].flatten()).reshape((len(chis[zs<zmax]),10))) # print("integrand is",integrand) # print("one over density should be",1/density*integrate.simps(integrand[0],zsources[0])) answer[zs<zmax]=density*integrate.simps(integrand[zs<zmax,:],zsources[zs<zmax,:]) # plt.plot(zsources[0],integrand[0],'o') # plt.show() return answer#number of sources should be 2.6 by definition no?
# print("one over density should be",1/density*integrate.simps(integrand[0],zsources[0])) answer[zs<zmax]=density*integrate.simps(integrand[zs<zmax,:],zsources[zs<zmax,:]) # plt.plot(zsources[0],integrand[0],'o') # plt.show() return answer#number of sources should be 2.6 by definition no? ''' Galaxy density efficiency kernel ''' Zs=np.linspace(0.2,1,100) normalisation_factor_lenses=integrate.simps(cosmo_functions.comoving_distance(Zs)**2/ cosmo_functions.results.hubble_parameter(Zs),Zs) def dnilensdz(z,spec): if spec=="magic": nlens_total=0.25 # is my normalisation factor okay? return nlens_total*cosmo_functions.comoving_distance(z)**2/ cosmo_functions.results.hubble_parameter(z)/normalisation_factor_lenses elif spec=="LSST": ngal=40 z0=0.3 return ngal*1/(2*z0)*(z/z0)**2*np.exp(-z/z0)