Пример #1
0
def rewrite_mask_files(pskys=[40,60,70,80],
                       mask_sources=True,
                       apodization=2,
                       smask_name='HFI_Mask_PointSrc_2048_R2.00.fits'):
    for psky in pskys:
        maskfile = pf.PLANCK_DATA_PATH + 'mask_psky{}_apo{}.fits'.format(psky,apodization)
        mask = pf.get_planck_mask(psky=psky,
                              mask_sources=mask_sources,
                              apodization=apodization,
                              smask_name=smask_name)

        hp.write_map(maskfile, mask)
Пример #2
0
def rewrite_mask_files(pskys=[40, 60, 70, 80],
                       mask_sources=True,
                       apodization=2,
                       smask_name='HFI_Mask_PointSrc_2048_R2.00.fits'):
    for psky in pskys:
        maskfile = pf.PLANCK_DATA_PATH + 'mask_psky{}_apo{}.fits'.format(
            psky, apodization)
        mask = pf.get_planck_mask(psky=psky,
                                  mask_sources=mask_sources,
                                  apodization=apodization,
                                  smask_name=smask_name)

        hp.write_map(maskfile, mask)
Пример #3
0
def b_cov_T353_E143_B143(cl_file=pf.PLANCK_DATA_PATH+'bf_base_cmbonly_plikHMv18_TT_lowTEB_lmax4000.minimum.theory_cl',lmax=100):

    Imap = hp.read_map(pf.PLANCK_DATA_PATH + 'HFI_SkyMap_353_2048_R2.02_full.fits')
    Tlm = hp.map2alm(Imap,lmax=lmax)
    cltt = hp.alm2cl(Tlm,lmax=lmax)

    mask = pf.get_planck_mask(psky=70)
    Qmap, Umap = hp.read_map(pf.PLANCK_DATA_PATH + 'HFI_SkyMap_143_2048_R2.02_full.fits',field=(1,2))
    Elm, Blm = hp.map2alm_spin( (Qmap*mask,Umap*mask), 2, lmax=lmax )
    clee = hp.alm2cl(Elm,lmax=lmax)
    clbb = hp.alm2cl(Blm,lmax=lmax)

    cov = calc_b_cov_TEB(cltt, clee, clbb)
    return cov
Пример #4
0
def b_cov_TEB(lmax=100,frequency=353):
    """this one is map-based"""

    Imap,Qmap, Umap = hp.read_map(pf.PLANCK_DATA_PATH + 'HFI_SkyMap_{}_2048_R2.02_full.fits'.format(frequency),field=(0,1,2))
    mask = pf.get_planck_mask()
    Tlm = hp.map2alm(Imap*mask,lmax=lmax)
    cltt = hp.alm2cl(Tlm,lmax=lmax)

    Elm, Blm = hp.map2alm_spin( (Qmap*mask,Umap*mask), 2, lmax=lmax )
    clee = hp.alm2cl(Elm,lmax=lmax)
    clbb = hp.alm2cl(Blm,lmax=lmax)

    #hs = get_hs(lmax=100)
    cov = calc_b_cov_TEB(cltt, clee, clbb)#/hs
    return cov
from process_fullsky import simulate_observed_map, calc_alm, get_planck_mask

frequencies = [353]  #[100,143,353,217]

filebase = sys.argv[1]

smear = True
mask_sources = True
nside = 2048
psky = 70
apodization = 2
lmax = 2000
lmax_bispectrum = 200

mask = get_planck_mask(psky=psky,
                       mask_sources=mask_sources,
                       apodization=apodization,
                       smask_name='HFI_Mask_PointSrc_2048_R2.00.fits')

#get the raw alms:
filename_cmb = FGS_SIM_PATH + 'alms/' + '{}_cmb_alm_lmax{}.npz'.format(
    filebase, lmax)
filename_fg = FGS_SIM_PATH + 'alms/' + '{}_fg_alm_lmax{}.npz'.format(
    filebase, lmax)
d = np.load(filename_cmb)
Tlm_cmb = d['Tlm']
Elm_cmb = d['Elm']
Blm_cmb = d['Blm']

alms_cmb = np.array([Tlm_cmb, Elm_cmb, Blm_cmb])

d = np.load(filename_fg)
Пример #6
0
from process_fullsky import PLANCK_DATA_PATH,calc_alm,get_planck_mask
import healpy as hp

frequencies = [353]#[100,143,353,217]

smear = True
mask_sources = True
nside=2048
psky = 70
apodization = 2

lmax_bispectrum = 199


mask = get_planck_mask(psky=psky,
                mask_sources=mask_sources,
                apodization=apodization,
                smask_name='HFI_Mask_PointSrc_2048_R2.00.fits')

for f in frequencies:
    outfilename = PLANCK_DATA_PATH + 'bispectrum_alms/' + 'data_planck_{}GHz_lmax{}'.format(f,lmax_bispectrum)
    mapname = PLANCK_DATA_PATH + 'HFI_SkyMap_{}_2048_R2.02_full.fits'.format(f)
    print 'reading map from file: {} ...'.format(mapname)
    I,Q,U = hp.read_map(mapname, field=(0,1,2))
    Tlm,Elm,Blm = calc_alm(I, Q, U, mask=mask,
                        lmax=lmax_bispectrum,add_beam=None,div_beam=None,
                        healpy_format=False)

    np.save(outfilename + '_Tlm.npy', Tlm)
    np.save(outfilename + '_Elm.npy', Elm)
    np.save(outfilename + '_Blm.npy', Blm)
Пример #7
0
def calibrate_fsky(mode,
                   nsim=1,
                   smear=True,
                   apo=2,
                   psky=70,
                   f=353,
                   nside=2048,
                   lmax=1000,
                   visual_check=False,
                   beam_file=pf.PLANCK_DATA_PATH +
                   'HFI_RIMO_Beams-100pc_R2.00.fits',
                   mask_sources=True,
                   put_mask=True):
    """No noise treatment here"""

    fsky_correction = []
    TTm = np.zeros(lmax + 1)
    EEm = np.zeros(lmax + 1)
    BBm = np.zeros(lmax + 1)

    if put_mask:
        print 'reading mask...'
        mask = pf.get_planck_mask(psky=psky,
                                  mask_sources=mask_sources,
                                  apodization=apo)
    else:
        mask = None
    print 'reading beams...'
    hdulist = pf.fits.open(beam_file)
    beam = hdulist[pf.BEAM_INDEX['{}'.format(f)]].data.NOMINAL[0][:lmax + 1]
    beamP = hdulist[pf.BEAM_INDEX['{}P'.format(f)]].data.NOMINAL[0][:lmax + 1]
    beam = beam[:lmax + 1]
    beamP = beamP[:lmax + 1]

    if mode == 'fg':
        ls, cls_theory = get_theory_fg(f=f, lmax=lmax, psky=psky, apo=apo)
    if mode == 'cmb':
        ls, cls_theor = pf.get_theory_cmb(lmax=lmax, mode='cl')
        factor = ls * (1 + ls)

    for i in np.arange(nsim):
        print 'sim #{}...'.format(i + 1)
        I, Q, U = pf.simulate_cmb_map(nside=nside,
                                      lmax=lmax,
                                      frequency=f,
                                      smear=smear,
                                      cls_theory=cls_theory,
                                      beam=beam,
                                      beamP=beamP,
                                      save=False,
                                      beam_file=None)
        print 'Cl #{}...'.format(i + 1)
        Tlm, Elm, Blm = pf.calc_alm(I,
                                    Q,
                                    U,
                                    mask=mask,
                                    lmax=lmax,
                                    add_beam=None,
                                    add_beamP=None,
                                    div_beam=beam,
                                    div_beamP=beamP,
                                    healpy_format=True)
        TT = hp.alm2cl(Tlm)
        EE = hp.alm2cl(Elm)
        BB = hp.alm2cl(Blm)

        #ls, TT, EE, BB, TE, TB, EB = measure_dlcl(mask=mask, Imap=I, Qmap=Q, Umap=U,
        #                                          beam=beam, beamP=beamP,
        #                                            mode='cl',frequency=f,
        #                                            lmax=lmax,lmin=0,
        #                                            put_mask=put_mask,
        #                                            psky=psky,
        #                                            mask_sources=mask_sources,
        #                                            apodization=apo)
        TTm += TT / nsim
        EEm += EE / nsim
        BBm += BB / nsim

        if visual_check:
            hp.mollview(I)
            hp.mollview(Q)
            hp.mollview(U)

    fsky_correction.append(cls_theory[0] / TTm)
    fsky_correction.append(cls_theory[1] / EEm)
    fsky_correction.append(cls_theory[2] / BBm)

    fsky_correction = np.array(fsky_correction)
    fsky_correction[np.isnan(fsky_correction)] = 0.
    fsky_correction[fsky_correction == np.inf] = 0.

    return ls, fsky_correction, TTm, EEm, BBm, cls_theory
Пример #8
0
def measure_dlcl(mode='dl',
                 frequency=353,
                 mask=None,
                 lmax=600,
                 lmin=40,
                 put_mask=True,
                 psky=70,
                 mask_sources=True,
                 apodization=2,
                 beam=None,
                 beamP=None,
                 Imap=None,
                 Qmap=None,
                 Umap=None,
                 Imap2=None,
                 Qmap2=None,
                 Umap2=None,
                 fsky_correction=True):
    """
       If mode=='dl', returns D quantity = Cl *ls*(ls+1)/2./np.pi*1e12 [units: uK_CMB^2]
    """

    if put_mask:
        if mask is None:
            print 'reading masks...'
            mask = pf.get_planck_mask(psky=psky,
                                      mask_sources=mask_sources,
                                      apodization=apodization)
    else:
        mask = map.copy() * 0. + 1.

    if (beam is None) or (beamP is None):
        print 'reading beams...'
        beam_file = pf.PLANCK_DATA_PATH + 'HFI_RIMO_Beams-100pc_R2.00.fits'
        hdulist = pf.fits.open(beam_file)
        beam = hdulist[pf.BEAM_INDEX['{}'.format(
            frequency)]].data.NOMINAL[0][:lmax + 1]
        beamP = hdulist[pf.BEAM_INDEX['{}P'.format(
            frequency)]].data.NOMINAL[0][:lmax + 1]
        beam = beam[lmin:lmax + 1]
        beamP = beamP[lmin:lmax + 1]

    fsky = mask.sum() / len(mask)
    ls = np.arange(lmin, lmax + 1)
    if mode == 'dl':
        factor = ls * (ls + 1) / (2. * np.pi) * 1e12 / fsky
    if mode == 'cl':
        factor = 1. / fsky

    if fsky_correction:
        fcfilename = pf.FGS_RESULTS_PATH + 'fskycorr_fg_psky{}_apo{}_lmax1000_TT_EE_BB.npy'.format(
            psky, apodization)
        if os.path.exists(fcfilename):
            fcorr = np.load(fcfilename)
            fcorr_TT = fcorr[0][lmin:lmax + 1]
            fcorr_EE = fcorr[1][lmin:lmax + 1]
            fcorr_BB = fcorr[2][lmin:lmax + 1]
        else:
            fcorr = None
    else:
        fcorr = None

    if (Imap is None) or (Qmap is None) or (Umap is None):
        print 'reading maps...'
        mapname1 = pf.PLANCK_DATA_PATH + 'HFI_SkyMap_{}_2048_R2.02_halfmission-1.fits'.format(
            frequency)
        mapname2 = pf.PLANCK_DATA_PATH + 'HFI_SkyMap_{}_2048_R2.02_halfmission-2.fits'.format(
            frequency)
        Imap = hp.read_map(mapname1, field=0)
        Imap2 = hp.read_map(mapname2, field=0)
        Qmap, Umap = hp.read_map(mapname1, field=(1, 2))
        Qmap2, Umap2 = hp.read_map(mapname2, field=(1, 2))

    Tlm1 = hp.map2alm(Imap * mask, lmax=lmax)
    Elm1, Blm1 = hp.map2alm_spin((Qmap * mask, Umap * mask), 2, lmax=lmax)
    if (Imap2 is None) or (Qmap2 is None) or (Umap2 is None):
        Tlm2 = Tlm1
        Elm2 = Elm1
        Blm2 = Blm1
    else:
        Tlm2 = hp.map2alm(Imap2 * mask, lmax=lmax)
        Elm2, Blm2 = hp.map2alm_spin((Qmap2 * mask, Umap2 * mask),
                                     2,
                                     lmax=lmax)

    TT = hp.alm2cl(Tlm1, Tlm2)
    EE = hp.alm2cl(Elm1, Elm2)
    BB = hp.alm2cl(Blm1, Blm2)

    EE = EE[lmin:] * factor / beamP**2
    TT = TT[lmin:] * factor / beam**2
    BB = BB[lmin:] * factor / beamP**2

    TE = hp.alm2cl(Tlm1, Elm2)
    EB = hp.alm2cl(Blm1, Elm2)
    TB = hp.alm2cl(Blm1, Tlm2)
    TE = TE[lmin:] * factor / beam / beamP
    TB = TB[lmin:] * factor / beam / beamP
    EB = EB[lmin:] * factor / beamP**2

    if fcorr is not None:
        TT *= fcorr_TT
        EE *= fcorr_EE
        BB *= fcorr_BB

    return ls, TT, EE, BB, TE, TB, EB
