def check_Bessel_spectrum(l, k=None, r0=100): # Initialise survey and spectra cosmo = cosmicpy.cosmology() surv = cosmicpy.survey(nzparams={ 'type': 'gaussian', 'cosmology': cosmo, 'r0': r0 }, zmax=5, fsky=1.0) spectra = cosmicpy.spectra(cosmo, surv) survey_volume = pi**(3.0 / 2.0) * r0**3 if k is None: k = np.logspace(log(0.0001) / log(10), log(0.25) / log(10), 512, endpoint=False) kw, w = spectra.W(l, k, evol=False) kw = kw.squeeze() w = w.squeeze() w_exact = np.zeros_like(w) for k1 in range(len(k)): w_exact[k1, :] = gaussian_bessel_window(l, r0, k[k1], kw[k1, :]) / survey_volume pk = cosmo.pk_lin(kw) integrand = np.square(kw * w_exact) * pk res = (2.0 / pi)**2 * trapz(integrand, x=kw) cl = spectra.cl_sfb(l, k) return k, cl, res
def check_Bessel_spectrum(l, k=None, r0=100): # Initialise survey and spectra cosmo = cosmicpy.cosmology() surv = cosmicpy.survey(nzparams={'type': 'gaussian', 'cosmology': cosmo, 'r0': r0}, zmax=5, fsky=1.0) spectra = cosmicpy.spectra(cosmo, surv) survey_volume = pi**(3.0 / 2.0) * r0**3 if k is None: k = np.logspace(log(0.0001) / log(10), log(0.25) / log(10), 512, endpoint=False) kw, w = spectra.W(l, k, evol=False) kw = kw.squeeze() w = w.squeeze() w_exact = np.zeros_like(w) for k1 in range(len(k)): w_exact[k1, :] = gaussian_bessel_window(l,r0, k[k1], kw[k1,:])/ survey_volume pk = cosmo.pk_lin(kw) integrand = np.square(kw * w_exact) * pk res = (2.0 / pi)**2 * trapz(integrand, x=kw) cl = spectra.cl_sfb(l, k) return k, cl, res
def check_Bessel_window(l, k=None, r0=100): r""" Checks the computation of the bessel window compared to the exact solution for Gaussian selection functions. Parameters ---------- l : int Order of the multipole. r0 : real, optional Radius parameter for the survey Gaussian selection function in Mpc/h Returns ------- (k, W, Wexact) : tuple of ndarrays Window compute the discrete spherical bessel transform and the exact window computed from theory """ # Initialise survey and spectra cosmo = cosmicpy.cosmology() surv = cosmicpy.survey(nzparams={ 'type': 'gaussian', 'cosmology': cosmo, 'r0': r0 }, zmax=0.5, fsky=1.0) spectra = cosmicpy.spectra(cosmo, surv) survey_volume = pi**(3.0 / 2.0) * r0**3 if k is None: k = np.logspace(log(0.001) / log(10), log(0.20) / log(10), 512, endpoint=False) W = spectra.W(l, k, k, evol=False, kmax=0.5) W = W.squeeze() Wexact = np.zeros_like(W) for k1 in range(len(k)): Wexact[k1, :] = (gaussian_bessel_window(l, r0, k[k1], k) / survey_volume) print("Maximum absolute error vs maximum value: " + str(abs(W - Wexact).max()) + " " + str(Wexact.max())) return (k, W, Wexact)
def check_Bessel_window(l, k=None, r0=100): r""" Checks the computation of the bessel window compared to the exact solution for Gaussian selection functions. Parameters ---------- l : int Order of the multipole. r0 : real, optional Radius parameter for the survey Gaussian selection function in Mpc/h Returns ------- (k, W, Wexact) : tuple of ndarrays Window compute the discrete spherical bessel transform and the exact window computed from theory """ # Initialise survey and spectra cosmo = cosmicpy.cosmology() surv = cosmicpy.survey(nzparams={'type': 'gaussian', 'cosmology': cosmo, 'r0': r0}, zmax=0.5, fsky=1.0) spectra = cosmicpy.spectra(cosmo, surv) survey_volume = pi**(3.0 / 2.0) * r0**3 if k is None: k = np.logspace(log(0.001) / log(10), log(0.20) / log(10), 512, endpoint=False) W = spectra.W(l, k, k, evol=False, kmax=0.5) W = W.squeeze() Wexact = np.zeros_like(W) for k1 in range(len(k)): Wexact[k1, :] = (gaussian_bessel_window(l, r0, k[k1], k) / survey_volume) print("Maximum absolute error vs maximum value: " + str(abs(W - Wexact).max()) + " " + str(Wexact.max())) return (k, W, Wexact)
def import_survey(filename, structure_name="fid", expt_name="sv1"): r""" Loads an icosmo survey from a fiducial structure stored in an idl save file into a cosmicpy survey. Parameters ---------- filename : str Name of the idl save from which to load the cosmology. structure_name : str, optional Name of the icosmo fiducial structure stored in the save file. Returns ------- surv : survey cosmicpy survey corresponding to the icosmo input. """ icosmo_file = readsav(filename) icosmo = icosmo_file.get(structure_name)['expt'][0] nzbins = icosmo[expt_name][0]['n_zbin'][0] zerror = icosmo[expt_name][0]['zerror'][0] ng = icosmo[expt_name][0]['ng'][0] a_survey = icosmo[expt_name][0]['a_survey'][0] dndztype = icosmo[expt_name][0]['dndztype'][0] if dndztype != b"smail": print("unsupported galaxy distribution") return None a = icosmo[expt_name][0]['dndzp'][0][0] b = icosmo[expt_name][0]['dndzp'][0][1] zmed = icosmo[expt_name][0]['z_med'][0] biastype = icosmo[expt_name][0]['biastype'][0] if biastype == b'bias0': btype = 'constant' elif biastype == b'bias1': btype = 'sqrt' else: print("unsupported bias type") return None # Compute fsky fsky = a_survey/(180./pi)**2/(4.0*pi) # find z0 corresponding to zmedian def med_smail(z0): smail = lambda z: z**a * exp(-(z/z0)**b) smail_norm = romberg(smail, 0, 5) smailn = lambda z: (z**a * exp(-(z/z0)**b)) / smail_norm f = lambda x: romberg(smailn, 0, x) - 0.5 return brentq(f, 0.01, 5) - zmed z0 = brentq(med_smail, 0.01, 3) surv = cosmicpy.survey(nzbins=nzbins, ngal=ng, zphot_sig=zerror, fsky=fsky, biastype=btype, nzparams={'type': 'smail', 'a': a, 'b': b, 'z0': z0}) return surv
def import_survey(filename, structure_name="fid", expt_name="sv1"): r""" Loads an icosmo survey from a fiducial structure stored in an idl save file into a cosmicpy survey. Parameters ---------- filename : str Name of the idl save from which to load the cosmology. structure_name : str, optional Name of the icosmo fiducial structure stored in the save file. Returns ------- surv : survey cosmicpy survey corresponding to the icosmo input. """ icosmo_file = readsav(filename) icosmo = icosmo_file.get(structure_name)['expt'][0] nzbins = icosmo[expt_name][0]['n_zbin'][0] zerror = icosmo[expt_name][0]['zerror'][0] ng = icosmo[expt_name][0]['ng'][0] a_survey = icosmo[expt_name][0]['a_survey'][0] dndztype = icosmo[expt_name][0]['dndztype'][0] if dndztype != b"smail": print("unsupported galaxy distribution") return None a = icosmo[expt_name][0]['dndzp'][0][0] b = icosmo[expt_name][0]['dndzp'][0][1] zmed = icosmo[expt_name][0]['z_med'][0] biastype = icosmo[expt_name][0]['biastype'][0] if biastype == b'bias0': btype = 'constant' elif biastype == b'bias1': btype = 'sqrt' else: print("unsupported bias type") return None # Compute fsky fsky = a_survey / (180. / pi)**2 / (4.0 * pi) # find z0 corresponding to zmedian def med_smail(z0): smail = lambda z: z**a * exp(-(z / z0)**b) smail_norm = romberg(smail, 0, 5) smailn = lambda z: (z**a * exp(-(z / z0)**b)) / smail_norm f = lambda x: romberg(smailn, 0, x) - 0.5 return brentq(f, 0.01, 5) - zmed z0 = brentq(med_smail, 0.01, 3) surv = cosmicpy.survey(nzbins=nzbins, ngal=ng, zphot_sig=zerror, fsky=fsky, biastype=btype, nzparams={ 'type': 'smail', 'a': a, 'b': b, 'z0': z0 }) return surv