예제 #1
0
    def Forecast_Cellyy(self, ellBinEdges, fsky, constraint='None'):

        ellMids = old_div((ellBinEdges[1:] + ellBinEdges[:-1]), 2)

        cls_tsz = self.fgs.tSZ(self.evalells,self.freq[0],self.freq[0]) / self.cc.c['TCMBmuK']**2. \
                / ((self.evalells+1.)*self.evalells) * 2.* np.pi

        cls_yy = old_div(cls_tsz,
                         (f_nu(self.cc.c,
                               self.freq[0]))**2)  # Normalized to get Cell^yy

        LF = LensForecast()
        if (constraint == 'None'):
            LF.loadGenericCls("yy", self.evalells, cls_yy, self.evalells,
                              self.N_ll_tsz)
        elif (constraint == 'cmb'):
            LF.loadGenericCls("yy", self.evalells, cls_yy, self.evalells,
                              self.N_ll_tsz_c_cmb)
        elif (constraint == 'cib'):
            LF.loadGenericCls("yy", self.evalells, cls_yy, self.evalells,
                              self.N_ll_tsz_c_cib)
        else:
            return "Wrong option"

        sn, errs = LF.sn(ellBinEdges, fsky, "yy")  # not squared

        cls_out = np.interp(ellMids, self.evalells, cls_yy)

        return ellMids, cls_out, errs, sn
