casa
$Rev:20696$
|
00001 import os 00002 from taskinit import * 00003 00004 import asap as sd 00005 from asap._asap import Scantable 00006 import pylab as pl 00007 from asap import _to_list 00008 from asap.scantable import is_scantable 00009 import sdutil 00010 00011 def sdcal(infile, antenna, fluxunit, telescopeparm, specunit, frame, doppler, calmode, fraction, noff, width, elongated, markonly, plotpointings, scanlist, field, iflist, pollist, channelrange, scanaverage, timeaverage, tweight, averageall, polaverage, pweight, tau, verify, outfile, outform, overwrite, plotlevel): 00012 00013 casalog.origin('sdcal') 00014 00015 ### 00016 ### Now the actual task code 00017 ### 00018 00019 restorer = None 00020 00021 try: 00022 worker = sdcal_worker(**locals()) 00023 worker.initialize() 00024 worker.execute() 00025 worker.finalize() 00026 00027 except Exception, instance: 00028 sdutil.process_exception(instance) 00029 raise Exception, instance 00030 00031 class sdcal_worker(sdutil.sdtask_template): 00032 def __init__(self, **kwargs): 00033 super(sdcal_worker,self).__init__(**kwargs) 00034 self.suffix = '_cal' 00035 00036 def initialize_scan(self): 00037 sorg=sd.scantable(self.infile,average=False,antenna=self.antenna) 00038 00039 if not isinstance(sorg,Scantable): 00040 raise Exception, 'Scantable data %s, is not found' 00041 00042 # A scantable selection 00043 sel = self.get_selector() 00044 sorg.set_selection(sel) 00045 00046 # Copy scantable when usign disk storage not to modify 00047 # the original table. 00048 if is_scantable(self.infile) and self.is_disk_storage: 00049 self.scan = sorg.copy() 00050 else: 00051 self.scan = sorg 00052 del sorg 00053 00054 def execute(self): 00055 engine = sdcal_engine(self) 00056 engine.prologue() 00057 00058 # apply inputs to scan 00059 self.set_to_scan() 00060 00061 ## # do opacity (atmospheric optical depth) correction 00062 ## sdutil.doopacity(self.scan, self.tau) 00063 00064 ## # channel splitting 00065 ## sdutil.dochannelrange(self.scan, self.channelrange) 00066 00067 # Actual implementation is defined outside the class 00068 # since those are used in task_sdreduce. 00069 engine.drive() 00070 00071 # do opacity (atmospheric optical depth) correction 00072 sdutil.doopacity(self.scan, self.tau) 00073 00074 # channel splitting 00075 sdutil.dochannelrange(self.scan, self.channelrange) 00076 00077 # Average data if necessary 00078 self.scan = sdutil.doaverage(self.scan, self.scanaverage, self.timeaverage, self.tweight, self.polaverage, self.pweight, self.averageall) 00079 00080 engine.epilogue() 00081 00082 def save(self): 00083 sdutil.save(self.scan, self.project, self.outform, self.overwrite) 00084 00085 00086 class sdcal_engine(sdutil.sdtask_engine): 00087 def __init__(self, worker): 00088 super(sdcal_engine,self).__init__(worker) 00089 00090 def prologue(self): 00091 if ( abs(self.plotlevel) > 1 ): 00092 casalog.post( "Initial Raw Scantable:" ) 00093 self.worker.scan._summary() 00094 00095 def drive(self): 00096 scanns = self.worker.scan.getscannos() 00097 sn=list(scanns) 00098 casalog.post( "Number of scans to be processed: %d" % (len(sn)) ) 00099 if self.calmode == 'otf' or self.calmode=='otfraster': 00100 self.__mark() 00101 if not self.markonly: 00102 self.worker.scan = sd.asapmath.calibrate( self.worker.scan, 00103 scannos=sn, 00104 calmode='ps', 00105 verify=self.verify ) 00106 else: 00107 self.worker.scan = sd.asapmath.calibrate( self.worker.scan, 00108 scannos=sn, 00109 calmode=self.calmode, 00110 verify=self.verify ) 00111 00112 def epilogue(self): 00113 if ( abs(self.plotlevel) > 1 ): 00114 casalog.post( "Final Calibrated Scantable:" ) 00115 self.worker.scan._summary() 00116 00117 # Plot final spectrum 00118 if ( abs(self.plotlevel) > 0 ): 00119 pltfile = project + '_calspec.eps' 00120 sdutil.plot_scantable(self.worker.scan, pltfile, self.plotlevel) 00121 00122 def __mark(self): 00123 israster = (self.calmode == 'otfraster') 00124 marker = sd.edgemarker(israster=israster) 00125 marker.setdata(self.worker.scan) 00126 self.npts = self.noff 00127 marker.setoption(**self.__dict__) 00128 marker.mark() 00129 if self.plotpointings: 00130 marker.plot() 00131 self.worker.scan = marker.getresult() 00132