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_fixvis import fixvis 00016 from task_fixvis import casalog 00017 00018 class fixvis_pg_: 00019 __name__ = "fixvis" 00020 00021 def __init__(self) : 00022 self.__bases__ = (fixvis_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, outputvis=None, field=None, refcode=None, reuse=None, phasecenter=None, datacolumn=None, async=None): 00027 00028 """Recalculates (u, v, w) and/or changes Phase Center 00029 00030 If the phase center is changed, the corresponding modifications are applied to the 00031 visibility columns given by the parameter "datacolumn" which is by default set 00032 to "all" (DATA, CORRECTED, and MODEL). 00033 00034 Input Parameters 00035 vis -- Name of the input visibility set 00036 00037 outputvis -- Name of the output visibility set, default: same as vis 00038 00039 field -- field selection string 00040 00041 refcode -- Reference frame to convert to, default: the refcode of PHASE_DIR in the 00042 FIELD table 00043 example: 'B1950' 00044 00045 reuse -- base recalculation on existing UVW coordinates? default=True 00046 ignored if parameter 'phasecenter' is set 00047 00048 phasecenter -- if set to a valid direction: change the phase center for the given 00049 field to this value 00050 example: 'J2000 9h25m00s -05d12m00s' 00051 If given without the equinox, e.g. '0h01m00s +00d12m00s', the parameter 00052 is interpreted as a pair of offsets in RA and DEC to the present 00053 phasecenter. The RA offset can be given in units of time or angle. If given 00054 as a time, it is applied as is. If given as an angle, it is corrected for 00055 the cos(DEC) before it is applied. 00056 00057 datacolumn -- when applying a phase center shift, modify visibilities only in 00058 this/these column(s) 00059 default: 'all' (DATA, CORRECTED, and MODEL) 00060 example: 'DATA,CORRECTED' (will not modify MODEL) 00061 00062 Examples: 00063 00064 fixvis('NGC3256.ms','NGC3256-fixed.ms') 00065 will recalculate the UVW coordinates for all fields based on the existing 00066 phase center information in the FIELD table. 00067 00068 fixvis('Moon.ms','Moon-fixed.ms','Moon', '', 'J2000 9h25m00s 05d12m00s') 00069 will set the phase center for field 'Moon' to the given direction and recalculate 00070 the UVW coordinates. 00071 00072 00073 """ 00074 a=inspect.stack() 00075 stacklevel=0 00076 for k in range(len(a)): 00077 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00078 stacklevel=k 00079 break 00080 myf=sys._getframe(stacklevel).f_globals 00081 myf['__last_task'] = 'fixvis' 00082 myf['taskname'] = 'fixvis' 00083 ### 00084 myf['update_params'](func=myf['taskname'],printtext=False) 00085 ### 00086 ### 00087 #Handle globals or user over-ride of arguments 00088 # 00089 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00090 useLocalDefaults = False 00091 00092 for item in function_signature_defaults.iteritems(): 00093 key,val = item 00094 keyVal = eval(key) 00095 if (keyVal == None): 00096 #user hasn't set it - use global/default 00097 pass 00098 else: 00099 #user has set it - use over-ride 00100 if (key != 'self') : 00101 useLocalDefaults = True 00102 #myf[key]=keyVal 00103 00104 myparams = {} 00105 if useLocalDefaults : 00106 for item in function_signature_defaults.iteritems(): 00107 key,val = item 00108 keyVal = eval(key) 00109 exec('myparams[key] = keyVal') 00110 if (keyVal == None): 00111 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00112 keyVal = eval(key) 00113 if(type(keyVal) == dict) : 00114 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00115 00116 else : 00117 uselessvariable = None 00118 myparams['vis'] = vis = myf['vis'] 00119 myparams['outputvis'] = outputvis = myf['outputvis'] 00120 myparams['field'] = field = myf['field'] 00121 myparams['refcode'] = refcode = myf['refcode'] 00122 myparams['reuse'] = reuse = myf['reuse'] 00123 myparams['phasecenter'] = phasecenter = myf['phasecenter'] 00124 myparams['datacolumn'] = datacolumn = myf['datacolumn'] 00125 00126 00127 result = None 00128 00129 # 00130 # The following is work around to avoid a bug with current python translation 00131 # 00132 mytmp = {} 00133 00134 mytmp['vis'] = vis 00135 mytmp['outputvis'] = outputvis 00136 mytmp['field'] = field 00137 mytmp['refcode'] = refcode 00138 mytmp['reuse'] = reuse 00139 mytmp['phasecenter'] = phasecenter 00140 mytmp['datacolumn'] = datacolumn 00141 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00142 trec = casac.utils().torecord(pathname+'fixvis.xml') 00143 00144 casalog.origin('fixvis') 00145 if not trec.has_key('fixvis') or not casac.utils().verify(mytmp, trec['fixvis']) : 00146 return False 00147 00148 00149 try : 00150 casalog.post('') 00151 casalog.post('##########################################') 00152 casalog.post('##### Begin Task: fixvis #####') 00153 casalog.post('') 00154 result = fixvis(vis, outputvis, field, refcode, reuse, phasecenter, datacolumn) 00155 casalog.post('') 00156 casalog.post('##### End Task: fixvis #####') 00157 casalog.post('##########################################') 00158 00159 00160 # saveinputs for individule engine has no use 00161 # saveinputs should alos be removed from casa_in_py.py 00162 # 00163 # 00164 # saveinputs = myf['saveinputs'] 00165 # saveinputs('fixvis', 'fixvis.last', myparams) 00166 # 00167 # 00168 except Exception, instance: 00169 #print '**** Error **** ',instance 00170 pass 00171 00172 gc.collect() 00173 return result 00174 # 00175 # 00176 ## 00177 # def paramgui(self, useGlobals=True): 00178 # """ 00179 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00180 # """ 00181 # import paramgui 00182 # 00183 # a=inspect.stack() 00184 # stacklevel=0 00185 # for k in range(len(a)): 00186 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00187 # stacklevel=k 00188 # break 00189 # myf = sys._getframe(stacklevel).f_globals 00190 # 00191 # if useGlobals: 00192 # paramgui.setGlobals(myf) 00193 # else: 00194 # paramgui.setGlobals({}) 00195 # 00196 # paramgui.runTask('fixvis', myf['_ip']) 00197 # paramgui.setGlobals({}) 00198 # 00199 # 00200 # 00201 # 00202 def defaults(self, param=None): 00203 a=inspect.stack() 00204 stacklevel=0 00205 for k in range(len(a)): 00206 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00207 stacklevel=k 00208 break 00209 myf=sys._getframe(stacklevel).f_globals 00210 a = odict() 00211 a['vis'] = '' 00212 a['outputvis'] = '' 00213 a['field'] = "" 00214 a['refcode'] = '' 00215 a['reuse'] = True 00216 a['phasecenter'] = '' 00217 a['datacolumn'] = 'all' 00218 00219 a['async']=False 00220 00221 ### This function sets the default values but also will return the list of 00222 ### parameters or the default value of a given parameter 00223 if(param == None): 00224 myf['__set_default_parameters'](a) 00225 elif(param == 'paramkeys'): 00226 return a.keys() 00227 else: 00228 if(a.has_key(param)): 00229 #if(type(a[param]) == dict) : 00230 # return a[param][len(a[param])-1]['value'] 00231 #else : 00232 return a[param] 00233 00234 00235 # 00236 # 00237 def check_params(self, param=None, value=None): 00238 a=inspect.stack() 00239 stacklevel=0 00240 for k in range(len(a)): 00241 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00242 stacklevel=k 00243 break 00244 myf=sys._getframe(stacklevel).f_globals 00245 00246 # print 'param:', param, 'value:', value 00247 try : 00248 if str(type(value)) != "<type 'instance'>" : 00249 value0 = value 00250 value = myf['cu'].expandparam(param, value) 00251 matchtype = False 00252 if(type(value) == numpy.ndarray): 00253 if(type(value) == type(value0)): 00254 myf[param] = value.tolist() 00255 else: 00256 #print 'value:', value, 'value0:', value0 00257 #print 'type(value):', type(value), 'type(value0):', type(value0) 00258 myf[param] = value0 00259 if type(value0) != list : 00260 matchtype = True 00261 else : 00262 myf[param] = value 00263 value = myf['cu'].verifyparam({param:value}) 00264 if matchtype: 00265 value = False 00266 except Exception, instance: 00267 #ignore the exception and just return it unchecked 00268 myf[param] = value 00269 return value 00270 00271 # 00272 # 00273 def description(self, key='fixvis', subkey=None): 00274 desc={'fixvis': 'Recalculates (u, v, w) and/or changes Phase Center ', 00275 'vis': 'Name of the input visibility set.', 00276 'outputvis': 'Name of the output visibility set. (Can be the same as vis.)', 00277 'field': 'Fields to operate on. '' = all.', 00278 'refcode': 'reference frame to convert UVW coordinates to', 00279 'reuse': 'base UVW calculation on the old values?', 00280 'phasecenter': 'use this direction as phase center', 00281 'datacolumn': 'when applying a phase center shift, modify visibilities only in this/these column(s)', 00282 00283 'async': 'If true the taskname must be started using fixvis(...)' 00284 } 00285 00286 if(desc.has_key(key)) : 00287 return desc[key] 00288 00289 def itsdefault(self, paramname) : 00290 a = {} 00291 a['vis'] = '' 00292 a['outputvis'] = '' 00293 a['field'] = "" 00294 a['refcode'] = '' 00295 a['reuse'] = True 00296 a['phasecenter'] = '' 00297 a['datacolumn'] = 'all' 00298 00299 if a.has_key(paramname) : 00300 return a[paramname] 00301 fixvis_pg = fixvis_pg_()