casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
task_sdreduce.py
Go to the documentation of this file.
00001 import os
00002 from taskinit import *
00003 import sys
00004 import string
00005 import inspect
00006 from odict import odict
00007 
00008 import sdutil
00009 import asap as sd
00010 from asap._asap import Scantable
00011 import pylab as pl
00012 from sdcal import sdcal
00013 from sdsmooth import sdsmooth
00014 from sdbaseline import sdbaseline
00015 import task_sdcal
00016 import task_sdsmooth
00017 import task_sdbaseline
00018 
00019 def sdreduce(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, calmode, fraction, noff, width, elongated, markonly, plotpointings, scanlist, field, iflist, pollist, channelrange, average, scanaverage, timeaverage, tweight, averageall, polaverage, pweight, tau, kernel, kwidth, chanwidth, masklist, maskmode, thresh, avg_limit, edge, blfunc, order, npiece, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, verifycal, verifysm, verifybl, verbosebl, bloutput, blformat, showprogress, minnrow, outfile, outform, overwrite, plotlevel):
00020 
00021     casalog.origin('sdreduce')
00022     
00023     ###
00024     ### Now the actual task code
00025     ###
00026     
00027     try:
00028         worker = sdreduce_worker(**locals())
00029         worker.initialize()
00030         worker.execute()
00031         worker.finalize()
00032 
00033     except Exception, instance:
00034         sdutil.process_exception(instance)
00035         raise Exception, instance
00036 
00037 class sdreduce_worker(sdutil.sdtask_template):
00038     def __init__(self, **kwargs):
00039         super(sdreduce_worker,self).__init__(**kwargs)
00040         self.suffix = '_cal'
00041 
00042     def __del__(self):
00043         # restore scantable when the instance is deleted
00044         self.cleanup()
00045 
00046     def initialize_scan(self):
00047         # instantiate scantable
00048         self.scan = sd.scantable(self.infile, average=False, antenna=self.antenna)
00049         
00050         # restorer
00051         self.restorer = sdutil.scantable_restore_factory(self.scan,
00052                                                          self.infile,
00053                                                          self.fluxunit,
00054                                                          self.specunit,
00055                                                          self.frame,
00056                                                          self.doppler,
00057                                                          self.restfreq)
00058         
00059         # Apply selection
00060         self.scan.set_selection(self.get_selector())
00061 
00062     def execute(self):
00063         # calibration stage
00064         casalog.post( "*** sdcal stage ***" )
00065         self.verify = self.verifycal
00066         engine = task_sdcal.sdcal_engine(self)
00067         engine.prologue()
00068         engine.drive()
00069 ##         self.scan = engine.get_result()
00070 ##         task_sdcal.prior_plot(self.scan, self.plotlevel)
00071 ##         self.scan = task_sdcal.docalibration(self.scan, self.calmode,
00072 ##                                              self.fraction,
00073 ##                                              self.noff, self.width,
00074 ##                                              self.elongated,
00075 ##                                              self.markonly, self.plotpointings,
00076 ##                                              self.verifycal)
00077 
00078         # apply input parameters 
00079         self.set_to_scan()
00080 
00081         # opacity correction
00082         sdutil.doopacity(self.scan, self.tau)
00083 
00084         # channel splitting
00085         sdutil.dochannelrange(self.scan, self.channelrange)
00086         
00087         # averaging stage
00088         if self.average:
00089             self.scan = sdutil.doaverage(self.scan, self.scanaverage,
00090                                          self.timeaverage, self.tweight,
00091                                          self.polaverage, self.pweight,
00092                                          self.averageall)
00093         else:
00094             casalog.post( "No averaging was applied..." )
00095 ##         task_sdcal.posterior_plot(self.scan, self.project, self.plotlevel)
00096         engine.epilogue()
00097         del engine
00098         
00099         # smoothing stage
00100         casalog.post( "" )
00101         casalog.post( "*** sdsmooth stage ***" )
00102         if self.kernel != 'none':
00103             self.verify = self.verifysm
00104             engine = task_sdsmooth.sdsmooth_engine(self)
00105             engine.prologue()
00106             engine.drive()
00107 ##             self.scan = engine.get_result()
00108             engine.epilogue()
00109             del engine
00110         else:
00111             casalog.post( "No smoothing was applied..." )
00112 
00113             
00114         # baseline stage
00115         casalog.post( "" )
00116         casalog.post( "*** sdbaseline stage ***")
00117         if self.blfunc != 'none':
00118             self.verify = self.verifybl
00119             self.verbose = self.verbosebl
00120             engine = task_sdbaseline.sdbaseline_engine(self)
00121             engine.prologue()
00122             engine.drive()
00123 ##             self.scan = engine.get_result()
00124             engine.epilogue()
00125             del engine
00126         else:
00127             casalog.post( "No baseline subtraction was applied..." )
00128 
00129     def save(self):
00130         # write result on disk
00131         sdutil.save(self.scan, self.project, self.outform, self.overwrite)
00132 
00133     def cleanup(self):
00134         # restore
00135         if self.restorer:
00136             self.restorer.restore()