casa
$Rev:20696$
|
00001 import os 00002 import sys 00003 from taskinit import * 00004 import sdutil 00005 import asap as sd 00006 from asap.scantable import is_scantable, is_ms 00007 00008 def sdscale(infile, antenna, factor, scaletsys, outfile, overwrite): 00009 00010 casalog.origin('sdscale') 00011 00012 try: 00013 worker = sdscale_worker(**locals()) 00014 worker.initialize() 00015 worker.execute() 00016 worker.finalize() 00017 00018 except Exception, instance: 00019 sdutil.process_exception(instance) 00020 raise Exception, instance 00021 00022 class sdscale_worker(sdutil.sdtask_template): 00023 def __init__(self, **kwargs): 00024 super(sdscale_worker,self).__init__(**kwargs) 00025 self.suffix = '_scaled%s'%(self.factor) 00026 self.outform = self.__get_outform() 00027 00028 def parameter_check(self): 00029 if isinstance( self.factor, str ): 00030 casalog.post( 'read factor from \'%s\'' %self.factor ) 00031 f = open( self.factor ) 00032 lines = f.readlines() 00033 f.close() 00034 del f 00035 for i in range( len(lines) ): 00036 lines[i] = lines[i].rstrip('\n') 00037 lines[i] = lines[i].split() 00038 for j in range( len(lines[i]) ): 00039 lines[i][j] = float( lines[i][j] ) 00040 self.factor = lines 00041 00042 def initialize_scan(self): 00043 self.scan = sd.scantable(self.infile, average=False, antenna=self.antenna) 00044 00045 def execute(self): 00046 # no scaling 00047 if self.factor == 1.0: 00048 casalog.post( "scaling factor is 1.0. No scaling" ) 00049 return 00050 00051 s2 = self.scan.scale(self.factor, self.scaletsys, False) 00052 casalog.post( "Scaled spectra and Tsys by "+str(self.factor) ) 00053 00054 if self.scaletsys: 00055 oldtsys=self.scan._row_callback(self.scan._gettsys, "Original Tsys") 00056 newtsys=s2._row_callback(s2._gettsys, "Scaled Tsys") 00057 else: 00058 oldtsys=s2._row_callback(s2._gettsys, "Tsys (not scaled)") 00059 self.scan = s2 00060 00061 def save(self): 00062 sdutil.save(self.scan, self.outfile, self.outform, self.overwrite) 00063 casalog.post( "Wrote scaled data to %s file, %s " % (self.outform, self.outfile) ) 00064 00065 def __get_outform(self): 00066 if is_scantable(self.infile): 00067 outform = 'ASAP' 00068 elif is_ms(infile): 00069 outform = 'MS2' 00070 else: 00071 outform = 'SDFITS' 00072 return outform 00073