Exemple #1
0
def obtain_1string_map(fwhm=1.4, string_map_file=STRING_MAP_FILE,
                        map_fov_deg=7.2,
                        beam_smear=True, Gmu=1.4e-7):

    
    Tcmb_uK = 2.72548*1e6
    deg2rad = np.pi/180.
    
    string_map =  liteMap.liteMapFromFits(string_map_file)
    string_map.data *= Gmu * Tcmb_uK
    string_map.area = map_fov_deg**2.
    string_map.Nx, string_map.Ny = np.shape(string_map.data)
    string_map.x0 = 0.
    string_map.y0 = 0.
    string_map.x1 = map_fov_deg
    string_map.y1 = map_fov_deg
    string_map.pixScaleX = deg2rad * map_fov_deg / string_map.Nx #this is in rad
    string_map.pixScaleY = deg2rad * map_fov_deg / string_map.Ny #this is in rad
    
    if beam_smear:
        string_map = string_map.convolveWithGaussian(fwhm=fwhm)
    
    gradx,grady = np.gradient(string_map.data,string_map.pixScaleX,string_map.pixScaleY)
    gradmap = np.sqrt(gradx**2 + grady**2)
    gradx,grady = np.gradient(gradmap,string_map.pixScaleX,string_map.pixScaleY)
    gradgradmap = np.sqrt(gradx**2 + grady**2)

    return string_map.data, gradmap, gradgradmap
Exemple #2
0
    def use4way_for_2way(self, fourwayfiles):
        """A kludge to average 4way maps 0+1 and 2+3 to emulate a 2-way split."""
        print "Kludge: using 4-ways as if 2-ways"
        assert len(fourwayfiles) == 4
        maps = [liteMap.liteMapFromFits(f) for f in fourwayfiles]
        weightfiles = [f.replace("1000", "weights") for f in fourwayfiles]
        wts = [liteMap.liteMapFromFits(f) for f in weightfiles]

        m1 = maps[0].copy()
        m2 = maps[2].copy()

        m1.data = (maps[0].data + maps[2].data) * 0.5
        m2.data = (maps[1].data + maps[3].data) * 0.5

        # Do a weighted sum
        w = [count.data for count in wts]

        # m1.data[::] = ((maps[1].data*w[1] + maps[2].data*w[2])/(w[1]+w[2]))[::]
        # m2.data[::] = ((maps[0].data*w[0] + maps[3].data*w[3])/(w[0]+w[3]))[::]
        return [m1, m2]
Exemple #3
0
    def __init__(
        self,
        existingSkyMap=None,
        mapfile=DEFAULT.map,
        weightfile=DEFAULT.weight,
        twowayfiles=DEFAULT.twoway,
        trim=True,
        raRange=[0, 105],
        decRange=[-56, -50.33],
        cal_correction=1.0,
    ):

        if existingSkyMap:
            for a in ("map", "fmap", "wt", "twoway", "ftwoway", "sensmap", "diff"):
                try:
                    self.__dict__[a] = existingSkyMap.__dict__[a]
                except KeyError:
                    pass
            return

        map = liteMap.liteMapFromFits(mapfile)
        wt = liteMap.liteMapFromFits(weightfile)

        if len(twowayfiles) == 4:
            twoway = self.use4way_for_2way(twowayfiles)
        else:
            twoway = [liteMap.liteMapFromFits(f) for f in twowayfiles]

        if trim:
            map = map.selectSubMap(raRange[0], raRange[1], decRange[0], decRange[1])
            wt = wt.selectSubMap(raRange[0], raRange[1], decRange[0], decRange[1])
            twoway = [tw.selectSubMap(raRange[0], raRange[1], decRange[0], decRange[1]) for tw in twoway]
        print "Applying calibration factor", cal_correction
        map.data *= cal_correction
        for t in twoway:
            t.data *= cal_correction

        self.map = map
        self.wt = wt
        self.twoway = twoway
        self.fmap = self.ftwoway = self.sensmap = self.diff = None  # will computer later
    kappa = qest.getKappa('TT')
    kappa = kappa - kappa.mean()

    if k == 0:
        pl = Plotter()
        pl.plot2d(kappa.real)
        pl.done("kappa.png")

        #meanfield = kappa.real.copy()*0.

    w2 = np.mean(window**2.)
    templateMap.data = kappa.real / w2
    templateMap.writeFits(savePath + "kappa" + str(i).zfill(3) + ".fits",
                          overWrite=True)

    lmap1 = lm.liteMapFromFits(savePath + "inputKappa" + str(i).zfill(3) +
                               ".fits")

    if k == 0:
        pl = Plotter()
        pl.plot2d(lmap1.data)
        pl.done("inkappa.png")



    px = np.abs(lmap1.x1-lmap1.x0)/lmap1.Nx*np.pi/180.\
         *np.cos(np.pi/180.*0.5*(lmap1.y0+lmap1.y1))*180./np.pi*60.
    print px
    lmap1.pixScaleX = px / 180. * np.pi / 60.

    lmap1.data = lmap1.data * window
    w4 = np.mean(window**4.)
