def QU2EB(rootdir, frame, BoxSize=None):
    if BoxSize is None:
        BoxSize = 1
    Qlist = glob.glob(rootdir + '/DD%04d_Q[xyz]*.fits' % frame)
    Ulist = []
    for Qfile in Qlist:
        mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile)
        Ufile = mo.group(1) + 'U' + mo.group(2) + '.fits'
        Ulist.append(Ufile)
        #here we implicity assume Temperature = density.
        Tfile = mo.group(1) + 'density_' + mo.group(2) + '.fits'

    QUlist = zip(Qlist, Ulist)

    for Qfile, Ufile in QUlist:

        Q = array(pyfits.open(Qfile)[0].data, dtype=double)
        U = array(pyfits.open(Ufile)[0].data, dtype=double)
        T = array(pyfits.open(Tfile)[0].data, dtype=double)

        N = array(shape(Q), dtype=int32)
        xsize = 5 * pi / 180
        size2d = array([xsize, xsize])
        Delta = size2d / N
        Deltal = cmbtools.Delta2l(Delta, N)

        stuff = EBfromQU(Q, U, T=T, return_quharm=True, BoxSize=BoxSize)

        lmax = Deltal[0] * N[0]
        lbins = linspace(0, lmax, 100)
        lcent = lbins[:-1] + diff(lbins) / 2.

        ClEE = cmbtools.harm2cl(stuff['Eh'], Deltal, lbins)
        ClBB = cmbtools.harm2cl(stuff['Bh'], Deltal, lbins)
        ClTE = cmbtools.harm2clcross_samegrid(stuff['Th'], stuff['Eh'], Deltal,
                                              lbins)
        ClEB = cmbtools.harm2clcross_samegrid(stuff['Eh'], stuff['Bh'], Deltal,
                                              lbins)

        # write the output near the input
        mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile)
        outroot = mo.group(1)
        outsuf = mo.group(2)

        Efile = outroot + 'E' + outsuf + '.fits'
        Bfile = outroot + 'B' + outsuf + '.fits'
        Clfile = outroot + 'Cl' + outsuf + '.dat'

        print(Efile, Bfile, Clfile)

        hdu = pyfits.PrimaryHDU(stuff['E'])
        hdulist = pyfits.HDUList([hdu])
        hdulist.writeto(Efile, overwrite=True)

        hdu = pyfits.PrimaryHDU(stuff['B'])
        hdulist = pyfits.HDUList([hdu])
        hdulist.writeto(Bfile, overwrite=True)

        savetxt(Clfile, list(zip(lcent, ClEE, ClBB, ClTE, ClEB)))
def EBfromQU(Q, U, T=None, H=None, BoxSize=1, return_quharm=False):

    if not Q.flags['C_CONTIGUOUS']:
        Q = np.ascontiguousarray(Q)
    if not U.flags['C_CONTIGUOUS']:
        U = np.ascontiguousarray(U)
    if T is not None:
        if not T.flags['C_CONTIGUOUS']:
            T = np.ascontiguousarray(T)
    if H is not None:
        if not H.flags['C_CONTIGUOUS']:
            H = np.ascontiguousarray(H)
    N = array(shape(Q), dtype=int32)
    xsize = 5 * pi / 180 * BoxSize
    size2d = array([xsize, xsize])
    Delta = size2d / N

    print("N = ", N)
    print("Delta = ", Delta)

    Deltal = cmbtools.Delta2l(Delta, N)

    Qharm = cmbtools.map2harm(Q, Delta)
    Uharm = cmbtools.map2harm(U, Delta)

    Eharm, Bharm = cmbtools.QU2EB(Qharm, Uharm, Deltal)

    E = cmbtools.harm2map(Eharm, Delta)
    B = cmbtools.harm2map(Bharm, Delta)
    if return_quharm:
        output = {
            'E': E,
            'B': B,
            'Eh': Eharm,
            'Bh': Bharm,
            'Qh': Qharm,
            'Uh': Uharm,
            'Deltal': Deltal,
            'Delta': Delta
        }
        output['N'] = N
    else:
        output = E, B, Eharm, Bharm

    if T is not None:
        Tharm = cmbtools.map2harm(T, Delta)
        output['Th'] = Tharm
    if H is not None:
        Hharm = cmbtools.map2harm(H, Delta)
        output['Hh'] = Hharm

    return output
예제 #3
0
    def compute_bins_5deg(self):
        #Earlier computations assumed a 5degree sky.
        #not robust against aliasing.  Probably shouldn't use.
        self.xsize = 5 * np.pi / 180

        self.size2d = np.array([self.xsize,self.xsize])
        self.N = np.array(np.shape(self.Q),dtype = np.int32)
        self.Delta = self.size2d/self.N
        self.Deltal = cmbtools.Delta2l(self.Delta,self.N)

        self.lmax = self.Deltal[0]*self.N[0] 
        self.lbins = np.linspace(0,self.lmax,100)
        self.lcent = self.lbins[:-1] + np.diff(self.lbins)/2.
