Example #1
0
 def xlm_to_qlm( self ):
     indxpn = LISAresponse.getMLvec( self.ntrunc , 'pn' )
     qlm = numpy.zeros( self.xlm.shape , dtype='complex' )
     for i,ml in enumerate( indxpn ) :
         m , l = ml[0] , ml[1]
         k = indxpn.index( (-m,l) )
         qlm[i] = ( self.xlm[i] - (-1)**m * numpy.conj( self.xlm[k] ) ) / 2j
     indxp = LISAresponse.getMLvec( self.ntrunc , 'p' )
     self._SkyMap__qlm = numpy.copy( qlm[ :len(indxp) ] )
     return
Example #2
0
 def xlm_to_qlm(self):
     indxpn = LISAresponse.getMLvec(self.ntrunc, 'pn')
     qlm = numpy.zeros(self.xlm.shape, dtype='complex')
     for i, ml in enumerate(indxpn):
         m, l = ml[0], ml[1]
         k = indxpn.index((-m, l))
         qlm[i] = (self.xlm[i] - (-1)**m * numpy.conj(self.xlm[k])) / 2j
     indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
     self._SkyMap__qlm = numpy.copy(qlm[:len(indxp)])
     return
Example #3
0
 def plmqlm_to_xlm( self ):
     indxp  = LISAresponse.getMLvec( self.ntrunc , 'p' )
     indxpn = LISAresponse.getMLvec( self.ntrunc , 'pn' )
     xlm = numpy.zeros( ( len(indxpn), ) , dtype='complex' )
     for i,ml in enumerate( indxpn ):
         m , l = ml
         k = indxp.index( ( abs(m),l ) )
         if m >= 0:
             xlm[i] = self.plm[k] + 1j*self.qlm[k]
         else:
             xlm[i] = (-1)**m * ( numpy.conj( self.plm[k] ) + 1j*numpy.conj( self.qlm[k] ) )
     self._SkyMap__xlm = numpy.copy( xlm )
     return
Example #4
0
 def plmqlm_to_xlm(self):
     indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
     indxpn = LISAresponse.getMLvec(self.ntrunc, 'pn')
     xlm = numpy.zeros((len(indxpn), ), dtype='complex')
     for i, ml in enumerate(indxpn):
         m, l = ml
         k = indxp.index((abs(m), l))
         if m >= 0:
             xlm[i] = self.plm[k] + 1j * self.qlm[k]
         else:
             xlm[i] = (-1)**m * (numpy.conj(self.plm[k]) +
                                 1j * numpy.conj(self.qlm[k]))
     self._SkyMap__xlm = numpy.copy(xlm)
     return
Example #5
0
    def __init__( self , nlat=3 , nlon=4  , X=None ):
        super( XSkyMap , self ).__init__()

        if X == None:
            if nlat < 3 or nlon < 4:
                print "Make sure that nlat >=3, and nlon >=4."
                raise ValueError
            else:
                self._SkyMap__X   = numpy.zeros( ( nlat , nlon ) , dtype='complex' )
                self._SkyMap__sky = LISAresponse.mySpharmt( nlon , nlat )
        else:
            nlat , nlon = X.shape
            self._SkyMap__X   = numpy.copy( X )
            self._SkyMap__sky = LISAresponse.mySpharmt( nlon , nlat )
        return
Example #6
0
    def __init__(self, nlat=3, nlon=4, X=None):
        super(XSkyMap, self).__init__()

        if X == None:
            if nlat < 3 or nlon < 4:
                print "Make sure that nlat >=3, and nlon >=4."
                raise ValueError
            else:
                self._SkyMap__X = numpy.zeros((nlat, nlon), dtype='complex')
                self._SkyMap__sky = LISAresponse.mySpharmt(nlon, nlat)
        else:
            nlat, nlon = X.shape
            self._SkyMap__X = numpy.copy(X)
            self._SkyMap__sky = LISAresponse.mySpharmt(nlon, nlat)
        return
