diff --git a/python/_project.pyx b/python/_project.pyx index efe66bd..a8ff9dc 100644 --- a/python/_project.pyx +++ b/python/_project.pyx @@ -143,6 +143,10 @@ def interp3d(x not None, y not None, z not None, npx.ndarray[DTYPE_t, ndim=3] d not None, DTYPE_t Lbox, bool periodic=False): + """ interp3d(x,y,z,d,Lbox,periodic=False) -> interpolated values + + Compute the tri-linear interpolation of the given field (d) at the given position (x,y,z). It assumes that they are box-centered coordinates. So (x,y,z) == (0,0,0) is equivalent to the pixel at (Nx/2,Ny/2,Nz/2) with Nx,Ny,Nz = d.shape. If periodic is set, it assumes the box is periodic +""" cdef npx.ndarray[DTYPE_t] out cdef npx.ndarray[DTYPE_t] ax, ay, az cdef int i diff --git a/python_sample/build_2lpt_skymap.py b/python_sample/build_2lpt_skymap.py index 102d6ef..dfc2acb 100644 --- a/python_sample/build_2lpt_skymap.py +++ b/python_sample/build_2lpt_skymap.py @@ -18,6 +18,7 @@ parser.add_argument('--maxval', type=float, default=60) parser.add_argument('--depth_min', type=float, default=10) parser.add_argument('--depth_max', type=float, default=60) parser.add_argument('--iid', type=int, default=0) +parser.add_argument('--proj_cat', type=bool, default=False) args = parser.parse_args() INDATA="/nethome/lavaux/Copy/PlusSimulation/BORG/Input_Data/2m++.npy" @@ -61,8 +62,12 @@ for i in xrange(args.start,args.end,args.step): plt.clf() d = np.load(args.base_cic % i) proj = build_sky_proj(1+d, dmin=args.depth_min,dmax=args.depth_max,iid=args.iid) + proj /= (args.depth_max-args.depth_min) - hp.mollview(proj, fig=1, coord='CG', cmap=plt.cm.coolwarm, title='Sample %d' % i, min=args.minval, max=args.maxval) - hp.projscatter(b[idx], l[idx], lw=0, color='g', s=2.0, alpha=0.7) + hp.write_map("skymaps/proj_map_%d.fits" % i, proj) + + hp.mollview(proj, fig=1, coord='CG', cmap=plt.cm.copper, title='Sample %d' % i, min=args.minval, max=args.maxval) + if args.proj_cat: + hp.projscatter(b[idx], l[idx], lw=0, color=[0.1,0.8,0.8], s=2.0, alpha=0.7) ff.savefig(args.base_fig % i) diff --git a/python_sample/build_nbody_ksz_from_galaxies.py b/python_sample/build_nbody_ksz_from_galaxies.py new file mode 100644 index 0000000..c2d999b --- /dev/null +++ b/python_sample/build_nbody_ksz_from_galaxies.py @@ -0,0 +1,138 @@ +import healpy as hp +import numpy as np +import cosmotool as ct +import argparse +import h5py as h5 +from matplotlib import pyplot as plt +import ksz +from ksz.constants import * +from cosmotool import interp3d + +def wrapper_impulsion(f): + + class _Wrapper(object): + def __init__(self): + pass + + def __getitem__(self,direction): + + if 'velocity' in f: + return f['velocity'][:,:,:,direction] + + n = "p%d" % direction + return f[n] + + return _Wrapper() + +parser=argparse.ArgumentParser(description="Generate Skymaps from CIC maps") +parser.add_argument('--boxsize', type=float, required=True) +parser.add_argument('--Nside', type=int, default=128) +parser.add_argument('--base_h5', type=str, required=True) +parser.add_argument('--base_fig', type=str, required=True) +parser.add_argument('--start', type=int, required=True) +parser.add_argument('--end', type=int, required=True) +parser.add_argument('--step', type=int, required=True) +parser.add_argument('--minval', type=float, default=-0.5) +parser.add_argument('--maxval', type=float, default=0.5) +parser.add_argument('--depth_min', type=float, default=10) +parser.add_argument('--depth_max', type=float, default=60) +parser.add_argument('--iid', type=int, default=0) +parser.add_argument('--ksz_map', type=str, required=True) +args = parser.parse_args() + +L = args.boxsize +Nside = args.Nside + +def build_unit_vectors(N): + ii = np.arange(N)*L/N - 0.5*L + d = np.sqrt(ii[:,None,None]**2 + ii[None,:,None]**2 + ii[None,None,:]**2) + d[N/2,N/2,N/2] = 1 + ux = ii[:,None,None] / d + uy = ii[None,:,None] / d + uz = ii[None,None,:] / d + + return ux,uy,uz + +def build_radial_v(v): + u = build_unit_vectors(N) + vr = v[0] * u[0] + vr += v[1] * u[1] + vr += v[2] * u[2] + return vr + +def generate_from_catalog(vfield,Boxsize): + 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'] 0)[0] + tan_theta_2 = 1/(cos_theta[idx]**2) - 1 + tan_theta_2_max = (self.rGalaxy/angularDistance)**2 + tan_theta_2_min = (R_star/angularDistance)**2 + + idx0 = np.where((tan_theta_2 < tan_theta_2_max)) + idx = idx[idx0] + tan_theta_2 = tan_theta_2[idx0] + tan_theta = np.sqrt(tan_theta_2) + + r = (tan_theta*DA) + + m,idx_mask = self.evaluate_profile(r) + + idx_mask = np.append(idx_mask,np.where(tan_theta_2