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_delmod import delmod 00016 from task_delmod import casalog 00017 00018 class delmod_pg_: 00019 __name__ = "delmod" 00020 00021 def __init__(self) : 00022 self.__bases__ = (delmod_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, otf=None, field=None, scr=None, async=None): 00027 00028 """Deletes model representations in the MS 00029 00030 This utility task is to be used to delete the model visibility 00031 data representations in the MS. The 'otf' representation is 00032 the new (as of v3.4) 'scratch-less' model data, stored as 00033 keywords in the MS header containing model data formation 00034 instructions. It is generated by the setjy, ft, and clean 00035 tasks (usescratch=F), and if present, overrides the 00036 old-fashioned MODEL_DATA column (if present). If a user 00037 wishes to use the MODEL_DATA column _after_ having operated 00038 with the 'otf' representation, this task can be used 00039 to delete the 'otf' represenatation to make the MODEL_DATA 00040 column visible. (Create the MODEL_DATA column by using 00041 usescratch=T in setjy, ft, or clean; or by running the 00042 clearcal task with addmodel=T.) 00043 00044 If otf=T, specific fields can be selected for deletion 00045 using standard field selection semantics. If field='', 00046 all fields' models will be deleted. 00047 00048 For convenience, this method also provides a means for 00049 deleting the MODEL_DATA column by setting scr=T. Note 00050 that it is not possible to delete the MODEL_DATA column 00051 per field. 00052 00053 If otf=F and scr=F, delmod will provide a listing 00054 of the header field records. 00055 00056 00057 00058 """ 00059 a=inspect.stack() 00060 stacklevel=0 00061 for k in range(len(a)): 00062 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00063 stacklevel=k 00064 break 00065 myf=sys._getframe(stacklevel).f_globals 00066 myf['__last_task'] = 'delmod' 00067 myf['taskname'] = 'delmod' 00068 ### 00069 myf['update_params'](func=myf['taskname'],printtext=False) 00070 ### 00071 ### 00072 #Handle globals or user over-ride of arguments 00073 # 00074 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00075 useLocalDefaults = False 00076 00077 for item in function_signature_defaults.iteritems(): 00078 key,val = item 00079 keyVal = eval(key) 00080 if (keyVal == None): 00081 #user hasn't set it - use global/default 00082 pass 00083 else: 00084 #user has set it - use over-ride 00085 if (key != 'self') : 00086 useLocalDefaults = True 00087 #myf[key]=keyVal 00088 00089 myparams = {} 00090 if useLocalDefaults : 00091 for item in function_signature_defaults.iteritems(): 00092 key,val = item 00093 keyVal = eval(key) 00094 exec('myparams[key] = keyVal') 00095 if (keyVal == None): 00096 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00097 keyVal = eval(key) 00098 if(type(keyVal) == dict) : 00099 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00100 00101 else : 00102 uselessvariable = None 00103 myparams['vis'] = vis = myf['vis'] 00104 myparams['otf'] = otf = myf['otf'] 00105 myparams['field'] = field = myf['field'] 00106 myparams['scr'] = scr = myf['scr'] 00107 00108 00109 result = None 00110 00111 # 00112 # The following is work around to avoid a bug with current python translation 00113 # 00114 mytmp = {} 00115 00116 mytmp['vis'] = vis 00117 mytmp['otf'] = otf 00118 mytmp['field'] = field 00119 mytmp['scr'] = scr 00120 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00121 trec = casac.utils().torecord(pathname+'delmod.xml') 00122 00123 casalog.origin('delmod') 00124 if not trec.has_key('delmod') or not casac.utils().verify(mytmp, trec['delmod']) : 00125 return False 00126 00127 00128 try : 00129 casalog.post('') 00130 casalog.post('##########################################') 00131 casalog.post('##### Begin Task: delmod #####') 00132 casalog.post('') 00133 result = delmod(vis, otf, field, scr) 00134 casalog.post('') 00135 casalog.post('##### End Task: delmod #####') 00136 casalog.post('##########################################') 00137 00138 00139 # saveinputs for individule engine has no use 00140 # saveinputs should alos be removed from casa_in_py.py 00141 # 00142 # 00143 # saveinputs = myf['saveinputs'] 00144 # saveinputs('delmod', 'delmod.last', myparams) 00145 # 00146 # 00147 except Exception, instance: 00148 #print '**** Error **** ',instance 00149 pass 00150 00151 gc.collect() 00152 return result 00153 # 00154 # 00155 ## 00156 # def paramgui(self, useGlobals=True): 00157 # """ 00158 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00159 # """ 00160 # import paramgui 00161 # 00162 # a=inspect.stack() 00163 # stacklevel=0 00164 # for k in range(len(a)): 00165 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00166 # stacklevel=k 00167 # break 00168 # myf = sys._getframe(stacklevel).f_globals 00169 # 00170 # if useGlobals: 00171 # paramgui.setGlobals(myf) 00172 # else: 00173 # paramgui.setGlobals({}) 00174 # 00175 # paramgui.runTask('delmod', myf['_ip']) 00176 # paramgui.setGlobals({}) 00177 # 00178 # 00179 # 00180 # 00181 def defaults(self, param=None): 00182 a=inspect.stack() 00183 stacklevel=0 00184 for k in range(len(a)): 00185 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00186 stacklevel=k 00187 break 00188 myf=sys._getframe(stacklevel).f_globals 00189 a = odict() 00190 a['vis'] = '' 00191 a['otf'] = True 00192 a['scr'] = False 00193 00194 a['async']=False 00195 a['otf'] = { 00196 0:odict([{'value':True}, {'field':''}]), 00197 1:{'value':False}} 00198 00199 ### This function sets the default values but also will return the list of 00200 ### parameters or the default value of a given parameter 00201 if(param == None): 00202 myf['__set_default_parameters'](a) 00203 elif(param == 'paramkeys'): 00204 return a.keys() 00205 else: 00206 if(a.has_key(param)): 00207 #if(type(a[param]) == dict) : 00208 # return a[param][len(a[param])-1]['value'] 00209 #else : 00210 return a[param] 00211 00212 00213 # 00214 # 00215 def check_params(self, param=None, value=None): 00216 a=inspect.stack() 00217 stacklevel=0 00218 for k in range(len(a)): 00219 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00220 stacklevel=k 00221 break 00222 myf=sys._getframe(stacklevel).f_globals 00223 00224 # print 'param:', param, 'value:', value 00225 try : 00226 if str(type(value)) != "<type 'instance'>" : 00227 value0 = value 00228 value = myf['cu'].expandparam(param, value) 00229 matchtype = False 00230 if(type(value) == numpy.ndarray): 00231 if(type(value) == type(value0)): 00232 myf[param] = value.tolist() 00233 else: 00234 #print 'value:', value, 'value0:', value0 00235 #print 'type(value):', type(value), 'type(value0):', type(value0) 00236 myf[param] = value0 00237 if type(value0) != list : 00238 matchtype = True 00239 else : 00240 myf[param] = value 00241 value = myf['cu'].verifyparam({param:value}) 00242 if matchtype: 00243 value = False 00244 except Exception, instance: 00245 #ignore the exception and just return it unchecked 00246 myf[param] = value 00247 return value 00248 00249 # 00250 # 00251 def description(self, key='delmod', subkey=None): 00252 desc={'delmod': 'Deletes model representations in the MS', 00253 'vis': 'Name of input visibility file (MS)', 00254 'otf': 'Delete the on-the-fly model data keywords', 00255 'field': 'Select field using field id(s) or field name(s)', 00256 'scr': 'Delete the MODEL_DATA scr col (if it exists)', 00257 00258 'async': 'If true the taskname must be started using delmod(...)' 00259 } 00260 00261 # 00262 # Set subfields defaults if needed 00263 # 00264 00265 if(desc.has_key(key)) : 00266 return desc[key] 00267 00268 def itsdefault(self, paramname) : 00269 a = {} 00270 a['vis'] = '' 00271 a['otf'] = True 00272 a['field'] = '' 00273 a['scr'] = False 00274 00275 if a.has_key(paramname) : 00276 return a[paramname] 00277 delmod_pg = delmod_pg_()