Esempio n. 1
0
def dust_ps(A_d, beta_d, lbin, nu=np.array([95, 150]), nu0=353, T_d=19.6):
    '''
    Input
    -------------------------
    A_d : PS template at reference frequency at each lbin; Using Namaster within corresponding mask. Input in **uK_RJ** units.
    beta_d : spectra index to be determined from likelihood analyis.
    
    Output
    -------------------------
    Cross power spectra for dust component, output in **uK_CMB** units.
    
    '''
    Nf = len(nu)
    coeff = convert_units("uK_RJ", "uK_CMB", nu)
    dl = np.ones((lbin, Nf, Nf))

    b0 = pf(nu0, T_d)
    b12 = pf(nu, T_d)

    factors = np.ones((Nf, Nf))
    for i in range(Nf):
        for j in range(Nf):
            factors[i][j] = b12[i] * b12[j] / b0**2

    for ell in range(lbin):

        for i in range(Nf):
            for j in range(Nf):

                dl[ell, i, j] = A_d[ell] * (nu[i] * nu[j] / nu0**2)**(
                    beta_d - 2) * factors[i, j] * coeff[i] * coeff[j]

    return dl
Esempio n. 2
0
def corre_fore_simple(epsilon,
                      A_d,
                      A_s,
                      beta_s,
                      beta_d,
                      lbin,
                      nu=np.array([95, 150]),
                      nu_s0=30,
                      nu_d0=353):
    '''
    correlation of dust and synchrotron;
    Input
    ---------------------------
    same as above.
    
    epsilon, A_d, A_s, beta_s, beta_d, lbin, nu = np.array([95, 150]), nu_s0 = 30, nu_d0 = 353
    '''

    Nf = len(nu)
    coeff = convert_units("uK_RJ", "uK_CMB", nu)

    fl = np.ones((lbin, Nf, Nf))

    for ell in range(lbin):
        for i in range(Nf):
            for j in range(Nf):

                fl[ell, i, j] = epsilon * np.sqrt(A_s[ell] * A_d[ell]) * (
                    f_d(nu[i], beta_d) * f_s(nu[j], beta_s) +
                    f_d(nu[j], beta_d) *
                    f_s(nu[i], beta_s)) * coeff[i] * coeff[j]

    return fl
Esempio n. 3
0
def corre_fore_complex(epsilon,
                       A_d,
                       A_s,
                       ells,
                       alpha_s,
                       alpha_d,
                       beta_s,
                       beta_d,
                       nu=np.array([95, 150]),
                       nu_s0=30,
                       nu_d0=353):

    Nf = len(nu)
    lbin = len(ells)
    coeff = convert_units("uK_RJ", "uK_CMB", nu)

    fl = np.ones((lbin, Nf, Nf))

    f = epsilon * np.sqrt(A_s * A_d)

    for ell in range(lbin):
        for i in range(Nf):
            for j in range(Nf):

                fl[ell, i,
                   j] = f * (ells[ell] / 71.5)**((alpha_s + alpha_d) / 2) * (
                       f_d(nu[i], beta_d) * f_s(nu[j], beta_s) +
                       f_d(nu[j], beta_d) *
                       f_s(nu[i], beta_s)) * coeff[i] * coeff[j]

    return fl
Esempio n. 4
0
def sync_ps(A_s, beta_s, lbin, nu=np.array([95, 150]), nu0=30):
    '''
    Input
    -------------------------
    A_s : PS template at reference frequency at each lbin; input in **uK_RJ** units.
    beta_s : spectra index to be determined from likelihood analyis.
    
    Output
    -------------------------
    Cross power spectra for dust component, output in **uK_CMB** units.
    
    '''

    Nf = len(nu)
    coeff = convert_units("uK_RJ", "uK_CMB", nu)
    sl = np.ones((lbin, Nf, Nf))

    for ell in range(lbin):

        for i in range(Nf):
            for j in range(Nf):
                sl[ell, i,
                   j] = A_s[ell] * (nu[i] * nu[j] /
                                    nu0**2)**(beta_s) * coeff[i] * coeff[j]

    return sl
