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_flagmanager import flagmanager 00016 from task_flagmanager import casalog 00017 00018 class flagmanager_pg_: 00019 __name__ = "flagmanager" 00020 00021 def __init__(self) : 00022 self.__bases__ = (flagmanager_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, mode=None, versionname=None, oldname=None, comment=None, merge=None, async=None): 00027 00028 """Enable list, save, restore, delete and rename flag version files. 00029 00030 00031 These flag version files are copies of the flag column for a 00032 measurement set. They can be restored to the data set to obtain 00033 a previous flag version. On running importvla, a flag 00034 version call 'Original' is automatically produced. It is wise to 00035 save a flagversion at the beginning or after serious editing. 00036 00037 Keyword arguments: 00038 vis -- Name of input visibility file 00039 default: none. example: vis='ngc5921.ms' 00040 mode -- Flag version operation 00041 default: 'list'; to list existing flagtables 00042 'save' will save flag column from vis to a specified flag file 00043 'restore' will place the specified flag file into vis 00044 'delete' will delete specified flag file 00045 'rename' will rename a specified flag file 00046 versionname -- Flag version name 00047 default: none; example: versionname='original_data' 00048 No imbedded blanks in the versionname 00049 comment -- Short description of a versionname, when mode is 'save' or 'rename' 00050 default: ''; example: comment='Clip above 1.85' 00051 comment = versionname 00052 oldname -- When mode='rename', the flag file to rename 00053 merge -- Merge operation 00054 Options: 'or','and', but not recommended for now. 00055 00056 00057 """ 00058 a=inspect.stack() 00059 stacklevel=0 00060 for k in range(len(a)): 00061 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00062 stacklevel=k 00063 break 00064 myf=sys._getframe(stacklevel).f_globals 00065 myf['__last_task'] = 'flagmanager' 00066 myf['taskname'] = 'flagmanager' 00067 ### 00068 myf['update_params'](func=myf['taskname'],printtext=False) 00069 ### 00070 ### 00071 #Handle globals or user over-ride of arguments 00072 # 00073 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00074 useLocalDefaults = False 00075 00076 for item in function_signature_defaults.iteritems(): 00077 key,val = item 00078 keyVal = eval(key) 00079 if (keyVal == None): 00080 #user hasn't set it - use global/default 00081 pass 00082 else: 00083 #user has set it - use over-ride 00084 if (key != 'self') : 00085 useLocalDefaults = True 00086 #myf[key]=keyVal 00087 00088 myparams = {} 00089 if useLocalDefaults : 00090 for item in function_signature_defaults.iteritems(): 00091 key,val = item 00092 keyVal = eval(key) 00093 exec('myparams[key] = keyVal') 00094 if (keyVal == None): 00095 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00096 keyVal = eval(key) 00097 if(type(keyVal) == dict) : 00098 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00099 00100 else : 00101 uselessvariable = None 00102 myparams['vis'] = vis = myf['vis'] 00103 myparams['mode'] = mode = myf['mode'] 00104 myparams['versionname'] = versionname = myf['versionname'] 00105 myparams['oldname'] = oldname = myf['oldname'] 00106 myparams['comment'] = comment = myf['comment'] 00107 myparams['merge'] = merge = myf['merge'] 00108 00109 00110 result = None 00111 00112 # 00113 # The following is work around to avoid a bug with current python translation 00114 # 00115 mytmp = {} 00116 00117 mytmp['vis'] = vis 00118 mytmp['mode'] = mode 00119 mytmp['versionname'] = versionname 00120 mytmp['oldname'] = oldname 00121 mytmp['comment'] = comment 00122 mytmp['merge'] = merge 00123 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00124 trec = casac.utils().torecord(pathname+'flagmanager.xml') 00125 00126 casalog.origin('flagmanager') 00127 if not trec.has_key('flagmanager') or not casac.utils().verify(mytmp, trec['flagmanager']) : 00128 return False 00129 00130 00131 try : 00132 casalog.post('') 00133 casalog.post('##########################################') 00134 casalog.post('##### Begin Task: flagmanager #####') 00135 casalog.post('') 00136 result = flagmanager(vis, mode, versionname, oldname, comment, merge) 00137 casalog.post('') 00138 casalog.post('##### End Task: flagmanager #####') 00139 casalog.post('##########################################') 00140 00141 00142 # saveinputs for individule engine has no use 00143 # saveinputs should alos be removed from casa_in_py.py 00144 # 00145 # 00146 # saveinputs = myf['saveinputs'] 00147 # saveinputs('flagmanager', 'flagmanager.last', myparams) 00148 # 00149 # 00150 except Exception, instance: 00151 #print '**** Error **** ',instance 00152 pass 00153 00154 gc.collect() 00155 return result 00156 # 00157 # 00158 ## 00159 # def paramgui(self, useGlobals=True): 00160 # """ 00161 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00162 # """ 00163 # import paramgui 00164 # 00165 # a=inspect.stack() 00166 # stacklevel=0 00167 # for k in range(len(a)): 00168 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00169 # stacklevel=k 00170 # break 00171 # myf = sys._getframe(stacklevel).f_globals 00172 # 00173 # if useGlobals: 00174 # paramgui.setGlobals(myf) 00175 # else: 00176 # paramgui.setGlobals({}) 00177 # 00178 # paramgui.runTask('flagmanager', myf['_ip']) 00179 # paramgui.setGlobals({}) 00180 # 00181 # 00182 # 00183 # 00184 def defaults(self, param=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 a = odict() 00193 a['vis'] = '' 00194 a['mode'] = 'list' 00195 00196 a['async']=False 00197 a['mode'] = { 00198 0:{'value':'list'}, 00199 1:odict([{'value':'save'}, {'versionname':''}, {'comment':''}, {'merge':'replace'}]), 00200 2:odict([{'value':'restore'}, {'versionname':''}, {'merge':'replace'}]), 00201 3:odict([{'value':'delete'}, {'versionname':''}]), 00202 4:odict([{'value':'rename'}, {'oldname':''}, {'versionname':''}, {'comment':''}])} 00203 00204 ### This function sets the default values but also will return the list of 00205 ### parameters or the default value of a given parameter 00206 if(param == None): 00207 myf['__set_default_parameters'](a) 00208 elif(param == 'paramkeys'): 00209 return a.keys() 00210 else: 00211 if(a.has_key(param)): 00212 #if(type(a[param]) == dict) : 00213 # return a[param][len(a[param])-1]['value'] 00214 #else : 00215 return a[param] 00216 00217 00218 # 00219 # 00220 def check_params(self, param=None, value=None): 00221 a=inspect.stack() 00222 stacklevel=0 00223 for k in range(len(a)): 00224 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00225 stacklevel=k 00226 break 00227 myf=sys._getframe(stacklevel).f_globals 00228 00229 # print 'param:', param, 'value:', value 00230 try : 00231 if str(type(value)) != "<type 'instance'>" : 00232 value0 = value 00233 value = myf['cu'].expandparam(param, value) 00234 matchtype = False 00235 if(type(value) == numpy.ndarray): 00236 if(type(value) == type(value0)): 00237 myf[param] = value.tolist() 00238 else: 00239 #print 'value:', value, 'value0:', value0 00240 #print 'type(value):', type(value), 'type(value0):', type(value0) 00241 myf[param] = value0 00242 if type(value0) != list : 00243 matchtype = True 00244 else : 00245 myf[param] = value 00246 value = myf['cu'].verifyparam({param:value}) 00247 if matchtype: 00248 value = False 00249 except Exception, instance: 00250 #ignore the exception and just return it unchecked 00251 myf[param] = value 00252 return value 00253 00254 # 00255 # 00256 def description(self, key='flagmanager', subkey=None): 00257 desc={'flagmanager': 'Enable list, save, restore, delete and rename flag version files.', 00258 'vis': 'Name of input visibility file (MS)', 00259 'mode': 'Operation: list, save, restore, delete, rename', 00260 'versionname': 'Flag version name', 00261 'oldname': 'Flag version to rename', 00262 'comment': 'Short description of a versionname', 00263 'merge': 'Merge option: replace will save or over-write the flags', 00264 00265 'async': 'If true the taskname must be started using flagmanager(...)' 00266 } 00267 00268 # 00269 # Set subfields defaults if needed 00270 # 00271 00272 if(desc.has_key(key)) : 00273 return desc[key] 00274 00275 def itsdefault(self, paramname) : 00276 a = {} 00277 a['vis'] = '' 00278 a['mode'] = 'list' 00279 a['versionname'] = '' 00280 a['oldname'] = '' 00281 a['comment'] = '' 00282 a['merge'] = 'replace' 00283 00284 if a.has_key(paramname) : 00285 return a[paramname] 00286 flagmanager_pg = flagmanager_pg_()