import numexpr as ne import healpy as hp 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 * 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() def build_unit_vectors(N): ii = np.arange(N,dtype=np.float64)/N - 0.5 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 generate_from_catalog(dmin,dmax,Nside,do_random=False): import progressbar as pbar cat = np.load("2m++.npy") cat['distance'] = cat['best_velcmb'] cat = cat[np.where((cat['distance']>100*dmin)*(cat['distance'] 0: proj *= mask proj = hp.ud_grade(proj, nside_out=args.degrade) mask = hp.ud_grade(mask, nside_out=args.degrade) Nside = args.degrade else: Nside = args.Nside hp.write_map(args.ksz_map + ".fits", proj) hp.write_map(args.ksz_map + "_mask.fits", mask) if args.build_dipole: x,y,z=hp.pix2vec(Nside, np.arange(hp.nside2npix(Nside))) hp.write_map(args.ksz_map + "_x.fits", proj*x) hp.write_map(args.ksz_map + "_y.fits", proj*y) hp.write_map(args.ksz_map + "_z.fits", proj*z) hp.mollview(proj*100*1e6, fig=1, coord='GG', cmap=plt.cm.coolwarm, title='', min=args.minval, max=args.maxval) ff.savefig(args.base_fig) main()