Esempio n. 5
0
def simulation(nside):
    print '########Simulating#######'
    c1_config = models("c1", nside)       
    s1_config = models("s1", nside)
    d1_config = models("d1", nside)
    f1_config = models("f1", nside)
    a1_config = models("a1", nside)
    sky_config = {
        'synchrotron' : s1_config,
        'dust' : d1_config,
        'freefree' : f1_config,
        'cmb' : c1_config,
        'ame' : a1_config
    }
    sky = pysm.Sky(sky_config) 
    
    global wn, cmb_MASKED, coefficients,mask,cmb
    nu = np.array([30., 44., 70., 95., 150., 217., 353., 545., 857.]) 
    coefficients = convert_units("uK_RJ", "uK_CMB", nu)
     
    #dust = sky.dust(nu);synchrotron = sky.synchrotron(nu);freefree = sky.freefree(nu)
    #cmb = sky.cmb(nu); ame = sky.ame(nu)
    #np.save('../simulation/Nside = 1024/dust_map.npy',convert_unit(dust)); np.save('../simulation/Nside = 1024/synchro_map.npy',convert_unit(synchrotron));
    #np.save('../simulation/Nside = 1024/9_fre/cmb_map.npy',convert_unit(cmb)); #np.save('../simulation/Nside = 1024/freefree_map.npy',convert_unit(freefree));
    #np.save('../simulation/Nside = 1024/ame_map.npy',convert_unit(ame))
    
    total = sky.signal()(nu)
    #total = (total - cmb)*0.7 + cmb         #decrease the foreground 
    np.save('../simulation/Nside = 1024/9_fre/total_map.npy',convert_unit(total))
Esempio n. 6
0
import pysm
from pysm.nominal import models
import numpy as np
import healpy as hp
import matplotlib.pyplot as plt
import matplotlib as mpl
from pysm.common import convert_units
from NPTFit import create_mask as cm
import matplotlib.style
mpl.style.use('classic')

nside = 128
nu = np.logspace(np.log10(30), np.log10(400), 30)
Nf = len(nu)
coefficients = convert_units("uK_RJ", "uK_CMB", nu)


def convert_unit(map):
    for i in range(0, Nf):
        map[i] = map[i] * coefficients[i]
    return map


def B_map(maps):
    alms = hp.map2alm(maps)
    Bmap = hp.alm2map(alms[2], nside=nside, verbose=False)
    return Bmap


s_rms = []
d_rms = []
SamNum = 100;

beams = [19, 11];
fres = [95, 150]; Nf = len(fres);

cpn = np.zeros((Nf, 2, 12*nside**2)); ## CMB plus noise
total = np.zeros((Nf, 2, 12*nside**2));
cl_f_all = np.ones((SamNum, 3, lbin, Nf, Nf))
nl_all = np.zeros((SamNum, 3, lbin, Nf, Nf))
Noise = np.zeros((Nf, 2, 12*nside**2))
cl_hat_all = np.ones((SamNum, 3, lbin, Nf, Nf))
#### foreground ####
sky_config = {'dust':models('d1', nside), 'synchrotron':models('s1', nside)}
sky = pysm.Sky(sky_config);
c95 = convert_units("uK_RJ", "uK_CMB", 95);
c150 = convert_units("uK_RJ", "uK_CMB", 150);

s30 = sky.synchrotron(30); 
d353 = sky.dust(353);

fore_maps = sky.signal()(np.array(fres))

fore_maps[0] *= c95;
fore_maps[1] *= c150

ali_ma = hp.read_map('/fnx/jianyao/Likelihood_data/ABSData/ali_mask.fits', field = None)

