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_ssoflux import ssoflux 00016 from task_ssoflux import casalog 00017 00018 class ssoflux_pg_: 00019 __name__ = "ssoflux" 00020 00021 def __init__(self) : 00022 self.__bases__ = (ssoflux_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, field=None, spw=None, modimage=None, fluxdensity=None, standard=None, async=None): 00027 00028 """Fills the model column with the visibilities of a calibrator 00029 *This is an experimental clone of setjy while flux calibration with 00030 Solar System objects is being tested. It will eventually be merged 00031 back into setjy.* 00032 00033 This task sets the model visibility amp and phase of a 00034 specified source (generally a calibrator). The simplest way is 00035 to enter the flux density (I,Q,U,V) explicitly, but this is 00036 valid only for a point source. 00037 00038 For an extended source, the clean model (image.model) can be 00039 specified and the model visibilities associated with this clean 00040 model is placed in the visibility model column. 00041 00042 Models are available for 3C48, 3C138, 3C286 between 00043 1.4 and 43 GHz. 3C147 is available above 13 GHz. These models 00044 are scaled to the precise frequency of the data. Only I source 00045 model can be inserted at a time. 00046 00047 The location of the models are system dependent: At the AOC and CV, 00048 the models are in the directory::/usr/lib/casapy/data/nrao/VLA/CalModels 00049 or /usr/lib64/casapy/data/nrao/VLA/CalModel. 00050 00051 ssoflux need only be run on the calibrator sources with a known flux 00052 density and/or model. 00053 00054 Keyword arguments: 00055 vis -- Name of input visibility file 00056 default: none. example: vis='ngc5921.ms' 00057 field -- Select field using field id(s) or field name(s). 00058 default: ''=all fields, but run ssoflux one field at a time. 00059 [run listobs to obtain the list id's or names of calibrators] 00060 If field is a non-negative integer, it is assumed to be a field 00061 index. Otherwise, it is taken to be a field name. 00062 field='0~2'; field ids 0,1,2 00063 field='0,4,5~7'; field ids 0,4,5,6,7 00064 field='3C286,3C295'; field named 3C286 and 3C295 00065 field = '3,4C*'; field id 3, all names starting with 4C 00066 spw -- Select spectral window/channels 00067 default: ''=all spectral windows and channels 00068 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 00069 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00070 spw='0:5~61'; spw 0, channels 5 to 61 00071 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, channels 3 to 45. 00072 spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each. 00073 spw='0:0~10;15~60'; spectral window 0 with channels 0-10,15-60 00074 spw='0:0~10,1:20~30,2:1;2;4'; spw 0, channels 0-10, 00075 spw 1, channels 20-30, and spw 2, channels, 1,2 and 4 00076 00077 Use one of the two methods below: modimage or fluxdensity 00078 00079 modimage -- Model image (I only) for setting the model visibilities. 00080 default: '' means use fluxdensity instead of modimage. 00081 Each field must be done separately. The image clean model 00082 will be scaled from the frequency in the model to that actually used, 00083 unless fluxdensity = 0 (or fluxdensity[0] = 0). 00084 Both the amplitude and phase are calculated. 00085 At the AOC or CV, the models are located in 00086 /usr/lib/casapy/data/nrao/VLA/CalModels/3C286_L.im (egs) 00087 lib64 00088 00089 fluxdensity -- Specified flux density [I,Q,U,V] in Jy 00090 default: -1, uses [1,0,0,0] flux density for all sources, 00091 except for 3C286, 3C48 and 3C147, which use standard flux 00092 densities. It is recommended to use modimage for 00093 these sources if they are resolved by the observation. 00094 Only one flux density can be specified at a time. The phases are 00095 set to zero. 00096 example fluxdensity=-1 will insert 1.0 for all calibrators 00097 except 3C286, 3C147 and 3C48. 00098 example field = '1'; fluxdensity=[3.2,0,0,0] wil put in 00099 a flux density of I=3.2 for field='1' 00100 00101 At present (June 2000), this is the only method to insert a 00102 polarized flux density model. 00103 example: fluxdensity=[2.63,0.21,-0.33,0.02] 00104 will put in I,Q,U,V flux densities of 2.63,0.21,-0.33, 00105 and 0.02, respectively, in the model column. 00106 00107 standard -- Flux density standard, used if fluxdensity<0 00108 default: 'Perley-Taylor 99'; example: standard='Baars' 00109 Options: 'Baars','Perley 90','Perley-Taylor 95', 00110 'Perley-Taylor 99', 'Perley-Butler 2010', 00111 and 'Butler-JPL-Horizons 2010'. 00112 All but the last one are for extragalactic calibrators, 00113 and the final one is for Solar System objects. 00114 00115 """ 00116 a=inspect.stack() 00117 stacklevel=0 00118 for k in range(len(a)): 00119 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00120 stacklevel=k 00121 break 00122 myf=sys._getframe(stacklevel).f_globals 00123 myf['__last_task'] = 'ssoflux' 00124 myf['taskname'] = 'ssoflux' 00125 ### 00126 myf['update_params'](func=myf['taskname'],printtext=False) 00127 ### 00128 ### 00129 #Handle globals or user over-ride of arguments 00130 # 00131 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00132 useLocalDefaults = False 00133 00134 for item in function_signature_defaults.iteritems(): 00135 key,val = item 00136 keyVal = eval(key) 00137 if (keyVal == None): 00138 #user hasn't set it - use global/default 00139 pass 00140 else: 00141 #user has set it - use over-ride 00142 if (key != 'self') : 00143 useLocalDefaults = True 00144 #myf[key]=keyVal 00145 00146 myparams = {} 00147 if useLocalDefaults : 00148 for item in function_signature_defaults.iteritems(): 00149 key,val = item 00150 keyVal = eval(key) 00151 exec('myparams[key] = keyVal') 00152 if (keyVal == None): 00153 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00154 keyVal = eval(key) 00155 if(type(keyVal) == dict) : 00156 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00157 00158 else : 00159 uselessvariable = None 00160 myparams['vis'] = vis = myf['vis'] 00161 myparams['field'] = field = myf['field'] 00162 myparams['spw'] = spw = myf['spw'] 00163 myparams['modimage'] = modimage = myf['modimage'] 00164 myparams['fluxdensity'] = fluxdensity = myf['fluxdensity'] 00165 myparams['standard'] = standard = myf['standard'] 00166 00167 00168 result = None 00169 00170 # 00171 # The following is work around to avoid a bug with current python translation 00172 # 00173 mytmp = {} 00174 00175 mytmp['vis'] = vis 00176 mytmp['field'] = field 00177 mytmp['spw'] = spw 00178 mytmp['modimage'] = modimage 00179 mytmp['fluxdensity'] = fluxdensity 00180 mytmp['standard'] = standard 00181 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00182 trec = casac.utils().torecord(pathname+'ssoflux.xml') 00183 00184 casalog.origin('ssoflux') 00185 if not trec.has_key('ssoflux') or not casac.utils().verify(mytmp, trec['ssoflux']) : 00186 return False 00187 00188 00189 try : 00190 casalog.post('') 00191 casalog.post('##########################################') 00192 casalog.post('##### Begin Task: ssoflux #####') 00193 casalog.post('') 00194 result = ssoflux(vis, field, spw, modimage, fluxdensity, standard) 00195 casalog.post('') 00196 casalog.post('##### End Task: ssoflux #####') 00197 casalog.post('##########################################') 00198 00199 00200 # saveinputs for individule engine has no use 00201 # saveinputs should alos be removed from casa_in_py.py 00202 # 00203 # 00204 # saveinputs = myf['saveinputs'] 00205 # saveinputs('ssoflux', 'ssoflux.last', myparams) 00206 # 00207 # 00208 except Exception, instance: 00209 #print '**** Error **** ',instance 00210 pass 00211 00212 gc.collect() 00213 return result 00214 # 00215 # 00216 ## 00217 # def paramgui(self, useGlobals=True): 00218 # """ 00219 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00220 # """ 00221 # import paramgui 00222 # 00223 # a=inspect.stack() 00224 # stacklevel=0 00225 # for k in range(len(a)): 00226 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00227 # stacklevel=k 00228 # break 00229 # myf = sys._getframe(stacklevel).f_globals 00230 # 00231 # if useGlobals: 00232 # paramgui.setGlobals(myf) 00233 # else: 00234 # paramgui.setGlobals({}) 00235 # 00236 # paramgui.runTask('ssoflux', myf['_ip']) 00237 # paramgui.setGlobals({}) 00238 # 00239 # 00240 # 00241 # 00242 def defaults(self, param=None): 00243 a=inspect.stack() 00244 stacklevel=0 00245 for k in range(len(a)): 00246 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00247 stacklevel=k 00248 break 00249 myf=sys._getframe(stacklevel).f_globals 00250 a = odict() 00251 a['vis'] = '' 00252 a['field'] = '' 00253 a['spw'] = '' 00254 a['modimage'] = '' 00255 a['fluxdensity'] = -1 00256 a['standard'] = 'Perley-Taylor 99' 00257 00258 a['async']=False 00259 00260 ### This function sets the default values but also will return the list of 00261 ### parameters or the default value of a given parameter 00262 if(param == None): 00263 myf['__set_default_parameters'](a) 00264 elif(param == 'paramkeys'): 00265 return a.keys() 00266 else: 00267 if(a.has_key(param)): 00268 #if(type(a[param]) == dict) : 00269 # return a[param][len(a[param])-1]['value'] 00270 #else : 00271 return a[param] 00272 00273 00274 # 00275 # 00276 def check_params(self, param=None, value=None): 00277 a=inspect.stack() 00278 stacklevel=0 00279 for k in range(len(a)): 00280 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00281 stacklevel=k 00282 break 00283 myf=sys._getframe(stacklevel).f_globals 00284 00285 # print 'param:', param, 'value:', value 00286 try : 00287 if str(type(value)) != "<type 'instance'>" : 00288 value0 = value 00289 value = myf['cu'].expandparam(param, value) 00290 matchtype = False 00291 if(type(value) == numpy.ndarray): 00292 if(type(value) == type(value0)): 00293 myf[param] = value.tolist() 00294 else: 00295 #print 'value:', value, 'value0:', value0 00296 #print 'type(value):', type(value), 'type(value0):', type(value0) 00297 myf[param] = value0 00298 if type(value0) != list : 00299 matchtype = True 00300 else : 00301 myf[param] = value 00302 value = myf['cu'].verifyparam({param:value}) 00303 if matchtype: 00304 value = False 00305 except Exception, instance: 00306 #ignore the exception and just return it unchecked 00307 myf[param] = value 00308 return value 00309 00310 # 00311 # 00312 def description(self, key='ssoflux', subkey=None): 00313 desc={'ssoflux': 'Fills the model column with the visibilities of a calibrator', 00314 'vis': 'Name of input visibility file', 00315 'field': 'Field name(s)', 00316 'spw': 'Spectral window identifier (list)', 00317 'modimage': 'File location for field model', 00318 'fluxdensity': 'Specified flux density [I,Q,U,V]; -1 will lookup values', 00319 'standard': 'Flux density standard', 00320 00321 'async': 'If true the taskname must be started using ssoflux(...)' 00322 } 00323 00324 if(desc.has_key(key)) : 00325 return desc[key] 00326 00327 def itsdefault(self, paramname) : 00328 a = {} 00329 a['vis'] = '' 00330 a['field'] = '' 00331 a['spw'] = '' 00332 a['modimage'] = '' 00333 a['fluxdensity'] = -1 00334 a['standard'] = 'Perley-Taylor 99' 00335 00336 if a.has_key(paramname) : 00337 return a[paramname] 00338 ssoflux_pg = ssoflux_pg_()