Example #7
0
def checkPIXELCONVERSION( lmax , nlat , nlon ) :
    """
    INPUT:
    lmax -- maximum degree of SpH, l
    nlat -- number of latitudes
    nlon -- number of longitudes 
    OUTPUT:
    U -- matrix for converting a matrix from SpH to PIXELS
    lats -- latitudes, repeated nlon times
    lons -- longitudes, repeated nlat times
    """
    indxpn = LISAresponse.getMLvec( lmax , 'pn' )
    U = numpy.empty( ( nlat*nlon , len(indxpn) ) , dtype='complex' )
    for i,ml in enumerate( indxpn ) :
        M = xlmSkyMap( ntrunc=ml[-1] )
        M.alter_ml( False , ( ml[0] , ml[-1] , 1 ) )
        M.xlm_to_plm()
        M.xlm_to_qlm()
        M.create_sky( nlat=nlat , nlon=nlon )
        M.plm_to_P()
        M.qlm_to_Q()
        M.PQ_to_X()
        U[ :,i ] = numpy.reshape( M.X , ( nlat*nlon, ) )

    lats = numpy.outer( M.sky.lats , numpy.ones( nlon ) )
    lons = numpy.outer( numpy.ones( nlat ) , M.sky.lons )
    lats = numpy.reshape( lats , ( nlat*nlon , ) )
    lons = numpy.reshape( lons , ( nlat*nlon , ) )
    return U , lats , lons
Example #8
0
def checkPIXELCONVERSION(lmax, nlat, nlon):
    """
    INPUT:
    lmax -- maximum degree of SpH, l
    nlat -- number of latitudes
    nlon -- number of longitudes 
    OUTPUT:
    U -- matrix for converting a matrix from SpH to PIXELS
    lats -- latitudes, repeated nlon times
    lons -- longitudes, repeated nlat times
    """
    indxpn = LISAresponse.getMLvec(lmax, 'pn')
    U = numpy.empty((nlat * nlon, len(indxpn)), dtype='complex')
    for i, ml in enumerate(indxpn):
        M = xlmSkyMap(ntrunc=ml[-1])
        M.alter_ml(False, (ml[0], ml[-1], 1))
        M.xlm_to_plm()
        M.xlm_to_qlm()
        M.create_sky(nlat=nlat, nlon=nlon)
        M.plm_to_P()
        M.qlm_to_Q()
        M.PQ_to_X()
        U[:, i] = numpy.reshape(M.X, (nlat * nlon, ))

    lats = numpy.outer(M.sky.lats, numpy.ones(nlon))
    lons = numpy.outer(numpy.ones(nlat), M.sky.lons)
    lats = numpy.reshape(lats, (nlat * nlon, ))
    lons = numpy.reshape(lons, (nlat * nlon, ))
    return U, lats, lons
Example #9
0
    def qlm_to_Q( self ):
        indxp = LISAresponse.getMLvec( self.ntrunc , 'p' )
        to_pyspharm = numpy.zeros( ( len(indxp), ) )
        for i,ml in enumerate( indxp ):
            to_pyspharm[i] = (-1)**ml[0] / numpy.sqrt( 2*numpy.pi )

        self._SkyMap__Q = self.sky.spectogrd( to_pyspharm * self.qlm )
        return
Example #10
0
    def qlm_to_Q(self):
        indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
        to_pyspharm = numpy.zeros((len(indxp), ))
        for i, ml in enumerate(indxp):
            to_pyspharm[i] = (-1)**ml[0] / numpy.sqrt(2 * numpy.pi)

        self._SkyMap__Q = self.sky.spectogrd(to_pyspharm * self.qlm)
        return
