예제 #1
0
def get_theory_dicts_white_noise(beam_fwhm,
                                 noise_t,
                                 noise_p=None,
                                 lmax=9000,
                                 grad=True):
    ls = np.arange(lmax + 1)
    if noise_p is None: noise_p = np.sqrt(2.) * noise_t
    nells = {}
    nells['TT'] = (noise_t * np.pi / 180. / 60.)**2. / maps.gauss_beam(
        beam_fwhm, ls)**2.
    nells['EE'] = (noise_p * np.pi / 180. / 60.)**2. / maps.gauss_beam(
        beam_fwhm, ls)**2.
    nells['BB'] = (noise_p * np.pi / 180. / 60.)**2. / maps.gauss_beam(
        beam_fwhm, ls)**2.
    return get_theory_dicts(nells=nells, lmax=lmax, grad=grad)
예제 #2
0
 def get_maps(self, seed=None):
     # SKY
     fgs = []
     for i, comp in enumerate(self.components):
         fgs.append(self.fgens[comp].get_map(seed=(1, i, seed)))
     arrays = []
     for k, (beam, inhom,
             nsplit) in enumerate(zip(self.beams, self.inhoms,
                                      self.nsplits)):
         # SKY
         sky = 0.
         for i, comp in enumerate(self.components):
             sky += (fgs[i] * self.rdict[comp][i])
         kbeam = maps.gauss_beam(self.modlmap, beam)
         kbeam[self.modlmap < self.ellmin] = 0
         sky_convolved = maps.filter_map(sky, kbeam)
         # NOISE
         nmaps = []
         for j in range(nsplit):
             nmap = self.ngens[k].get_map(seed=(2, j, seed)) * nsplit
             nmaps.append(nmap.copy())
         nmaps = np.stack(nmaps)
         observed = enmap.enmap(sky_convolved + nmaps, self.wcs)
         arrays.append(observed.copy())
     return arrays
예제 #3
0
    def get_beam(self, ells, array_id=None):
        from orphics import maps

        season, array, freq = self._expand(array_id)
        if "150" in freq:
            fwhm = 1.4
        if "090" in freq:
            fwhm = 1.4 * 150.0 / 90.0
        return maps.gauss_beam(ells, fwhm)
예제 #4
0
def get_kbeam(qid, modlmap):
    if qid == 'p143':
        fwhm = 7.
    elif qid == 'p100':
        fwhm = 7. * (143. / 100.)
    elif qid in ['s16_01', 's16_02']:
        fwhm = 1.4
    elif qid in ['s16_03']:
        fwhm = 1.4 * (148. / 93.)
    return maps.gauss_beam(modlmap, fwhm)
예제 #5
0
def init_geometry(ishape,iwcs):
    modlmap = enmap.modlmap(ishape,iwcs)
    bin_edges = np.arange(args.kellmin,args.kellmax,args.dell)
    binner = stats.bin2D(modlmap,bin_edges)
    if args.beam<1e-5:
        kbeam = None
    else:
        kbeam = maps.gauss_beam(modlmap,args.beam)
    lmax = modlmap.max()
    ells = np.arange(2,lmax,1)
    wnoise_TT = ells*0.+(args.noise*(np.pi/180./60.))**2.
    wnoise_PP = 2.*wnoise_TT
    nT = modlmap*0.+(args.noise*(np.pi/180./60.))**2.
    nP = 2.*nT
    ncomp = 3 if pol else 1
    ps = np.zeros((ncomp,ncomp,ells.size))
    ps[0,0] = wnoise_TT
    if pol:
        ps[1,1] = wnoise_PP
        ps[2,2] = wnoise_PP
    oshape = (3,)+ishape if pol else ishape

    if not(args.flat) and args.noise_pad>1.e-5:
        # Pad noise sim geometry
        pad_width_deg = args.noise_pad
        pad_width = pad_width_deg * np.pi/180.
        res = maps.resolution(oshape[-2:],iwcs)
        pad_pixels = int(pad_width/res)
        template = enmap.zeros(oshape,iwcs)
        btemplate = enmap.pad(template,pad_pixels)
        bshape,bwcs = btemplate.shape,btemplate.wcs
        del template
        del btemplate
        ngen = maps.MapGen(bshape,bwcs,ps)
    else:
        ngen = maps.MapGen(oshape,iwcs,ps)
    
    tmask = maps.mask_kspace(ishape,iwcs,lmin=args.tellmin,lmax=args.tellmax)
    pmask = maps.mask_kspace(ishape,iwcs,lmin=args.pellmin,lmax=args.pellmax)
    kmask = maps.mask_kspace(ishape,iwcs,lmin=args.kellmin,lmax=args.kellmax)

    qest = lensing.qest(ishape,iwcs,theory,noise2d=nT,beam2d=kbeam,kmask=tmask,noise2d_P=nP,kmask_P=pmask,kmask_K=kmask,pol=pol,grad_cut=None,unlensed_equals_lensed=True)

    taper,w2 = maps.get_taper_deg(ishape,iwcs,taper_width_degrees = args.taper_width,pad_width_degrees = args.pad_width)
    fc = maps.FourierCalc(oshape,iwcs,iau=args.iau)

    
    purifier = maps.Purify(ishape,iwcs,taper) if args.purify else None

    
    return qest,ngen,kbeam,binner,taper,fc,purifier
예제 #6
0
def get_sim(cmb, task, expid):
    if expid == 'planck':
        nid = 1
        fwhm = pfwhm
        nlevel = pnlevel
    elif expid == 'act':
        nid = 2
        fwhm = afwhm
        nlevel = anlevel
    seed = (nid, task)
    npower = (nlevel * np.pi / 180. / 60.)**2.
    nmap = enmap.rand_map((1, ) + shape,
                          wcs,
                          np.ones(shape)[None, None] * npower,
                          seed=seed)
    return maps.filter_map(cmb, maps.gauss_beam(modlmap, fwhm)) + nmap
