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_listobs import listobs 00016 from task_listobs import casalog 00017 00018 class listobs_pg_: 00019 __name__ = "listobs" 00020 00021 def __init__(self) : 00022 self.__bases__ = (listobs_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, selectdata=None, spw=None, field=None, antenna=None, uvrange=None, timerange=None, correlation=None, scan=None, intent=None, feed=None, array=None, observation=None, verbose=None, listfile=None, async=None): 00027 00028 """List the summary of a data set in the logger or in a file 00029 00030 List the summary information of a data set in the logger or in a file, based on 00031 a data selection. Only rows can be selected and printed. No in-row selection is 00032 possible (channel or correlation). Refer to the task listvis to list visibilites. 00033 00034 Lists the following properties of a measurement set: 00035 scan list, field list, spectral window list with 00036 correlators, antenna locations, ms table information. 00037 00038 Keyword arguments: 00039 vis -- Name of input visibility file 00040 default: none. example: vis='ngc5921.ms' 00041 00042 selectdata -- Select a subset of data for flagging 00043 default: False 00044 options: True,False 00045 The summary listing will only apply to the specified selection. 00046 00047 antenna -- Select data based on baseline 00048 default: '' (all); example: antenna='5&6' baseline 5-6 00049 antenna='5&6;7&8' #baseline 5-6 and 7-8 00050 antenna='5' # all cross-correlation baselines between antenna 5 and all other available 00051 antennas 00052 antenna='5,6' # all baselines with antennas 5 and 6 00053 antenna='1&&1' # only the auto-correlation baselines for antenna 1 00054 antenna='1&&*' # cross and auto-correlation baselines between antenna 1 00055 and all other available antennas 00056 antenna='1~7&&&' # only the auto-correlation baselines for antennas in range 1~7 00057 spw -- Select data based on spectral window and channels 00058 default: '' (all); example: spw='1' 00059 spw='<2' #spectral windows less than 2 00060 spw='>1' #spectral windows greater than 1 00061 correlation -- Correlation types 00062 default: '' (all); 00063 example: correlation='RR LL' 00064 field -- Select data based on field id(s) or name(s) 00065 default: '' (all); example: field='1' 00066 field='0~2' # field ids inclusive from 0 to 2 00067 field='3C*' # all field names starting with 3C 00068 uvrange -- Select data within uvrange (default units meters) 00069 default: '' (all); example: 00070 uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lamgda 00071 uvrange='>4klamda';uvranges greater than 4 kilo-lambda 00072 uvrange='0~1000km'; uvrange in kilometers 00073 timerange -- Select data based on time range: 00074 default = '' (all); example, 00075 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' 00076 Note: YYYY/MM/DD can be dropped as needed: 00077 timerange='09:14:0~09:54:0' # this time range 00078 timerange='09:44:00' # data within one integration of time 00079 timerange='>10:24:00' # data after this time 00080 timerange='09:44:00+00:13:00' #data 13 minutes after time 00081 scan -- Select data based on scan number 00082 default: '' (all); example: scan='>3' 00083 intent -- Select data based on observation intent 00084 default: '' (all); example: intent='*CAL*,*BAND*' 00085 feed -- Selection based on the feed - NOT IMPLEMENTED YET 00086 array -- Selection based on the antenna array 00087 observation -- Selection based on the observation ID 00088 default: '' (all); example: observation='1' or observation=1 00089 00090 00091 verbose -- level of detail 00092 verbose=True: (default); scan and antenna lists 00093 verbose=False: less information 00094 00095 listfile -- name of disk file to write output. 00096 default: None. Example: listfile='list.txt' 00097 00098 00099 The 'Int (s)' column is the average of the MS's INTERVAL column 00100 for each scan, so in a time-averaged MS 'Int' = 9.83s more likely 00101 means 5 10s integrations and 1 9s integration (timebin) than 6 00102 9.83s integrations. 00103 00104 """ 00105 a=inspect.stack() 00106 stacklevel=0 00107 for k in range(len(a)): 00108 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00109 stacklevel=k 00110 break 00111 myf=sys._getframe(stacklevel).f_globals 00112 myf['__last_task'] = 'listobs' 00113 myf['taskname'] = 'listobs' 00114 ### 00115 myf['update_params'](func=myf['taskname'],printtext=False) 00116 ### 00117 ### 00118 #Handle globals or user over-ride of arguments 00119 # 00120 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00121 useLocalDefaults = False 00122 00123 for item in function_signature_defaults.iteritems(): 00124 key,val = item 00125 keyVal = eval(key) 00126 if (keyVal == None): 00127 #user hasn't set it - use global/default 00128 pass 00129 else: 00130 #user has set it - use over-ride 00131 if (key != 'self') : 00132 useLocalDefaults = True 00133 #myf[key]=keyVal 00134 00135 myparams = {} 00136 if useLocalDefaults : 00137 for item in function_signature_defaults.iteritems(): 00138 key,val = item 00139 keyVal = eval(key) 00140 exec('myparams[key] = keyVal') 00141 if (keyVal == None): 00142 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00143 keyVal = eval(key) 00144 if(type(keyVal) == dict) : 00145 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00146 00147 else : 00148 uselessvariable = None 00149 myparams['vis'] = vis = myf['vis'] 00150 myparams['selectdata'] = selectdata = myf['selectdata'] 00151 myparams['spw'] = spw = myf['spw'] 00152 myparams['field'] = field = myf['field'] 00153 myparams['antenna'] = antenna = myf['antenna'] 00154 myparams['uvrange'] = uvrange = myf['uvrange'] 00155 myparams['timerange'] = timerange = myf['timerange'] 00156 myparams['correlation'] = correlation = myf['correlation'] 00157 myparams['scan'] = scan = myf['scan'] 00158 myparams['intent'] = intent = myf['intent'] 00159 myparams['feed'] = feed = myf['feed'] 00160 myparams['array'] = array = myf['array'] 00161 myparams['observation'] = observation = myf['observation'] 00162 myparams['verbose'] = verbose = myf['verbose'] 00163 myparams['listfile'] = listfile = myf['listfile'] 00164 00165 00166 result = None 00167 00168 # 00169 # The following is work around to avoid a bug with current python translation 00170 # 00171 mytmp = {} 00172 00173 mytmp['vis'] = vis 00174 mytmp['selectdata'] = selectdata 00175 mytmp['spw'] = spw 00176 mytmp['field'] = field 00177 mytmp['antenna'] = antenna 00178 mytmp['uvrange'] = uvrange 00179 mytmp['timerange'] = timerange 00180 mytmp['correlation'] = correlation 00181 mytmp['scan'] = scan 00182 mytmp['intent'] = intent 00183 mytmp['feed'] = feed 00184 mytmp['array'] = array 00185 mytmp['observation'] = observation 00186 mytmp['verbose'] = verbose 00187 mytmp['listfile'] = listfile 00188 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00189 trec = casac.utils().torecord(pathname+'listobs.xml') 00190 00191 casalog.origin('listobs') 00192 if not trec.has_key('listobs') or not casac.utils().verify(mytmp, trec['listobs']) : 00193 return False 00194 00195 00196 try : 00197 casalog.post('') 00198 casalog.post('##########################################') 00199 casalog.post('##### Begin Task: listobs #####') 00200 casalog.post('') 00201 result = listobs(vis, selectdata, spw, field, antenna, uvrange, timerange, correlation, scan, intent, feed, array, observation, verbose, listfile) 00202 casalog.post('') 00203 casalog.post('##### End Task: listobs #####') 00204 casalog.post('##########################################') 00205 00206 00207 # saveinputs for individule engine has no use 00208 # saveinputs should alos be removed from casa_in_py.py 00209 # 00210 # 00211 # saveinputs = myf['saveinputs'] 00212 # saveinputs('listobs', 'listobs.last', myparams) 00213 # 00214 # 00215 except Exception, instance: 00216 #print '**** Error **** ',instance 00217 pass 00218 00219 gc.collect() 00220 return result 00221 # 00222 # 00223 ## 00224 # def paramgui(self, useGlobals=True): 00225 # """ 00226 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00227 # """ 00228 # import paramgui 00229 # 00230 # a=inspect.stack() 00231 # stacklevel=0 00232 # for k in range(len(a)): 00233 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00234 # stacklevel=k 00235 # break 00236 # myf = sys._getframe(stacklevel).f_globals 00237 # 00238 # if useGlobals: 00239 # paramgui.setGlobals(myf) 00240 # else: 00241 # paramgui.setGlobals({}) 00242 # 00243 # paramgui.runTask('listobs', myf['_ip']) 00244 # paramgui.setGlobals({}) 00245 # 00246 # 00247 # 00248 # 00249 def defaults(self, param=None): 00250 a=inspect.stack() 00251 stacklevel=0 00252 for k in range(len(a)): 00253 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00254 stacklevel=k 00255 break 00256 myf=sys._getframe(stacklevel).f_globals 00257 a = odict() 00258 a['vis'] = '' 00259 a['selectdata'] = True 00260 a['verbose'] = True 00261 a['listfile'] = '' 00262 00263 a['async']=False 00264 a['selectdata'] = { 00265 0:odict([{'value':True}, {'field':''}, {'spw':''}, {'antenna':''}, {'timerange':''}, {'correlation':''}, {'scan':''}, {'intent':''}, {'feed':''}, {'array':''}, {'uvrange':''}, {'observation':''}]), 00266 1:{'value':False}} 00267 00268 ### This function sets the default values but also will return the list of 00269 ### parameters or the default value of a given parameter 00270 if(param == None): 00271 myf['__set_default_parameters'](a) 00272 elif(param == 'paramkeys'): 00273 return a.keys() 00274 else: 00275 if(a.has_key(param)): 00276 #if(type(a[param]) == dict) : 00277 # return a[param][len(a[param])-1]['value'] 00278 #else : 00279 return a[param] 00280 00281 00282 # 00283 # 00284 def check_params(self, param=None, value=None): 00285 a=inspect.stack() 00286 stacklevel=0 00287 for k in range(len(a)): 00288 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00289 stacklevel=k 00290 break 00291 myf=sys._getframe(stacklevel).f_globals 00292 00293 # print 'param:', param, 'value:', value 00294 try : 00295 if str(type(value)) != "<type 'instance'>" : 00296 value0 = value 00297 value = myf['cu'].expandparam(param, value) 00298 matchtype = False 00299 if(type(value) == numpy.ndarray): 00300 if(type(value) == type(value0)): 00301 myf[param] = value.tolist() 00302 else: 00303 #print 'value:', value, 'value0:', value0 00304 #print 'type(value):', type(value), 'type(value0):', type(value0) 00305 myf[param] = value0 00306 if type(value0) != list : 00307 matchtype = True 00308 else : 00309 myf[param] = value 00310 value = myf['cu'].verifyparam({param:value}) 00311 if matchtype: 00312 value = False 00313 except Exception, instance: 00314 #ignore the exception and just return it unchecked 00315 myf[param] = value 00316 return value 00317 00318 # 00319 # 00320 def description(self, key='listobs', subkey=None): 00321 desc={'listobs': 'List the summary of a data set in the logger or in a file', 00322 'vis': 'Name of input visibility file (MS)', 00323 'selectdata': 'Data selection parameters', 00324 'spw': 'spectral-window/frequency/channel', 00325 'field': 'Field names or field index numbers: \'\'==>all, field=\'0~2,3C286\'', 00326 'antenna': 'antenna/baselines: \'\'==>all, antenna =\'3,VA04\'', 00327 'uvrange': 'uv range: \'\'==>all; uvrange =\'0~100klambda\', default units=meters', 00328 'timerange': 'time range: \'\'==>all,timerange=\'09:14:0~09:54:0\'', 00329 'correlation': 'Select data based on correlation', 00330 'scan': 'scan numbers: \'\'==>all', 00331 'intent': 'Select data based on observation intent: \'\'==>all', 00332 'feed': 'multi-feed numbers: Not yet implemented', 00333 'array': '(sub)array numbers: \'\'==>all', 00334 'observation': 'Select data based on observation ID: \'\'==>all', 00335 'verbose': '', 00336 'listfile': 'Name of disk file to write output: \'\'==>to terminal', 00337 00338 'async': 'If true the taskname must be started using listobs(...)' 00339 } 00340 00341 # 00342 # Set subfields defaults if needed 00343 # 00344 00345 if(desc.has_key(key)) : 00346 return desc[key] 00347 00348 def itsdefault(self, paramname) : 00349 a = {} 00350 a['vis'] = '' 00351 a['selectdata'] = True 00352 a['spw'] = '' 00353 a['field'] = '' 00354 a['antenna'] = '' 00355 a['uvrange'] = '' 00356 a['timerange'] = '' 00357 a['correlation'] = '' 00358 a['scan'] = '' 00359 a['intent'] = '' 00360 a['feed'] = '' 00361 a['array'] = '' 00362 a['observation'] = '' 00363 a['verbose'] = True 00364 a['listfile'] = '' 00365 00366 if a.has_key(paramname) : 00367 return a[paramname] 00368 listobs_pg = listobs_pg_()