def weighted_xi(x, y, z, marks, L, rmin, rmax, nbins, savename, nthreads=1): print("Computing M(r)") #LOG rbins = np.logspace(np.log10(rmin), np.log10(rmax), nbins + 1) # note the + 1 to nbins r_avg = 10**(0.5 * (np.log10(rbins)[1:] + np.log10(rbins)[:-1])) #LINEAR #rbins = np.linspace(rmin, rmax, nbins + 1) # note the + 1 to nbins #r_avg = 0.5*(rbins[1:] + rbins[:-1]) res = xi(L, nthreads, rbins, x, y, z, weights=marks, weight_type="pair_product") print("Saving") os.makedirs(os.path.dirname(savename), exist_ok=True) xi_vals = res['xi'] print(xi_vals) results = np.array([r_avg, xi_vals]) np.savetxt(savename, results.T, delimiter=',', fmt=['%f', '%e'])
def compute_xi0(x, y, z, L, r_min, r_max, n_bins, fn_save, nthreads=1): print("Computing xi_0") # Set up bins (log) r_bins = np.logspace(np.log10(r_min), np.log10(r_max), n_bins + 1) # Note the + 1 to nbins r_avg = 10**(0.5 * (np.log10(r_bins)[1:] + np.log10(r_bins)[:-1])) res = xi(L, nthreads, r_bins, x, y, z) xi_vals = res['xi'] print("Saving") os.makedirs(os.path.dirname(fn_save), exist_ok=True) results = np.array([r_avg, xi_vals]) np.savetxt(fn_save, results.T, delimiter=',', fmt=['%f', '%e'])
def CF(Mhalo, x, y, z): Mlh = np.log10(Mhalo[Mhalo > 0]) nthreads = multiprocessing.cpu_count() box = 500. nbins = 20 bins = 10**np.linspace(np.log10(0.5), np.log10(50), nbins + 1) #------------------------------------------------------------- # Correlation function samples: logM > 10.5, 11.0, 11.5 #------------------------------------------------------------- mh1 = np.where(Mlh > 10.5) mh2 = np.where(Mlh > 11.0) mh3 = np.where(Mlh > 11.5) print('Number of haloes Mlh > 10.5', len(x[mh1])) print('Number of haloes Mlh > 11.0', len(x[mh2])) print('Number of haloes Mlh > 11.5', len(x[mh3])) xi_h1 = xi(box, nthreads, bins, x[mh1], y[mh1], z[mh1], output_ravg=True) print("xi1 done") xi_h2 = xi(box, nthreads, bins, x[mh2], y[mh2], z[mh2], output_ravg=True) print("xi2 done") xi_h3 = xi(box, nthreads, bins, x[mh3], y[mh3], z[mh3], output_ravg=True) print("xi3 done") xir1 = xi_h1['xi'] xir2 = xi_h2['xi'] xir3 = xi_h3['xi'] rr1 = xi_h1['ravg'] rr2 = xi_h2['ravg'] rr3 = xi_h3['ravg'] return rr1, xir1, rr2, xir2, rr3, xir3
def calc_hhcf(halo_path, save_path=None, config=config_default): """Calculate the halo-halo correlation function Note: assumes the halo catalog has the format X,Y,Z,N,M,Richness. Args: halo_path (string): Path to the halo catalog save_path (string, optional): Path to save the output config (dictionary): Configuration of the Corrfunc run. Default is config_default """ boxsize = config["boxsize"] nthreads = config["nthreads"] bins = config["bins"] X, Y, Z, Np, M, Rich = np.genfromtxt(halo_path, unpack=True) result = xi(boxsize, nthreads, bins, X, Y, Z) if save_path: np.savetxt(save_path, result) return
def Galaxy_Corr(galaxy_table, mod='lin', **kwargs): ''' Evaluates the galaxies correlation function. Possible inputs: mod: string, controlling the spacing of the bins. 'lin' or 'log' rbins: numpy.array for the bins. If specified, 'mod' is ignored ''' X = array(galaxy_table['x']) Y = array(galaxy_table['y']) Z = array(galaxy_table['z']) try: rbins = kwargs['rbins'] except: if mod=='lin': rbins = linspace(1, 100, 11) elif mod=='log': rbins = logspace(0, 2, 21) else: raise Exception return xi(1024,N_PROC,rbins, X,Y,Z, output_ravg=True)
elif 'ds14b' in tag: boxsize = 1000 #Mpc/h else: raise ValueError if '_n' in savetag: nd_halos = am.calc_number_densities(vmaxs, boxsize) nthresh = float(nthresh_str) X = X[nd_halos < nthresh] #less than bc bigger halos have lower number dens Y = Y[nd_halos < nthresh] Z = Z[nd_halos < nthresh] print(len(X)) nthreads = 24 nbins = 15 bins = np.logspace(np.log10(0.01), np.log10(10.0), nbins + 1) #log print(bins) #bins = np.linspace(0.1, 10.0, nbins + 1) #regular #bins = np.linspace(40.0, 150.0, nbins + 1) #rbig print("Running corrfunc") if mode == 'xi': res = xi(boxsize, nthreads, bins, X, Y, Z) elif mode == 'wp': pimax = 40.0 res = wp(boxsize, pimax, nthreads, bins, X, Y, Z) print("Ran corrfunc") np.save('../results/{}{}.npy'.format(mode, savetag), np.array([bins, res]))
nthreads, binfile, x, y, z, X2=px, Y2=py, Z2=pz, boxsize=boxsize) ddc = DD1['npairs'] # Get the cross-correlation functions cf = ddc / _RR(binfile, boxsize, len(px), len(x)) - 1 # For the errors, the subsample DD is needed subxi = xi(boxsize, nthreads, binfile, x, y, z) dd = subxi['npairs'] err = (1 + cf) / np.sqrt(dd) # Write output outfile = inpath+'/iz'+sn+'/'+space+'/ccf/'+\ elabels[iie]+'_'+cw+'_'+cut+'cut_'+\ survey+'_sn'+sn+\ '_ccf_'+space+'.dat' tofile = np.column_stack((bin_middle, cf, err, dd, ddc)) with open(outfile, 'w') as outf: outf.write( '# r/h-1Mpc Cross-CF (1+CCF)/sqrt(DD) DD DDtotal \n') np.savetxt(outf,
x2 = s_xgal[mask] y2 = s_ygal[mask] z2 = s_zgal[mask] # Plot the clustering as a test fig, ax0 = plt.subplots(nrows=1, ncols=1, figsize=(10, 10)) gs = gridspec.GridSpec(2, 1) gs.update(wspace=0., hspace=0.) ax = plt.subplot(gs[0, 0]) ax2 = plt.subplot(gs[1, 0], sharex=ax) rbins = np.logspace(-2., 2., 40) rbins_mid = rbins[:-1] + (rbins[1] - rbins[0]) / 2. nthreads = 4 xi1_cf = xi(lbox, nthreads, rbins, x1, y1, z1) xi2_cf = xi(lbox, nthreads, rbins, x2, y2, z2) ratios = xi1_cf['xi'] / xi2_cf['xi'] print('Clustering ratios = {}'.format(ratios)) ax.set_xlim([-1., 1.5]) ax.set_xlim([-2., 3.5]) ax.set_ylabel(r'$\rm log_{10}\xi(r)$') ax.plot(np.log10(rbins_mid), np.log10(xi1_cf['xi']), label='nd=' + str(nd)) ax.plot(np.log10(rbins_mid), np.log10(xi2_cf['xi']), label='Shuffled') ax2.set_ylim([0.5, 1.5]) ax2.set_ylabel(r'$\rm log(r/h^{-1}Mpc$') ax2.set_ylabel(r'$\rm Ratios$') ax2.plot([-3, 3], [1, 1], color='k', ls=':', linewidth=1) ax2.plot(np.log10(rbins_mid), ratios)
nprojbins = nbins qq_ana = qq_analytic(rmin, rmax, nd, volume, nprojbins, nsbins, sbins, proj_type) # In[11]: from Corrfunc._countpairs_mocks import evaluate_xi # Compare to theoretical DD(r): # In[46]: xi_3d_res = xi(boxsize, nthreads, rbins, x, y, z) xi_3d = np.array([x[3] for x in xi_3d_res], dtype=float) # Try with estimator: # # xi(s, mu) with mumax = 1 and 1 mubin should be equiv to xi(r) # For randoms let's load in our bigger box for better convergence: # In[12]: boxsize = 750 nbar_str_big = '3e-4' cat_tag_big = '_L{}_nbar{}'.format(boxsize, nbar_str_big)
# cat = treecorr.Catalog(x=x,y=y,z=z) #units are arcmin by default, but pretend MPc # dd.process(cat) # dr.process(cat,cat_r) # xi,varxi = dd.calculateXi(rr,dr) # xi_smooth = savgol_filter(xi, 11, 5) # r = np.exp(dd.logr) results = xi(0.5 * BoxSize, nthreads, log_rbins, x_sub, y_sub, z_sub, output_ravg=True) output_filename = "/Users/jkwan/emulators/TitanU/xi/M{:0>3}/STEP{:3}/xi_M{:0>3}_L2100_sod_0.4985_{:4.2f}_test.{}.dat".format( model_no, step_no, model_no, mass_cut[int(bin_no)], jk_no) # output_filename = "/Users/jkwan/emulators/TitanU/xi/M{:0>3}/STEP{:3}/xi_mm_M{:0>3}_L5000_1.0000_test.dat".format(model_no, step_no, model_no) # np.savetxt(output_filename, np.column_stack([r*BoxSize, xi])) np.savetxt( output_filename, np.column_stack( [results['ravg'], results['xi'], results['npairs']]))
zstrings = ["1.0", "0.5", "0.25", "0.0"] c = np.linspace(1.0, 0.0, len(lM_edges) - 1) cmaps = ['Reds', 'Oranges', 'Greens', 'Blues'] if do_hhcf: for i in range(len(indices)): ind = indices[i] red = redshifts[i] cmap = plt.get_cmap(cmaps[i]) for j in range(len(lM_edges) - 1): if do_calc: data = np.genfromtxt(halopath % (j, red)) if not data.size: continue x, y, z, N, M, lam = data.T result = xi(boxsize, nthreads, bins, x, y, z) np.savetxt("results/hhcf_m%d_z%.2f.txt" % (j, red), result) result = np.loadtxt("results/hhcf_m%d_z%.2f.txt" % (j, red)) hhcf = result[:, 3] plt.loglog(R, hhcf, c=cmap(c[j]), label=r"$z=%.2f\ m%d$" % (red, j)) plt.legend(loc=0, fontsize=10) plt.xlabel(r"$R\ [{\rm Mpc/h}]$", fontsize=24) plt.ylabel(r"$\xi_{\rm hh}$", fontsize=24) plt.subplots_adjust(bottom=0.17, left=0.2) #plt.gcf().savefig("figures/hhcf_richnesses_z%0.2f.png"%z) plt.show() plt.clf()