Example #11
0
 def getImagMultipleMoments(self,msign='pn'):
     try:
         assert msign=='p' or msign=='pn'
     except AssertionError:
         print "Keyword parameter 'msign' must either be 'p' for only positive m's or 'pn' for all m's."
     indxpn = LISAresponse.getMLvec( self.ntrunc , 'pn' )
     qlm = numpy.zeros( numpy.shape(self.xlm) , dtype = complex )
     for i,ml in enumerate(indxpn):
         m = ml[0]
         l = ml[1]
         k = indxpn.index((-m,l))
         qlm[i] = ( self.xlm[i] - (-1)**m*numpy.conj(self.xlm[k]) ) / 2j
     if ( msign=='p' ):
         indxp = LISAresponse.getMLvec( self.ntrunc , 'p' )
         qlm = qlm[:len(indxp)]
     else:
         qlm = qlm
     return qlm
Example #12
0
 def getImagMultipleMoments(self, msign='pn'):
     try:
         assert msign == 'p' or msign == 'pn'
     except AssertionError:
         print "Keyword parameter 'msign' must either be 'p' for only positive m's or 'pn' for all m's."
     indxpn = LISAresponse.getMLvec(self.ntrunc, 'pn')
     qlm = numpy.zeros(numpy.shape(self.xlm), dtype=complex)
     for i, ml in enumerate(indxpn):
         m = ml[0]
         l = ml[1]
         k = indxpn.index((-m, l))
         qlm[i] = (self.xlm[i] - (-1)**m * numpy.conj(self.xlm[k])) / 2j
     if (msign == 'p'):
         indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
         qlm = qlm[:len(indxp)]
     else:
         qlm = qlm
     return qlm
Example #13
0
    def Q_to_qlm( self ):
        indxp =LISAresponse.getMLvec( self.ntrunc , 'p' )
        to_standard = numpy.zeros( ( len(indxp), ) )

        for i, ml in enumerate( indxp ):
            to_standard[i] = (-1)**ml[0] * numpy.sqrt( 2*numpy.pi )
                        
        self._SkyMap__qlm = to_standard * self.sky.grdtospec( self.Q , self.ntrunc )
        return
Example #14
0
    def Q_to_qlm(self):
        indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
        to_standard = numpy.zeros((len(indxp), ))

        for i, ml in enumerate(indxp):
            to_standard[i] = (-1)**ml[0] * numpy.sqrt(2 * numpy.pi)

        self._SkyMap__qlm = to_standard * self.sky.grdtospec(
            self.Q, self.ntrunc)
        return
Example #15
0
 def getMultipleMoments(self, msign='pn'):
     try:
         assert msign == 'p' or msign == 'pn'
     except AssertionError:
         print "Keyword parameter 'msign' must either be 'p' for only positive m's or 'pn' for all m's."
     if (msign == 'p'):
         indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
         xlm = self.xlm[:len(indxp)]
     else:
         xlm = self.xlm
     return xlm
Example #16
0
 def getMultipleMoments(self,msign='pn'):
     try:
         assert msign=='p' or msign=='pn'
     except AssertionError:
         print "Keyword parameter 'msign' must either be 'p' for only positive m's or 'pn' for all m's."
     if ( msign == 'p' ):
         indxp = LISAresponse.getMLvec( self.ntrunc , 'p' )
         xlm = self.xlm[:len(indxp)]
     else:
         xlm = self.xlm
     return xlm
Example #17
0
    def getMultipleMoments(self, msign='pn'):
        if not hasattr(self, 'ntrunc'):
            self.getntrunc()
        try:
            assert msign == 'p' or msign == 'pn'
        except AssertionError:
            print "Keyword parameter 'msign' must either be 'p' for only positive m's or 'pn' for all m's."
        numf = self.Length

        sqrt2pi = numpy.sqrt(2 * numpy.pi)

        if (msign == 'p'):
            indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
            p = self.realr - 1j * self.reali  # + 1j*self.reali
            q = self.imagr - 1j * self.imagi  # + 1j*self.imagi
            g = numpy.zeros((len(indxp), numf), complex)
            for i, ml in enumerate(indxp):
                g[i] = (-1)**ml[0] * sqrt2pi * (p[i] + 1j * q[i])
            self.indxp = indxp
            self.Moments_pm = g
        else:
            indxp = LISAresponse.getMLvec(self.ntrunc, 'p')
            indxpn = LISAresponse.getMLvec(self.ntrunc, 'pn')
            p = self.realr - 1j * self.reali  # + 1j*self.reali
            q = self.imagr - 1j * self.imagi  # + 1j*self.imagi
            g = numpy.zeros((len(indxpn), numf), complex)
            for i, ml in enumerate(indxpn):
                m = ml[0]
                l = ml[1]
                if m >= 0:
                    k = indxp.index(ml)
                    g[i, :] = (-1)**m * sqrt2pi * (p[k, :] + 1j * q[k, :])
                else:
                    ml = (-m, l)
                    k = indxp.index(ml)
                    g[i, :] = sqrt2pi * (numpy.conj(p[k, :]) +
                                         1j * numpy.conj(q[k, :]))
            self.indxpn = indxpn
            self.Moments = g
        return g
