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_clearcal import clearcal 00016 from task_clearcal import casalog 00017 00018 class clearcal_pg_: 00019 __name__ = "clearcal" 00020 00021 def __init__(self) : 00022 self.__bases__ = (clearcal_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, field=None, spw=None, intent=None, addmodel=None, async=None): 00027 00028 """Re-initializes the calibration for a visibility data set 00029 00030 Clearcal reinitializes the calibration columns in a measurement set. 00031 Specificially, it will set the MODEL_DATA column to unity in total intensity 00032 and zero in polarization, and it will set the CORRECTED_DATA column to the original 00033 (observed) DATA in the DATA column. Use the field and spw parameters to select 00034 which data to initialize. If the dataset does not yet have the scratch 00035 columns, they will be created and initilized for the whole dataset (field and spw 00036 ill be ignored). 00037 00038 Keyword arguments: 00039 vis -- Name of input visibility file 00040 default: none; example: vis='ngc5921.ms' 00041 00042 field -- Select field using field id(s) or field name(s). 00043 [run listobs to obtain the list id's or names] 00044 default: ''=all fields 00045 If field string is a non-negative integer, it is assumed a field index 00046 otherwise, it is assumed a field name 00047 field='0~2'; field ids 0,1,2 00048 field='0,4,5~7'; field ids 0,4,5,6,7 00049 field='3C286,3C295'; field named 3C286 adn 3C295 00050 field = '3,4C*'; field id 3, all names starting with 4C 00051 spw -- Select spectral window 00052 default: ''=all spectral windows and channels 00053 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 00054 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00055 spw='0:5~61'; spw 0, channels 5 to 61 00056 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, channels 3 to 45. 00057 spw='0~2:2:6'; spw 0,1,2 with channels 2 through 6 in each. 00058 NB: Multiple channel ranges per spw are not supported in clearcal. 00059 intent -- Select observing intent 00060 default: '' (no selection by intent) 00061 intent='*BANDPASS*' (selects data labelled with 00062 BANDPASS intent) 00063 addmodel -- add MODEL_DATA along with CORRECTED_DATA if True; 00064 otherwise it will add/reset only CORRECTED_DATA, model visibilities 00065 will then be evaluated when needed. 00066 00067 00068 """ 00069 a=inspect.stack() 00070 stacklevel=0 00071 for k in range(len(a)): 00072 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00073 stacklevel=k 00074 break 00075 myf=sys._getframe(stacklevel).f_globals 00076 myf['__last_task'] = 'clearcal' 00077 myf['taskname'] = 'clearcal' 00078 ### 00079 myf['update_params'](func=myf['taskname'],printtext=False) 00080 ### 00081 ### 00082 #Handle globals or user over-ride of arguments 00083 # 00084 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00085 useLocalDefaults = False 00086 00087 for item in function_signature_defaults.iteritems(): 00088 key,val = item 00089 keyVal = eval(key) 00090 if (keyVal == None): 00091 #user hasn't set it - use global/default 00092 pass 00093 else: 00094 #user has set it - use over-ride 00095 if (key != 'self') : 00096 useLocalDefaults = True 00097 #myf[key]=keyVal 00098 00099 myparams = {} 00100 if useLocalDefaults : 00101 for item in function_signature_defaults.iteritems(): 00102 key,val = item 00103 keyVal = eval(key) 00104 exec('myparams[key] = keyVal') 00105 if (keyVal == None): 00106 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00107 keyVal = eval(key) 00108 if(type(keyVal) == dict) : 00109 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00110 00111 else : 00112 uselessvariable = None 00113 myparams['vis'] = vis = myf['vis'] 00114 myparams['field'] = field = myf['field'] 00115 myparams['spw'] = spw = myf['spw'] 00116 myparams['intent'] = intent = myf['intent'] 00117 myparams['addmodel'] = addmodel = myf['addmodel'] 00118 00119 00120 result = None 00121 00122 # 00123 # The following is work around to avoid a bug with current python translation 00124 # 00125 mytmp = {} 00126 00127 mytmp['vis'] = vis 00128 mytmp['field'] = field 00129 mytmp['spw'] = spw 00130 mytmp['intent'] = intent 00131 mytmp['addmodel'] = addmodel 00132 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00133 trec = casac.utils().torecord(pathname+'clearcal.xml') 00134 00135 casalog.origin('clearcal') 00136 if not trec.has_key('clearcal') or not casac.utils().verify(mytmp, trec['clearcal']) : 00137 return False 00138 00139 00140 try : 00141 casalog.post('') 00142 casalog.post('##########################################') 00143 casalog.post('##### Begin Task: clearcal #####') 00144 casalog.post('') 00145 result = clearcal(vis, field, spw, intent, addmodel) 00146 casalog.post('') 00147 casalog.post('##### End Task: clearcal #####') 00148 casalog.post('##########################################') 00149 00150 00151 # saveinputs for individule engine has no use 00152 # saveinputs should alos be removed from casa_in_py.py 00153 # 00154 # 00155 # saveinputs = myf['saveinputs'] 00156 # saveinputs('clearcal', 'clearcal.last', myparams) 00157 # 00158 # 00159 except Exception, instance: 00160 #print '**** Error **** ',instance 00161 pass 00162 00163 gc.collect() 00164 return result 00165 # 00166 # 00167 ## 00168 # def paramgui(self, useGlobals=True): 00169 # """ 00170 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00171 # """ 00172 # import paramgui 00173 # 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 # 00182 # if useGlobals: 00183 # paramgui.setGlobals(myf) 00184 # else: 00185 # paramgui.setGlobals({}) 00186 # 00187 # paramgui.runTask('clearcal', myf['_ip']) 00188 # paramgui.setGlobals({}) 00189 # 00190 # 00191 # 00192 # 00193 def defaults(self, param=None): 00194 a=inspect.stack() 00195 stacklevel=0 00196 for k in range(len(a)): 00197 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00198 stacklevel=k 00199 break 00200 myf=sys._getframe(stacklevel).f_globals 00201 a = odict() 00202 a['vis'] = '' 00203 a['field'] = '' 00204 a['spw'] = '' 00205 a['intent'] = '' 00206 a['addmodel'] = True 00207 00208 a['async']=False 00209 00210 ### This function sets the default values but also will return the list of 00211 ### parameters or the default value of a given parameter 00212 if(param == None): 00213 myf['__set_default_parameters'](a) 00214 elif(param == 'paramkeys'): 00215 return a.keys() 00216 else: 00217 if(a.has_key(param)): 00218 #if(type(a[param]) == dict) : 00219 # return a[param][len(a[param])-1]['value'] 00220 #else : 00221 return a[param] 00222 00223 00224 # 00225 # 00226 def check_params(self, param=None, value=None): 00227 a=inspect.stack() 00228 stacklevel=0 00229 for k in range(len(a)): 00230 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00231 stacklevel=k 00232 break 00233 myf=sys._getframe(stacklevel).f_globals 00234 00235 # print 'param:', param, 'value:', value 00236 try : 00237 if str(type(value)) != "<type 'instance'>" : 00238 value0 = value 00239 value = myf['cu'].expandparam(param, value) 00240 matchtype = False 00241 if(type(value) == numpy.ndarray): 00242 if(type(value) == type(value0)): 00243 myf[param] = value.tolist() 00244 else: 00245 #print 'value:', value, 'value0:', value0 00246 #print 'type(value):', type(value), 'type(value0):', type(value0) 00247 myf[param] = value0 00248 if type(value0) != list : 00249 matchtype = True 00250 else : 00251 myf[param] = value 00252 value = myf['cu'].verifyparam({param:value}) 00253 if matchtype: 00254 value = False 00255 except Exception, instance: 00256 #ignore the exception and just return it unchecked 00257 myf[param] = value 00258 return value 00259 00260 # 00261 # 00262 def description(self, key='clearcal', subkey=None): 00263 desc={'clearcal': 'Re-initializes the calibration for a visibility data set', 00264 'vis': 'Name of input visibility file (MS)', 00265 'field': 'Select field using field id(s) or field name(s)', 00266 'spw': 'Select spectral window/channel.', 00267 'intent': 'Select observing intent', 00268 'addmodel': 'Add MODEL_DATA scratch column', 00269 00270 'async': 'If true the taskname must be started using clearcal(...)' 00271 } 00272 00273 if(desc.has_key(key)) : 00274 return desc[key] 00275 00276 def itsdefault(self, paramname) : 00277 a = {} 00278 a['vis'] = '' 00279 a['field'] = '' 00280 a['spw'] = '' 00281 a['intent'] = '' 00282 a['addmodel'] = True 00283 00284 if a.has_key(paramname) : 00285 return a[paramname] 00286 clearcal_pg = clearcal_pg_()