예제 #7
0
      def __init__(self,shape,wcs,theory,freqs,beams,noises,lknees,alphas,ellmins,ellmaxes):

          fgn = fg.fgNoises(cosmology.defaultConstants,ksz_file='/home/msyriac/repos/szar/input/ksz_BBPS.txt',
                    ksz_p_file='/home/msyriac/repos/szar/input/ksz_p_BBPS.txt',
                    tsz_cib_file='/home/msyriac/repos/szar/input/sz_x_cib_template.txt',
                    ksz_battaglia_test_csv=None,
                    tsz_battaglia_template_csv="/home/msyriac/repos/szar/input/sz_template_battaglia.csv",
                    rs_template="/home/msyriac/repos/szar/input/fiducial_scalCls_lensed_5_5.txt",
                    rsx_template="/home/msyriac/repos/szar/input/fiducial_scalCls_lensed_1_5.txt",
                    components=['tsz','cibp','cibc','radps'],lmax=20000)
        
          self.modlmap = enmap.modlmap(shape,wcs)
          modlmap = self.modlmap
          self.fgn = fgn
          lmax = self.modlmap.max()
          ells = np.arange(0,lmax,1)
          ps_cmb = theory.lCl('TT',modlmap).reshape((1,1,shape[-2],shape[-1]))
          self.ps_cmb = ps_cmb
          ps_y = fgn.tsz_template(ells).reshape((1,1,ells.size))*self.fgn.c['A_tsz']*2.*np.pi*np.nan_to_num(1./ells/(ells+1.))
          ps_cibp = (fgn.c['A_cibp'] * ((ells/fgn.c['ell0sec'])) ** 2.0 *2.*np.pi*np.nan_to_num(1./ells/(ells+1.))).reshape((1,1,ells.size))
          ps_cibc = (fgn.c['A_cibc'] * ((ells/fgn.c['ell0sec'])) ** (2.-fgn.c['n_cib']) *                   2.*np.pi*np.nan_to_num(1./ells/(ells+1.))).reshape((1,1,ells.size))
          ps_radps = (fgn.c['A_ps'] * ((ells/fgn.c['ell0sec'])) ** 2 *                   2.*np.pi*np.nan_to_num(1./ells/(ells+1.))).reshape((1,1,ells.size))
          self.cgen = maps.MapGen(shape[-2:],wcs,ps_cmb)
          self.tgen = maps.MapGen(shape[-2:],wcs,ps_y)
          self.cibpgen = maps.MapGen(shape[-2:],wcs,ps_cibp)
          self.cibcgen = maps.MapGen(shape[-2:],wcs,ps_cibc)
          self.radpsgen = maps.MapGen(shape[-2:],wcs,ps_radps)
          self.shape = shape ; self.wcs = wcs
          self.freqs = freqs
          self.kbeams = []
          self.ngens = []
          self.n2ds = []
          for ai,nu in enumerate(self.freqs):
              self.kbeams.append(maps.gauss_beam(fwhm=beams[ai],ell=self.modlmap))
              n2d = cosmology.noise_func(self.modlmap,0,noises[ai],lknee=lknees[ai],alpha=alphas[ai],dimensionless=False,TCMB=2.7255e6)
              n2d[modlmap<ellmins[ai]] = 0
              n2d[modlmap>ellmaxes[ai]] = 0
              n2dmod = n2d.copy()
              n2dmod[modlmap>ellmaxes[ai]] =  1e90
              n2dmod[modlmap<ellmins[ai]] =  1e90
              self.n2ds.append(n2dmod.copy())
              ps_noise = n2d.reshape((1,1,shape[-2],shape[-1]))
              self.ngens.append(maps.MapGen(shape[-2:],wcs,ps_noise))
          self.ellmins = ellmins
          self.ellmaxes = ellmaxes
예제 #8
0
    def cl_noise(self, ells, patch, dm, season=None, array=None):
        # beam
        if dm == 'planck':
            import soapack.interfaces as sints
            dmodel = sints.PlanckHybrid()
            lbeam = dmodel.get_beam(ells, array=array)
            lknee = 0
            alpha = 1
            rms = self.planck_rms[array]
        elif dm == 'act':
            afreq = get_act_freq(array)
            fwhm = 1.4 * 150. / afreq
            lbeam = maps.gauss_beam(ells, fwhm)
            lknee = 2500
            alpha = -4
            a, f = array.split('_')
            rms = self.act_rms(season, patch, a, f)

        from tilec.covtools import rednoise
        return rednoise(ells, rms, lknee=lknee, alpha=alpha) / lbeam**2.
예제 #9
0
# io.hplot(rms,colorbar=True)

pmap = enmap.pixsizemap(shape,wcs)

ivar = maps.ivar(shape,wcs,rms,ipsizemap=pmap)
# io.hplot(ivar,colorbar=True)

my_tasks = range(nsims)

theory = cosmology.default_theory()
cov = theory.lCl('TT',modlmap)
mgen = maps.MapGen((1,)+shape,wcs,cov=cov[None,None])

fwhm = 1.5
wnoise = 40.
kbeam = maps.gauss_beam(modlmap,fwhm)

feed_dict = {}
lmin = 200
lmax = 3000
Lmin = 40
Lmax = 3000
xmask = maps.mask_kspace(shape,wcs,lmin=lmin,lmax=lmax)
ymask = xmask
kmask = maps.mask_kspace(shape,wcs,lmin=Lmin,lmax=Lmax)
feed_dict['uC_T_T'] = cov
feed_dict['tC_T_T'] = cov + (wnoise*np.pi/180/60)**2 / kbeam**2
qe = symlens.QE(shape,wcs,feed_dict,'hu_ok','TT',xmask=xmask,ymask=ymask,kmask=kmask)

s = stats.Stats()
예제 #10
0
# Tiny Geometry
bshape, bwcs = maps.rect_geometry(width_arcmin=barc,px_res_arcmin=bpix,pol=False)
bmodlmap = enmap.modlmap(bshape,bwcs)
bmodrmap = enmap.modrmap(bshape,bwcs)





# Noise model
noise_uK_rad = args.noise*np.pi/180./60.
normfact = np.sqrt(np.prod(enmap.pixsize(bshape,bwcs)))
noise_uK_pixel = noise_uK_rad/normfact
Ncov = np.diag([(noise_uK_pixel)**2.]*np.prod(bshape))

