KSZ fix.
This commit is contained in:
parent
f2b81d863f
commit
eb9d4a2932
6 changed files with 77 additions and 39 deletions
|
@ -3,6 +3,8 @@ import numpy as np
|
|||
import cosmotool as ct
|
||||
import argparse
|
||||
import h5py as h5
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
from matplotlib import pyplot as plt
|
||||
import ksz
|
||||
from ksz.constants import *
|
||||
|
@ -54,48 +56,60 @@ def build_unit_vectors(N):
|
|||
return ux,uy,uz
|
||||
|
||||
def build_radial_v(v):
|
||||
N = v[0].shape[0]
|
||||
u = build_unit_vectors(N)
|
||||
vr = v[0] * u[0]
|
||||
vr = v[0] * u[2]
|
||||
vr += v[1] * u[1]
|
||||
vr += v[2] * u[2]
|
||||
return vr
|
||||
vr += v[2] * u[0]
|
||||
|
||||
def generate_from_catalog(vfield,Boxsize):
|
||||
return vr.transpose()
|
||||
|
||||
def generate_from_catalog(vfield,Boxsize,dmin,dmax):
|
||||
import progressbar as pbar
|
||||
|
||||
cat = np.load("2m++.npy")
|
||||
|
||||
profiler = KSZ_Isothermal(2.37)
|
||||
|
||||
cat['distance'] = cat['best_velcmb']
|
||||
cat = cat[np.where((cat['distance']>100*dmin)*(cat['distance']<dmax*100))]
|
||||
|
||||
deg2rad = np.pi/180
|
||||
Npix = 12*Nside**2
|
||||
xp,yp,zp = hp.pix2vec(Nside, np.arange(Npix))
|
||||
N2 = np.sqrt(xp**2+yp**2+zp**2)
|
||||
|
||||
ksz_template = np.zeros(12*Nside**2, dtype=np.float64)
|
||||
ksz_mask = np.zeros(12**Nside**2, dtype=np.uint8)
|
||||
ksz_template = np.zeros(Npix, dtype=np.float64)
|
||||
ksz_mask = np.zeros(Npix, dtype=np.uint8)
|
||||
|
||||
pb = pbar.ProgressBar(maxval = cat.size, widgets=[pb.Bar(), pb.ETA()]).start()
|
||||
pb = pbar.ProgressBar(maxval = cat.size, widgets=[pbar.Bar(), pbar.ETA()]).start()
|
||||
|
||||
for k,i in np.ndenumerate(cat):
|
||||
pb.update(k)
|
||||
pb.update(k[0])
|
||||
l,b=i['gal_long'],i['gal_lat']
|
||||
ra,dec=i['ra'],i['dec']
|
||||
|
||||
l *= deg2rad
|
||||
b *= deg2rad
|
||||
|
||||
x0 = np.cos(l)*np.cos(b)
|
||||
y0 = np.sin(l)*np.cos(b)
|
||||
z0 = np.sin(b)
|
||||
ra *= deg2rad
|
||||
dec *= deg2rad
|
||||
|
||||
# x0 = np.cos(l)*np.cos(b)
|
||||
# y0 = np.sin(l)*np.cos(b)
|
||||
# z0 = np.sin(b)
|
||||
|
||||
x0 = xra = np.cos(ra)*np.cos(dec)
|
||||
y0 = yra = np.sin(ra)*np.cos(dec)
|
||||
z0 = zra = np.sin(dec)
|
||||
|
||||
DA =i['distance']/100
|
||||
Lgal = DA**2*10**(0.4*(tmpp_cat['Msun']-i['K2MRS']+25))
|
||||
|
||||
idx0 = hp.query_disc(Nside, (x0,y0,z0), 3*rGalaxy/DA)
|
||||
profiler = ksz.KSZ_Isothermal(Lgal, 2.37)
|
||||
|
||||
vr = interp3d(DA * x0, DA * y0, DA * z0, vfield, Boxsize)
|
||||
idx0 = hp.query_disc(Nside, (x0,y0,z0), 3*profiler.rGalaxy/DA)
|
||||
|
||||
vr = interp3d(DA * xra, DA * yra, DA * zra, vfield, Boxsize)
|
||||
|
||||
xp1 = xp[idx0]
|
||||
yp1 = yp[idx0]
|
||||
|
@ -119,18 +133,33 @@ for i in xrange(args.start,args.end,args.step):
|
|||
ff=plt.figure(1)
|
||||
plt.clf()
|
||||
v=[]
|
||||
with h5.File(args.base_h5 % i, mode="r") as f:
|
||||
p = wrapper_impulsion(f)
|
||||
v.append(p[i] / f['density'][:])
|
||||
fname = args.base_h5 % i
|
||||
if False:
|
||||
print("Opening %s..." % fname)
|
||||
with h5.File(fname, mode="r") as f:
|
||||
p = wrapper_impulsion(f)
|
||||
for j in xrange(3):
|
||||
v.append(p[j] / f['density'][:])
|
||||
|
||||
print("Building radial velocities...")
|
||||
|
||||
# Rescale by Omega_b / Omega_m
|
||||
vr = build_radial_v(v)
|
||||
vr *= -ksz_normalization*rho_mean_matter*1e6
|
||||
del v
|
||||
vr = build_radial_v(v)
|
||||
# _,_,vr = build_unit_vectors(128)
|
||||
# vr *= 1000 * 500
|
||||
vr *= ksz_normalization*1e6
|
||||
del v
|
||||
# np.save("vr.npy", vr)
|
||||
else:
|
||||
print("Loading vrs...")
|
||||
vr = np.load("vr.npy")
|
||||
|
||||
proj = generate_from_catalog(vfield,Boxsize)
|
||||
print("Generating map...")
|
||||
|
||||
proj,mask = generate_from_catalog(vr,args.boxsize,args.depth_min,args.depth_max)
|
||||
|
||||
hp.write_map(args.ksz_map % i, proj)
|
||||
hp.write_map((args.ksz_map % i) + "_mask", mask)
|
||||
|
||||
hp.mollview(proj, fig=1, coord='CG', cmap=plt.cm.coolwarm, title='Sample %d' % i, min=args.minval,
|
||||
max=args.maxval)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue