source: trunk/python/asapgrid.py @ 2361

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

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: No

Interface Changes: Yes

What Interface Changed: Added method to set weight type

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Weighting type can be specified.
Supported types are:

UNIFORM
TINT
TSYS
TINTSYS


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