casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
task_sdtpimaging.py
Go to the documentation of this file.
00001 # sd task for total power raster scan imaging
00002 import os
00003 import numpy
00004 import pylab as pl
00005 import asap as sd
00006 from taskinit import *
00007 import sdutil
00008 
00009 interactive=False
00010 
00011 # This is a task version of the script originally made for reducing ATF raster scan data 
00012 # in total power mode. Still experimental...
00013 # 
00014 def sdtpimaging(infile, calmode, masklist, blpoly, backup, flaglist, antenna, spw, stokes, createimage, outfile, imsize, cell, phasecenter, ephemsrcname, pointingcolumn, gridfunction, plotlevel):
00015     # NEED to include spw, src? name for movingsource param. in function argument
00016     # put implementation here....
00017     casalog.origin('sdtpimaging')
00018     try:
00019         worker = sdtpimaging_worker(**locals())
00020         worker.initialize()
00021         worker.execute()
00022         worker.finalize()
00023 
00024     except Exception, instance:
00025         sdutil.process_exception(instance)
00026         raise Exception, instance
00027 
00028 class sdtpimaging_worker(sdutil.sdtask_template_imaging):
00029     # list of ephemeris objects that CASA supports
00030     ephemobjs = set(['MERCURY','VENUS','MARS','JUPITER','SATURN','URANUS','NEPTUNE','PLUTO','SUN','MOON'])
00031 
00032     # define stokestypes (only up to 'YL') based on enumerated stokes type in CASA
00033     stokestypes=['undef','I','Q','U','V','RR','RL','LR','LL','XX','XY','YX','YY','RX','RY','LX','LY','XR','XL','YR','YL']
00034     def __init__(self, **kwargs):
00035         super(sdtpimaging_worker,self).__init__(**kwargs)
00036 
00037     def __del__(self, base=sdutil.sdtask_template_imaging):
00038         super(sdtpimaging_worker,self).__del__()
00039 
00040     def parameter_check(self):
00041         # use FLOAT_DATA if exists
00042         self.open_table(self.infile)
00043         colnames = self.table.colnames()
00044         if any(col=='FLOAT_DATA' for col in colnames):
00045             self.datacol = 'FLOAT_DATA'
00046             casalog.post( "FLOAT_DATA exist" )
00047         else:
00048             self.datacol = 'DATA'
00049             casalog.post( "No FLOAT_DATA, DATA is used" )
00050         self.close_table()
00051 
00052         # masklist must be specified for baseline subtraction
00053         self.dobaseline = self.calmode.lower() == 'baseline'
00054         if self.dobaseline and (self.masklist is None \
00055                                 or len(self.masklist) == 0):
00056             msg='Please specify a region to be fitted in masklist'
00057             raise Exception, msg
00058 
00059         # outfile must be specified for imaging
00060         if self.createimage and self.outfile == '':
00061             msg='Please specify out image name'
00062             raise Exception, msg
00063 
00064         # flag operation
00065         self.doflag = len(self.flaglist) > 0
00066 
00067         # plot
00068         self.doplot = abs(self.plotlevel) > 0
00069         
00070     def compile(self):
00071         # common parameters
00072         self.__compile_common()
00073         
00074         # for baseline calibration
00075         if self.dobaseline:
00076             self.__compile_for_baseline()
00077 
00078         # for imaging
00079         if self.createimage:
00080             self.__compile_for_imaging()
00081 
00082     def execute(self):        
00083         if self.dobaseline:
00084             self.__backup()
00085             self.__execute_baseline()
00086         elif self.doplot:
00087             self.__plot(subplot=111, title=True, ylabel=self.datacol)
00088 
00089         if self.doflag:
00090             self.__execute_flag()
00091 
00092         if self.createimage:
00093             self.__execute_imaging()
00094 
00095     def __backup(self):
00096         # back up original file if backup == True
00097         casalog.post('%s column in %s will be overwritten.'%(self.datacol,self.infile))
00098         if self.backup:
00099             import time
00100             backupname = self.infile.rstrip('/')+'.sdtpimaging.bak.'+time.asctime(time.gmtime()).replace(' ','_')
00101             casalog.post('The task will create a back up named %s'%backupname)
00102             self.open_table(self.infile)
00103             backuptb = self.table.copy( backupname, deep=True, valuecopy=True )
00104             if backuptb:
00105                 backuptb.close()
00106             self.close_table()
00107 
00108     def __execute_baseline(self):
00109         #print "calibration begins..."
00110         #select the totalpower data for antenna1,2=1 (DV01, vertex antenna)
00111         # use generic pylab
00112         if type(self.antid) == list and len(self.antid) > 2:
00113             #print "Assume the antenna selection is all..."
00114             casalog.post( "Assume the antenna selection is all..." )
00115         self.open_table(self.infile)
00116         ndat = 0
00117         pl.ioff()
00118         # determine the size of processing data
00119         subtb = self.table.query('any(ANTENNA1==%s && ANTENNA2==%s)' % (self.antid,self.antid))
00120         nr = subtb.nrows()
00121         #nr = len(data)*len(data[0])
00122         #ndatcol = numpy.zeros((npol,nr),dtype=numpy.float)
00123         ndatcol = subtb.getcol(self.datacol)
00124         (l,m,n) = ndatcol.shape
00125         # m (= nchan) should be 1 since the task is specifically designed for total power data
00126         ndatcol.reshape(l,n) 
00127         for np in range(len(self.selcorrtypeind)):
00128             pl.figure(np+1)
00129             pl.clf()
00130             pl.subplot(311)
00131             #pl.title(infile+' Ant:'+str(antlist.values()))
00132             pl.ylabel(self.datacol,fontsize='smaller')
00133             symbols=['b.','c.']
00134 
00135             #print "Arranging data by scans..."
00136             casalog.post( "Arranging data by scans..." )
00137 
00138             data = []
00139             ndat0 = 0
00140             ndat = 0
00141             if self.selnpol == 1: np = self.selpol
00142             pl.title(self.infile.rstrip('/')+' Ant:'+self.antnameused+' '+self.corrtypestr[np])
00143             casalog.post( "select %s data..." % self.corrtypestr[np] )
00144             for i in xrange(self.nscan):
00145                 idata = []
00146                 #for j in xrange(nsubscan):
00147                 for j in xrange(self.nsubscan[i]):
00148                     # may be need to iterate on each antenna 
00149                     # identify 'scan' by STATE ID
00150                     #subtb=tb.query('any(ANTENNA1==%s && ANTENNA2==%s) && SCAN_NUMBER==%s && STATE_ID==%s' % (antid,antid,scans[i],subscans[j]))
00151                     subtb = self.table.query('any(ANTENNA1==%s && ANTENNA2==%s) && SCAN_NUMBER==%s && STATE_ID==%s' % (self.antid,self.antid,self.scans[i],self.subscans[i][j]))
00152                     datcol = subtb.getcol(self.datacol)
00153                     if self.npol > 1 and self.selnpol == 1:
00154                         #casalog.post( "select %s data..." % corrtypestr[selpol] )
00155                         rdatcol = datcol[self.selpol].real
00156                     else:
00157                         rdatcol = datcol[self.selcorrtypeind[np]].real
00158                     (m,n) = rdatcol.shape
00159                     rdatcol = rdatcol.reshape(n)
00160                     #data.append(rdatcol)
00161                     idata.append(rdatcol)
00162                     ndat0 = ndat
00163                     ndat += len(rdatcol)
00164                 data.append(idata)
00165             if abs(self.plotlevel) > 0:
00166                 pl.xlim(0,ndat)
00167                 t1 = pl.getp(pl.gca(), 'xticklabels')
00168                 t2 = pl.getp(pl.gca(), 'yticklabels')
00169                 pl.setp((t1,t2), fontsize='smaller')
00170                 mdat = 0
00171                 for i in xrange(self.nscan):
00172                     #for j in xrange(nsubscan):
00173                     for j in xrange(self.nsubscan[i]):
00174                         mdat0 = mdat
00175                         mdat += len(data[i][j])
00176                         #pl.plot(xrange(mdat0,mdat),data[i][j],symbols[subscans[j]%2])
00177                         pl.plot(xrange(mdat0,mdat), data[i][j], symbols[self.subscans[i][j]%2])
00178                         ax = pl.gca()
00179                         if i == 1: 
00180                             leg = ax.legend(('even subscan no.', 'odd subscan no.'), numpoints=1, handletextsep=0.01) 
00181                             for t in leg.get_texts():
00182                                 t.set_fontsize('small')
00183                 pl.ion()
00184                 pl.plot()
00185                 #pl.draw()
00186             ### Calibration ############################################
00187             # Do a zero-th order calibration by subtracting a baseline #
00188             # from each scan to take out atmospheric effect.          #
00189             # The baseline fitting range specified by masklist must be #
00190             # given and is the same for all the scans.                 # 
00191             ############################################################
00192             f = sd.fitter()
00193             f.set_function(lpoly = self.blpoly)
00194             #print "Processing %s %s scans" % (corrtypestr[np], nscan)
00195             casalog.post( "Processing %s %s scans" % (self.corrtypestr[np], self.nscan) )
00196             cdat = numpy.array([])
00197             pl.subplot(312)
00198             pl.ioff()
00199             for i in xrange(self.nscan):
00200                 casalog.post( "Processing Scan#=%s" % i )
00201                 #for j in xrange(nsubscan):
00202                 for j in xrange(self.nsubscan[i]):
00203                     masks = numpy.zeros(len(data[i][j]), dtype=numpy.int)
00204                     if self.left_mask >= len(data[i][j]) \
00205                            or self.right_mask >= len(data[i][j]):
00206                         msg = "Too large mask. All data will be used for baseline subtraction.\n The fitting may not be correct since it might confuse signal component as a background..."
00207                         casalog.post(msg, "WARN")
00208                     else:
00209                         msg = "Subtracting baselines, set masks for fitting at row ranges: [0,%s] and [%s,%s] " % (self.left_mask-1, len(masks)-self.right_mask, len(masks)-1)
00210                         casalog.post(msg, "INFO")
00211                     masks[:self.left_mask] = True
00212                     masks[-self.right_mask:] = True
00213                     x = xrange(len(data[i][j]))
00214                     if self.plotlevel > 1:
00215                         pl.cla()
00216                         pl.ioff()
00217                         pl.title('scan %s subscan %s'%(self.scans[i],self.subscans[i][j]))
00218                         pl.plot(x, data[i][j], 'b')
00219                     f.set_data(x, data[i][j], mask=masks)
00220                     f.fit()
00221                     #f.plot(residual=True, components=[1], plotparms=True)
00222                     fitd=f.get_fit()
00223                     data[i][j] = data[i][j]-fitd
00224                     if self.plotlevel > 1:
00225                         pl.ion()
00226                         pl.plot(xrange(len(fitd)), fitd, 'r-')
00227                         pl.draw()
00228                         pl.cla()
00229                         pl.ioff()
00230                         pl.title('scan %s subscan %s'%(self.scans[i], self.subscans[i][j]))
00231                         pl.ion()
00232                         pl.plot(x, data[i][j], 'g')
00233                         pl.draw()
00234                         if interactive: check=raw_input('Hit return for Next\n')
00235                     cdat = numpy.concatenate([cdat,data[i][j]])
00236             ndatcol[np] = cdat
00237             del data
00238         subtb.close()
00239         self.close_table()
00240         self.open_table(self.infile, nomodify=False)
00241         # put the corrected data to CORRECTED_DATA column in MS
00242         # assuming the data for the vertex are stored in every other
00243         # row starting from 2nd row for the vertex antenna....
00244         # For the alcatel startrow=0, for len(antid) >1,
00245         # it assumes all the data to be corrected. 
00246         if type(self.antid) == int:
00247             startrow = self.antid
00248             rowincr = self.nant
00249         else:
00250             startrow = 0
00251             rowincr = 1
00252         casalog.post( "Storing the corrected data to %s column in the MS..."%self.datacol )
00253         casalog.post( "Note that %s will be overwritten"%self.datacol )
00254         cdatm = ndatcol.reshape(self.npol,1,len(cdat))
00255         self.table.putcol(self.datacol, cdatm, startrow=startrow, rowincr=rowincr)
00256         self.close_table()
00257         # calibration end
00258         #
00259         # plot corrected data
00260         if abs(self.plotlevel) > 0:
00261             casalog.post( "plotting corrected data..." )
00262             self.__plot(subplot=313, title=False, ylabel='CORRECTED_DATA')
00263 
00264     def __execute_flag(self):
00265         #flag scans
00266         self.open_table(self.infile)
00267         subtb=self.table.query('any(ANTENNA1==%s && ANTENNA2==%s)' % (self.antid,self.antid))
00268         fdatcol = subtb.getcol('FLAG')
00269         (l,m,n) = fdatcol.shape
00270         # assume m = nchan = 1
00271         fdatcol.reshape(l,n)
00272         casalog.post( "Flag processing..." )
00273         flagscanlist=[]
00274         if type(self.antid) == int:
00275             startrow = self.antid
00276             rowincr = self.nant
00277         else:
00278             startrow = 0
00279             rowincr = 1
00280         subtb.close()
00281         self.close_table()
00282         self.open_table(self.infile, nomodify=False)
00283         for flag in self.flaglist:
00284             if type(flag) == list:
00285                 flagscanlist.extend(range(flag[0],(flag[1]+1)))
00286             if type(flag) == int:
00287                 flagscanlist.append(flag)
00288         flagscanset = set(flagscanlist) 
00289         for np in range(len(self.selcorrtypeind)):
00290             fdata=[]
00291             fdatac = numpy.array([])
00292             for i in xrange(self.nscan):
00293                 #fdata=[]
00294                 #for j in xrange(nsubscan):
00295                 for j in xrange(self.nsubscan[i]):
00296                     #subtb=tb.query('any(ANTENNA1==%s && ANTENNA2==%s) && SCAN_NUMBER==%s && STATE_ID==%s' % (antid,antid,scans[i],subscans[j]))
00297                     subtb=self.table.query('any(ANTENNA1==%s && ANTENNA2==%s) && SCAN_NUMBER==%s && STATE_ID==%s' % (self.antid,self.antid,self.scans[i],self.subscans[i][j]))
00298                     fcolall = subtb.getcol('FLAG')
00299                     if self.npol > 1 and self.selnpol == 1:
00300                         fcol=fcolall[self.selpol]
00301                     else:
00302                         fcol=fcolall[self.selcorrtypeind[np]]
00303                     (m,n) = fcol.shape
00304                     fcoln = fcol.reshape(n)
00305                     if i in flagscanset:
00306                         flgs = numpy.ones(n,dtype=numpy.bool)
00307                         fcoln = flgs 
00308                     #fdata.append(fcoln)
00309                     fdatac = numpy.concatenate([fdatac,fcoln])
00310             fdatcol[np] = fdatac
00311             #flagc=tb.getcol('FLAG')
00312         subtb.close()
00313         fdatacm = fdatcol.reshape(self.npol,1,len(fdatac))
00314         self.table.putcol('FLAG', fdatacm, startrow=startrow, rowincr=rowincr)
00315         #print "Scans flagged: %s" % list(flagscanset)
00316         casalog.post( "Scans flagged: %s" % list(flagscanset) )
00317         self.close_table()
00318 
00319     def __execute_imaging(self):
00320         #if pointingcolumn.upper()=="OFFSET":
00321         #   pointingcolumn="POINTING_OFFSET"
00322         #print "pointingcolumn=",pointingcolumn
00323         #print "Imaging...."
00324         casalog.post( "pointingcolumn used: %s" % self.pointingcolumn )
00325         casalog.post( "Imaging...." )
00326         self.open_imager(self.infile)
00327         self.imager.selectvis(field=0, spw=self.spw, baseline=self.antsel)
00328         #self.imager.selectvis(vis=infile, field=0, spw=spw, baseline=antsel)
00329         #self.imager.defineimage(nx=nx, ny=ny, cellx=cellx, celly=celly,  phasecenter=phasecenter, spw=0, stokes=stokes, movingsource=ephemsrcname)
00330         self.imager.defineimage(nx=self.nx, ny=self.ny, cellx=self.cellx, celly=self.celly, phasecenter=self.phasecenter, spw=self.spw, stokes=self.stokes, movingsource=self.ephemsrcname)
00331         #self.imager.defineimage(nx=nx, ny=ny, cellx=cellx, celly=celly,  phasecenter=phasecenter, spw=0, stokes=stokes, movingsource=ephemsrcname,restfreq=1.14e11)
00332         self.imager.setoptions(ftmachine='sd', gridfunction=self.gridfunction)
00333         #self.imager.setsdoptions(convsupport=5)
00334         self.imager.setsdoptions(pointingcolumntouse=self.pointingcolumn)
00335         self.imager.makeimage(type='singledish-observed', image=self.outfile)
00336         #self.imager.makeimage(type='singledish', image=outfile)
00337         self.close_imager()
00338 
00339     def __compile_common(self):
00340         # antenna parameter handling
00341         #print "antenna parameter handling..."
00342         self.open_table(self.antenna_table)
00343         antnames = self.table.getcol('NAME')
00344         self.nant = self.table.nrows()
00345         self.close_table()
00346         self.antid=[]
00347         if self.antenna == "": # assume all antennas
00348             self.antenna = str(range(self.nant)).lstrip('[').rstrip(']')
00349             self.antsel = self.antenna.replace(',','&&& ; ') + '&&&'
00350         elif self.antenna.find('&')==-1 and self.antenna.find(';')==-1:
00351             self.antsel = self.antenna + '&&&'
00352         else:
00353             self.antsel = self.antenna
00354         antennav = self.antenna.split(',')
00355         for i in range(len(antennav)):
00356             for j in xrange(self.nant):
00357                 if antennav[i].strip() in [antnames[j], str(j)]:
00358                     self.antid.append(j)
00359         if len(self.antid)==1: 
00360             self.antid=self.antid[0] 
00361         elif len(self.antid)==0:
00362             msg='No matching antenna ID or name in the data, please check antenna parameter'
00363             raise Exception, msg
00364         self.antnameused = ''
00365         if type(self.antid) == int:
00366             self.antnameused = antnames[self.antid]
00367         else: 
00368             for i in self.antid:
00369                 self.antnameused += antnames[i]+' ' 
00370 
00371         # check if the data contain multiple polarizations
00372         self.open_table(self.infile)
00373         ddids = numpy.unique(self.table.getcol('DATA_DESC_ID'))
00374         self.close_table()
00375         self.open_table(self.data_desc_table)
00376         polids = self.table.getcol('POLARIZATION_ID').take(ddids)
00377         spwids = self.table.getcol('SPECTRAL_WINDOW_ID').take(ddids)
00378         self.close_table()
00379         idx=[]
00380         casalog.post('spw=%s, spwids=%s'%(self.spw,spwids),'INFO')
00381         for id in xrange(len(spwids)):
00382             if spwids[id] == self.spw:
00383                 idx.append(id)
00384         if len(idx) == 0:
00385             msg='No matching spw ID in the data, please check spw parameter'
00386             raise Exception, msg
00387         
00388         polid = polids[idx[0]]
00389         self.open_table(self.polarization_table)
00390         # only use first line of POLARIZATION table
00391         self.npol = self.table.getcell('NUM_CORR', polid)
00392         corrtype = self.table.getcell('CORR_TYPE', polid)
00393         self.corrtypestr = ([self.stokestypes[corrtype[i]] for i in range(self.npol)])
00394         
00395         #print corrtypestr
00396         #print "no. of polarization: %s" % npol
00397         casalog.post( "no. of polarization: %s" % self.npol )
00398         self.close_table()
00399         
00400         selpol = 0
00401         selnpol = 0
00402         selcorrtypeind=[]
00403         if self.npol>1:
00404             if self.stokes=='':
00405                 self.stokes='I'
00406             if self.stokes.upper()=='I':
00407                 if set(self.corrtypestr).issuperset(set(("XX","YY"))):
00408                     for ct in self.corrtypestr:
00409                         if ct == 'XX' or ct == 'YY':
00410                             selcorrtypeind.append(self.corrtypestr.index(ct))
00411                     #print "selected corr type indices: %s" % selcorrtypeind
00412                     casalog.post( "selected corr type indices: %s" % selcorrtypeind ) 
00413                     #print "selected (%s,%s) data" % corrtypestr
00414                 elif set(self.corrtypestr).issuperset(set(("RR","LL"))):
00415                     for ct in self.corrtypestr:
00416                         if ct == 'RR' or ct == 'LL':
00417                             selcorrtypeind.append(ct.index(ct))
00418                     #print "selected corr type indices: %s" % selcorrtypeind
00419                     casalog.post( "selected corr type indices: %s" % selcorrtypeind )
00420                     #print "selected (%s,%s) data" % corrtypestr
00421                 else:
00422                     #print "Cannot get Stokes I with the input (%s,%s) data" % corrtypestr
00423                     casalog.post( "Cannot get Stokes I with the input (%s,%s) data" % self.corrtypestr, priority='WARN' )
00424                 selnpol = len(selcorrtypeind)
00425             else:            
00426                 if len(self.stokes) <= 2:
00427                     for i in range(self.npol):
00428                         if self.stokes.upper()==self.corrtypestr[i]:
00429                             selcorrtypeind.append(i)
00430                             selpol = selcorrtypeind[0]
00431                             #print "selected %s data" % corrtypestr[i]
00432                             casalog.post( "selected %s data" % self.corrtypestr[i] )
00433                     selnpol=1 
00434                 else:
00435                     # try to identify multiple corrtypes in stokes parm.
00436                     for i in range(len(self.stokes)):
00437                         ns = 2*i
00438                         for i in range(self.npol):
00439                             if self.stokes.upper()[ns:ns+2]==self.corrtypestr[i]:
00440                                 selcorrtypeind.append(i)
00441                     selnpol=len(selcorrtypeind)
00442         else:
00443             #single pol data
00444             selpol=0
00445             selnpol=1
00446             selcorrtypeind.append(0)
00447             if self.stokes=='': self.stokes=self.corrtypestr[0]
00448             else:
00449                 if self.stokes != self.corrtypestr[0]:
00450                     msg='stokes=%s specified but the data contains only %s' % (self.stokes, self.corrtypestr)
00451                     raise Exception, msg
00452         self.selpol = selpol
00453         self.selnpol = selnpol
00454         self.selcorrtypeind = selcorrtypeind
00455 
00456         # get number of scans and subscans
00457         self.open_table(self.infile)
00458         self.scans = numpy.unique(self.table.getcol('SCAN_NUMBER'))
00459         self.nscan = len(self.scans)
00460         casalog.post('There are %s scans in the data.'%self.nscan)
00461         # 2011/2/27 TN
00462         # number of subscans can be variable in each scan
00463 ##         subscans = numpy.unique(self.table.getcol('STATE_ID'))
00464 ##         nsubscan = len(subscans)
00465         self.subscans = []
00466         self.nsubscan = []
00467         for iscan in xrange(self.nscan):
00468             subtb = self.table.query( 'SCAN_NUMBER==%s'%(self.scans[iscan]) )
00469             self.subscans.append( numpy.unique(subtb.getcol('STATE_ID')) )
00470             subtb.close()
00471             self.nsubscan.append( len(self.subscans[iscan]) )
00472             casalog.post('There are %s subscans in scan %s'%(self.nsubscan[iscan],self.scans[iscan]))
00473         self.close_table()
00474 
00475     def __compile_for_baseline(self):
00476         # compile masklist
00477         casalog.post( "masklist...." )
00478         if type(self.masklist) == int:
00479             self.masklist = [self.masklist]
00480         if len(self.masklist) > 1:
00481             self.left_mask = self.masklist[0]
00482             self.right_mask = self.masklist[1]
00483         elif len(self.masklist) == 1:
00484             self.left_mask = self.right_mask = self.masklist[0]
00485 
00486     def __compile_for_imaging(self):
00487         # pointing data column to use
00488         #if pointingcolumn.upper()=="OFFSET":
00489         #    pointingcolumn="POINTING_OFFSET"
00490         # check ephemsrcname and set a proper source name if not given
00491         if self.ephemsrcname == '':
00492             # assume single source/field
00493             # try determine if it is a known ephemeris source 
00494             self.open_table(self.source_table)
00495             src = self.table.getcol('NAME')
00496             self.close_table()
00497             src = src[0]
00498             if src.upper() in self.ephemobjs:
00499                 self.ephemsrcname = src
00500 
00501         # imsize
00502         (self.nx, self.ny) = sdutil.get_nx_ny(self.imsize)
00503 
00504         # cell size
00505         (self.cellx, self.celly) = sdutil.get_cellx_celly(self.cell,
00506                                                           unit='arcmin')
00507         if self.cellx == '' or self.celly == '':
00508             msg='Unrecognized quantity for cell'
00509             raise Exception, msg
00510             
00511         if self.phasecenter =='' and len(self.ephemsrcname)>0:
00512             # if phasecenter is undefined and if it is a moving source, 
00513             # the phasecneter is set to the position of the moving source
00514             # at the time of the first data in the POINTING table.  
00515             if self.pointingcolumn.upper() =='POINTING_OFFSET':
00516                 self.phasecenter='AZELGEO 0d0m 0d0m'
00517             else:
00518                 self.open_table(self.observation_table)
00519                 telname = self.table.getcol('TELESCOPE_NAME')
00520                 self.close_table()
00521                 self.open_table(self.pointing_table)
00522                 t = self.table.getcol('TIME')
00523                 self.close_table()
00524                 me.doframe(me.observatory(telname[0]))
00525                 me.doframe(me.epoch('utc',str(t[0])+'s'))
00526                 self.phasecenter = me.measure(me.direction(self.ephemsrcname),'AZELGEO')
00527 
00528     def __plot(self, subplot=111, title=None, ylabel=None):
00529         self.open_table(self.infile)
00530         subt = self.table.query('any(ANTENNA1==%s && ANTENNA2==%s)' % (self.antid, self.antid))
00531         datcol = subt.getcol(self.datacol)
00532         (l,m,n) = datcol.shape
00533         nrow = subt.nrows()
00534         subt.close()
00535         self.close_table()
00536 
00537         pl.ioff()
00538         if not ylabel:
00539             ylabel = self.datacol
00540         for np in range(self.selnpol):
00541             pl.ioff()
00542             pl.figure(np+1)
00543             pl.subplot(subplot)
00544             pl.cla()
00545             ip = self.selpol if self.selnpol == 1 else np
00546             if title:
00547                 pl.title(self.infile+' Ant:'+ self.antnameused+' '+self.corrtypestr[ip])
00548             datcol2 = datcol[ip].reshape(n)
00549             if self.plotlevel > 0:
00550                 pl.ion()
00551             pl.plot(range(len(datcol2)), datcol2, 'g.')
00552             pl.xlim(0, nrow)
00553             t1 = pl.getp(pl.gca(), 'xticklabels')
00554             t2 = pl.getp(pl.gca(), 'yticklabels')
00555             pl.setp((t1,t2), fontsize='smaller')
00556             pl.ylabel(ylabel, fontsize='smaller')
00557             pl.xlabel('row #')
00558             pl.draw()
00559             if self.plotlevel < 0:
00560                 outplfile=self.infile.rstrip('/')+'_scans_'+self.corrtypestr[self.selcorrtypeind[np]]+'.eps'
00561                 pl.savefig(outplfile,format='eps')
00562                 casalog.post( "Plot  was written to %s" % outplfile )