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