示例#1
0
def computeXCorrSNR(params):
    """
    @brief return the expected signal to noise ratio for a cross-correlation, 
    given data estimates of the two auto spectra and a theory estimate for the 
    cross correlation power spectrum

    @param params: dictionary containing the following:
            maps: list of names of map files (list)
            dataAuto_1: data file containing auto spectrum of map #1 (str)
            dataAuto_2: data file containing auto spectrum of map #2 (str)
            theoryCross: data file containng the theory cross spectrum (str) 
            
    @return s_to_n: the signal to noise ratio (float)        
    """

    # read in map coverage and compute f_sky
    f_sky = 0.0
    for mapFile in params['maps']:

        m = liteMap.liteMapFromFits(mapFile)
        inds = np.where(m.data != 0.0)[0]
        f_sky += m.pixScaleX*m.pixScaleY*len(inds)

    f_sky /= (4.*np.pi)

    # load the 1st data auto spectrum
    ell_1, cl_1 = np.loadtxt(params['dataAuto_1'], useCols=[0,1], unpack=True)

    # get the bin width in ell space, assuming constant bins
    dl = ell_1[1] - ell_1[0]

    # load the 2nd data auto spectrum
    ell_2, cl_2 = np.loadtxt(params['dataAuto_2'], useCols=[0,1], unpack=True)

    # load the theory cross spectrum
    ell_12, cl_12 = np.loadtxt(params['theoryCross'], useCols=[0,1], unpack=True)

    # put theory curve into same binning
    f = interp1d(ell_12, cl_12)
    cl_12 = f(ell_1)

    # loop over each ell bin to get S/N
    s_to_n = 0.0
    for i, ell in enumerate(ell_1):
        x = (2*ell*dl) * cl_12[i]**2 / (cl_1[i]*cl_2[i] + cl_12[i]**2)
        s_to_n += x

    s_to_n *= f_sky

    s_to_n = np.sqrt(s_to_n)

    return s_to_n
示例#2
0
    def cache_sim(self, idx):
        tfname_phi_fft = self.lib_dir + "/sim_" + ('%04d' % idx) + "_phi_fft.pk"
        tfname_teb_unl = self.lib_dir + "/sim_" + ('%04d' % idx) + "_teb_unl.pk"
        tfname_tqu_len = self.lib_dir + "/sim_" + ('%04d' % idx) + "_tqu_len.pk"

        assert( not os.path.exists(tfname_phi_fft) )
        assert( not os.path.exists(tfname_teb_unl) )
        assert( not os.path.exists(tfname_tqu_len) )

        self.phase.set_state(idx)
        teb_unl = sims.tebfft( self.pix, self.cl_unl )
        phi_fft = sims.rfft( self.pix, self.cl_unl.clpp )
        self.phase.check_state_final(idx)

        tqu_unl = teb_unl.get_tqu()
        tqu_len = ql.lens.make_lensed_map_flat_sky( tqu_unl, phi_fft )

        ## RA edits
        dustT = liteMap.liteMapFromFits( self.dust_dir + 'dustT.fits' ) ## Read in the dust map fits files
        dustQ = liteMap.liteMapFromFits( self.dust_dir + 'dustQ.fits' )
        dustU = liteMap.liteMapFromFits( self.dust_dir + 'dustU.fits' )

        assert self.pix.nx == dustT.Nx and self.pix.ny == dustT.Ny, 'Dust map incorrect size, check nx, ny'
        tqu_dust = ql.maps.tqumap( self.pix.nx, self.pix.dx, maps = [dustT.data, dustQ.data, dustU.data], ny = self.pix.ny, dy = self.pix.dy )
        tqu_len  += tqu_dust ## Now tqu_len contains lensed CMB + dust
        if not self.cmb:	## In this case, don't add cmb to the dust map
		tqu_len = tqu_dust
        ## RA edits done. 

        assert( not os.path.exists(tfname_phi_fft) )
        assert( not os.path.exists(tfname_teb_unl) )
        assert( not os.path.exists(tfname_tqu_len) )

        pk.dump( phi_fft, open(tfname_phi_fft, 'w') )
        pk.dump( teb_unl, open(tfname_teb_unl, 'w') )
        pk.dump( tqu_len, open(tfname_tqu_len, 'w') )