Пример #9
0
def calibrate_fsky(mode, nsim=1,
                   smear=True,apo=2,
                    psky=70, f=353, 
                    nside=2048,lmax=1000,
                    visual_check=False,
                    beam_file=pf.PLANCK_DATA_PATH+'HFI_RIMO_Beams-100pc_R2.00.fits',
                    mask_sources=True, put_mask=True):

    """No noise treatment here"""

    fsky_correction = []
    TTm = np.zeros(lmax + 1)
    EEm = np.zeros(lmax + 1)
    BBm = np.zeros(lmax + 1)
    
    if put_mask:
        print 'reading mask...'
        mask = pf.get_planck_mask(psky=psky,
                                mask_sources=mask_sources,
                                apodization=apo)
    else:
        mask = None
    print 'reading beams...'
    hdulist = pf.fits.open(beam_file)
    beam = hdulist[pf.BEAM_INDEX['{}'.format(f)]].data.NOMINAL[0][:lmax+1]
    beamP = hdulist[pf.BEAM_INDEX['{}P'.format(f)]].data.NOMINAL[0][:lmax+1]
    beam = beam[:lmax+1]
    beamP = beamP[:lmax+1]

    if mode == 'fg':
        ls, cls_theory = get_theory_fg(f=f, lmax=lmax, psky=psky, apo=apo)
    if mode == 'cmb':
        ls, cls_theor = pf.get_theory_cmb(lmax=lmax, mode='cl')
        factor = ls*(1+ls)
        
    for i in np.arange(nsim):
        print 'sim #{}...'.format(i+1)
        I, Q, U = pf.simulate_cmb_map(nside=nside, lmax=lmax,
                                    frequency=f,smear=smear,
                                    cls_theory=cls_theory,
                                    beam=beam, beamP=beamP,
                                    save=False,
                                    beam_file=None)
        print 'Cl #{}...'.format(i+1)
        Tlm, Elm, Blm = pf.calc_alm(I, Q, U, mask=mask,
                                    lmax=lmax,
                                    add_beam=None,add_beamP=None,
                                    div_beam=beam,div_beamP=beamP,
                                    healpy_format=True)
        TT = hp.alm2cl(Tlm)
        EE = hp.alm2cl(Elm)
        BB = hp.alm2cl(Blm)
 
        #ls, TT, EE, BB, TE, TB, EB = measure_dlcl(mask=mask, Imap=I, Qmap=Q, Umap=U,
        #                                          beam=beam, beamP=beamP,
        #                                            mode='cl',frequency=f,
        #                                            lmax=lmax,lmin=0,
        #                                            put_mask=put_mask,
        #                                            psky=psky,
        #                                            mask_sources=mask_sources,
        #                                            apodization=apo)
        TTm += TT/nsim; EEm += EE/nsim; BBm += BB/nsim
        
        if visual_check:
            hp.mollview(I)
            hp.mollview(Q)
            hp.mollview(U)

    fsky_correction.append(cls_theory[0] / TTm)
    fsky_correction.append(cls_theory[1] / EEm)
    fsky_correction.append(cls_theory[2] / BBm)

    fsky_correction = np.array(fsky_correction)
    fsky_correction[np.isnan(fsky_correction)] = 0.
    fsky_correction[fsky_correction==np.inf] = 0.

    return ls, fsky_correction, TTm, EEm, BBm, cls_theory
