Beispiel #1
0
    def observe(self,freq_GHz,noise_ukarcmin=3.,beam_fwhm_arcmin=8.):

        import pysm3
        import pysm3.units as u
        #np.random.seed(213114124+int(freq_GHz))

        beam = gauss_beam(np.arange(self.lmax_sim+10),beam_fwhm_arcmin)#hp.gauss_beam(beam_fwhm_arcmin*(np.pi/60./180),lmax=3*self.nside)
        beam[beam==0] = np.inf
        beam = 1/beam

        shape,wcs = enmap.fullsky_geometry(self.pixRes_arcmin)

        Q_noise = np.sqrt(2)*noise_ukarcmin*(np.pi/180/60)*curvedsky.rand_map(shape, wcs, beam**2)
        U_noise = np.sqrt(2)*noise_ukarcmin*(np.pi/180/60)*curvedsky.rand_map(shape, wcs, beam**2)

        sky = pysm3.Sky(nside=self.nside_pysm,preset_strings=["d1","s1"],output_unit="K_CMB")
        # Get the map at the desired frequency:
        I,Q_foreground,U_foreground = sky.get_emission(freq_GHz*u.GHz)*1e6

        I,Q_foreground,U_foreground = reproject.enmap_from_healpix([I,Q_foreground,U_foreground], shape, wcs,
                                  ncomp=3, unit=1, lmax=self.lmax_sim,rot=None)

        Q_map =  self.Q_cmb.copy()
        Q_map += Q_noise
        Q_map += Q_foreground


        U_map =  self.U_cmb.copy()
        U_map += U_noise
        U_map += U_foreground

        return Q_map,U_map
Beispiel #2
0
    def observe(self,freq_GHz,noise_ukarcmin=3.,beam_fwhm_arcmin=8.):


        #np.random.seed(213114124+int(freq_GHz))


        beam = gauss_beam(np.arange(self.lmax_sim+10),beam_fwhm_arcmin)#hp.gauss_beam(beam_fwhm_arcmin*(np.pi/60./180),lmax=3*self.nside)
        beam[beam==0] = np.inf
        beam = 1/beam

        shape,wcs = enmap.fullsky_geometry(self.pixRes_arcmin)

        Q_noise = np.sqrt(2)*noise_ukarcmin*(np.pi/180/60)*curvedsky.rand_map(shape, wcs, beam**2)
        U_noise = np.sqrt(2)*noise_ukarcmin*(np.pi/180/60)*curvedsky.rand_map(shape, wcs, beam**2)
        Q_map =  self.Q_cmb.copy()
        Q_map += Q_noise
        Q_map += self.Q_dust*galaticDust_SED(freq_GHz,in_uk=True)
        Q_map += self.Q_sync*synchrotron_SED(freq_GHz,in_uk=True)


        U_map =  self.U_cmb.copy()
        U_map += U_noise
        U_map += self.U_dust*galaticDust_SED(freq_GHz,in_uk=True)
        U_map += self.U_sync*synchrotron_SED(freq_GHz,in_uk=True)

        return Q_map,U_map
Beispiel #3
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 #4
0
 def test_sim_slice(self):
     ps = powspec.read_spectrum(DATA_PREFIX+"test_scalCls.dat")[:1,:1]
     test_res_arcmin = 10.0
     lmax = 2000
     fact = 2.
     shape,wcs = enmap.fullsky_geometry(res=np.deg2rad(test_res_arcmin/60.),proj='car')
     omap = curvedsky.rand_map(shape, wcs, ps,lmax=lmax)
     ofunc = lambda ishape,iwcs: fact*enmap.extract(omap,ishape,iwcs)
     nmap = reproject.populate(shape,wcs,ofunc,maxpixy = 400,maxpixx = 400)
     assert np.all(np.isclose(nmap/omap,2.))
Beispiel #5
0
def generate_map(shape, wcs, powspec, lmax, seed):
    return curvedsky.rand_map(shape,
                              wcs,
                              powspec,
                              lmax=lmax,
                              dtype=np.float64,
                              seed=seed,
                              oversample=2.0,
                              spin=[0, 2],
                              method="auto",
                              direct=False,
                              verbose=False)
