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