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_plotuv import plotuv 00018 class plotuv_cli_: 00019 __name__ = "plotuv" 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__ = (plotuv_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'vis':None, 'field':None, 'antenna':None, 'spw':None, 'observation':None, 'array':None, 'maxnpts':None, 'colors':None, 'symb':None, 'ncycles':None, 'figfile':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, field=None, antenna=None, spw=None, observation=None, array=None, maxnpts=None, colors=None, symb=None, ncycles=None, figfile=None, async=None): 00047 00048 """Plot the baseline distribution 00049 Plots the uv coverage of vis in klambda. ncycles of colors will be 00050 allocated to representative wavelengths. 00051 00052 Keyword arguments: 00053 vis -- Name of input visibility file 00054 default: none; example: vis='ngc5921.ms' 00055 00056 --- Data Selection (see help par.selectdata for more detailed 00057 information) 00058 00059 field -- Select field using field id(s) or field name(s). 00060 [run listobs to obtain the list IDs or names] 00061 default: ''=all fields. If field is a non-negative 00062 integer, it is assumed to be a field index. 00063 Otherwise, it is assumed to be a field name 00064 field='0~2'; field ids 0,1,2 00065 field='0,4,5~7'; field ids 0,4,5,6,7 00066 field='3C286,3C295'; fields named 3C286 and 3C295 00067 field = '3,4C*'; field id 3, all names starting with 4C 00068 antenna -- Select data based on antenna/baseline 00069 default: '' (all) 00070 Non-negative integers are assumed to be antenna indices, and 00071 anything else is taken as an antenna name. 00072 00073 Examples: 00074 antenna='5&6': baseline between antenna index 5 and index 6. 00075 antenna='VA05&VA06': baseline between VLA antenna 5 and 6. 00076 antenna='5&6;7&8': baselines 5-6 and 7-8 00077 antenna='5': all baselines with antenna 5 00078 antenna='5,6,10': all baselines including antennas 5, 6, or 10 00079 antenna='5,6,10&': all baselines with *only* antennas 5, 6, or 00080 10. (cross-correlations only. Use && 00081 to include autocorrelations, and &&& 00082 to get only autocorrelations.) 00083 antenna='!ea03,ea12,ea17': all baselines except those that 00084 include EVLA antennas ea03, ea12, or 00085 ea17. 00086 spw -- Select spectral windows. Channel selection is ignored for now. 00087 default: ''=all spectral windows 00088 spw='0~2,4'; spectral windows 0,1,2,4 00089 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00090 spw='0'; spw 0 00091 spw='0,10,3'; spws 0, 10, and 3 00092 observation -- Select by observation ID(s). default: '' = all 00093 array -- (Sub)array number range. default: ''=all 00094 00095 maxnpts -- Save memory and/or screen space by plotting a maximum of maxnpts 00096 (or all of them if maxnpts < 1). There is a very sharp 00097 slowdown if the plotter starts swapping. 00098 default: 100000 00099 colors -- a list of matplotlib color codes, used in order of decreasing 00100 visibility wavelength. 00101 default: ['r', 'y', 'g', 'b'] (red, yellow, green, blue) 00102 symb -- One of matplotlib's codes for plot symbols: .:,o^v<>s+xDd234hH|_ 00103 default: ',': The smallest points I could find. 00104 ncycles -- The number of times colors will be cycled through per plot. 00105 default: 1 00106 figfile -- If not '', save the plots using names based on figfile. 00107 Example: if figfile is 'test.png', and field is '1,2,4', the plots 00108 will be saved to test_fld1.png, test_fld2.png, 00109 and test_fld4.png. 00110 default: '' (Do not save) 00111 00112 """ 00113 if not hasattr(self, "__globals__") or self.__globals__ == None : 00114 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00115 #casac = self.__globals__['casac'] 00116 casalog = self.__globals__['casalog'] 00117 #casalog = casac.casac.logsink() 00118 self.__globals__['__last_task'] = 'plotuv' 00119 self.__globals__['taskname'] = 'plotuv' 00120 ### 00121 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00122 ### 00123 ### 00124 #Handle globals or user over-ride of arguments 00125 # 00126 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00127 useLocalDefaults = False 00128 00129 for item in function_signature_defaults.iteritems(): 00130 key,val = item 00131 keyVal = eval(key) 00132 if (keyVal == None): 00133 #user hasn't set it - use global/default 00134 pass 00135 else: 00136 #user has set it - use over-ride 00137 if (key != 'self') : 00138 useLocalDefaults = True 00139 00140 myparams = {} 00141 if useLocalDefaults : 00142 for item in function_signature_defaults.iteritems(): 00143 key,val = item 00144 keyVal = eval(key) 00145 exec('myparams[key] = keyVal') 00146 self.parameters[key] = keyVal 00147 if (keyVal == None): 00148 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00149 keyVal = eval(key) 00150 if(type(keyVal) == dict) : 00151 if len(keyVal) > 0 : 00152 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00153 else : 00154 exec('myparams[key] = ' + key + ' = {}') 00155 00156 else : 00157 async = self.parameters['async'] 00158 myparams['vis'] = vis = self.parameters['vis'] 00159 myparams['field'] = field = self.parameters['field'] 00160 myparams['antenna'] = antenna = self.parameters['antenna'] 00161 myparams['spw'] = spw = self.parameters['spw'] 00162 myparams['observation'] = observation = self.parameters['observation'] 00163 myparams['array'] = array = self.parameters['array'] 00164 myparams['maxnpts'] = maxnpts = self.parameters['maxnpts'] 00165 myparams['colors'] = colors = self.parameters['colors'] 00166 myparams['symb'] = symb = self.parameters['symb'] 00167 myparams['ncycles'] = ncycles = self.parameters['ncycles'] 00168 myparams['figfile'] = figfile = self.parameters['figfile'] 00169 00170 if type(colors)==str: colors=[colors] 00171 00172 result = None 00173 00174 # 00175 # The following is work around to avoid a bug with current python translation 00176 # 00177 mytmp = {} 00178 00179 mytmp['vis'] = vis 00180 mytmp['field'] = field 00181 mytmp['antenna'] = antenna 00182 mytmp['spw'] = spw 00183 mytmp['observation'] = observation 00184 mytmp['array'] = array 00185 mytmp['maxnpts'] = maxnpts 00186 mytmp['colors'] = colors 00187 mytmp['symb'] = symb 00188 mytmp['ncycles'] = ncycles 00189 mytmp['figfile'] = figfile 00190 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00191 trec = casac.casac.utils().torecord(pathname+'plotuv.xml') 00192 00193 casalog.origin('plotuv') 00194 try : 00195 #if not trec.has_key('plotuv') or not casac.casac.utils().verify(mytmp, trec['plotuv']) : 00196 #return False 00197 00198 casac.casac.utils().verify(mytmp, trec['plotuv'], True) 00199 scriptstr=[''] 00200 saveinputs = self.__globals__['saveinputs'] 00201 saveinputs('plotuv', 'plotuv.last', myparams, self.__globals__,scriptstr=scriptstr) 00202 if async : 00203 count = 0 00204 keybase = time.strftime("%y%m%d.%H%M%S") 00205 key = keybase + "_" + str(count) 00206 while self.__async__.has_key(key) : 00207 count += 1 00208 key = keybase + "_" + str(count) 00209 result = tm.execute('plotuv', vis, field, antenna, spw, observation, array, maxnpts, colors, symb, ncycles, figfile) 00210 print "Use: " 00211 print " tm.retrieve(return_value) # to retrieve the status" 00212 print 00213 self.rkey = key 00214 self.__async__[key] = result 00215 else : 00216 tname = 'plotuv' 00217 spaces = ' '*(18-len(tname)) 00218 casalog.post('\n##########################################'+ 00219 '\n##### Begin Task: ' + tname + spaces + ' #####') 00220 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00221 result = plotuv(vis, field, antenna, spw, observation, array, maxnpts, colors, symb, ncycles, figfile) 00222 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00223 '\n##########################################') 00224 00225 except Exception, instance: 00226 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00227 raise 00228 else : 00229 #print '**** Error **** ',instance 00230 tname = 'plotuv' 00231 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00232 pass 00233 00234 gc.collect() 00235 return result 00236 # 00237 # 00238 # 00239 def paramgui(self, useGlobals=True, ipython_globals=None): 00240 """ 00241 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00242 """ 00243 import paramgui 00244 if not hasattr(self, "__globals__") or self.__globals__ == None : 00245 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00246 00247 if useGlobals: 00248 if ipython_globals == None: 00249 myf=self.__globals__ 00250 else: 00251 myf=ipython_globals 00252 00253 paramgui.setGlobals(myf) 00254 else: 00255 paramgui.setGlobals({}) 00256 00257 paramgui.runTask('plotuv', myf['_ip']) 00258 paramgui.setGlobals({}) 00259 00260 # 00261 # 00262 # 00263 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 00264 if not hasattr(self, "__globals__") or self.__globals__ == None : 00265 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00266 if ipython_globals == None: 00267 myf=self.__globals__ 00268 else: 00269 myf=ipython_globals 00270 00271 a = odict() 00272 a['vis'] = '' 00273 a['field'] = '' 00274 a['antenna'] = '' 00275 a['spw'] = '' 00276 a['observation'] = '' 00277 a['array'] = '' 00278 a['maxnpts'] = 100000 00279 a['colors'] = ['r', 'y', 'g', 'b'] 00280 a['symb'] = ',' 00281 a['ncycles'] = 1 00282 a['figfile'] = '' 00283 00284 a['async']=False 00285 00286 ### This function sets the default values but also will return the list of 00287 ### parameters or the default value of a given parameter 00288 if(param == None): 00289 myf['__set_default_parameters'](a) 00290 elif(param == 'paramkeys'): 00291 return a.keys() 00292 else: 00293 if(paramvalue==None and subparam==None): 00294 if(a.has_key(param)): 00295 return a[param] 00296 else: 00297 return self.itsdefault(param) 00298 else: 00299 retval=a[param] 00300 if(type(a[param])==dict): 00301 for k in range(len(a[param])): 00302 valornotval='value' 00303 if(a[param][k].has_key('notvalue')): 00304 valornotval='notvalue' 00305 if((a[param][k][valornotval])==paramvalue): 00306 retval=a[param][k].copy() 00307 retval.pop(valornotval) 00308 if(subparam != None): 00309 if(retval.has_key(subparam)): 00310 retval=retval[subparam] 00311 else: 00312 retval=self.itsdefault(subparam) 00313 else: 00314 retval=self.itsdefault(subparam) 00315 return retval 00316 00317 00318 # 00319 # 00320 def check_params(self, param=None, value=None, ipython_globals=None): 00321 if ipython_globals == None: 00322 myf=self.__globals__ 00323 else: 00324 myf=ipython_globals 00325 # print 'param:', param, 'value:', value 00326 try : 00327 if str(type(value)) != "<type 'instance'>" : 00328 value0 = value 00329 value = myf['cu'].expandparam(param, value) 00330 matchtype = False 00331 if(type(value) == numpy.ndarray): 00332 if(type(value) == type(value0)): 00333 myf[param] = value.tolist() 00334 else: 00335 #print 'value:', value, 'value0:', value0 00336 #print 'type(value):', type(value), 'type(value0):', type(value0) 00337 myf[param] = value0 00338 if type(value0) != list : 00339 matchtype = True 00340 else : 00341 myf[param] = value 00342 value = myf['cu'].verifyparam({param:value}) 00343 if matchtype: 00344 value = False 00345 except Exception, instance: 00346 #ignore the exception and just return it unchecked 00347 myf[param] = value 00348 return value 00349 # 00350 # 00351 def description(self, key='plotuv', subkey=None): 00352 desc={'plotuv': 'Plot the baseline distribution', 00353 'vis': 'Name of input visibility file (MS)', 00354 'field': 'Select field using ID(s) or name(s)', 00355 'antenna': 'Select data based on antenna/baseline', 00356 'spw': 'Select spectral window/channels', 00357 'observation': 'Select by observation ID(s)', 00358 'array': 'Select (sub)array(s) by array ID number', 00359 'maxnpts': 'Maximum number of points per plot.', 00360 'colors': 'a list of matplotlib color codes', 00361 'symb': 'A matplotlib plot symbol code', 00362 'ncycles': 'How many times to cycle through colors per plot.', 00363 'figfile': 'Save the plotted figure(s) using this name', 00364 00365 'async': 'If true the taskname must be started using plotuv(...)' 00366 } 00367 00368 if(desc.has_key(key)) : 00369 return desc[key] 00370 00371 def itsdefault(self, paramname) : 00372 a = {} 00373 a['vis'] = '' 00374 a['field'] = '' 00375 a['antenna'] = '' 00376 a['spw'] = '' 00377 a['observation'] = '' 00378 a['array'] = '' 00379 a['maxnpts'] = 100000 00380 a['colors'] = ['r', 'y', 'g', 'b'] 00381 a['symb'] = ',' 00382 a['ncycles'] = 1 00383 a['figfile'] = '' 00384 00385 #a = sys._getframe(len(inspect.stack())-1).f_globals 00386 00387 if a.has_key(paramname) : 00388 return a[paramname] 00389 plotuv_cli = plotuv_cli_()