source: trunk/python/asapgrid.py@ 2363

Last change on this file since 2363 was 2363, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: No

Interface Changes: Yes/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...

For Gaussian kernel, user-specified kernel width is treated as HWHM,
and convolution support is set to 4*HWHM.


File size: 4.4 KB
Line 
1import numpy
2from asap.scantable import scantable
3from asap._asap import stgrid
4import pylab as pl
5
6class asapgrid:
7 def __init__( self, infile ):
8 self.infile = infile
9 self.outfile = None
10 self.gridder = stgrid( self.infile )
11
12 def setData( self, infile ):
13 self.gridder._setin( infile )
14
15 def setIF( self, ifno ):
16 self.gridder._setif( ifno )
17
18 def setPolList( self, pollist ):
19 self.gridder._setpollist( pollist )
20
21 def defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ):
22 self.gridder._defineimage( nx, ny, cellx, celly, center )
23
24 def setOption( self, convType='box', width=-1 ):
25 self.gridder._setoption( convType, width )
26
27 def setWeight( self, weightType='uniform' ):
28 self.gridder._setweight( weightType )
29
30 def grid( self ):
31 self.gridder._grid()
32
33 def save( self, outfile='' ):
34 self.outfile = self.gridder._save( outfile )
35
36 def plot( self, plotchan=-1, plotpol=-1 ):
37 plotter = _SDGridPlotter( self.infile, self.outfile )
38 plotter.plot( chan=plotchan, pol=plotpol )
39
40class _SDGridPlotter:
41 def __init__( self, infile, outfile=None ):
42 self.infile = infile
43 self.outfile = outfile
44 if self.outfile is None:
45 self.outfile = self.infile.rstrip('/')+'.grid'
46 self.grid = None
47 self.pointing = None
48 self.data = None
49 self.nx = -1
50 self.ny = -1
51 self.nchan = 0
52 self.npol = 0
53 self.pollist = []
54 self.cellx = 0.0
55 self.celly = 0.0
56 self.center = [0.0,0.0]
57 self.nonzero = [[0.0],[0.0]]
58 self.get()
59
60 def get( self ):
61 s = scantable( self.infile, average=False )
62 self.pointing = numpy.array( s.get_directionval() ).transpose()
63 spectra = []
64 for i in xrange(s.nrow()):
65 spectra.append( s._getspectrum( i ) )
66 spectra = numpy.array( spectra ).transpose()
67 self.nchan = spectra.shape[0]
68 del s
69
70 s = scantable( self.outfile, average=False )
71 nrow = s.nrow()
72 pols = numpy.ones( nrow, dtype=int )
73 for i in xrange(nrow):
74 pols[i] = s.getpol(i)
75 self.pollist, indices = numpy.unique( pols, return_inverse=True )
76 self.npol = len(self.pollist)
77 self.pollist = self.pollist[indices[:self.npol]]
78 #print 'pollist=',self.pollist
79 #print 'npol=',self.npol
80 #print 'nrow=',nrow
81 dirstring = numpy.array(s.get_direction()).take(range(0,nrow,self.npol))
82 self.grid = numpy.array( s.get_directionval() ).take(range(0,nrow,self.npol),axis=0).transpose()
83 spectra = numpy.zeros( (self.npol,self.nchan,nrow/self.npol), dtype=float )
84 irow = 0
85 for i in xrange(nrow/self.npol):
86 for ip in xrange(self.npol):
87 spectra[ip,:,i] = s._getspectrum( irow )
88 irow += 1
89
90 idx = 0
91 d0 = dirstring[0].split()[-1]
92 while ( dirstring[idx].split()[-1] == d0 ):
93 idx += 1
94 self.ny = idx
95 self.nx = nrow / (self.npol * idx )
96 #print 'nx,ny=',self.nx,self.ny
97
98 self.cellx = abs( self.grid[0][0] - self.grid[0][1] )
99 self.celly = abs( self.grid[1][0] - self.grid[1][self.ny] )
100 #print 'cellx,celly=',self.cellx,self.celly
101
102 self.data = spectra.reshape( (self.npol,self.nchan,self.nx,self.ny) )
103
104 def plot( self, chan=-1, pol=-1 ):
105 if pol < 0:
106 data = self.data.mean(axis=0)
107 opt = 'averaged over pol'
108 else:
109 idx = self.pollist.tolist().index( pol )
110 #print 'idx=',idx
111 data = self.data[idx]
112 opt = 'pol %s'%(pol)
113 if chan < 0:
114 data = data.mean(axis=0)
115 opt += ', averaged over channel'
116 else:
117 data = data[chan]
118 opt += ', channel %s'%(chan)
119 title = 'Gridded Image (%s)'%(opt)
120 pl.figure(10)
121 pl.clf()
122 pl.plot(self.grid[0],self.grid[1],'.',color='blue')
123 pl.plot(self.pointing[0],self.pointing[1],'.',color='red')
124 extent=[self.grid[0].min()-0.5*self.cellx,
125 self.grid[0].max()+0.5*self.cellx,
126 self.grid[1].min()-0.5*self.celly,
127 self.grid[1].max()+0.5*self.celly]
128 pl.imshow(data,extent=extent,origin='lower',interpolation='nearest')
129 pl.colorbar()
130 pl.xlabel('R.A. [rad]')
131 pl.ylabel('Dec. [rad]')
132 pl.title( title )
Note: See TracBrowser for help on using the repository browser.