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_sdgrid import sdgrid 00016 from task_sdgrid import casalog 00017 00018 class sdgrid_pg_: 00019 __name__ = "sdgrid" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdgrid_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infiles=None, antenna=None, scanlist=None, ifno=None, pollist=None, gridfunction=None, convsupport=None, truncate=None, gwidth=None, jwidth=None, weight=None, clipminmax=None, outfile=None, overwrite=None, npix=None, cell=None, center=None, plot=None, async=None): 00027 00028 """SD task: gridding single dish data 00029 Keyword arguments: 00030 infiles -- name of input SD dataset. can be list. 00031 example: 'testimage.asap' 00032 ['testimage1.asap','testimage2.asap'] 00033 antenna -- select data based on antenna name(s) or id(s) 00034 default: -1 00035 example: 0, 'DV01' 00036 scanlist -- list of scan numbers to process 00037 default: [] (use all scans) 00038 example: [21,22,23,24] 00039 ifno -- IFNO to be gridded 00040 default: -1 (only process IFNO in the first row) 00041 example: 1 00042 pollist -- POLNO to be gridded 00043 default: [] (all polarizations) 00044 example: 1,[0,1] 00045 gridfunction -- gridding function 00046 options: 'BOX' (Box-car), 'SF' (Spheroidal), 00047 'GAUSS' (Gaussian), 'PB' (Primary-beam) 00048 'GJINC' (Gaussian*Jinc) 00049 default: 'BOX' 00050 example: 'SF' 00051 >>> gridfunction expandable parameter: 00052 convsupport -- convolution support for 'SF' 00053 default: -1 (use default for each gridfunction) 00054 example: 3 00055 truncate -- truncattion radius of convolution kernel. 00056 effective only for 'GAUSS' and 'GJINC'. 00057 default: '-1' (use default for each gridfunction) 00058 example: 3, '20arcsec', '3pixel' 00059 gwidth -- HWHM for gaussian. Effective only for 00060 'GAUSS' and 'GJINC'. 00061 default: '-1' (use default for each gridfunction) 00062 example: 3, '20arcsec', '3pixel' 00063 jwidth -- Width of jinc function. Effective only for 00064 'GJINC'. 00065 default: '-1' (use default for each gridfunction) 00066 example: 3, '20arcsec', '3pixel' 00067 weight -- weight type (both lower-case and upper-case are 00068 acceptable) 00069 options: 'UNIFORM', 00070 'TSYS' (1/Tsys**2 weighted) 00071 'TINT' (integration time weighted) 00072 'TINTSYS' (Tint/Tsys**2) 00073 default: 'UNIFORM' 00074 clipminmax -- do min/max cliping if True 00075 default: False 00076 outfile -- output data name 00077 default: '' (outfile will be set to infile+'.grid') 00078 example: 'mydata.asap.grid' 00079 overwrite -- overwrite option for outfile 00080 default: False (not overwrite) 00081 options: True, False 00082 example: if True, existing file will be overwritten 00083 npix -- x and y image size in pixels, symmetric for single value 00084 default: -1 (automatically calculated from cell size and 00085 the data) 00086 example: npix=200 (equivalent to [200,200]) 00087 cell -- x and y cell size. default unit arcsec 00088 default: '' (automatically calculated from npix if it is 00089 set, otherwise '1.0arcmin') 00090 example: cell=['0.2arcmin, 0.2arcmin'] 00091 cell='0.2arcmin' (equivalent to example above) 00092 cell=12.0 (interpreted as '12.0arcsec'='0.2arcmin') 00093 center -- grid center 00094 default: '' (automatically calculated from the data) 00095 example: 'J2000 13h44m00 -17d02m00' 00096 ['05:34:48.2', '-05.22.17.7'] (in J2000 frame) 00097 [1.46, -0.09] (interpreted as radian in J2000 frame) 00098 plot -- Plot result or not 00099 default: False (not plot) 00100 example: if True, result will be plotted 00101 00102 DESCRIPTION: 00103 00104 The sdgrid task performs spatial gridding according to the user 00105 specification of spatial grid, convolution function, etc. 00106 00107 For grid configuration, the task supplements necessary information 00108 by referring input data if any of gridding parameter ('npix', 00109 'cell', or 'center') is not specified by the user. If 'center' is 00110 default value (empty string), central position of the grid will be 00111 set to the center of observed area, i.e. x=0.5*(xmax+xmin), 00112 y=0.5*(ymax+ymin). If either 'cell' or 'npix' is set, unspecified 00113 one will be calculated from the others. In that case, total extent of 00114 the grid will be set to cover all observed position. If neither 'cell' 00115 nor 'npix' is set, cell size will be set to 1.0 arcmin and number of 00116 pixel will be calculated based on that cell size. 00117 00118 Currently, only J2000 frame is supported. 00119 00120 The parameter gridfunction sets gridding function for imaging. 00121 Currently, the task supports 'BOX' (Box-car), 'SF' (Prolate 00122 Spheroidal Wave Function), 'GAUSS' (Gaussian), 'GJINC' (Gaussian* 00123 Jinc), where Jinc(x) = J_1(pi*x/c)/(pi*x/c) with a first order 00124 Bessel function J_1, and 'PB' (Primary Beam, not implemented yet). 00125 For 'PB', correct antenna informations should be included in input 00126 file. 00127 00128 There are four subparameters for gridfunction: convsupport, truncate, 00129 gwidth, and jwidth. The convsupport is an integer specifying cut-off 00130 radius for 'SF' in units of pixel. By default (convsupport=-1), 00131 the cut-off radius is set to 3 pixels. The truncate is a cut-off 00132 radius for 'GAUSS' or 'GJINC'. It accepts integer, float, and 00133 string values of numeric plus unit. Allowed units are angular 00134 units such as 'deg', 'arcmin', 'arcsec', and 'pixel'. Default unit 00135 is 'pixel' so that string without unit or numerical values (integer 00136 or float) will be interpreted as radius in pixel. Default value 00137 for truncate, which is used when negative radius is set, is 3*HWHM 00138 for 'GAUSS' and radius at first null for 'GJINC'. The gwidth is 00139 the HWHM of gaussian for 'GAUSS' and 'GJINC'. Default value is 00140 sqrt(log(2)) pixel for 'GAUSS' and 2.52*sqrt(log(2)) pixel for 00141 'GJINC'. The jwidth specifies width of the jinc function (parameter 00142 'c' in the definition above). Default is 1.55 pixel. Both gwidth 00143 jwidth allows integer, float, or string of numeric plus unit. 00144 Default values for gwidth and jwidth are taken from Mangum et al. 00145 (2007). 00146 00147 Boolean parameter 'plot' controls whether gridded result is plotted 00148 or not. If True, color map of gridded data will be shown. Pixel 00149 center and observed position are overlayed as blue dot and red dot, 00150 respectively. Currently, channel averaged value will be plotted. 00151 00152 """ 00153 a=inspect.stack() 00154 stacklevel=0 00155 for k in range(len(a)): 00156 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00157 stacklevel=k 00158 break 00159 myf=sys._getframe(stacklevel).f_globals 00160 myf['__last_task'] = 'sdgrid' 00161 myf['taskname'] = 'sdgrid' 00162 ### 00163 myf['update_params'](func=myf['taskname'],printtext=False) 00164 ### 00165 ### 00166 #Handle globals or user over-ride of arguments 00167 # 00168 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00169 useLocalDefaults = False 00170 00171 for item in function_signature_defaults.iteritems(): 00172 key,val = item 00173 keyVal = eval(key) 00174 if (keyVal == None): 00175 #user hasn't set it - use global/default 00176 pass 00177 else: 00178 #user has set it - use over-ride 00179 if (key != 'self') : 00180 useLocalDefaults = True 00181 #myf[key]=keyVal 00182 00183 myparams = {} 00184 if useLocalDefaults : 00185 for item in function_signature_defaults.iteritems(): 00186 key,val = item 00187 keyVal = eval(key) 00188 exec('myparams[key] = keyVal') 00189 if (keyVal == None): 00190 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00191 keyVal = eval(key) 00192 if(type(keyVal) == dict) : 00193 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00194 00195 else : 00196 uselessvariable = None 00197 myparams['infiles'] = infiles = myf['infiles'] 00198 myparams['antenna'] = antenna = myf['antenna'] 00199 myparams['scanlist'] = scanlist = myf['scanlist'] 00200 myparams['ifno'] = ifno = myf['ifno'] 00201 myparams['pollist'] = pollist = myf['pollist'] 00202 myparams['gridfunction'] = gridfunction = myf['gridfunction'] 00203 myparams['convsupport'] = convsupport = myf['convsupport'] 00204 myparams['truncate'] = truncate = myf['truncate'] 00205 myparams['gwidth'] = gwidth = myf['gwidth'] 00206 myparams['jwidth'] = jwidth = myf['jwidth'] 00207 myparams['weight'] = weight = myf['weight'] 00208 myparams['clipminmax'] = clipminmax = myf['clipminmax'] 00209 myparams['outfile'] = outfile = myf['outfile'] 00210 myparams['overwrite'] = overwrite = myf['overwrite'] 00211 myparams['npix'] = npix = myf['npix'] 00212 myparams['cell'] = cell = myf['cell'] 00213 myparams['center'] = center = myf['center'] 00214 myparams['plot'] = plot = myf['plot'] 00215 00216 if type(scanlist)==int: scanlist=[scanlist] 00217 00218 result = None 00219 00220 # 00221 # The following is work around to avoid a bug with current python translation 00222 # 00223 mytmp = {} 00224 00225 mytmp['infiles'] = infiles 00226 mytmp['antenna'] = antenna 00227 mytmp['scanlist'] = scanlist 00228 mytmp['ifno'] = ifno 00229 mytmp['pollist'] = pollist 00230 mytmp['gridfunction'] = gridfunction 00231 mytmp['convsupport'] = convsupport 00232 mytmp['truncate'] = truncate 00233 mytmp['gwidth'] = gwidth 00234 mytmp['jwidth'] = jwidth 00235 mytmp['weight'] = weight 00236 mytmp['clipminmax'] = clipminmax 00237 mytmp['outfile'] = outfile 00238 mytmp['overwrite'] = overwrite 00239 mytmp['npix'] = npix 00240 mytmp['cell'] = cell 00241 mytmp['center'] = center 00242 mytmp['plot'] = plot 00243 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00244 trec = casac.utils().torecord(pathname+'sdgrid.xml') 00245 00246 casalog.origin('sdgrid') 00247 if not trec.has_key('sdgrid') or not casac.utils().verify(mytmp, trec['sdgrid']) : 00248 return False 00249 00250 00251 try : 00252 casalog.post('') 00253 casalog.post('##########################################') 00254 casalog.post('##### Begin Task: sdgrid #####') 00255 casalog.post('') 00256 result = sdgrid(infiles, antenna, scanlist, ifno, pollist, gridfunction, convsupport, truncate, gwidth, jwidth, weight, clipminmax, outfile, overwrite, npix, cell, center, plot) 00257 casalog.post('') 00258 casalog.post('##### End Task: sdgrid #####') 00259 casalog.post('##########################################') 00260 00261 00262 # saveinputs for individule engine has no use 00263 # saveinputs should alos be removed from casa_in_py.py 00264 # 00265 # 00266 # saveinputs = myf['saveinputs'] 00267 # saveinputs('sdgrid', 'sdgrid.last', myparams) 00268 # 00269 # 00270 except Exception, instance: 00271 #print '**** Error **** ',instance 00272 pass 00273 00274 gc.collect() 00275 return result 00276 # 00277 # 00278 ## 00279 # def paramgui(self, useGlobals=True): 00280 # """ 00281 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00282 # """ 00283 # import paramgui 00284 # 00285 # a=inspect.stack() 00286 # stacklevel=0 00287 # for k in range(len(a)): 00288 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00289 # stacklevel=k 00290 # break 00291 # myf = sys._getframe(stacklevel).f_globals 00292 # 00293 # if useGlobals: 00294 # paramgui.setGlobals(myf) 00295 # else: 00296 # paramgui.setGlobals({}) 00297 # 00298 # paramgui.runTask('sdgrid', myf['_ip']) 00299 # paramgui.setGlobals({}) 00300 # 00301 # 00302 # 00303 # 00304 def defaults(self, param=None): 00305 a=inspect.stack() 00306 stacklevel=0 00307 for k in range(len(a)): 00308 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00309 stacklevel=k 00310 break 00311 myf=sys._getframe(stacklevel).f_globals 00312 a = odict() 00313 a['infiles'] = [""] 00314 a['antenna'] = -1 00315 a['scanlist'] = [] 00316 a['ifno'] = -1 00317 a['pollist'] = [] 00318 a['gridfunction'] = 'BOX' 00319 a['weight'] = 'UNIFORM' 00320 a['clipminmax'] = False 00321 a['outfile'] = '' 00322 a['overwrite'] = False 00323 a['npix'] = -1 00324 a['cell'] = '' 00325 a['center'] = '' 00326 a['plot'] = False 00327 00328 a['async']=False 00329 a['gridfunction'] = { 00330 0:{'value':'BOX'}, 00331 1:{'value':'box'}, 00332 2:odict([{'value':'SF'}, {'convsupport':-1}]), 00333 3:odict([{'value':'sf'}, {'convsupport':-1}]), 00334 4:odict([{'value':'GAUSS'}, {'truncate':-1}, {'gwidth':-1}]), 00335 5:odict([{'value':'gauss'}, {'truncate':-1}, {'gwidth':-1}]), 00336 6:odict([{'value':'GJINC'}, {'truncate':-1}, {'gwidth':-1}, {'jwidth':-1}]), 00337 7:odict([{'value':'gjinc'}, {'truncate':-1}, {'gwidth':-1}, {'jwidth':-1}]), 00338 8:{'value':'PB'}, 00339 9:{'value':'pb'}} 00340 00341 ### This function sets the default values but also will return the list of 00342 ### parameters or the default value of a given parameter 00343 if(param == None): 00344 myf['__set_default_parameters'](a) 00345 elif(param == 'paramkeys'): 00346 return a.keys() 00347 else: 00348 if(a.has_key(param)): 00349 #if(type(a[param]) == dict) : 00350 # return a[param][len(a[param])-1]['value'] 00351 #else : 00352 return a[param] 00353 00354 00355 # 00356 # 00357 def check_params(self, param=None, value=None): 00358 a=inspect.stack() 00359 stacklevel=0 00360 for k in range(len(a)): 00361 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00362 stacklevel=k 00363 break 00364 myf=sys._getframe(stacklevel).f_globals 00365 00366 # print 'param:', param, 'value:', value 00367 try : 00368 if str(type(value)) != "<type 'instance'>" : 00369 value0 = value 00370 value = myf['cu'].expandparam(param, value) 00371 matchtype = False 00372 if(type(value) == numpy.ndarray): 00373 if(type(value) == type(value0)): 00374 myf[param] = value.tolist() 00375 else: 00376 #print 'value:', value, 'value0:', value0 00377 #print 'type(value):', type(value), 'type(value0):', type(value0) 00378 myf[param] = value0 00379 if type(value0) != list : 00380 matchtype = True 00381 else : 00382 myf[param] = value 00383 value = myf['cu'].verifyparam({param:value}) 00384 if matchtype: 00385 value = False 00386 except Exception, instance: 00387 #ignore the exception and just return it unchecked 00388 myf[param] = value 00389 return value 00390 00391 # 00392 # 00393 def description(self, key='sdgrid', subkey=None): 00394 desc={'sdgrid': 'SD task: gridding single dish data', 00395 'infiles': '(list of) input SD dataset', 00396 'antenna': 'antenna name(s) or id(s)', 00397 'scanlist': 'list of scans to use (e.g. [1,2,3,4])', 00398 'ifno': 'IFNO for gridding', 00399 'pollist': 'POLNO for gridding', 00400 'gridfunction': 'gridding function for imaging ("BOX","SF","GAUSS","PB")', 00401 'convsupport': 'truncate of convolution kernel', 00402 'truncate': 'truncation radius of convolution kernel', 00403 'gwidth': 'HWHM for gaussian', 00404 'jwidth': 'c-parameter for jinc function', 00405 'weight': 'weight type', 00406 'clipminmax': 'clip minimum and maximum values during gridding', 00407 'outfile': 'output image name', 00408 'overwrite': 'overwrite option', 00409 'npix': 'number of pixels in x and y, symmetric for single value', 00410 'cell': 'x and y cell size. default unit arcsec', 00411 'center': 'Image center', 00412 'plot': 'Plot result or not', 00413 00414 'async': 'If true the taskname must be started using sdgrid(...)' 00415 } 00416 00417 # 00418 # Set subfields defaults if needed 00419 # 00420 00421 if(desc.has_key(key)) : 00422 return desc[key] 00423 00424 def itsdefault(self, paramname) : 00425 a = {} 00426 a['infiles'] = [""] 00427 a['antenna'] = -1 00428 a['scanlist'] = [] 00429 a['ifno'] = -1 00430 a['pollist'] = [] 00431 a['gridfunction'] = 'BOX' 00432 a['convsupport'] = -1 00433 a['truncate'] = -1 00434 a['gwidth'] = -1 00435 a['jwidth'] = -1 00436 a['weight'] = 'UNIFORM' 00437 a['clipminmax'] = False 00438 a['outfile'] = '' 00439 a['overwrite'] = False 00440 a['npix'] = -1 00441 a['cell'] = '' 00442 a['center'] = '' 00443 a['plot'] = False 00444 00445 if a.has_key(paramname) : 00446 return a[paramname] 00447 sdgrid_pg = sdgrid_pg_()