示例#3
0
def  LensedSimPolMaps(m0,ell,Cell_TT,Cell_EE,Cell_TE,Cell_BB=None,nUp=3,bufferFactor=1):
    
    
    m = liteMap.getEmptyMapWithDifferentDims(m0,m0.Ny*nUp,m0.Nx*nUp)
    
    T_map,Q_map,U_map =liteMapPol.SimPolMapsFromEandB(m,ell,Cell_TT,Cell_EE,Cell_TE,Cell_BB=Cell_BB,bufferFactor=1)
    	
    phi  = liteMap.liteMapFromFits("phikappa/phiMapHiRes.fits")
    alpha = phi.takeGradient()
    iy,ix = numpy.mgrid[0:phi.Ny,0:phi.Nx]
    iyf = iy.flatten()
    ixf = ix.flatten()

    a = numpy.array(alpha.gradX.data/ alpha.gradX.pixScaleX,dtype='int64')
    b = numpy.array(alpha.gradY.data/ alpha.gradY.pixScaleY,dtype='int64')

    iyLensed = iyf.copy()
    ixLensed = ixf.copy()

    iyLensed[:] = iyf[:] + b.flatten()
    ixLensed[:] = ixf[:] + a.flatten()

    id = numpy.where((ixLensed > ixf.max()) | (ixLensed < ixf.min()))
    id2 = numpy.where((iyLensed > iyf.max()) | (iyLensed < iyf.min()))

    ixLensed[id]  = ixf[id]
    iyLensed[id2] = iyf[id2]
	
    lensed_T_map=T_map.copy()
    lensed_Q_map=Q_map.copy()
    lensed_U_map=U_map.copy()
	
    lensed_T_map.data[iyf,ixf] = T_map.data[iyLensed,ixLensed]
    lensed_Q_map.data[iyf,ixf] = Q_map.data[iyLensed,ixLensed]
    lensed_U_map.data[iyf,ixf] = U_map.data[iyLensed,ixLensed]
		
    lensed_T_mapLo = m0.copy()
    lensed_T_mapLo = liteMap.resampleFromHiResMap(lensed_T_map,m0)
    
    lensed_Q_mapLo = m0.copy()
    lensed_Q_mapLo = liteMap.resampleFromHiResMap(lensed_Q_map,m0)
    
    lensed_U_mapLo = m0.copy()
    lensed_U_mapLo = liteMap.resampleFromHiResMap(lensed_U_map,m0)
    
    
    return(lensed_T_mapLo,lensed_Q_mapLo,lensed_U_mapLo)
示例#4
0
listCrossPower = {}
listReconPower = {}

for polComb in polCombList:
    listCrossPower[polComb] = []
    listReconPower[polComb] = []

bin_edges = np.arange(kellmin, kellmax, 80)

whiteNoiseT = (np.pi / (180. * 60))**2. * noiseT**2.  #/ TCMB**2.
whiteNoiseP = (np.pi / (180. * 60))**2. * noiseP**2.  #/ TCMB**2.

for k, i in enumerate(myIs):
    print i

    lensedTLm = lm.liteMapFromFits(lensedTPath(i))
    lensedQLm = lm.liteMapFromFits(lensedQPath(i))
    lensedULm = lm.liteMapFromFits(lensedUPath(i))
    kappaLm = lm.liteMapFromFits(kappaPath(i))

    if k == 0:
        lxMap, lyMap, modLMap, thetaMap, lx, ly = fmaps.getFTAttributesFromLiteMap(
            lensedTLm)
        beamTemplate = fmaps.makeTemplate(l, beamells, modLMap)
        fMaskCMB = fmaps.fourierMask(lx,
                                     ly,
                                     modLMap,
                                     lmin=cmbellmin,
                                     lmax=cmbellmax)
        fMask = fmaps.fourierMask(lx, ly, modLMap, lmin=kellmin, lmax=kellmax)
示例#5
0
import sys, os
from skimage.transform import resize

# For Mat on BNL
map_location = "/astro/astronfs01/workarea/msyriac/act/cmb_maps/c7v5_release/s2/ACTPol_148_D56_PA1_S2_1way_I_src_free.fits"
cat_location = "/astro/astronfs01/workarea/msyriac/act/ACTPol.fits"
out_dir = os.environ['WWW']