Beispiel #6
0
def test_sim_slice():
    path = os.path.dirname(enmap.__file__) + "/../tests/"
    ps = powspec.read_spectrum(path + "data/test_scalCls.dat")[:1, :1]
    test_res_arcmin = 10.0
    lmax = 2000
    fact = 2.
    shape, wcs = enmap.fullsky_geometry(res=np.deg2rad(test_res_arcmin / 60.),
                                        proj='car')
    omap = curvedsky.rand_map(shape, wcs, ps, lmax=lmax)
    ofunc = lambda ishape, iwcs: fact * enmap.extract(omap, ishape, iwcs)
    nmap = reproject.populate(shape, wcs, ofunc, maxpixy=400, maxpixx=400)
    assert np.all(np.isclose(nmap / omap, 2.))
Beispiel #7
0
def generate_sim(ivar_list, cls, lmax, seed):
    """
	Input: ivar_list: list of inverse variance maps
	cls: flattened 1D power spectrum Pab
	lmax:maximum multipole to generate the simulated maps
	seed: currently a number, need to fix this.
	Returns:
	list of sumulated maps.
	"""
    shape = ivar_list[0].shape
    wcs = ivar_list[0].wcs
    pmap = enmap.pixsizemap(shape, wcs)
    k = len(ivar_list)
    sim_maplist = []
    for i in range(len(ivar_list)):
        sim_map = np.sqrt(k) * cs.rand_map(
            shape, wcs, cls, lmax, spin=0, seed=seed + i) / (np.sqrt(
                ivar_eff(i, ivar_list) / pmap))
        sim_map[~np.isfinite(sim_map)] = 0
        sim_maplist.append(sim_map)
    return sim_maplist
Beispiel #8
0
importlib.reload(plot_ps)

lmin = 2
lmax = 1000
ls = np.arange(0, lmax)
nside = 400


def t(ls):
    return ls * (ls + 1)


shape, wcs = enmap.fullsky_geometry(res=20 * utils.arcmin, proj='car')
# generate unlensed map using input unlensd ps
unlensed_ps = load_data.unlensed(lmin, lmax, 'TT').spectra()
unlensed_map = curvedsky.rand_map(shape, wcs, unlensed_ps)
unlensed_alm = curvedsky.map2alm(unlensed_map, lmax=lmax)

# generate deflection potential using input
input_cldd = load_data.input_cldd(lmin, lmax).spectra()

if 1:
    phi_lm = fitsfunc.read_alm('./fullskyPhi_alm_00000.fits')
    phi_lm = phi_lm.astype(np.cdouble)
    cl_phi = sphtfunc.alm2cl(a)[0:lmax]
    cl_dd = cl_phi * t(ls)

if 1:
    plot_ps.plot(lmin, lmax, [input_cldd, cl_dd], ['1', '2'])
Beispiel #9
0
                                                  verbose=True,
                                                  phi_seed=phiSeed,
                                                  seed=cmbSeed)

        mapList = [uTquMap, lTquMap, pMap]

        mapNameList = ['fullskyUnlensedCMB', 'fullskyLensedCMB', 'fullskyPhi']

        if False:
            print(
                'temporarily doing a gaussian random field -- lensed = unlensed'
            )
            print('calling curvedsky.rand_map')
            uTquMap = curvedsky.rand_map((3, ) + shape,
                                         wcs,
                                         ps[1:, 1:, :],
                                         lmax=p['LMAX'],
                                         seed=iii * 100)

            mapList = [uTquMap]

            mapNameList = ['fullskyUnlensed']

        if p['doAberration']:
            unaberrated = lTquMap.copy()

            from pixell import aberration
            print('doing aberration')
            #This was Sigurd's old version
            # lTquMap = aberration.aberrate(lTquMap,
            #                               aberration.dir_equ,
Beispiel #10
0
# generate power spectrum for alpha
ell = np.arange(0, lmax + 1)
ps_alpha = A_CB * 1E-4 * 2 * np.pi / (ell * (ell + 1))
ps_alpha[0] = 0

shape, wcs = enmap.fullsky_geometry(pixel_size * utils.arcmin)

for sim_id in np.arange(core_start, core_end):
    print("Looking at set=%d sim_id=%d" % (set_id, sim_id))

    # check if simulation already exists
    postfix = "set%d_id%d.fits" % (set_id, sim_id)
    filename = "fullskyalpha_%s" % postfix
    filename = os.path.join(alpha_map_dir, filename)
    if force or not os.path.isfile(filename):
        # generate full sky rotation map
        seed = generate_seed(sim_id)
        print("Generating random alpha map...")
        alpha_map = curvedsky.rand_map((1, ) + shape,
                                       wcs,
                                       ps_alpha,
                                       lmax=lmax,
                                       seed=seed)
        # save alpha map
        print("Saving to disk...")
        print("Saving data: %s..." % filename)
        enmap.write_map(filename, alpha_map)
    else:
        pass