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_browsetable import browsetable 00016 from task_browsetable import casalog 00017 00018 class browsetable_pg_: 00019 __name__ = "browsetable" 00020 00021 def __init__(self) : 00022 self.__bases__ = (browsetable_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, tablename=None, mightedit=None, sortlist=None, taql=None, skipcols=None, async=None): 00027 00028 """Browse a table (MS, calibration table, image) 00029 This task brings up a browser that can open and display any CASA table. 00030 The tablename can be specified at startup, or any table can be loaded after 00031 the browser comes up. 00032 00033 Parameters: 00034 tablename -- Name of table file on disk (vis, calibration table, image) 00035 default: none; example: tablename='ngc5921.ms' 00036 mightedit -- If True disable the filtering options (below) and allow 00037 editing the table. Warning: the GUI appears to ignore 00038 whether the table tool is opened read-only - just be 00039 aware that you should not edit filtered tables unless 00040 you know what you are doing. 00041 sortlist -- List of columns to sort by. 00042 default: [] (none) 00043 taql -- TaQL query string for prefiltering the table. 00044 default: "" (none); example: taql="ANTENNA2 < 6" 00045 skipcols -- Columns to NOT display. 00046 default: [] (none); example: skipcols='feed1, feed2' 00047 00048 00049 Some comments on using browsetable (see cookbook also): 00050 00051 Most often you will browse a measurement set. Either specify the vis name 00052 as the tablename, or when the browser comes up, 00053 00054 click on <file> (upper left), then click on <open table> 00055 00056 If you want to look at sub-tables, use the tab table keywords along the 00057 left side to bring up a panel with the sub-tables listed (Fig 3.8), then 00058 choose (left-click) a table and View. 00059 00060 Note that one useful feature is that you can Edit any table and its 00061 contents. Use the Edit tab (to the right of the file tab). Be careful 00062 with this, and make a backup copy of the table before editing! 00063 00064 Use the Close Tables and Exit option from the Files menu to quit the 00065 casabrowser. 00066 00067 To get a plot of two table values, click on tools, then click on plot 2D. 00068 For example, to get a u-v plot, in the Plotter Option Gui, 00069 set Rows: 0 to <Large Number> 00070 X Axis: UVW Slice (set 0) 00071 Y Axis: UVW Slice (set 1) 00072 click 'Clear and Plot' on right. 00073 00074 For visibility plots 00075 X Axis: TIME 00076 Y Axis: DATA Slice Amplitude 00077 click 'Clear and Plot' on right. 00078 00079 00080 00081 """ 00082 a=inspect.stack() 00083 stacklevel=0 00084 for k in range(len(a)): 00085 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00086 stacklevel=k 00087 break 00088 myf=sys._getframe(stacklevel).f_globals 00089 myf['__last_task'] = 'browsetable' 00090 myf['taskname'] = 'browsetable' 00091 ### 00092 myf['update_params'](func=myf['taskname'],printtext=False) 00093 ### 00094 ### 00095 #Handle globals or user over-ride of arguments 00096 # 00097 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00098 useLocalDefaults = False 00099 00100 for item in function_signature_defaults.iteritems(): 00101 key,val = item 00102 keyVal = eval(key) 00103 if (keyVal == None): 00104 #user hasn't set it - use global/default 00105 pass 00106 else: 00107 #user has set it - use over-ride 00108 if (key != 'self') : 00109 useLocalDefaults = True 00110 #myf[key]=keyVal 00111 00112 myparams = {} 00113 if useLocalDefaults : 00114 for item in function_signature_defaults.iteritems(): 00115 key,val = item 00116 keyVal = eval(key) 00117 exec('myparams[key] = keyVal') 00118 if (keyVal == None): 00119 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00120 keyVal = eval(key) 00121 if(type(keyVal) == dict) : 00122 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00123 00124 else : 00125 uselessvariable = None 00126 myparams['tablename'] = tablename = myf['tablename'] 00127 myparams['mightedit'] = mightedit = myf['mightedit'] 00128 myparams['sortlist'] = sortlist = myf['sortlist'] 00129 myparams['taql'] = taql = myf['taql'] 00130 myparams['skipcols'] = skipcols = myf['skipcols'] 00131 00132 00133 result = None 00134 00135 # 00136 # The following is work around to avoid a bug with current python translation 00137 # 00138 mytmp = {} 00139 00140 mytmp['tablename'] = tablename 00141 mytmp['mightedit'] = mightedit 00142 mytmp['sortlist'] = sortlist 00143 mytmp['taql'] = taql 00144 mytmp['skipcols'] = skipcols 00145 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00146 trec = casac.utils().torecord(pathname+'browsetable.xml') 00147 00148 casalog.origin('browsetable') 00149 if not trec.has_key('browsetable') or not casac.utils().verify(mytmp, trec['browsetable']) : 00150 return False 00151 00152 00153 try : 00154 casalog.post('') 00155 casalog.post('##########################################') 00156 casalog.post('##### Begin Task: browsetable #####') 00157 casalog.post('') 00158 result = browsetable(tablename, mightedit, sortlist, taql, skipcols) 00159 casalog.post('') 00160 casalog.post('##### End Task: browsetable #####') 00161 casalog.post('##########################################') 00162 00163 00164 # saveinputs for individule engine has no use 00165 # saveinputs should alos be removed from casa_in_py.py 00166 # 00167 # 00168 # saveinputs = myf['saveinputs'] 00169 # saveinputs('browsetable', 'browsetable.last', myparams) 00170 # 00171 # 00172 except Exception, instance: 00173 #print '**** Error **** ',instance 00174 pass 00175 00176 gc.collect() 00177 return result 00178 # 00179 # 00180 ## 00181 # def paramgui(self, useGlobals=True): 00182 # """ 00183 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00184 # """ 00185 # import paramgui 00186 # 00187 # a=inspect.stack() 00188 # stacklevel=0 00189 # for k in range(len(a)): 00190 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00191 # stacklevel=k 00192 # break 00193 # myf = sys._getframe(stacklevel).f_globals 00194 # 00195 # if useGlobals: 00196 # paramgui.setGlobals(myf) 00197 # else: 00198 # paramgui.setGlobals({}) 00199 # 00200 # paramgui.runTask('browsetable', myf['_ip']) 00201 # paramgui.setGlobals({}) 00202 # 00203 # 00204 # 00205 # 00206 def defaults(self, param=None): 00207 a=inspect.stack() 00208 stacklevel=0 00209 for k in range(len(a)): 00210 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00211 stacklevel=k 00212 break 00213 myf=sys._getframe(stacklevel).f_globals 00214 a = odict() 00215 a['tablename'] = '' 00216 00217 a['async']=False 00218 a['tablename'] = { 00219 0:odict([{'notvalue':''}, {'mightedit':False}, {'sortlist':''}, {'taql':''}, {'skipcols':''}])} 00220 00221 ### This function sets the default values but also will return the list of 00222 ### parameters or the default value of a given parameter 00223 if(param == None): 00224 myf['__set_default_parameters'](a) 00225 elif(param == 'paramkeys'): 00226 return a.keys() 00227 else: 00228 if(a.has_key(param)): 00229 #if(type(a[param]) == dict) : 00230 # return a[param][len(a[param])-1]['value'] 00231 #else : 00232 return a[param] 00233 00234 00235 # 00236 # 00237 def check_params(self, param=None, value=None): 00238 a=inspect.stack() 00239 stacklevel=0 00240 for k in range(len(a)): 00241 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00242 stacklevel=k 00243 break 00244 myf=sys._getframe(stacklevel).f_globals 00245 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 # 00273 def description(self, key='browsetable', subkey=None): 00274 desc={'browsetable': 'Browse a table (MS, calibration table, image)', 00275 'tablename': 'Name of input table', 00276 'mightedit': 'Warning: the GUI seems to ignore whether the table tool is opened read-only - just be careful, esp. if filtering.', 00277 'sortlist': 'Columns to sort by (ascending)', 00278 'taql': 'TaQL query string for prefiltering the table.', 00279 'skipcols': 'Columns to omit', 00280 00281 'async': 'If true the taskname must be started using browsetable(...)' 00282 } 00283 00284 # 00285 # Set subfields defaults if needed 00286 # 00287 00288 if(desc.has_key(key)) : 00289 return desc[key] 00290 00291 def itsdefault(self, paramname) : 00292 a = {} 00293 a['tablename'] = '' 00294 a['mightedit'] = False 00295 a['sortlist'] = '' 00296 a['taql'] = '' 00297 a['skipcols'] = '' 00298 00299 if a.has_key(paramname) : 00300 return a[paramname] 00301 browsetable_pg = browsetable_pg_()