# For Teva
#map_location = '../ACTdata/ACTPol_148_D56_PA1_S2_1way_I.fits'
#cat_location = '../ACTdata/ACTPol.fits'
#out_dir = "./"

hdulist = fits.open(cat_location)
catalog = hdulist[1].data
lmap = liteMap.liteMapFromFits(map_location)
#io.highResPlot2d(lmap.data,out_dir+"bigmap.png")
RAs = []
DECs = []
widthStampArcminute = 60.
pixScale = 0.5
Nrands = 1000

lmap.info()

# select non-noisy part by trial and error
lmap = lmap.selectSubMap(348, 41, -8.3, 5.3)
io.highResPlot2d(lmap.data, out_dir + "cutmap.png")
lmap.info()
#sys.exit()
示例#6
0
# kellmax = 3000

#polCombList = ['TT']
#polCombList = ['TT','TE']
#polCombList = ['TT','EE','ET','EB','TB']
#colorList = ['red','blue','green','orange','purple']
polCombList = ['TT','EE','ET','TE','EB','TB']
colorList = ['red','blue','green','cyan','orange','purple']

TCMB = 2.7255e6

#cambRoot = "/astro/u/msyriac/repos/cmb-lensing-projections/data/TheorySpectra/ell28k_highacc"
dataFile = "/astro/astronfs01/workarea/msyriac/act/FinalScinetPaper/preparedMap_T_6.fits"

print "Loading map..."
templateMap = lm.liteMapFromFits(dataFile)


templateMap.info()
print templateMap.data.shape

# pl = Plotter()
# pl.plot2d(templateMap.data)
# pl.done("map.png")

print "Interpolating Cls..."

#from orphics.tools.cmb import loadTheorySpectraFromCAMB
#theory = loadTheorySpectraFromCAMB(cambRoot,unlensedEqualsLensed=False,useTotal=False,TCMB = TCMB,lpad=9000)
from orphics.theory.cosmology import Cosmology
cc = Cosmology(lmax=8000,pickling=True)
示例#7
0
import flipper.liteMap as lm
import btip.inpaintSims as inp
import orphics.tools.io as io
import pyfits
import os, sys
import orphics.analysis.flatMaps as fmaps

out_dir = os.environ['WWW']
lmap = lm.liteMapFromFits(
    "/gpfs01/astro/www/msyriac/forTeva/s15_pa2_s15_pa2_day_s15_pa3_150_fullex_I_map.fits"
)
Ny, Nx = lmap.data.shape
hdu = pyfits.open("/gpfs01/astro/www/msyriac/forTeva/ACTPol_BOSS-N_BJF.fits")
catalog = hdu[1].data
ras = hdu[1].data['RADeg']
decs = hdu[1].data['decDeg']
print((catalog.columns))

sys.exit()

print((ras.min()))
print((ras.max()))
#sys.exit()

ras = ras[ras > 160]
decs = decs[ras > 160]

ras = ras[ras < 233]
decs = decs[ras < 233]

