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