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 casac 00010 import string 00011 import time 00012 import inspect 00013 import gc 00014 import numpy 00015 from odict import odict 00016 from taskmanager import tm 00017 from task_autoclean import autoclean 00018 class autoclean_cli_: 00019 __name__ = "autoclean" 00020 __async__ = {} 00021 rkey = None 00022 i_am_a_casapy_task = None 00023 # The existence of the i_am_a_casapy_task attribute allows help() 00024 # (and other) to treat casapy tasks as a special case. 00025 00026 def __init__(self) : 00027 self.__bases__ = (autoclean_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'vis':None, 'imagename':None, 'field':None, 'spw':None, 'selectdata':None, 'timerange':None, 'uvrange':None, 'antenna':None, 'scan':None, 'mode':None, 'nchan':None, 'start':None, 'width':None, 'interpolation':None, 'doconcat':None, 'psfmode':None, 'imagermode':None, 'cyclefactor':None, 'cyclespeedup':None, 'imsize':None, 'cell':None, 'phasecenter':None, 'restfreq':None, 'stokes':None, 'weighting':None, 'robust':None, 'noise':None, 'npixels':None, 'interactive':None, 'mask':None, 'modelimage':None, 'uvtaper':None, 'outertaper':None, 'innertaper':None, 'niter':None, 'npercycle':None, 'npercycle_speedup':None, 'gain':None, 'pbcor':None, 'minpb':None, 'clean_threshold':None, 'Nrms':None, 'eps_maxres':None, 'useabsresid':None, 'allow_maxres_inc':None, 'island_rms':None, 'diag':None, 'peak_rms':None, 'gain_threshold':None, 'Npeak':None, 'shape':None, 'boxstretch':None, 'irregsize':None, 'async':None} 00031 00032 00033 def result(self, key=None): 00034 #### here we will scan the task-ids in __async__ 00035 #### and add any that have completed... 00036 if key is not None and self.__async__.has_key(key) and self.__async__[key] is not None: 00037 ret = tm.retrieve(self.__async__[key]) 00038 if ret['state'] == "done" : 00039 self.__async__[key] = None 00040 elif ret['state'] == 'crashed' : 00041 self.__async__[key] = None 00042 return ret 00043 return None 00044 00045 00046 def __call__(self, vis=None, imagename=None, field=None, spw=None, selectdata=None, timerange=None, uvrange=None, antenna=None, scan=None, mode=None, nchan=None, start=None, width=None, interpolation=None, doconcat=None, psfmode=None, imagermode=None, cyclefactor=None, cyclespeedup=None, imsize=None, cell=None, phasecenter=None, restfreq=None, stokes=None, weighting=None, robust=None, noise=None, npixels=None, interactive=None, mask=None, modelimage=None, uvtaper=None, outertaper=None, innertaper=None, niter=None, npercycle=None, npercycle_speedup=None, gain=None, pbcor=None, minpb=None, clean_threshold=None, Nrms=None, eps_maxres=None, useabsresid=None, allow_maxres_inc=None, island_rms=None, diag=None, peak_rms=None, gain_threshold=None, Npeak=None, shape=None, boxstretch=None, irregsize=None, async=None): 00047 00048 """CLEAN an image with automatically-chosen clean regions. 00049 This is a wrapper for clean which includes automatic clean boxing. 00050 Current capabilities include: 00051 00052 1) Multi-frequency-continuum images or spectral channel imaging 00053 2) Stokes I imaging only 00054 3) Use starting mask 00055 00056 00057 vis -- Name of input visibility file 00058 default: none; example: vis='ngc5921.ms' 00059 imagename -- Pre-name of output images: 00060 default: none; example: imagename='m2' 00061 output images are: 00062 m2.image; cleaned and restored image 00063 With or without primary beam correction 00064 m2.psf; point-spread function (dirty beam) 00065 m2.flux; relative sky sensitivity over field 00066 m2.mask; total clean regions 00067 m2.model; image of clean components 00068 m2.residual; image of residuals 00069 field -- Select fields in mosaic. Use field id(s) or field name(s). 00070 ['go listobs' to obtain the list id's or names] 00071 default: ''= all fields 00072 If field string is a non-negative integer, it is assumed to 00073 be a field index otherwise, it is assumed to be a 00074 field name 00075 field='0~2'; field ids 0,1,2 00076 field='0,4,5~7'; field ids 0,4,5,6,7 00077 field='3C286,3C295'; field named 3C286 and 3C295 00078 field = '3,4C*'; field id 3, all names starting with 4C 00079 spw -- Select spectral window/channels 00080 NOTE: This selects the data passed as the INPUT to mode 00081 default: ''=all spectral windows and channels 00082 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 00083 spw='0:5~61'; spw 0, channels 5 to 61 00084 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00085 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, 00086 channels 3 to 45. 00087 spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each. 00088 spw='0:0~10;15~60'; spectral window 0 with channels 00089 0-10,15-60 00090 spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10, 00091 spw 1, channels 20-30, and spw 2, channels, 1,2 and 3 00092 selectdata -- Other data selection parameters 00093 default: True 00094 00095 >>> selectdata=True expandable parameters 00096 See help par.selectdata for more on these 00097 00098 timerange -- Select data based on time range: 00099 default: '' (all); examples, 00100 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' 00101 Note: if YYYY/MM/DD is missing date defaults to first 00102 day in data set 00103 timerange='09:14:0~09:54:0' picks 40 min on first day 00104 timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 00105 30min on NEXT day 00106 timerange='09:44:00' pick data within one integration 00107 of time 00108 timerange='>10:24:00' data after this time 00109 uvrange -- Select data within uvrange (default units meters) 00110 default: '' (all); example: 00111 uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda 00112 uvrange='>4klambda';uvranges greater than 4 kilo lambda 00113 antenna -- Select data based on antenna/baseline 00114 default: '' (all) 00115 If antenna string is a non-negative integer, it is 00116 assumed to be an antenna index, otherwise, it is 00117 considered an antenna name. 00118 antenna='5&6'; baseline between antenna index 5 and 00119 index 6. 00120 antenna='VA05&VA06'; baseline between VLA antenna 5 00121 and 6. 00122 antenna='5&6;7&8'; baselines 5-6 and 7-8 00123 antenna='5'; all baselines with antenna index 5 00124 antenna='05'; all baselines with antenna number 05 00125 (VLA old name) 00126 antenna='5,6,9'; all baselines with antennas 5,6,9 00127 index numbers 00128 scan -- Scan number range. 00129 default: '' (all) 00130 example: scan='1~5' 00131 Check 'go listobs' to insure the scan numbers are in 00132 order. 00133 mode -- Frequency Specification: 00134 NOTE: Channels deselected with spw parameter will contain all 00135 zeros. 00136 See examples below. 00137 default: 'mfs' 00138 mode = 'mfs' means produce one image from all 00139 specified data. 00140 mode = 'channel'; Use with nchan, start, width to specify 00141 output image cube. See examples below 00142 mode = 'velocity', means channels are specified in 00143 velocity. 00144 mode = 'frequency', means channels are specified in 00145 frequency. 00146 00147 >>> mode expandable parameters (for modes other than 'mfs') 00148 Start, width are given in units of channels, frequency 00149 or velocity as indicated by mode (note: only nearest neighbour 00150 interpolation is available at this time). 00151 nchan -- Number of channels (planes) in output image 00152 default: 1; example: nchan=3 00153 start -- Start input channel (relative-0) 00154 default=0; example: start=5 00155 width -- Output channel width in units of the input 00156 channel width (>1 indicates channel averaging) 00157 default=1; example: width=4 00158 interpolation -- Interpolation type of spectral data when gridded on 00159 the uv-plane 00160 default = 'linear' 00161 doconcat -- Tells autoclean to concatenate multiple channel images into 00162 single image at the end of its run. (Autoclean makes an image 00163 for each channel, and cleans/boxes them one at a time.) 00164 default = 'True' 00165 examples: 00166 spw = '0,1'; mode = 'mfs' 00167 will produce one image made from all channels in spw 00168 0 and 1 00169 spw='0:5~28^2'; mode = 'mfs' 00170 will produce one image made with channels 00171 (5,7,9,...,25,27) 00172 spw = '0'; mode = 'channel': nchan=3; start=5; width=4 00173 will produce an image with 3 output planes 00174 plane 1 contains data from channels (5+6+7+8) 00175 plane 2 contains data from channels (9+10+11+12) 00176 plane 3 contains data from channels (13+14+15+16) 00177 spw = '0:0~63^3'; mode='channel'; nchan=21; start = 0; 00178 width = 1 00179 will produce an image with 20 output planes 00180 Plane 1 contains data from channel 0 00181 Plane 2 contains date from channel 2 00182 Plane 21 contains data from channel 61 00183 spw = '0:0~40^2'; mode = 'channel'; nchan = 3; start = 00184 5; width = 4 00185 will produce an image with three output planes 00186 plane 1 contains channels (5,7) 00187 plane 2 contains channels (13,15) 00188 plane 3 contains channels (21,23) 00189 00190 psfmode -- method of PSF calculation to use during minor cycles: 00191 default: 'clark': Options: 'clark','clarkstokes', 'hogbom' 00192 'clark' use smaller beam (faster, usually good enough); 00193 for stokes images clean components peaks are searched in the I^2+Q^2+U^2+V^2 domain 00194 'clarkstokes' locate clean components independently in each stokes image 00195 'hogbom' full-width of image (slower, better for poor 00196 uv-coverage) 00197 Note: psfmode will be used to clean is imagermode = '' 00198 imagermode -- Advanced imaging e.g mosaic or Cotton-Schwab clean 00199 default: imagermode='': Options: '', 'csclean' 00200 default '' => psfmode cleaning algorithm used 00201 00202 >>> imagermode='csclean' expandable parameter(s): 00203 Image using the Cotton-Schwab algorithm in between major cycles 00204 cyclefactor -- Change the threshold at which 00205 the deconvolution cycle will stop, degrid 00206 and subtract from the visibilities. For 00207 poor PSFs, reconcile often (cyclefactor=4 or 00208 5); For good PSFs, use cyclefactor 1.5 to 00209 2.0. Note: threshold = cyclefactor * max 00210 sidelobe * max residual. 00211 default: 1.5; example: cyclefactor=4 00212 cyclespeedup -- Cycle threshold doubles in this 00213 number of iterations default: -1; 00214 example: cyclespeedup=3 00215 try cyclespeedup = 50 to speed up cleaning 00216 00217 imsize -- Image pixel size (x,y). DOES NOT HAVE TO BE A POWER OF 2 00218 default = [256,256]; example: imsize=[350,350] 00219 imsize = 500 is equivalent to [500,500] 00220 Avoid odd-numbered imsize. 00221 cell -- Cell size (x,y) 00222 default= '1.0arcsec'; 00223 example: cell=['0.5arcsec,'0.5arcsec'] or 00224 cell=['1arcmin', '1arcmin'] 00225 cell = '1arcsec' is equivalent to ['1arcsec','1arcsec'] 00226 NOTE:cell = 2.0 => ['2arcsec', '2arcsec'] 00227 phasecenter -- direction measure or fieldid for the mosaic center 00228 default: '' => first field selected ; example: phasecenter=6 00229 or phasecenter='J2000 19h30m00 -40d00m00' 00230 restfreq -- Specify rest frequency to use for output image 00231 default='' Occasionally it is necessary to set this (for 00232 example some VLA spectral line data). For example for 00233 NH_3 (1,1) put restfreq='23.694496GHz' 00234 stokes -- Stokes parameters to image 00235 default='I'; example: stokes='IQUV'; 00236 Options: 'I','IV''QU','IQUV','RR','LL','XX','YY','RRLL','XXYY' 00237 00238 weighting -- Weighting to apply to visibilities: 00239 default='natural'; example: weighting='uniform'; 00240 Options: 'natural','uniform','briggs', 00241 'superuniform','briggsabs','radial' 00242 00243 >>> Weighting expandable parameters 00244 For weighting='briggs' and 'briggsabs' 00245 robust -- Brigg's robustness parameter 00246 default=0.0; example: robust=0.5; 00247 Options: -2.0 to 2.0; -2 (uniform)/+2 (natural) 00248 For weighting='briggsabs' 00249 noise -- noise parameter to use for Briggs "abs" 00250 weighting 00251 example noise='1.0mJy' 00252 npixels -- uv-cell area used for weight calculation 00253 example npixels=1 00254 Default = 0 00255 superuniform: 0 Means 3x3 cells for weighting 00256 the cell weight is proportional to the weight of 00257 the 3x3 cells centered on it. 00258 superuniform = F means 1x1 cell for averaging weights. 00259 briggs/briggsabs: 0 is similar to 1x1 cell weight. 00260 1 may? be similar to 3X3 cells. 00261 Only npixels 0 or 1 recommended 00262 00263 mask -- Initial specification of cleanbox(es), mask image(s), and/or 00264 region(s) to be used for CLEANing. For channel data (image cubes), 00265 any initial mask will be applied to every channel. mask default: 00266 [] (no masking); Possible specification types: (a) Explicit 00267 cleanbox pixel ranges example: mask=[110,110,150,145] clean 00268 region with blc=110,100; trc=150,145 (pixel values) (b) 00269 Filename with cleanbox pixel values with ascii format: 00270 example: mask='mycleanbox.txt' <fieldid blc-x blc-y 00271 trc-x trc-y> on each line 00272 1 45 66 123 124 00273 2 23 100 300 340 00274 (c) Filename for image mask example: mask='myimage.mask' 00275 (d) Filename for region specification (e.g. from viewer) 00276 example: mask='myregion.rgn' (e) Combinations of any of the 00277 above example: mask=[[110,110,150,145],'mycleanbox.txt', 00278 'myimage.mask','myregion.rgn'] 00279 If include outlier fields, then mask need to be spefied in 00280 nested lists: e.g. mask=[[[110,110,150,145],'myimage.mask'],[],[20,20,40,40]] 00281 (A clean box with [110,110,150,145] and a image mask for main field, 00282 no mask for 1st outlier field, 1 clean box for second outlier field.) 00283 modelimage -- Name of model image(s) to initialize cleaning. If 00284 multiple images, then these will be added together to 00285 form initial starting model NOTE: these are in addition 00286 to any initial model in the <imagename>.model image file 00287 default: '' (none); example: modelimage='orion.model' 00288 modelimage=['orion.model','sdorion.image'] Note: if the 00289 units in the image are Jy/beam as in a single-dish 00290 image, then it will be converted to Jy/pixel as in a 00291 model image, using the restoring beam in the image 00292 header 00293 >>> uvtaper=True expandable parameters 00294 outertaper -- uv-taper on outer baselines in uv-plane 00295 [bmaj, bmin, bpa] taper Gaussian scale in uv or 00296 angular units. NOTE: uv taper in (klambda) is roughly on-sky 00297 FWHM(arcsec/200) 00298 default: outertaper=[]; no outer taper applied 00299 example: outertaper=['5klambda'] circular taper 00300 FWHM=5 kilo-lambda 00301 outertaper=['5klambda','3klambda','45.0deg'] 00302 outertaper=['10arcsec'] on-sky FWHM 10" 00303 outertaper=['300.0'] default units are meters 00304 in aperture plane 00305 innertaper -- uv-taper in center of uv-plane 00306 [bmaj,bmin,bpa] Gaussian scale at which taper falls to 00307 zero at uv=0 00308 default: innertaper=[]; no inner taper applied 00309 NOT YET IMPLEMENTED 00310 niter -- Maximum number iterations over all clean iterations. 00311 default: 500; example: niter=5000 00312 npercycle -- Number of clean minor cycles before making new clean region 00313 selection. 00314 default: 100; example: npercycle = 100 00315 npercycle_speedup: If no new clean regions found during an iteration of 00316 clean region selections, increase npercycle by this factor. 00317 (Npercycle returns to initial value if new clean regions are later 00318 found.) 00319 default: 1.5; example: npercycle_speedup = 2 00320 gain -- Loop gain for CLEANing 00321 default: 0.1; example: gain=0.5 00322 pbcor -- Output primary beam-corrected image 00323 default: pbcor=False; output un-corrected image 00324 example: pbcor=True; output pb-corrected image (masked outside 00325 minpb) Note: if you set pbcor=False, you can later 00326 recover the pbcor image by dividing by the .flux image 00327 (e.g. using immath) 00328 minpb -- Minimum PB level to use default=0.1; 00329 The flux image is used to determine this 00330 except for the case of mosaic with ft='mosaic' 00331 where the flux.pbcoverage image is used. 00332 example: 00333 minpb=0.01 Note: this minpb is always in effect 00334 (regardless of pbcor=True/False) 00335 clean_threshold -- Flux level at which to stop CLEANing 00336 default: '0.0mJy'; 00337 example: threshold='2.3mJy' (always include units) 00338 threshold = '0.0023Jy' 00339 threshold = '0.0023Jy/beam' (okay also) 00340 Nrms -- Stop cleaning when maximum residual is below this value times 00341 the current rms (outside the current clean regions). 00342 default: 6 00343 example: Nrms=4 00344 eps_maxres -- Convergence parameter to stop cleaning: stop if maximum 00345 residual has changed by less than a factor of eps_maxres. 00346 default: 0.01 (one per cent change) 00347 example: eps_maxres = 0.05 00348 allow_maxres_inc -- Parameter to stop cleaning: stop if maximum residual 00349 has increased between clean iterations this number of times. 00350 default: 3 00351 example: allow_maxres_inc = 2 00352 island_rms: threshold (this value times current rms) at which to box the 00353 residual image when searching for new clean regions 00354 default: 4 00355 example: island_rms = 3 00356 diag: T/F switch to declare if pixels connected on the diagonal belong 00357 to the same island, when selecting pixels for clean boxing 00358 default: False 00359 example: diag = True 00360 peak_rms: threshold (this value times current rms) for peak pixel flux 00361 to qualify an island for clean boxing 00362 default: 6 00363 example: peak_rms = 5 00364 gain_threshold: threshold (this value times current maximum residual) of 00365 peak pixel in island to qualify island for clean boxing. 00366 default: 0.1 00367 example: gain_threshold = 0.5 00368 Npeak: maximum number of new clean regions to add each iteration 00369 default: 3 00370 example: Npeak = 5 00371 shape: parameter to determine shape of clean regions. 00372 0: all circles 00373 1: all boxes 00374 2: choose according to island shape (circles if island has similar 00375 dimension in x and y direction, box otherwise) 00376 default: 1 00377 example: shape=2 00378 boxstretch: number of pixels to increase outward size of clean region, 00379 can range from -1 to 5. 00380 default: 1 00381 example: boxstretch = 3 00382 irregsize: for islands this large (dimension in pixels) or larger, fill 00383 in mask with island's actual shape rather than using a box or 00384 circle. Set to 0 to ignore this parameter. 00385 default: 100 00386 example: irregsize = 50 00387 00388 00389 """ 00390 if not hasattr(self, "__globals__") or self.__globals__ == None : 00391 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00392 #casac = self.__globals__['casac'] 00393 casalog = self.__globals__['casalog'] 00394 #casalog = casac.casac.logsink() 00395 self.__globals__['__last_task'] = 'autoclean' 00396 self.__globals__['taskname'] = 'autoclean' 00397 ### 00398 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00399 ### 00400 ### 00401 #Handle globals or user over-ride of arguments 00402 # 00403 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00404 useLocalDefaults = False 00405 00406 for item in function_signature_defaults.iteritems(): 00407 key,val = item 00408 keyVal = eval(key) 00409 if (keyVal == None): 00410 #user hasn't set it - use global/default 00411 pass 00412 else: 00413 #user has set it - use over-ride 00414 if (key != 'self') : 00415 useLocalDefaults = True 00416 00417 myparams = {} 00418 if useLocalDefaults : 00419 for item in function_signature_defaults.iteritems(): 00420 key,val = item 00421 keyVal = eval(key) 00422 exec('myparams[key] = keyVal') 00423 self.parameters[key] = keyVal 00424 if (keyVal == None): 00425 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00426 keyVal = eval(key) 00427 if(type(keyVal) == dict) : 00428 if len(keyVal) > 0 : 00429 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00430 else : 00431 exec('myparams[key] = ' + key + ' = {}') 00432 00433 else : 00434 async = self.parameters['async'] 00435 myparams['vis'] = vis = self.parameters['vis'] 00436 myparams['imagename'] = imagename = self.parameters['imagename'] 00437 myparams['field'] = field = self.parameters['field'] 00438 myparams['spw'] = spw = self.parameters['spw'] 00439 myparams['selectdata'] = selectdata = self.parameters['selectdata'] 00440 myparams['timerange'] = timerange = self.parameters['timerange'] 00441 myparams['uvrange'] = uvrange = self.parameters['uvrange'] 00442 myparams['antenna'] = antenna = self.parameters['antenna'] 00443 myparams['scan'] = scan = self.parameters['scan'] 00444 myparams['mode'] = mode = self.parameters['mode'] 00445 myparams['nchan'] = nchan = self.parameters['nchan'] 00446 myparams['start'] = start = self.parameters['start'] 00447 myparams['width'] = width = self.parameters['width'] 00448 myparams['interpolation'] = interpolation = self.parameters['interpolation'] 00449 myparams['doconcat'] = doconcat = self.parameters['doconcat'] 00450 myparams['psfmode'] = psfmode = self.parameters['psfmode'] 00451 myparams['imagermode'] = imagermode = self.parameters['imagermode'] 00452 myparams['cyclefactor'] = cyclefactor = self.parameters['cyclefactor'] 00453 myparams['cyclespeedup'] = cyclespeedup = self.parameters['cyclespeedup'] 00454 myparams['imsize'] = imsize = self.parameters['imsize'] 00455 myparams['cell'] = cell = self.parameters['cell'] 00456 myparams['phasecenter'] = phasecenter = self.parameters['phasecenter'] 00457 myparams['restfreq'] = restfreq = self.parameters['restfreq'] 00458 myparams['stokes'] = stokes = self.parameters['stokes'] 00459 myparams['weighting'] = weighting = self.parameters['weighting'] 00460 myparams['robust'] = robust = self.parameters['robust'] 00461 myparams['noise'] = noise = self.parameters['noise'] 00462 myparams['npixels'] = npixels = self.parameters['npixels'] 00463 myparams['interactive'] = interactive = self.parameters['interactive'] 00464 myparams['mask'] = mask = self.parameters['mask'] 00465 myparams['modelimage'] = modelimage = self.parameters['modelimage'] 00466 myparams['uvtaper'] = uvtaper = self.parameters['uvtaper'] 00467 myparams['outertaper'] = outertaper = self.parameters['outertaper'] 00468 myparams['innertaper'] = innertaper = self.parameters['innertaper'] 00469 myparams['niter'] = niter = self.parameters['niter'] 00470 myparams['npercycle'] = npercycle = self.parameters['npercycle'] 00471 myparams['npercycle_speedup'] = npercycle_speedup = self.parameters['npercycle_speedup'] 00472 myparams['gain'] = gain = self.parameters['gain'] 00473 myparams['pbcor'] = pbcor = self.parameters['pbcor'] 00474 myparams['minpb'] = minpb = self.parameters['minpb'] 00475 myparams['clean_threshold'] = clean_threshold = self.parameters['clean_threshold'] 00476 myparams['Nrms'] = Nrms = self.parameters['Nrms'] 00477 myparams['eps_maxres'] = eps_maxres = self.parameters['eps_maxres'] 00478 myparams['useabsresid'] = useabsresid = self.parameters['useabsresid'] 00479 myparams['allow_maxres_inc'] = allow_maxres_inc = self.parameters['allow_maxres_inc'] 00480 myparams['island_rms'] = island_rms = self.parameters['island_rms'] 00481 myparams['diag'] = diag = self.parameters['diag'] 00482 myparams['peak_rms'] = peak_rms = self.parameters['peak_rms'] 00483 myparams['gain_threshold'] = gain_threshold = self.parameters['gain_threshold'] 00484 myparams['Npeak'] = Npeak = self.parameters['Npeak'] 00485 myparams['shape'] = shape = self.parameters['shape'] 00486 myparams['boxstretch'] = boxstretch = self.parameters['boxstretch'] 00487 myparams['irregsize'] = irregsize = self.parameters['irregsize'] 00488 00489 if type(imsize)==int: imsize=[imsize] 00490 if type(cell)==float: cell=[cell] 00491 if type(outertaper)==str: outertaper=[outertaper] 00492 if type(innertaper)==str: innertaper=[innertaper] 00493 00494 result = None 00495 00496 # 00497 # The following is work around to avoid a bug with current python translation 00498 # 00499 mytmp = {} 00500 00501 mytmp['vis'] = vis 00502 mytmp['imagename'] = imagename 00503 mytmp['field'] = field 00504 mytmp['spw'] = spw 00505 mytmp['selectdata'] = selectdata 00506 mytmp['timerange'] = timerange 00507 mytmp['uvrange'] = uvrange 00508 mytmp['antenna'] = antenna 00509 mytmp['scan'] = scan 00510 mytmp['mode'] = mode 00511 mytmp['nchan'] = nchan 00512 mytmp['start'] = start 00513 mytmp['width'] = width 00514 mytmp['interpolation'] = interpolation 00515 mytmp['doconcat'] = doconcat 00516 mytmp['psfmode'] = psfmode 00517 mytmp['imagermode'] = imagermode 00518 mytmp['cyclefactor'] = cyclefactor 00519 mytmp['cyclespeedup'] = cyclespeedup 00520 mytmp['imsize'] = imsize 00521 if type(cell) == str : 00522 mytmp['cell'] = casac.casac.qa.quantity(cell) 00523 else : 00524 mytmp['cell'] = cell 00525 mytmp['phasecenter'] = phasecenter 00526 mytmp['restfreq'] = restfreq 00527 mytmp['stokes'] = stokes 00528 mytmp['weighting'] = weighting 00529 mytmp['robust'] = robust 00530 mytmp['noise'] = noise 00531 mytmp['npixels'] = npixels 00532 mytmp['interactive'] = interactive 00533 mytmp['mask'] = mask 00534 mytmp['modelimage'] = modelimage 00535 mytmp['uvtaper'] = uvtaper 00536 mytmp['outertaper'] = outertaper 00537 mytmp['innertaper'] = innertaper 00538 mytmp['niter'] = niter 00539 mytmp['npercycle'] = npercycle 00540 mytmp['npercycle_speedup'] = npercycle_speedup 00541 mytmp['gain'] = gain 00542 mytmp['pbcor'] = pbcor 00543 mytmp['minpb'] = minpb 00544 if type(clean_threshold) == str : 00545 mytmp['clean_threshold'] = casac.casac.qa.quantity(clean_threshold) 00546 else : 00547 mytmp['clean_threshold'] = clean_threshold 00548 mytmp['Nrms'] = Nrms 00549 mytmp['eps_maxres'] = eps_maxres 00550 mytmp['useabsresid'] = useabsresid 00551 mytmp['allow_maxres_inc'] = allow_maxres_inc 00552 mytmp['island_rms'] = island_rms 00553 mytmp['diag'] = diag 00554 mytmp['peak_rms'] = peak_rms 00555 mytmp['gain_threshold'] = gain_threshold 00556 mytmp['Npeak'] = Npeak 00557 mytmp['shape'] = shape 00558 mytmp['boxstretch'] = boxstretch 00559 mytmp['irregsize'] = irregsize 00560 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00561 trec = casac.casac.utils().torecord(pathname+'autoclean.xml') 00562 00563 casalog.origin('autoclean') 00564 try : 00565 #if not trec.has_key('autoclean') or not casac.casac.utils().verify(mytmp, trec['autoclean']) : 00566 #return False 00567 00568 casac.casac.utils().verify(mytmp, trec['autoclean'], True) 00569 scriptstr=[''] 00570 saveinputs = self.__globals__['saveinputs'] 00571 saveinputs('autoclean', 'autoclean.last', myparams, self.__globals__,scriptstr=scriptstr) 00572 if async : 00573 count = 0 00574 keybase = time.strftime("%y%m%d.%H%M%S") 00575 key = keybase + "_" + str(count) 00576 while self.__async__.has_key(key) : 00577 count += 1 00578 key = keybase + "_" + str(count) 00579 result = tm.execute('autoclean', vis, imagename, field, spw, selectdata, timerange, uvrange, antenna, scan, mode, nchan, start, width, interpolation, doconcat, psfmode, imagermode, cyclefactor, cyclespeedup, imsize, cell, phasecenter, restfreq, stokes, weighting, robust, noise, npixels, interactive, mask, modelimage, uvtaper, outertaper, innertaper, niter, npercycle, npercycle_speedup, gain, pbcor, minpb, clean_threshold, Nrms, eps_maxres, useabsresid, allow_maxres_inc, island_rms, diag, peak_rms, gain_threshold, Npeak, shape, boxstretch, irregsize) 00580 print "Use: " 00581 print " tm.retrieve(return_value) # to retrieve the status" 00582 print 00583 self.rkey = key 00584 self.__async__[key] = result 00585 else : 00586 tname = 'autoclean' 00587 spaces = ' '*(18-len(tname)) 00588 casalog.post('\n##########################################'+ 00589 '\n##### Begin Task: ' + tname + spaces + ' #####') 00590 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00591 result = autoclean(vis, imagename, field, spw, selectdata, timerange, uvrange, antenna, scan, mode, nchan, start, width, interpolation, doconcat, psfmode, imagermode, cyclefactor, cyclespeedup, imsize, cell, phasecenter, restfreq, stokes, weighting, robust, noise, npixels, interactive, mask, modelimage, uvtaper, outertaper, innertaper, niter, npercycle, npercycle_speedup, gain, pbcor, minpb, clean_threshold, Nrms, eps_maxres, useabsresid, allow_maxres_inc, island_rms, diag, peak_rms, gain_threshold, Npeak, shape, boxstretch, irregsize) 00592 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00593 '\n##########################################') 00594 00595 except Exception, instance: 00596 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00597 raise 00598 else : 00599 #print '**** Error **** ',instance 00600 tname = 'autoclean' 00601 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00602 pass 00603 00604 gc.collect() 00605 return result 00606 # 00607 # 00608 # 00609 def paramgui(self, useGlobals=True, ipython_globals=None): 00610 """ 00611 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00612 """ 00613 import paramgui 00614 if not hasattr(self, "__globals__") or self.__globals__ == None : 00615 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00616 00617 if useGlobals: 00618 if ipython_globals == None: 00619 myf=self.__globals__ 00620 else: 00621 myf=ipython_globals 00622 00623 paramgui.setGlobals(myf) 00624 else: 00625 paramgui.setGlobals({}) 00626 00627 paramgui.runTask('autoclean', myf['_ip']) 00628 paramgui.setGlobals({}) 00629 00630 # 00631 # 00632 # 00633 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 00634 if not hasattr(self, "__globals__") or self.__globals__ == None : 00635 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00636 if ipython_globals == None: 00637 myf=self.__globals__ 00638 else: 00639 myf=ipython_globals 00640 00641 a = odict() 00642 a['vis'] = '' 00643 a['imagename'] = '' 00644 a['field'] = '' 00645 a['spw'] = '' 00646 a['selectdata'] = True 00647 a['mode'] = 'mfs' 00648 a['psfmode'] = 'clark' 00649 a['imagermode'] = '' 00650 a['imsize'] = [256, 256] 00651 a['cell'] = ['1.0arcsec'] 00652 a['phasecenter'] = '' 00653 a['restfreq'] = '' 00654 a['stokes'] = 'I' 00655 a['weighting'] = 'natural' 00656 a['interactive'] = False 00657 a['mask'] = [] 00658 a['modelimage'] = '' 00659 a['uvtaper'] = False 00660 a['niter'] = 500 00661 a['npercycle'] = 100 00662 a['npercycle_speedup'] = 1.5 00663 a['gain'] = 0.1 00664 a['pbcor'] = False 00665 a['minpb'] = 0.1 00666 a['clean_threshold'] = '0.0mJy' 00667 a['Nrms'] = 6 00668 a['eps_maxres'] = 0.01 00669 a['useabsresid'] = False 00670 a['allow_maxres_inc'] = 3 00671 a['island_rms'] = 4 00672 a['diag'] = False 00673 a['peak_rms'] = 6 00674 a['gain_threshold'] = 0.1 00675 a['Npeak'] = 3 00676 a['shape'] = 1 00677 a['boxstretch'] = 1 00678 a['irregsize'] = 100 00679 00680 a['async']=False 00681 a['selectdata'] = { 00682 0:{'value':False}, 00683 1:odict([{'value':True}, {'timerange':''}, {'uvrange':''}, {'antenna':''}, {'scan':''}])} 00684 a['mode'] = { 00685 0:odict([{'value':'mfs'}, {'nterms':1}, {'reffreq':''}]), 00686 1:odict([{'value':'channel'}, {'nchan':1}, {'start':0}, {'width':1}, {'interpolation':'linear'}, {'doconcat':True}]), 00687 2:odict([{'value':'velocity'}, {'nchan':1}, {'start':'0.0km/s'}, {'width':'1km/s'}, {'interpolation':'linear'}, {'doconcat':True}]), 00688 3:odict([{'value':'frequency'}, {'nchan':1}, {'start':'1.4GHz'}, {'width':'10kHz'}, {'interpolation':'linear'}, {'doconcat':True}])} 00689 a['weighting'] = { 00690 0:{'value':'natural'}, 00691 1:{'value':'uniform'}, 00692 2:odict([{'value':'briggs'}, {'robust':0.0}, {'npixels':0}]), 00693 3:odict([{'value':'briggsabs'}, {'robust':0.0}, {'noise':'1.0Jy'}, {'npixels':0}]), 00694 4:odict([{'value':'superuniform'}, {'npixels':0}])} 00695 a['uvtaper'] = { 00696 0:{'value':False}, 00697 1:odict([{'value':True}, {'outertaper':[]}, {'innertaper':[]}])} 00698 a['imagermode'] = { 00699 0:{'value':''}, 00700 1:odict([{'value':'csclean'}, {'cyclefactor':1.5}, {'cyclespeedup':-1}])} 00701 00702 ### This function sets the default values but also will return the list of 00703 ### parameters or the default value of a given parameter 00704 if(param == None): 00705 myf['__set_default_parameters'](a) 00706 elif(param == 'paramkeys'): 00707 return a.keys() 00708 else: 00709 if(paramvalue==None and subparam==None): 00710 if(a.has_key(param)): 00711 return a[param] 00712 else: 00713 return self.itsdefault(param) 00714 else: 00715 retval=a[param] 00716 if(type(a[param])==dict): 00717 for k in range(len(a[param])): 00718 valornotval='value' 00719 if(a[param][k].has_key('notvalue')): 00720 valornotval='notvalue' 00721 if((a[param][k][valornotval])==paramvalue): 00722 retval=a[param][k].copy() 00723 retval.pop(valornotval) 00724 if(subparam != None): 00725 if(retval.has_key(subparam)): 00726 retval=retval[subparam] 00727 else: 00728 retval=self.itsdefault(subparam) 00729 else: 00730 retval=self.itsdefault(subparam) 00731 return retval 00732 00733 00734 # 00735 # 00736 def check_params(self, param=None, value=None, ipython_globals=None): 00737 if ipython_globals == None: 00738 myf=self.__globals__ 00739 else: 00740 myf=ipython_globals 00741 # print 'param:', param, 'value:', value 00742 try : 00743 if str(type(value)) != "<type 'instance'>" : 00744 value0 = value 00745 value = myf['cu'].expandparam(param, value) 00746 matchtype = False 00747 if(type(value) == numpy.ndarray): 00748 if(type(value) == type(value0)): 00749 myf[param] = value.tolist() 00750 else: 00751 #print 'value:', value, 'value0:', value0 00752 #print 'type(value):', type(value), 'type(value0):', type(value0) 00753 myf[param] = value0 00754 if type(value0) != list : 00755 matchtype = True 00756 else : 00757 myf[param] = value 00758 value = myf['cu'].verifyparam({param:value}) 00759 if matchtype: 00760 value = False 00761 except Exception, instance: 00762 #ignore the exception and just return it unchecked 00763 myf[param] = value 00764 return value 00765 # 00766 # 00767 def description(self, key='autoclean', subkey=None): 00768 desc={'autoclean': 'CLEAN an image with automatically-chosen clean regions.', 00769 'vis': 'Name of input visibility file', 00770 'imagename': 'Pre-name of output images', 00771 'field': 'Field Name or id', 00772 'spw': 'Spectral windows:channels e.g. \'0~3:3~100\', \'\' is all', 00773 'selectdata': 'Other data selection parameters', 00774 'timerange': 'Range of time to select from data', 00775 'uvrange': 'Select data within uvrange ', 00776 'antenna': 'Select data based on antenna/baseline', 00777 'scan': 'Scan number range', 00778 'mode': 'Spectral gridding type (mfs, channel, velocity, frequency)', 00779 'nchan': 'Number of channels (planes) in output image', 00780 'start': 'First channel in input to use', 00781 'width': 'Number of input channels to average', 00782 'interpolation': 'Spectral interpolation(nearest, linear, cubic)', 00783 'doconcat': 'Concatenate multiple channels into single final image', 00784 'psfmode': 'Method of PSF calculation to use during minor cycles', 00785 'imagermode': 'Options: \'csclean\' or \'mosaic\', \' \', uses psfmode', 00786 'cyclefactor': 'change depth in between of csclean cycle', 00787 'cyclespeedup': 'Cycle threshold doubles in this number of iteration', 00788 'imsize': 'x and y image size in pixels. Single value: same for both', 00789 'cell': 'x and y cell size(s). Default unit arcsec.', 00790 'phasecenter': 'Image center: direction or field index', 00791 'restfreq': 'Rest frequency to assign to image (see help)', 00792 'stokes': 'Stokes params to image (eg I,IV, QU,IQUV); Current autoclean implementation requires Stokes="I".', 00793 'weighting': 'Weighting of uv (natural, uniform, briggs, ...)', 00794 'robust': 'Briggs robustness parameter', 00795 'noise': 'noise parameter for briggs abs mode weighting', 00796 'npixels': 'number of pixels for superuniform or briggs weighting', 00797 'interactive': 'use interactive clean (with GUI viewer)', 00798 'mask': 'Initial cleanbox(es), mask image(s), and/or region(s) used in cleaning', 00799 'modelimage': 'Name of model image(s) to initialize cleaning', 00800 'uvtaper': 'Apply additional uv tapering of visibilities', 00801 'outertaper': 'uv-taper on outer baselines in uv-plane', 00802 'innertaper': 'uv-taper in center of uv-plane (not implemented)', 00803 'niter': 'Max number of total clean cycles per channel', 00804 'npercycle': 'Clean iterations before adding new clean boxes', 00805 'npercycle_speedup': 'Increase npercycle by this factor if no new regions found.', 00806 'gain': 'Loop gain for cleaning', 00807 'pbcor': 'Output primary beam-corrected image', 00808 'minpb': 'Minimum PB level to use', 00809 'clean_threshold': 'Flux level to stop cleaning. Must include units.', 00810 'Nrms': 'Threshold to stop cleaning: current rms * Nrms', 00811 'eps_maxres': 'Stop cleaning if max abs(residual) changes by less than this factor', 00812 'useabsresid': 'If True, use absolute value of residual to test for clean convergence.', 00813 'allow_maxres_inc': 'Stop cleaning if max abs(residual) increases this many times (set to -1 to ignore)', 00814 'island_rms': 'Threshold for islands when finding clean regions: current rms * island_rms', 00815 'diag': 'Count diagonal connection as same island?', 00816 'peak_rms': 'Threshold to add new clean box: peak in island must be at least current rms * peak_rms', 00817 'gain_threshold': 'Threshold to add new clean box: peak in island must be at least current max residual * gain_threshold', 00818 'Npeak': 'Max number of new clean regions to add in each iteration.', 00819 'shape': 'Shape of clean regions: 0 for circles, 1 for boxes, 2 for both.', 00820 'boxstretch': 'Increase clean region size by this many pixels beyond island size.', 00821 'irregsize': 'For regions this large (in pixels), use irregular clean region.', 00822 00823 'async': 'If true the taskname must be started using autoclean(...)' 00824 } 00825 00826 # 00827 # Set subfields defaults if needed 00828 # 00829 if(subkey == 'channel'): 00830 desc['start'] = 'First channel to use (0=first channel specified in spw)' 00831 if(subkey == 'velocity'): 00832 desc['start'] = 'Velocity of first image channel: e.g \'0.0km/s\'' 00833 if(subkey == 'velocity'): 00834 desc['width'] = 'image channel width in velocity units: e.g \'1.0km/s\'' 00835 if(subkey == 'frequency'): 00836 desc['start'] = 'Frequency of first image channel: e.q. \'1.4GHz\'' 00837 if(subkey == 'frequency'): 00838 desc['width'] = 'Image channel width in frequency units: e.g \'1.0kHz\'' 00839 if(subkey == 'briggs'): 00840 desc['npixels'] = 'number of pixels to determine uv-cell size 0=> field of view' 00841 if(subkey == 'briggsabs'): 00842 desc['npixels'] = 'number of pixels to determine uv-cell size 0=> field of view' 00843 if(subkey == 'superuniform'): 00844 desc['npixels'] = 'number of pixels to determine uv-cell size 0=> +/-3pixels' 00845 00846 if(desc.has_key(key)) : 00847 return desc[key] 00848 00849 def itsdefault(self, paramname) : 00850 a = {} 00851 a['vis'] = '' 00852 a['imagename'] = '' 00853 a['field'] = '' 00854 a['spw'] = '' 00855 a['selectdata'] = True 00856 a['timerange'] = '' 00857 a['uvrange'] = '' 00858 a['antenna'] = '' 00859 a['scan'] = '' 00860 a['mode'] = 'mfs' 00861 a['nchan'] = 1 00862 a['start'] = 0 00863 a['width'] = 1 00864 a['interpolation'] = 'linear' 00865 a['doconcat'] = True 00866 a['psfmode'] = 'clark' 00867 a['imagermode'] = '' 00868 a['cyclefactor'] = 1.5 00869 a['cyclespeedup'] = -1 00870 a['imsize'] = [256, 256] 00871 a['cell'] = ['1.0arcsec'] 00872 a['phasecenter'] = '' 00873 a['restfreq'] = '' 00874 a['stokes'] = 'I' 00875 a['weighting'] = 'natural' 00876 a['robust'] = 0.0 00877 a['noise'] = '1.0Jy' 00878 a['npixels'] = 0 00879 a['interactive'] = False 00880 a['mask'] = [] 00881 a['modelimage'] = '' 00882 a['uvtaper'] = False 00883 a['outertaper'] = [''] 00884 a['innertaper'] = ['1.0'] 00885 a['niter'] = 500 00886 a['npercycle'] = 100 00887 a['npercycle_speedup'] = 1.5 00888 a['gain'] = 0.1 00889 a['pbcor'] = False 00890 a['minpb'] = 0.1 00891 a['clean_threshold'] = '0.0mJy' 00892 a['Nrms'] = 6 00893 a['eps_maxres'] = 0.01 00894 a['useabsresid'] = False 00895 a['allow_maxres_inc'] = 3 00896 a['island_rms'] = 4 00897 a['diag'] = False 00898 a['peak_rms'] = 6 00899 a['gain_threshold'] = 0.1 00900 a['Npeak'] = 3 00901 a['shape'] = 1 00902 a['boxstretch'] = 1 00903 a['irregsize'] = 100 00904 00905 #a = sys._getframe(len(inspect.stack())-1).f_globals 00906 00907 if self.parameters['selectdata'] == True: 00908 a['timerange'] = '' 00909 a['uvrange'] = '' 00910 a['antenna'] = '' 00911 a['scan'] = '' 00912 00913 if self.parameters['mode'] == 'mfs': 00914 a['nterms'] = 1 00915 a['reffreq'] = '' 00916 00917 if self.parameters['mode'] == 'channel': 00918 a['nchan'] = 1 00919 a['start'] = 0 00920 a['width'] = 1 00921 a['interpolation'] = 'linear' 00922 a['doconcat'] = True 00923 00924 if self.parameters['mode'] == 'velocity': 00925 a['nchan'] = 1 00926 a['start'] = '0.0km/s' 00927 a['width'] = '1km/s' 00928 a['interpolation'] = 'linear' 00929 a['doconcat'] = True 00930 00931 if self.parameters['mode'] == 'frequency': 00932 a['nchan'] = 1 00933 a['start'] = '1.4GHz' 00934 a['width'] = '10kHz' 00935 a['interpolation'] = 'linear' 00936 a['doconcat'] = True 00937 00938 if self.parameters['weighting'] == 'briggs': 00939 a['robust'] = 0.0 00940 a['npixels'] = 0 00941 00942 if self.parameters['weighting'] == 'briggsabs': 00943 a['robust'] = 0.0 00944 a['noise'] = '1.0Jy' 00945 a['npixels'] = 0 00946 00947 if self.parameters['weighting'] == 'superuniform': 00948 a['npixels'] = 0 00949 00950 if self.parameters['uvtaper'] == True: 00951 a['outertaper'] = [] 00952 a['innertaper'] = [] 00953 00954 if self.parameters['imagermode'] == 'csclean': 00955 a['cyclefactor'] = 1.5 00956 a['cyclespeedup'] = -1 00957 00958 if a.has_key(paramname) : 00959 return a[paramname] 00960 autoclean_cli = autoclean_cli_()