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_fixplanets import fixplanets 00016 from task_fixplanets import casalog 00017 00018 class fixplanets_pg_: 00019 __name__ = "fixplanets" 00020 00021 def __init__(self) : 00022 self.__bases__ = (fixplanets_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, field=None, fixuvw=None, direction=None, refant=None, reftime=None, async=None): 00027 00028 """Changes FIELD and SOURCE table entries based on user given direction or POINTING table, optionally fixes the UVW coordinates 00029 This task's main purpose is to correct observations which were performed 00030 with correct pointing and correlation but for which incorrect direction 00031 information was entered in the FIELD and SOURCE table of the MS. 00032 If you actually want to change the phase center of the visibilties in an MS, 00033 you should use task fixvis. 00034 00035 Input Parameters 00036 vis -- Name of the input visibility set 00037 00038 field -- field selection string 00039 00040 fixuvw -- recalc uvw coordinates? (default: False) 00041 00042 direction -- if set, don't use pointing table but set direction to this value 00043 default= '' (use pointing table) 00044 example: 'J2000 19h30m00 -40d00m00' 00045 00046 refant -- if using pointing table information, use it from this antenna 00047 default: 0 (antenna id 0) 00048 examples: 'DV06' (antenna with name DV06) 00049 3 (antenna id 3) 00050 reftime -- if using pointing table information, use it from this timestamp 00051 default: 'first' 00052 examples: 'median' will use the median timestamp for the given field 00053 using only the unflagged maintable rows 00054 '2012/07/11/08:41:32' will use the given timestamp (must be 00055 within the observaton time) 00056 00057 Examples: 00058 00059 fixplanets('uid___A002_X1c6e54_X223.ms', 'Titan', True) 00060 will look up the pointing direction from antenna 0 for field 'Titan' in 00061 the POINTING table based on the first timestamp in the main table rows for 00062 this field, enter this direction in the FIELD and SOURCE tables, and then 00063 recalculate the UVW coordinates for this field. 00064 00065 fixplanets('uid___A002_X1c6e54_X223.ms', 'Titan', False, 'J2000 12h30m15 -02d12m00') 00066 will set the directions for field 'Titan' in the FIELD and SOURCE table to the 00067 given direction and not recalculate the UVW coordinates. 00068 (This can be useful for several purposes, among them preparing a concatenation 00069 of datasets. Only fields with the same direction will be recognised as identical. 00070 fixplanets can then be run again after the concatenation using parameters as in 00071 the first example above.) 00072 00073 00074 """ 00075 a=inspect.stack() 00076 stacklevel=0 00077 for k in range(len(a)): 00078 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00079 stacklevel=k 00080 break 00081 myf=sys._getframe(stacklevel).f_globals 00082 myf['__last_task'] = 'fixplanets' 00083 myf['taskname'] = 'fixplanets' 00084 ### 00085 myf['update_params'](func=myf['taskname'],printtext=False) 00086 ### 00087 ### 00088 #Handle globals or user over-ride of arguments 00089 # 00090 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00091 useLocalDefaults = False 00092 00093 for item in function_signature_defaults.iteritems(): 00094 key,val = item 00095 keyVal = eval(key) 00096 if (keyVal == None): 00097 #user hasn't set it - use global/default 00098 pass 00099 else: 00100 #user has set it - use over-ride 00101 if (key != 'self') : 00102 useLocalDefaults = True 00103 #myf[key]=keyVal 00104 00105 myparams = {} 00106 if useLocalDefaults : 00107 for item in function_signature_defaults.iteritems(): 00108 key,val = item 00109 keyVal = eval(key) 00110 exec('myparams[key] = keyVal') 00111 if (keyVal == None): 00112 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00113 keyVal = eval(key) 00114 if(type(keyVal) == dict) : 00115 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00116 00117 else : 00118 uselessvariable = None 00119 myparams['vis'] = vis = myf['vis'] 00120 myparams['field'] = field = myf['field'] 00121 myparams['fixuvw'] = fixuvw = myf['fixuvw'] 00122 myparams['direction'] = direction = myf['direction'] 00123 myparams['refant'] = refant = myf['refant'] 00124 myparams['reftime'] = reftime = myf['reftime'] 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['field'] = field 00136 mytmp['fixuvw'] = fixuvw 00137 mytmp['direction'] = direction 00138 mytmp['refant'] = refant 00139 mytmp['reftime'] = reftime 00140 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00141 trec = casac.utils().torecord(pathname+'fixplanets.xml') 00142 00143 casalog.origin('fixplanets') 00144 if not trec.has_key('fixplanets') or not casac.utils().verify(mytmp, trec['fixplanets']) : 00145 return False 00146 00147 00148 try : 00149 casalog.post('') 00150 casalog.post('##########################################') 00151 casalog.post('##### Begin Task: fixplanets #####') 00152 casalog.post('') 00153 result = fixplanets(vis, field, fixuvw, direction, refant, reftime) 00154 casalog.post('') 00155 casalog.post('##### End Task: fixplanets #####') 00156 casalog.post('##########################################') 00157 00158 00159 # saveinputs for individule engine has no use 00160 # saveinputs should alos be removed from casa_in_py.py 00161 # 00162 # 00163 # saveinputs = myf['saveinputs'] 00164 # saveinputs('fixplanets', 'fixplanets.last', myparams) 00165 # 00166 # 00167 except Exception, instance: 00168 #print '**** Error **** ',instance 00169 pass 00170 00171 gc.collect() 00172 return result 00173 # 00174 # 00175 ## 00176 # def paramgui(self, useGlobals=True): 00177 # """ 00178 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00179 # """ 00180 # import paramgui 00181 # 00182 # a=inspect.stack() 00183 # stacklevel=0 00184 # for k in range(len(a)): 00185 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00186 # stacklevel=k 00187 # break 00188 # myf = sys._getframe(stacklevel).f_globals 00189 # 00190 # if useGlobals: 00191 # paramgui.setGlobals(myf) 00192 # else: 00193 # paramgui.setGlobals({}) 00194 # 00195 # paramgui.runTask('fixplanets', myf['_ip']) 00196 # paramgui.setGlobals({}) 00197 # 00198 # 00199 # 00200 # 00201 def defaults(self, param=None): 00202 a=inspect.stack() 00203 stacklevel=0 00204 for k in range(len(a)): 00205 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00206 stacklevel=k 00207 break 00208 myf=sys._getframe(stacklevel).f_globals 00209 a = odict() 00210 a['vis'] = '' 00211 a['field'] = "" 00212 a['fixuvw'] = False 00213 a['direction'] = '' 00214 a['refant'] = 0 00215 a['reftime'] = 'first' 00216 00217 a['async']=False 00218 00219 ### This function sets the default values but also will return the list of 00220 ### parameters or the default value of a given parameter 00221 if(param == None): 00222 myf['__set_default_parameters'](a) 00223 elif(param == 'paramkeys'): 00224 return a.keys() 00225 else: 00226 if(a.has_key(param)): 00227 #if(type(a[param]) == dict) : 00228 # return a[param][len(a[param])-1]['value'] 00229 #else : 00230 return a[param] 00231 00232 00233 # 00234 # 00235 def check_params(self, param=None, value=None): 00236 a=inspect.stack() 00237 stacklevel=0 00238 for k in range(len(a)): 00239 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00240 stacklevel=k 00241 break 00242 myf=sys._getframe(stacklevel).f_globals 00243 00244 # print 'param:', param, 'value:', value 00245 try : 00246 if str(type(value)) != "<type 'instance'>" : 00247 value0 = value 00248 value = myf['cu'].expandparam(param, value) 00249 matchtype = False 00250 if(type(value) == numpy.ndarray): 00251 if(type(value) == type(value0)): 00252 myf[param] = value.tolist() 00253 else: 00254 #print 'value:', value, 'value0:', value0 00255 #print 'type(value):', type(value), 'type(value0):', type(value0) 00256 myf[param] = value0 00257 if type(value0) != list : 00258 matchtype = True 00259 else : 00260 myf[param] = value 00261 value = myf['cu'].verifyparam({param:value}) 00262 if matchtype: 00263 value = False 00264 except Exception, instance: 00265 #ignore the exception and just return it unchecked 00266 myf[param] = value 00267 return value 00268 00269 # 00270 # 00271 def description(self, key='fixplanets', subkey=None): 00272 desc={'fixplanets': 'Changes FIELD and SOURCE table entries based on user given direction or POINTING table, optionally fixes the UVW coordinates', 00273 'vis': 'Name of the input visibility set.', 00274 'field': 'Fields to operate on. Blank = all.', 00275 'fixuvw': 'recalc uvw?', 00276 'direction': 'if set, don\'t use pointing table but set direction to this value', 00277 'refant': 'if using pointing table information, use it from this antenna', 00278 'reftime': 'if using pointing table information, use it from this timestamp (\'first\', \'median\', or YYYY/MM/DD/hh:mm:ss)', 00279 00280 'async': 'If true the taskname must be started using fixplanets(...)' 00281 } 00282 00283 if(desc.has_key(key)) : 00284 return desc[key] 00285 00286 def itsdefault(self, paramname) : 00287 a = {} 00288 a['vis'] = '' 00289 a['field'] = "" 00290 a['fixuvw'] = False 00291 a['direction'] = '' 00292 a['refant'] = 0 00293 a['reftime'] = 'first' 00294 00295 if a.has_key(paramname) : 00296 return a[paramname] 00297 fixplanets_pg = fixplanets_pg_()