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