Exemple #5
0
def downWriteMap(fname):
    nowMap = lm.liteMapFromFits(fname)
    lowTemp = lm.getEmptyMapWithDifferentDims(nowMap, int(nowMap.Ny / 2.),
                                              int(nowMap.Nx / 2.))
    lowMap = lm.resampleFromHiResMap(nowMap, lowTemp)
    lowMap.writeFits(fname[:-5] + "_down.fits", overWrite=True)
def main(argv):

    # Read some parameters from the ini file
    config = ConfigParser.SafeConfigParser()
    config.read("input/general.ini")
    fileRoot = config.get('sims', 'root_location') + config.get(
        'sims', 'sim_root')
    savePath = config.get('sims', 'root_location') + "output/"
    istart = config.getint('sims', 'istart')
    iend = config.getint('sims', 'iend')
    widthArcmin = config.getfloat('cutouts', 'widthArcmin')
    pixScaleArcmin = config.getfloat('sims', 'pixScaleArcmin')

    npixx = int(widthArcmin / pixScaleArcmin / 2.)
    npixy = int(widthArcmin / pixScaleArcmin / 2.)

    stackTot = 0.  # stack on lensed cmb + sz
    stackSZ = 0.  # stack on sz
    stackDx = 0.  # stack on deflection_x
    stackDy = 0.  # stack on deflection_y
    stackKappa = 0.  # stack on kappa = div.Deflection / 2
    stackAlt = 0.  # stack on kappa = div.Deflection / 2 calculated with FFTs
    stackEst = 0.  # stack on kappa reconstruction

    totnum = 0  # total number of stamps read
    skip = 0  # number skipped because stamp falls outside edges
    for i in range(istart, iend + 1):

        froot = fileRoot + str(i).zfill(3)

        # read catalog of clusters and make a selection on mass
        catFile = froot + ".txt"
        xcens, ycens, m200s = np.loadtxt(catFile,
                                         unpack=True,
                                         usecols=[1, 2, 6])
        selection = m200s > 1.e14

        # open cmb map
        imgFile = froot + "_tSZ_MOD.fits"
        print "Loading fits file ", i, "with ", len(
            xcens[selection]), " clusters ..."
        hd = pyfits.open(imgFile)

        # open kappa reconstruction and apply a dumb correction to the pixel scale
        lmap = lm.liteMapFromFits(savePath + "kappa" + str(i).zfill(3) +
                                  ".fits")
        px = np.abs(lmap.x1-lmap.x0)/lmap.Nx*np.pi/180.\
             *np.cos(np.pi/180.*0.5*(lmap.y0+lmap.y1))*180./np.pi*60.
        lmap.pixScaleX = px / 180. * np.pi / 60.
        print "pixel scale arcminutes X , ", lmap.pixScaleX * 180. * 60. / np.pi
        print "pixel scale arcminutes X , ", lmap.pixScaleY * 180. * 60. / np.pi

        tot = hd[0].data
        sz = hd[6].data + hd[7].data
        unl = hd[3].data

        dx = hd[8].data * np.pi / 180. / 60.
        dy = hd[9].data * np.pi / 180. / 60.

        pl = Plotter()
        pl.plot2d(dx)
        pl.done("dx.png")

        pl = Plotter()
        pl.plot2d(dy)
        pl.done("dy.png")

        kappa = 0.5 * (np.gradient(dx, axis=0) + np.gradient(dy, axis=1))

        pl = Plotter()
        pl.plot2d(kappa)
        pl.done("rkappa.png")

        diffmap = tot - sz - unl

        #alt kappa
        import orphics.analysis.flatMaps as fmaps
        lxMap, lyMap, modLMap, thetaMap, lx, ly = fmaps.getFTAttributesFromLiteMap(
            lmap)
        win = fmaps.initializeCosineWindow(lmap, lenApod=100, pad=10)
        Ny = lmap.Ny
        kgradx = lx * fft2(dy * win) * 1j
        kgrady = ly.reshape((Ny, 1)) * fft2(dx * win) * 1j
        altkappa = 0.5 * ifft2(kgradx + kgrady).real
        saveMap = lmap.copy()
        saveMap.data = altkappa
        saveMap.writeFits(savePath + "inputKappa" + str(i).zfill(3) + ".fits",
                          overWrite=True)

        pl = Plotter()
        pl.plot2d(altkappa)
        pl.done("fkappa.png")

        if i == 0:
            pl = Plotter()
            pl.plot2d(diffmap * win)
            pl.done("diff.png")
            #sys.exit()

        bigY, bigX = tot.shape
        print "Map area ", bigX * bigY * pixScaleArcmin * pixScaleArcmin / 60. / 60., " sq. deg."

        doRandom = False

        if doRandom:
            xlbound = xcens[selection].min()
            xrbound = xcens[selection].max()
            ylbound = ycens[selection].min()
            yrbound = ycens[selection].max()

        for xcen, ycen, m200 in zip(xcens[selection], ycens[selection],
                                    m200s[selection]):
            totnum += 1
            if doRandom:
                xcen = np.random.randint(xlbound, xrbound)
                ycen = np.random.randint(ylbound, yrbound)
            else:
                xcen = int(xcen)
                ycen = int(ycen)

            if ycen - npixy < 0 or xcen - npixx < 0 or ycen + npixy > (
                    bigY - 1) or xcen + npixx > (bigX - 1):
                skip += 1
                continue

            cutOutTot = tot[(ycen - npixy):(ycen + npixy),
                            (xcen - npixx):(xcen + npixx)]
            cutOutSZ = sz[(ycen - npixy):(ycen + npixy),
                          (xcen - npixx):(xcen + npixx)]
            cutOutDx = dx[(ycen - npixy):(ycen + npixy),
                          (xcen - npixx):(xcen + npixx)]
            cutOutDy = dy[(ycen - npixy):(ycen + npixy),
                          (xcen - npixx):(xcen + npixx)]
            cutOutKappa = kappa[(ycen - npixy):(ycen + npixy),
                                (xcen - npixx):(xcen + npixx)]
            cutOutAlt = altkappa[(ycen - npixy):(ycen + npixy),
                                 (xcen - npixx):(xcen + npixx)]
            cutOutEst = lmap.data[(ycen - npixy):(ycen + npixy),
                                  (xcen - npixx):(xcen + npixx)]

            stackTot += cutOutTot
            stackSZ += cutOutSZ
            stackDx += cutOutDx
            stackDy += cutOutDy
            stackKappa += cutOutKappa
            stackAlt += cutOutAlt
            stackEst += cutOutEst

    print "Percentage near bounds = ", skip * 100. / totnum, " %"

    if doRandom:
        rs = "R"
    else:
        rs = ""

    N = totnum - skip

    stackD = np.sqrt(stackDx**2. + stackDy**2.)
    pl = Plotter()
    pl.plot2d(stackD / N)
    pl.done("plots/stackD" + rs + ".png")

    pl = Plotter()
    pl.plot2d(stackKappa / N)
    pl.done("plots/stackK" + rs + ".png")

    pl = Plotter()
    pl.plot2d(stackAlt / N)
    pl.done("plots/stackA" + rs + ".png")

    pl = Plotter()
    pl.plot2d(stackTot / N)
    pl.done("plots/stackTot" + rs + ".png")

    pl = Plotter()
    pl.plot2d(stackSZ / N)
    pl.done("plots/stackSZ" + rs + ".png")

    pl = Plotter()
    pl.plot2d(stackEst / N)
    pl.done("plots/stackE" + rs + ".png")
