casa
$Rev:20696$
|
00001 import os 00002 from taskinit import * 00003 00004 import asap as sd 00005 from asap.scantable import is_scantable 00006 import sdutil 00007 00008 def sdsave(infile, antenna, getpt, rowlist, scanlist, field, iflist, pollist, scanaverage, timeaverage, tweight, polaverage, pweight, restfreq, outfile, outform, overwrite): 00009 00010 casalog.origin('sdsave') 00011 00012 ### 00013 ### Now the actual task code 00014 ### 00015 00016 try: 00017 worker = sdsave_worker(**locals()) 00018 worker.initialize() 00019 worker.execute() 00020 worker.finalize() 00021 00022 except Exception, instance: 00023 sdutil.process_exception(instance) 00024 raise Exception, instance 00025 00026 class sdsave_worker(sdutil.sdtask_template): 00027 def __init__(self, **kwargs): 00028 super(sdsave_worker,self).__init__(**kwargs) 00029 self.suffix = '_saved' 00030 00031 def __del__(self): 00032 self.cleanup() 00033 00034 def parameter_check(self): 00035 # for restore information 00036 self.restore = False 00037 self.molids = None 00038 self.rfset = (self.restfreq != '') and (self.restfreq != []) 00039 00040 def initialize_scan(self): 00041 self.scan = sd.scantable(self.infile, 00042 average=self.scanaverage, 00043 antenna=self.antenna, 00044 getpt=self.getpt) 00045 00046 # scantable selection 00047 self.scan.set_selection(self.get_selector()) 00048 00049 def execute(self): 00050 # Apply averaging 00051 self.original_scan = self.scan 00052 self.scan = sdutil.doaverage(self.original_scan, self.scanaverage, 00053 self.timeaverage, self.tweight, 00054 self.polaverage, self.pweight) 00055 00056 if self.original_scan == self.scan and self.rfset \ 00057 and is_scantable(self.infile) \ 00058 and self.is_disk_storage: 00059 self.molids = self.original_scan._getmolidcol_list() 00060 self.restore = True 00061 00062 # set rest frequency 00063 casalog.post('restore=%s'%(self.restore)) 00064 if self.rfset: 00065 self.scan.set_restfreqs(sdutil.normalise_restfreq(self.restfreq)) 00066 00067 def save(self): 00068 # save 00069 sdutil.save(self.scan, self.outfile, self.outform, self.overwrite) 00070 00071 def cleanup(self): 00072 if self.restore: 00073 casalog.post( "Restoreing MOLECULE_ID column in %s "%self.infile ) 00074 self.original_scan._setmolidcol_list(self.molids) 00075