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_sdtpimaging import sdtpimaging 00016 from task_sdtpimaging import casalog 00017 00018 class sdtpimaging_pg_: 00019 __name__ = "sdtpimaging" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdtpimaging_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infile=None, calmode=None, masklist=None, blpoly=None, backup=None, flaglist=None, antenna=None, spw=None, stokes=None, createimage=None, outfile=None, imsize=None, cell=None, phasecenter=None, ephemsrcname=None, pointingcolumn=None, gridfunction=None, plotlevel=None, async=None): 00027 00028 """SD task: do a simple calibration and imaging for total power data 00029 Keyword arguments: 00030 infile -- name of input SD (MS) dataset 00031 calmode -- calibration mode (currently only baseline subtraction) 00032 options: 'baseline','none' 00033 default: 'none' 00034 example: choose mode 'none' if you have 00035 already calibrated and want to do 00036 plotting nd/or imaging 00037 >>> calmode='baseline' expandable parameters 00038 masklist -- mask in numbers of rows from each edge of each scan 00039 to be included for baseline fitting 00040 default: none 00041 example: [30,30] or [30] 00042 used first 30 rows and last 30 rows of each scan for 00043 the baseline 00044 blpoly -- polynomial order for the baseline fit 00045 default: 1 00046 backup -- set True to create backup for input data 00047 default: True 00048 flaglist -- list of scan numbers to flag (ranges can be accepted) 00049 default: [] (use all scans) 00050 example: [[0,3],80] 00051 flag the scan range [0,3] = [0,1,2,3] and scan 80 00052 antenna -- select data based on antenna name(s) or id(s) in string 00053 default: '' (use all antennas) 00054 example: '0,1', 'DV01' 00055 WARNING: currently baseline subtraction properly 00056 only one of the antennas. 00057 spw -- spectral window id 00058 default: 0 00059 example: 1 00060 stokes -- select data based on stokes or polarization type 00061 default: '' (use all polarizations) 00062 example: 'XX' 00063 createimage -- do imaging? 00064 default: False 00065 >>> createimage=True expandable parameters 00066 outfile -- output image name 00067 default: none 00068 example: 'mySDimage.im' 00069 imsize -- x and y image size in pixels, symmetric for single 00070 value 00071 default: [256,256] 00072 example: imsize=200 (equivalent to [200,200]) 00073 cell -- x and y cell size. default unit arcmin 00074 default: '1.0arcmin' 00075 example: cell=['0.2arcmin, 0.2arcmin'] 00076 cell='0.2arcmin' (equivalent to example above) 00077 phasecenter -- image phase center: direction measure or fieldid 00078 default: 0 00079 example: 'J2000 13h44m00 -17d02m00', 'AZEL -123d48m29 15d41m41' 00080 ephemsrcname -- ephemeris source name to proper shifting to 00081 center on the moving source for imaging 00082 default: '' 00083 if the source name in the data matches one of the 00084 known solar objects by the system, this task 00085 automatically set the source name. 00086 example: 'moon' 00087 pointingcolumn -- pointing data column to use 00088 option: 'direction', 'target', 'pointing_offset', 00089 'source_offset', 'encoder' 00090 default: 'direction' 00091 gridfunction -- gridding function for imaging 00092 options: 'BOX' (Box-car), 'SF' (Spheroidal), 00093 'PB' (Primary-beam), 'GAUSS' (Gaussian), 00094 'GJINC' (Gaussian*Jinc) 00095 default: 'BOX' 00096 example: 'SF' 00097 plotlevel -- control for plotting of results 00098 options: (int) 0=none, 1=some, 2=more, <0=hardcopy 00099 default: 0 (no plotting) 00100 example: plotlevel<0 as abs(plotlevel), e.g. 00101 -1: hardcopy plot 00102 (will be named <infile>_scans.eps) 00103 1: plot raw data, calibrated data 00104 (for calmode='baseline) 00105 plot raw or if exist calibrated data 00106 (for calmode='none') 00107 2: plot raw data, progressively display baseline 00108 fitting for each scan, and final calibrated data 00109 (for calmode='baseline') 00110 00111 00112 DESCRIPTION: 00113 00114 Task sdtpimaging performs data selection, calibration, and imaging for 00115 single-dish totalpower raster scan data. This is a still experimental 00116 task made to work mostly for the data taken at the ALMA Testing 00117 Facility (ATF) or OSF. Currently, this task directly accesses the 00118 Measurement Set data only because of the data access efficiency. So it 00119 differs from other single-dish tasks that mostly operate on the ASAP 00120 scantable data format. By setting calmode='none', one can run 00121 sdtpimaging to plot the data (raw or calibrated, if exists) and 00122 further imaging by setting createimage=True. 00123 00124 The calibration available at this moment is just a simple baseline 00125 subtraction for each scan. The fitted regions set by masklist are the 00126 common for all the scans. Selection of the antennas can be made by 00127 setting antennaid(s) or antenna name(s) in string (e.g. '0', '0,1', 00128 'DV01',etc.). 00129 00130 For baseline subtraction, it currently works properly for a single 00131 antenna selection. So a separate sdtpimaging task needs to be ran for 00132 each antenna. It currently assumes that the data has a single spw(=0) 00133 and fieldid(=0). By setting flaglist, one can set flag by scan numbers 00134 to be excluded from imaging. (Note: 'scan numbers' are determined from 00135 state id and related to SUB_SCAN column in STATE subtable and not to 00136 SCAN_NUMBER in MS.) By default, baseline subtraction stage overwrites 00137 (FLOAT_)DATA column of input data. You can keep original data by 00138 setting backup parameter to True. In this case, the task make a copy 00139 of input data specified by infile parameter. Name of backup file is 00140 <infile>.sdtpimaging.bak.<timestamp>. 00141 00142 The selection of polarizations can be made by specifying the 00143 polarization name in stokes, such as 'XX' or 'YY' for linear 00144 polarizations. For example, with createimage=True, stokes='XXYY' will 00145 produces an image cube with each plane contains the image of one of 00146 the polarizations while stokes='' or stokes='I' will produces a 'total 00147 intensity' or Stokes I image. 00148 00149 Among the imaging sub-parameters, ephemsrcname is used to set the name 00150 of a moving source such as planets to produce a stationary image (can 00151 be omitted), and pointingcolumn is used to specify which pointing data 00152 column to use for imaging. Convolution kernel for imaging can be 00153 specified by using gridfunction. Available options are 'Box' (Box-car), 00154 'SF' (Spheroidal), 'PB' (Primary-beam), 'GAUSS' (Gaussian), and 00155 'GJINC' (Gaussian*Jinc), where Jinc(x) = J_1(pi*x/c)/(pi*x/c) with a 00156 first order Bessel function J_1. Sub-parameters for convolution 00157 functions cannot be specified in this task. To costomize your 00158 convolution function, please do imaging using sdimaging task or 00159 imager tool. 00160 00161 """ 00162 a=inspect.stack() 00163 stacklevel=0 00164 for k in range(len(a)): 00165 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00166 stacklevel=k 00167 break 00168 myf=sys._getframe(stacklevel).f_globals 00169 myf['__last_task'] = 'sdtpimaging' 00170 myf['taskname'] = 'sdtpimaging' 00171 ### 00172 myf['update_params'](func=myf['taskname'],printtext=False) 00173 ### 00174 ### 00175 #Handle globals or user over-ride of arguments 00176 # 00177 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00178 useLocalDefaults = False 00179 00180 for item in function_signature_defaults.iteritems(): 00181 key,val = item 00182 keyVal = eval(key) 00183 if (keyVal == None): 00184 #user hasn't set it - use global/default 00185 pass 00186 else: 00187 #user has set it - use over-ride 00188 if (key != 'self') : 00189 useLocalDefaults = True 00190 #myf[key]=keyVal 00191 00192 myparams = {} 00193 if useLocalDefaults : 00194 for item in function_signature_defaults.iteritems(): 00195 key,val = item 00196 keyVal = eval(key) 00197 exec('myparams[key] = keyVal') 00198 if (keyVal == None): 00199 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00200 keyVal = eval(key) 00201 if(type(keyVal) == dict) : 00202 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00203 00204 else : 00205 uselessvariable = None 00206 myparams['infile'] = infile = myf['infile'] 00207 myparams['calmode'] = calmode = myf['calmode'] 00208 myparams['masklist'] = masklist = myf['masklist'] 00209 myparams['blpoly'] = blpoly = myf['blpoly'] 00210 myparams['backup'] = backup = myf['backup'] 00211 myparams['flaglist'] = flaglist = myf['flaglist'] 00212 myparams['antenna'] = antenna = myf['antenna'] 00213 myparams['spw'] = spw = myf['spw'] 00214 myparams['stokes'] = stokes = myf['stokes'] 00215 myparams['createimage'] = createimage = myf['createimage'] 00216 myparams['outfile'] = outfile = myf['outfile'] 00217 myparams['imsize'] = imsize = myf['imsize'] 00218 myparams['cell'] = cell = myf['cell'] 00219 myparams['phasecenter'] = phasecenter = myf['phasecenter'] 00220 myparams['ephemsrcname'] = ephemsrcname = myf['ephemsrcname'] 00221 myparams['pointingcolumn'] = pointingcolumn = myf['pointingcolumn'] 00222 myparams['gridfunction'] = gridfunction = myf['gridfunction'] 00223 myparams['plotlevel'] = plotlevel = myf['plotlevel'] 00224 00225 if type(masklist)==int: masklist=[masklist] 00226 if type(flaglist)==int: flaglist=[flaglist] 00227 if type(imsize)==int: imsize=[imsize] 00228 if type(cell)==float: cell=[cell] 00229 00230 result = None 00231 00232 # 00233 # The following is work around to avoid a bug with current python translation 00234 # 00235 mytmp = {} 00236 00237 mytmp['infile'] = infile 00238 mytmp['calmode'] = calmode 00239 mytmp['masklist'] = masklist 00240 mytmp['blpoly'] = blpoly 00241 mytmp['backup'] = backup 00242 mytmp['flaglist'] = flaglist 00243 mytmp['antenna'] = antenna 00244 mytmp['spw'] = spw 00245 mytmp['stokes'] = stokes 00246 mytmp['createimage'] = createimage 00247 mytmp['outfile'] = outfile 00248 mytmp['imsize'] = imsize 00249 if type(cell) == str : 00250 mytmp['cell'] = casac.quanta().quantity(cell) 00251 else : 00252 mytmp['cell'] = cell 00253 mytmp['phasecenter'] = phasecenter 00254 mytmp['ephemsrcname'] = ephemsrcname 00255 mytmp['pointingcolumn'] = pointingcolumn 00256 mytmp['gridfunction'] = gridfunction 00257 mytmp['plotlevel'] = plotlevel 00258 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00259 trec = casac.utils().torecord(pathname+'sdtpimaging.xml') 00260 00261 casalog.origin('sdtpimaging') 00262 if not trec.has_key('sdtpimaging') or not casac.utils().verify(mytmp, trec['sdtpimaging']) : 00263 return False 00264 00265 00266 try : 00267 casalog.post('') 00268 casalog.post('##########################################') 00269 casalog.post('##### Begin Task: sdtpimaging #####') 00270 casalog.post('') 00271 result = sdtpimaging(infile, calmode, masklist, blpoly, backup, flaglist, antenna, spw, stokes, createimage, outfile, imsize, cell, phasecenter, ephemsrcname, pointingcolumn, gridfunction, plotlevel) 00272 casalog.post('') 00273 casalog.post('##### End Task: sdtpimaging #####') 00274 casalog.post('##########################################') 00275 00276 00277 # saveinputs for individule engine has no use 00278 # saveinputs should alos be removed from casa_in_py.py 00279 # 00280 # 00281 # saveinputs = myf['saveinputs'] 00282 # saveinputs('sdtpimaging', 'sdtpimaging.last', myparams) 00283 # 00284 # 00285 except Exception, instance: 00286 #print '**** Error **** ',instance 00287 pass 00288 00289 gc.collect() 00290 return result 00291 # 00292 # 00293 ## 00294 # def paramgui(self, useGlobals=True): 00295 # """ 00296 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00297 # """ 00298 # import paramgui 00299 # 00300 # a=inspect.stack() 00301 # stacklevel=0 00302 # for k in range(len(a)): 00303 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00304 # stacklevel=k 00305 # break 00306 # myf = sys._getframe(stacklevel).f_globals 00307 # 00308 # if useGlobals: 00309 # paramgui.setGlobals(myf) 00310 # else: 00311 # paramgui.setGlobals({}) 00312 # 00313 # paramgui.runTask('sdtpimaging', myf['_ip']) 00314 # paramgui.setGlobals({}) 00315 # 00316 # 00317 # 00318 # 00319 def defaults(self, param=None): 00320 a=inspect.stack() 00321 stacklevel=0 00322 for k in range(len(a)): 00323 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00324 stacklevel=k 00325 break 00326 myf=sys._getframe(stacklevel).f_globals 00327 a = odict() 00328 a['infile'] = '' 00329 a['calmode'] = 'none' 00330 a['flaglist'] = [] 00331 a['antenna'] = '' 00332 a['spw'] = 0 00333 a['stokes'] = '' 00334 a['createimage'] = False 00335 a['plotlevel'] = 0 00336 00337 a['async']=False 00338 a['calmode'] = { 00339 0:{'value':'none'}, 00340 1:odict([{'value':'baseline'}, {'masklist':[]}, {'blpoly':1}, {'backup':True}])} 00341 a['createimage'] = { 00342 0:{'value':False}, 00343 1:odict([{'value':True}, {'outfile':''}, {'imsize':[256, 256]}, {'cell':[1, 1]}, {'phasecenter':''}, {'ephemsrcname':''}, {'pointingcolumn':'direction'}, {'gridfunction':'BOX'}])} 00344 00345 ### This function sets the default values but also will return the list of 00346 ### parameters or the default value of a given parameter 00347 if(param == None): 00348 myf['__set_default_parameters'](a) 00349 elif(param == 'paramkeys'): 00350 return a.keys() 00351 else: 00352 if(a.has_key(param)): 00353 #if(type(a[param]) == dict) : 00354 # return a[param][len(a[param])-1]['value'] 00355 #else : 00356 return a[param] 00357 00358 00359 # 00360 # 00361 def check_params(self, param=None, value=None): 00362 a=inspect.stack() 00363 stacklevel=0 00364 for k in range(len(a)): 00365 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00366 stacklevel=k 00367 break 00368 myf=sys._getframe(stacklevel).f_globals 00369 00370 # print 'param:', param, 'value:', value 00371 try : 00372 if str(type(value)) != "<type 'instance'>" : 00373 value0 = value 00374 value = myf['cu'].expandparam(param, value) 00375 matchtype = False 00376 if(type(value) == numpy.ndarray): 00377 if(type(value) == type(value0)): 00378 myf[param] = value.tolist() 00379 else: 00380 #print 'value:', value, 'value0:', value0 00381 #print 'type(value):', type(value), 'type(value0):', type(value0) 00382 myf[param] = value0 00383 if type(value0) != list : 00384 matchtype = True 00385 else : 00386 myf[param] = value 00387 value = myf['cu'].verifyparam({param:value}) 00388 if matchtype: 00389 value = False 00390 except Exception, instance: 00391 #ignore the exception and just return it unchecked 00392 myf[param] = value 00393 return value 00394 00395 # 00396 # 00397 def description(self, key='sdtpimaging', subkey=None): 00398 desc={'sdtpimaging': 'SD task: do a simple calibration and imaging for total power data ', 00399 'infile': 'name of input SD dataset(only MS is allowed for this task)', 00400 'calmode': 'SD calibration mode (currently only support none or baseline subtraction )', 00401 'masklist': 'mask in data row numbers to be included for baseline fitting for each scan', 00402 'blpoly': 'polynomial order for the baseline fit', 00403 'backup': 'set True to create backup for input data', 00404 'flaglist': 'list of scan numbers to flag (e.g. [[1,3], 80])', 00405 'antenna': 'antenna name(s) or id(s)', 00406 'spw': 'spectral window id for imaging', 00407 'stokes': 'stokes or correlation name (e.g. "I", "XX")', 00408 'createimage': 'do imaging?', 00409 'outfile': 'output image name', 00410 'imsize': 'x and y image size in pixels, symmetric for single value', 00411 'cell': 'x and y cell size. default unit arcmin', 00412 'phasecenter': 'Image phase center: position or field index', 00413 'ephemsrcname': 'ephemeris source name', 00414 'pointingcolumn': 'pointing data column to use', 00415 'gridfunction': 'gridding function for imaging ("BOX","SF","PB")', 00416 'plotlevel': 'plot results (0=none,1+=some,<0=hardcopy)', 00417 00418 'async': 'If true the taskname must be started using sdtpimaging(...)' 00419 } 00420 00421 # 00422 # Set subfields defaults if needed 00423 # 00424 00425 if(desc.has_key(key)) : 00426 return desc[key] 00427 00428 def itsdefault(self, paramname) : 00429 a = {} 00430 a['infile'] = '' 00431 a['calmode'] = 'none' 00432 a['masklist'] = [] 00433 a['blpoly'] = 1 00434 a['backup'] = True 00435 a['flaglist'] = [] 00436 a['antenna'] = '' 00437 a['spw'] = 0 00438 a['stokes'] = '' 00439 a['createimage'] = False 00440 a['outfile'] = '' 00441 a['imsize'] = [256, 256] 00442 a['cell'] = ['1.0arcmin', '1.0arcmin'] 00443 a['phasecenter'] = '' 00444 a['ephemsrcname'] = '' 00445 a['pointingcolumn'] = 'direction' 00446 a['gridfunction'] = 'BOX' 00447 a['plotlevel'] = 0 00448 00449 if a.has_key(paramname) : 00450 return a[paramname] 00451 sdtpimaging_pg = sdtpimaging_pg_()