Exemple #7
0
def main(argv):
    
    iniFile = 'input/noise.ini'

    config = ConfigParser()
    config.read(iniFile)

    
    mass = 1.E14
    conc = 3.0
    z = 1.0

    #noiseT = 1.0
    #beam = 5.0
    #ellbeam = 7000.
    Nclus = 1000.
    arcupto = 10.

    mss = []
    #beams = np.arange(1.0,7.0,0.1)

    beams = [float(argv[0])]
    noiseT = float(argv[1])
    xy = argv[2]
    print beams
    #sys.exit()
    
    
    for beam in beams:

        ellbeam = 7000
        #ellbeam = int(np.sqrt(8.*np.log(2.)) / beam *60. * 180./np.pi)
        print "Ellbeam, ", ellbeam

        Nsupp = 10000.


        px = 0.1
        arc = 20.
        #xy = 'TT'
        bin_width = 10 #int(beam/px)
        Nreals = 5000
        Nbins = int(arcupto/bin_width)
        scale = px
        thetas = np.arange(bin_width*scale/2.,arcupto,scale*bin_width)

        lensedClFile = "../cmb-lensing-projections/data/TheorySpectra/ell28k_highacc_lensedCls.dat"
        unlensedClFile = "../cmb-lensing-projections/data/TheorySpectra/ell28k_highacc_scalCls.dat"

        cmbells,cltt,clee,clbb,clte = Lens.loadCls(lensedClFile)
        ucmbells,ucltt,uclee,uclte,dummy = Lens.loadCls(unlensedClFile)
        uclbb = clbb.copy()[:len(ucmbells)]
        uClsNow = [ucltt,uclee,uclbb,uclte]
        uClsFid = [ucltt,uclee,uclbb,uclte]
        lClsFid = [cltt,clee,clbb,clte]


        template = "../DerivGen/data/order5_lensedCMB_T_beam_cutout_3.fits"
        templateMap = liteMap.liteMapFromFits(template)


        Lens.makeBinfile("../cmb-lensing-projections/data/bintemp.dat",first=2,last=9000,width=20)

        lmin = 2.
        lmax = 8000.

        if xy=='mv':
            NormGen = Lens.AL(templateMap,'TT',ucmbells,uClsNow,ucmbells,uClsFid,cmbells,lClsFid,lmax,lmax,gradCut=2000.)
            NormGen.addWhiteNoise(noiseT,np.sqrt(2.)*noiseT,beam,(0,0,lmin,lmax),(lmin,lmax,lmin,lmax))
            L1,Nl1,ph = NormGen.binnedNLkk("../cmb-lensing-projections/data/bintemp.dat",inverted=False,halo=True)
            NormGen = Lens.AL(templateMap,'EB',ucmbells,uClsNow,ucmbells,uClsFid,cmbells,lClsFid,lmax,lmax,gradCut=2000.)
            NormGen.addWhiteNoise(noiseT,np.sqrt(2.)*noiseT,beam,(0,0,lmin,lmax),(lmin,lmax,lmin,lmax))
            L2,Nl2,ph = NormGen.binnedNLkk("../cmb-lensing-projections/data/bintemp.dat",inverted=False,halo=True)
            assert np.all(L1==L2)
            L = L1.copy()
            Nl = 1./(1./Nl1+1./Nl2)
            
            
        else:
            NormGen = Lens.AL(templateMap,xy,ucmbells,uClsNow,ucmbells,uClsFid,cmbells,lClsFid,lmax,lmax,gradCut=2000.)
            NormGen.addWhiteNoise(noiseT,np.sqrt(2.)*noiseT,beam,(0,0,lmin,lmax),(lmin,lmax,lmin,lmax))
            L,Nl,ph = NormGen.binnedNLkk("../cmb-lensing-projections/data/bintemp.dat",inverted=False,halo=True)
                

        pl = Plotter(scaleX='log',scaleY='log')
        pl.add(L,Nl)
        pl.done('stampNl.png')

        #sys.exit()


        rads = []
        print "Making stamps to determine profile covmat..."
        for i in range(Nreals):
            #print i
            lm = liteMap.makeEmptyCEATemplate(raSizeDeg=arc/60., decSizeDeg=arc/60.,pixScaleXarcmin = px, pixScaleYarcmin=px)

            if i==0:
                #print lm.data.shape
                Npix = lm.data.shape[0]
                lfilt = stepFunctionFilterFromLiteMap(lm,ellbeam)
                kapmaker = kappaMaker(Cosmology(defaultLCDM),mass,conc,z,storeKap=False)
                kapstamp,kaprad = kapmaker.getKappaAndProfile(Npix,scale=px,beam=None,bin_width=bin_width)
                # pl = Plotter()
                # pl.plot2d(kapstamp)
                # pl.done('kappa.png')
                # sys.exit()


            lm.fillWithGaussianRandomField(L,Nl/Nsupp,bufferFactor = 1)
            stamp = lm.data.copy()
            stamp = stamp+kapstamp.copy()
            stamp = np.nan_to_num(filterDataFromTemplate(stamp,lfilt))
            prof = radial_data(stamp,annulus_width=bin_width).mean
            #print prof
            rads.append(prof)
            if i%1000==0: print i

        radmeans, covMean, cov, errMean,err,corrcoef = getStats(rads,Nreals)

        thstamp = np.nan_to_num(filterDataFromTemplate(kapstamp,lfilt))
        thprof = radial_data(thstamp,annulus_width=bin_width).mean


        siginv = np.linalg.pinv(cov[:len(thetas),:len(thetas)])
        #print siginv
        #print radmeans[:len(thetas)]
        b = np.dot(siginv,radmeans[:len(thetas)])
        chisq = np.dot(radmeans[:len(thetas)],b)

        print np.sqrt(chisq*Nclus/Nsupp)


        #print radmeans
        #print err

        pl = Plotter()
        pl.addErr(thetas,radmeans[:len(thetas)],yerr=err[:len(thetas)])
        pl.add(thetas,kapmaker.kappa(thetas))
        pl._ax.set_ylim(-0.01,0.25)
        pl._ax.set_xlim(0.0,arcupto)
        pl.done('profile.png')


        pl = Plotter()
        pl.plot2d(corrcoef)
        pl.done('corrcoef.png')




        pl = Plotter()
        pl.plot2d(stamp)
        pl.done('stamp.png')


        amplitudeRange = np.arange(-1.,2.,0.01)
        width = amplitudeRange[1]-amplitudeRange[0]
        amplist = []
        print "Fitting amplitudes..."
        for i in range(Nreals):
            prof = rads[i][:len(thetas)]
            Likelihood = lambda x: np.exp(-0.5*fchisq(prof,siginv,thprof[:len(thetas)],amp=x))
            Likes = np.array([Likelihood(x) for x in amplitudeRange])
            Likes = Likes / (Likes.sum()*width) #normalize
            ampBest,ampErr = cfit(norm.pdf,amplitudeRange,Likes,p0=[1.0,0.5])[0]

            #print ampBest,ampErr
            amplist.append(ampBest)


        ms = plotstat( -1.,2.,0.01 , (np.array(amplist)) , "amps",fit=True,scale=np.sqrt(Nclus/Nsupp))

        mss.append(ms)

    pl = Plotter()
    pl.add(beams,mss)
    pl.done('beam.png')

    np.savetxt("output/m1beamsms"+xy+argv[0]+"_noise"+str(noiseT)+".txt",np.vstack((beams,mss)).transpose())
