Commit 1e454347 by Maude Le Jeune

### +nilc

parent f8422b39
 ... ... @@ -22,7 +22,7 @@ from pylab import * import utils import spherelib_alm import bin import healpy as hp ## from http://www.phys.uu.nl/~haque/computing/WPark_recipes_in_python.html ## using numerical recipes ... ... @@ -51,32 +51,32 @@ def lmax2nside(lmax, level=2): ## nside >= (lmax+1)/sqrt(12) ## npix >= (lmax+1)^2 if level==1: nside = 2 ** nextpow2( (lmax+1)/sqrt(12.0) ) nside = nextpow2( (lmax+1)/sqrt(12.0) ) ## Healpix's advice ## nside >= lmax/2 ## i.e. npix >= 3 * lmax^2 elif level==2: nside = 2 ** nextpow2( lmax/2.0 ) nside = nextpow2( lmax/2.0 ) ## More conservative ## nside >= lmax elif level==3: nside = 2 ** nextpow2( lmax ) nside = nextpow2( lmax ) else: raise Exception ("level is 1, 2 or 3") nside = max( nside, 4 ) ## because map2alm not happy with nside = 1 or 2 return nside def alm2cov (list_alm): def alm2cov (almtab): """ Compute second order statistics of spherical harmonic coefficients. Parameters ---------- list_alm : list of alm array of same size. almtab : array of alm (nalm, nin) Returns ------- ... ... @@ -84,13 +84,15 @@ def alm2cov (list_alm): vector of number of modes used to compute each matrix. """ nin = len(list_alm) nalm = len(list_alm[0]) almtab = zeros((nin, nalm), dtype="complex128") nin = shape(almtab)[1] nalm = shape(almtab)[0] #nin = len(list_alm) #nalm = len(list_alm[0]) #almtab = zeros((nin, nalm), dtype="complex128") lmax = int(round((sqrt(1+8*nalm)-3) / 2) ) for i in range(nin): almtab[i,:] = list_alm[i] #for i in range(nin): # almtab[i,:] = list_alm[i] ncross = nin*(nin+1)/2 ... ... @@ -106,3 +108,5 @@ def alm2cov (list_alm): nmode = bin.get_nmode(bin.uniformbin (0, lmax, 1)) return cov, nmode
 ... ... @@ -220,8 +220,10 @@ def smooth_cl (cl, dloverl=0.1): ell = arange(0,lmax+1) clsmooth = zeros(shape(cl)); for l in range(lmax+1): llo = max(int(round(ell[l]*(1-dloverl/2))), 0) lhi = min(int(round(ell[l]*(1+dloverl/2))), lmax) llo = max(int(round(ell[l]*(1-dloverl/2.0))), 0) lhi = min(int(round(ell[l]*(1+dloverl/2.0))), lmax) if llo==lhi: lhi=llo+1 clsmooth[l] = mean(cl[llo:lhi]) return clsmooth ... ...
 ... ... @@ -20,6 +20,7 @@ from pylab import * import bin import map import healpy def beam_correction (cov, beams, max_inv=10000): """ Correct covariance matrices from beam effect ... ... @@ -129,3 +130,27 @@ def wiener (RModel): for q in range(nbin): W[comp,:,:,q] = dot(RModel[:,:,q,comp],inv(R[:,:,q])) return W def plotlocalizedfield (F, zone, figfile=None): """ Plot an Healpix map of a localized field. Parameters ---------- F : array-like, shape (1, N), with N number of zones. zone : array-like, shape (npix, 1). An HEALPix map with pixel equal to zone number. figfile : string. File name where to save the plot. """ nside = healpy.get_nside(zone) npix = healpy.nside2npix(nside) map = zeros((npix, 1)) if shape(F): for p in range(npix): map[p] = F[zone[p]] else: map = ones((npix, 1))*F healpy.mollview(squeeze(map)) if figfile is None: show() else: savefig(figfile)
 ... ... @@ -20,6 +20,7 @@ Healpix map computations. import spherelib_map from numpy import * import utils def mask2mll(mask, lmax): """ Compute the mode coupling matrix. ... ... @@ -38,3 +39,81 @@ def mask2mll(mask, lmax): return mll def make_kp_zone (covers, refmap, nside=128): """ Build kp-like zone. Parameters ---------- covers: array-like, sky coverage of each zone. refmap: reference map (like WMAP K band) nside: integer, map resolution """ npix = 12*nside*nside map = zeros((npix)) spherelib_map._make_kp_zone(map, covers, refmap) return squeeze(map) def make_grid_zone (nside_grid, nside=128): """ Build healpix grid zone. Parameters ---------- nside_grid: integer, grid resolution nside: integer, map resolution """ npix = 12*nside*nside map = zeros((npix)) spherelib_map._make_grid_zone(map, nside_grid) return squeeze(map) def map2cov (maptab, zone): """ Compute second order statistics of healpix maps. Parameters ---------- maptab : array of map (nin, npix) zone: map which indices pixel sets from 0 to nz Returns ------- 3D array representing symetric covariance matrices vector of number of modes used to compute each matrix. (nin, nin, nz) """ nin = shape(maptab)[0] npix = max(zone)+1 ncross = nin*(nin+1)/2 covtab = zeros((ncross, npix)) nmode = zeros((npix)) spherelib_map._map2cov (maptab, zone, covtab, nmode) cov = zeros((nin, nin, npix)) for p in range(npix): cov[:,:,p] = utils.vec2mat(covtab[:,p]) return cov, nmode def combine_zone (maptab, zone, w): """ Combine healpy maps by pixel sets. Parameters ---------- maptab : array of map (nin, npix) zone: map which indices pixel sets from 0 to nz w : weight for combination (nin, nz) Returns ------- an healpix map (npix) """ nin = shape(maptab)[0] npix = len(zone) cmap = zeros((npix)) spherelib_map._combine_zone(maptab, zone, cmap, w) return cmap
 ... ... @@ -183,7 +183,7 @@ def read_alm (file): alm[j] = complex(vec[i], vec[i+1]) j = j+1 else: alm = sp.read_alm(file) alm = hp.read_alm(file) return np.squeeze(alm) ... ...