def __init__(self, fname_params): self.p = ParamRun(fname_params) self.cosmo = self.p.get_cosmo() self.cosmo_vary = COSMO_VARY(self.p) self.kwargs = self.p.get_cosmo_pars() self.hmc = get_hmcalc(**self.kwargs) self._PP = norm.sf(-1) - norm.sf(1)
def th(pars,d): if not cosmo_vary: cosmo_fid = cosmo hmc_fid = hmc else: cosmo_fid = COSMO_ARGS(kwargs) hmc_fid = get_hmcalc(cosmo_fid, **kwargs) return get_theory(p, d, cosmo_fid, hmc_fid, hm_correction=hm_correction, selection=None,**pars)
def th2h(pars): if not cosmo_vary: pars_fid = pars cosmo_fid = cosmo hmc_fid = hmc else: pars_fid = {**p.get_cosmo_pars(), **pars} cosmo_fid = COSMO_ARGS(pars_fid) hmc_fid = get_hmcalc(cosmo_fid, **pars_fid) return get_theory(p, d, cosmo_fid, hmc_fid, return_separated=False, hm_correction=None, include_1h=False, include_2h=True, **pars_fid)
def bias_one(p0, num): """Calculates the halo model bias for a set of parameters.""" if self.cosmo_vary: cosmo = COSMO_ARGS(pars) hmc = get_hmcalc( cosmo, **{ "mass_function": self.p.get_massfunc(), "halo_bias": self.p.get_halobias() }) else: cosmo = self.cosmo hmc = self.hmc bb = hm_bias(cosmo, hmc, 1 / (1 + zarr), d.tracers[num][1], **lik.build_kwargs(p0)) return bb
def th2h(self, pars): if not cosmo_vary: cosmo_fid = cosmo hmc_fid = hmc else: cosmo_fid = COSMO_ARGS(kwargs) hmc_fid = get_hmcalc(cosmo_fid, **kwargs) return get_theory(p, self.d, cosmo_fid, hmc_fid, hm_correction=hm_correction, selection=sel, include_2h=True, include_1h=False, **pars)
def model_xcorr(p, fields, xcorr): """Model the angular power spectrum.""" # copy & reset shape mcorr = copy.deepcopy(xcorr) for name1 in mcorr: for name2 in mcorr[name1]: mcorr[name1][name2].cell = None # calculate models where applicable & inherit measurements for name1 in mcorr: for name2 in mcorr[name1]: print(name1, name2, end='') f1, type1 = fields[name1] f2, type2 = fields[name2] is_model = np.array([type1 in types, type2 in types]) is_yy = (type1, type2) == ('y', 'y') # don't model yxy if is_model.all() and not is_yy: if mcorr[name2][name1].cell is not None: cl = mcorr[name2][name1].cell print(' <--- %s %s' % (name2, name1)) else: # model the cross correlation prof1, kwargs1 = get_profile(p, name1) prof2, kwargs2 = get_profile(p, name2) # best fit from 1909.09102 if ('y' in (type1, type2)) and ('g' not in (type1, type2)): kwargs1 = kwargs2 = {**kwargs1, **{'mass_bias': 0.75}} kwargs = kwargs1 cosmo = COSMO_ARGS(kwargs) l = mcorr[name1][name2].leff hmc = get_hmcalc(**kwargs) cl = hm_ang_power_spectrum(cosmo, hmc, l, (prof1, prof2), **kwargs) if type1 == type2 == 'g': nl = np.load(p.get_fname_cls(f1.name, f2.name))['nls'] cl += nl print('\n', end='') mcorr[name1][name2].cell = cl else: mcorr[name1][name2] = xcorr[name1][name2] print(' ## not modelled') return mcorr
def get_1h_covariance(p, fields, xcorr, f11, f12, f21, f22): '''Computes and saves the 1-halo covariance.''' fname_cov = p.get_fname_cov(f11.name, f12.name, f21.name, f22.name, "1h4pt") fname_cov_T = p.get_fname_cov(f21.name, f22.name, f11.name, f12.name, "1h4pt") # print(fname_cov) if (not os.path.isfile(fname_cov)) and (not os.path.isfile(fname_cov_T)): fsky = np.mean(f11.mask * f12.mask * f21.mask * f22.mask) leff = xcorr[f11.name][f11.name].leff # Set-up profiles profiles = [[], [], [], []] flds = [f11, f12, f21, f22] for i, F in enumerate(flds): # retrieve map parameters from param file for m in p.get("maps"): if m["name"] == F.name: break # initialize profile and update it prof = ProfTracer(m) if F.is_ndens: kwargs = m["model"] cosmo = COSMO_ARGS(kwargs) # TODO: final cosmo is used prof.update_parameters(cosmo, **kwargs) else: prof.update_parameters(COSMO_DEFAULT(), **{"mass_bias": 0.75}) profiles[i] = prof # Get single model parameter dictionary models_a = p.get_models()[f11.name] models_b = p.get_models()[f12.name] kwargs = models_a hmc = get_hmcalc(**kwargs) # Calculate covariace dcov = hm_ang_1h_covariance(fsky, leff, cosmo, hmc, profiles, **kwargs) dcov *= Beam(f11.name + f12.name, leff, p.get_nside())[:, None] dcov *= Beam(f21.name + f22.name, leff, p.get_nside())[None, :] cov = Covariance(f11.name, f12.name, f21.name, f22.name, dcov) cov.to_file(p.get_outdir() + "/dcov_1h4pt_" + f11.name + "_" + f12.name + "_" + f21.name + "_" + f22.name + ".npz")
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) rc('text', usetex=True) sample='wisc3' dgg_wdpj=np.load("output_default/cls_"+sample+"_"+sample+".npz") dgg_wodpj=np.load("output_default_nodpj/cls_"+sample+"_"+sample+".npz") cov_gg=np.load("output_default/cov_comb_m_"+sample+"_"+sample+ "_"+sample+"_"+sample+".npz")['cov'] ls=dgg_wdpj['ls'] fname_params = "params_wnarrow.yml" p = ParamRun(fname_params) kwargs = p.get_cosmo_pars() cosmo = p.get_cosmo() hmc = get_hmcalc(cosmo, **kwargs) cosmo_vary = COSMO_VARY(p) hm_correction = HalomodCorrection(cosmo) v=None for s,vv in enumerate(p.get("data_vectors")): if vv['name']==sample: v=vv dat = DataManager(p, v, cosmo, all_data=False) gat = DataManager(p, v, cosmo, all_data=True) def th(pars,d): if not cosmo_vary: cosmo_fid = cosmo hmc_fid = hmc