def fiddlebias(aa, saveb=False, bname='h1bias.txt', ofolder=None): #Fiddling bias for halos. Deprecated. print('Read in catalogs') halocat = readincatalog(aa, matter=False) hpos = halocat['Position'] hmass = halocat['Mass'] h1mass = dohod.HI_mass(hmass, aa) dm = BigFileMesh(project + sim + '/fastpm_%0.4f/'%aa + '/dmesh_N%04d'%nc, '1').paint() if ofolder is None: ofolder = project + '/%s/fastpm_%0.4f/'%(sim, aa) #measure power pm = ParticleMesh(BoxSize = bs, Nmesh = [nc, nc, nc]) pkm = FFTPower(dm/dm.cmean(), mode='1d').power k, pkm = pkm['k'], pkm['power'] ##H1 print("H1") h1mesh = pm.paint(hpos, mass=h1mass) pkh1 = FFTPower(h1mesh/h1mesh.cmean(), mode='1d').power['power'] pkh1m = FFTPower(h1mesh/h1mesh.cmean(), second=dm/dm.cmean(), mode='1d').power['power'] #Bias b1h1 = pkh1m/pkm b1h1sq = pkh1/pkm if saveb: np.savetxt(ofolder+bname, np.stack((k, b1h1, b1h1sq**0.5), axis=1), header='k, pkh1xm/pkm, pkh1/pkm^0.5') return k, b1h1, b1h1sq
def calc_bias(aa, h1mesh, suff): '''Compute the bias(es) for the HI''' if rank == 0: print('Calculating bias') if rank == 0: print("Processing a={:.4f}...".format(aa)) print('Reading DM mesh...') dm = BigFileMesh(args['matterfile'] % (aa), 'N1024').paint() dm /= dm.cmean() if rank == 0: print('Computing DM P(k)...') pkmm = FFTPower(dm, mode='1d').power k, pkmm = pkmm['k'], pkmm['power'] # Ignore shotnoise. if rank == 0: print('Done.') # pkh1h1 = FFTPower(h1mesh, mode='1d').power kk = pkh1h1.coords['k'] pkh1h1 = pkh1h1['power'] - pkh1h1.attrs['shotnoise'] pkh1mm = FFTPower(h1mesh, second=dm, mode='1d').power['power'] if rank == 0: print('Done.') # Compute the biases. b1x = np.abs(pkh1mm / (pkmm + 1e-10)) b1a = np.abs(pkh1h1 / (pkmm + 1e-10))**0.5 if rank == 0: print("Finishing processing a={:.4f}.".format(aa)) # if rank == 0: fout = open(outfolder + "HI_bias_{:6.4f}.txt".format(aa), "w") fout.write("# {:>8s} {:>10s} {:>10s} {:>15s}\n".\ format("k","b1_x","b1_a","Pkmm")) for i in range(1, kk.size): fout.write("{:10.5f} {:10.5f} {:10.5f} {:15.5e}\n".\ format(kk[i],b1x[i],b1a[i],pkmm[i].real)) fout.close()
def make_lagfields(nc, seed, bs=1536, T=40, B=2, simpath=sc_simpath, outpath=sc_outpath, Rsm=0): fname = get_filename(nc, seed, T=T, B=B) spath = simpath + fname opath = outpath + fname try: os.makedirs(opath) except: pass pm = ParticleMesh(BoxSize=bs, Nmesh=[nc, nc, nc], dtype='f4') rank = pm.comm.rank lin = BigFileMesh(spath + '/linear', 'LinearDensityK').paint() lin -= lin.cmean() print(rank, 'lin field read') header = '1,b1,b2,bg,bk' names = header.split(',') lag_fields = tools.getlagfields( pm, lin, R=Rsm) # use the linear field at the desired redshift print(rank, 'lag field created') for i, ff in enumerate(lag_fields): x = FieldMesh(ff) x.save(opath + 'lag', dataset=names[i], mode='real')
def calc_bias(aa,mcut,suff): '''Compute the bias(es) for the HI''' print('Read in DM mesh') dm = BigFileMesh(project+sim+'/fastpm_%0.4f/'%aa+\ '/dmesh_N%04d'%nc,'1').paint() dm /= dm.cmean() pkmm = FFTPower(dm,mode='1d').power k,pkmm= pkmm['k'],pkmm['power'] # Ignore shotnoise. # print('Read in central/satellite catalogs') cencat = BigFileCatalog(project+sim+'/fastpm_%0.4f/cencat'%aa) satcat = BigFileCatalog(project+sim+'/fastpm_%0.4f/satcat'%aa+suff) # cencat['HImass'] = HI_hod(cencat['Mass'],aa,mcut) satcat['HImass'] = HI_hod(satcat['Mass'],aa,mcut) totHImass = cencat['HImass'].sum().compute() +\ satcat['HImass'].sum().compute() cencat['HImass']/= totHImass/float(nc)**3 satcat['HImass']/= totHImass/float(nc)**3 # allcat = MultipleSpeciesCatalog(['cen','sat'],cencat,satcat) # h1mesh = allcat.to_mesh(BoxSize=bs,Nmesh=[nc,nc,nc],weight='HImass') pkh1h1 = FFTPower(h1mesh,mode='1d').power pkh1h1 = pkh1h1['power']-pkh1h1.attrs['shotnoise'] pkh1mm = FFTPower(h1mesh,second=dm,mode='1d').power['power'] # Compute the biases. b1x = np.abs(pkh1mm/(pkmm+1e-10)) b1a = np.abs(pkh1h1/(pkmm+1e-10))**0.5 return(k,b1x,b1a,np.abs(pkmm))
def calc_bias(aa, h1mesh, suff): '''Compute the bias(es) for the HI''' if rank == 0: print("Processing a={:.4f}...".format(aa)) print('Reading DM mesh...') if ncsim == 10240: dm = BigFileMesh(scratchyf+sim+'/fastpm_%0.4f/'%aa+\ '/1-mesh/N%04d'%nc,'').paint() else: dm = BigFileMesh(project+sim+'/fastpm_%0.4f/'%aa+\ '/dmesh_N%04d/1/'%nc,'').paint() dm /= dm.cmean() if rank == 0: print('Computing DM P(k)...') pkmm = FFTPower(dm, mode='1d').power k, pkmm = pkmm['k'], pkmm['power'] # Ignore shotnoise. if rank == 0: print('Done.') # pkh1h1 = FFTPower(h1mesh, mode='1d').power pkh1h1 = pkh1h1['power'] - pkh1h1.attrs['shotnoise'] pkh1mm = FFTPower(h1mesh, second=dm, mode='1d').power['power'] if rank == 0: print('Done.') # Compute the biases. b1x = np.abs(pkh1mm / (pkmm + 1e-10)) b1a = np.abs(pkh1h1 / (pkmm + 1e-10))**0.5 if rank == 0: print("Finishing processing a={:.4f}.".format(aa)) return (k, b1x, b1a, np.abs(pkmm))
def fiddlebiasgal(aa, suff, nc=nc, mcfv=[1.], saveb=False, bname='h1bias', ofolder=None): '''Fiddle bias for galaxies''' if ofolder is None: ofolder = project + '/%s/fastpm_%0.4f/'%(sim, aa) pm = ParticleMesh(BoxSize = bs, Nmesh = [nc, nc, nc]) print('Read in catalogs') cencat = BigFileCatalog(project + sim + '/fastpm_%0.4f/cencat'%aa) satcat = BigFileCatalog(project + sim + '/fastpm_%0.4f/satcat'%aa+suff) cpos, spos = cencat['Position'], satcat['Position'] cmass, smass = cencat['Mass'], satcat['Mass'] pos = np.concatenate((cpos, spos), axis=0) dm = BigFileMesh(project + sim + '/fastpm_%0.4f/'%aa + '/dmesh_N%04d'%nc, '1').paint() pkm = FFTPower(dm/dm.cmean(), mode='1d').power k, pkm = pkm['k'], pkm['power'] b1, b1sq = np.zeros((k.size, len(mcfv))), np.zeros((k.size, len(mcfv))) for imc, mcf in enumerate(mcfv): print(mcf) ch1mass = HI_masscutfiddle(cmass, aa, mcutf=mcf) sh1mass = HI_masscutfiddle(smass, aa, mcutf=mcf) h1mass = np.concatenate((ch1mass, sh1mass), axis=0) # h1mesh = pm.paint(pos, mass=h1mass) pkh1 = FFTPower(h1mesh/h1mesh.cmean(), mode='1d').power['power'] pkh1m = FFTPower(h1mesh/h1mesh.cmean(), second=dm/dm.cmean(), mode='1d').power['power'] #Bias b1[:, imc] = pkh1m/pkm b1sq[:, imc] = pkh1/pkm np.savetxt(ofolder+bname+'auto'+suff+'.txt', np.concatenate((k.reshape(-1, 1), b1sq**0.5), axis=1), header='mcut factors = %s\nk, pkh1xm/pkm, pkh1/pkm^0.5'%mcfv) np.savetxt(ofolder+bname+'cross'+suff+'.txt', np.concatenate((k.reshape(-1, 1), b1), axis=1), header='mcut factors = %s\nk, pkh1xm/pkm, pkh1mx/pkm'%mcfv) return k, b1, b1sq
def calc_bias(aa, mcut, suff): '''Compute the bias(es) for the HI''' if rank == 0: print("Processing a={:.4f}...".format(aa)) print('Reading DM mesh...') dm = BigFileMesh(scratch1+sim+'/fastpm_%0.4f/'%aa+\ '/1-mesh/N%04d'%nc,'').paint() dm /= dm.cmean() if rank == 0: print('Computing DM P(k)...') pkmm = FFTPower(dm, mode='1d').power k, pkmm = pkmm['k'], pkmm['power'] # Ignore shotnoise. if rank == 0: print('Done.') # if rank == 0: print('Reading central/satellite catalogs...') cencat = BigFileCatalog(scratch2 + sim + '/fastpm_%0.4f/cencat-16node' % aa) satcat = BigFileCatalog(scratch2 + sim + '/fastpm_%0.4f/satcat' % aa + suff) if rank == 0: print('Catalogs read.') # if rank == 0: print('Computing HI masses...') cencat['HImass'] = HI_hod(cencat['Mass'], aa, mcut) satcat['HImass'] = HI_hod(satcat['Mass'], aa, mcut) rankHImass = cencat['HImass'].sum().compute() +\ satcat['HImass'].sum().compute() rankHImass = np.array([rankHImass]) totHImass = np.zeros(1, dtype='float') comm.Allreduce(rankHImass, totHImass, MPI.SUM) totHImass = totHImass[0] cencat['HImass'] /= totHImass / float(nc)**3 satcat['HImass'] /= totHImass / float(nc)**3 if rank == 0: print('HI masses done.') # if rank == 0: print('Combining catalogs and computing P(k)...') allcat = MultipleSpeciesCatalog(['cen', 'sat'], cencat, satcat) h1mesh = allcat.to_mesh(BoxSize=bs, Nmesh=[nc, nc, nc], weight='HImass') pkh1h1 = FFTPower(h1mesh, mode='1d').power pkh1h1 = pkh1h1['power'] - pkh1h1.attrs['shotnoise'] pkh1mm = FFTPower(h1mesh, second=dm, mode='1d').power['power'] if rank == 0: print('Done.') # Compute the biases. b1x = np.abs(pkh1mm / (pkmm + 1e-10)) b1a = np.abs(pkh1h1 / (pkmm + 1e-10))**0.5 if rank == 0: print("Finishing processing a={:.4f}.".format(aa)) return (k, b1x, b1a, np.abs(pkmm))
def calc_bias(aa,h1mesh, outfolder, fname): '''Compute the bias(es) for the HI''' if rank==0: print('Calculating bias') if rank==0: print("Processing a={:.4f}...".format(aa)) print('Reading DM mesh...') if ncsim == 10240: dm = BigFileMesh(scratchyf+sim+'/fastpm_%0.4f/'%aa+\ '/1-mesh/N%04d'%nc,'').paint() else: dm = BigFileMesh(project+sim+'/fastpm_%0.4f/'%aa+\ '/dmesh_N%04d/1/'%nc,'').paint() dm /= dm.cmean() if rank==0: print('Computing DM P(k)...') pkmm = FFTPower(dm,mode='1d').power k,pkmm= pkmm['k'],pkmm['power'] # Ignore shotnoise. if rank==0: print('Done.') # pkh1h1 = FFTPower(h1mesh,mode='1d').power kk = pkh1h1.coords['k'] pkh1h1 = pkh1h1['power']-pkh1h1.attrs['shotnoise'] pkh1mm = FFTPower(h1mesh,second=dm,mode='1d').power['power'] if rank==0: print('Done.') # Compute the biases. b1x = np.abs(pkh1mm/(pkmm+1e-10)) b1a = np.abs(pkh1h1/(pkmm+1e-10))**0.5 if rank==0: print("Finishing processing a={:.4f}.".format(aa)) # if rank==0: fout = open(outfolder + "{}_bias_{:6.4f}.txt".format(fname, aa),"w") fout.write("# {:>8s} {:>10s} {:>10s} {:>15s}\n".\ format("k","b1_x","b1_a","Pkmm")) for i in range(1,kk.size): fout.write("{:10.5f} {:10.5f} {:10.5f} {:15.5e}\n".\ format(kk[i],b1x[i],b1a[i],pkmm[i].real)) fout.close()
except: pass #################################### #initiate # if ray: hmeshreal = BigFileMesh( '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100/fastpm_%0.4f/HImesh-N%04d/' % (bs * 10, aa, ncd), 'ModelA').paint() else: hmeshreal = BigFileMesh( '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100-fixed/fastpm_%0.4f/HImesh-N%04d/' % (bs * 10, aa, ncd), 'ModelA').paint() hmeshreal /= hmeshreal.cmean() hmeshreal -= 1 if rsdpos: if ray: hmesh = BigFileMesh( '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100/fastpm_%0.4f/HImeshz-N%04d/' % (bs * 10, aa, ncd), 'ModelA').paint() else: hmesh = BigFileMesh( '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100-fixed/fastpm_%0.4f/HImeshz-N%04d/' % (bs * 10, aa, ncd), 'ModelA').paint() hmesh /= hmesh.cmean() hmesh -= 1. if rsdpos: if ray:
with open(pp) as ff: for line in ff.readlines(): if 'RSDFactor' in line: rsdfac = float(line.split()[-2]) else: if ray: hmesh = BigFileMesh( '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100/fastpm_%0.4f/HImesh-N%04d/' % (bs * 10, aa, nc), 'ModelA').paint() else: hmesh = BigFileMesh( '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100-fixed/fastpm_%0.4f/HImesh-N%04d/' % (bs * 10, aa, nc), 'ModelA').paint() rsdfac = 0 rsdfac *= 100. / aa ##Add hoc factor due to incorrect velocity dimensions in nbody.py hmesh /= hmesh.cmean() hmesh -= 1. if rank == 0: print('RSD factor is : ', rsdfac) ## ##rankweight = sum(masswt.compute()) ##totweight = comm.allreduce(rankweight) ##rankweight = sum((masswt**2).compute()) ##totweight2 = comm.allreduce(rankweight) #noise = bs**3 / (hmesh.csum()**2 / (hmesh**2).csum()) noise = None if rank == 0: print('Noise : ', noise) ######################################### #dynamics stages = numpy.linspace(0.01, aa, nsteps, endpoint=True) if pmdisp: dynamic_model = NBodyModel(cosmo, truth_pm, B=B, steps=stages)
aa = 1.0000 zz = 1/aa-1 dgrow = cosmo.scale_independent_growth_factor(zz) Rsm = 0 dpath = '/global/cscratch1/sd/yfeng1/m3127/desi/6144-%d-40eae2464/'%(seed) lpath = '/global/cscratch1/sd/chmodi/m3127/crowcanyon/N%d-T0/S%d/'%(nc, seed) ofolder = lpath + '/spectra/' try: os.makedirs(ofolder) except : pass pm = ParticleMesh(BoxSize=bs, Nmesh=[nc, nc, nc], dtype='f4') rank = pm.comm.rank #grid = pm.mesh_coordinates()*bs/nc lin = BigFileMesh(lpath+ '/linear', 'LinearDensityK').paint() lin -= lin.cmean() print(rank, 'lin field read') header = '1,b1,b2,bg,bk' names = header.split(',') lag_fields = tools.getlagfields(pm, lin, R=Rsm) # use the linear field at the desired redshift print(rank, 'lag field created') for i, ff in enumerate(lag_fields): x = FieldMesh(ff) x.save(lpath + 'lag', dataset=names[i], mode='real') ###
def measurepk(nc=nc, dpath=scratchyf): '''plot the power spectrum of halos on 'nc' grid''' pm = ParticleMesh(BoxSize=bs, Nmesh=[nc, nc, nc]) for i, aa in enumerate(aafiles): zz = zzfiles[i] if rank == 0: print('redshift = ', zz) if ncsim == 10240: dm = BigFileMesh(scratchyf+sim+'/fastpm_%0.4f/'%aa+\ '/1-mesh/N%04d'%nc,'').paint() else: dm = BigFileMesh(project+sim+'/fastpm_%0.4f/'%aa+\ '/dmesh_N%04d/1/'%nc,'').paint() #dm = BigFileMesh(project + sim + '/fastpm_%0.4f/'%aa + '/dmesh_N%04d'%nc, '1').paint() halos = BigFileCatalog(scratchyf + sim + '/fastpm_%0.4f/' % aa, dataset='LL-0.200') mp = halos.attrs['MassTable'][1] * 1e10 if rank == 0: print('Mass of particle is = %0.2e' % mp) hmass = halos["Length"].compute() * mp hpos = halos['Position'].compute() layout = pm.decompose(hpos) if rank == 0: print("paint") hpmesh = pm.paint(hpos, layout=layout) hmesh = pm.paint(hpos, mass=hmass, layout=layout) print(rank, dm.cmean(), hmesh.cmean(), hpmesh.cmean()) pkm = FFTPower(dm / dm.cmean(), mode='1d').power pkh = FFTPower(hmesh / hmesh.cmean(), mode='1d').power pkhp = FFTPower(hpmesh / hpmesh.cmean(), mode='1d').power pkhm = FFTPower(hmesh / hmesh.cmean(), second=dm / dm.cmean(), mode='1d').power pkhpm = FFTPower(hpmesh / hpmesh.cmean(), second=dm / dm.cmean(), mode='1d').power def savebinned(path, binstat, header): if halos.comm.rank == 0: k, p, modes = binstat['k'].real, binstat[ 'power'].real, binstat['modes'].real np.savetxt(path, np.stack((k, p, modes), axis=1), header=header) ofolder = "../data/outputs/halos/{}/".format(sim) if rank == 0: print(ofolder) try: os.makedirs(ofolder) except: pass savebinned(ofolder + 'pkhp_%0.4f.txt' % aa, pkhp, header='k, P(k), Nmodes') savebinned(ofolder + 'pkhm_%0.4f.txt' % aa, pkh, header='k, P(k), Nmodes') savebinned(ofolder + 'pkd_%0.4f.txt' % aa, pkm, header='k, P(k), Nmodes') savebinned(ofolder + 'pkhpxd_%0.4f.txt' % aa, pkhpm, header='k, P(k), Nmodes') savebinned(ofolder + 'pkhmxd_%0.4f.txt' % aa, pkhm, header='k, P(k), Nmodes')
def make_bias_plot(): """Does the work of making the real-space xi(r) and b(r) figure.""" hmesh = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap', 'mapp').paint() noises = np.loadtxt('/global/u1/c/chmodi/Programs/21cm/21cm_cleaning/data/summaryHI.txt').T for i in range(noises[0].size): if noises[0][i] == np.round(1/aa-1, 2): noise = noises[3][i] print(noise) zamod = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/fitp/', 'mapp').paint() pmmod = BigFileMesh(dpath+'T05-B1/opt_s999_h1massA_fourier/fitp/', 'mapp').paint() fin = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap/', 'd').paint() fin /= fin.cmean() fin -= 1 finsm = ft.smooth(fin, 3, 'gauss') grid = pm.mesh_coordinates()*bs/nc params, finmod = getbias(pm, basemesh=finsm, hmesh=hmesh, pos=grid, grid=grid) # models = [zamod, pmmod, finmod, fin.copy()] lbls = ['ZA shift', 'PM shift', 'Eulerian (R=3)', 'Final Matter'] lss = ['-', '-', '-', '--'] fig, ax = plt.subplots(1, 3, figsize=(15, 4)) for ii, mod in enumerate(models): pmod = FFTPower(mod, mode='1d').power k, pmod = pmod['k'], pmod['power'] ph = FFTPower(hmesh, mode='1d').power['power'] pxmodh = FFTPower(hmesh, second=mod, mode='1d').power['power'] perr = FFTPower(hmesh -mod, mode='1d').power['power'] ax[0].plot(k, pxmodh/(pmod*ph)**0.5, label=lbls[ii], lw=2, ls=lss[ii]) ax[0].set_ylabel('$r_{cc}$', fontdict=font) ax[1].plot(k,(pmod/ph)**0.5, lw=2, ls=lss[ii]) #ax[1].set_ylabel(r'$\sqrt{P_{\rm mod}/P_{hh}}$', fontdict=font) ax[1].set_ylabel(r'$T_f$', fontdict=font) ax[2].plot(k, perr, lw=2, ls=lss[ii]) ax[2].set_ylabel(r'$P_{\delta_{\rm mod}-\delta_h}$', fontdict=font) ax[2].set_yscale('log') ax[2].axhline(noise) for axis in ax: axis.set_xscale('log') axis.grid(which='both') axis.legend(prop=fontmanage) axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font) axis.set_xscale('log') # Put on some more labels. for axis in ax: axis.set_xscale('log') for tick in axis.xaxis.get_major_ticks(): tick.label.set_fontproperties(fontmanage) for tick in axis.yaxis.get_major_ticks(): tick.label.set_fontproperties(fontmanage) ##and finish plt.tight_layout(rect=[0, 0, 1, 0.95]) plt.savefig(figpath + '/bfit_L%04d_%04d.pdf'%(bs, aa*10000))
def make_biask_plot(): """Does the work of making the real-space xi(r) and b(r) figure.""" hmesh = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap', 'mapp').paint() noises = np.loadtxt('/global/u1/c/chmodi/Programs/21cm/21cm_cleaning/data/summaryHI.txt').T for i in range(noises[0].size): if noises[0][i] == np.round(1/aa-1, 2): noise = noises[3][i] print(noise) zamod = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/fitp/', 'mapp').paint() pmmod = BigFileMesh(dpath+'T05-B1/opt_s999_h1massA_fourier/fitp/', 'mapp').paint() fin = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap/', 'd').paint() fin /= fin.cmean() fin -= 1 finsm = ft.smooth(fin, 3, 'gauss') grid = pm.mesh_coordinates()*bs/nc params, finmod = getbias(pm, basemesh=finsm, hmesh=hmesh, pos=grid, grid=grid) models = [zamod, pmmod, finmod, finsm.copy()] lbls = ['ZA shift', 'PM shift', 'Eulerian (R=3)', 'Eulerian (R=3), $b_1$'] lss = ['-', '-', '-', '--'] lin = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap/', 's').paint() dyn = BigFileCatalog('/global/cscratch1/sd/chmodi/m3127/cm_lowres/5stepT-B1/%d-%d-9100-fixed/fastpm_%0.4f/1'%(bs, nc, aa)) dgrow = cosmo.scale_independent_growth_factor(zz) zapos = za.doza(lin.r2c(), grid, z=zz, dgrow=dgrow) fpos = dyn['Position'] params, _ = getbias(pm, basemesh=lin, hmesh=hmesh, pos=zapos, grid=grid) kk, paramsk, _ = getbiask(pm, basemesh=lin, hmesh=hmesh, pos=zapos, grid=grid) fig, ax = plt.subplots(1, 2, figsize=(9, 4)) for ii, mod in enumerate(models): pmod = FFTPower(mod, mode='1d').power k, pmod = pmod['k'], pmod['power'] ph = FFTPower(hmesh, mode='1d').power['power'] if ii == 3: mod *= (ph[1]/pmod[1]).real **0.5 pmod *= (ph[1]/pmod[1]).real pxmodh = FFTPower(hmesh, second=mod, mode='1d').power['power'] perr = FFTPower(hmesh -mod, mode='1d').power['power'] ax[0].plot(k, perr, lw=2, ls=lss[ii], label=lbls[ii]) ax[0].set_ylabel(r'$P_{\rm err}$', fontdict=font) ax[0].set_yscale('log') ax[0].axhline(noise, color='k', ls="--") ax[0].set_ylim(2, 5e2) lbls = ['$b_1$', '$b_2$', '$b_s$'] for ii in range(3): ax[1].plot(kk, paramsk[ii], lw=2, color='C%d'%ii, label=lbls[ii]) ax[1].axhline(params[ii], lw=1, color='C%d'%ii, ls="--") ax[1].set_ylabel(r'$b(k)$', fontdict=font) for axis in ax: axis.set_xscale('log') axis.grid(which='both') axis.legend(prop=fontmanage, ncol=2) axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font) axis.set_xscale('log') # Put on some more labels. for axis in ax: axis.set_xscale('log') for tick in axis.xaxis.get_major_ticks(): tick.label.set_fontproperties(fontmanage) for tick in axis.yaxis.get_major_ticks(): tick.label.set_fontproperties(fontmanage) ##and finish plt.tight_layout(rect=[0, 0, 1, 0.95]) plt.savefig(figpath + '/bfitk_L%04d_%04d.pdf'%(bs, aa*10000))
def make_bias2p_plot(): """Does the work of making the real-space xi(r) and b(r) figure.""" hmesh = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap', 'mapp').paint() grid = pm.mesh_coordinates()*bs/nc noises = np.loadtxt('/global/u1/c/chmodi/Programs/21cm/21cm_cleaning/data/summaryHI.txt').T for i in range(noises[0].size): if noises[0][i] == np.round(1/aa-1, 2): noise = noises[3][i] print(noise) zamod = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/fitp/', 'mapp').paint() try: pmmod = BigFileMesh(dpath+'T05-B1/opt_s999_h1massA_fourier/fitp/', 'mapp').paint() except: lin = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap/', 's').paint() dyn = BigFileCatalog('/global/cscratch1/sd/chmodi/m3127/cm_lowres/5stepT-B1/%d-%d-9100-fixed/fastpm_%0.4f/1'%(bs, nc, aa)) fpos = dyn['Position'] _, pmod = getbias(pm, basemesh=lin, hmesh=hmesh, pos=fpos, grid=grid, fpos=fpos) fin = BigFileMesh(dpath+'ZA/opt_s999_h1massA_fourier/datap/', 'd').paint() fin /= fin.cmean() fin -= 1 finsm = ft.smooth(fin, 3, 'gauss') params, finmod = getbias(pm, basemesh=finsm, hmesh=hmesh, pos=grid, grid=grid) models = [zamod, pmmod, finmod, finsm.copy()] lbls = ['ZA shift', 'PM shift', 'Eulerian (R=3)', 'Eulerian (R=3), $b_1$'] lss = ['-', '-', '-', '--'] fig, ax = plt.subplots(1, 2, figsize=(9, 4)) for ii, mod in enumerate(models): pmod = FFTPower(mod, mode='1d').power k, pmod = pmod['k'], pmod['power'] ph = FFTPower(hmesh, mode='1d').power['power'] if ii == 3: mod *= (ph[1]/pmod[1]).real**0.5 pmod *= (ph[1]/pmod[1]).real pxmodh = FFTPower(hmesh, second=mod, mode='1d').power['power'] perr = FFTPower(hmesh -mod, mode='1d').power['power'] ax[0].plot(k, pxmodh/(pmod*ph)**0.5, label=lbls[ii], lw=2, ls=lss[ii]) ax[0].set_ylabel('$r_{cc}$', fontdict=font) #if ii == 3: pmod *= ph[1]/pmod[1] ax[1].plot(k,(pmod/ph)**0.5, lw=2, ls=lss[ii]) ax[1].set_ylabel(r'$T_f$', fontdict=font) #ax[1].set_ylabel(r'$\sqrt{P_{\rm mod}/P_{hh}}$', fontdict=font) for axis in ax: axis.set_xscale('log') axis.grid(which='both') axis.legend(prop=fontmanage) axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font) axis.set_xscale('log') # Put on some more labels. for axis in ax: axis.set_xscale('log') for tick in axis.xaxis.get_major_ticks(): tick.label.set_fontproperties(fontmanage) for tick in axis.yaxis.get_major_ticks(): tick.label.set_fontproperties(fontmanage) ##and finish plt.tight_layout(rect=[0, 0, 1, 0.95]) plt.savefig(figpath + '/bfit2p_L%04d_%04d.pdf'%(bs, aa*10000))
if __name__ == "__main__": bs, nc = 400, 256 dpath = '/global/cscratch1/sd/chmodi/cosmo4d/data/z00/L%04d_N%04d_S0100_40step/' % ( bs, nc) aa = 1.0000 zz = 1 / aa - 1 Rsm = 0 zadisp = True pm = ParticleMesh(BoxSize=bs, Nmesh=[nc, nc, nc]) rank = pm.comm.rank #grid = pm.mesh_coordinates()*bs/nc lin = BigFileMesh(dpath + '/mesh', 's').paint() print(lin.cmean()) dyn = BigFileCatalog(dpath + '/dynamic/1') hcat = BigFileCatalog(dpath + '/FOF/') for Rsm in [0, 2]: for zadisp in [True, False]: # grid = dyn['InitPosition'].compute() fpos = dyn['Position'].compute() print(rank, (grid - fpos).std(axis=0)) dgrow = cosmo.scale_independent_growth_factor(zz) if zadisp: fpos = za.doza(lin.r2c(), grid, z=zz, dgrow=dgrow) dlay = pm.decompose(fpos) hpos = hcat['CMPosition']