- Timestamp:
- 12/14/11 13:24:30 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapgrid.py
r2365 r2367 1 1 import numpy 2 from asap import rcParams 2 3 from asap.scantable import scantable 4 from asap.selector import selector 3 5 from asap._asap import stgrid 4 6 import pylab as pl 7 from logging import asaplog 5 8 6 9 class asapgrid: … … 9 12 self.outfile = None 10 13 self.gridder = stgrid( self.infile ) 14 self.ifno = None 11 15 12 16 def setData( self, infile ): … … 14 18 15 19 def setIF( self, ifno ): 16 self.gridder._setif( ifno ) 20 self.ifno = ifno 21 self.gridder._setif( self.ifno ) 17 22 18 23 def setPolList( self, pollist ): … … 38 43 39 44 def plot( self, plotchan=-1, plotpol=-1 ): 40 plotter = _SDGridPlotter( self.infile, self.outfile ) 45 import time 46 t0=time.time() 47 # to load scantable on disk 48 storg = rcParams['scantable.storage'] 49 rcParams['scantable.storage'] = 'disk' 50 plotter = _SDGridPlotter( self.infile, self.outfile, self.ifno ) 41 51 plotter.plot( chan=plotchan, pol=plotpol ) 52 # back to original setup 53 rcParams['scantable.storage'] = storg 54 t1=time.time() 55 asaplog.push('plot: elapsed time %s sec'%(t1-t0)) 56 asaplog.post('DEBUG','asapgrid.plot') 42 57 43 58 class _SDGridPlotter: 44 def __init__( self, infile, outfile=None ):59 def __init__( self, infile, outfile=None, ifno=0 ): 45 60 self.infile = infile 46 61 self.outfile = outfile … … 49 64 self.grid = None 50 65 self.pointing = None 51 self.data = None52 66 self.nx = -1 53 67 self.ny = -1 … … 59 73 self.center = [0.0,0.0] 60 74 self.nonzero = [[0.0],[0.0]] 75 self.ifno = ifno 61 76 self.get() 62 77 63 78 def get( self ): 64 79 s = scantable( self.infile, average=False ) 80 sel = selector() 81 sel.set_ifs( self.ifno ) 82 s.set_selection( sel ) 65 83 self.pointing = numpy.array( s.get_directionval() ).transpose() 66 spectra = [] 67 for i in xrange(s.nrow()): 68 spectra.append( s._getspectrum( i ) ) 69 spectra = numpy.array( spectra ).transpose() 70 self.nchan = spectra.shape[0] 84 self.nchan = len(s._getspectrum(0)) 85 s.set_selection() 71 86 del s 87 del sel 72 88 73 89 s = scantable( self.outfile, average=False ) … … 84 100 dirstring = numpy.array(s.get_direction()).take(range(0,nrow,self.npol)) 85 101 self.grid = numpy.array( s.get_directionval() ).take(range(0,nrow,self.npol),axis=0).transpose() 86 spectra = numpy.zeros( (self.npol,self.nchan,nrow/self.npol), dtype=float )87 irow = 088 for i in xrange(nrow/self.npol):89 for ip in xrange(self.npol):90 spectra[ip,:,i] = s._getspectrum( irow )91 irow += 192 102 93 103 idx = 0 … … 95 105 while ( dirstring[idx].split()[-1] == d0 ): 96 106 idx += 1 107 97 108 self.ny = idx 98 109 self.nx = nrow / (self.npol * idx ) … … 103 114 #print 'cellx,celly=',self.cellx,self.celly 104 115 105 self.data = spectra.reshape( (self.npol,self.nchan,self.nx,self.ny) )106 107 116 def plot( self, chan=-1, pol=-1 ): 108 117 if pol < 0: 109 data = self.data.mean(axis=0)110 118 opt = 'averaged over pol' 111 119 else: 112 idx = self.pollist.tolist().index( pol )113 #print 'idx=',idx114 data = self.data[idx]115 120 opt = 'pol %s'%(pol) 116 121 if chan < 0: 117 data = data.mean(axis=0)118 122 opt += ', averaged over channel' 119 123 else: 120 data = data[chan]121 124 opt += ', channel %s'%(chan) 125 data = self.getData( chan, pol ) 122 126 title = 'Gridded Image (%s)'%(opt) 123 127 pl.figure(10) … … 134 138 pl.ylabel('Dec. [rad]') 135 139 pl.title( title ) 140 141 def getData( self, chan=-1, pol=-1 ): 142 if chan == -1: 143 spectra = self.__chanAverage() 144 else: 145 spectra = self.__chanIndex( chan ) 146 data = spectra.reshape( (self.npol,self.nx,self.ny) ) 147 if pol == -1: 148 retval = data.mean(axis=0) 149 else: 150 retval = data[pol] 151 return retval 152 153 def __chanAverage( self ): 154 s = scantable( self.outfile, average=False ) 155 nrow = self.nx * self.ny 156 spectra = numpy.zeros( (self.npol,nrow/self.npol), dtype=float ) 157 irow = 0 158 sp = [0 for i in xrange(self.nchan)] 159 for i in xrange(nrow/self.npol): 160 for ip in xrange(self.npol): 161 sp = s._getspectrum( irow ) 162 spectra[ip,i] = numpy.mean( sp ) 163 irow += 1 164 return spectra 165 166 def __chanIndex( self, idx ): 167 s = scantable( self.outfile, average=False ) 168 nrow = self.nx * self.ny 169 spectra = numpy.zeros( (self.npol,nrow/self.npol), dtype=float ) 170 irow = 0 171 sp = [0 for i in xrange(self.nchan)] 172 for i in xrange(nrow/self.npol): 173 for ip in xrange(self.npol): 174 sp = s._getspectrum( irow ) 175 spectra[ip,i] = sp[idx] 176 irow += 1 177 return spectra 178 179
Note:
See TracChangeset
for help on using the changeset viewer.