예제 #2
0
    def __init__(self,clusterCosmology, fgs,fwhms=[1.5],rms_noises =[1.], freqs = [150.],lmax=8000,lknee=0.,alpha=1.,dell=1.,v3mode=-1):
        
        #Inputs
        #clusterCosmology is a class that contains cosmological parameters and power spectra.
        #fgs is a class that contains the functional forms for the foregrounds and constants

        #Options

        #initial set up for ILC
        self.cc = clusterCosmology

        #initializing the frequency matrices
        if (len(freqs) > 1):
            fq_mat   = np.matlib.repmat(freqs,len(freqs),1) 
            fq_mat_t = np.transpose(np.matlib.repmat(freqs,len(freqs),1))
        else:
            fq_mat   = freqs
            fq_mat_t = freqs

        self.fgs = fgs

    
        self.dell = dell
        #set-up ells to evaluate up to lmax
        self.evalells = np.arange(2,lmax,self.dell)
        self.N_ll_noILC = self.evalells*0.0
        self.N_ll_tsz = self.evalells*0.0
        self.N_ll_cmb = self.evalells*0.0
        self.N_ll_rsx = self.evalells*0.0
        self.N_ll_cmb_c_tsz = self.evalells*0.0
        self.N_ll_tsz_c_cmb = self.evalells*0.0
        self.N_ll_tsz_c_cib = self.evalells*0.0

        #Only for SO forecasts, including the SO atmosphere modeling
        if v3mode>-1:
            print("V3 flag enabled.")
            import szar.V3_calc_public as v3

            if v3mode <= 2:
                vfreqs = v3.Simons_Observatory_V3_LA_bands()
                freqs = vfreqs
                vbeams = v3.Simons_Observatory_V3_LA_beams()
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]

                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.Simons_Observatory_V3_LA_noise(sensitivity_mode=v3mode,f_sky=fsky,ell_max=v3lmax+v3dell,delta_ell=v3dell)
            elif v3mode == 3:
                vfreqs = v3.AdvACT_bands()
                freqs = vfreqs
                vbeams = v3.AdvACT_beams()
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.AdvACT_noise(f_sky=fsky,ell_max=v3lmax+v3dell,delta_ell=\
v3dell)

        #initializing the weighting functions for the ilc
        #thermal SZ weights
        self.W_ll_tsz = np.zeros([len(self.evalells),len(np.array(freqs))])
        #CMB weights
        self.W_ll_cmb = np.zeros([len(self.evalells),len(np.array(freqs))])
        #rayleigh scattering cross correlation weights
        self.W_ll_rsx = np.zeros([len(self.evalells),len(np.array(freqs))])
        #thermal SZ constraining the CIB weights 
        self.W_ll_tsz_c_cib = np.zeros([len(self.evalells),len(np.array(freqs))])
        #thermal SZ constraining the CMB weights 
        self.W_ll_tsz_c_cmb = np.zeros([len(self.evalells),len(np.array(freqs))])
        #CMB constraining the thermal SZ weights 
        self.W_ll_cmb_c_tsz = np.zeros([len(self.evalells),len(np.array(freqs))])
        self.freq = freqs

        #frequency functions for
        f_nu_tsz = f_nu(self.cc.c,np.array(freqs)) #tSZ
        f_nu_cmb = f_nu_tsz*0.0 + 1. #CMB
        f_nu_cib = self.fgs.f_nu_cib(np.array(freqs)) #CIB
        f_nu_rsx = self.fgs.rs_nu(np.array(freqs)) #Rayleigh Cross

        for ii in range(len(self.evalells)):

            cmb_els = fq_mat*0.0 + self.cc.clttfunc(self.evalells[ii])
            
            if v3mode < 0:
                inst_noise = ( old_div(noise_func(self.evalells[ii],np.array(fwhms),np.array(rms_noises),lknee,alpha,dimensionless=False), self.cc.c['TCMBmuK']**2.))
                nells = np.diag(inst_noise)
            elif v3mode<=2:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff,ii], self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))
                # Adding in atmo. freq-freq correlations 
                #nells[0,1] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[1,0] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[2,3] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[3,2] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[4,5] = N_ell_T_LA[8,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[5,4] = N_ell_T_LA[8,ii]/ self.cc.c['TCMBmuK']**2.

            elif v3mode==3:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff,ii], self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))
                # Adding in atmo. freq-freq correlations
                #nells[0,1] = N_ell_T_LA[5,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[1,0] = N_ell_T_LA[5,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[2,3] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[3,2] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[3,4] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[4,3] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.

            self.N_ll_noILC[ii] = nells[3,3]

            totfg = (self.fgs.rad_pst(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) +
                      self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi 

            totfgrs = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) +
                       self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.rs_auto(self.evalells[ii],fq_mat,fq_mat_t) + \
                       self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii] ) * 2.* np.pi 

            totfg_cib = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi


            ksz = fq_mat*0.0 + self.fgs.ksz_temp(self.evalells[ii]) / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            tsz = self.fgs.tSZ(self.evalells[ii],fq_mat,fq_mat_t) / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi            

            cib = (self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t)) \
                     / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            N_ll_for_tsz = nells + totfg + cmb_els + ksz 
            N_ll_for_cmb = nells + totfg + tsz + ksz 
            N_ll_for_rsx = nells + totfg + tsz + ksz + cmb_els

            N_ll_for_tsz_c_cmb = nells + totfg 
            N_ll_for_cmb_c_tsz = N_ll_for_tsz_c_cmb + ksz
            N_ll_for_tsz_c_cib = nells + totfg_cib + cmb_els + ksz

            N_ll_for_tsz_inv = np.linalg.inv(N_ll_for_tsz)
            N_ll_for_cmb_inv = np.linalg.inv(N_ll_for_cmb)
            N_ll_for_rsx_inv = np.linalg.inv(N_ll_for_rsx)
            N_ll_for_tsz_c_cmb_inv = np.linalg.inv(N_ll_for_tsz_c_cmb)
            N_ll_for_cmb_c_tsz_inv = N_ll_for_tsz_c_cmb_inv
            N_ll_for_tsz_c_cib_inv = np.linalg.inv(N_ll_for_tsz_c_cib)

            self.W_ll_tsz[ii,:]=weightcalculator(f_nu_tsz,N_ll_for_tsz)
            self.W_ll_rsx[ii,:]=weightcalculator(f_nu_rsx,N_ll_for_rsx)
            self.W_ll_cmb[ii,:]=weightcalculator(f_nu_cmb,N_ll_for_cmb)
            self.N_ll_tsz[ii] = np.dot(np.transpose(self.W_ll_tsz[ii,:]),np.dot(N_ll_for_tsz,self.W_ll_tsz[ii,:]))
            self.N_ll_cmb[ii] = np.dot(np.transpose(self.W_ll_cmb[ii,:]),np.dot(N_ll_for_cmb,self.W_ll_cmb[ii,:]))
            self.N_ll_rsx[ii] = np.dot(np.transpose(self.W_ll_rsx[ii,:]),np.dot(N_ll_for_rsx,self.W_ll_rsx[ii,:]))
            self.W_ll_tsz_c_cmb[ii,:]=constweightcalculator(f_nu_cmb,f_nu_tsz,N_ll_for_tsz_c_cmb_inv)
            self.W_ll_tsz_c_cib[ii,:]=constweightcalculator(f_nu_cib,f_nu_tsz,N_ll_for_tsz_c_cib_inv)
            self.W_ll_cmb_c_tsz[ii,:]=constweightcalculator(f_nu_tsz,f_nu_cmb,N_ll_for_cmb_c_tsz_inv)
            self.N_ll_tsz_c_cmb[ii] = np.dot(np.transpose(self.W_ll_tsz_c_cmb[ii,:]),np.dot(N_ll_for_tsz_c_cmb,self.W_ll_tsz_c_cmb[ii,:]))
            self.N_ll_cmb_c_tsz[ii] = np.dot(np.transpose(self.W_ll_cmb_c_tsz[ii,:]),np.dot(N_ll_for_cmb_c_tsz,self.W_ll_cmb_c_tsz[ii,:]))
            self.N_ll_tsz_c_cib[ii] = np.dot(np.transpose(self.W_ll_tsz_c_cib[ii,:]),np.dot(N_ll_for_tsz_c_cib,self.W_ll_tsz_c_cib[ii,:]))

            '''
예제 #3
0
    def __init__(self,
                 clusterCosmology,
                 fgs,
                 fwhms=[1.5],
                 rms_noises=[1.],
                 freqs=[150.],
                 lmax=8000,
                 lknee=0.,
                 alpha=1.,
                 dell=1.,
                 v3mode=-1):

        #ksz_file='input/ksz_BBPS.txt',ksz_p_file='input/ksz_p_BBPS.txt', \
        #tsz_cib_file='input/sz_x_cib_template.dat',fg=True):

        self.cc = clusterCosmology

        if (len(freqs) > 1):
            fq_mat = np.matlib.repmat(freqs, len(freqs), 1)
            fq_mat_t = np.transpose(np.matlib.repmat(freqs, len(freqs), 1))
        else:
            fq_mat = freqs
            fq_mat_t = freqs

        self.fgs = fgs  #fgNoises(self.cc.c,ksz_file=ksz_file,ksz_p_file=ksz_p_file,tsz_cib_file=tsz_cib_file,tsz_battaglia_template_csv="data/sz_template_battaglia.csv")

        self.dell = dell
        self.evalells = np.arange(2, lmax, self.dell)
        self.N_ll_noILC = self.evalells * 0.0
        self.N_ll_tsz = self.evalells * 0.0
        self.N_ll_cmb = self.evalells * 0.0
        self.N_ll_rsx = self.evalells * 0.0
        self.N_ll_cmb_c_tsz = self.evalells * 0.0
        self.N_ll_tsz_c_cmb = self.evalells * 0.0
        self.N_ll_tsz_c_cib = self.evalells * 0.0

        if v3mode > -1:
            print("V3 flag enabled.")
            import szar.V3_calc_public as v3

            if v3mode <= 2:
                vfreqs = v3.Simons_Observatory_V3_LA_bands()
                freqs = vfreqs
                vbeams = v3.Simons_Observatory_V3_LA_beams()
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]

                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.Simons_Observatory_V3_LA_noise(
                    sensitivity_mode=v3mode,
                    f_sky=fsky,
                    ell_max=v3lmax + v3dell,
                    delta_ell=v3dell)
            elif v3mode == 3:
                vfreqs = v3.AdvACT_bands()
                freqs = vfreqs
                vbeams = v3.AdvACT_beams()
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.AdvACT_noise(f_sky=fsky,ell_max=v3lmax+v3dell,delta_ell=\
v3dell)

        self.W_ll_tsz = np.zeros([len(self.evalells), len(np.array(freqs))])
        self.W_ll_cmb = np.zeros([len(self.evalells), len(np.array(freqs))])
        self.W_ll_rsx = np.zeros([len(self.evalells), len(np.array(freqs))])
        self.W_ll_tsz_c_cib = np.zeros(
            [len(self.evalells), len(np.array(freqs))])
        self.W_ll_tsz_c_cmb = np.zeros(
            [len(self.evalells), len(np.array(freqs))])
        self.W_ll_cmb_c_tsz = np.zeros(
            [len(self.evalells), len(np.array(freqs))])
        self.freq = freqs

        f_nu_tsz = f_nu(self.cc.c, np.array(freqs))
        f_nu_cmb = f_nu_tsz * 0.0 + 1.
        f_nu_cib = self.fgs.f_nu_cib(np.array(freqs))
        f_nu_rsx = self.fgs.rs_nu(np.array(freqs))

        for ii in range(len(self.evalells)):

            cmb_els = fq_mat * 0.0 + self.cc.clttfunc(self.evalells[ii])

            if v3mode < 0:
                inst_noise = (old_div(
                    noise_func(self.evalells[ii],
                               np.array(fwhms),
                               np.array(rms_noises),
                               lknee,
                               alpha,
                               dimensionless=False), self.cc.c['TCMBmuK']**2.))
                nells = np.diag(inst_noise)
            elif v3mode <= 2:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff, ii],
                                         self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))
                # Adding in atmo. freq-freq correlations
                #nells[0,1] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[1,0] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[2,3] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[3,2] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[4,5] = N_ell_T_LA[8,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[5,4] = N_ell_T_LA[8,ii]/ self.cc.c['TCMBmuK']**2.

            elif v3mode == 3:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff, ii],
                                         self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))
                # Adding in atmo. freq-freq correlations
                #nells[0,1] = N_ell_T_LA[5,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[1,0] = N_ell_T_LA[5,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[2,3] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[3,2] = N_ell_T_LA[6,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[3,4] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.
                #nells[4,3] = N_ell_T_LA[7,ii]/ self.cc.c['TCMBmuK']**2.

            self.N_ll_noILC[ii] = nells[3, 3]

            totfg = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) +
                      self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            totfgrs = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) +
                       self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.rs_auto(self.evalells[ii],fq_mat,fq_mat_t) + \
                       self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii] ) * 2.* np.pi

            totfg_cib = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            ksz = fq_mat * 0.0 + self.fgs.ksz_temp(
                self.evalells[ii]) / self.cc.c['TCMBmuK']**2. / (
                    (self.evalells[ii] + 1.) * self.evalells[ii]) * 2. * np.pi

            tsz = self.fgs.tSZ(
                self.evalells[ii], fq_mat,
                fq_mat_t) / self.cc.c['TCMBmuK']**2. / (
                    (self.evalells[ii] + 1.) * self.evalells[ii]) * 2. * np.pi

            cib = (self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t)) \
                     / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            N_ll_for_tsz = nells + totfg + cmb_els + ksz
            N_ll_for_cmb = nells + totfg + tsz + ksz
            N_ll_for_rsx = nells + totfg + tsz + ksz + cmb_els

            N_ll_for_tsz_c_cmb = nells + totfg
            N_ll_for_cmb_c_tsz = N_ll_for_tsz_c_cmb + ksz
            N_ll_for_tsz_c_cib = nells + totfg_cib + cmb_els + ksz

            N_ll_for_tsz_inv = np.linalg.inv(N_ll_for_tsz)
            N_ll_for_cmb_inv = np.linalg.inv(N_ll_for_cmb)
            N_ll_for_rsx_inv = np.linalg.inv(N_ll_for_rsx)
            N_ll_for_tsz_c_cmb_inv = np.linalg.inv(N_ll_for_tsz_c_cmb)
            N_ll_for_cmb_c_tsz_inv = N_ll_for_tsz_c_cmb_inv
            N_ll_for_tsz_c_cib_inv = np.linalg.inv(N_ll_for_tsz_c_cib)


            self.W_ll_tsz[ii,:] = 1./np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_inv,f_nu_tsz)) \
                                  * np.dot(np.transpose(f_nu_tsz),N_ll_for_tsz_inv)
            self.W_ll_cmb[ii,:] = 1./np.dot(np.transpose(f_nu_cmb),np.dot(N_ll_for_cmb_inv,f_nu_cmb)) \
                                  * np.dot(np.transpose(f_nu_cmb),N_ll_for_cmb_inv)
            self.W_ll_rsx[ii,:] = 1./np.dot(np.transpose(f_nu_rsx),np.dot(N_ll_for_rsx_inv,f_nu_rsx)) \
                                  * np.dot(np.transpose(f_nu_rsx),N_ll_for_rsx_inv)

            self.N_ll_tsz[ii] = np.dot(
                np.transpose(self.W_ll_tsz[ii, :]),
                np.dot(N_ll_for_tsz, self.W_ll_tsz[ii, :]))
            self.N_ll_cmb[ii] = np.dot(
                np.transpose(self.W_ll_cmb[ii, :]),
                np.dot(N_ll_for_cmb, self.W_ll_cmb[ii, :]))
            self.N_ll_rsx[ii] = np.dot(
                np.transpose(self.W_ll_rsx[ii, :]),
                np.dot(N_ll_for_rsx, self.W_ll_rsx[ii, :]))

            self.W_ll_tsz_c_cmb[ii,:] = old_div((np.dot(np.transpose(f_nu_cmb),np.dot(N_ll_for_tsz_c_cmb_inv,f_nu_cmb)) \
                                             * np.dot(np.transpose(f_nu_tsz),N_ll_for_tsz_c_cmb_inv) \
                                             - np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_c_cmb_inv,f_nu_cmb)) \
                                             * np.dot(np.transpose(f_nu_cmb),N_ll_for_tsz_c_cmb_inv)), \
                                        (np.dot(np.transpose(f_nu_cmb),np.dot(N_ll_for_tsz_c_cmb_inv,f_nu_cmb)) \
                                             * np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_c_cmb_inv,f_nu_tsz)) \
                                             - (np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_c_cmb_inv,f_nu_cmb)))**2))

            self.W_ll_tsz_c_cib[ii,:] = old_div((np.dot(np.transpose(f_nu_cib),np.dot(N_ll_for_tsz_c_cib_inv,f_nu_cib)) \
                                             * np.dot(np.transpose(f_nu_tsz),N_ll_for_tsz_c_cib_inv) \
                                             - np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_c_cib_inv,f_nu_cib)) \
                                             * np.dot(np.transpose(f_nu_cib),N_ll_for_tsz_c_cib_inv)), \
                                        (np.dot(np.transpose(f_nu_cib),np.dot(N_ll_for_tsz_c_cib_inv,f_nu_cib)) \
                                             * np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_c_cib_inv,f_nu_tsz)) \
                                             - (np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_tsz_c_cib_inv,f_nu_cib)))**2))

            self.W_ll_cmb_c_tsz[ii,:] = old_div((np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_cmb_c_tsz_inv,f_nu_tsz)) \
                                             * np.dot(np.transpose(f_nu_cmb),N_ll_for_cmb_c_tsz_inv) \
                                             - np.dot(np.transpose(f_nu_cmb),np.dot(N_ll_for_cmb_c_tsz_inv,f_nu_tsz)) \
                                             * np.dot(np.transpose(f_nu_tsz),N_ll_for_cmb_c_tsz_inv)), \
                                        (np.dot(np.transpose(f_nu_cmb),np.dot(N_ll_for_cmb_c_tsz_inv,f_nu_cmb)) \
                                             * np.dot(np.transpose(f_nu_tsz),np.dot(N_ll_for_cmb_c_tsz_inv,f_nu_tsz)) \
                                             - (np.dot(np.transpose(f_nu_cmb),np.dot(N_ll_for_cmb_c_tsz_inv,f_nu_tsz)))**2))

            self.N_ll_tsz_c_cmb[ii] = np.dot(
                np.transpose(self.W_ll_tsz_c_cmb[ii, :]),
                np.dot(N_ll_for_tsz_c_cmb, self.W_ll_tsz_c_cmb[ii, :]))
            self.N_ll_cmb_c_tsz[ii] = np.dot(
                np.transpose(self.W_ll_cmb_c_tsz[ii, :]),
                np.dot(N_ll_for_cmb_c_tsz, self.W_ll_cmb_c_tsz[ii, :]))
            self.N_ll_tsz_c_cib[ii] = np.dot(
                np.transpose(self.W_ll_tsz_c_cib[ii, :]),
                np.dot(N_ll_for_tsz_c_cib, self.W_ll_tsz_c_cib[ii, :]))
예제 #4
0
    def __init__(self,clusterCosmology,clusterDict, \
                 fwhms=[1.5],rms_noises =[1.], freqs = [150.],lmax=8000,lknee=0.,alpha=1., \
                 dell=10,pmaxN=5,numps=1000,nMax=1, \
                 ymin=1.e-14,ymax=4.42e-9,dlnY = 0.1, qmin=5., \
                 ksz_file=root_dir+'input/ksz_BBPS.txt',ksz_p_file=root_dir+'input/ksz_p_BBPS.txt', \
                 tsz_cib_file=root_dir+'input/sz_x_cib_template.txt',fg=True,tsz_cib=False,
                 tsz_battaglia_template_csv=root_dir+"input/sz_template_battaglia.csv",v3mode=-1,fsky=None):

        self.cc = clusterCosmology
        self.P0 = clusterDict['P0']
        self.xc = clusterDict['xc']
        self.al = clusterDict['al']
        self.gm = clusterDict['gm']
        self.bt = clusterDict['bt']

        self.scaling = self.cc.paramDict

        self.qmin = qmin

        lnYmin = np.log(ymin)
        lnYmax = np.log(ymax)
        self.lnY = np.arange(lnYmin, lnYmax, dlnY)
        fgs = fgNoises(self.cc.c,
                       ksz_file=ksz_file,
                       ksz_p_file=ksz_p_file,
                       tsz_cib_file=tsz_cib_file,
                       tsz_battaglia_template_csv=tsz_battaglia_template_csv)

        self.dell = dell
        self.nlinv = 0.
        self.nlinv_cmb = 0.
        self.nlinv_nofg = 0.
        self.nlinv_cmb_nofg = 0.
        self.evalells = np.arange(2, lmax, self.dell)

        if v3mode > -1:
            print("V3 flag enabled.")
            import szar.V3_calc_public as v3

            if v3mode <= 2:
                import szar.so_noise_lat_v3_1_CAND as v3_1
                lat = v3_1.SOLatV3point1(v3mode, el=50.)
                vfreqs = lat.get_bands()  # v3.Simons_Observatory_V3_LA_bands()
                print("Simons Obs")
                print("Replacing ", freqs, " with ", vfreqs)
                N_bands = len(vfreqs)
                freqs = vfreqs
                vbeams = lat.get_beams()  #v3.Simons_Observatory_V3_LA_beams()
                print("Replacing ", fwhms, " with ", vbeams)
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                print("Using ", fsky, " for fsky")

                v3ell, N_ell_T_LA_full, N_ell_P_LA = lat.get_noise_curves(
                    fsky,
                    v3lmax + v3dell,
                    v3dell,
                    full_covar=True,
                    deconv_beam=True)

                N_ell_T_LA = np.diagonal(N_ell_T_LA_full).T
                Map_white_noise_levels = lat.get_white_noise(fsky)**.5

                #v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.Simons_Observatory_V3_LA_noise(sensitivity_mode=v3mode,f_sky=fsky,ell_max=v3lmax+v3dell,delta_ell=v3dell)
            elif v3mode == 3:
                vfreqs = v3.AdvACT_bands()
                print("AdvACT")
                print("Replacing ", freqs, " with ", vfreqs)
                freqs = vfreqs
                vbeams = v3.AdvACT_beams()
                print("Replacing ", fwhms, " with ", vbeams)
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                print("Using ", fsky, " for fsky")

                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.AdvACT_noise(
                    f_sky=fsky, ell_max=v3lmax + v3dell, delta_ell=v3dell)

            elif v3mode == 4:
                import szar.noise_model_190604d_public as s4
                #mode = 2
                #ncalc = s4.S4LatV1(mode, N_tels=2)
                #vfreqs = ncalc.get_bands()
                print("S4")

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]

                v3ell = np.arange(2, v3lmax + 1, v3dell)
                #print (v3ell, self.evalells)
                info, vfreqs, Nmatrix = s4.get_model('hires_deepwide',
                                                     'TT',
                                                     v3ell,
                                                     gal_cut=10,
                                                     deconv_beam=True)
                print("Replacing ", freqs, " with ", vfreqs)

                print("Using ", fsky, " for fsky")

                freqs = vfreqs
                #vbeams = ncalc.get_beams()
                #print("Replacing ",fwhms,  " with ", vbeams)
                fwhms = freqs * 1.  #not used

                N_ell_T_LA_full = Nmatrix
                N_ell_T_LA = np.diagonal(N_ell_T_LA_full).T
                print(N_ell_T_LA.shape)

            elif v3mode == 5:
                import szar.lat_noise_190528_w350ds4 as ccatp
                tubes = (0, 0, 0, 2, 2, 1)
                lat = ccatp.CcatLatv2(v3mode,
                                      el=50.,
                                      survey_years=4000 / 24. / 365.24,
                                      survey_efficiency=1.0,
                                      N_tubes=tubes)
                vfreqs = lat.get_bands()  # v3.Simons_Observatory_V3_LA_bands()
                print("CCATP")
                print("Replacing ", freqs, " with ", vfreqs)
                N_bands = len(vfreqs)
                freqs = vfreqs
                vbeams = lat.get_beams()  #v3.Simons_Observatory_V3_LA_beams()
                print("Replacing ", fwhms, " with ", vbeams)
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                print("Using ", fsky, " for fsky")

                v3ell, N_ell_T_LA_full, N_ell_P_LA = lat.get_noise_curves(
                    fsky,
                    v3lmax + v3dell,
                    v3dell,
                    full_covar=True,
                    deconv_beam=True)

                N_ell_T_LA = np.diagonal(N_ell_T_LA_full).T
                Map_white_noise_levels = lat.get_white_noise(fsky)**.5

            if v3mode >= 7:

                usemode = v3mode - 6
                print("V3mode ", usemode)

                vfreqs = v3.Simons_Observatory_V3_LA_bands()
                print("Simons Obs")
                print("Replacing ", freqs, " with ", vfreqs)
                freqs = vfreqs
                vbeams = v3.Simons_Observatory_V3_LA_beams()
                print("Replacing ", fwhms, " with ", vbeams)
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                print("Using ", fsky, " for fsky")

                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.Simons_Observatory_V3_LA_noise(
                    sensitivity_mode=usemode,
                    f_sky=fsky,
                    ell_max=v3lmax + v3dell,
                    delta_ell=v3dell)

            assert np.all(v3ell == self.evalells)

        # pl = io.Plotter(yscale='log',xlabel='l',ylabel='D_l')

        for ii, (freq, fwhm, noise) in enumerate(zip(freqs, fwhms,
                                                     rms_noises)):
            freq_fac = (f_nu(self.cc.c, freq))**2

            if v3mode > -1:
                inst_noise = N_ell_T_LA[ii] / self.cc.c['TCMBmuK']**2.
            else:
                inst_noise = (noise_func(self.evalells,
                                         fwhm,
                                         noise,
                                         lknee,
                                         alpha,
                                         dimensionless=False) /
                              self.cc.c['TCMBmuK']**2.)

            # pl.add(self.evalells,inst_noise*self.evalells**2.,color="C"+str(ii))
            # pl.add(self.evalells,N_ell_T_LA[ii]*self.evalells**2./ self.cc.c['TCMBmuK']**2.,color="C"+str(ii),ls="--")

            nells = self.cc.clttfunc(self.evalells) + inst_noise
            self.nlinv_nofg += old_div((freq_fac), nells)
            self.nlinv_cmb_nofg += (old_div(1., inst_noise))

            totfg = (fgs.rad_ps(self.evalells,freq,freq) + fgs.cib_p(self.evalells,freq,freq) + \
                      fgs.cib_c(self.evalells,freq,freq) + fgs.ksz_temp(self.evalells)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells+1.)*self.evalells) * 2.* np.pi
            nells += totfg

            if (tsz_cib):
                tszcib = fgs.tSZ_CIB(self.evalells,freq,freq) \
                         / self.cc.c['TCMBmuK']**2. / ((self.evalells+1.)*self.evalells) * 2.* np.pi
                nells += tszcib

            self.nlinv += old_div((freq_fac), nells)
            self.nlinv_cmb += (old_div(1., (inst_noise + totfg)))

        # pl.add(self.evalells,self.cc.clttfunc(self.evalells)*self.evalells**2.,color='k',lw=3)
        # pl.done(io.dout_dir+"v3comp.png")

        self.nl_old = (1. / self.nlinv)
        self.nl_cmb = (1. / self.nlinv_cmb)
        self.nl_nofg = (1. / self.nlinv_nofg)
        self.nl_cmb_nofg = (1. / self.nlinv_cmb_nofg)

        f_nu_tsz = f_nu(self.cc.c, np.array(freqs))

        if (len(freqs) > 1):
            fq_mat = repmat(freqs, len(freqs), 1)
            fq_mat_t = np.transpose(repmat(freqs, len(freqs), 1))
        else:
            fq_mat = np.array(freqs)
            fq_mat_t = np.array(freqs)

        self.nl = self.evalells * 0.0

        for ii in range(len(self.evalells)):
            cmb_els = fq_mat * 0.0 + self.cc.clttfunc(self.evalells[ii])

            if v3mode < 0:
                inst_noise = (old_div(
                    noise_func(self.evalells[ii],
                               np.array(fwhms),
                               np.array(rms_noises),
                               lknee,
                               alpha,
                               dimensionless=False), self.cc.c['TCMBmuK']**2.))
                nells = np.diag(inst_noise)
            elif v3mode <= 2:
                nells = N_ell_T_LA_full[:, :, ii] / self.cc.c['TCMBmuK']**2.

                #corr_pairs = [(0,1),(2,3),(4,5)]

                #N_ell_LA_T  = N_ell_LA_T_full[range(N_bands),range(N_bands)]
                #N_ell_LA_Tx = [N_ell_LA_T_full[i,j] for i,j in corr_pairs]
                #N_ell_LA_P  = N_ell_LA_P_full[range(N_bands),range(N_bands)]
                #N_ell_LA_Px = [N_ell_LA_P_full[i,j] for i,j in corr_pairs]

                #nells = N_ell_LA_Tx

                #ndiags = []
                #for ff in range(len(freqs)):
                #    inst_noise = old_div(N_ell_T_LA[ff,ii], self.cc.c['TCMBmuK']**2.)
                #    ndiags.append(inst_noise)
                #nells = np.diag(np.array(ndiags))
                ## Adding in atmo. freq-freq correlations
                #nells[0,1] = old_div(N_ell_T_LA[6,ii], self.cc.c['TCMBmuK']**2.)
                #nells[1,0] = old_div(N_ell_T_LA[6,ii], self.cc.c['TCMBmuK']**2.)
                #nells[2,3] = old_div(N_ell_T_LA[7,ii], self.cc.c['TCMBmuK']**2.)
                #nells[3,2] = old_div(N_ell_T_LA[7,ii], self.cc.c['TCMBmuK']**2.)
                #nells[4,5] = old_div(N_ell_T_LA[8,ii], self.cc.c['TCMBmuK']**2.)
                #nells[5,4] = old_div(N_ell_T_LA[8,ii], self.cc.c['TCMBmuK']**2.)
            elif v3mode == 3:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff, ii],
                                         self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))
                # Adding in atmo. freq-freq correlations
                nells[0, 1] = old_div(N_ell_T_LA[5, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[1, 0] = old_div(N_ell_T_LA[5, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[2, 3] = old_div(N_ell_T_LA[6, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[3, 2] = old_div(N_ell_T_LA[6, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[3, 4] = old_div(N_ell_T_LA[7, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[4, 3] = old_div(N_ell_T_LA[7, ii],
                                      self.cc.c['TCMBmuK']**2.)
            elif v3mode == 4:
                nells = N_ell_T_LA_full[:, :, ii] / self.cc.c['TCMBmuK']**2.
            elif v3mode == 5:
                nells = N_ell_T_LA_full[:, :, ii] / self.cc.c['TCMBmuK']**2.
            elif v3mode >= 7:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff, ii],
                                         self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))
                # Adding in atmo. freq-freq correlations
                nells[0, 1] = old_div(N_ell_T_LA[6, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[1, 0] = old_div(N_ell_T_LA[6, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[2, 3] = old_div(N_ell_T_LA[7, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[3, 2] = old_div(N_ell_T_LA[7, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[4, 5] = old_div(N_ell_T_LA[8, ii],
                                      self.cc.c['TCMBmuK']**2.)
                nells[5, 4] = old_div(N_ell_T_LA[8, ii],
                                      self.cc.c['TCMBmuK']**2.)

            totfg = (fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t)
                     + fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t)) \
                     / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            if (tsz_cib):
                totfg += fgs.tSZ_CIB(self.evalells[ii], fq_mat,
                                     fq_mat_t) / self.cc.c['TCMBmuK']**2. / (
                                         (self.evalells[ii] + 1.) *
                                         self.evalells[ii]) * 2. * np.pi
                totfg += fgs.tSZ(
                    self.evalells[ii], fq_mat, fq_mat_t
                ) / self.cc.c['TCMBmuK']**2. / (
                    (self.evalells[ii] + 1.) * self.evalells[ii]
                ) * 2. * np.pi / 2.  # factor of two accounts for resolved halos

            ksz = fq_mat * 0.0 + fgs.ksz_temp(
                self.evalells[ii]) / self.cc.c['TCMBmuK']**2. / (
                    (self.evalells[ii] + 1.) * self.evalells[ii]) * 2. * np.pi

            nells += totfg + cmb_els + ksz

            self.nl[ii] = old_div(
                1., (np.dot(np.transpose(f_nu_tsz),
                            np.dot(np.linalg.inv(nells), f_nu_tsz))))

        # from orphics.io import Plotter
        # pl = Plotter(yscale='log',xlabel='l',ylabel='D_l')
        # pl.add(self.evalells,self.nl*self.evalells**2.)
        # ells = np.arange(2,3000,1)
        # pl.add(ells,self.cc.clttfunc(ells)*ells**2.)
        # pl.done("nltt.png")
        # sys.exit()

        self.fg = fg

        c = self.xc
        alpha = self.al
        beta = self.bt
        gamma = self.gm
        p = lambda x: old_div(1., (((c * x)**gamma) * ((1. + (
            (c * x)**alpha))**(old_div((beta - gamma), alpha)))))

        pmaxN = pmaxN
        numps = numps
        pzrange = np.linspace(-pmaxN, pmaxN, numps)
        self.g = lambda x: np.trapz(p(np.sqrt(pzrange**2. + x**2.)), pzrange,
                                    np.diff(pzrange))

        self.gxrange = np.linspace(0., nMax, numps)
        self.gint = np.array([self.g(x) for x in self.gxrange])

        self.gnorm_pre = np.trapz(self.gxrange * self.gint, self.gxrange)
예제 #5
0
# kszAlt = fgs.ksz_battaglia_test(ls)/ls/(ls+1.)*2.*np.pi/ cc.c['TCMBmuK']**2.

print_ells = [100,200,300,400,500,600]

print(("freqs", freqs))
print(("freqs", freqs[3:]))
print(("freqs", freqs[3:6]))

fq_mat   = np.matlib.repmat(freqs,len(freqs),1)
fq_mat_t = np.transpose(np.matlib.repmat(freqs,len(freqs),1))

#f_nu_arr2 = np.array(freqs)*0.0
#for ii in xrange(len(freqs)):
#    f_nu_arr2[ii] = f_nu_old(cc.c,freqs[ii])

f_nu_arr = f_nu(cc.c,np.array(freqs))

#print "TEST", np.sum(f_nu_arr - f_nu_arr2)

#print fq_mat
#print fq_mat_t

radio_mat = old_div(fgs.rad_ps(print_ells[4],fq_mat,fq_mat_t), cc.c['TCMBmuK']**2.)

#print "contraction", np.dot(np.transpose(f_nu_arr),np.dot(np.linalg.inv(radio_mat),f_nu_arr))

#print fgs.rad_ps(ls[10],fq_mat_t,fq_mat)/ls[10]/(ls[10]+1.)*2.*np.pi/ cc.c['TCMBmuK']**2.

#print fgs.rad_ps(ls[10],fq_mat_t,fq_mat)*0.0 + 1.

print(("noise", old_div(noise_func(print_ells[4],np.array(beams),np.array(noises),lknee,alpha,dimensionless=False), cc.c['TCMBmuK']**2.)))
예제 #6
0
파일: ilc.py 프로젝트: JerreYjz/szar
    def __init__(self,
                 clusterCosmology,
                 fgs,
                 fwhms=[1.5],
                 rms_noises=[1.],
                 freqs=[150.],
                 lmax=8000,
                 lknee=0.,
                 alpha=1.,
                 dell=1.,
                 v3mode=-1,
                 fsky=None):

        #Inputs
        #clusterCosmology is a class that contains cosmological parameters and power spectra.
        #fgs is a class that contains the functional forms for the foregrounds and constants

        #Options

        #initial set up for ILC
        self.cc = clusterCosmology

        #initializing the frequency matrices

        self.fgs = fgs

        self.dell = dell
        #set-up ells to evaluate up to lmax
        self.evalells = np.arange(2, lmax, self.dell)
        self.N_ll_tsz = self.evalells * 0.0
        self.N_ll_cmb = self.evalells * 0.0
        self.N_ll_rsx = self.evalells * 0.0
        self.N_ll_rsxEE = self.evalells * 0.0
        self.N_ll_rsx_NoFG = self.evalells * 0.0
        self.N_ll_cmb_c_tsz = self.evalells * 0.0
        self.N_ll_tsz_c_cmb = self.evalells * 0.0
        self.N_ll_tsz_c_cib = self.evalells * 0.0

        #Only for SO forecasts, including the SO atmosphere modeling
        if v3mode > -1:
            print("V3 flag enabled.")
            import szar.V3_calc_public as v3
            import szar.so_noise_lat_v3_1_CAND as v3_1

            if v3mode <= 2:
                lat = v3_1.SOLatV3point1(v3mode, el=50.)
                vfreqs = lat.get_bands()  # v3.Simons_Observatory_V3_LA_bands()
                print("Simons Obs")
                print("Replacing ", freqs, " with ", vfreqs)
                N_bands = len(vfreqs)
                freqs = vfreqs
                vbeams = lat.get_beams()  #v3.Simons_Observatory_V3_LA_beams()
                print("Replacing ", fwhms, " with ", vbeams)
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                print("Using ", fsky, " for fsky")

                v3ell, N_ell_T_LA_full, N_ell_P_LA = lat.get_noise_curves(
                    fsky,
                    v3lmax + v3dell,
                    v3dell,
                    full_covar=True,
                    deconv_beam=True)

                N_ell_T_LA = np.diagonal(N_ell_T_LA_full).T
                Map_white_noise_levels = lat.get_white_noise(fsky)**.5

            #if v3mode <= 2:
            #    vfreqs = v3.Simons_Observatory_V3_LA_bands()
            #    freqs = vfreqs
            #    vbeams = v3.Simons_Observatory_V3_LA_beams()
            #    fwhms = vbeams

            #    v3lmax = self.evalells.max()
            #    v3dell = np.diff(self.evalells)[0]

            #    v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.Simons_Observatory_V3_LA_noise(sensitivity_mode=v3mode,f_sky=fsky,ell_max=v3lmax+v3dell,delta_ell=v3dell)
            elif v3mode == 3:
                vfreqs = v3.AdvACT_bands()
                freqs = vfreqs
                vbeams = v3.AdvACT_beams()
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                v3ell, N_ell_T_LA, N_ell_P_LA, Map_white_noise_levels = v3.AdvACT_noise(f_sky=fsky,ell_max=v3lmax+v3dell,delta_ell=\
v3dell)
            elif v3mode == 5:
                import szar.lat_noise_190528_w350ds4 as ccatp
                tubes = (0, 0, 0, 2, 2, 1)
                lat = ccatp.CcatLatv2(v3mode,
                                      el=50.,
                                      survey_years=4000 / 24. / 365.24,
                                      survey_efficiency=1.0,
                                      N_tubes=tubes)
                vfreqs = lat.get_bands()  # v3.Simons_Observatory_V3_LA_bands()
                print("CCATP")
                print("Replacing ", freqs, " with ", vfreqs)
                N_bands = len(vfreqs)
                freqs = vfreqs
                vbeams = lat.get_beams()  #v3.Simons_Observatory_V3_LA_beams()
                print("Replacing ", fwhms, " with ", vbeams)
                fwhms = vbeams

                v3lmax = self.evalells.max()
                v3dell = np.diff(self.evalells)[0]
                print("Using ", fsky, " for fsky")

                v3ell, N_ell_T_LA_full, N_ell_P_LA = lat.get_noise_curves(
                    fsky,
                    v3lmax + v3dell,
                    v3dell,
                    full_covar=True,
                    deconv_beam=True)

                N_ell_T_LA = np.diagonal(N_ell_T_LA_full).T
                Map_white_noise_levels = lat.get_white_noise(fsky)**.5
        #print(freqs)
        if (len(freqs) > 1):
            fq_mat = np.matlib.repmat(freqs, len(freqs), 1)
            fq_mat_t = np.transpose(np.matlib.repmat(freqs, len(freqs), 1))
        else:
            fq_mat = freqs
            fq_mat_t = freqs
        #print(fq_mat)
        #initializing the weighting functions for the ilc
        #thermal SZ weights
        self.W_ll_tsz = np.zeros([len(self.evalells), len(np.array(freqs))])
        #CMB weights
        self.W_ll_cmb = np.zeros([len(self.evalells), len(np.array(freqs))])
        #rayleigh scattering cross correlation weights
        self.W_ll_rsx = np.zeros([len(self.evalells), len(np.array(freqs))])
        #rayleigh scattering cross E-mode of CMB correlation weights
        self.W_ll_rsxEE = np.zeros([len(self.evalells), len(np.array(freqs))])
        #rayleigh scattering cross correlation weights NO foregrounds
        self.W_ll_rsx_NF = np.zeros([len(self.evalells), len(np.array(freqs))])
        #thermal SZ constraining the CIB weights
        self.W_ll_tsz_c_cib = np.zeros(
            [len(self.evalells), len(np.array(freqs))])
        #thermal SZ constraining the CMB weights
        self.W_ll_tsz_c_cmb = np.zeros(
            [len(self.evalells), len(np.array(freqs))])
        #CMB constraining the thermal SZ weights
        self.W_ll_cmb_c_tsz = np.zeros(
            [len(self.evalells), len(np.array(freqs))])
        self.freq = freqs

        #frequency functions for
        f_nu_tsz = f_nu(self.cc.c, np.array(freqs))  #tSZ
        f_nu_cmb = f_nu_tsz * 0.0 + 1.  #CMB
        f_nu_cib = self.fgs.f_nu_cib(np.array(freqs))  #CIB
        f_nu_rsx = self.fgs.rs_nu(np.array(freqs))  #Rayleigh Cross

        for ii in range(len(self.evalells)):

            cmb_els = fq_mat * 0.0 + self.cc.clttfunc(self.evalells[ii])
            cmb_ee = fq_mat * 0.0 + self.cc.cleefunc(self.evalells[ii])
            if v3mode < 0:
                inst_noise = (old_div(
                    noise_func(self.evalells[ii],
                               np.array(fwhms),
                               np.array(rms_noises),
                               lknee,
                               alpha,
                               dimensionless=False), self.cc.c['TCMBmuK']**2.))
                nells = np.diag(inst_noise)
            elif v3mode <= 2:
                nells = N_ell_T_LA_full[:, :, ii] / self.cc.c['TCMBmuK']**2.

            elif v3mode == 3:
                ndiags = []
                for ff in range(len(freqs)):
                    inst_noise = old_div(N_ell_T_LA[ff, ii],
                                         self.cc.c['TCMBmuK']**2.)
                    ndiags.append(inst_noise)
                nells = np.diag(np.array(ndiags))

            elif v3mode == 5:
                nells = N_ell_T_LA_full[:, :, ii] / self.cc.c['TCMBmuK']**2.


            totfg = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) +
                      self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            totfgrs = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) +
                       self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.rs_auto(self.evalells[ii],fq_mat,fq_mat_t) + \
                       self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii] ) * 2.* np.pi

            fgrspol = (self.fgs.rad_pol_ps(self.evalells[ii],fq_mat,fq_mat_t)+self.fgs.gal_dust_pol(self.evalells[ii],fq_mat,fq_mat_t)+self.fgs.gal_sync_pol(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii] ) * 2.* np.pi

            totfg_cib = (self.fgs.rad_ps(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.tSZ_CIB(self.evalells[ii],fq_mat,fq_mat_t)) \
                      / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            ksz = fq_mat * 0.0 + self.fgs.ksz_temp(
                self.evalells[ii]) / self.cc.c['TCMBmuK']**2. / (
                    (self.evalells[ii] + 1.) * self.evalells[ii]) * 2. * np.pi

            tsz = self.fgs.tSZ(
                self.evalells[ii], fq_mat,
                fq_mat_t) / self.cc.c['TCMBmuK']**2. / (
                    (self.evalells[ii] + 1.) * self.evalells[ii]) * 2. * np.pi

            cib = (self.fgs.cib_p(self.evalells[ii],fq_mat,fq_mat_t) + self.fgs.cib_c(self.evalells[ii],fq_mat,fq_mat_t)) \
                     / self.cc.c['TCMBmuK']**2. / ((self.evalells[ii]+1.)*self.evalells[ii]) * 2.* np.pi

            N_ll_for_tsz = nells + totfg + cmb_els + ksz
            N_ll_for_cmb = nells + totfg + tsz + ksz
            N_ll_for_rsx = nells + totfg + tsz + ksz + cmb_els
            N_ll_for_rsxEE = nells + fgrspol + cmb_ee

            N_ll_for_tsz_c_cmb = nells + totfg
            N_ll_for_cmb_c_tsz = N_ll_for_tsz_c_cmb + ksz
            N_ll_for_tsz_c_cib = nells + totfg_cib + cmb_els + ksz

            N_ll_for_tsz_inv = np.linalg.inv(N_ll_for_tsz)
            N_ll_for_cmb_inv = np.linalg.inv(N_ll_for_cmb)
            N_ll_for_rsx_inv = np.linalg.inv(N_ll_for_rsx)
            N_ll_for_tsz_c_cmb_inv = np.linalg.inv(N_ll_for_tsz_c_cmb)
            N_ll_for_cmb_c_tsz_inv = N_ll_for_tsz_c_cmb_inv
            N_ll_for_tsz_c_cib_inv = np.linalg.inv(N_ll_for_tsz_c_cib)

            N_ll_noFG = nells

            self.W_ll_tsz[ii, :] = weightcalculator(f_nu_tsz, N_ll_for_tsz)
            self.W_ll_rsx[ii, :] = weightcalculator(f_nu_rsx, N_ll_for_rsx)
            self.W_ll_rsx_NF[ii, :] = weightcalculator(f_nu_rsx, N_ll_noFG)
            self.W_ll_rsxEE[ii, :] = weightcalculator(f_nu_rsx, N_ll_for_rsxEE)
            self.W_ll_cmb[ii, :] = weightcalculator(f_nu_cmb, N_ll_for_cmb)
            self.N_ll_tsz[ii] = np.dot(
                np.transpose(self.W_ll_tsz[ii, :]),
                np.dot(N_ll_for_tsz, self.W_ll_tsz[ii, :]))
            self.N_ll_cmb[ii] = np.dot(
                np.transpose(self.W_ll_cmb[ii, :]),
                np.dot(N_ll_for_cmb, self.W_ll_cmb[ii, :]))
            self.N_ll_rsx[ii] = np.dot(
                np.transpose(self.W_ll_rsx[ii, :]),
                np.dot(N_ll_for_rsx, self.W_ll_rsx[ii, :]))
            self.N_ll_rsxEE[ii] = np.dot(
                np.transpose(self.W_ll_rsxEE[ii, :]),
                np.dot(N_ll_for_rsxEE, self.W_ll_rsxEE[ii, :]))
            self.N_ll_rsx_NoFG[ii] = np.dot(
                np.transpose(self.W_ll_rsx_NF[ii, :]),
                np.dot(N_ll_noFG, self.W_ll_rsx_NF[ii, :]))
            self.W_ll_tsz_c_cmb[ii, :] = constweightcalculator(
                f_nu_cmb, f_nu_tsz, N_ll_for_tsz_c_cmb_inv)
            self.W_ll_tsz_c_cib[ii, :] = constweightcalculator(
                f_nu_cib, f_nu_tsz, N_ll_for_tsz_c_cib_inv)
            self.W_ll_cmb_c_tsz[ii, :] = constweightcalculator(
                f_nu_tsz, f_nu_cmb, N_ll_for_cmb_c_tsz_inv)
            self.N_ll_tsz_c_cmb[ii] = np.dot(
                np.transpose(self.W_ll_tsz_c_cmb[ii, :]),
                np.dot(N_ll_for_tsz_c_cmb, self.W_ll_tsz_c_cmb[ii, :]))
            self.N_ll_cmb_c_tsz[ii] = np.dot(
                np.transpose(self.W_ll_cmb_c_tsz[ii, :]),
                np.dot(N_ll_for_cmb_c_tsz, self.W_ll_cmb_c_tsz[ii, :]))
            self.N_ll_tsz_c_cib[ii] = np.dot(
                np.transpose(self.W_ll_tsz_c_cib[ii, :]),
                np.dot(N_ll_for_tsz_c_cib, self.W_ll_tsz_c_cib[ii, :]))
            '''