kbeam = maps.gauss_beam(bbeam,bmodlmap)

        



# Theory
theory_file_root = "../alhazen/data/Aug6_highAcc_CDM"
cc = counts.ClusterCosmology(skipCls=True)
theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False,
                                             useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False)


# Simulate
lmax = int(bmodlmap.max()+1)
ells = np.arange(0,lmax,1)
예제 #11
0
def reconvolve(x, ybname, fwhm):
    if not (do_reconvolve): return x
    ls, bells = np.loadtxt(ybname, unpack=True)
    beam_rat = maps.gauss_beam(modlmap, fwhm) / maps.interp(ls, bells)(modlmap)
    beam_rat[~np.isfinite(beam_rat)] = 0
    return maps.filter_map(x, beam_rat)
예제 #12
0
def build_and_save_ilc(arrays,region,version,cov_version,beam_version,
                       solutions,beams,chunk_size,
                       effective_freq,overwrite,maxval,unsanitized_beam=False,do_weights=False,
                       pa1_shift = None,
                       pa2_shift = None,
                       pa3_150_shift = None,
                       pa3_090_shift = None,
                       no_act_color_correction=False, ccor_exp = -1, 
                       isotropize=False, isotropize_width=20):

    print("Chunk size is ", chunk_size*64./8./1024./1024./1024., " GB.")
    def warn(): print("WARNING: no bandpass file found. Assuming array ",dm.c['id']," has no response to CMB, tSZ and CIB.")
    aspecs = tutils.ASpecs().get_specs
    bandpasses = not(effective_freq)
    savedir = tutils.get_save_path(version,region)
    covdir = tutils.get_save_path(cov_version,region)
    assert os.path.exists(covdir)
    if not(overwrite):
        assert not(os.path.exists(savedir)), \
       "This version already exists on disk. Please use a different version identifier."
    try: os.makedirs(savedir)
    except:
        if overwrite: pass
        else: raise


    mask = enmap.read_map(covdir+"tilec_mask.fits")
    shape,wcs = mask.shape,mask.wcs
    Ny,Nx = shape
    modlmap = enmap.modlmap(shape,wcs)



    arrays = arrays.split(',')
    narrays = len(arrays)
    kcoadds = []
    kbeams = []
    bps = []
    names = []
    lmins = []
    lmaxs = []
    shifts = []
    cfreqs = []
    lbeams = []
    ells = np.arange(0,modlmap.max())
    for i,qid in enumerate(arrays):
        dm = sints.models[sints.arrays(qid,'data_model')](region=mask,calibrated=True)
        lmin,lmax,hybrid,radial,friend,cfreq,fgroup,wrfit = aspecs(qid)
        cfreqs.append(cfreq)
        lmins.append(lmin)
        lmaxs.append(lmax)
        names.append(qid)
        if dm.name=='act_mr3':
            season,array1,array2 = sints.arrays(qid,'season'),sints.arrays(qid,'array'),sints.arrays(qid,'freq')
            array = '_'.join([array1,array2])
        elif dm.name=='planck_hybrid':
            season,patch,array = None,None,sints.arrays(qid,'freq')
        else:
            raise ValueError
        kcoadd_name = covdir + "kcoadd_%s.npy" % qid
        kmask = maps.mask_kspace(shape,wcs,lmin=lmin,lmax=lmax)
        kcoadd = enmap.enmap(np.load(kcoadd_name),wcs)
        dtype = kcoadd.dtype
        kcoadds.append(kcoadd.copy()*kmask)
        kbeam = tutils.get_kbeam(qid,modlmap,sanitize=not(unsanitized_beam),version=beam_version,planck_pixwin=True)
        if dm.name=='act_mr3':
            lbeam = tutils.get_kbeam(qid,ells,sanitize=not(unsanitized_beam),version=beam_version,planck_pixwin=False) # note no pixwin but doesnt matter since no ccorr for planck
        elif dm.name=='planck_hybrid':
            lbeam = None
        else:
            raise ValueError
        lbeams.append(lbeam)
        kbeams.append(kbeam.copy())
        if bandpasses:
            try: 
                fname = dm.get_bandpass_file_name(array) 
                bps.append("data/"+fname)
                if (pa1_shift is not None) and 'PA1' in fname:
                    shifts.append(pa1_shift)
                elif (pa2_shift is not None) and 'PA2' in fname:
                    shifts.append(pa2_shift)
                elif (pa3_150_shift is not None) and ('PA3' in fname) and ('150' in fname):
                    shifts.append(pa3_150_shift)
                elif (pa3_090_shift is not None) and ('PA3' in fname) and ('090' in fname):
                    shifts.append(pa3_90_shift)
                else:
                    shifts.append(0)

            except:
                warn()
                bps.append(None)
        else:
            try: bps.append(cfreq)
            except:
                warn()
                bps.append(None)

    kcoadds = enmap.enmap(np.stack(kcoadds),wcs)



    # Read Covmat
    cov = maps.SymMat(narrays,shape[-2:])
    for aindex1 in range(narrays):
        for aindex2 in range(aindex1,narrays):
            icov = enmap.enmap(np.load(covdir+"tilec_hybrid_covariance_%s_%s.npy" % (names[aindex1],names[aindex2])),wcs)
            if isotropize:
                bin_edges = np.append([0.],np.arange(min(lmins),modlmap.max(),isotropize_width))
                binner = stats.bin2D(modlmap,bin_edges)
                ls,c1d = binner.bin(icov)
                icov = maps.interp(ls,c1d)(modlmap)
                
            if aindex1==aindex2: 
                icov[modlmap<lmins[aindex1]] = maxval
                icov[modlmap>lmaxs[aindex1]] = maxval
            cov[aindex1,aindex2] = icov
    cov.data = enmap.enmap(cov.data,wcs,copy=False)
    covfunc = lambda sel: cov.to_array(sel,flatten=True)

    assert cov.data.shape[0]==((narrays*(narrays+1))/2) # FIXME: generalize
    assert np.all(np.isfinite(cov.data))

    # Make responses
    responses = {}
    for comp in ['tSZ','CMB','CIB']:
        if bandpasses:
            if no_act_color_correction:
                responses[comp] = tfg.get_mix_bandpassed(bps, comp, bandpass_shifts=shifts)
            else:
                responses[comp] = tfg.get_mix_bandpassed(bps, comp, bandpass_shifts=shifts,
                                                         ccor_cen_nus=cfreqs, ccor_beams=lbeams, 
                                                         ccor_exps = [ccor_exp] * narrays)
        else:
            responses[comp] = tfg.get_mix(bps, comp)

    ilcgen = ilc.chunked_ilc(modlmap,np.stack(kbeams),covfunc,chunk_size,responses=responses,invert=True)

    # Initialize containers
    solutions = solutions.split(',')
    data = {}
    kcoadds = kcoadds.reshape((narrays,Ny*Nx))
    for solution in solutions:
        data[solution] = {}
        comps = solution.split('-')
        data[solution]['comps'] = comps
        if len(comps)<=2: 
            data[solution]['noise'] = enmap.zeros((Ny*Nx),wcs)
        if len(comps)==2: 
            data[solution]['cnoise'] = enmap.zeros((Ny*Nx),wcs)
        data[solution]['kmap'] = enmap.zeros((Ny*Nx),wcs,dtype=dtype) # FIXME: reduce dtype?
        if do_weights and len(comps)<=2:
            for qid in arrays:
                data[solution]['weight_%s' % qid] = enmap.zeros((Ny*Nx),wcs)
            

    for chunknum,(hilc,selchunk) in enumerate(ilcgen):
        print("ILC on chunk ", chunknum+1, " / ",int(modlmap.size/chunk_size)+1," ...")
        for solution in solutions:
            comps = data[solution]['comps']
            if len(comps)==1: # GENERALIZE
                data[solution]['noise'][selchunk] = hilc.standard_noise(comps[0])
                if do_weights: weight = hilc.standard_weight(comps[0])
                data[solution]['kmap'][selchunk] = hilc.standard_map(kcoadds[...,selchunk],comps[0])
            elif len(comps)==2:
                data[solution]['noise'][selchunk] = hilc.constrained_noise(comps[0],comps[1])
                data[solution]['cnoise'][selchunk] = hilc.cross_noise(comps[0],comps[1])
                ret = hilc.constrained_map(kcoadds[...,selchunk],comps[0],comps[1],return_weight=do_weights)
                if do_weights:
                    data[solution]['kmap'][selchunk],weight = ret
                else:
                    data[solution]['kmap'][selchunk] = ret

            elif len(comps)>2:
                data[solution]['kmap'][selchunk] = np.nan_to_num(hilc.multi_constrained_map(kcoadds[...,selchunk],comps[0],*comps[1:]))

            if len(comps)<=2 and do_weights:
                for qind,qid in enumerate(arrays):
                    data[solution]['weight_%s' % qid][selchunk] = weight[qind]


    del ilcgen,cov

    # Reshape into maps
    name_map = {'CMB':'cmb','tSZ':'comptony','CIB':'cib'}
    beams = beams.split(',')
    for solution,beam in zip(solutions,beams):
        comps = "tilec_single_tile_"+region+"_"
        comps = comps + name_map[data[solution]['comps'][0]]+"_"
        if len(data[solution]['comps'])>1: comps = comps + "deprojects_"+ '_'.join([name_map[x] for x in data[solution]['comps'][1:]]) + "_"
        comps = comps + version

        if do_weights and len(data[solution]['comps'])<=2:
            for qind,qid in enumerate(arrays):
                enmap.write_map("%s/%s_%s_weight.fits" % (savedir,comps,qid), enmap.enmap(data[solution]['weight_%s' % qid].reshape((Ny,Nx)),wcs))
            


        try:
            noise = enmap.enmap(data[solution]['noise'].reshape((Ny,Nx)),wcs)
            enmap.write_map("%s/%s_noise.fits" % (savedir,comps),noise)
        except: pass
        try:
            cnoise = enmap.enmap(data[solution]['cnoise'].reshape((Ny,Nx)),wcs)
            enmap.write_map("%s/%s_cross_noise.fits" % (savedir,comps),cnoise)
        except: pass

        ells = np.arange(0,modlmap.max(),1)
        try:
            fbeam = float(beam)
            kbeam = maps.gauss_beam(modlmap,fbeam)
            lbeam = maps.gauss_beam(ells,fbeam)
        except:
            qid = beam
            bfunc = lambda x: tutils.get_kbeam(qid,x,version=beam_version,sanitize=not(unsanitized_beam),planck_pixwin=False)
            kbeam = bfunc(modlmap)
            lbeam = bfunc(ells)

        kmap = enmap.enmap(data[solution]['kmap'].reshape((Ny,Nx)),wcs)
        smap = enmap.ifft(kbeam*kmap,normalize='phys').real
        enmap.write_map("%s/%s.fits" % (savedir,comps),smap)
        io.save_cols("%s/%s_beam.txt" % (savedir,comps),(ells,lbeam),header="ell beam")


    enmap.write_map(savedir+"/tilec_mask.fits",mask)
