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_plotants import plotants 00016 from task_plotants import casalog 00017 00018 class plotants_pg_: 00019 __name__ = "plotants" 00020 00021 def __init__(self) : 00022 self.__bases__ = (plotants_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, figfile=None, async=None): 00027 00028 """Plot the antenna distribution in the local reference frame: 00029 Plot the antenna distribution in the local reference frame: 00030 00031 The location of the antennas in the MS will be plotted with 00032 X-toward local east; Y-toward local north. 00033 00034 Keyword arguments: 00035 vis -- Name of input visibility file. 00036 default: none. example: vis='ngc5921.ms' 00037 00038 figfile -- Save the plotted figure in this file. 00039 default: ''. example: figfile='myFigure.png' 00040 00041 The name of each antenna (egs. vla=antenna number) is 00042 shown next to its respective location. 00043 00044 DO NOT use the buttons on the Mark Region line. These are 00045 not implemented yet and might abort CASA. 00046 00047 You can zoom in by pressing the magnifier button (bottom, 00048 third from left) and making a rectangular region with 00049 the mouse. Press the home button (left most button) to 00050 remove zoom. 00051 00052 A hard-copy of this plot can be obtained by pressing the 00053 button on the right at the bottom of the display. This 00054 produces a png format file. 00055 00056 """ 00057 a=inspect.stack() 00058 stacklevel=0 00059 for k in range(len(a)): 00060 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00061 stacklevel=k 00062 break 00063 myf=sys._getframe(stacklevel).f_globals 00064 myf['__last_task'] = 'plotants' 00065 myf['taskname'] = 'plotants' 00066 ### 00067 myf['update_params'](func=myf['taskname'],printtext=False) 00068 ### 00069 ### 00070 #Handle globals or user over-ride of arguments 00071 # 00072 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00073 useLocalDefaults = False 00074 00075 for item in function_signature_defaults.iteritems(): 00076 key,val = item 00077 keyVal = eval(key) 00078 if (keyVal == None): 00079 #user hasn't set it - use global/default 00080 pass 00081 else: 00082 #user has set it - use over-ride 00083 if (key != 'self') : 00084 useLocalDefaults = True 00085 #myf[key]=keyVal 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 if (keyVal == None): 00094 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00095 keyVal = eval(key) 00096 if(type(keyVal) == dict) : 00097 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00098 00099 else : 00100 uselessvariable = None 00101 myparams['vis'] = vis = myf['vis'] 00102 myparams['figfile'] = figfile = myf['figfile'] 00103 00104 00105 result = None 00106 00107 # 00108 # The following is work around to avoid a bug with current python translation 00109 # 00110 mytmp = {} 00111 00112 mytmp['vis'] = vis 00113 mytmp['figfile'] = figfile 00114 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00115 trec = casac.utils().torecord(pathname+'plotants.xml') 00116 00117 casalog.origin('plotants') 00118 if not trec.has_key('plotants') or not casac.utils().verify(mytmp, trec['plotants']) : 00119 return False 00120 00121 00122 try : 00123 casalog.post('') 00124 casalog.post('##########################################') 00125 casalog.post('##### Begin Task: plotants #####') 00126 casalog.post('') 00127 result = plotants(vis, figfile) 00128 casalog.post('') 00129 casalog.post('##### End Task: plotants #####') 00130 casalog.post('##########################################') 00131 00132 00133 # saveinputs for individule engine has no use 00134 # saveinputs should alos be removed from casa_in_py.py 00135 # 00136 # 00137 # saveinputs = myf['saveinputs'] 00138 # saveinputs('plotants', 'plotants.last', myparams) 00139 # 00140 # 00141 except Exception, instance: 00142 #print '**** Error **** ',instance 00143 pass 00144 00145 gc.collect() 00146 return result 00147 # 00148 # 00149 ## 00150 # def paramgui(self, useGlobals=True): 00151 # """ 00152 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00153 # """ 00154 # import paramgui 00155 # 00156 # a=inspect.stack() 00157 # stacklevel=0 00158 # for k in range(len(a)): 00159 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00160 # stacklevel=k 00161 # break 00162 # myf = sys._getframe(stacklevel).f_globals 00163 # 00164 # if useGlobals: 00165 # paramgui.setGlobals(myf) 00166 # else: 00167 # paramgui.setGlobals({}) 00168 # 00169 # paramgui.runTask('plotants', myf['_ip']) 00170 # paramgui.setGlobals({}) 00171 # 00172 # 00173 # 00174 # 00175 def defaults(self, param=None): 00176 a=inspect.stack() 00177 stacklevel=0 00178 for k in range(len(a)): 00179 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00180 stacklevel=k 00181 break 00182 myf=sys._getframe(stacklevel).f_globals 00183 a = odict() 00184 a['vis'] = '' 00185 a['figfile'] = '' 00186 00187 a['async']=False 00188 00189 ### This function sets the default values but also will return the list of 00190 ### parameters or the default value of a given parameter 00191 if(param == None): 00192 myf['__set_default_parameters'](a) 00193 elif(param == 'paramkeys'): 00194 return a.keys() 00195 else: 00196 if(a.has_key(param)): 00197 #if(type(a[param]) == dict) : 00198 # return a[param][len(a[param])-1]['value'] 00199 #else : 00200 return a[param] 00201 00202 00203 # 00204 # 00205 def check_params(self, param=None, value=None): 00206 a=inspect.stack() 00207 stacklevel=0 00208 for k in range(len(a)): 00209 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00210 stacklevel=k 00211 break 00212 myf=sys._getframe(stacklevel).f_globals 00213 00214 # print 'param:', param, 'value:', value 00215 try : 00216 if str(type(value)) != "<type 'instance'>" : 00217 value0 = value 00218 value = myf['cu'].expandparam(param, value) 00219 matchtype = False 00220 if(type(value) == numpy.ndarray): 00221 if(type(value) == type(value0)): 00222 myf[param] = value.tolist() 00223 else: 00224 #print 'value:', value, 'value0:', value0 00225 #print 'type(value):', type(value), 'type(value0):', type(value0) 00226 myf[param] = value0 00227 if type(value0) != list : 00228 matchtype = True 00229 else : 00230 myf[param] = value 00231 value = myf['cu'].verifyparam({param:value}) 00232 if matchtype: 00233 value = False 00234 except Exception, instance: 00235 #ignore the exception and just return it unchecked 00236 myf[param] = value 00237 return value 00238 00239 # 00240 # 00241 def description(self, key='plotants', subkey=None): 00242 desc={'plotants': 'Plot the antenna distribution in the local reference frame:', 00243 'vis': 'Name of input visibility file (MS)', 00244 'figfile': 'Save the plotted figure to this file', 00245 00246 'async': 'If true the taskname must be started using plotants(...)' 00247 } 00248 00249 if(desc.has_key(key)) : 00250 return desc[key] 00251 00252 def itsdefault(self, paramname) : 00253 a = {} 00254 a['vis'] = '' 00255 a['figfile'] = '' 00256 00257 if a.has_key(paramname) : 00258 return a[paramname] 00259 plotants_pg = plotants_pg_()