casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2008, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 import time 00011 import inspect 00012 import gc 00013 import numpy 00014 from odict import odict 00015 from task_sdscale import sdscale 00016 from task_sdscale import casalog 00017 00018 class sdscale_pg_: 00019 __name__ = "sdscale" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdscale_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infile=None, antenna=None, factor=None, scaletsys=None, outfile=None, overwrite=None, async=None): 00027 00028 """ASAP SD task: scale the sd spectra 00029 Keyword arguments: 00030 infile -- name of input SD dataset 00031 antenna -- antenna name or id (only effective for MS input). 00032 factor -- scaling factor. float or one- or two-dimensional float list. 00033 default: 1 (no scaling) 00034 scaletsys -- scaling of associated Tsys 00035 default: True 00036 outfile -- output file name 00037 outfile='' will write the data to a file named, 00038 <infile>_scaled<factor> 00039 default: '' 00040 overwrite -- overwrite the output file if already exists 00041 options: (bool) True,False 00042 default: False 00043 00044 00045 DESCRIPTION: 00046 00047 Task sdscale performs scaling of single-dish spectra. 00048 By setting scaletsys = True, associated Tsys is also scaled. 00049 Tsys informations are written in the casalogger and they are 00050 automatically stored in 'casapy.log'. 00051 The infile can be any of ASAP, MS, SDFITS, or RPFITS format. 00052 If outfile name is given or outfile=''(default), the scaled data 00053 is written to a new file with the same format as the input data 00054 (Note: in case of the RPFITS format input data, it will be written 00055 to SDFITS format). 00056 00057 The scaling factor, factor, accepts both scalar type and list 00058 type value. The list must be one or two dimensional. If factor is 00059 one dimensional, its length must coincide with a number of spectral 00060 channel. If factor is two dimensional, its shape must be 00061 (n, 1) or (n, m), where n is a number of spectrum, while m is a 00062 number of channel for each spcetum. m can be variable for each 00063 spectrum. In addition, the factor can be an ASCII filename that 00064 stores a space-separated list of scaling factor consisting of 00065 adequate number of rows and columns. For example, if the contents 00066 of input ASCII file is shown as, 00067 00068 0.5 0.3 0.2 00069 1.0 0.2 0.9 00070 00071 it is interpreted as a list [[0.5, 0.3, 0.2],[1.0, 0.2, 0.9]]. 00072 00073 WARNING for the GBT raw SDFITS format data as input: 00074 SDtasks are able to handle GBT raw SDFITS format data since the 00075 data filler is available. However, the functionality is not well 00076 tested yet, so that there may be unknown bugs. 00077 00078 00079 """ 00080 a=inspect.stack() 00081 stacklevel=0 00082 for k in range(len(a)): 00083 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00084 stacklevel=k 00085 break 00086 myf=sys._getframe(stacklevel).f_globals 00087 myf['__last_task'] = 'sdscale' 00088 myf['taskname'] = 'sdscale' 00089 ### 00090 myf['update_params'](func=myf['taskname'],printtext=False) 00091 ### 00092 ### 00093 #Handle globals or user over-ride of arguments 00094 # 00095 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00096 useLocalDefaults = False 00097 00098 for item in function_signature_defaults.iteritems(): 00099 key,val = item 00100 keyVal = eval(key) 00101 if (keyVal == None): 00102 #user hasn't set it - use global/default 00103 pass 00104 else: 00105 #user has set it - use over-ride 00106 if (key != 'self') : 00107 useLocalDefaults = True 00108 #myf[key]=keyVal 00109 00110 myparams = {} 00111 if useLocalDefaults : 00112 for item in function_signature_defaults.iteritems(): 00113 key,val = item 00114 keyVal = eval(key) 00115 exec('myparams[key] = keyVal') 00116 if (keyVal == None): 00117 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00118 keyVal = eval(key) 00119 if(type(keyVal) == dict) : 00120 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00121 00122 else : 00123 uselessvariable = None 00124 myparams['infile'] = infile = myf['infile'] 00125 myparams['antenna'] = antenna = myf['antenna'] 00126 myparams['factor'] = factor = myf['factor'] 00127 myparams['scaletsys'] = scaletsys = myf['scaletsys'] 00128 myparams['outfile'] = outfile = myf['outfile'] 00129 myparams['overwrite'] = overwrite = myf['overwrite'] 00130 00131 00132 result = None 00133 00134 # 00135 # The following is work around to avoid a bug with current python translation 00136 # 00137 mytmp = {} 00138 00139 mytmp['infile'] = infile 00140 mytmp['antenna'] = antenna 00141 mytmp['factor'] = factor 00142 mytmp['scaletsys'] = scaletsys 00143 mytmp['outfile'] = outfile 00144 mytmp['overwrite'] = overwrite 00145 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00146 trec = casac.utils().torecord(pathname+'sdscale.xml') 00147 00148 casalog.origin('sdscale') 00149 if not trec.has_key('sdscale') or not casac.utils().verify(mytmp, trec['sdscale']) : 00150 return False 00151 00152 00153 try : 00154 casalog.post('') 00155 casalog.post('##########################################') 00156 casalog.post('##### Begin Task: sdscale #####') 00157 casalog.post('') 00158 result = sdscale(infile, antenna, factor, scaletsys, outfile, overwrite) 00159 casalog.post('') 00160 casalog.post('##### End Task: sdscale #####') 00161 casalog.post('##########################################') 00162 00163 00164 # saveinputs for individule engine has no use 00165 # saveinputs should alos be removed from casa_in_py.py 00166 # 00167 # 00168 # saveinputs = myf['saveinputs'] 00169 # saveinputs('sdscale', 'sdscale.last', myparams) 00170 # 00171 # 00172 except Exception, instance: 00173 #print '**** Error **** ',instance 00174 pass 00175 00176 gc.collect() 00177 return result 00178 # 00179 # 00180 ## 00181 # def paramgui(self, useGlobals=True): 00182 # """ 00183 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00184 # """ 00185 # import paramgui 00186 # 00187 # a=inspect.stack() 00188 # stacklevel=0 00189 # for k in range(len(a)): 00190 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00191 # stacklevel=k 00192 # break 00193 # myf = sys._getframe(stacklevel).f_globals 00194 # 00195 # if useGlobals: 00196 # paramgui.setGlobals(myf) 00197 # else: 00198 # paramgui.setGlobals({}) 00199 # 00200 # paramgui.runTask('sdscale', myf['_ip']) 00201 # paramgui.setGlobals({}) 00202 # 00203 # 00204 # 00205 # 00206 def defaults(self, param=None): 00207 a=inspect.stack() 00208 stacklevel=0 00209 for k in range(len(a)): 00210 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00211 stacklevel=k 00212 break 00213 myf=sys._getframe(stacklevel).f_globals 00214 a = odict() 00215 a['infile'] = '' 00216 a['antenna'] = 0 00217 a['factor'] = 1.0 00218 a['scaletsys'] = True 00219 a['outfile'] = '' 00220 a['overwrite'] = False 00221 00222 a['async']=False 00223 00224 ### This function sets the default values but also will return the list of 00225 ### parameters or the default value of a given parameter 00226 if(param == None): 00227 myf['__set_default_parameters'](a) 00228 elif(param == 'paramkeys'): 00229 return a.keys() 00230 else: 00231 if(a.has_key(param)): 00232 #if(type(a[param]) == dict) : 00233 # return a[param][len(a[param])-1]['value'] 00234 #else : 00235 return a[param] 00236 00237 00238 # 00239 # 00240 def check_params(self, param=None, value=None): 00241 a=inspect.stack() 00242 stacklevel=0 00243 for k in range(len(a)): 00244 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00245 stacklevel=k 00246 break 00247 myf=sys._getframe(stacklevel).f_globals 00248 00249 # print 'param:', param, 'value:', value 00250 try : 00251 if str(type(value)) != "<type 'instance'>" : 00252 value0 = value 00253 value = myf['cu'].expandparam(param, value) 00254 matchtype = False 00255 if(type(value) == numpy.ndarray): 00256 if(type(value) == type(value0)): 00257 myf[param] = value.tolist() 00258 else: 00259 #print 'value:', value, 'value0:', value0 00260 #print 'type(value):', type(value), 'type(value0):', type(value0) 00261 myf[param] = value0 00262 if type(value0) != list : 00263 matchtype = True 00264 else : 00265 myf[param] = value 00266 value = myf['cu'].verifyparam({param:value}) 00267 if matchtype: 00268 value = False 00269 except Exception, instance: 00270 #ignore the exception and just return it unchecked 00271 myf[param] = value 00272 return value 00273 00274 # 00275 # 00276 def description(self, key='sdscale', subkey=None): 00277 desc={'sdscale': 'ASAP SD task: scale the sd spectra', 00278 'infile': 'name of input SD dataset', 00279 'antenna': 'antenna name or id (only effective for MS input)', 00280 'factor': 'scaling factor (float or float list)', 00281 'scaletsys': 'scaling of associated Tsys', 00282 'outfile': 'if specified write the scaled data to a separate scantable file', 00283 'overwrite': 'overwrite the output file if already exists', 00284 00285 'async': 'If true the taskname must be started using sdscale(...)' 00286 } 00287 00288 if(desc.has_key(key)) : 00289 return desc[key] 00290 00291 def itsdefault(self, paramname) : 00292 a = {} 00293 a['infile'] = '' 00294 a['antenna'] = 0 00295 a['factor'] = 1.0 00296 a['scaletsys'] = True 00297 a['outfile'] = '' 00298 a['overwrite'] = False 00299 00300 if a.has_key(paramname) : 00301 return a[paramname] 00302 sdscale_pg = sdscale_pg_()