source: trunk/python/asapgrid.py @ 2358

Last change on this file since 2358 was 2358, checked in by Takeshi Nakazato, 12 years ago

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...

Updated plotter class.


File size: 3.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 defineImage( self, nx=-1, ny=-1, cellx='', celly='', center='' ):
16        self.gridder._defineimage( nx, ny, cellx, celly, center )
17
18    def setOption( self, convType='box', convSupport=-1 ):
19        self.gridder._setoption( convType, convSupport )
20
21    def grid( self ):
22        self.gridder._grid()
23
24    def save( self, outfile='' ):
25        self.outfile = self.gridder._save( outfile )
26
27    def plot( self, plotchan=-1 ):
28        plotter = _SDGridPlotter( self.infile, self.outfile )
29        plotter.plot( chan=plotchan )
30       
31class _SDGridPlotter:
32    def __init__( self, infile, outfile=None ):
33        self.infile = infile
34        self.outfile = outfile
35        if self.outfile is None:
36            self.outfile = self.infile.rstrip('/')+'.grid'
37        self.grid = None
38        self.pointing = None
39        self.data = None
40        self.nx = -1
41        self.ny = -1
42        self.nchan = 0
43        self.cellx = 0.0
44        self.celly = 0.0
45        self.center = [0.0,0.0]
46        self.nonzero = [[0.0],[0.0]]
47        self.get()
48
49    def get( self ):
50        s = scantable( self.infile, average=False )
51        self.pointing = numpy.array( s.get_directionval() ).transpose()
52        spectra = []
53        for i in xrange(s.nrow()):
54            spectra.append( s._getspectrum( i ) )
55        spectra = numpy.array( spectra ).transpose()
56        self.nchan = spectra.shape[0]
57        del s
58
59        idx = spectra.nonzero()[1]
60        #self.nonzero = self.pointing.take( idx, axis=1 )
61       
62        s = scantable( self.outfile, average=False )
63        self.grid = numpy.array( s.get_directionval() ).transpose()
64        dirstring = s.get_direction()
65        nrow = s.nrow()
66        spectra = []
67        for i in xrange(nrow):
68            spectra.append( s._getspectrum( i ) )
69        spectra = numpy.array( spectra ).transpose()
70
71        idx = 0
72        d0 = dirstring[0].split()[-1]
73        while ( dirstring[idx].split()[-1] == d0 ): 
74            idx += 1
75
76        self.ny = idx
77        self.nx = nrow / idx
78       
79        self.cellx = abs( self.grid[0][0] - self.grid[0][1] )
80        self.celly = abs( self.grid[1][0] - self.grid[1][self.ny] )
81
82        self.data = spectra.reshape( (self.nchan,self.nx,self.ny) )
83
84    def plot( self, chan=-1 ):
85        if chan < 0:
86            data = self.data.mean(axis=0)
87            title = 'Gridded Image (averaged over channel)'
88        else:
89            data = self.data[chan]
90            title = 'Gridded Image (channel %s)'%(chan)
91        pl.figure(10)
92        pl.clf()
93        pl.plot(self.grid[0],self.grid[1],'.',color='blue')
94        pl.plot(self.pointing[0],self.pointing[1],'.',color='red')
95        #pl.plot(self.nonzero[0],self.nonzero[1],'o',color='green')
96        extent=[self.grid[0].min()-0.5*self.cellx,
97                self.grid[0].max()+0.5*self.cellx,
98                self.grid[1].min()-0.5*self.celly,
99                self.grid[1].max()+0.5*self.celly]
100        pl.imshow(data,extent=extent,origin='lower',interpolation='nearest')
101        pl.colorbar()
102        pl.xlabel('R.A. [rad]')
103        pl.ylabel('Dec. [rad]')
104        pl.title( title )
Note: See TracBrowser for help on using the repository browser.