def smoothft(mesh, R1=None, R2=None, quad=False, shear=False, pm=None, Rmore=None): '''Currently does the following to the mesh- Deconvolve -> Subtract mean -> Smooth at given scales & GD ''' pmdc = ft.decic(mesh) meshdict = {'final': mesh.value, 'decic': pmdc.value} mean = pmdc[...].mean() pmdc[...] -= mean pmdc[...] /= mean dk = pmdc.r2c() #Create features and parameters if R1 is not None: R1mesh = ft.smooth(dk, R1, 'fingauss') meshdict['R1'] = R1mesh.value if R2 is not None: R2mesh = ft.smooth(dk, R2, 'fingauss') meshdict['R2'] = R2mesh.value if R2 is not None and R2 is not None: R12mesh = R1mesh - R2mesh meshdict['R12'] = R12mesh.value if shear: s2 = ft.shear(pm, mesh) meshdict['shear'] = s2.value if Rmore is not None: for i, R in enumerate(Rmore): Rmesh = ft.smooth(dk, R, 'fingauss') meshdict['Rmore%d' % i] = Rmesh.value if quad: meshdict['fR1'] = (R1mesh * mesh).value meshdict['fR2'] = (R2mesh * mesh).value meshdict['R1R2'] = (R1mesh * R2mesh).value return meshdict
def getlagfields(pm, basemesh, R=0, smoothd0=True, kernel='gauss'): '''generate 5 lagrangian fields - 1, \delta, \delta^2, \s^2, \nabla\delta''' if R > 0: base = ft.smooth(basemesh, R, kernel) else: base = basemesh.copy() one = (base * 0 + 1).copy() d2 = 1. * base**2 d2 -= d2.cmean() s2 = ft.shear(pm, base) s2 -= s2.cmean() lap = ft.laplace(pm, base) lap -= lap.cmean() #do we smooth the field with b1? if smoothd0: d0 = base.copy() else: d0 = basemesh.copy() return one, d0, d2, s2, lap
doexp=doexp, mexp=mexp, cc=cc, stellar=stellar) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) if regression: nnmass = ntools.applymassreg(mftt, mtup).reshape(nc, nc, nc) else: nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc) if doexp: nnmass = mf.fmexp(ntools.relu(nnmass), mexp, cc) predict = pm.create(mode='real') predict[...] = nnpred * nnmass predictR = ft.smooth(predict, Rsm, 'fingauss') #data hdictf = ntools.gridhalos(pm, scratch + '/data/L%04d_N%04d_S%04d_40step/' % (bs, fine * nc, seed), R1=R1, R2=R2, pmesh=True, abund=abund, doexp=doexp, mexp=mexp, cc=cc, stellar=stellar)[1] datap = pm.paint(hdictf['position'][:num], hdictf['mass'][:num])
def gridhalos(pm, dpath=None, pos=None, mass=None, R1=None, R2=None, rank=None, abund=True, sigma=None, seed=123, pmesh=True, z=0, doexp=False, mexp=None, cc=None, stellar=False, verbose=True): '''Read halo file or pos/mas arrays and grid and smooth them after scattering or matching abundance or both The path should have folder FOF in it. ''' #Matter bs, nc = pm.BoxSize[0], pm.Nmesh[0] #Halos if dpath is not None: from nbodykit.lab import CurrentMPIComm CurrentMPIComm.set( pm.comm ) #WORKAROUND because BigFileCatalog ignores comm o/w. Should not need after nbodykit v0.3.4 fofcat = BigFileCatalog(dpath + 'FOF', header='Header', comm=pm.comm) halopos = fofcat['PeakPosition'].compute()[1:] halomass = (fofcat['Mass'].compute() * 10**10)[1:] try: hvel = fofcat['CMVelocity'].compute()[1:] except Exception as e: print(e) print('Cannot read velocity') hvel = None if verbose: print('BigFileCatalog read') elif pos is not None: halopos = pos if mass is not None: halomass = mass else: print( 'No halo masses given, so mass=1. Scatter and abundance not valid' ) halomass = np.ones(halopos.shape[0]) sigma = None abund = False else: print('Need either path of Bigfile, or catalogs') return None if abund: if verbose: print('Match abundance') halomass = mf.icdf_sampling(hmass=halomass, bs=bs, z=z) if stellar: halomass = mf.stellar_mass(halomass) if sigma is not None: print('Scatter catalog with sigma = %0.2f' % sigma) halomass, halopos = dg.scatter_catalog(halomass, halopos, sigma, seed) if doexp: if verbose: print('Doing doexp with mexp = %0.2f, cc=%0.2f' % (mexp, cc)) halomass = mf.fmexp(halomass, mexp, cc) #print('In gridhalos') #print(rank, halomass.size) #print(dpath) if rank is not None: if rank > halomass.size: print('\nCatalog not big enough to be able to match abundance') print('\nDesired rank = %d, catalog size = %d' % (rank, halomass.size)) return None else: halopos = halopos[:rank + 1] halomass = halomass[:rank + 1] hvel = hvel[:rank + 1] halos = {'position': halopos, 'mass': halomass, 'velocity': hvel} if pmesh: halomesh = pm.paint(halopos, mass=halomass) hposmesh = pm.paint(halopos) meshdict = {'hposmesh': hposmesh.value, 'halomesh': halomesh.value} dkh = halomesh.r2c() if R1 is not None: hmR1mesh = ft.smooth(dkh, R1, 'fingauss') meshdict['hmR1mesh'] = hmR1mesh.value if R2 is not None: hmR2mesh = ft.smooth(dkh, R2, 'fingauss') meshdict['hmR2mesh'] = hmR2mesh.value else: meshdict = None return meshdict, halos
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_bsum_plot(): """bias rcc, tf, error, bk""" ik = args.ik 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) if args.ray: hmesh = BigFileMesh('/global/cscratch1/sd/chmodi/m3127/H1mass/highres/%d-9100/fastpm_%0.4f/HImesh-N%04d/'%(bs*10, aa, nc), 'ModelA').paint() lin = BigFileMesh('/global/cscratch1/sd/chmodi/m3127/cm_lowres/5stepT-B1/%d-%d-9100/linear'%(bs, nc), 'LinearDensityK').paint() dyn = BigFileCatalog('/global/cscratch1/sd/chmodi/m3127/cm_lowres/5stepT-B1/%d-%d-9100/fastpm_%0.4f/1'%(bs, nc, aa), comm=pm.comm, header='Header') 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() lin = BigFileMesh('/global/cscratch1/sd/chmodi/m3127/cm_lowres/5stepT-B1/%d-%d-9100-fixed/linear'%(bs, nc), 'LinearDensityK').paint() dyn = BigFileCatalog('/global/cscratch1/sd/chmodi/m3127/cm_lowres/5stepT-B1/%d-%d-9100-fixed/fastpm_%0.4f/1'%(bs, nc, aa), comm=pm.comm, header='Header') print(pm.comm.rank, dyn.Index.compute()) fpos = dyn['Position'] flay = pm.decompose(fpos) # dgrow = cosmo.scale_independent_growth_factor(zz) zapos = za.doza(lin.r2c(), grid, z=zz, dgrow=dgrow) print(zapos.shape, fpos.shape) paramsza, zamod = getbias(pm, basemesh=lin, hmesh=hmesh, pos=zapos, grid=grid, ik=ik) _, pmmod = getbias(pm, basemesh=lin, hmesh=hmesh, pos=fpos, grid=grid, ik=ik) kk, paramszak, _ = getbiask(pm, basemesh=lin, hmesh=hmesh, pos=zapos, grid=grid) # fin = pm.paint(fpos, layout=flay) fin /= fin.cmean() fin -= 1 finsm = ft.smooth(fin, 3, 'gauss') _, finmod = getbias(pm, basemesh=finsm, hmesh=hmesh, pos=grid, grid=grid, ik=ik) models = [zamod, pmmod, finmod, finsm.copy()] lbls = ['ZA shift', 'PM shift', 'Eulerian (R=3)', 'Eulerian (R=3), $b_1^E$'] lss = ['-', '-', '-', '--'] print('Setup done') ##### fig, ax = plt.subplots(2, 2, figsize=(8, 6), sharex=True) 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, 0].plot(k, pxmodh/(pmod*ph)**0.5, label=lbls[ii], lw=2, ls=lss[ii]) ax[0, 0].set_ylabel('$r_{cc}$', fontdict=font) #if ii == 3: pmod *= ph[1]/pmod[1] ax[0, 1].plot(k,(pmod/ph)**0.5, lw=2, ls=lss[ii]) ax[0, 1].set_ylabel(r'$T_f$', fontdict=font) #ax[1].set_ylabel(r'$\sqrt{P_{\rm mod}/P_{hh}}$', fontdict=font) ax[1, 0].plot(k, perr, lw=2, ls=lss[ii]) ax[1, 0].set_ylabel(r'$P_{\rm err}$', fontdict=font) ax[1, 0].set_yscale('log') ax[1, 0].axhline(noise, color='k', ls="--") ax[1, 0].set_ylim(2, 5e2) lbls = ['$b_1$', '$b_2$', '$b_s$'] for ii in range(3): ax[1, 1].plot(kk, paramszak[ii], lw=2, color='C%d'%ii, label=lbls[ii]) ax[1, 1].axhline(paramsza[ii], lw=1, color='C%d'%ii, ls="--") ax[1, 1].set_ylabel(r'$b(k)$', fontdict=font) for axis in ax.flatten(): axis.set_xscale('log') axis.grid(which='both', alpha=0.2, color='gray', lw=0.2) axis.legend(prop=fontmanage) axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font) axis.set_xscale('log') axis.axvline(kk[ik], color='k', ls="--") # Put on some more labels. for axis in ax.flatten(): 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]) if args.ray: plt.savefig(figpath + '/bsum_L%04d_N%04d_%04d_ik%d.pdf'%(bs, nc, aa*10000, ik)) else: plt.savefig(figpath + '/bsumfix_L%04d_N%04d_%04d_ik%d.pdf'%(bs, nc, aa*10000, ik))
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))
R1, R2 = pdict['R1'], pdict['R2'] #model meshdict, dummy = ntools.readfiles( pm, scratch + '/data/L%04d_N%04d_S%04d_05step/' % (bs, nc, seed), R1=R1, R2=R2, abund=abund) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc) predict = pm.create(mode='real') predict[...] = nnpred * nnmass predictR = ft.smooth(predict, 3, 'fingauss') #data #hdictf = ntools.gridhalos(pm, scratch +'/data/L%04d_N%04d_S%04d_40step/'%(bs, 4*nc, seed), rank=num, R1=R1, R2=R2, pmesh=True) #datapt = pm.create(mode='real', zeros=True) #datapt[...] = hdictf[0]['halomesh'] hdictf = ntools.gridhalos(pm, scratch + '/data/L%04d_N%04d_S%04d_40step/' % (bs, fine * nc, seed), R1=R1, R2=R2, pmesh=True, abund=abund)[1] datap = pm.paint(hdictf['position'][:num], hdictf['mass'][:num]) datapR = ft.smooth(datap, 3, 'fingauss')
#model print('Reading Files') meshdict, dummy = ntools.readfiles(pm, scratch + '/data/z%02d/L%04d_N%04d_S%04d_05step/' % (zz * 10, bs, nc, seed), R1=R1, R2=R2, abund=abund) ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal) mftt = ntools.createdata(pm, meshdict, mftname, mlocal) nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc) predict = pm.create(mode='real', value=nnpred) predictR = ft.smooth(predict, Rsm, 'fingauss') if ovd: predictR[...] = (predictR[...] - predictR.cmean()) / (predictR.cmean()) #data print('Generating data') hdictf = ntools.gridhalos(pm, dpath=scratch + '/data/z%02d/L%04d_N%04d_S%04d_40step/' % (zz * 10, bs, sfine * nc, seed), R1=R1, R2=R2, pmesh=False, abund=abund)[1] datap = pm.paint(hdictf['position'][:num])
predict = pm.create(mode='real') predict[...] = nnpred * nnmass if rsd: if not zz: cat = BigFileCatalog(scratch + '/data/L%04d_N%04d_S%04d_05step/dynamic/1' % (bs, nc, seed), header='Header') else: cat = BigFileCatalog(scratch + '/data/z%02d/L%04d_N%04d_S%04d_05step/dynamic/1' % (zz * 10, bs, nc, seed), header='Header') mass = pm.paint(cat['Position']) mom = pm.paint(cat['Position'], mass=cat['Velocity'][:, 2]) masssm = ft.smooth(mass, Rrsd, 'fingauss') + 1e-5 momsm = ft.smooth(mom, Rrsd, 'fingauss') vel = momsm / masssm gridpt = pm.generate_uniform_particle_grid(shift=0) vgrid = vel.readout(gridpt) vgrid *= rsdfactor predictgrid = predict.readout(gridpt) predict = pm.paint(gridpt + vgrid.reshape(-1, 1) * direct.reshape(1, -1), mass=predictgrid) predictR = ft.smooth(predict, Rsm, 'fingauss') #data print('Generating data') #hdictf = ntools.gridhalos(pm, scratch +'/data/L%04d_N%04d_S%04d_40step/'%(bs, 4*nc, seed), rank=num, R1=R1, R2=R2, pmesh=True)
def standard(pm, fofcat, datap, mf, kb=6, Rsm=7, rsd=False, zz=0, M=0.3175, mass=False, poskey='PeakPosition'): if rsd: if pm.comm.rank == 0: print( '\n RSD! Key used to get position is --- RSPeakPosition \n\n') position = fofcat['RS%s' % poskey].compute() else: position = fofcat['%s' % poskey].compute() try: hmass = fofcat['AMass'].compute() * 1e10 except: hmass = fofcat['Mass'].compute() * 1e10 pks = FFTPower(datap.s, mode='1d').power['power'] pkf = FFTPower(datap.d, mode='1d').power['power'] random = pm.generate_uniform_particle_grid() # random = np.random.uniform(0, 400, 3*128**3).reshape(-1, 3) Rbao = Rsm / 2**0.5 aa = mf.cosmo.ztoa(zz) ff = mf.cosmo.Fomega1(mf.cosmo.ztoa(zz)) layout = pm.decompose(position) if mass: hmesh = pm.paint(position, mass=hmass, layout=layout) else: hmesh = pm.paint(position, layout=layout) hmesh /= hmesh.cmean() hmesh -= 1 hmeshsm = ft.smooth(hmesh, Rbao, 'gauss') #bias layout = pm.decompose(fofcat['%s' % poskey]) hrealp = pm.paint(fofcat['%s' % poskey], layout=layout) hrealp /= hrealp.cmean() hrealp -= 1 pkhp = FFTPower(hrealp, mode='1d').power['power'] bias = ((pkhp[1:kb] / pkf[1:kb]).mean()**0.5).real beta = bias / ff print('bias = ', bias) displist = calc_displist(pm=pm, base=hmeshsm, b=bias) if mass: hpshift = displace(pm, displist, position, rsd=rsd, f=ff, beta=beta, mass=hmass) else: hpshift = displace(pm, displist, position, rsd=rsd, f=ff, beta=beta, mass=None) rshift = displace(pm, displist, random, rsd=rsd, f=ff, beta=beta) recon = hpshift - rshift return recon, hpshift, rshift
def dostd(hdict, numd, pkf, datas, kb=6, Rsm=7, rsd=False, zz=0, M=0.3175, mass=False, retfield=False, retpower=False, mode='1d', Nmu=5, los=[0, 0, 1], retall=False): #propogator is divided by bias hpos = hdict['position'] hmass = hdict['mass'] pks = FFTPower(datas, mode=mode, Nmu=Nmu, los=[0, 0, 1]).power['power'] aa = mf.cosmo.ztoa(zz) ff = mf.cosmo.Fomega1(mf.cosmo.ztoa(zz)) rsdfac = 100 / (aa**2 * mf.cosmo.Ha(z=zz)**1) print('rsdfac = ', rsdfac) hposrsd = hdict['position'] + np.array(los) * hdict['velocity'] * rsdfac layout = pm.decompose(hpos[:int(numd * bs**3)]) if mass: hpmesh = pm.paint(hpos[:int(numd * bs**3)], mass=hmass[:int(numd * bs**3)], layout=layout) else: hpmesh = pm.paint(hpos[:int(numd * bs**3)], layout=layout) hpmesh /= hpmesh.cmean() hpmesh -= 1 layout = pm.decompose(hposrsd[:int(numd * bs**3)]) if mass: hpmeshrsd = pm.paint(hposrsd[:int(numd * bs**3)], mass=hmass[:int(numd * bs**3)], layout=layout) else: hpmeshrsd = pm.paint(hposrsd[:int(numd * bs**3)], layout=layout) hpmeshrsd /= hpmeshrsd.cmean() hpmeshrsd -= 1 pkhp = FFTPower(hpmesh, mode='1d').power['power'] bias = ((pkhp[1:kb] / pkf[1:kb]).mean()**0.5).real beta = bias / ff print('bias = ', bias) random = pm.generate_uniform_particle_grid() random = np.random.uniform(0, 400, 3 * 128**3).reshape(-1, 3) Rbao = Rsm / 2**0.5 if not rsd: hpmeshsm = ft.smooth(hpmesh, Rbao, 'gauss') displist = calc_displist(hpmeshsm, b=bias) if mass: hpshift = displace(pm, displist, hpos[:int(numd * bs**3)], mass=hmass[:int(numd * bs**3)]) else: hpshift = displace(pm, displist, hpos[:int(numd * bs**3)]) rshift = displace(pm, displist, random) recon = hpshift - rshift pksstd = FFTPower(recon, mode=mode, Nmu=Nmu, los=[0, 0, 1]).power['power'] pkxsstd = FFTPower(recon, second=datas, mode=mode, Nmu=Nmu, los=[0, 0, 1]).power['power'] rccstd = pkxsstd / (pks * pksstd)**0.5 cksstd = pkxsstd / pks / bias if rsd: RSD hpmeshrsdsm = ft.smooth(hpmeshrsd, Rbao, 'gauss') displist = calc_displist(hpmeshrsdsm, b=bias) hpshift = displace(pm, displist, hposrsd[:int(numd * bs**3)], rsd=True, f=ff, beta=bias / ff) if mass: hpshift = displace(pm, displist, hposrsd[:int(numd * bs**3)], rsd=True, f=ff, beta=bias / ff, mass=hmass[:int(numd * bs**3)]) else: hpshift = displace(pm, displist, hposrsd[:int(numd * bs**3)], rsd=True, f=ff, beta=bias / ff) rshift = displace(pm, displist, random, rsd=True, f=ff, beta=beta) recon = hpshift - rshift pksstd = FFTPower(recon, mode='1d').power['power'] pkxsstd = FFTPower(recon, second=datap[tkey].s, mode='1d').power['power'] pksstd = FFTPower(recon, mode=mode, Nmu=Nmu, los=[0, 0, 1]).power['power'] pkxsstd = FFTPower(recon, second=datas, mode=mode, Nmu=Nmu, los=[0, 0, 1]).power['power'] rccstd = pkxsstd / (pks * pksstd)**0.5 cksstd = pkxsstd / pks / bias if retall: return [rccstd, cksstd], [recon, hpshift, rshift, displist], [pkxsstd, pksstd, pks], bias if retfield: return [rccstd, cksstd], [recon, hpshift, rshift, displist] elif retpower: return [rccstd, cksstd], [pkxsstd, pksstd, pks], bias else: return rccstd, cksstd