source: trunk/python/asapgrid.py@ 2356

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

New Development: Yes

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

Defined new class STGrid and its python interface.
The STGrid class performs single dish gridding.
At the moment, only single polarization data is supported.


File size: 3.2 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 ):
28 plotter = _SDGridPlotter( self.infile, self.outfile )
29 plotter.plot()
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 else:
88 data = self.data[chan]
89 pl.figure(10)
90 pl.clf()
91 pl.plot(self.grid[0],self.grid[1],'.',color='blue')
92 pl.plot(self.pointing[0],self.pointing[1],'.',color='red')
93 pl.plot(self.nonzero[0],self.nonzero[1],'o',color='green')
94 extent=[self.grid[0].min()-0.5*self.cellx,
95 self.grid[0].max()+0.5*self.cellx,
96 self.grid[1].min()-0.5*self.celly,
97 self.grid[1].max()+0.5*self.celly]
98 pl.imshow(data,extent=extent,origin='lower',interpolation='nearest')
99 pl.colorbar()
100 pl.xlabel('R.A. [rad]')
101 pl.ylabel('Dec. [rad]')
Note: See TracBrowser for help on using the repository browser.