# ali_ma = hp.read_map('/fnx/jianyao/DataChallenge/AncillaryData/AliCPTWhiteNoiseMatrix/BINARYMASK_95_C_1024.fits', field=None, verbose = False)
# hit = hp.read_map('/fnx/jianyao/DataChallenge/AliCPT/HITMAP.fits',dtype=np.int,verbose=0)
# extra_ratio = 0.3
Esempio n. 8
0
    def testConvert_Units(self):
        a1 = common.convert_units("K_CMB", "uK_RJ", 300.)
        a2 = common.convert_units("uK_RJ", "K_CMB", 300.)
        self.assertAlmostEqual(1., a1 * a2)
        a1 = common.convert_units("K_CMB", "MJysr", 300.)
        a2 = common.convert_units("MJysr", "K_CMB", 300.)
        self.assertAlmostEqual(1., a1 * a2)
        """Validation against ECRSC tables.
        https://irsasupport.ipac.caltech.edu/index.php?/Knowledgebase/
        Article/View/181/20/what-are-the-intensity-units-of-the-planck
        -all-sky-maps-and-how-do-i-convert-between-them
        These tables are based on the following tables: 
        h = 6.626176e-26 erg*s
        k = 1.380662e-16 erg/L
        c = 2.997792458e1- cm/s
        T_CMB = 2.726
        The impact of the incorrect CMB temperature is especially impactful
        and limits some comparison to only ~2/3 s.f.
        """

        uK_CMB_2_K_RJ_30 = 9.77074e-7
        uK_CMB_2_K_RJ_143 = 6.04833e-7
        uK_CMB_2_K_RJ_857 = 6.37740e-11

        self.assertAlmostEqual(uK_CMB_2_K_RJ_30,
                               common.convert_units("uK_CMB", "K_RJ", 30.))
        self.assertAlmostEqual(uK_CMB_2_K_RJ_143,
                               common.convert_units("uK_CMB", "K_RJ", 143.))
        self.assertAlmostEqual(uK_CMB_2_K_RJ_857,
                               common.convert_units("uK_CMB", "K_RJ", 857.))

        K_CMB_2_MJysr_30 = 27.6515
        K_CMB_2_MJysr_143 = 628.272
        K_CMB_2_MJysr_857 = 22565.1

        self.assertAlmostEqual(K_CMB_2_MJysr_30 /
                               common.convert_units("K_RJ", "MJysr", 30.),
                               1.,
                               places=4)
        self.assertAlmostEqual(K_CMB_2_MJysr_143 /
                               common.convert_units("K_RJ", "MJysr", 143.),
                               1.,
                               places=4)
        self.assertAlmostEqual(K_CMB_2_MJysr_857 /
                               common.convert_units("K_RJ", "MJysr", 857.),
                               1.,
                               places=4)

        uK_CMB_2_MJysr_30 = 2.7e-5
        uK_CMB_2_MJysr_143 = 0.0003800
        uK_CMB_2_MJysr_857 = 1.43907e-6

        #Note that the MJysr definition seems to match comparatively poorly. The
        #definitions of h, k, c in the document linked above are in cgs and differ
        #from those on wikipedia. This may conflict with the scipy constants I use.

        self.assertAlmostEqual(uK_CMB_2_MJysr_30 /
                               common.convert_units("uK_CMB", "MJysr", 30.),
                               1.,
                               places=2)
        self.assertAlmostEqual(uK_CMB_2_MJysr_143 /
                               common.convert_units("uK_CMB", "MJysr", 143.),
                               1.,
                               places=2)
        self.assertAlmostEqual(uK_CMB_2_MJysr_857 /
                               common.convert_units("uK_CMB", "MJysr", 857.),
                               1.,
                               places=2)
Esempio n. 9
0
fwhmpix = pixelization[n][1]
Apix = hp.nside2pixarea(nside)  #square radians
fwhmrad = np.sqrt(Apix) * fwhmpix
sigma = fwhmpix / 2.355482
#sky config with the principal models for each component
sky_config = {
    'synchrotron': models("s1", nside),
    'dust': models("d1", nside),
    'freefree': models("f1", nside),
    'ame': models("a1", nside),
    'cmb': models("c1", nside)
}

sky = pysm.Sky(sky_config)
#unit conversion factor
mapFactor = convert_units("uK_RJ", "uK_CMB", nu)
sourceFactor = convert_units("Jysr", "uK_CMB", nu)
allmaps = sky.signal()(nu)

if verbose:
    print('Microwave sky simulated')

T = np.array(allmaps[0], dtype=float) * mapFactor
Q = np.array(allmaps[1], dtype=float) * mapFactor
U = np.array(allmaps[2], dtype=float) * mapFactor
#smoothing with gaussian psf
t = hp.smoothing(map_in=T, fwhm=fwhmrad, verbose=False)
q = hp.smoothing(map_in=Q, fwhm=fwhmrad, verbose=False)
u = hp.smoothing(map_in=U, fwhm=fwhmrad, verbose=False)
if verbose:
    print('Maps smoothed')
Esempio n. 10
0
    if verbose:
        print('FWHM ' + str(h + 1) + '/' + str(len(fwhmpix)))

    lsize = int(nside[h] / 4)
    centralpix = int(lsize / 2)
    Apix = hp.nside2pixarea(nside[h])
    sigma = fwhmpix[h] / 2.355482
    R = np.array(Rcal) * sigma
    pE = np.zeros((len(phiStokes), len(R)), dtype=float)
    phiE = np.zeros((len(phiStokes), len(R)), dtype=float)
    phiB = np.zeros((len(phiStokes), len(R)), dtype=float)
    pB = np.zeros((len(phiStokes), len(R)), dtype=float)
    #point-like sources
    sourcesE = []
    sourcesB = []
    Pi = (F * polDegree * convert_units("Jysr", "uK_CMB", nu)) / Apix
    if verbose:
        print('Computing source images')

    progressCount = 0
    prevProgress = 0
    for l in np.arange(0, len(phiStokes), 1):
        sE = np.zeros((lsize, lsize), dtype=float)
        sB = np.zeros((lsize, lsize), dtype=float)
        #coordinates origin in [centralpix,centralpix]
        for i in np.arange(0, lsize, 1, dtype=int):
            for j in np.arange(0, lsize, 1, dtype=int):
                #x,y with sign of each quadrant
                y = i - centralpix
                x = j - centralpix
                r2 = x**2 + y**2