Example #18
0
    def getMultipleMoments(self,msign='pn'):
        if not hasattr(self,'ntrunc'):
            self.getntrunc()
        try:
            assert msign=='p' or msign=='pn'
        except AssertionError:
            print "Keyword parameter 'msign' must either be 'p' for only positive m's or 'pn' for all m's."
        numf = self.Length
        
        sqrt2pi = numpy.sqrt( 2*numpy.pi )

        if (msign == 'p'):
            indxp = LISAresponse.getMLvec(self.ntrunc,'p')
            p = self.realr - 1j*self.reali # + 1j*self.reali
            q = self.imagr - 1j*self.imagi # + 1j*self.imagi
            g = numpy.zeros( ( len(indxp),numf ) , complex )
            for i,ml in enumerate( indxp ):
                g[i] = (-1)**ml[0] * sqrt2pi * ( p[i] + 1j*q[i] )
            self.indxp = indxp
            self.Moments_pm = g
        else:
            indxp  = LISAresponse.getMLvec(self.ntrunc,'p')
            indxpn = LISAresponse.getMLvec(self.ntrunc,'pn')
            p = self.realr - 1j*self.reali # + 1j*self.reali
            q = self.imagr - 1j*self.imagi # + 1j*self.imagi
            g = numpy.zeros( ( len(indxpn),numf ) ,complex)
            for i,ml in enumerate(indxpn):
                m = ml[0]
                l = ml[1]
                if m >= 0:
                    k = indxp.index(ml)
                    g[i,:] = (-1)**m * sqrt2pi * ( p[k,:] + 1j*q[k,:] )
                else:
                    ml = (-m,l)
                    k = indxp.index(ml)
                    g[i,:] = sqrt2pi * ( numpy.conj(p[k,:]) + 1j*numpy.conj(q[k,:]) )
            self.indxpn = indxpn        
            self.Moments = g
        return g
Example #19
0
 def getPixels(self):
     nlat = self.ntrunc + 30
     nlon = 2 * (nlat - 1)
     self.sky = LISAresponse.mySpharmt(nlon, nlat)
     if self.maptype in ['X', 'XX']:
         norm = 1e-45
     elif self.maptype in ['P']:
         norm = 1
     xlm = self.getMultipleMoments('p') * norm
     plm = self.getRealMultipleMoments('p') * norm
     qlm = self.getImagMultipleMoments('p') * norm
     self.pix = self.sky.spectogrd(xlm)
     self.pixp = self.sky.spectogrd(plm)
     self.pixq = self.sky.spectogrd(qlm)
     self.gotpix = True
     return self.pix, self.pixp, self.pixq
Example #20
0
 def getPixels(self):
     nlat = self.ntrunc + 30
     nlon = 2*(nlat - 1)
     self.sky  = LISAresponse.mySpharmt(nlon,nlat)
     if self.maptype in ['X','XX']:
         norm = 1e-45
     elif self.maptype in ['P']:
         norm = 1
     xlm  = self.getMultipleMoments('p')      * norm
     plm  = self.getRealMultipleMoments('p')  * norm
     qlm  = self.getImagMultipleMoments('p')  * norm
     self.pix  = self.sky.spectogrd(xlm)
     self.pixp = self.sky.spectogrd(plm)
     self.pixq = self.sky.spectogrd(qlm)
     self.gotpix = True
     return self.pix, self.pixp, self.pixq