예제 #13
0
shape, iwcs = enmap.fullsky_geometry(res=np.deg2rad(res / 60.), proj="car")
wcs = enmap.zeros(shape, iwcs)[..., ::-1].wcs
mlmax = max(args.lmaxt, args.lmaxp) + 500

# Sim location
try:
    if args.sim_location is not None: raise
    from soapack import interfaces as sints
    sim_location = sints.dconfig['actsims']['signal_path']
except:
    sim_location = args.sim_location
    assert sim_location is not None

# Beam and noise
ells = np.arange(mlmax)
lbeam = maps.gauss_beam(ells, args.beam)
ps_noise = np.zeros((3, 3, ells.size))
ps_noise[0, 0] = (args.noise * np.pi / 180. / 60.)**2.
ps_noise[1, 1] = (args.noise * np.pi / 180. / 60.)**2. * 2.
ps_noise[2, 2] = (args.noise * np.pi / 180. / 60.)**2. * 2.

# MPI
comm = mpi.MPI.COMM_WORLD
rank = comm.Get_rank()
numcores = comm.Get_size()
Nsims = args.nsims
num_each, each_tasks = mpi.mpi_distribute(Nsims, numcores)
if rank == 0: print("At most ", max(num_each), " tasks...")
my_tasks = each_tasks[rank]
s = stats.Stats(comm)
예제 #14
0
deg = 15.
shape,wcs = maps.rect_geometry(width_deg=deg,px_res_arcmin=1.0)
modlmap = enmap.modlmap(shape,wcs)
modrmap = enmap.modrmap(shape,wcs)
lmax = modlmap.max()
ells = np.arange(0,lmax,1)
ps = cc.theory.lCl('TT',ells).reshape((1,1,ells.size))