Exemple #8
0
from __future__ import division, print_function

import numpy as np
from scipy.stats import moment
import matplotlib.pyplot as plt

import liteMap
import fftTools
from flipper import *
STRING_MAP_FILE = '/data/verag/strings/inputs/dTmap_stg_Dcmb0000.fits'#'/Users/verag/Research/strings/strings/data/dTmap_stg_Dcmb0000.fits'
string_template =  liteMap.liteMapFromFits(STRING_MAP_FILE)
string_template.Nx, string_template.Ny = np.shape(string_template.data)
string_fovX = 7.2 #deg
string_fovY = 7.2 #deg
string_scaleX = np.deg2rad(string_fovX) / string_template.Nx
string_scaleY = np.deg2rad(string_fovY) / string_template.Ny


class Statistic(object):
    def __init__(self, function, name):
        """function takes map data in, spits out number or array
        """
        self.function = function
        self.name = name

    def __call__(self, data, **kwargs):
        return self.function(data, **kwargs)

class Moments(Statistic):
    def __init__(self, moments=[2,3,4], name='moments'):
        self.moments = moments
Exemple #9
0
def obtain_N_cmb_maps(fwhm=1.4, string_file_num=0,
                        spectra_file=SPECTRA_FILE, map_fov_deg=7.2,
                        return_strings=False,
                        beam_smear=True, Nmaps=1, Gmu=0.,
                        noise=16, Nx=None, Ny=None):

    if string_file_num < 10:
        string_map_file = '/data/verag/strings/inputs/dTmap_stg_Dcmb000{}.fits'.format(string_file_num) # this can be 0-9
    else:
        string_map_file = '/data/verag/strings/inputs/dTmap_stg_Dcmb00{}.fits'.format(string_file_num) # this can be 0-9

    maps = []
    maps_stringy = []
    
    Tcmb_uK = 2.72548*1e6
    deg2rad = np.pi/180.
    
    string_map =  liteMap.liteMapFromFits(string_map_file)
    string_map.data *= Gmu * Tcmb_uK
    string_map.area = map_fov_deg**2.
    string_map.Nx, string_map.Ny = np.shape(string_map.data)
    string_map.x0 = 0.
    string_map.y0 = 0.
    string_map.x1 = map_fov_deg
    string_map.y1 = map_fov_deg
    string_map.pixScaleX = deg2rad * map_fov_deg / string_map.Nx #this is in rad
    string_map.pixScaleY = deg2rad * map_fov_deg / string_map.Ny #this is in rad

    if Gmu>0:
        if beam_smear:
            string_map = string_map.convolveWithGaussian(fwhm=fwhm)

    cmb_map = string_map.copy()
    if Nx is not None:
        cmb_map.Nx = Nx
    if Ny is not None:
        cmb_map.Ny = Ny
    cmb_map.data = np.zeros((cmb_map.Nx,cmb_map.Ny))
    cmb_map.pixScaleX = deg2rad * map_fov_deg / cmb_map.Nx #this is in rad
    cmb_map.pixScaleY = deg2rad * map_fov_deg / cmb_map.Ny #this is in rad


    spectra = np.loadtxt(spectra_file)
    ls = spectra[:,0]
    cl = spectra[:,1]/(ls*(ls + 1))*2.*np.pi

    for i in np.arange(Nmaps):
        logging.info('{} of {}'.format(i+1, Nmaps))
        cmb_map.fillWithGaussianRandomField(ls,cl)
        if beam_smear:
            cmb_map = cmb_map.convolveWithGaussian(fwhm=fwhm)
        noise_map = np.random.standard_normal(np.shape(cmb_map.data)) * (noise)
        
        cmb = cmb_map.data + noise_map
        maps.append(cmb - cmb.mean())

        if Gmu>0:
            stringycmb = cmb_map.data + noise_map + string_map.data
            maps_stringy.append(stringycmb - stringycmb.mean())

    if Gmu>0 and return_strings:
        return maps_stringy
    else:
        return maps
