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_sdimprocess import sdimprocess 00016 from task_sdimprocess import casalog 00017 00018 class sdimprocess_pg_: 00019 __name__ = "sdimprocess" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdimprocess_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infiles=None, mode=None, numpoly=None, beamsize=None, smoothsize=None, direction=None, masklist=None, tmax=None, tmin=None, outfile=None, overwrite=None, async=None): 00027 00028 """SD task: task for single-dish image processing 00029 Keyword arguments: 00030 infiles -- name of input SD (FITS or CASA) image 00031 mode -- processing mode 00032 default: 'basket' 00033 options: 'basket', 'press' 00034 00035 >>>mode expandable parameter 00036 direction -- scan direction in unit of degree 00037 default: [] 00038 example: [0.0,90.0] 00039 masklist -- mask width for Basket-Weaving on percentage 00040 default: 1.0 (1.0% of map size) 00041 numpoly -- order of polynomial fit in Presssed-out 00042 default: 2 00043 beamsize -- beam size 00044 default: 0.0 00045 example: 10.0 (interpreted as '10arcsec'), '1arcmin' 00046 smoothsize -- smoothing beam in Pressed-out 00047 default: 2.0 (interpreted as 2.0 * beamsize) 00048 example: '1arcmin' (set smoothsize directly) 00049 00050 tmax -- maximum value used for process 00051 default: 0.0 (no threshold in maximum) 00052 example: 10.0 (mask data larger value than 10.0) 00053 tmin -- minimum value used for process 00054 default: 0.0 (no threshold in minimum) 00055 example: -10.0 (mask data smaller value than -10.0) 00056 outfile -- output CASA image name 00057 default: '' (use default name) 00058 example: 'output.im' 00059 overwrite -- overwrite option for outfile 00060 default: False (not overwrite) 00061 options: True, False 00062 example: if True, existing file will be overwritten 00063 00064 00065 DESCRIPTION: 00066 00067 Task sdimprocess is used to remove a scanning noise that appears 00068 as a striped noise pattern along the scan direction in a raster 00069 scan data. 00070 00071 By default, the scanning noise is removed by using the 00072 'Basket-Weaving' method (Emerson & Grave 1988) that requires 00073 multiple images that observed exactly the same area with different 00074 scanning direction. If only one image is available, the 'Pressed-out' 00075 method (Sofue & Reich 1979) can be used to remove the scanning 00076 effect. 00077 00078 For 'Basket-Weaving', scanning directions must have at least two 00079 different values. Normally, the scanning direction should be 00080 specified for each input image. Otherwise, specified scanning 00081 directions will be used iteratively. The masklist is a width of 00082 masking region in the Fourier plane. It is specified as a fraction 00083 (percentage) of the image size. 00084 00085 For 'Pressed-out', the scanning direction must be unique. There are 00086 two ways to specify a size of smoothing beam used for process. One 00087 is to specify smoothing size directly. To do this, smoothsize should 00088 be specified as string that consists of a numerical value and an unit 00089 (e.g. '10.0arcsec'). A value of beamsize will be ignored in this case. 00090 Another way to specify smoothing size is to set an observed beam size 00091 and indicate smoothing size as a scale factor of the observed beam 00092 size. In this case, the beamsize is interpreted as the observed beam 00093 size, and the smoothsize is the scale factor. If the beamsize is 00094 provided as float value, its unit is assumed to 'arcsec'. It is also 00095 possible to set the beamsize as string consisting of the numerical 00096 value and the unit. The smoothsize must be float value. 00097 00098 The infiles only allows an image data (CASA or FITS), and not does 00099 not work with MS or Scantable. The direction is an angle with respect 00100 to the horizontal direction, and its unit is degree. Any value may be 00101 interpreted properly, but the value ranging from 0.0 to 180.0 will be 00102 secure. The tmax and the tmin is used to specify a threshold that 00103 defines a range of spectral values used for processing. The data point 00104 that has the value larger than tmax or smaller than tmin will be 00105 excluded from the processing. The default (0.0) is no threshold. 00106 The outfile specifies an output CASA image name. If the outfile is 00107 empty, the default name ('sdimprocess.out.im') will be used. 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'] = 'sdimprocess' 00118 myf['taskname'] = 'sdimprocess' 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['infiles'] = infiles = myf['infiles'] 00155 myparams['mode'] = mode = myf['mode'] 00156 myparams['numpoly'] = numpoly = myf['numpoly'] 00157 myparams['beamsize'] = beamsize = myf['beamsize'] 00158 myparams['smoothsize'] = smoothsize = myf['smoothsize'] 00159 myparams['direction'] = direction = myf['direction'] 00160 myparams['masklist'] = masklist = myf['masklist'] 00161 myparams['tmax'] = tmax = myf['tmax'] 00162 myparams['tmin'] = tmin = myf['tmin'] 00163 myparams['outfile'] = outfile = myf['outfile'] 00164 myparams['overwrite'] = overwrite = myf['overwrite'] 00165 00166 00167 result = None 00168 00169 # 00170 # The following is work around to avoid a bug with current python translation 00171 # 00172 mytmp = {} 00173 00174 mytmp['infiles'] = infiles 00175 mytmp['mode'] = mode 00176 mytmp['numpoly'] = numpoly 00177 mytmp['beamsize'] = beamsize 00178 mytmp['smoothsize'] = smoothsize 00179 mytmp['direction'] = direction 00180 mytmp['masklist'] = masklist 00181 mytmp['tmax'] = tmax 00182 mytmp['tmin'] = tmin 00183 mytmp['outfile'] = outfile 00184 mytmp['overwrite'] = overwrite 00185 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00186 trec = casac.utils().torecord(pathname+'sdimprocess.xml') 00187 00188 casalog.origin('sdimprocess') 00189 if not trec.has_key('sdimprocess') or not casac.utils().verify(mytmp, trec['sdimprocess']) : 00190 return False 00191 00192 00193 try : 00194 casalog.post('') 00195 casalog.post('##########################################') 00196 casalog.post('##### Begin Task: sdimprocess #####') 00197 casalog.post('') 00198 result = sdimprocess(infiles, mode, numpoly, beamsize, smoothsize, direction, masklist, tmax, tmin, outfile, overwrite) 00199 casalog.post('') 00200 casalog.post('##### End Task: sdimprocess #####') 00201 casalog.post('##########################################') 00202 00203 00204 # saveinputs for individule engine has no use 00205 # saveinputs should alos be removed from casa_in_py.py 00206 # 00207 # 00208 # saveinputs = myf['saveinputs'] 00209 # saveinputs('sdimprocess', 'sdimprocess.last', myparams) 00210 # 00211 # 00212 except Exception, instance: 00213 #print '**** Error **** ',instance 00214 pass 00215 00216 gc.collect() 00217 return result 00218 # 00219 # 00220 ## 00221 # def paramgui(self, useGlobals=True): 00222 # """ 00223 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00224 # """ 00225 # import paramgui 00226 # 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 # if useGlobals: 00236 # paramgui.setGlobals(myf) 00237 # else: 00238 # paramgui.setGlobals({}) 00239 # 00240 # paramgui.runTask('sdimprocess', myf['_ip']) 00241 # paramgui.setGlobals({}) 00242 # 00243 # 00244 # 00245 # 00246 def defaults(self, param=None): 00247 a=inspect.stack() 00248 stacklevel=0 00249 for k in range(len(a)): 00250 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00251 stacklevel=k 00252 break 00253 myf=sys._getframe(stacklevel).f_globals 00254 a = odict() 00255 a['infiles'] = [''] 00256 a['mode'] = '' 00257 a['tmax'] = 0.0 00258 a['tmin'] = 0.0 00259 a['outfile'] = '' 00260 a['overwrite'] = False 00261 00262 a['async']=False 00263 a['mode'] = { 00264 0:odict([{'value':'basket'}, {'direction':[]}, {'masklist':1.0}]), 00265 1:odict([{'value':'press'}, {'numpoly':2}, {'beamsize':0.0}, {'smoothsize':2.0}, {'direction':0.0}])} 00266 00267 ### This function sets the default values but also will return the list of 00268 ### parameters or the default value of a given parameter 00269 if(param == None): 00270 myf['__set_default_parameters'](a) 00271 elif(param == 'paramkeys'): 00272 return a.keys() 00273 else: 00274 if(a.has_key(param)): 00275 #if(type(a[param]) == dict) : 00276 # return a[param][len(a[param])-1]['value'] 00277 #else : 00278 return a[param] 00279 00280 00281 # 00282 # 00283 def check_params(self, param=None, value=None): 00284 a=inspect.stack() 00285 stacklevel=0 00286 for k in range(len(a)): 00287 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00288 stacklevel=k 00289 break 00290 myf=sys._getframe(stacklevel).f_globals 00291 00292 # print 'param:', param, 'value:', value 00293 try : 00294 if str(type(value)) != "<type 'instance'>" : 00295 value0 = value 00296 value = myf['cu'].expandparam(param, value) 00297 matchtype = False 00298 if(type(value) == numpy.ndarray): 00299 if(type(value) == type(value0)): 00300 myf[param] = value.tolist() 00301 else: 00302 #print 'value:', value, 'value0:', value0 00303 #print 'type(value):', type(value), 'type(value0):', type(value0) 00304 myf[param] = value0 00305 if type(value0) != list : 00306 matchtype = True 00307 else : 00308 myf[param] = value 00309 value = myf['cu'].verifyparam({param:value}) 00310 if matchtype: 00311 value = False 00312 except Exception, instance: 00313 #ignore the exception and just return it unchecked 00314 myf[param] = value 00315 return value 00316 00317 # 00318 # 00319 def description(self, key='sdimprocess', subkey=None): 00320 desc={'sdimprocess': 'SD task: task for single-dish image processing', 00321 'infiles': 'name of input SD image (FITS or CASA image)', 00322 'mode': 'processing mode ("press" or "basket")', 00323 'numpoly': 'order of polynomial fit', 00324 'beamsize': 'beam size', 00325 'smoothsize': 'size of smoothing beam', 00326 'direction': 'scan direction in unit of degree', 00327 'masklist': 'mask width (on percentage)', 00328 'tmax': 'maximum value used for process', 00329 'tmin': 'minimum value used for process', 00330 'outfile': 'output CASA image name', 00331 'overwrite': 'overwrite option for outfile', 00332 00333 'async': 'If true the taskname must be started using sdimprocess(...)' 00334 } 00335 00336 # 00337 # Set subfields defaults if needed 00338 # 00339 00340 if(desc.has_key(key)) : 00341 return desc[key] 00342 00343 def itsdefault(self, paramname) : 00344 a = {} 00345 a['infiles'] = [''] 00346 a['mode'] = '' 00347 a['numpoly'] = 2 00348 a['beamsize'] = 0.0 00349 a['smoothsize'] = 2.0 00350 a['direction'] = [] 00351 a['masklist'] = 1.0 00352 a['tmax'] = 0.0 00353 a['tmin'] = 0.0 00354 a['outfile'] = '' 00355 a['overwrite'] = False 00356 00357 if a.has_key(paramname) : 00358 return a[paramname] 00359 sdimprocess_pg = sdimprocess_pg_()