Пример #10
0
def measure_dlcl(mode='dl',frequency=353,
                 mask=None,
              lmax=600,lmin=40,
              put_mask=True,
              psky=70,
              mask_sources=True,
              apodization=2,
              beam=None,beamP=None,
              Imap=None,Qmap=None,Umap=None,
              Imap2=None,Qmap2=None,Umap2=None,
              fsky_correction=True):

    """
       If mode=='dl', returns D quantity = Cl *ls*(ls+1)/2./np.pi*1e12 [units: uK_CMB^2]
    """

    
    if put_mask:
        if mask is None:
            print 'reading masks...'
            mask = pf.get_planck_mask(psky=psky,
                                mask_sources=mask_sources,
                                apodization=apodization)
    else:
        mask = map.copy()*0. + 1.

    if (beam is None) or (beamP is None):
        print 'reading beams...'
        beam_file = pf.PLANCK_DATA_PATH+'HFI_RIMO_Beams-100pc_R2.00.fits'
        hdulist = pf.fits.open(beam_file)
        beam = hdulist[pf.BEAM_INDEX['{}'.format(frequency)]].data.NOMINAL[0][:lmax+1]
        beamP = hdulist[pf.BEAM_INDEX['{}P'.format(frequency)]].data.NOMINAL[0][:lmax+1]
        beam = beam[lmin:lmax+1]
        beamP = beamP[lmin:lmax+1]

    fsky = mask.sum() / len(mask)
    ls = np.arange(lmin, lmax+1)
    if mode == 'dl':
        factor =  ls * (ls+1) / (2.*np.pi) * 1e12 / fsky
    if mode == 'cl':
        factor =  1. / fsky

    if fsky_correction:
        fcfilename = pf.FGS_RESULTS_PATH + 'fskycorr_fg_psky{}_apo{}_lmax1000_TT_EE_BB.npy'.format(psky,apodization)
        if os.path.exists(fcfilename):
            fcorr = np.load(fcfilename)
            fcorr_TT = fcorr[0][lmin:lmax+1]
            fcorr_EE = fcorr[1][lmin:lmax+1]
            fcorr_BB = fcorr[2][lmin:lmax+1]
        else:
            fcorr = None
    else:
        fcorr = None
    
    
    if (Imap is None) or (Qmap is None) or (Umap is None):
        print 'reading maps...'
        mapname1 = pf.PLANCK_DATA_PATH + 'HFI_SkyMap_{}_2048_R2.02_halfmission-1.fits'.format(frequency)
        mapname2 = pf.PLANCK_DATA_PATH + 'HFI_SkyMap_{}_2048_R2.02_halfmission-2.fits'.format(frequency)
        Imap = hp.read_map(mapname1,field=0)       
        Imap2 = hp.read_map(mapname2,field=0)
        Qmap, Umap = hp.read_map(mapname1,field=(1,2))
        Qmap2, Umap2 = hp.read_map(mapname2,field=(1,2))
   
    Tlm1 = hp.map2alm(Imap*mask, lmax=lmax)
    Elm1, Blm1 = hp.map2alm_spin( (Qmap*mask, Umap*mask), 2, lmax=lmax )
    if (Imap2 is None) or (Qmap2 is None) or (Umap2 is None):
        Tlm2 = Tlm1
        Elm2 = Elm1
        Blm2 = Blm1       
    else:
        Tlm2 = hp.map2alm(Imap2*mask, lmax=lmax)
        Elm2, Blm2 = hp.map2alm_spin( (Qmap2*mask,Umap2*mask), 2, lmax=lmax )


    TT = hp.alm2cl(Tlm1, Tlm2)
    EE = hp.alm2cl(Elm1, Elm2)
    BB = hp.alm2cl(Blm1, Blm2)

    EE = EE[lmin:] * factor / beamP**2
    TT = TT[lmin:] * factor / beam**2
    BB = BB[lmin:] * factor / beamP**2
    
    TE = hp.alm2cl(Tlm1, Elm2)
    EB = hp.alm2cl(Blm1, Elm2)
    TB = hp.alm2cl(Blm1, Tlm2)
    TE = TE[lmin:] * factor / beam / beamP
    TB = TB[lmin:] * factor / beam / beamP
    EB = EB[lmin:] * factor / beamP**2

    if fcorr is not None:
        TT *= fcorr_TT
        EE *= fcorr_EE
        BB *= fcorr_BB


    return ls, TT, EE, BB, TE, TB, EB