Example #21
0
    def AngularPower(self, l=0, realimag='real'):
        if realimag == 'real':
            xlm = numpy.copy(self.plm)
        elif realimag == 'imag':
            xlm = numpy.copy(self.qlm)
        else:
            raise Exception, "realimag must either be 'real' or 'imag'."

        mlvec = LISAresponse.getMLvec(self.ntrunc)

        angpower = 0
        for m in range(l + 1):
            dangpower = abs(xlm[mlvec.index((m, l))])**2
            if m == 0:
                angpower += dangpower
            else:
                angpower += 2 * dangpower
        return angpower
Example #22
0
    def AngularPower( self , l=0 , realimag='real' ) :
        if realimag == 'real' :
            xlm = numpy.copy( self.plm )
        elif realimag == 'imag' :
            xlm = numpy.copy( self.qlm )
        else :
            raise Exception , "realimag must either be 'real' or 'imag'."

        mlvec = LISAresponse.getMLvec( self.ntrunc )        

        angpower = 0
        for m in range( l+1 ) :
            dangpower = abs( xlm[ mlvec.index( (m,l) ) ] )**2
            if m == 0 :
                angpower += dangpower
            else :
                angpower += 2 * dangpower
        return angpower
Example #23
0
    def alter_ml( self , add_on=False , *mlvs ):
        if mlvs == ():
            print "No (m,l) to add/overwrite."
            return

        mlvec = LISAresponse.getMLvec( self.ntrunc )

        for mlv in mlvs:
            m , l , value = mlv

            if (m,l) not in mlvec:
                print "(%d,%d) is out of range. lmax = %d . " % ( m , l ,self.ntrunc )
                continue

            indx = mlvec.index( (m,l) )
            if add_on==False:
                self._SkyMap__xlm[ indx ] = value
            elif add_on==True:
                self._SkyMap__xlm[ indx ] = self._SkyMap__xlm[ indx ] + value
        return
Example #24
0
    def alter_ml(self, add_on=False, *mlvs):
        if mlvs == ():
            print "No (m,l) to add/overwrite."
            return

        mlvec = LISAresponse.getMLvec(self.ntrunc)

        for mlv in mlvs:
            m, l, value = mlv

            if (m, l) not in mlvec:
                print "(%d,%d) is out of range. lmax = %d . " % (m, l,
                                                                 self.ntrunc)
                continue

            indx = mlvec.index((m, l))
            if add_on == False:
                self._SkyMap__xlm[indx] = value
            elif add_on == True:
                self._SkyMap__xlm[indx] = self._SkyMap__xlm[indx] + value
        return
Example #25
0
 def create_sky( self , nlon=6 , nlat=4 ):
     self._SkyMap__sky = LISAresponse.mySpharmt( nlon , nlat )
     return
Example #26
0
 def create_sky(self, nlon=6, nlat=4):
     self._SkyMap__sky = LISAresponse.mySpharmt(nlon, nlat)
     return
Example #27
0
import cPickle
import LISAresponse
import Utilities4 as U4


sourcename = ''  #Name your custom function something.

mapdir = ''


nlon =
nlat = 

ntrunc = 20

sky = LISAresponse.mySpharmt( nlon , nlat )
X = numpy.zeros( ( nlat , nlon ) )
for i,lat in enumerate( sky.lats ):
    theta = ( 90 - lat ) / 180 * numpy.pi
    for k,lon in enumerate( sky.lons ):
        lon = lon / 180 * numpy.pi
        X[ i,k ] = #Enter your function here in terms of theta and lon

skymap = U4.XSkyMap( X=X )
skymap.X_to_P()
skymap.X_to_Q()
skymap.ntrunc_equals( ntrunc )
skymap.P_to_plm()
skymap.Q_to_qlm()
skymap.plmqlm_to_xlm()