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_sdlist import sdlist 00016 from task_sdlist import casalog 00017 00018 class sdlist_pg_: 00019 __name__ = "sdlist" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdlist_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infile=None, antenna=None, scanaverage=None, outfile=None, overwrite=None, async=None): 00027 00028 """ASAP SD task: list summary of single dish data 00029 Keyword arguments: 00030 infile -- name of input SD dataset 00031 antenna -- antenna name or id (only effective for MS input). 00032 scanaverage -- average integrations within scans 00033 options: (bool) True,False 00034 default: False 00035 example: if True, this happens in read-in 00036 For GBT, set False! 00037 outfile -- Name of output file for summary list 00038 default: '' (no output file) 00039 example: 'mysd_summary.txt' 00040 overwrite -- overwrite the output file if already exists 00041 options: (bool) True,False 00042 default: False 00043 00044 00045 DESCRIPTION: 00046 00047 Task sdlist lists the scan summary of the dataset after importing 00048 as a scantable into ASAP. It will optionally output this summary 00049 as file. 00050 00051 Note that if your PAGER environment variable is set to 'less' and 00052 you have set the 'verbose' ASAP environment variable to True 00053 (the default), then the screen version of the summary will page. 00054 You can disable this for sdlist by setting 00055 sd.rcParams['verbose']=False 00056 before running sdlist. Set it back afterwards if you want lots 00057 of information. 00058 00059 WARNING for the GBT raw SDFITS format data as input: 00060 SDtasks are able to handle GBT raw SDFITS format data since the 00061 data filler is available. However, the functionality is not well 00062 tested yet, so that there may be unknown bugs. 00063 00064 00065 """ 00066 a=inspect.stack() 00067 stacklevel=0 00068 for k in range(len(a)): 00069 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00070 stacklevel=k 00071 break 00072 myf=sys._getframe(stacklevel).f_globals 00073 myf['__last_task'] = 'sdlist' 00074 myf['taskname'] = 'sdlist' 00075 ### 00076 myf['update_params'](func=myf['taskname'],printtext=False) 00077 ### 00078 ### 00079 #Handle globals or user over-ride of arguments 00080 # 00081 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00082 useLocalDefaults = False 00083 00084 for item in function_signature_defaults.iteritems(): 00085 key,val = item 00086 keyVal = eval(key) 00087 if (keyVal == None): 00088 #user hasn't set it - use global/default 00089 pass 00090 else: 00091 #user has set it - use over-ride 00092 if (key != 'self') : 00093 useLocalDefaults = True 00094 #myf[key]=keyVal 00095 00096 myparams = {} 00097 if useLocalDefaults : 00098 for item in function_signature_defaults.iteritems(): 00099 key,val = item 00100 keyVal = eval(key) 00101 exec('myparams[key] = keyVal') 00102 if (keyVal == None): 00103 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00104 keyVal = eval(key) 00105 if(type(keyVal) == dict) : 00106 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00107 00108 else : 00109 uselessvariable = None 00110 myparams['infile'] = infile = myf['infile'] 00111 myparams['antenna'] = antenna = myf['antenna'] 00112 myparams['scanaverage'] = scanaverage = myf['scanaverage'] 00113 myparams['outfile'] = outfile = myf['outfile'] 00114 myparams['overwrite'] = overwrite = myf['overwrite'] 00115 00116 00117 result = None 00118 00119 # 00120 # The following is work around to avoid a bug with current python translation 00121 # 00122 mytmp = {} 00123 00124 mytmp['infile'] = infile 00125 mytmp['antenna'] = antenna 00126 mytmp['scanaverage'] = scanaverage 00127 mytmp['outfile'] = outfile 00128 mytmp['overwrite'] = overwrite 00129 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00130 trec = casac.utils().torecord(pathname+'sdlist.xml') 00131 00132 casalog.origin('sdlist') 00133 if not trec.has_key('sdlist') or not casac.utils().verify(mytmp, trec['sdlist']) : 00134 return False 00135 00136 00137 try : 00138 casalog.post('') 00139 casalog.post('##########################################') 00140 casalog.post('##### Begin Task: sdlist #####') 00141 casalog.post('') 00142 result = sdlist(infile, antenna, scanaverage, outfile, overwrite) 00143 casalog.post('') 00144 casalog.post('##### End Task: sdlist #####') 00145 casalog.post('##########################################') 00146 00147 00148 # saveinputs for individule engine has no use 00149 # saveinputs should alos be removed from casa_in_py.py 00150 # 00151 # 00152 # saveinputs = myf['saveinputs'] 00153 # saveinputs('sdlist', 'sdlist.last', myparams) 00154 # 00155 # 00156 except Exception, instance: 00157 #print '**** Error **** ',instance 00158 pass 00159 00160 gc.collect() 00161 return result 00162 # 00163 # 00164 ## 00165 # def paramgui(self, useGlobals=True): 00166 # """ 00167 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00168 # """ 00169 # import paramgui 00170 # 00171 # a=inspect.stack() 00172 # stacklevel=0 00173 # for k in range(len(a)): 00174 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00175 # stacklevel=k 00176 # break 00177 # myf = sys._getframe(stacklevel).f_globals 00178 # 00179 # if useGlobals: 00180 # paramgui.setGlobals(myf) 00181 # else: 00182 # paramgui.setGlobals({}) 00183 # 00184 # paramgui.runTask('sdlist', myf['_ip']) 00185 # paramgui.setGlobals({}) 00186 # 00187 # 00188 # 00189 # 00190 def defaults(self, param=None): 00191 a=inspect.stack() 00192 stacklevel=0 00193 for k in range(len(a)): 00194 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00195 stacklevel=k 00196 break 00197 myf=sys._getframe(stacklevel).f_globals 00198 a = odict() 00199 a['infile'] = '' 00200 a['antenna'] = 0 00201 a['scanaverage'] = False 00202 a['outfile'] = '' 00203 a['overwrite'] = False 00204 00205 a['async']=False 00206 00207 ### This function sets the default values but also will return the list of 00208 ### parameters or the default value of a given parameter 00209 if(param == None): 00210 myf['__set_default_parameters'](a) 00211 elif(param == 'paramkeys'): 00212 return a.keys() 00213 else: 00214 if(a.has_key(param)): 00215 #if(type(a[param]) == dict) : 00216 # return a[param][len(a[param])-1]['value'] 00217 #else : 00218 return a[param] 00219 00220 00221 # 00222 # 00223 def check_params(self, param=None, value=None): 00224 a=inspect.stack() 00225 stacklevel=0 00226 for k in range(len(a)): 00227 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00228 stacklevel=k 00229 break 00230 myf=sys._getframe(stacklevel).f_globals 00231 00232 # print 'param:', param, 'value:', value 00233 try : 00234 if str(type(value)) != "<type 'instance'>" : 00235 value0 = value 00236 value = myf['cu'].expandparam(param, value) 00237 matchtype = False 00238 if(type(value) == numpy.ndarray): 00239 if(type(value) == type(value0)): 00240 myf[param] = value.tolist() 00241 else: 00242 #print 'value:', value, 'value0:', value0 00243 #print 'type(value):', type(value), 'type(value0):', type(value0) 00244 myf[param] = value0 00245 if type(value0) != list : 00246 matchtype = True 00247 else : 00248 myf[param] = value 00249 value = myf['cu'].verifyparam({param:value}) 00250 if matchtype: 00251 value = False 00252 except Exception, instance: 00253 #ignore the exception and just return it unchecked 00254 myf[param] = value 00255 return value 00256 00257 # 00258 # 00259 def description(self, key='sdlist', subkey=None): 00260 desc={'sdlist': 'ASAP SD task: list summary of single dish data', 00261 'infile': 'name of input SD dataset', 00262 'antenna': 'antenna name or id (only effective for MS input)', 00263 'scanaverage': 'average integs within scans (True,False) ', 00264 'outfile': 'Name of output file for summary list', 00265 'overwrite': 'overwrite the output file if already exists', 00266 00267 'async': 'If true the taskname must be started using sdlist(...)' 00268 } 00269 00270 if(desc.has_key(key)) : 00271 return desc[key] 00272 00273 def itsdefault(self, paramname) : 00274 a = {} 00275 a['infile'] = '' 00276 a['antenna'] = 0 00277 a['scanaverage'] = False 00278 a['outfile'] = '' 00279 a['overwrite'] = False 00280 00281 if a.has_key(paramname) : 00282 return a[paramname] 00283 sdlist_pg = sdlist_pg_()