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_uvcontsub3 import uvcontsub3 00016 from task_uvcontsub3 import casalog 00017 00018 class uvcontsub3_pg_: 00019 __name__ = "uvcontsub3" 00020 00021 def __init__(self) : 00022 self.__bases__ = (uvcontsub3_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, fitspw=None, combine=None, fitorder=None, field=None, spw=None, scan=None, intent=None, correlation=None, observation=None, async=None): 00027 00028 """An experimental clone of uvcontsub 00029 00030 uvcontsub3 is an experimental clone of uvcontsub with the goal of taking 00031 less time and temporary disk space. 00032 00033 Continuum fitting and subtraction in the uv plane: 00034 00035 This task estimates the continuum emission by fitting polynomials to 00036 the real and imaginary parts of the spectral windows and channels 00037 selected by fitspw. This fit represents a model of the continuum in 00038 all channels. 00039 00040 The fitted continuum spectrum is subtracted from all channels 00041 selected in spw, and the result (presumably only line emission) 00042 is stored in a new MS (vis + ".contsub"). 00043 It will read from the CORRECTED_DATA column of vis if it is present, 00044 or DATA if it is not. Whichever column is read is presumed to have 00045 already been calibrated. 00046 00047 Keyword arguments: 00048 vis -- Name of input visibility file 00049 default: none; example: vis='ngc5921.ms' 00050 00051 fitspw -- Selection of spectral windows and channels to use in the 00052 fit for the continuum, using general spw:chan syntax. 00053 See the note under combine. 00054 default: '' (all) 00055 example: fitspw='0:5~30;40~55' 00056 00057 combine -- Let the continuum estimation span multiple spectral windows. 00058 default = '' (Make separate estimates for each spw.) 00059 combine = 'spw': Necessary when one or more of the spws are 00060 completely blanketed by lines, so the estimate 00061 must be made in different spws. 00062 00063 fitorder -- Polynomial order for the fits of the continuum w.r.t. 00064 frequency. fitorders > 1 are strongly discouraged 00065 because high order polynomials have more flexibility, may 00066 absorb line emission, and tend go wild at the edges of 00067 fitspw, which is not what you want. 00068 00069 default: 0 (constant); example: fitorder=1 00070 00071 field -- Field selection for continuum estimation and subtraction. 00072 The estimation and subtraction is done for each selected field 00073 in turn. (Run listobs to get lists of the ID and names.) 00074 default: ''=all fields. If the field string is a non-negative 00075 integer, it is assumed to be a field index 00076 otherwise, it is assumed to be a field name 00077 field='0~2'; field ids 0,1,2 00078 field='0,4,5~7'; field ids 0,4,5,6,7 00079 field='3C286,3C295'; fields named 3C286 and 3C295 00080 field = '3,4C*'; field id 3, all names starting with 4C 00081 00082 spw -- Select spectral windows for the output. 00083 default: ''=all spectral windows 00084 N.B. uvcontsub3 does not yet support exclusion by channels for 00085 the output. Meanwhile, use split to further reduce the size 00086 of the output MS if desired. 00087 spw='0~2,4'; spectral windows 0,1,2,4 00088 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00089 00090 scan -- Scan number range 00091 default: ''=all 00092 00093 intent -- Select by scan intent (state). Case sensitive. 00094 default: '' = all 00095 Examples: 00096 intent = 'CALIBRATE_ATMOSPHERE_REFERENCE' 00097 intent = 'calibrate_atmosphere_reference'.upper() # same as above 00098 # Select states that include one or both of CALIBRATE_WVR.REFERENCE 00099 # or OBSERVE_TARGET_ON_SOURCE. 00100 intent = 'CALIBRATE_WVR.REFERENCE, OBSERVE_TARGET_ON_SOURCE' 00101 00102 correlation -- Select correlations, e.g. 'rr, ll' or ['XY', 'YX']. 00103 default '' (all). 00104 00105 observation -- Select by observation ID(s). 00106 default: '' = all 00107 00108 00109 """ 00110 a=inspect.stack() 00111 stacklevel=0 00112 for k in range(len(a)): 00113 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00114 stacklevel=k 00115 break 00116 myf=sys._getframe(stacklevel).f_globals 00117 myf['__last_task'] = 'uvcontsub3' 00118 myf['taskname'] = 'uvcontsub3' 00119 ### 00120 myf['update_params'](func=myf['taskname'],printtext=False) 00121 ### 00122 ### 00123 #Handle globals or user over-ride of arguments 00124 # 00125 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00126 useLocalDefaults = False 00127 00128 for item in function_signature_defaults.iteritems(): 00129 key,val = item 00130 keyVal = eval(key) 00131 if (keyVal == None): 00132 #user hasn't set it - use global/default 00133 pass 00134 else: 00135 #user has set it - use over-ride 00136 if (key != 'self') : 00137 useLocalDefaults = True 00138 #myf[key]=keyVal 00139 00140 myparams = {} 00141 if useLocalDefaults : 00142 for item in function_signature_defaults.iteritems(): 00143 key,val = item 00144 keyVal = eval(key) 00145 exec('myparams[key] = keyVal') 00146 if (keyVal == None): 00147 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00148 keyVal = eval(key) 00149 if(type(keyVal) == dict) : 00150 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00151 00152 else : 00153 uselessvariable = None 00154 myparams['vis'] = vis = myf['vis'] 00155 myparams['fitspw'] = fitspw = myf['fitspw'] 00156 myparams['combine'] = combine = myf['combine'] 00157 myparams['fitorder'] = fitorder = myf['fitorder'] 00158 myparams['field'] = field = myf['field'] 00159 myparams['spw'] = spw = myf['spw'] 00160 myparams['scan'] = scan = myf['scan'] 00161 myparams['intent'] = intent = myf['intent'] 00162 myparams['correlation'] = correlation = myf['correlation'] 00163 myparams['observation'] = observation = myf['observation'] 00164 00165 00166 result = None 00167 00168 # 00169 # The following is work around to avoid a bug with current python translation 00170 # 00171 mytmp = {} 00172 00173 mytmp['vis'] = vis 00174 mytmp['fitspw'] = fitspw 00175 mytmp['combine'] = combine 00176 mytmp['fitorder'] = fitorder 00177 mytmp['field'] = field 00178 mytmp['spw'] = spw 00179 mytmp['scan'] = scan 00180 mytmp['intent'] = intent 00181 mytmp['correlation'] = correlation 00182 mytmp['observation'] = observation 00183 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00184 trec = casac.utils().torecord(pathname+'uvcontsub3.xml') 00185 00186 casalog.origin('uvcontsub3') 00187 if not trec.has_key('uvcontsub3') or not casac.utils().verify(mytmp, trec['uvcontsub3']) : 00188 return False 00189 00190 00191 try : 00192 casalog.post('') 00193 casalog.post('##########################################') 00194 casalog.post('##### Begin Task: uvcontsub3 #####') 00195 casalog.post('') 00196 result = uvcontsub3(vis, fitspw, combine, fitorder, field, spw, scan, intent, correlation, observation) 00197 casalog.post('') 00198 casalog.post('##### End Task: uvcontsub3 #####') 00199 casalog.post('##########################################') 00200 00201 00202 # saveinputs for individule engine has no use 00203 # saveinputs should alos be removed from casa_in_py.py 00204 # 00205 # 00206 # saveinputs = myf['saveinputs'] 00207 # saveinputs('uvcontsub3', 'uvcontsub3.last', myparams) 00208 # 00209 # 00210 except Exception, instance: 00211 #print '**** Error **** ',instance 00212 pass 00213 00214 gc.collect() 00215 return result 00216 # 00217 # 00218 ## 00219 # def paramgui(self, useGlobals=True): 00220 # """ 00221 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00222 # """ 00223 # import paramgui 00224 # 00225 # a=inspect.stack() 00226 # stacklevel=0 00227 # for k in range(len(a)): 00228 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00229 # stacklevel=k 00230 # break 00231 # myf = sys._getframe(stacklevel).f_globals 00232 # 00233 # if useGlobals: 00234 # paramgui.setGlobals(myf) 00235 # else: 00236 # paramgui.setGlobals({}) 00237 # 00238 # paramgui.runTask('uvcontsub3', myf['_ip']) 00239 # paramgui.setGlobals({}) 00240 # 00241 # 00242 # 00243 # 00244 def defaults(self, param=None): 00245 a=inspect.stack() 00246 stacklevel=0 00247 for k in range(len(a)): 00248 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00249 stacklevel=k 00250 break 00251 myf=sys._getframe(stacklevel).f_globals 00252 a = odict() 00253 a['vis'] = '' 00254 a['fitspw'] = '' 00255 a['combine'] = '' 00256 a['fitorder'] = 0 00257 a['field'] = '' 00258 a['spw'] = '' 00259 a['scan'] = '' 00260 a['intent'] = '' 00261 a['correlation'] = '' 00262 a['observation'] = '' 00263 00264 a['async']=False 00265 00266 ### This function sets the default values but also will return the list of 00267 ### parameters or the default value of a given parameter 00268 if(param == None): 00269 myf['__set_default_parameters'](a) 00270 elif(param == 'paramkeys'): 00271 return a.keys() 00272 else: 00273 if(a.has_key(param)): 00274 #if(type(a[param]) == dict) : 00275 # return a[param][len(a[param])-1]['value'] 00276 #else : 00277 return a[param] 00278 00279 00280 # 00281 # 00282 def check_params(self, param=None, value=None): 00283 a=inspect.stack() 00284 stacklevel=0 00285 for k in range(len(a)): 00286 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00287 stacklevel=k 00288 break 00289 myf=sys._getframe(stacklevel).f_globals 00290 00291 # print 'param:', param, 'value:', value 00292 try : 00293 if str(type(value)) != "<type 'instance'>" : 00294 value0 = value 00295 value = myf['cu'].expandparam(param, value) 00296 matchtype = False 00297 if(type(value) == numpy.ndarray): 00298 if(type(value) == type(value0)): 00299 myf[param] = value.tolist() 00300 else: 00301 #print 'value:', value, 'value0:', value0 00302 #print 'type(value):', type(value), 'type(value0):', type(value0) 00303 myf[param] = value0 00304 if type(value0) != list : 00305 matchtype = True 00306 else : 00307 myf[param] = value 00308 value = myf['cu'].verifyparam({param:value}) 00309 if matchtype: 00310 value = False 00311 except Exception, instance: 00312 #ignore the exception and just return it unchecked 00313 myf[param] = value 00314 return value 00315 00316 # 00317 # 00318 def description(self, key='uvcontsub3', subkey=None): 00319 desc={'uvcontsub3': 'An experimental clone of uvcontsub', 00320 'vis': 'Name of input MS. Output goes to vis + ".contsub"', 00321 'fitspw': 'Spectral window:channel selection for fitting the continuum', 00322 'combine': 'Data axes to combine for the continuum estimation (none ('') or spw)', 00323 'fitorder': 'Polynomial order for the fits', 00324 'field': 'Select field(s) using id(s) or name(s)', 00325 'spw': 'Spectral window selection for output', 00326 'scan': 'Select data by scan numbers', 00327 'intent': 'Select data by scan intents', 00328 'correlation': 'Select correlations', 00329 'observation': 'Select by observation ID(s)', 00330 00331 'async': 'If true the taskname must be started using uvcontsub3(...)' 00332 } 00333 00334 if(desc.has_key(key)) : 00335 return desc[key] 00336 00337 def itsdefault(self, paramname) : 00338 a = {} 00339 a['vis'] = '' 00340 a['fitspw'] = '' 00341 a['combine'] = '' 00342 a['fitorder'] = 0 00343 a['field'] = '' 00344 a['spw'] = '' 00345 a['scan'] = '' 00346 a['intent'] = '' 00347 a['correlation'] = '' 00348 a['observation'] = '' 00349 00350 if a.has_key(paramname) : 00351 return a[paramname] 00352 uvcontsub3_pg = uvcontsub3_pg_()