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_tclean import tclean 00016 from task_tclean import casalog 00017 00018 class tclean_pg_: 00019 __name__ = "tclean" 00020 00021 def __init__(self) : 00022 self.__bases__ = (tclean_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, field=None, spw=None, imagename=None, nchan=None, startmodel=None, niter=None, threshold=None, loopgain=None, maxcycleniter=None, cyclefactor=None, minpsffraction=None, maxpsffraction=None, usescratch=None, clusterdef=None, async=None): 00027 00028 """Construct and deconvolve images 00029 00030 This is an empty task. 00031 It is meant only to build/test/maintain the interface for the refactored imaging code. 00032 When ready, it will be offered to users for testing. 00033 00034 00035 """ 00036 a=inspect.stack() 00037 stacklevel=0 00038 for k in range(len(a)): 00039 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00040 stacklevel=k 00041 break 00042 myf=sys._getframe(stacklevel).f_globals 00043 myf['__last_task'] = 'tclean' 00044 myf['taskname'] = 'tclean' 00045 ### 00046 myf['update_params'](func=myf['taskname'],printtext=False) 00047 ### 00048 ### 00049 #Handle globals or user over-ride of arguments 00050 # 00051 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00052 useLocalDefaults = False 00053 00054 for item in function_signature_defaults.iteritems(): 00055 key,val = item 00056 keyVal = eval(key) 00057 if (keyVal == None): 00058 #user hasn't set it - use global/default 00059 pass 00060 else: 00061 #user has set it - use over-ride 00062 if (key != 'self') : 00063 useLocalDefaults = True 00064 #myf[key]=keyVal 00065 00066 myparams = {} 00067 if useLocalDefaults : 00068 for item in function_signature_defaults.iteritems(): 00069 key,val = item 00070 keyVal = eval(key) 00071 exec('myparams[key] = keyVal') 00072 if (keyVal == None): 00073 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00074 keyVal = eval(key) 00075 if(type(keyVal) == dict) : 00076 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00077 00078 else : 00079 uselessvariable = None 00080 myparams['vis'] = vis = myf['vis'] 00081 myparams['field'] = field = myf['field'] 00082 myparams['spw'] = spw = myf['spw'] 00083 myparams['imagename'] = imagename = myf['imagename'] 00084 myparams['nchan'] = nchan = myf['nchan'] 00085 myparams['startmodel'] = startmodel = myf['startmodel'] 00086 myparams['niter'] = niter = myf['niter'] 00087 myparams['threshold'] = threshold = myf['threshold'] 00088 myparams['loopgain'] = loopgain = myf['loopgain'] 00089 myparams['maxcycleniter'] = maxcycleniter = myf['maxcycleniter'] 00090 myparams['cyclefactor'] = cyclefactor = myf['cyclefactor'] 00091 myparams['minpsffraction'] = minpsffraction = myf['minpsffraction'] 00092 myparams['maxpsffraction'] = maxpsffraction = myf['maxpsffraction'] 00093 myparams['usescratch'] = usescratch = myf['usescratch'] 00094 myparams['clusterdef'] = clusterdef = myf['clusterdef'] 00095 00096 00097 result = None 00098 00099 # 00100 # The following is work around to avoid a bug with current python translation 00101 # 00102 mytmp = {} 00103 00104 mytmp['vis'] = vis 00105 mytmp['field'] = field 00106 mytmp['spw'] = spw 00107 mytmp['imagename'] = imagename 00108 mytmp['nchan'] = nchan 00109 mytmp['startmodel'] = startmodel 00110 mytmp['niter'] = niter 00111 mytmp['threshold'] = threshold 00112 mytmp['loopgain'] = loopgain 00113 mytmp['maxcycleniter'] = maxcycleniter 00114 mytmp['cyclefactor'] = cyclefactor 00115 mytmp['minpsffraction'] = minpsffraction 00116 mytmp['maxpsffraction'] = maxpsffraction 00117 mytmp['usescratch'] = usescratch 00118 mytmp['clusterdef'] = clusterdef 00119 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00120 trec = casac.utils().torecord(pathname+'tclean.xml') 00121 00122 casalog.origin('tclean') 00123 if not trec.has_key('tclean') or not casac.utils().verify(mytmp, trec['tclean']) : 00124 return False 00125 00126 00127 try : 00128 casalog.post('') 00129 casalog.post('##########################################') 00130 casalog.post('##### Begin Task: tclean #####') 00131 casalog.post('') 00132 result = tclean(vis, field, spw, imagename, nchan, startmodel, niter, threshold, loopgain, maxcycleniter, cyclefactor, minpsffraction, maxpsffraction, usescratch, clusterdef) 00133 casalog.post('') 00134 casalog.post('##### End Task: tclean #####') 00135 casalog.post('##########################################') 00136 00137 00138 # saveinputs for individule engine has no use 00139 # saveinputs should alos be removed from casa_in_py.py 00140 # 00141 # 00142 # saveinputs = myf['saveinputs'] 00143 # saveinputs('tclean', 'tclean.last', myparams) 00144 # 00145 # 00146 except Exception, instance: 00147 #print '**** Error **** ',instance 00148 pass 00149 00150 gc.collect() 00151 return result 00152 # 00153 # 00154 ## 00155 # def paramgui(self, useGlobals=True): 00156 # """ 00157 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00158 # """ 00159 # import paramgui 00160 # 00161 # a=inspect.stack() 00162 # stacklevel=0 00163 # for k in range(len(a)): 00164 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00165 # stacklevel=k 00166 # break 00167 # myf = sys._getframe(stacklevel).f_globals 00168 # 00169 # if useGlobals: 00170 # paramgui.setGlobals(myf) 00171 # else: 00172 # paramgui.setGlobals({}) 00173 # 00174 # paramgui.runTask('tclean', myf['_ip']) 00175 # paramgui.setGlobals({}) 00176 # 00177 # 00178 # 00179 # 00180 def defaults(self, param=None): 00181 a=inspect.stack() 00182 stacklevel=0 00183 for k in range(len(a)): 00184 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00185 stacklevel=k 00186 break 00187 myf=sys._getframe(stacklevel).f_globals 00188 a = odict() 00189 a['vis'] = '' 00190 a['field'] = '' 00191 a['spw'] = '' 00192 a['imagename'] = '' 00193 a['nchan'] = 1 00194 a['startmodel'] = '' 00195 a['niter'] = 500 00196 a['threshold'] = 0.0 00197 a['loopgain'] = 0.1 00198 a['maxcycleniter'] = -1 00199 a['usescratch'] = False 00200 a['clusterdef'] = '' 00201 00202 a['async']=False 00203 a['maxcycleniter'] = { 00204 0:odict([{'notvalue':-1}, {'cyclefactor':1.0}, {'minpsffraction':0.05}, {'maxpsffraction':0.8}])} 00205 00206 ### This function sets the default values but also will return the list of 00207 ### parameters or the default value of a given parameter 00208 if(param == None): 00209 myf['__set_default_parameters'](a) 00210 elif(param == 'paramkeys'): 00211 return a.keys() 00212 else: 00213 if(a.has_key(param)): 00214 #if(type(a[param]) == dict) : 00215 # return a[param][len(a[param])-1]['value'] 00216 #else : 00217 return a[param] 00218 00219 00220 # 00221 # 00222 def check_params(self, param=None, value=None): 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 # print 'param:', param, 'value:', value 00232 try : 00233 if str(type(value)) != "<type 'instance'>" : 00234 value0 = value 00235 value = myf['cu'].expandparam(param, value) 00236 matchtype = False 00237 if(type(value) == numpy.ndarray): 00238 if(type(value) == type(value0)): 00239 myf[param] = value.tolist() 00240 else: 00241 #print 'value:', value, 'value0:', value0 00242 #print 'type(value):', type(value), 'type(value0):', type(value0) 00243 myf[param] = value0 00244 if type(value0) != list : 00245 matchtype = True 00246 else : 00247 myf[param] = value 00248 value = myf['cu'].verifyparam({param:value}) 00249 if matchtype: 00250 value = False 00251 except Exception, instance: 00252 #ignore the exception and just return it unchecked 00253 myf[param] = value 00254 return value 00255 00256 # 00257 # 00258 def description(self, key='tclean', subkey=None): 00259 desc={'tclean': 'Construct and deconvolve images', 00260 'vis': 'Name of input visibility file(s)', 00261 'field': 'field(s) to select', 00262 'spw': 'spw(s) to select', 00263 'imagename': 'Pre-name of output images', 00264 'nchan': 'Number of channels in the output image', 00265 'startmodel': 'Name of starting model image', 00266 'niter': 'Maximum number of iterations', 00267 'threshold': 'Stopping threshold (number, in units of Jy)', 00268 'loopgain': 'Loop gain', 00269 'maxcycleniter': 'Maximum number of minor-cycle iterations before triggering a major cycle', 00270 'cyclefactor': 'Scaling on PSF sidelobe level to compute the minor-cycle stopping threshold.', 00271 'minpsffraction': 'PSF fraction that marks the max depth of cleaning in the minor cycle ', 00272 'maxpsffraction': 'PSF fraction that marks the minimum depth of cleaning in the minor cycle ', 00273 'usescratch': 'True if to save model visibilities in MODEL_DATA column', 00274 'clusterdef': 'Name of a file that contains the cluster definition', 00275 00276 'async': 'If true the taskname must be started using tclean(...)' 00277 } 00278 00279 # 00280 # Set subfields defaults if needed 00281 # 00282 00283 if(desc.has_key(key)) : 00284 return desc[key] 00285 00286 def itsdefault(self, paramname) : 00287 a = {} 00288 a['vis'] = '' 00289 a['field'] = '' 00290 a['spw'] = '' 00291 a['imagename'] = '' 00292 a['nchan'] = 1 00293 a['startmodel'] = '' 00294 a['niter'] = 500 00295 a['threshold'] = 0.0 00296 a['loopgain'] = 0.1 00297 a['maxcycleniter'] = -1 00298 a['cyclefactor'] = 1.0 00299 a['minpsffraction'] = 0.05 00300 a['maxpsffraction'] = 0.8 00301 a['usescratch'] = False 00302 a['clusterdef'] = '' 00303 00304 if a.has_key(paramname) : 00305 return a[paramname] 00306 tclean_pg = tclean_pg_()