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_uvsub import uvsub 00016 from task_uvsub import casalog 00017 00018 class uvsub_pg_: 00019 __name__ = "uvsub" 00020 00021 def __init__(self) : 00022 self.__bases__ = (uvsub_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, reverse=None, async=None): 00027 00028 """Subtract/add model from/to the corrected visibility data. 00029 Help for uvsub task 00030 00031 This function subtracts model visibility data from corrected visibility 00032 data leaving the residuals in the corrected data column. If the 00033 parameter 'reverse' is set true, the process is reversed. 00034 Please note the model visibility used is the one that has been saved in the MODEL_DATA of the MS and the 00035 CORRECTED_DATA column is the one that is modified. If no CORRECTED_DATA column exists in the MS, one will be created and 00036 a copy of the DATA column is saved in it before the uvsub operation selected is performed. uvsub does not modify the DATA column. 00037 00038 Keyword arguments: 00039 vis -- Name of input visibility file (MS) 00040 default: none; example: vis='ngc5921.ms' 00041 reverse -- Reverse the operation (add rather than subtract) 00042 default: False; example: reverse=true 00043 00044 uvsub(vis='ngc5921.ms', reverse=False) 00045 00046 00047 """ 00048 a=inspect.stack() 00049 stacklevel=0 00050 for k in range(len(a)): 00051 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00052 stacklevel=k 00053 break 00054 myf=sys._getframe(stacklevel).f_globals 00055 myf['__last_task'] = 'uvsub' 00056 myf['taskname'] = 'uvsub' 00057 ### 00058 myf['update_params'](func=myf['taskname'],printtext=False) 00059 ### 00060 ### 00061 #Handle globals or user over-ride of arguments 00062 # 00063 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00064 useLocalDefaults = False 00065 00066 for item in function_signature_defaults.iteritems(): 00067 key,val = item 00068 keyVal = eval(key) 00069 if (keyVal == None): 00070 #user hasn't set it - use global/default 00071 pass 00072 else: 00073 #user has set it - use over-ride 00074 if (key != 'self') : 00075 useLocalDefaults = True 00076 #myf[key]=keyVal 00077 00078 myparams = {} 00079 if useLocalDefaults : 00080 for item in function_signature_defaults.iteritems(): 00081 key,val = item 00082 keyVal = eval(key) 00083 exec('myparams[key] = keyVal') 00084 if (keyVal == None): 00085 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00086 keyVal = eval(key) 00087 if(type(keyVal) == dict) : 00088 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00089 00090 else : 00091 uselessvariable = None 00092 myparams['vis'] = vis = myf['vis'] 00093 myparams['reverse'] = reverse = myf['reverse'] 00094 00095 00096 result = None 00097 00098 # 00099 # The following is work around to avoid a bug with current python translation 00100 # 00101 mytmp = {} 00102 00103 mytmp['vis'] = vis 00104 mytmp['reverse'] = reverse 00105 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00106 trec = casac.utils().torecord(pathname+'uvsub.xml') 00107 00108 casalog.origin('uvsub') 00109 if not trec.has_key('uvsub') or not casac.utils().verify(mytmp, trec['uvsub']) : 00110 return False 00111 00112 00113 try : 00114 casalog.post('') 00115 casalog.post('##########################################') 00116 casalog.post('##### Begin Task: uvsub #####') 00117 casalog.post('') 00118 result = uvsub(vis, reverse) 00119 casalog.post('') 00120 casalog.post('##### End Task: uvsub #####') 00121 casalog.post('##########################################') 00122 00123 00124 # saveinputs for individule engine has no use 00125 # saveinputs should alos be removed from casa_in_py.py 00126 # 00127 # 00128 # saveinputs = myf['saveinputs'] 00129 # saveinputs('uvsub', 'uvsub.last', myparams) 00130 # 00131 # 00132 except Exception, instance: 00133 #print '**** Error **** ',instance 00134 pass 00135 00136 gc.collect() 00137 return result 00138 # 00139 # 00140 ## 00141 # def paramgui(self, useGlobals=True): 00142 # """ 00143 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00144 # """ 00145 # import paramgui 00146 # 00147 # a=inspect.stack() 00148 # stacklevel=0 00149 # for k in range(len(a)): 00150 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00151 # stacklevel=k 00152 # break 00153 # myf = sys._getframe(stacklevel).f_globals 00154 # 00155 # if useGlobals: 00156 # paramgui.setGlobals(myf) 00157 # else: 00158 # paramgui.setGlobals({}) 00159 # 00160 # paramgui.runTask('uvsub', myf['_ip']) 00161 # paramgui.setGlobals({}) 00162 # 00163 # 00164 # 00165 # 00166 def defaults(self, param=None): 00167 a=inspect.stack() 00168 stacklevel=0 00169 for k in range(len(a)): 00170 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00171 stacklevel=k 00172 break 00173 myf=sys._getframe(stacklevel).f_globals 00174 a = odict() 00175 a['vis'] = '' 00176 a['reverse'] = False 00177 00178 a['async']=False 00179 00180 ### This function sets the default values but also will return the list of 00181 ### parameters or the default value of a given parameter 00182 if(param == None): 00183 myf['__set_default_parameters'](a) 00184 elif(param == 'paramkeys'): 00185 return a.keys() 00186 else: 00187 if(a.has_key(param)): 00188 #if(type(a[param]) == dict) : 00189 # return a[param][len(a[param])-1]['value'] 00190 #else : 00191 return a[param] 00192 00193 00194 # 00195 # 00196 def check_params(self, param=None, value=None): 00197 a=inspect.stack() 00198 stacklevel=0 00199 for k in range(len(a)): 00200 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00201 stacklevel=k 00202 break 00203 myf=sys._getframe(stacklevel).f_globals 00204 00205 # print 'param:', param, 'value:', value 00206 try : 00207 if str(type(value)) != "<type 'instance'>" : 00208 value0 = value 00209 value = myf['cu'].expandparam(param, value) 00210 matchtype = False 00211 if(type(value) == numpy.ndarray): 00212 if(type(value) == type(value0)): 00213 myf[param] = value.tolist() 00214 else: 00215 #print 'value:', value, 'value0:', value0 00216 #print 'type(value):', type(value), 'type(value0):', type(value0) 00217 myf[param] = value0 00218 if type(value0) != list : 00219 matchtype = True 00220 else : 00221 myf[param] = value 00222 value = myf['cu'].verifyparam({param:value}) 00223 if matchtype: 00224 value = False 00225 except Exception, instance: 00226 #ignore the exception and just return it unchecked 00227 myf[param] = value 00228 return value 00229 00230 # 00231 # 00232 def description(self, key='uvsub', subkey=None): 00233 desc={'uvsub': 'Subtract/add model from/to the corrected visibility data.', 00234 'vis': 'Name of input visibility file (MS)', 00235 'reverse': 'reverse the operation (add rather than subtract)', 00236 00237 'async': 'If true the taskname must be started using uvsub(...)' 00238 } 00239 00240 # 00241 # Set subfields defaults if needed 00242 # 00243 00244 if(desc.has_key(key)) : 00245 return desc[key] 00246 00247 def itsdefault(self, paramname) : 00248 a = {} 00249 a['vis'] = '' 00250 a['reverse'] = False 00251 00252 if a.has_key(paramname) : 00253 return a[paramname] 00254 uvsub_pg = uvsub_pg_()