def run(self, zlim, nmesh, Poles=[0, 2, 4], dK=None, kMin=0.0, use_fkp=True, P0fkp=6e3): zmin, zmax = zlim self.randoms['Selection'] = (self.randoms['Z'] >= zmin) & (self.randoms['Z'] < zmax) self.data['Selection'] = (self.data['Z'] >= zmin) & (self.data['Z'] < zmax) # # combine the data and randoms into a single catalog # add the n(z) columns to the FKPCatalog # fkp = nb.FKPCatalog(self.data, self.randoms) fkp['randoms/NZ'] = self.nofz(self.randoms['Z']) fkp['data/NZ'] = self.nofz(self.data['Z']) mesh = fkp.to_mesh(Nmesh=nmesh, nbar='NZ') # # r = nb.ConvolvedFFTPower(mesh, poles=Poles, dk=dK, kmin=kMin, use_fkp_weights=use_fkp, P0_FKP=P0fkp) output = {} output['attrs'] = r.attrs output['attrs']['zbin'] = zlim output['poles_data'] = r.poles output['nz'] = self.nofz return output
# apply the Completeness weights to both data and randoms if sys_tot: if rank ==0:print('including sys_tot') data['WEIGHT'] = data['WEIGHT_SYSTOT'] * data['WEIGHT_NOZ'] * data['WEIGHT_CP'] else: if rank ==0:print('excluding sys_tot') data['WEIGHT'] = data['WEIGHT_NOZ'] * data['WEIGHT_CP'] # data['WEIGHT_SYSTOT'] randoms['WEIGHT'] = randoms['WEIGHT_SYSTOT'] * randoms['WEIGHT_NOZ'] * randoms['WEIGHT_CP'] # combine the data and randoms into a single catalog fkp = nb.FKPCatalog(data, randoms, nbar='NZ') mesh = fkp.to_mesh(Nmesh=nmesh, fkp_weight='WEIGHT_FKP', comp_weight='WEIGHT', window='tsc') # compute r = nb.ConvolvedFFTPower(mesh, poles=[0, 2, 4], dk=0.001, kmin=0.0) # save r.save(output_path) # --- save in txt format comm.Barrier() if rank == 0: # # write P0-shotnoise P2 P4 to file with open(output_path.replace('.json', '.txt'), 'w') as output: # write the attributes for k in r.attrs: output.write(f'#{k:20s} : {r.attrs[k]}\n')
def run_ConvolvedFFTPower(galaxy_path, random_path, output_path, use_systot=True, zmin=None, zmax=None, compmin=0.5, cosmology=None, boxsize=None, nmesh=512, dk=0.002, poles=[0, 2, 4], kmax=None, comm=None, return_pk=False): if isinstance(nmesh, list): if len(nmesh)==1: nmesh=nmesh[0] if isinstance(boxsize, list): if len(boxsize)==1: boxsize=boxsize[0] if (cosmology is None) or (cosmology=='boss'): # the fiducial BOSS DR12 cosmology # see Alam et al. https://arxiv.org/abs/1607.03155 cosmo = Cosmology(h=0.676).match(Omega0_m=0.31) elif cosmology=='ezmock': _h = 0.6777 _Ob0 = 0.048206 _Ocdm0 = 0.307115 - _Ob0 cosmo = Cosmology(h=_h, Omega_b=_Ob0, Omega_cdm=_Ocdm0, m_ncdm=None, n_s=0.9611, T_cmb=2.7255).match(sigma8=0.8225) elif cosmology=='boss2': h = 0.676 redshift = 1.48 cos = Cosmology(h=0.676,Omega0_b=0.022/h**2,n_s=0.97).match(Omega0_m=0.31) cosmo = cos.match(sigma8=0.8) elif isinstance(cosmology, Cosmology): cosmo = cosmology else: raise NotImplementedError(f'{cosmology} is not implemented') data = FITSCat(galaxy_path) random = FITSCat(random_path) # select based on redshift and comp_BOSS kwargs = dict(compmin=compmin, zmin=zmin, zmax=zmax) data = data.trim_redshift_range(**kwargs) random = random.trim_redshift_range(**kwargs) # sky to xyz data.sky_to_xyz(cosmo) random.sky_to_xyz(cosmo) # prepare weights data.apply_weight(use_systot=use_systot) random.apply_weight(use_systot=True) # always weight randoms by systot # combine the data and randoms into a single catalog mesh_kwargs = {'interlaced': True,'window': 'tsc'} fkp = nb.FKPCatalog(data, random, nbar='NZ', BoxSize=boxsize) mesh = fkp.to_mesh(Nmesh=nmesh, fkp_weight='WEIGHT_FKP', **mesh_kwargs) r = nb.ConvolvedFFTPower(mesh, poles=poles, dk=dk, kmin=0.0, kmax=kmax) comm.Barrier() if comm.rank == 0: for parameter in ['sigma8', 'Omega0_m', 'h', 'n_s', 'Omega0_b', 'Omega0_lambda']: r.attrs[parameter] = getattr(cosmo, parameter) if comm.rank == 0: output_dir = os.path.dirname(os.path.abspath(output_path)) if not os.path.exists(output_dir): os.makedirs(output_dir) r.save(output_path) if return_pk: if comm.rank == 0: return r
# initialize the FKP source # add the n(z) columns to the FKPCatalog randoms['NZ'] = nofz(randoms[zcol_name]) data['NZ'] = nofz(data[zcol_name]) fkp = nb.FKPCatalog(data, randoms, nbar='NZ') Pzero = 6000 fkp['data/FKPWeight'] = 1.0 / (1 + fkp['data/NZ'] * Pzero) fkp['randoms/FKPWeight'] = 1.0 / (1 + fkp['randoms/NZ'] * Pzero) mesh = fkp.to_mesh(Nmesh=ns.nmesh, fkp_weight='FKPWeight', comp_weight='Weight', window='tsc') r = nb.ConvolvedFFTPower(mesh, poles=ns.poles, dk=0.005, kmin=0.0) comm.Barrier() if rank == 0: # # write P0-shotnoise P2 P4 to file output = open(ns.output, 'w') for k in args: output.write(f'#{k:20s} : {args[k]}\n') # write the attributes for k in r.attrs: output.write(f'#{k:20s} : {r.attrs[k]}\n') output.write('# k_avg P0 P2 P4 Nmodes\n')