예제 #4
0
def QU2EB(rootdir, frame):
    Qlist = glob.glob(rootdir + '/DD%04d_Q[xyz]*.fits' % frame)
    Ulist = []
    for Qfile in Qlist:
        mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile)
        Ufile = mo.group(1) + 'U' + mo.group(2) + '.fits'
        Ulist.append(Ufile)

    QUlist = zip(Qlist, Ulist)

    for Qfile, Ufile in QUlist:

        Q = array(pyfits.open(Qfile)[0].data, dtype=double)
        U = array(pyfits.open(Ufile)[0].data, dtype=double)

        N = array(shape(Q), dtype=int32)
        xsize = 5 * pi / 180
        size2d = array([xsize, xsize])
        Delta = size2d / N
        Deltal = cmbtools.Delta2l(Delta, N)

        E, B, Eharm, Bharm, Tharm = EBfromQU(Q, U)

        lmax = Deltal[0] * N[0]
        lbins = linspace(0, lmax, 100)
        lcent = lbins[:-1] + diff(lbins) / 2.

        ClEE = cmbtools.harm2cl(Eharm, Deltal, lbins)
        ClBB = cmbtools.harm2cl(Bharm, Deltal, lbins)
        #ClTE = cmbtools.harm2clcross_samegrid(Eharm, Tharm,Deltal,lbins)

        # write the output near the input
        mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile)
        outroot = mo.group(1)
        outsuf = mo.group(2)

        Efile = outroot + 'E' + outsuf + '.fits'
        Bfile = outroot + 'B' + outsuf + '.fits'
        Clfile = outroot + 'Cl' + outsuf + '.dat'

        print(Efile, Bfile, Clfile)

        hdu = pyfits.PrimaryHDU(E)
        hdulist = pyfits.HDUList([hdu])
        hdulist.writeto(Efile, overwrite=True)

        hdu = pyfits.PrimaryHDU(B)
        hdulist = pyfits.HDUList([hdu])
        hdulist.writeto(Bfile, overwrite=True)

        savetxt(Clfile, list(zip(lcent, ClEE, ClBB)))
예제 #5
0
    def compute_bins_horse_around(self):
        #Change bin size to enjoy aliasing effects.
        self.N = np.array(np.shape(self.Q),dtype = np.int32)
        self.xsize = self.N[0]

        self.size2d = np.array([self.xsize,self.xsize])
        self.Delta = self.size2d/self.N
        self.Deltal = cmbtools.Delta2l(self.Delta,self.N)

        self.lmax = self.Deltal[0]*self.N[0]
        self.lbins = np.linspace(0,self.lmax,100)
        #self.lmax = self.Deltal[0]*self.N[0]/2
        #self.lbins = np.arange(0,self.N[0]//2) *self.Deltal[0]


        self.lcent = self.lbins[:-1] + np.diff(self.lbins)/2.
예제 #6
0
def Make_other(arr, BoxSize=1):
    N = np.array(arr.shape, dtype=np.int32)
    arr = np.ascontiguousarray(arr, dtype=np.double)
    xsize = N.max()  #5 * np.pi / 180*BoxSize
    size2d = np.array([xsize, xsize])
    Delta = size2d / N
    Deltal = cmbtools.Delta2l(Delta, N)
    harm = cmbtools.map2harm(arr, Delta)
    lmax = Deltal[0] * N[0] / 2
    lbins = np.arange(N[0] // 2 + 1) * Deltal[0]  #np.linspace(0,lmax,N//2)
    lcent = lbins[:-1] + np.diff(lbins) / 2.
    ClBB = cmbtools.harm2cl(harm, Deltal, lbins)
    output = {
        'Delta': Delta,
        'Deltal': Deltal,
        'harm': harm,
        'lbins': lbins,
        'ClBB': ClBB,
        'lmax': lmax
    }
    return output
예제 #7
0
import cmbtools
#from pylab import *

#close('all')

N = np.array([128, 128], dtype=np.int32)
xsize = 1 * np.pi / 180
size2d = np.array([xsize, xsize])

Delta = size2d / N

print("N = ", N)
print("Delta = ", Delta)

Deltal = cmbtools.Delta2l(Delta, N)

print("Deltal = ", Deltal)

E = np.zeros(N)
#E = array([[cos(3*2*pi*(i+2*j)/N[1]) for i in range(N[1]) ] for j in range(N[0])])
# + sin(2*pi*i/N[1])

B = np.array([[np.cos(3 * 2 * np.pi * (i + j) / N[1]) for i in range(N[1])]
              for j in range(N[0])])

Eharm = cmbtools.map2harm(E, Delta)
Bharm = cmbtools.map2harm(B, Delta)

Qharm, Uharm = cmbtools.EB2QU(Eharm, Bharm, Deltal)