Changeset 2372


Ignore:
Timestamp:
12/16/11 16:03:11 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: No

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Speed up plot routine.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapgrid.py

    r2367 r2372  
    6262        if self.outfile is None:
    6363            self.outfile = self.infile.rstrip('/')+'.grid'
    64         self.grid = None
    65         self.pointing = None
    6664        self.nx = -1
    6765        self.ny = -1
     
    7472        self.nonzero = [[0.0],[0.0]]
    7573        self.ifno = ifno
     74        self.tablein = None
     75        self.nrow = 0
     76        self.blc = None
     77        self.trc = None
    7678        self.get()
    7779
    7880    def get( self ):
    79         s = scantable( self.infile, average=False )
     81        self.tablein = scantable( self.infile, average=False )
    8082        sel = selector()
    8183        sel.set_ifs( self.ifno )
    82         s.set_selection( sel )
    83         self.pointing = numpy.array( s.get_directionval() ).transpose()
    84         self.nchan = len(s._getspectrum(0))
    85         s.set_selection()
    86         del s
     84        self.tablein.set_selection( sel )
     85        self.nchan = len(self.tablein._getspectrum(0))
     86        self.nrow = self.tablein.nrow()
    8787        del sel
    8888
     
    9898        #print 'npol=',self.npol
    9999        #print 'nrow=',nrow
    100         dirstring = numpy.array(s.get_direction()).take(range(0,nrow,self.npol))
    101         self.grid = numpy.array( s.get_directionval() ).take(range(0,nrow,self.npol),axis=0).transpose()
    102100
    103101        idx = 0
    104         d0 = dirstring[0].split()[-1]
    105         while ( dirstring[idx].split()[-1] == d0 ): 
     102        d0 = s.get_direction( 0 ).split()[-1]
     103        while ( s.get_direction(self.npol*idx).split()[-1] == d0 ): 
    106104            idx += 1
    107105       
    108         self.ny = idx
    109         self.nx = nrow / (self.npol * idx )
     106        self.nx = idx
     107        self.ny = nrow / (self.npol * idx )
    110108        #print 'nx,ny=',self.nx,self.ny
    111        
    112         self.cellx = abs( self.grid[0][0] - self.grid[0][1] )
    113         self.celly = abs( self.grid[1][0] - self.grid[1][self.ny] )
     109
     110        self.blc = s.get_directionval( 0 )
     111        self.trc = s.get_directionval( nrow-self.npol )
     112        #print self.blc
     113        #print self.trc
     114        incrx = s.get_directionval( self.npol )
     115        incry = s.get_directionval( self.nx*self.npol )
     116        self.cellx = abs( self.blc[0] - incrx[0] )
     117        self.celly = abs( self.blc[1] - incry[1] )
    114118        #print 'cellx,celly=',self.cellx,self.celly
    115119
     
    127131        pl.figure(10)
    128132        pl.clf()
    129         pl.plot(self.grid[0],self.grid[1],',',color='blue')
    130         pl.plot(self.pointing[0],self.pointing[1],',',color='green')
    131         extent=[self.grid[0].min()-0.5*self.cellx,
    132                 self.grid[0].max()+0.5*self.cellx,
    133                 self.grid[1].min()-0.5*self.celly,
    134                 self.grid[1].max()+0.5*self.celly]
     133        # plot grid position
     134        x = numpy.arange(self.blc[0],self.trc[0]+0.5*self.cellx,self.cellx,dtype=float)
     135        #print 'len(x)=',len(x)
     136        #print 'x=',x
     137        ybase = numpy.ones(self.ny,dtype=float)*self.blc[1]
     138        #print 'len(ybase)=',len(ybase)
     139        incr = self.celly
     140        for iy in xrange(self.ny):
     141            y = ybase + iy * incr
     142            #print y
     143            pl.plot(x,y,',',color='blue')
     144        # plot observed position
     145        irow = 0
     146        while ( irow < self.nrow ):
     147            chunk = self.getPointingChunk( irow )
     148            #print chunk
     149            pl.plot(chunk[0],chunk[1],',',color='green')
     150            irow += chunk.shape[1]
     151            #print irow
     152        # show image
     153        extent=[self.blc[0]-0.5*self.cellx,
     154                self.trc[0]+0.5*self.cellx,
     155                self.blc[1]-0.5*self.celly,
     156                self.trc[1]+0.5*self.celly]
    135157        pl.imshow(data,extent=extent,origin='lower',interpolation='nearest')
    136158        pl.colorbar()
     
    139161        pl.title( title )
    140162
     163    def getPointingChunk( self, irow ):
     164        numchunk = 1000
     165        nrow = min( self.nrow-irow, numchunk )
     166        #print 'nrow=',nrow
     167        v = numpy.zeros( (2,nrow), dtype=float )
     168        idx = 0
     169        for i in xrange(irow,irow+nrow):
     170            d = self.tablein.get_directionval( i )
     171            v[0,idx] = d[0]
     172            v[1,idx] = d[1]
     173            idx += 1
     174        return v
     175
    141176    def getData( self, chan=-1, pol=-1 ):
    142177        if chan == -1:
     
    144179        else:
    145180            spectra = self.__chanIndex( chan )
    146         data = spectra.reshape( (self.npol,self.nx,self.ny) )
     181        data = spectra.reshape( (self.npol,self.ny,self.nx) )
    147182        if pol == -1:
    148183            retval = data.mean(axis=0)
    149184        else:
    150185            retval = data[pol]
     186        #retval[0][self.nx-1] = -1.0
    151187        return retval
    152188
    153189    def __chanAverage( self ):
    154190        s = scantable( self.outfile, average=False )
    155         nrow = self.nx * self.ny
     191        nrow = s.nrow()
    156192        spectra = numpy.zeros( (self.npol,nrow/self.npol), dtype=float )
    157193        irow = 0
     
    166202    def __chanIndex( self, idx ):
    167203        s = scantable( self.outfile, average=False )
    168         nrow = self.nx * self.ny
     204        nrow = s.nrow()
    169205        spectra = numpy.zeros( (self.npol,nrow/self.npol), dtype=float )
    170206        irow = 0
Note: See TracChangeset for help on using the changeset viewer.