Exemple #10
0
matplotlib.use('Agg')
from astLib import astWCS, astCoords
import liteMap as lm
import ConfigParser

config = ConfigParser.SafeConfigParser()
config.read("input/general.ini")

savePath = config.get('sims', 'root_location') + "output/"

N = 38

for i in range(1, N + 1):
    print i

    lmap = lm.liteMapFromFits(savePath + "kappa" + str(i).zfill(3) + ".fits")
    if i == 1:
        mf = lmap.data * 0.

    mf += lmap.data

mf = mf / (N - 1)

lmap = lm.liteMapFromFits(savePath + "kappa000.fits")
from orphics.tools.output import Plotter

pl = Plotter()
pl.plot2d(mf)
pl.done("mf.png")

pl = Plotter()
Exemple #11
0
def getTaperedMap(lkk,clkk,templateMapLoc = "../DerivGen/data/order5_lensedCMB_T_beam_cutout_3.fits",bufferFactor=2,taperWidth = 120,jackknife=36):
    # jackknife = (number of jackknife regions)
    
    assert is_square(jackknife)
    

    templateMap = liteMap.liteMapFromFits(templateMapLoc)
    templateMap.data[:,:] = 0.
    templateMap.fillWithGaussianRandomField(lkk,clkk,bufferFactor = bufferFactor)
    retMap = templateMap.copy()

    xa,xb = (templateMap.x0,templateMap.x1)
    ya,yb = (templateMap.y0,templateMap.y1)
    x0 = min(xa,xb)
    x1 = max(xa,xb)
    y0 = min(ya,yb)
    y1 = max(ya,yb)

    xl = x1-x0
    yl = y1-y0

    Neach = int(np.sqrt(jackknife))
    xeach = xl/Neach
    yeach = yl/Neach

    bufferx = 0.001
    buffery = 0.001

    smaps = []
    stapers = []
    for i in range(Neach):
        
        tx0 = x0+i*xeach
        tx1 = x0+(i+1)*xeach

        if i==0: tx0 += bufferx
        if i==Neach-1: tx1 -= bufferx
            
        for j in range(Neach):
            ty0 = y0+j*yeach
            ty1 = y0+(j+1)*yeach

            if j==0: ty0 += buffery
            if j==Neach-1: ty1 -= buffery
            
            
            print((tx0,tx1,ty0,ty1))
            smap = templateMap.selectSubMap(tx0,tx1,ty0,ty1, safe = False)
            #print smap.info()
            
            subtaper = lpol.initializeCosineWindow(smap,int(taperWidth/Neach),0)
            smap.data[:] = smap.data[:]*subtaper.data[:]
            pl = Plotter()
            pl.plot2d(smap.data)
            pl.done("kappa"+str(i)+str(j)+".png")

            smaps.append(smap)
            stapers.append(subtaper)
            
    #sys.exit()



    taper = lpol.initializeCosineWindow(retMap,taperWidth,0)
    retMap.data[:] = retMap.data[:]*taper.data[:]


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

    return retMap,taper,smaps,stapers