def projected_correlation_function(table_l, table_r, rp_bins, pi_max): n_l = len(table_l) n_r = len(table_r) n = multiprocessing.cpu_count() c = constants.c / 1000.0 ll = DDrppi_mocks(True, 2, n, pi_max, rp_bins, table_l['ra'], table_l['dec'], table_l['z'] * c)['npairs'] rr = DDrppi_mocks(True, 2, n, pi_max, rp_bins, table_r['ra'], table_r['dec'], table_r['z'].astype(np.float64) * c)['npairs'] lr = DDrppi_mocks(False, 2, n, pi_max, rp_bins, table_l['ra'], table_l['dec'], table_l['z'] * c, RA2=table_r['ra'], DEC2=table_r['dec'], CZ2=table_r['z'].astype(np.float64) * c)['npairs'] wp = convert_rp_pi_counts_to_wp(n_l, n_l, n_r, n_r, ll, lr, lr, rr, len(rp_bins) - 1, pi_max) return wp
def reference_survey_tpcf(data1, randoms1, edges, pimax, data2=None, randoms2=None): """Reference projected 2PCF using Corrfunc""" from Corrfunc.utils import convert_3d_counts_to_cf, convert_rp_pi_counts_to_wp from Corrfunc.mocks import DDrppi_mocks if data2 is None: data2 = data1 if randoms2 is None: randoms2 = randoms1 # updack the columns to pass to Corrfunc ra_d1, dec_d1, r_d1 = data1.T ra_r1, dec_r1, r_r1 = randoms1.T ra_d2, dec_d2, r_d2 = data2.T ra_r2, dec_r2, r_r2 = randoms2.T # the Corrfunc keywords kws = {} kws['cosmology'] = 1 kws['nthreads'] = 1 kws['pimax'] = pimax kws['binfile'] = edges kws['is_comoving_dist'] = True # do the pair counting D1D2 = DDrppi_mocks(0, RA1=ra_d1, DEC1=dec_d1, CZ1=r_d1, RA2=ra_d2, DEC2=dec_d2, CZ2=r_d2, **kws) D1R2 = DDrppi_mocks(0, RA1=ra_d1, DEC1=dec_d1, CZ1=r_d1, RA2=ra_r2, DEC2=dec_r2, CZ2=r_r2, **kws) D2R1 = DDrppi_mocks(0, RA1=ra_d2, DEC1=dec_d2, CZ1=r_d2, RA2=ra_r1, DEC2=dec_r1, CZ2=r_r1, **kws) R1R2 = DDrppi_mocks(0, RA1=ra_r1, DEC1=dec_r1, CZ1=r_r1, RA2=ra_r2, DEC2=dec_r2, CZ2=r_r2, **kws) # combine using Landy-Szalay ND1 = len(ra_d1); ND2 = len(ra_d2) NR1 = len(ra_r1); NR2 = len(ra_r2) CF = convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, D1D2, D1R2, D2R1, R1R2).reshape((-1,pimax)) wp = convert_rp_pi_counts_to_wp(ND1, ND2, NR1, NR2, D1D2, D1R2, D2R1, R1R2, len(edges)-1, pimax) D1D2 = D1D2.reshape((-1,pimax)) D1R2 = D1R2.reshape((-1,pimax)) D2R1 = D2R1.reshape((-1,pimax)) R1R2 = R1R2.reshape((-1,pimax)) return D1D2, D1R2, D2R1, R1R2, CF, wp
def get_wp(RA, DEC, CZ): N = len(RA) weights = np.ones_like(RA) # Random points rand_num = eco_nobuff.size * 5 rand_RA = np.round(random.uniform(eco_nobuff.radeg.min(),eco_nobuff.radeg.max(),\ rand_num), 5) rand_DEC = np.round(random.uniform(eco_nobuff.dedeg.min(),eco_nobuff.dedeg.max(),\ rand_num), 7) rand_CZ = np.round(random.uniform(eco_nobuff.grpcz.min(),eco_nobuff.grpcz.max(),\ rand_num), 1) rand_N = len(rand_RA) rand_weights = np.ones_like(rand_RA) nbins = 10 bins = np.logspace(np.log10(0.1), np.log10(20.0), nbins + 1) cosmology = 2 # Planck nthreads = 2 pimax = 25.0 # Auto pair counts in DD autocorr = 1 DD_counts = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, bins, RA, \ DEC, CZ, weights1=weights, weight_type='pair_product') # Auto pair counts in RR RR_counts = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, bins, rand_RA, \ rand_DEC, rand_CZ, weights1=rand_weights, weight_type='pair_product') # Cross pair counts in DR autocorr = 0 DR_counts = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, bins, RA, DEC, \ CZ, RA2=rand_RA, DEC2=rand_DEC, CZ2=rand_CZ, weights1=weights, \ weights2=rand_weights, weight_type='pair_product') wp = convert_rp_pi_counts_to_wp(N, N, rand_N, rand_N, DD_counts, DR_counts, \ DR_counts, RR_counts, nbins, pimax) return bins, wp
print('DD') DD_counts = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, bins, RA, DEC, CZ) # Cross pair counts in DR autocorr = 0 print('DR') DR_counts = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, bins, RA, DEC, CZ, RA2=rand_RA, DEC2=rand_DEC, CZ2=rand_CZ) # Auto pairs counts in RR autocorr = 1 print('RR') RR_counts = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, bins, rand_RA, rand_DEC, rand_CZ) # All the pair counts are done, get the angular correlation function wp = convert_rp_pi_counts_to_wp(N, N, rand_N, rand_N, DD_counts, DR_counts, DR_counts, RR_counts, nbins, pimax) print wp
def counts(ra_data, dec_data, z_data, ra_rand, dec_rand, z_rand, rpbins, pimax, weights_data=None, weights_rand=None, pibinwidth=1, comoving=False): assert (len(ra_data) == len(dec_data) and len(ra_data) == len(z_data)) assert (len(ra_rand) == len(dec_rand) and len(ra_rand) == len(z_rand)) ndata = len(ra_data) nrand = len(ra_rand) nbins = len(rpbins) - 1 pibins = np.arange(0, pimax + pibinwidth, pibinwidth) if comoving: zdf = pd.DataFrame(z_data) z_data = zdf.apply(get_comoving_dist)[0].values rzdf = pd.DataFrame(z_rand) z_rand = rzdf.apply(get_comoving_dist)[0].values dd_res_corrfunc = DDrppi_mocks(1, 2, 0, pimax, rpbins, ra_data, dec_data, z_data, is_comoving_dist=comoving) dr_res_corrfunc = DDrppi_mocks(0, 2, 0, pimax, rpbins, ra_data, dec_data, z_data, RA2=ra_rand, DEC2=dec_rand, CZ2=z_rand, is_comoving_dist=comoving) rr_res_corrfunc = DDrppi_mocks(1, 2, 0, pimax, rpbins, ra_rand, dec_rand, z_rand, is_comoving_dist=comoving) wp = convert_rp_pi_counts_to_wp(ndata, ndata, nrand, nrand, dd_res_corrfunc, dr_res_corrfunc, dr_res_corrfunc, rr_res_corrfunc, nbins, pimax) dd_rp_pi_corrfunc = np.zeros((len(pibins) - 1, len(rpbins) - 1)) dr_rp_pi_corrfunc = np.zeros((len(pibins) - 1, len(rpbins) - 1)) rr_rp_pi_corrfunc = np.zeros((len(pibins) - 1, len(rpbins) - 1)) for m in range(len(pibins) - 1): for n in range(len(rpbins) - 1): idx = (len(pibins) - 1) * n + m dd_rp_pi_corrfunc[m][n] = dd_res_corrfunc[idx][4] dr_rp_pi_corrfunc[m][n] = dr_res_corrfunc[idx][4] rr_rp_pi_corrfunc[m][n] = rr_res_corrfunc[idx][4] estimator_corrfunc = calc_ls(dd_rp_pi_corrfunc, dr_rp_pi_corrfunc, rr_rp_pi_corrfunc, ndata, nrand) wprp_corrfunc = 2 * pibinwidth * np.sum(estimator_corrfunc, axis=0) est_ls, wprp_nopi = calc_wprp_nopi(dd_rp_pi_corrfunc, dr_rp_pi_corrfunc, rr_rp_pi_corrfunc, ndata, nrand) return wp, wprp_corrfunc, wprp_nopi