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_plotcal import plotcal 00018 class plotcal_cli_: 00019 __name__ = "plotcal" 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__ = (plotcal_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'caltable':None, 'xaxis':None, 'yaxis':None, 'poln':None, 'field':None, 'antenna':None, 'spw':None, 'timerange':None, 'subplot':None, 'overplot':None, 'clearpanel':None, 'iteration':None, 'plotrange':None, 'showflags':None, 'plotsymbol':None, 'plotcolor':None, 'markersize':None, 'fontsize':None, 'showgui':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, caltable=None, xaxis=None, yaxis=None, poln=None, field=None, antenna=None, spw=None, timerange=None, subplot=None, overplot=None, clearpanel=None, iteration=None, plotrange=None, showflags=None, plotsymbol=None, plotcolor=None, markersize=None, fontsize=None, showgui=None, figfile=None, async=None): 00047 00048 """An all-purpose plotter for calibration results 00049 00050 The values for all calibration solutions (G, T, GSPLINE, B, BPOLY, D, M) 00051 can be displayed for a variety of polarization combinations and calibrations. 00052 The plot solutions may be iterated through antennas/spw/fields during one execution, 00053 and many frames can be obtained in each plot. 00054 00055 The plotter permits zooming, listing and flagging of solutions, although 00056 the results of flagged solutions are not yet available. 00057 00058 00059 The plotter permits zooming, listing and flagging of solutions, although 00060 the implications of flagged solutions are not yet made. See some hints at the end 00061 of this description. 00062 00063 00064 Keyword arguments: 00065 caltable -- Name of input calibration table 00066 default: none; example: caltable='ngc5921.gcal' 00067 The type of calibration table is determined automatically. 00068 xaxis -- Value to plot on the x axis 00069 Options: 'time','scan','chan','freq','antenna','amp','phase','real','imag','snr' 00070 Default: cal type dependent, usually 'time' 00071 yaxis -- Value to plot on the y-axis 00072 Options: 'amp','phase','real','imag','snr','antenna','tsys','delay','spgain' 00073 Default: cal type dependent, usually 'amp' 00074 poln -- Polarization (or combination) to plot 00075 default: '' (RL); all polarizations 00076 Options: '' = ('RL'),'R','L','XY','X','Y', 00077 '/' --> form complex poln ratio 00078 (amp ratio and phase difference) 00079 field -- Select field using field id(s) or field name(s). 00080 ['go listobs' to obtain the fieldt id's or names] 00081 default: ''=all fields 00082 If field string is a non-negative integer, it is assumed a 00083 field index, otherwise it is assumed a field name 00084 field='0~2'; field ids 0,1,2 00085 field='0,4,5~7'; field ids 0,4,5,6,7 00086 field='3C286,3C295'; field named 3C286 and 3C295 00087 field = '3,4C*'; field id 3, all names starting with 4C 00088 antenna -- Antenna selection (baseline syntax ignored) 00089 default: '' (all); 00090 example: antenna='1,3~5' means antenna 00091 indices 1,3,4,5. 00092 spw -- Select spectral window (channel syntax ignored, except for D) 00093 default: ''=all spectral windows 00094 spw='0~2,4'; spectral windows 0,1,2,4 00095 spw='<2'; spectral windows less than 2 00096 timerange -- Time selection 00097 default: '' (all) 00098 example: timerange='1995/04/13/09:15:00~1995/04/13/09:25:00' 00099 00100 --- Plot Options --- 00101 subplot -- Panel number on the display screen 00102 default: 111 (full screen display); 00103 examples: 00104 if iteration = 'antenna'; subplot=321 then 00105 a plot frame will contain the first 6 antennas, in three 00106 rows and two columns. Follow instructions on screen to 00107 cycle through the frames 00108 if iteration = ''; then one frame can be filled with many 00109 plots in a piecemeal fashion; for example 00110 antenna='0'; subplot=221; plotcal() 00111 antenna='1'; subplot=222; plotcal() 00112 antenna='2'; subplot=223; plotcal() 00113 antenna='3'; subplot=224; plotcal() 00114 overplot -- Overplot these values on current plot (if possible) 00115 default: False; 00116 True (overplotting) can be done ONLY IF iteration='' 00117 clearpanel -- Ignore this parameter. 00118 Clear nothing on the plot window, automatically 00119 clear plotting area, clear the current plot area, or 00120 clear the whole plot panel. 00121 options: None, Auto, Current, All (None and Auto not supported) 00122 default: Auto 00123 example: clearpanel='Current' 00124 iteration -- Create a sequence of plots, iterating over antenna, time, 00125 field, and/or spw 00126 default: '' --> create in all in one plot 00127 example: iteration='antenna' --> create a sequence of 00128 separate plots separated by antenna. Flagging cannot 00129 be done in iteration mode. 00130 plotrange -- Control the x and y ranges of the plot, as a list of 00131 values, e.g., [xmin,xmax,ymin,ymax] 00132 default=[] --> plot will self-scale 00133 Note: time plotting ranges are cumbersome to use. 00134 Use the zoom option 00135 showflags -- If true, only flagged solutions will be plotted 00136 default: false --> only show unflagged solutions 00137 plotsymbol -- pylab plot symbol. See cookbook for details 00138 default: '.': large points 00139 ',' = small points (see markersize) 00140 '-' = connect points by line 00141 colors are cycled automatically for multi-function plots 00142 plotcolor -- Initial color to use on each plot 00143 default: 'blue' 00144 markersize -- Control the size of plot symbols 00145 default: 5.0 --> a nice size for symbols 00146 fontsize -- Control the font size of title (axes labels will be 00147 80% of this size) 00148 default: 10.0 00149 showgui -- Whether or not to display the plotting GUI 00150 default: True; example showgui=False 00151 figfile -- File name to save the plotted figure to. 00152 default: ''; example figfile=myPlot.png 00153 00154 Hints on using plotxy (see section 3.4 in cookbook) 00155 00156 Useful Buttons at bottom left: 00157 5th--magnifying glass. Click on this, 00158 left mouse button rectangle drag will zoom 00159 right mose button rectangle drag will unzoom a certain amount 00160 1st--restore original magnification 00161 00162 Useful regions just above: 00163 Quit will terminate plotter 00164 Next will go to next plot as specified by iteration 00165 To locate, you must click 'Mark Region' first 00166 then make appropriate region(s) 00167 then click locate to list points on logger 00168 DO NOT USE Flag, Unflag at the present time. 00169 00170 00171 """ 00172 if not hasattr(self, "__globals__") or self.__globals__ == None : 00173 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00174 #casac = self.__globals__['casac'] 00175 casalog = self.__globals__['casalog'] 00176 #casalog = casac.casac.logsink() 00177 self.__globals__['__last_task'] = 'plotcal' 00178 self.__globals__['taskname'] = 'plotcal' 00179 ### 00180 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00181 ### 00182 ### 00183 #Handle globals or user over-ride of arguments 00184 # 00185 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00186 useLocalDefaults = False 00187 00188 for item in function_signature_defaults.iteritems(): 00189 key,val = item 00190 keyVal = eval(key) 00191 if (keyVal == None): 00192 #user hasn't set it - use global/default 00193 pass 00194 else: 00195 #user has set it - use over-ride 00196 if (key != 'self') : 00197 useLocalDefaults = True 00198 00199 myparams = {} 00200 if useLocalDefaults : 00201 for item in function_signature_defaults.iteritems(): 00202 key,val = item 00203 keyVal = eval(key) 00204 exec('myparams[key] = keyVal') 00205 self.parameters[key] = keyVal 00206 if (keyVal == None): 00207 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00208 keyVal = eval(key) 00209 if(type(keyVal) == dict) : 00210 if len(keyVal) > 0 : 00211 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00212 else : 00213 exec('myparams[key] = ' + key + ' = {}') 00214 00215 else : 00216 async = self.parameters['async'] 00217 myparams['caltable'] = caltable = self.parameters['caltable'] 00218 myparams['xaxis'] = xaxis = self.parameters['xaxis'] 00219 myparams['yaxis'] = yaxis = self.parameters['yaxis'] 00220 myparams['poln'] = poln = self.parameters['poln'] 00221 myparams['field'] = field = self.parameters['field'] 00222 myparams['antenna'] = antenna = self.parameters['antenna'] 00223 myparams['spw'] = spw = self.parameters['spw'] 00224 myparams['timerange'] = timerange = self.parameters['timerange'] 00225 myparams['subplot'] = subplot = self.parameters['subplot'] 00226 myparams['overplot'] = overplot = self.parameters['overplot'] 00227 myparams['clearpanel'] = clearpanel = self.parameters['clearpanel'] 00228 myparams['iteration'] = iteration = self.parameters['iteration'] 00229 myparams['plotrange'] = plotrange = self.parameters['plotrange'] 00230 myparams['showflags'] = showflags = self.parameters['showflags'] 00231 myparams['plotsymbol'] = plotsymbol = self.parameters['plotsymbol'] 00232 myparams['plotcolor'] = plotcolor = self.parameters['plotcolor'] 00233 myparams['markersize'] = markersize = self.parameters['markersize'] 00234 myparams['fontsize'] = fontsize = self.parameters['fontsize'] 00235 myparams['showgui'] = showgui = self.parameters['showgui'] 00236 myparams['figfile'] = figfile = self.parameters['figfile'] 00237 00238 if type(plotrange)==float: plotrange=[plotrange] 00239 00240 result = None 00241 00242 # 00243 # The following is work around to avoid a bug with current python translation 00244 # 00245 mytmp = {} 00246 00247 mytmp['caltable'] = caltable 00248 mytmp['xaxis'] = xaxis 00249 mytmp['yaxis'] = yaxis 00250 mytmp['poln'] = poln 00251 mytmp['field'] = field 00252 mytmp['antenna'] = antenna 00253 mytmp['spw'] = spw 00254 mytmp['timerange'] = timerange 00255 mytmp['subplot'] = subplot 00256 mytmp['overplot'] = overplot 00257 mytmp['clearpanel'] = clearpanel 00258 mytmp['iteration'] = iteration 00259 mytmp['plotrange'] = plotrange 00260 mytmp['showflags'] = showflags 00261 mytmp['plotsymbol'] = plotsymbol 00262 mytmp['plotcolor'] = plotcolor 00263 mytmp['markersize'] = markersize 00264 mytmp['fontsize'] = fontsize 00265 mytmp['showgui'] = showgui 00266 mytmp['figfile'] = figfile 00267 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00268 trec = casac.casac.utils().torecord(pathname+'plotcal.xml') 00269 00270 casalog.origin('plotcal') 00271 try : 00272 #if not trec.has_key('plotcal') or not casac.casac.utils().verify(mytmp, trec['plotcal']) : 00273 #return False 00274 00275 casac.casac.utils().verify(mytmp, trec['plotcal'], True) 00276 scriptstr=[''] 00277 saveinputs = self.__globals__['saveinputs'] 00278 saveinputs('plotcal', 'plotcal.last', myparams, self.__globals__,scriptstr=scriptstr) 00279 if async : 00280 count = 0 00281 keybase = time.strftime("%y%m%d.%H%M%S") 00282 key = keybase + "_" + str(count) 00283 while self.__async__.has_key(key) : 00284 count += 1 00285 key = keybase + "_" + str(count) 00286 result = tm.execute('plotcal', caltable, xaxis, yaxis, poln, field, antenna, spw, timerange, subplot, overplot, clearpanel, iteration, plotrange, showflags, plotsymbol, plotcolor, markersize, fontsize, showgui, figfile) 00287 print "Use: " 00288 print " tm.retrieve(return_value) # to retrieve the status" 00289 print 00290 self.rkey = key 00291 self.__async__[key] = result 00292 else : 00293 tname = 'plotcal' 00294 spaces = ' '*(18-len(tname)) 00295 casalog.post('\n##########################################'+ 00296 '\n##### Begin Task: ' + tname + spaces + ' #####') 00297 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00298 result = plotcal(caltable, xaxis, yaxis, poln, field, antenna, spw, timerange, subplot, overplot, clearpanel, iteration, plotrange, showflags, plotsymbol, plotcolor, markersize, fontsize, showgui, figfile) 00299 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00300 '\n##########################################') 00301 00302 except Exception, instance: 00303 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00304 raise 00305 else : 00306 #print '**** Error **** ',instance 00307 tname = 'plotcal' 00308 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00309 pass 00310 00311 gc.collect() 00312 return result 00313 # 00314 # 00315 # 00316 def paramgui(self, useGlobals=True, ipython_globals=None): 00317 """ 00318 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00319 """ 00320 import paramgui 00321 if not hasattr(self, "__globals__") or self.__globals__ == None : 00322 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00323 00324 if useGlobals: 00325 if ipython_globals == None: 00326 myf=self.__globals__ 00327 else: 00328 myf=ipython_globals 00329 00330 paramgui.setGlobals(myf) 00331 else: 00332 paramgui.setGlobals({}) 00333 00334 paramgui.runTask('plotcal', myf['_ip']) 00335 paramgui.setGlobals({}) 00336 00337 # 00338 # 00339 # 00340 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 00341 if not hasattr(self, "__globals__") or self.__globals__ == None : 00342 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00343 if ipython_globals == None: 00344 myf=self.__globals__ 00345 else: 00346 myf=ipython_globals 00347 00348 a = odict() 00349 a['caltable'] = '' 00350 a['xaxis'] = '' 00351 a['yaxis'] = '' 00352 a['poln'] = '' 00353 a['field'] = '' 00354 a['antenna'] = '' 00355 a['spw'] = '' 00356 a['timerange'] = '' 00357 a['subplot'] = 111 00358 a['overplot'] = False 00359 a['clearpanel'] = 'Auto' 00360 a['iteration'] = '' 00361 a['plotrange'] = [ 00362 ] 00363 a['showflags'] = False 00364 a['plotsymbol'] = 'o' 00365 a['plotcolor'] = 'blue' 00366 a['markersize'] = 5.0 00367 a['fontsize'] = 10.0 00368 a['showgui'] = True 00369 a['figfile'] = '' 00370 00371 a['async']=False 00372 00373 ### This function sets the default values but also will return the list of 00374 ### parameters or the default value of a given parameter 00375 if(param == None): 00376 myf['__set_default_parameters'](a) 00377 elif(param == 'paramkeys'): 00378 return a.keys() 00379 else: 00380 if(paramvalue==None and subparam==None): 00381 if(a.has_key(param)): 00382 return a[param] 00383 else: 00384 return self.itsdefault(param) 00385 else: 00386 retval=a[param] 00387 if(type(a[param])==dict): 00388 for k in range(len(a[param])): 00389 valornotval='value' 00390 if(a[param][k].has_key('notvalue')): 00391 valornotval='notvalue' 00392 if((a[param][k][valornotval])==paramvalue): 00393 retval=a[param][k].copy() 00394 retval.pop(valornotval) 00395 if(subparam != None): 00396 if(retval.has_key(subparam)): 00397 retval=retval[subparam] 00398 else: 00399 retval=self.itsdefault(subparam) 00400 else: 00401 retval=self.itsdefault(subparam) 00402 return retval 00403 00404 00405 # 00406 # 00407 def check_params(self, param=None, value=None, ipython_globals=None): 00408 if ipython_globals == None: 00409 myf=self.__globals__ 00410 else: 00411 myf=ipython_globals 00412 # print 'param:', param, 'value:', value 00413 try : 00414 if str(type(value)) != "<type 'instance'>" : 00415 value0 = value 00416 value = myf['cu'].expandparam(param, value) 00417 matchtype = False 00418 if(type(value) == numpy.ndarray): 00419 if(type(value) == type(value0)): 00420 myf[param] = value.tolist() 00421 else: 00422 #print 'value:', value, 'value0:', value0 00423 #print 'type(value):', type(value), 'type(value0):', type(value0) 00424 myf[param] = value0 00425 if type(value0) != list : 00426 matchtype = True 00427 else : 00428 myf[param] = value 00429 value = myf['cu'].verifyparam({param:value}) 00430 if matchtype: 00431 value = False 00432 except Exception, instance: 00433 #ignore the exception and just return it unchecked 00434 myf[param] = value 00435 return value 00436 # 00437 # 00438 def description(self, key='plotcal', subkey=None): 00439 desc={'plotcal': 'An all-purpose plotter for calibration results ', 00440 'caltable': 'Name of input calibration table', 00441 'xaxis': 'Value to plot along x axis (time,chan,freq, antenna,antenna1,antenna2,scan, amp,phase,real,imag,snr, tsys,delay,spgain)', 00442 'yaxis': 'Value to plot along y axis (amp,phase,real,imag,snr, antenna,antenna1,antenna2,scan, tsys,delay,spgain)', 00443 'poln': 'Antenna polarization to plot (RL,R,L,XY,X,Y,/)', 00444 'field': 'field names or index of calibrators: \'\'==>all', 00445 'antenna': 'antenna/baselines: \'\'==>all, antenna = \'3,VA04\'', 00446 'spw': 'spectral window:channels: \'\'==>all, spw=\'1:5~57\'', 00447 'timerange': 'time range: \'\'==>all', 00448 'subplot': 'Panel number on display screen (yxn)', 00449 'overplot': 'Overplot solutions on existing display', 00450 'clearpanel': 'Specify if old plots are cleared or not (ignore)', 00451 'iteration': 'Iterate plots on antenna,time,spw,field', 00452 'plotrange': 'plot axes ranges: [xmin,xmax,ymin,ymax]', 00453 'showflags': 'If true, show flagged solutions', 00454 'plotsymbol': 'pylab plot symbol', 00455 'plotcolor': 'initial plotting color', 00456 'markersize': 'Size of plotted marks', 00457 'fontsize': 'Font size for labels', 00458 'showgui': 'Show plot on gui', 00459 'figfile': '\'\'= no plot hardcopy, otherwise supply name', 00460 00461 'async': 'If true the taskname must be started using plotcal(...)' 00462 } 00463 00464 if(desc.has_key(key)) : 00465 return desc[key] 00466 00467 def itsdefault(self, paramname) : 00468 a = {} 00469 a['caltable'] = '' 00470 a['xaxis'] = '' 00471 a['yaxis'] = '' 00472 a['poln'] = '' 00473 a['field'] = '' 00474 a['antenna'] = '' 00475 a['spw'] = '' 00476 a['timerange'] = '' 00477 a['subplot'] = 111 00478 a['overplot'] = False 00479 a['clearpanel'] = 'Auto' 00480 a['iteration'] = '' 00481 a['plotrange'] = [ 00482 ] 00483 a['showflags'] = False 00484 a['plotsymbol'] = 'o' 00485 a['plotcolor'] = 'blue' 00486 a['markersize'] = 5.0 00487 a['fontsize'] = 10.0 00488 a['showgui'] = True 00489 a['figfile'] = '' 00490 00491 #a = sys._getframe(len(inspect.stack())-1).f_globals 00492 00493 if a.has_key(paramname) : 00494 return a[paramname] 00495 plotcal_cli = plotcal_cli_()