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_ft import ft 00016 from task_ft import casalog 00017 00018 class ft_pg_: 00019 __name__ = "ft" 00020 00021 def __init__(self) : 00022 self.__bases__ = (ft_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, field=None, spw=None, model=None, nterms=None, reffreq=None, complist=None, incremental=None, usescratch=None, async=None): 00027 00028 """Insert a source model a visibility set: 00029 00030 A source model (souce.model image) or components list is converted into a 00031 model visibility that is inserted into the MODEL_DATA column. This is 00032 needed to use resolved source in gaincal and in fluxscale. 00033 00034 Setjy will automatically make this ft step on the 00035 sources currently available are 3C48, 3C138, 3C147, 3C286 00036 at 1.4, 5.0, 8.4, 15, 22, 43 GHz. Their location is site 00037 dependent. In Charlottesville and at the AOC, the models are 00038 in /usr/lib(lib64)/casapy/data/nrao/VLA/CalModels. 00039 00040 00041 Keyword arguments: 00042 vis -- Name of input visibility file 00043 default: none; example: vis='ngc5921.ms' 00044 field -- Field name list 00045 default: '' ==> all 00046 NOTE: BUT, only one source can be specified in a multi-source vis. 00047 field = '1328+307' specifies source '1328+307' 00048 field = '4' specified field with index 4 00049 spw -- Spw selection 00050 default: spw = '' (all spw) 00051 model -- Name of input model image 00052 default: '' ==> None; 00053 example: model='/usr/lib/casapy/data/nrao/VLA/CalModels/3C286_X.im' 00054 Note: The model visibilities are scaled from the model frequency 00055 to the observed frequency of the data. 00056 nterms -- Number of terms used to model the sky frequency dependence 00057 default: 1 ==> one model image is required 00058 example : nterms=3 represents a 2nd order Taylor-polynomial in frequency 00059 and should be used in conjuction with coefficient model images as 00060 model=['xxx.model.tt0','xxx.model.tt1', 'xxx.model.tt2'] 00061 reffreq -- Reference-frequency about which this Taylor-expansion is defined. 00062 default: '' ==> reads the reference frequency from the model image 00063 example : reffreq = '1.5GHz' 00064 complist -- Name of component list 00065 default: None; ; example: complist='test.cl' 00066 component lists are difficult to make. 00067 incremental -- Add model visibility to the existing model visibilties stored in the MS 00068 default: False; example: incremental=True 00069 usescratch -- if True model visibilities will be stored in the scratch column 00070 MODEL_DATA; when false the model visibilities will be generated 00071 on the fly (this mode may save some disk space equivalent to 00072 the volume of the observed data). 00073 default: False; example usescratch=True 00074 00075 00076 00077 00078 00079 00080 00081 """ 00082 a=inspect.stack() 00083 stacklevel=0 00084 for k in range(len(a)): 00085 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00086 stacklevel=k 00087 break 00088 myf=sys._getframe(stacklevel).f_globals 00089 myf['__last_task'] = 'ft' 00090 myf['taskname'] = 'ft' 00091 ### 00092 myf['update_params'](func=myf['taskname'],printtext=False) 00093 ### 00094 ### 00095 #Handle globals or user over-ride of arguments 00096 # 00097 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00098 useLocalDefaults = False 00099 00100 for item in function_signature_defaults.iteritems(): 00101 key,val = item 00102 keyVal = eval(key) 00103 if (keyVal == None): 00104 #user hasn't set it - use global/default 00105 pass 00106 else: 00107 #user has set it - use over-ride 00108 if (key != 'self') : 00109 useLocalDefaults = True 00110 #myf[key]=keyVal 00111 00112 myparams = {} 00113 if useLocalDefaults : 00114 for item in function_signature_defaults.iteritems(): 00115 key,val = item 00116 keyVal = eval(key) 00117 exec('myparams[key] = keyVal') 00118 if (keyVal == None): 00119 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00120 keyVal = eval(key) 00121 if(type(keyVal) == dict) : 00122 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00123 00124 else : 00125 uselessvariable = None 00126 myparams['vis'] = vis = myf['vis'] 00127 myparams['field'] = field = myf['field'] 00128 myparams['spw'] = spw = myf['spw'] 00129 myparams['model'] = model = myf['model'] 00130 myparams['nterms'] = nterms = myf['nterms'] 00131 myparams['reffreq'] = reffreq = myf['reffreq'] 00132 myparams['complist'] = complist = myf['complist'] 00133 myparams['incremental'] = incremental = myf['incremental'] 00134 myparams['usescratch'] = usescratch = myf['usescratch'] 00135 00136 00137 result = None 00138 00139 # 00140 # The following is work around to avoid a bug with current python translation 00141 # 00142 mytmp = {} 00143 00144 mytmp['vis'] = vis 00145 mytmp['field'] = field 00146 mytmp['spw'] = spw 00147 mytmp['model'] = model 00148 mytmp['nterms'] = nterms 00149 mytmp['reffreq'] = reffreq 00150 mytmp['complist'] = complist 00151 mytmp['incremental'] = incremental 00152 mytmp['usescratch'] = usescratch 00153 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00154 trec = casac.utils().torecord(pathname+'ft.xml') 00155 00156 casalog.origin('ft') 00157 if not trec.has_key('ft') or not casac.utils().verify(mytmp, trec['ft']) : 00158 return False 00159 00160 00161 try : 00162 casalog.post('') 00163 casalog.post('##########################################') 00164 casalog.post('##### Begin Task: ft #####') 00165 casalog.post('') 00166 result = ft(vis, field, spw, model, nterms, reffreq, complist, incremental, usescratch) 00167 casalog.post('') 00168 casalog.post('##### End Task: ft #####') 00169 casalog.post('##########################################') 00170 00171 00172 # saveinputs for individule engine has no use 00173 # saveinputs should alos be removed from casa_in_py.py 00174 # 00175 # 00176 # saveinputs = myf['saveinputs'] 00177 # saveinputs('ft', 'ft.last', myparams) 00178 # 00179 # 00180 except Exception, instance: 00181 #print '**** Error **** ',instance 00182 pass 00183 00184 gc.collect() 00185 return result 00186 # 00187 # 00188 ## 00189 # def paramgui(self, useGlobals=True): 00190 # """ 00191 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00192 # """ 00193 # import paramgui 00194 # 00195 # a=inspect.stack() 00196 # stacklevel=0 00197 # for k in range(len(a)): 00198 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00199 # stacklevel=k 00200 # break 00201 # myf = sys._getframe(stacklevel).f_globals 00202 # 00203 # if useGlobals: 00204 # paramgui.setGlobals(myf) 00205 # else: 00206 # paramgui.setGlobals({}) 00207 # 00208 # paramgui.runTask('ft', myf['_ip']) 00209 # paramgui.setGlobals({}) 00210 # 00211 # 00212 # 00213 # 00214 def defaults(self, param=None): 00215 a=inspect.stack() 00216 stacklevel=0 00217 for k in range(len(a)): 00218 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00219 stacklevel=k 00220 break 00221 myf=sys._getframe(stacklevel).f_globals 00222 a = odict() 00223 a['vis'] = '' 00224 a['field'] = '' 00225 a['spw'] = '' 00226 a['model'] = '' 00227 a['nterms'] = 1 00228 a['complist'] = '' 00229 a['incremental'] = False 00230 a['usescratch'] = False 00231 00232 a['async']=False 00233 a['nterms'] = { 00234 0:odict([{'notvalue':1}, {'reffreq':''}])} 00235 00236 ### This function sets the default values but also will return the list of 00237 ### parameters or the default value of a given parameter 00238 if(param == None): 00239 myf['__set_default_parameters'](a) 00240 elif(param == 'paramkeys'): 00241 return a.keys() 00242 else: 00243 if(a.has_key(param)): 00244 #if(type(a[param]) == dict) : 00245 # return a[param][len(a[param])-1]['value'] 00246 #else : 00247 return a[param] 00248 00249 00250 # 00251 # 00252 def check_params(self, param=None, value=None): 00253 a=inspect.stack() 00254 stacklevel=0 00255 for k in range(len(a)): 00256 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00257 stacklevel=k 00258 break 00259 myf=sys._getframe(stacklevel).f_globals 00260 00261 # print 'param:', param, 'value:', value 00262 try : 00263 if str(type(value)) != "<type 'instance'>" : 00264 value0 = value 00265 value = myf['cu'].expandparam(param, value) 00266 matchtype = False 00267 if(type(value) == numpy.ndarray): 00268 if(type(value) == type(value0)): 00269 myf[param] = value.tolist() 00270 else: 00271 #print 'value:', value, 'value0:', value0 00272 #print 'type(value):', type(value), 'type(value0):', type(value0) 00273 myf[param] = value0 00274 if type(value0) != list : 00275 matchtype = True 00276 else : 00277 myf[param] = value 00278 value = myf['cu'].verifyparam({param:value}) 00279 if matchtype: 00280 value = False 00281 except Exception, instance: 00282 #ignore the exception and just return it unchecked 00283 myf[param] = value 00284 return value 00285 00286 # 00287 # 00288 def description(self, key='ft', subkey=None): 00289 desc={'ft': 'Insert a source model a visibility set:', 00290 'vis': 'Name of input visibility file (MS)', 00291 'field': 'Field selection', 00292 'spw': 'Spw selection', 00293 'model': 'Name of input model image(s)', 00294 'nterms': 'Number of terms used to model the sky frequency dependence', 00295 'reffreq': 'Reference frequency (e.g. \'1.5e+9\' or \'1.5GHz\')', 00296 'complist': 'Name of component list', 00297 'incremental': 'Add to the existing model visibility?', 00298 'usescratch': 'If True predicted visibility is stored in MODEL_DATA column', 00299 00300 'async': 'If true the taskname must be started using ft(...)' 00301 } 00302 00303 # 00304 # Set subfields defaults if needed 00305 # 00306 00307 if(desc.has_key(key)) : 00308 return desc[key] 00309 00310 def itsdefault(self, paramname) : 00311 a = {} 00312 a['vis'] = '' 00313 a['field'] = '' 00314 a['spw'] = '' 00315 a['model'] = '' 00316 a['nterms'] = 1 00317 a['reffreq'] = '' 00318 a['complist'] = '' 00319 a['incremental'] = False 00320 a['usescratch'] = False 00321 00322 if a.has_key(paramname) : 00323 return a[paramname] 00324 ft_pg = ft_pg_()