print((len(ras)))
示例#8
0
def realSpaceCorr(params):
    """
    @brief compute the real space correlation between two maps
           and output the relevant files
    @param params: dictionary containing the following:

           totalMapPairs: the total pairs of maps to compute correlation over (int)
           root_A: the file tag for map #1 (str)
           root_B: the file tag for map #2 (str)
           thetaExtent: the angular extent to compute correlation to, in degrees (float)
           files_A: array containing filenames of map A (can be more than 1 non overlapping regions)
           files_B: array containing filenames of map B (can be more than 1 non overlapping regions)
           makePlots: whether to plot the results (bool)     
    """

    totalMapPairs = params['totalMapPairs']

    tag_A = params['root_A']
    tag_B = params['root_B']


    print "cross correlating %s and %s..." %(tag_A, tag_B)

    # extent of correlation to calculate
    dimDegree = params['thetaExtent']
    dimDegree *= np.pi/180.

    # loop over all map pairs
    for i in range(totalMapPairs):

        print 'correlating map pairs #%d...' %i

        # read in maps to cross correlate
        map_A = liteMap.liteMapFromFits(params['files_A'][i])
        map_B = liteMap.liteMapFromFits(params['files_B'][i])

        map_A.data = np.nan_to_num(map_A.data)
        map_B.data = np.nan_to_num(map_B.data)

        # set outliers to the median value
        inds = np.where(map_A.data != 0.0)
        dev = np.std(map_A.data[inds])
        inds2 = np.where(abs(map_A.data) > 10.*dev)
        map_A.data[inds2] = np.median(map_A.data[inds])

        inds = np.where(map_B.data != 0.0)
        dev = np.std(map_B.data[inds])
        inds2 = np.where(abs(map_B.data) > 10.*dev)
        map_B.data[inds2] = np.median(map_B.data[inds])

        # this map will store mapA_shifted*mapB values
        map_AB = map_A.copy()
        map_AB.data[:] = 0.

        # make map that will be use for shifting
        map_A_shifted = map_A.copy()
        map_A_shifted.data[:] = 0.

        # only do this first time around
        if i == 0:
            # num of pixels in this theta extent
            Ndim = np.int(dimDegree/map_A.pixScaleX)
            if np.mod(Ndim,2) != 0:
                Ndim += 1

            # initialize correlation and theta matrices
            corr  = np.zeros((Ndim+1,Ndim+1), dtype=float)
            theta  = np.zeros((Ndim+1,Ndim+1), dtype=float) # this will be in arcminutes
            weight = np.zeros((Ndim+1,Ndim+1), dtype=float) # weight array for combining multiple maps

    
        # might not have this package
        try:
            bar = initializeProgressBar((Ndim+1.0)**2)
        except:
            pass

        # n shifts map in x-direction, m shifts map in y directions
        iter = 0
        for m in xrange(-Ndim/2, Ndim/2+1, 1):
            for n in xrange(-Ndim/2, Ndim/2+1, 1):


                try:
                    bar.update(iter + 1)
                except:
                    pass

                iter += 1

                # shift map A and then multiply shifted map A by map B
                map_A_shifted.data = MapShiftFunc(map_A.data, n, m)
                map_AB.data[:] = map_A_shifted.data[:]*map_B.data[:]
                inds = np.where(map_AB.data != 0.)

                w = 1.0*len(inds[0]) # number of nonzero values in mean

                # due weighted sum of this corr value and any past corr values
                corr[m+Ndim/2,n+Ndim/2] = corr[m+Ndim/2,n+Ndim/2]*weight[m+Ndim/2,n+Ndim/2] + w*(map_AB.data[inds]).mean()

                # update the nonzero elements at this array element
                weight[m+Ndim/2,n+Ndim/2] += w

                # divide by the total weight
                corr[m+Ndim/2,n+Ndim/2] /= weight[m+Ndim/2,n+Ndim/2]

                # store the theta value
                theta[m+Ndim/2,n+Ndim/2] = np.sqrt(n**2*map_A.pixScaleX**2+m**2*map_A.pixScaleY**2)*180.*60/np.pi


    # plot and save the 2D correlation figure
    arcmin = 180.*60/np.pi

    # make sure output directories exist
    if not os.path.exists('./output'):
        os.makedirs('./output')
        
    if params['makePlots']:
        
        # make sure figs directory exists
        if not os.path.exists('./output/figs'):
            os.makedirs('./output/figs')
        
        plt.imshow(corr,origin='down',cmap = cm.gray,extent=[-Ndim/2*map_A.pixScaleX*arcmin,(Ndim/2+1)*map_A.pixScaleX*arcmin,\
                                                                -Ndim/2*map_A.pixScaleY*arcmin,(Ndim/2+1)*map_A.pixScaleY*arcmin])
        plt.colorbar()
        
        plt.savefig('./output/figs/corr_%s_%s.png'%(tag_A,tag_B))


        # plot the 1D correlation and save
        fig, r, mean, std = plot1DCorr(None, data=(theta, corr))
        fig.savefig('./output/figs/corr_1d_%s_%s.png'%(tag_A,tag_B))


    # make sure data directory exists
    if not os.path.exists('./output/data'):
        os.makedirs('./output/data')

    # save the 2D correlation and theta as a pickle
    pickle.dump([theta, corr],open('./output/data/corr_%s_%s.pkl' %(tag_A,tag_B), 'w'))
    plt.close()

    # save the 2D correlation as a fits file    
    hdu = pyfits.PrimaryHDU(corr)
    hdu.writeto('./output/data/corr_%s_%s.fits'%(tag_A,tag_B),clobber=True)

    return 0