Beispiel #1
0
def rand_map(shape, wcs, ps_lensinput, doRotation=False, ps_rot=None, lmax=None,
             maplmax=None, dtype=np.float64, seed=None, phi_seed=None,
             oversample=2.0, spin=[0,2], output="l", geodesic=True, verbose=False,
             delta_theta=None):
    from pixell import curvedsky, sharp
    ctype   = np.result_type(dtype,0j)

    # Restrict to target number of components
    oshape  = shape[-3:]
    if len(oshape) == 2: shape = (1,)+tuple(shape)
    ncomp   = shape[-3]
    ps_lensinput = ps_lensinput[:1+ncomp,:1+ncomp]
    # First draw a random lensing field, and use it to compute the undeflected positions
    if verbose: print("Generating alms")
    if phi_seed is None:
        alm, ainfo = curvedsky.rand_alm(ps_lensinput, lmax=lmax, seed=seed, dtype=ctype, return_ainfo=True)
    else:
        # We want separate seeds for cmb and phi. This means we have to do things a bit more manually
        wps, ainfo = curvedsky.prepare_ps(ps_lensinput, lmax=lmax)
        alm = np.empty([1+ncomp,ainfo.nelem],ctype)
        curvedsky.rand_alm_white(ainfo, alm=alm[:1], seed=phi_seed)
        curvedsky.rand_alm_white(ainfo, alm=alm[1:], seed=seed)
        ps12 = enmap.multi_pow(wps, 0.5)
        ainfo.lmul(alm, (ps12/2**0.5).astype(dtype), alm)
        alm[:,:ainfo.lmax].imag  = 0
        alm[:,:ainfo.lmax].real *= 2**0.5
        del wps, ps12

    phi_alm, cmb_alm = alm[0], alm[1:]

    if doRotation:
        # generate a gaussian random field of rotational field
        alpha_shape = (1, shape[-2], shape[-1])

        alpha_map = curvedsky.rand_map(alpha_shape, wcs, ps_rot, lmax=lmax)

        # convert alm to enmap object
        cmb_map = enmap.empty((3,shape[-2],shape[-1]), wcs)
        curvedsky.alm2map(cmb_alm, cmb_map)

        # rotate tqu map by a rotational field
        # Q_map = cmb_map[1]
        # U_map = cmb_map[2]
        cmb_map_rot = enmap.rotate_pol(cmb_map, alpha_map)

        # convert tqu map back to the alm
        cmb_alm = curvedsky.map2alm(cmb_map_rot, lmax=lmax)
        del alpha_map, cmb_map, cmb_map_rot

        del alm
        # Truncate alm if we want a smoother map. In taylens, it was necessary to truncate
        # to a lower lmax for the map than for phi, to avoid aliasing. The appropriate lmax
        # for the cmb was the one that fits the resolution. FIXME: Can't slice alm this way.
        #if maplmax: cmb_alm = cmb_alm[:,:maplmax]
        return lens_map_curved(shape=shape, wcs=wcs, phi_alm=phi_alm,
                               cmb_alm=cmb_alm, phi_ainfo=ainfo, maplmax=maplmax,
                               dtype=dtype, oversample=oversample, spin=spin,
                               output=output, geodesic=geodesic, verbose=verbose,
                               delta_theta=delta_theta)
Beispiel #2
0
def get_covsqrt(ps, method="arrayops"):
    if method == "multipow":
        covsq = enmap.multi_pow(ps.copy(), 0.5)
    elif method == "arrayops":
        from enlib import array_ops
        covsq = array_ops.eigpow(ps.copy(), 0.5, axes=[0, 1])
    covsq[:, :, ps.modlmap() < 2] = 0
    assert np.all(np.isfinite(covsq))
    return enmap.enmap(covsq, ps.wcs)
Beispiel #3
0
                                        array=args.array,
                                        mkdir=True,
                                        overwrite=args.overwrite,
                                        mask_patch=mask_patch)

# Get data model
mask = sints.get_act_mr3_crosslinked_mask(mask_patch,
                                          version=args.mask_version,
                                          kind=args.mask_kind,
                                          season=args.season,
                                          array=args.array + "_f150",
                                          pad=args.mask_pad)
dm = sints.models[args.model](region=mask, calibrated=args.calibrated)

n2d = enmap.read_map(pout + '_n2d.fits')
covsq = enmap.multi_pow(n2d.copy(), 0.5)
covsq[:, :, n2d.modlmap() < 2] = 0
print('D', np.argwhere(~np.isfinite(covsq)))
covsq = enmap.enmap(covsq, n2d.wcs)
print('E', np.argwhere(~np.isfinite(covsq)))

#enmap.write_map(pout+'_covsqrt_tmp.fits',covsq)
#covsq = enmap.read_map(pout+'_covsqrt_tmp.fits')

#covsq = enmap.read_map(pout+'_covsqrt.fits')

#shape = np.shape(n2d[0,0,:,:])
#res = n2d*0.
#for li in range(shape[0]):
#    for lj in range(shape[1]):
#        E, V = np.linalg.eigh(n2d[:,:,li,lj])