mgen = maps.MapGen(shape,wcs,ps)




fwhm = 5.
kbeam = maps.gauss_beam(modlmap,fwhm)
imap = mgen.get_map()

bmap2 = maps.convolve_gaussian(imap.copy(),fwhm=fwhm,nsigma=5.0)
print(bmap2.shape)

bmap = maps.filter_map(imap.copy(),kbeam)

taper,w2 = maps.get_taper(shape)

io.plot_img(imap*taper,io.dout_dir+"bmap0.png",high_res=True)
io.plot_img(bmap*taper,io.dout_dir+"bmap1.png",high_res=True)
io.plot_img(bmap2*taper,io.dout_dir+"bmap2.png",high_res=True)

bin_edges = np.arange(200,3000,100)
binner = stats.bin2D(modlmap,bin_edges)
예제 #15
0
if rank == 0:
    print(bshape, bwcs)
    print(shape, wcs)
    print(oshape, owcs)

# Binning
bin_edges = np.arange(0., 20.0, bpix * 2)
binner = stats.bin2D(omodrmap * 60. * 180. / np.pi, bin_edges)

# Noise model
noise_uK_rad = args.noise * np.pi / 180. / 60.
normfact = np.sqrt(np.prod(enmap.pixsize(bshape, bwcs)))
noise_uK_pixel = noise_uK_rad / normfact
Ncov = np.diag([(noise_uK_pixel)**2.] * np.prod(bshape))

kbeam = maps.gauss_beam(args.beam, modlmap)
okbeam = maps.gauss_beam(args.beam, omodlmap)

if True:  #True:
    # Load covs
    bkamps = np.loadtxt(GridName + "/amps.txt", unpack=True)  #[:1] # !!!
    if rank == 0: print("Amplitudes: ", bkamps)
    cov_file = lambda x: GridName + "/cov_" + str(x) + ".npy"
    cinvs = []
    logdets = []
    for k in range(len(bkamps)):
        if rank == 0:

            print("Loading cov", k, " / ", len(bkamps), "...")
            cov = np.load(cov_file(k))
예제 #16
0
            do_radial = True
        else:
            do_radial = False
        # dncov,_ = tilec.noise_average(ncov,radial_fit=do_radial) if ((aindex1==aindex2) or is90150(aindex1,aindex2)) else (0.,None)
        dncov, _ = tilec.noise_average(ncov, radial_fit=do_radial) if (
            aindex1 == aindex2) else (0., None)  # ignore 90 / 150

        if isplanck(aindex1) and isplanck(aindex2):
            lmin = maps.minimum_ell(shape, wcs)
        else:
            lmin = 300

        sel = np.logical_or(modlmap < lmin, modlmap > lmax)
        ifwhm, jfwhm = get_beams(aindex1, aindex2)
        dncov /= np.nan_to_num(
            maps.gauss_beam(modlmap, ifwhm) * maps.gauss_beam(modlmap, jfwhm))
        dscov /= np.nan_to_num(
            maps.gauss_beam(modlmap, ifwhm) * maps.gauss_beam(modlmap, jfwhm))
        # dncov[sel] = 1e90 #np.inf # inf gives invertible matrix but nonsensical output, 1e90 gives noninvertible, but with eigpow sensible
        # dscov[sel] = 1e90 #np.inf

        # io.plot_img((np.fft.fftshift(ncov)),"tuncov%d%d.png"%(aindex1,aindex2),aspect='auto')
        # io.plot_img(np.log10(np.fft.fftshift(scov+ncov)),"udsncov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])
        # io.plot_img(np.log10(np.fft.fftshift(ncov)),"uncov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])
        # io.plot_img(np.log10(np.fft.fftshift(scov)),"usncov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])

        # io.plot_img(np.log10(np.fft.fftshift(dscov+dncov)),"dsncov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])
        # io.plot_img(np.log10(np.fft.fftshift(dncov)),"dncov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])
        # io.plot_img(np.log10(np.fft.fftshift(dscov)),"dsncov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])
        # io.plot_img(np.log10(np.fft.fftshift(ncov/dncov)),"rcov%d%d.png"%(aindex1,aindex2),aspect='auto',lim=[-5,1])
예제 #17
0
                                              lmax=6000,
                                              lensed=True,
                                              pol=False)
fc = maps.FourierCalc(shape, wcs)

nsims = 10

brealfile = '/gpfs01/astro/workarea/msyriac/data/act/beams/171206/beam_profile_171206_pa1_150GHz_3_310_s15_map.txt'
bfourierfile = '/gpfs01/astro/workarea/msyriac/data/act/beams/171206/beam_tform_171206_pa1_150GHz_3_310_s15_map.txt'

rs, brs = np.loadtxt(brealfile, usecols=[0, 1], unpack=True)
rs *= np.pi / 180.
ls, bells = np.loadtxt(bfourierfile, usecols=[0, 1], unpack=True)

fwhm_test = 1.4
btest = maps.gauss_beam(ls, fwhm_test)

# pl = io.Plotter()
# pl.add(ls,bells)
# pl.add(ls,btest,ls="--")
# pl.done(io.dout_dir+'kbeam.png')

btest = maps.gauss_beam_real(rs, fwhm_test)

# pl = io.Plotter()
# pl.add(rs,brs*rs)
# pl.add(rs,btest*rs,ls="--")
# pl.done(io.dout_dir+'rbeam.png')