Esempio n. 11
0
    def testConvert_Units(self):
        a1 = common.convert_units("K_CMB", "uK_RJ", 300.)
        a2 = common.convert_units("uK_RJ", "K_CMB", 300.)
        self.assertAlmostEqual(1., a1 * a2)
        a1 = common.convert_units("K_CMB", "MJysr", 300.)
        a2 = common.convert_units("MJysr", "K_CMB", 300.)
        self.assertAlmostEqual(1., a1 * a2)
        
        """Validation against ECRSC tables.
        https://irsasupport.ipac.caltech.edu/index.php?/Knowledgebase/
        Article/View/181/20/what-are-the-intensity-units-of-the-planck
        -all-sky-maps-and-how-do-i-convert-between-them
        These tables are based on the following tables: 
        h = 6.626176e-26 erg*s
        k = 1.380662e-16 erg/L
        c = 2.997792458e1- cm/s
        T_CMB = 2.726
        The impact of the incorrect CMB temperature is especially impactful
        and limits some comparison to only ~2/3 s.f.
        """

        uK_CMB_2_K_RJ_30 = 9.77074e-7
        uK_CMB_2_K_RJ_143 = 6.04833e-7
        uK_CMB_2_K_RJ_857 = 6.37740e-11

        self.assertAlmostEqual(uK_CMB_2_K_RJ_30, common.convert_units("uK_CMB", "K_RJ", 30.))
        self.assertAlmostEqual(uK_CMB_2_K_RJ_143, common.convert_units("uK_CMB", "K_RJ", 143.))
        self.assertAlmostEqual(uK_CMB_2_K_RJ_857, common.convert_units("uK_CMB", "K_RJ", 857.))

        K_CMB_2_MJysr_30 = 27.6515 
        K_CMB_2_MJysr_143 = 628.272 
        K_CMB_2_MJysr_857 = 22565.1

        self.assertAlmostEqual(K_CMB_2_MJysr_30 / common.convert_units("K_RJ", "MJysr", 30.), 1., places = 4)
        self.assertAlmostEqual(K_CMB_2_MJysr_143 / common.convert_units("K_RJ", "MJysr", 143.), 1., places = 4)
        self.assertAlmostEqual(K_CMB_2_MJysr_857 / common.convert_units("K_RJ", "MJysr", 857.), 1., places = 4)
        
        uK_CMB_2_MJysr_30 = 2.7e-5
        uK_CMB_2_MJysr_143 = 0.0003800
        uK_CMB_2_MJysr_857 = 1.43907e-6

        #Note that the MJysr definition seems to match comparatively poorly. The
        #definitions of h, k, c in the document linked above are in cgs and differ
        #from those on wikipedia. This may conflict with the scipy constants I use.

        self.assertAlmostEqual(uK_CMB_2_MJysr_30 / common.convert_units("uK_CMB", "MJysr", 30.), 1., places = 2)
        self.assertAlmostEqual(uK_CMB_2_MJysr_143 / common.convert_units("uK_CMB", "MJysr", 143.), 1., places = 2)
        self.assertAlmostEqual(uK_CMB_2_MJysr_857 / common.convert_units("uK_CMB", "MJysr", 857.), 1., places = 2)
Esempio n. 12
0
else:
    n=2
    
if k not in [1,2,3]:
    print('Index for noise level not supported.')
    exit()    

sigma_noise=noiseLevels[n][k-1]
#the error is only known for one filter scale
R=1

#read fwhm
words3=calibName.split()
fwhmpix=float(words3[3])
nside=int(words3[1])
convFac=convert_units("uK_CMB","Jysr",nu)
sigma=fwhmpix/2.355482 
#load maps    
emap=np.load('patches/'+mapName+'/'+mapName+'_E.npy')   
bmap=np.load('patches/'+mapName+'/'+mapName+'_B.npy')    
if verbose:
    print('E and B patches correctly readed')

#load calibration functions
fE=np.load('config/E phi '+calibName+'.npy')
fB=np.load('config/B phi '+calibName+'.npy')
gE=np.load('config/E p '+calibName+'.npy')
gB=np.load('config/B p '+calibName+'.npy')
phiEcal=np.load('config/phi E '+calibName+'.npy')
phiBcal=np.load('config/phi B '+calibName+'.npy')
Rcal=np.arange(0.4,2.2,0.05)