Changeset 2372 for trunk/python
- Timestamp:
- 12/16/11 16:03:11 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapgrid.py
r2367 r2372 62 62 if self.outfile is None: 63 63 self.outfile = self.infile.rstrip('/')+'.grid' 64 self.grid = None65 self.pointing = None66 64 self.nx = -1 67 65 self.ny = -1 … … 74 72 self.nonzero = [[0.0],[0.0]] 75 73 self.ifno = ifno 74 self.tablein = None 75 self.nrow = 0 76 self.blc = None 77 self.trc = None 76 78 self.get() 77 79 78 80 def get( self ): 79 s = scantable( self.infile, average=False )81 self.tablein = scantable( self.infile, average=False ) 80 82 sel = selector() 81 83 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() 87 87 del sel 88 88 … … 98 98 #print 'npol=',self.npol 99 99 #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()102 100 103 101 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 ): 106 104 idx += 1 107 105 108 self.n y= idx109 self.n x= nrow / (self.npol * idx )106 self.nx = idx 107 self.ny = nrow / (self.npol * idx ) 110 108 #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] ) 114 118 #print 'cellx,celly=',self.cellx,self.celly 115 119 … … 127 131 pl.figure(10) 128 132 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] 135 157 pl.imshow(data,extent=extent,origin='lower',interpolation='nearest') 136 158 pl.colorbar() … … 139 161 pl.title( title ) 140 162 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 141 176 def getData( self, chan=-1, pol=-1 ): 142 177 if chan == -1: … … 144 179 else: 145 180 spectra = self.__chanIndex( chan ) 146 data = spectra.reshape( (self.npol,self.n x,self.ny) )181 data = spectra.reshape( (self.npol,self.ny,self.nx) ) 147 182 if pol == -1: 148 183 retval = data.mean(axis=0) 149 184 else: 150 185 retval = data[pol] 186 #retval[0][self.nx-1] = -1.0 151 187 return retval 152 188 153 189 def __chanAverage( self ): 154 190 s = scantable( self.outfile, average=False ) 155 nrow = s elf.nx * self.ny191 nrow = s.nrow() 156 192 spectra = numpy.zeros( (self.npol,nrow/self.npol), dtype=float ) 157 193 irow = 0 … … 166 202 def __chanIndex( self, idx ): 167 203 s = scantable( self.outfile, average=False ) 168 nrow = s elf.nx * self.ny204 nrow = s.nrow() 169 205 spectra = numpy.zeros( (self.npol,nrow/self.npol), dtype=float ) 170 206 irow = 0
Note:
See TracChangeset
for help on using the changeset viewer.