modrmap = enmap.modrmap(shape, wcs)
kbeam = maps.interp(ls, bells)(modlmap)
예제 #18
0
        # comps = comps + name_map[data[solution]['comps'][0]]+"_"
        # if len(data[solution]['comps'])>1: comps = comps + "deprojects_"+ '_'.join([name_map[x] for x in data[solution]['comps'][1:]]) + "_"
        # comps = comps + version
        # try:
        #     noise = enmap.enmap(data[solution]['noise'].reshape((Ny,Nx)),ewcs)
        #     enmap.write_map("%s/%s_noise.fits" % (savedir,comps),noise)
        # except: pass
        # try:
        #     cnoise = enmap.enmap(data[solution]['cnoise'].reshape((Ny,Nx)),ewcs)
        #     enmap.write_map("%s/%s_cross_noise.fits" % (savedir,comps),noise)
        # except: pass

        ells = np.arange(0, modlmap.max(), 1)
        try:
            fbeam = float(beam)
            kbeam = maps.gauss_beam(modlmap, fbeam)
            lbeam = maps.gauss_beam(ells, fbeam)
        except:
            raise
            # array = beam
            # ainfo = gconfig[array]
            # array_id = ainfo['id']
            # dm = sints.models[ainfo['data_model']](region=mask)
            # if dm.name=='act_mr3':
            #     season,array1,array2 = array_id.split('_')
            #     narray = array1 + "_" + array2
            #     patch = region
            # elif dm.name=='planck_hybrid':
            #     season,patch,narray = None,None,array_id
            # bfunc = lambda x: dm.get_beam(x,season=season,patch=patch,array=narray,version=beam_version)
            # kbeam = bfunc(modlmap)
예제 #19
0
noise_uK_rad = args.noise * np.pi / 180. / 60.
normfact = np.sqrt(np.prod(enmap.pixsize(shape, wcs)))
noise_uK_pixel = noise_uK_rad / normfact
Ncov = np.diag([(noise_uK_pixel)**2.] * np.prod(shape))

# Unlensed signal

power2d = theory.uCl('TT', bmodlmap)
bfcov = maps.diagonal_cov(power2d)
sny, snx = shape
ny, nx = bshape
Ucov = maps.pixcov(bshape, bwcs, bfcov)
Ucov = Ucov.reshape(np.prod(bshape), np.prod(bshape))

# Noise model
kbeam = maps.gauss_beam(args.beam, bmodlmap)

# Lens template
lens_order = 5
posmap = enmap.posmap(bshape, bwcs)

# Lens grid
amin = 0.18
amax = 0.22
num_amps = 10
kamps = np.linspace(amin, amax, num_amps)

cinvs = []
logdets = []
for k, kamp in enumerate(kamps):
예제 #20
0
# ahm1 = hp.map2alm(hm1)
# ahm2 = hp.map2alm(hm2)

bin_edges = np.append(np.arange(2,2500,80),np.arange(2500+400,6000,400))
binner = stats.bin1D(bin_edges)

cls0 = hp.alm2cl(afull,afull) / fsky 
cls1 = hp.alm2cl(aring1,aring2) / fsky 
# cls2 = hp.alm2cl(ahm1,ahm2) / fsky

pwin = hp.pixwin(hp.npix2nside(ring1.size))
print(pwin.shape,cls1.shape)

ls = np.arange(0,len(cls1),1)

cls0 = cls0 / maps.gauss_beam(ls,beam)**2. / pwin**2
cls1 = cls1 / maps.gauss_beam(ls,beam)**2. / pwin**2
# cls2 = cls2 / maps.gauss_beam(ls,beam)**2. / pwin**2

lss,cls0 = binner.binned(ls,cls0)
lss,cls1 = binner.binned(ls,cls1)
# lss,cls2 = binner.binned(ls,cls2)
# zls,clsz = binner.binned(zls,ztt)

ells,cls = np.loadtxt('theory_150.txt',unpack=True)

pl = io.Plotter(xyscale='linlog',xlabel='l',ylabel='C')
pl.add(ells,cls,color='green',ls='--')
# pl.add(zls,clsz,ls=':',alpha=0.4,label='zack')
pl.add(lss,cls0,ls=':',alpha=0.4,label='full')
pl.add(lss,cls1,alpha=0.4,label='ring')
예제 #21
0
lsl,lnls = np.loadtxt("/home/msyriac/repos/halofg/data/lgmca_nls.txt",unpack=True)
snls = snls[lss<3000]
lss = lss[lss<3000]
lnls = lnls[lsl<3000]
lsl = lsl[lsl<3000]


pl = io.Plotter(yscale='log',xlabel='l',ylabel='D')
pl.add(cents,cmb*cents**2.,lw=2,color='k')
pl.add_err(cents,scxcmb*cents**2.,yerr=escxcmb*cents**2,lw=1,label="ilc",marker="o",color="C0")
pl.add_err(cents,ccxcmb*cents**2.,yerr=eccxcmb*cents**2,lw=1,label="cilc",marker="o",color="C1")
pl.add(cents,sc*cents**2.,lw=1,ls="--",color="C0")
pl.add(cents,cc*cents**2.,lw=1,ls="--",color="C1")
pl.add(cents,(sc_noise-tt)*cents**2.,lw=1,ls="-.",color="C0")
pl.add(cents,(cc_noise-tt)*cents**2.,lw=1,ls="-.",color="C1")
pl.add(lss,(snls)*lss**2./maps.gauss_beam(lss,5.)**2.,lw=1,ls="-.",color="C2",label='smica',alpha=0.5)
pl.add(lsl,(lnls)*lsl**2./maps.gauss_beam(lss,5.)**2.,lw=1,ls="-.",color="C3",label='lgmca',alpha=0.5)
pl._ax.set_ylim(1e1,3e4)
pl.legend(loc='lower center')
pl.done(save_root+"cmb.png")


