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_listsdm import listsdm 00016 from task_listsdm import casalog 00017 00018 class listsdm_pg_: 00019 __name__ = "listsdm" 00020 00021 def __init__(self) : 00022 self.__bases__ = (listsdm_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, sdm=None, async=None): 00027 00028 """Lists observation information present in an SDM directory. 00029 00030 The listsdm task reads SDM XML tables, processes the 00031 observation information contained therein, and prints this 00032 information to the CASA log. It will also return a dictionary 00033 keyed on scan number. The dictionary contains the following 00034 information: 00035 00036 'baseband' list of baseband name(s) 00037 'chanwidth' list of channel widths (Hz) 00038 'end' observation end time (UTC) 00039 'field' field ID 00040 'intent' scan intent(s) 00041 'nchan' list of number of channels 00042 'nsubs' number of subscans 00043 'reffreq' list of reference frequencies (Hz) 00044 'source' source name 00045 'spws' list of spectral windows 00046 'start' observation start time (UTC) 00047 'timerange' start time - end time range (UTC) 00048 00049 Example: 00050 00051 myscans = listsdm(sdm='AS1039_sb1382796_2_000.55368.51883247685') 00052 00053 Prints information about the requested SDM to the CASA logger 00054 and returns a dictionary with scan information in 'myscans'. 00055 00056 Keyword argument: 00057 00058 sdm -- Name of input SDM directory. 00059 example: sdm='AG836_sb1377811_1.55345.300883159725' 00060 00061 00062 """ 00063 a=inspect.stack() 00064 stacklevel=0 00065 for k in range(len(a)): 00066 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00067 stacklevel=k 00068 break 00069 myf=sys._getframe(stacklevel).f_globals 00070 myf['__last_task'] = 'listsdm' 00071 myf['taskname'] = 'listsdm' 00072 ### 00073 myf['update_params'](func=myf['taskname'],printtext=False) 00074 ### 00075 ### 00076 #Handle globals or user over-ride of arguments 00077 # 00078 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00079 useLocalDefaults = False 00080 00081 for item in function_signature_defaults.iteritems(): 00082 key,val = item 00083 keyVal = eval(key) 00084 if (keyVal == None): 00085 #user hasn't set it - use global/default 00086 pass 00087 else: 00088 #user has set it - use over-ride 00089 if (key != 'self') : 00090 useLocalDefaults = True 00091 #myf[key]=keyVal 00092 00093 myparams = {} 00094 if useLocalDefaults : 00095 for item in function_signature_defaults.iteritems(): 00096 key,val = item 00097 keyVal = eval(key) 00098 exec('myparams[key] = keyVal') 00099 if (keyVal == None): 00100 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00101 keyVal = eval(key) 00102 if(type(keyVal) == dict) : 00103 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00104 00105 else : 00106 uselessvariable = None 00107 myparams['sdm'] = sdm = myf['sdm'] 00108 00109 00110 result = None 00111 00112 # 00113 # The following is work around to avoid a bug with current python translation 00114 # 00115 mytmp = {} 00116 00117 mytmp['sdm'] = sdm 00118 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00119 trec = casac.utils().torecord(pathname+'listsdm.xml') 00120 00121 casalog.origin('listsdm') 00122 if not trec.has_key('listsdm') or not casac.utils().verify(mytmp, trec['listsdm']) : 00123 return False 00124 00125 00126 try : 00127 casalog.post('') 00128 casalog.post('##########################################') 00129 casalog.post('##### Begin Task: listsdm #####') 00130 casalog.post('') 00131 result = listsdm(sdm) 00132 casalog.post('') 00133 casalog.post('##### End Task: listsdm #####') 00134 casalog.post('##########################################') 00135 00136 00137 # saveinputs for individule engine has no use 00138 # saveinputs should alos be removed from casa_in_py.py 00139 # 00140 # 00141 # saveinputs = myf['saveinputs'] 00142 # saveinputs('listsdm', 'listsdm.last', myparams) 00143 # 00144 # 00145 except Exception, instance: 00146 #print '**** Error **** ',instance 00147 pass 00148 00149 gc.collect() 00150 return result 00151 # 00152 # 00153 ## 00154 # def paramgui(self, useGlobals=True): 00155 # """ 00156 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00157 # """ 00158 # import paramgui 00159 # 00160 # a=inspect.stack() 00161 # stacklevel=0 00162 # for k in range(len(a)): 00163 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00164 # stacklevel=k 00165 # break 00166 # myf = sys._getframe(stacklevel).f_globals 00167 # 00168 # if useGlobals: 00169 # paramgui.setGlobals(myf) 00170 # else: 00171 # paramgui.setGlobals({}) 00172 # 00173 # paramgui.runTask('listsdm', myf['_ip']) 00174 # paramgui.setGlobals({}) 00175 # 00176 # 00177 # 00178 # 00179 def defaults(self, param=None): 00180 a=inspect.stack() 00181 stacklevel=0 00182 for k in range(len(a)): 00183 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00184 stacklevel=k 00185 break 00186 myf=sys._getframe(stacklevel).f_globals 00187 a = odict() 00188 a['sdm'] = '' 00189 00190 a['async']=False 00191 00192 ### This function sets the default values but also will return the list of 00193 ### parameters or the default value of a given parameter 00194 if(param == None): 00195 myf['__set_default_parameters'](a) 00196 elif(param == 'paramkeys'): 00197 return a.keys() 00198 else: 00199 if(a.has_key(param)): 00200 #if(type(a[param]) == dict) : 00201 # return a[param][len(a[param])-1]['value'] 00202 #else : 00203 return a[param] 00204 00205 00206 # 00207 # 00208 def check_params(self, param=None, value=None): 00209 a=inspect.stack() 00210 stacklevel=0 00211 for k in range(len(a)): 00212 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00213 stacklevel=k 00214 break 00215 myf=sys._getframe(stacklevel).f_globals 00216 00217 # print 'param:', param, 'value:', value 00218 try : 00219 if str(type(value)) != "<type 'instance'>" : 00220 value0 = value 00221 value = myf['cu'].expandparam(param, value) 00222 matchtype = False 00223 if(type(value) == numpy.ndarray): 00224 if(type(value) == type(value0)): 00225 myf[param] = value.tolist() 00226 else: 00227 #print 'value:', value, 'value0:', value0 00228 #print 'type(value):', type(value), 'type(value0):', type(value0) 00229 myf[param] = value0 00230 if type(value0) != list : 00231 matchtype = True 00232 else : 00233 myf[param] = value 00234 value = myf['cu'].verifyparam({param:value}) 00235 if matchtype: 00236 value = False 00237 except Exception, instance: 00238 #ignore the exception and just return it unchecked 00239 myf[param] = value 00240 return value 00241 00242 # 00243 # 00244 def description(self, key='listsdm', subkey=None): 00245 desc={'listsdm': 'Lists observation information present in an SDM directory.', 00246 'sdm': 'Name of input SDM directory', 00247 00248 'async': 'If true the taskname must be started using listsdm(...)' 00249 } 00250 00251 if(desc.has_key(key)) : 00252 return desc[key] 00253 00254 def itsdefault(self, paramname) : 00255 a = {} 00256 a['sdm'] = '' 00257 00258 if a.has_key(paramname) : 00259 return a[paramname] 00260 listsdm_pg = listsdm_pg_()