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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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