pl = io.Plotter(yscale='log',xlabel='l',ylabel='D')
pl.add(cents,y*cents**2.,lw=2,color='k')
pl.add_err(cents,syxy*cents**2.,yerr=esyxy*cents**2,lw=1,label="ilc",marker="o",color="C0")
pl.add_err(cents,cyxy*cents**2.,yerr=ecyxy*cents**2,lw=1,label="cilc",marker="o",color="C1")
pl.add(cents,sy*cents**2.,lw=1,ls="--",color="C0")
pl.add(cents,cy*cents**2.,lw=1,ls="--",color="C1")
pl.add(cents,sy_noise*cents**2.,lw=1,ls="-.",color="C0")
pl.add(cents,cy_noise*cents**2.,lw=1,ls="-.",color="C1")
pl._ax.set_ylim(2e0,2e4)
예제 #22
0
from pixell import enmap, reproject
import numpy as np
import os, sys
import healpy as hp
from soapack import interfaces as sints
import tilec.fg as tfg
import tilec.utils as tutils
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
                               AutoMinorLocator)

cversion = 'joint'
redo = True
ppath = "/scratch/r/rbond/msyriac/data/planck/data/pr2/"
fwhm = 10.
invbeam = lambda x: np.piecewise(x, [x < 1, x >= 1], [
    lambda y: y * 0, lambda y: 1. / maps.gauss_beam(y, fwhm)
])
#invbeam = lambda x: x*0 + 1

dfwhm = 0.0001

region_map = {'boss': 'BN', 'deep56': 'D56'}

pl = io.Plotter(
    xyscale='linlog',
    xlabel='$\\ell$',
    ylabel='$\\ell^2 C^{yy,\\rm{tot}}_{\\ell}/2\\pi~\\mathrm{(dimensionless)}$',
    scalefn=lambda x: x**2. / 2. / np.pi,
    ftsize=16,
    labsize=14)
for col, region in zip(['red', 'blue'], ['deep56', 'boss']):
예제 #23
0
plt.rcParams["mathtext.fontset"] = "cm"
from orphics import maps,io,cosmology,stats
from pixell import enmap,reproject
import numpy as np
import os,sys
import healpy as hp
from soapack import interfaces as sints
import tilec.fg as tfg
import tilec.utils as tutils
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
                               AutoMinorLocator)

cversion = 'joint'
redo = True
fwhm = 5.
invbeam = lambda x: np.piecewise(x, [x<1,x>=1], [lambda y: y*0 , lambda y: 1./maps.gauss_beam(y,fwhm)])

dfwhm = 0.0001

region_map = {'boss':'BN','deep56':'D56'}

#for method,methodp in zip(['_deprojects_comptony'],['nosz']):
for method,methodp in zip(['','_deprojects_comptony'],['sz','nosz']):
    pl = io.Plotter(xyscale='linlog',xlabel='$\\ell$',
                    ylabel='$\\ell^2 C^{\\rm{CMB},\\rm{tot}}_{\\ell}/2\\pi (\\mu \\rm{K})^2 $',
                    scalefn = lambda x: x**2./2./np.pi,ftsize=16,labsize=14)
    for col,region in zip(['red','blue'],['deep56','boss']):

        if redo:
            mask = sints.get_act_mr3_crosslinked_mask(region)
            shape,wcs = mask.shape,mask.wcs
예제 #24
0
            l_stamp.wcs,
            taper_percent=tap_per,
            pad_percent=pad_per,
            weight=None,
        )
        taper = taper[0]

        # get geometry and Fourier info
        shape = kstamp.shape
        wcs = kstamp.wcs
        modlmap = enmap.modlmap(shape, wcs)

        assert wcsutils.equal(kstamp.wcs, lstamp.wcs)

        # evaluate the 2D Gaussian beam on an isotropic Fourier grid
        beam2d = maps.gauss_beam(modlmap, fwhm)

        # build Fourier space masks for lensing reconstruction
        xmask = maps.mask_kspace(shape, wcs, lmin=xlmin, lmax=xlmax)
        ymask = maps.mask_kspace(shape,
                                 wcs,
                                 lmin=ylmin,
                                 lmax=ylmax,
                                 lxcut=ylcut,
                                 lycut=ylcut)
        kmask = maps.mask_kspace(shape, wcs, lmin=klmin, lmax=klmax)

        # get theory spectrum and build interpolated 2D Fourier CMB from theory and maps
        theory = cosmology.default_theory()
        ucltt2d = theory.lCl('TT', modlmap)
예제 #25
0
theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False,
                                                    useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False)

# Geometry
shape, wcs = maps.rect_geometry(width_arcmin=args.arc,px_res_arcmin=args.pix,pol=False)
modlmap = enmap.modlmap(shape,wcs)
modrmap = enmap.modrmap(shape,wcs)

# Binning
bin_edges = np.arange(0.,20.0,args.pix*2)
binner = stats.bin2D(modrmap*60.*180./np.pi,bin_edges)

# Noise model
noise_uK_rad = args.noise*np.pi/180./60.
normfact = np.sqrt(np.prod(enmap.pixsize(shape,wcs)))
kbeam = maps.gauss_beam(args.beam,modlmap)


# Simulate
lmax = int(modlmap.max()+1)
ells = np.arange(0,lmax,1)
ps = theory.uCl('TT',ells).reshape((1,1,lmax))
~ps_noise = np.array([(noise_uK_rad)**2.]*ells.size).reshape((1,1,ells.size))
mg = maps.MapGen(shape,wcs,ps)
ng = maps.MapGen(shape,wcs,ps_noise)
kamp_true = args.Amp
kappa = lensing.nfw_kappa(kamp_true*1e15,modrmap,cc,overdensity=200.,critical=True,atClusterZ=True)
phi,_ = lensing.kappa_to_phi(kappa,modlmap,return_fphi=True)
grad_phi = enmap.grad(phi)
posmap = enmap.posmap(shape,wcs)
pos = posmap + grad_phi
예제 #26
0
        pl.add(nu_ghz,trans/trans.max())
        bcent = cfreq
        bsig = 0.15 * bcent
        trans = np.exp(-(nu_ghz-bcent)**2./2./bsig**2.)
        pl.add(nu_ghz,trans/trans.max())
        pl.done("band_%s.png" % qid)
    

    

    if gauss_beam:
        if 'p' in qid:
            fwhm = dm.fwhms[array]
        else:
            fwhm = 1.4 * (150./cfreq)
        lbeam = maps.gauss_beam(ells,fwhm)
    else:
        lbeam = tutils.get_kbeam(qid,ells,sanitize=False,planck_pixwin=False) 

    with bench.show("beamint"):
        fbnus = maps.interp(ells,lbeam[None,:],fill_value=(lbeam[0],lbeam[-1]))
        bnus = fbnus((cfreq/nu_ghz)*ells[:,None])[0].swapaxes(0,1)
        bnus = bnus / bnus[:,:1]

        pl = io.Plotter(xlabel='l',ylabel='b')
        for i in range(bnus.shape[0]):

            if trans[i]>1e-1: pl.add(ells,bnus[i]/lbeam)
        pl.hline(y=1)
        pl._ax.set_ylim(0.8,1.2)
        pl.done("abeams_%s.png" % qid)
