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_listfits import listfits 00016 from task_listfits import casalog 00017 00018 class listfits_pg_: 00019 __name__ = "listfits" 00020 00021 def __init__(self) : 00022 self.__bases__ = (listfits_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, fitsfile=None, async=None): 00027 00028 """List the HDU and typical data rows of a fits file: 00029 00030 The HDU and typical data rows in a fits file are listed in the logger. 00031 00032 Keyword arguments: 00033 fitsfile -- Name of input fits file 00034 default: none; example: fitsfile='ngc5921.uvfits' 00035 async -- Run asynchronously 00036 default = False; do not run asychronously 00037 00038 """ 00039 a=inspect.stack() 00040 stacklevel=0 00041 for k in range(len(a)): 00042 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00043 stacklevel=k 00044 break 00045 myf=sys._getframe(stacklevel).f_globals 00046 myf['__last_task'] = 'listfits' 00047 myf['taskname'] = 'listfits' 00048 ### 00049 myf['update_params'](func=myf['taskname'],printtext=False) 00050 ### 00051 ### 00052 #Handle globals or user over-ride of arguments 00053 # 00054 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00055 useLocalDefaults = False 00056 00057 for item in function_signature_defaults.iteritems(): 00058 key,val = item 00059 keyVal = eval(key) 00060 if (keyVal == None): 00061 #user hasn't set it - use global/default 00062 pass 00063 else: 00064 #user has set it - use over-ride 00065 if (key != 'self') : 00066 useLocalDefaults = True 00067 #myf[key]=keyVal 00068 00069 myparams = {} 00070 if useLocalDefaults : 00071 for item in function_signature_defaults.iteritems(): 00072 key,val = item 00073 keyVal = eval(key) 00074 exec('myparams[key] = keyVal') 00075 if (keyVal == None): 00076 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00077 keyVal = eval(key) 00078 if(type(keyVal) == dict) : 00079 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00080 00081 else : 00082 uselessvariable = None 00083 myparams['fitsfile'] = fitsfile = myf['fitsfile'] 00084 00085 00086 result = None 00087 00088 # 00089 # The following is work around to avoid a bug with current python translation 00090 # 00091 mytmp = {} 00092 00093 mytmp['fitsfile'] = fitsfile 00094 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00095 trec = casac.utils().torecord(pathname+'listfits.xml') 00096 00097 casalog.origin('listfits') 00098 if not trec.has_key('listfits') or not casac.utils().verify(mytmp, trec['listfits']) : 00099 return False 00100 00101 00102 try : 00103 casalog.post('') 00104 casalog.post('##########################################') 00105 casalog.post('##### Begin Task: listfits #####') 00106 casalog.post('') 00107 result = listfits(fitsfile) 00108 casalog.post('') 00109 casalog.post('##### End Task: listfits #####') 00110 casalog.post('##########################################') 00111 00112 00113 # saveinputs for individule engine has no use 00114 # saveinputs should alos be removed from casa_in_py.py 00115 # 00116 # 00117 # saveinputs = myf['saveinputs'] 00118 # saveinputs('listfits', 'listfits.last', myparams) 00119 # 00120 # 00121 except Exception, instance: 00122 #print '**** Error **** ',instance 00123 pass 00124 00125 gc.collect() 00126 return result 00127 # 00128 # 00129 ## 00130 # def paramgui(self, useGlobals=True): 00131 # """ 00132 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00133 # """ 00134 # import paramgui 00135 # 00136 # a=inspect.stack() 00137 # stacklevel=0 00138 # for k in range(len(a)): 00139 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00140 # stacklevel=k 00141 # break 00142 # myf = sys._getframe(stacklevel).f_globals 00143 # 00144 # if useGlobals: 00145 # paramgui.setGlobals(myf) 00146 # else: 00147 # paramgui.setGlobals({}) 00148 # 00149 # paramgui.runTask('listfits', myf['_ip']) 00150 # paramgui.setGlobals({}) 00151 # 00152 # 00153 # 00154 # 00155 def defaults(self, param=None): 00156 a=inspect.stack() 00157 stacklevel=0 00158 for k in range(len(a)): 00159 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00160 stacklevel=k 00161 break 00162 myf=sys._getframe(stacklevel).f_globals 00163 a = odict() 00164 a['fitsfile'] = '' 00165 00166 a['async']=False 00167 00168 ### This function sets the default values but also will return the list of 00169 ### parameters or the default value of a given parameter 00170 if(param == None): 00171 myf['__set_default_parameters'](a) 00172 elif(param == 'paramkeys'): 00173 return a.keys() 00174 else: 00175 if(a.has_key(param)): 00176 #if(type(a[param]) == dict) : 00177 # return a[param][len(a[param])-1]['value'] 00178 #else : 00179 return a[param] 00180 00181 00182 # 00183 # 00184 def check_params(self, param=None, value=None): 00185 a=inspect.stack() 00186 stacklevel=0 00187 for k in range(len(a)): 00188 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00189 stacklevel=k 00190 break 00191 myf=sys._getframe(stacklevel).f_globals 00192 00193 # print 'param:', param, 'value:', value 00194 try : 00195 if str(type(value)) != "<type 'instance'>" : 00196 value0 = value 00197 value = myf['cu'].expandparam(param, value) 00198 matchtype = False 00199 if(type(value) == numpy.ndarray): 00200 if(type(value) == type(value0)): 00201 myf[param] = value.tolist() 00202 else: 00203 #print 'value:', value, 'value0:', value0 00204 #print 'type(value):', type(value), 'type(value0):', type(value0) 00205 myf[param] = value0 00206 if type(value0) != list : 00207 matchtype = True 00208 else : 00209 myf[param] = value 00210 value = myf['cu'].verifyparam({param:value}) 00211 if matchtype: 00212 value = False 00213 except Exception, instance: 00214 #ignore the exception and just return it unchecked 00215 myf[param] = value 00216 return value 00217 00218 # 00219 # 00220 def description(self, key='listfits', subkey=None): 00221 desc={'listfits': 'List the HDU and typical data rows of a fits file:', 00222 'fitsfile': 'Name of input fits file', 00223 00224 'async': 'If true the taskname must be started using listfits(...)' 00225 } 00226 00227 if(desc.has_key(key)) : 00228 return desc[key] 00229 00230 def itsdefault(self, paramname) : 00231 a = {} 00232 a['fitsfile'] = '' 00233 00234 if a.has_key(paramname) : 00235 return a[paramname] 00236 listfits_pg = listfits_pg_()