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 casac 00010 import string 00011 import time 00012 import inspect 00013 import gc 00014 import numpy 00015 from odict import odict 00016 from taskmanager import tm 00017 from task_listhistory import listhistory 00018 class listhistory_cli_: 00019 __name__ = "listhistory" 00020 __async__ = {} 00021 rkey = None 00022 i_am_a_casapy_task = None 00023 # The existence of the i_am_a_casapy_task attribute allows help() 00024 # (and other) to treat casapy tasks as a special case. 00025 00026 def __init__(self) : 00027 self.__bases__ = (listhistory_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'vis':None, 'async':None} 00031 00032 00033 def result(self, key=None): 00034 #### here we will scan the task-ids in __async__ 00035 #### and add any that have completed... 00036 if key is not None and self.__async__.has_key(key) and self.__async__[key] is not None: 00037 ret = tm.retrieve(self.__async__[key]) 00038 if ret['state'] == "done" : 00039 self.__async__[key] = None 00040 elif ret['state'] == 'crashed' : 00041 self.__async__[key] = None 00042 return ret 00043 return None 00044 00045 00046 def __call__(self, vis=None, async=None): 00047 00048 """List the processing history of a dataset: 00049 00050 The list of all task processing steps in a visibility data set 00051 are listed in the logger. 00052 00053 Keyword arguments: 00054 vis -- Name of input visibility file 00055 default: none; example: vis='ngc5921.ms' 00056 async -- Run asynchronously 00057 default = False; do not run asychronously 00058 00059 """ 00060 if not hasattr(self, "__globals__") or self.__globals__ == None : 00061 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00062 #casac = self.__globals__['casac'] 00063 casalog = self.__globals__['casalog'] 00064 #casalog = casac.casac.logsink() 00065 self.__globals__['__last_task'] = 'listhistory' 00066 self.__globals__['taskname'] = 'listhistory' 00067 ### 00068 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00069 ### 00070 ### 00071 #Handle globals or user over-ride of arguments 00072 # 00073 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00074 useLocalDefaults = False 00075 00076 for item in function_signature_defaults.iteritems(): 00077 key,val = item 00078 keyVal = eval(key) 00079 if (keyVal == None): 00080 #user hasn't set it - use global/default 00081 pass 00082 else: 00083 #user has set it - use over-ride 00084 if (key != 'self') : 00085 useLocalDefaults = True 00086 00087 myparams = {} 00088 if useLocalDefaults : 00089 for item in function_signature_defaults.iteritems(): 00090 key,val = item 00091 keyVal = eval(key) 00092 exec('myparams[key] = keyVal') 00093 self.parameters[key] = keyVal 00094 if (keyVal == None): 00095 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00096 keyVal = eval(key) 00097 if(type(keyVal) == dict) : 00098 if len(keyVal) > 0 : 00099 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00100 else : 00101 exec('myparams[key] = ' + key + ' = {}') 00102 00103 else : 00104 async = self.parameters['async'] 00105 myparams['vis'] = vis = self.parameters['vis'] 00106 00107 00108 result = None 00109 00110 # 00111 # The following is work around to avoid a bug with current python translation 00112 # 00113 mytmp = {} 00114 00115 mytmp['vis'] = vis 00116 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00117 trec = casac.casac.utils().torecord(pathname+'listhistory.xml') 00118 00119 casalog.origin('listhistory') 00120 try : 00121 #if not trec.has_key('listhistory') or not casac.casac.utils().verify(mytmp, trec['listhistory']) : 00122 #return False 00123 00124 casac.casac.utils().verify(mytmp, trec['listhistory'], True) 00125 scriptstr=[''] 00126 saveinputs = self.__globals__['saveinputs'] 00127 saveinputs('listhistory', 'listhistory.last', myparams, self.__globals__,scriptstr=scriptstr) 00128 if async : 00129 count = 0 00130 keybase = time.strftime("%y%m%d.%H%M%S") 00131 key = keybase + "_" + str(count) 00132 while self.__async__.has_key(key) : 00133 count += 1 00134 key = keybase + "_" + str(count) 00135 result = tm.execute('listhistory', vis) 00136 print "Use: " 00137 print " tm.retrieve(return_value) # to retrieve the status" 00138 print 00139 self.rkey = key 00140 self.__async__[key] = result 00141 else : 00142 tname = 'listhistory' 00143 spaces = ' '*(18-len(tname)) 00144 casalog.post('\n##########################################'+ 00145 '\n##### Begin Task: ' + tname + spaces + ' #####') 00146 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00147 result = listhistory(vis) 00148 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00149 '\n##########################################') 00150 00151 except Exception, instance: 00152 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00153 raise 00154 else : 00155 #print '**** Error **** ',instance 00156 tname = 'listhistory' 00157 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00158 pass 00159 00160 gc.collect() 00161 return result 00162 # 00163 # 00164 # 00165 def paramgui(self, useGlobals=True, ipython_globals=None): 00166 """ 00167 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00168 """ 00169 import paramgui 00170 if not hasattr(self, "__globals__") or self.__globals__ == None : 00171 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00172 00173 if useGlobals: 00174 if ipython_globals == None: 00175 myf=self.__globals__ 00176 else: 00177 myf=ipython_globals 00178 00179 paramgui.setGlobals(myf) 00180 else: 00181 paramgui.setGlobals({}) 00182 00183 paramgui.runTask('listhistory', myf['_ip']) 00184 paramgui.setGlobals({}) 00185 00186 # 00187 # 00188 # 00189 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 00190 if not hasattr(self, "__globals__") or self.__globals__ == None : 00191 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00192 if ipython_globals == None: 00193 myf=self.__globals__ 00194 else: 00195 myf=ipython_globals 00196 00197 a = odict() 00198 a['vis'] = '' 00199 00200 a['async']=False 00201 00202 ### This function sets the default values but also will return the list of 00203 ### parameters or the default value of a given parameter 00204 if(param == None): 00205 myf['__set_default_parameters'](a) 00206 elif(param == 'paramkeys'): 00207 return a.keys() 00208 else: 00209 if(paramvalue==None and subparam==None): 00210 if(a.has_key(param)): 00211 return a[param] 00212 else: 00213 return self.itsdefault(param) 00214 else: 00215 retval=a[param] 00216 if(type(a[param])==dict): 00217 for k in range(len(a[param])): 00218 valornotval='value' 00219 if(a[param][k].has_key('notvalue')): 00220 valornotval='notvalue' 00221 if((a[param][k][valornotval])==paramvalue): 00222 retval=a[param][k].copy() 00223 retval.pop(valornotval) 00224 if(subparam != None): 00225 if(retval.has_key(subparam)): 00226 retval=retval[subparam] 00227 else: 00228 retval=self.itsdefault(subparam) 00229 else: 00230 retval=self.itsdefault(subparam) 00231 return retval 00232 00233 00234 # 00235 # 00236 def check_params(self, param=None, value=None, ipython_globals=None): 00237 if ipython_globals == None: 00238 myf=self.__globals__ 00239 else: 00240 myf=ipython_globals 00241 # print 'param:', param, 'value:', value 00242 try : 00243 if str(type(value)) != "<type 'instance'>" : 00244 value0 = value 00245 value = myf['cu'].expandparam(param, value) 00246 matchtype = False 00247 if(type(value) == numpy.ndarray): 00248 if(type(value) == type(value0)): 00249 myf[param] = value.tolist() 00250 else: 00251 #print 'value:', value, 'value0:', value0 00252 #print 'type(value):', type(value), 'type(value0):', type(value0) 00253 myf[param] = value0 00254 if type(value0) != list : 00255 matchtype = True 00256 else : 00257 myf[param] = value 00258 value = myf['cu'].verifyparam({param:value}) 00259 if matchtype: 00260 value = False 00261 except Exception, instance: 00262 #ignore the exception and just return it unchecked 00263 myf[param] = value 00264 return value 00265 # 00266 # 00267 def description(self, key='listhistory', subkey=None): 00268 desc={'listhistory': 'List the processing history of a dataset:', 00269 'vis': 'Name of input visibility file (MS)', 00270 00271 'async': 'If true the taskname must be started using listhistory(...)' 00272 } 00273 00274 if(desc.has_key(key)) : 00275 return desc[key] 00276 00277 def itsdefault(self, paramname) : 00278 a = {} 00279 a['vis'] = '' 00280 00281 #a = sys._getframe(len(inspect.stack())-1).f_globals 00282 00283 if a.has_key(paramname) : 00284 return a[paramname] 00285 listhistory_cli = listhistory_cli_()