예제 #27
0
Tcmb = 2.726e6  # CMB temperature
lmax = 2048  # maximum multipole of output normalization
rlmin = 500
rlmax = 2048  # reconstruction multipole range
beam = 1.5
wnoise = 6.
ell = np.arange(lmax + 1)


def gauss_beam(ell, fwhm):
    tht_fwhm = np.deg2rad(fwhm / 60.)
    return np.exp(-(tht_fwhm**2.) * (ell**2.) / (16. * np.log(2.)))


bfact = maps.gauss_beam(beam, ell)**2.
nells = (wnoise * np.pi / 180 / 60)**2. / (Tcmb**2 * np.ones(len(ell)) * bfact)
nellsp = 2 * nells
# load unlensed and lensed Cls

lcl = basic.aps.read_cambcls(
    '../data/cosmo2017_10K_acc3_lensedCls.dat', 2, lmax, 4, bb=True) / Tcmb**2
QDO = [True, True, True, True, True, False]

bins = np.arange(0, lmax + 1)
noise = np.array([nells, nellsp, nellsp, nellsp])
ocl = lcl + noise

#normalization
Ag, Ac, Wg, Wc = cs.norm_lens.qall(QDO, lmax, rlmin, rlmax, lcl, ocl)
예제 #28
0
                                             unlensedEqualsLensed=False,
                                             useTotal=False,
                                             TCMB=2.7255e6,
                                             lpad=9000,
                                             get_dimensionless=dimensionless)
shape, wcs = maps.rect_geometry(width_arcmin=arc, px_res_arcmin=px, pol=False)
print(shape)
lmax = 8000
ells = np.arange(0, lmax, 1)
ps = theory.uCl('TT', ells).reshape((1, 1, lmax))
#ps = cosmology.enmap_power_from_orphics_theory(theory,lmax,lensed=False,dimensionless=dimensionless,orphics_dimensionless=dimensionless)
#Ucov = np.load("scov.npy")

modlmap = enmap.modlmap(shape, wcs)
fwhm = 1.
kbeam = maps.gauss_beam(fwhm, modlmap)
power2d = theory.uCl('TT', modlmap)
fcov = maps.diagonal_cov(power2d)
# io.plot_img(fcov.reshape(np.prod(shape),np.prod(shape)))
Ucov = maps.pixcov(shape, wcs, fcov).reshape(np.prod(shape),
                                             np.prod(shape))  #+ 6000
#io.plot_img(Ucov,"theorypcov.png")
#io.plot_img(np.random.multivariate_normal(np.zeros(np.prod(shape)),Ucov).reshape(shape[0],shape[1]) )

# Ucov = maps.pixcov_sim(shape,wcs,ps,Nsims=10000,mean_sub=False,seed=1)
# io.plot_img(Ucov,"simpcov.png")

# # io.plot_img(np.random.multivariate_normal(np.zeros(np.prod(shape)),Ucov).reshape(shape[0],shape[1]) )
#sys.exit()
# Ucov = maps.pixcov_sim(shape,wcs,ps,Nsims=10000,mean_sub=mean_sub,seed=1)
예제 #29
0
    lymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=6000)
    estimator = 'hdv'
else:
    xmask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    ymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    lxmask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    lymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    estimator = 'hu_ok'

kmask = maps.mask_kspace(shape, wcs, lmin=20, lmax=Lmax)

feed_dict = {}
feed_dict['uC_T_T'] = theory.uCl('TT', modlmap)
feed_dict['tC_T_T'] = theory.lCl(
    'TT',
    modlmap) + (6. * np.pi / 180 / 60)**2. / maps.gauss_beam(modlmap, 1.4)**2.
feed_dict['pc_T_T'] = 1

N_l = qe.N_l_optimal(shape,
                     wcs,
                     feed_dict,
                     'hu_ok',
                     'TT',
                     xmask=lxmask,
                     ymask=lymask,
                     field_names=None,
                     kmask=kmask)
h = qe.HardenedTT(shape,
                  wcs,
                  feed_dict,
                  xmask=xmask,
예제 #30
0
import numpy as np
import os, sys

cache = True
hdv = False
deg = 5
px = 1.5
shape, wcs = maps.rect_geometry(width_deg=deg, px_res_arcmin=px)
mc = sc.LensingModeCoupling(shape, wcs)
pols = ['TT', "TE", 'EE', 'EB', 'TB']

theory = cosmology.default_theory(lpad=20000)
noise_t = 10.0
noise_p = 10.0 * np.sqrt(2.)
fwhm = 1.5
kbeam = maps.gauss_beam(fwhm, mc.modlmap)
ells = np.arange(0, 3000, 1)
lbeam = maps.gauss_beam(fwhm, ells)
ntt = np.nan_to_num((noise_t * np.pi / 180. / 60.)**2. / kbeam**2.)
nee = np.nan_to_num((noise_p * np.pi / 180. / 60.)**2. / kbeam**2.)
nbb = np.nan_to_num((noise_p * np.pi / 180. / 60.)**2. / kbeam**2.)
lntt = np.nan_to_num((noise_t * np.pi / 180. / 60.)**2. / lbeam**2.)
lnee = np.nan_to_num((noise_p * np.pi / 180. / 60.)**2. / lbeam**2.)
lnbb = np.nan_to_num((noise_p * np.pi / 180. / 60.)**2. / lbeam**2.)

ellmin = 20
ellmax = 3000
xmask = maps.mask_kspace(shape, wcs, lmin=ellmin, lmax=ellmax)
ymask = xmask

Als = {}