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_clean import clean 00018 class clean_cli_: 00019 __name__ = "clean" 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__ = (clean_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'vis':None, 'imagename':None, 'outlierfile':None, 'field':None, 'spw':None, 'selectdata':None, 'timerange':None, 'uvrange':None, 'antenna':None, 'scan':None, 'observation':None, 'mode':None, 'gridmode':None, 'wprojplanes':None, 'facets':None, 'cfcache':None, 'painc':None, 'aterm':None, 'psterm':None, 'wbawp':None, 'epjtable':None, 'interpolation':None, 'niter':None, 'gain':None, 'threshold':None, 'psfmode':None, 'imagermode':None, 'ftmachine':None, 'mosweight':None, 'scaletype':None, 'multiscale':None, 'negcomponent':None, 'smallscalebias':None, 'interactive':None, 'mask':None, 'nchan':None, 'start':None, 'width':None, 'outframe':None, 'veltype':None, 'imsize':None, 'cell':None, 'phasecenter':None, 'restfreq':None, 'stokes':None, 'weighting':None, 'robust':None, 'uvtaper':None, 'outertaper':None, 'innertaper':None, 'modelimage':None, 'restoringbeam':None, 'pbcor':None, 'minpb':None, 'usescratch':None, 'noise':None, 'npixels':None, 'npercycle':None, 'cyclefactor':None, 'cyclespeedup':None, 'nterms':None, 'reffreq':None, 'chaniter':None, 'flatnoise':None, 'allowchunk':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, outlierfile=None, field=None, spw=None, selectdata=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, mode=None, gridmode=None, wprojplanes=None, facets=None, cfcache=None, painc=None, aterm=None, psterm=None, wbawp=None, epjtable=None, interpolation=None, niter=None, gain=None, threshold=None, psfmode=None, imagermode=None, ftmachine=None, mosweight=None, scaletype=None, multiscale=None, negcomponent=None, smallscalebias=None, interactive=None, mask=None, nchan=None, start=None, width=None, outframe=None, veltype=None, imsize=None, cell=None, phasecenter=None, restfreq=None, stokes=None, weighting=None, robust=None, uvtaper=None, outertaper=None, innertaper=None, modelimage=None, restoringbeam=None, pbcor=None, minpb=None, usescratch=None, noise=None, npixels=None, npercycle=None, cyclefactor=None, cyclespeedup=None, nterms=None, reffreq=None, chaniter=None, flatnoise=None, allowchunk=None, async=None): 00047 00048 """Invert and deconvolve images with selected algorithm 00049 The clean task has many options: 00050 00051 1) Make 'dirty' image and 'dirty' beam (psf) 00052 2) Multi-frequency-continuum images or spectral channel imaging 00053 3) Full Stokes imaging 00054 4) Mosaicking of several pointings 00055 5) Multi-scale cleaning 00056 6) Widefield cleaning 00057 7) Interactive clean boxing 00058 8) Use starting model (eg from single dish) 00059 00060 00061 vis -- Name(s) of input visibility file(s) 00062 default: none; 00063 example: vis='ngc5921.ms' 00064 vis=['ngc5921a.ms','ngc5921b.ms']; multiple MSes 00065 imagename -- Pre-name of output images: 00066 default: none; example: imagename='m2' 00067 output images are: 00068 m2.image; cleaned and restored image 00069 With or without primary beam correction 00070 m2.psf; point-spread function (dirty beam) 00071 m2.flux; relative sky sensitivity over field 00072 m2.flux.pbcoverage; relative pb coverage over field 00073 (gets created only for ft='mosaic') 00074 m2.model; image of clean components 00075 m2.residual; image of residuals 00076 m2.interactive.mask; image containing clean regions 00077 To include outlier fields: 00078 imagename=['n5921','outlier1','outlier2'] 00079 outlierfile --- Text file name which contains image names, sizes, field 00080 centers (See 'HINTS ON CLEAN WITH FLANKING FIELDS' below 00081 for the format of this outlier file.) 00082 field -- Select fields to image or mosaic. Use field id(s) or name(s). 00083 ['go listobs' to obtain the list id's or names] 00084 default: ''= all fields 00085 If field string is a non-negative integer, it is assumed to 00086 be a field index otherwise, it is assumed to be a 00087 field name 00088 field='0~2'; field ids 0,1,2 00089 field='0,4,5~7'; field ids 0,4,5,6,7 00090 field='3C286,3C295'; field named 3C286 and 3C295 00091 field = '3,4C*'; field id 3, all names starting with 4C 00092 For multiple MS input, a list of field strings can be used: 00093 field = ['0~2','0~4']; field ids 0-2 for the first MS and 0-4 00094 for the second 00095 field = '0~2'; field ids 0-2 for all input MSes 00096 spw -- Select spectral window/channels 00097 NOTE: channels de-selected here will contain all zeros if 00098 selected by the parameter mode subparameters. 00099 default: ''=all spectral windows and channels 00100 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 00101 spw='0:5~61'; spw 0, channels 5 to 61 00102 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00103 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, 00104 channels 3 to 45. 00105 spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each. 00106 For multiple MS input, a list of spw strings can be used: 00107 spw=['0','0~3']; spw ids 0 for the first MS and 0-3 for the second 00108 spw='0~3' spw ids 0-3 for all input MS 00109 spw='3:10~20;50~60' for multiple channel ranges within spw id 3 00110 spw='3:10~20;50~60,4:0~30' for different channel ranges for spw ids 3 and 4 00111 spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10, 00112 spw 1, channels 20-30, and spw 2, channels, 1,2 and 3 00113 spw='1~4;6:15~48' for channels 15 through 48 for spw ids 1,2,3,4 and 6 00114 00115 selectdata -- Other data selection parameters 00116 default: True 00117 00118 >>> selectdata=True expandable parameters 00119 See help par.selectdata for more on these 00120 00121 timerange -- Select data based on time range: 00122 default: '' (all); examples, 00123 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' 00124 Note: if YYYY/MM/DD is missing date defaults to first 00125 day in data set 00126 timerange='09:14:0~09:54:0' picks 40 min on first day 00127 timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 00128 30min on NEXT day 00129 timerange='09:44:00' pick data within one integration 00130 of time 00131 timerange='>10:24:00' data after this time 00132 For multiple MS input, a list of timerange strings can be 00133 used: 00134 timerange=['09:14:0~09:54:0','>10:24:00'] 00135 timerange='09:14:0~09:54:0''; apply the same timerange for 00136 all input MSes 00137 uvrange -- Select data within uvrange (default units meters) 00138 default: '' (all); example: 00139 uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda 00140 uvrange='>4klambda';uvranges greater than 4 kilo lambda 00141 For multiple MS input, a list of uvrange strings can be 00142 used: 00143 uvrange=['0~1000klambda','100~1000klamda'] 00144 uvrange='0~1000klambda'; apply 0-1000 kilo-lambda for all 00145 input MSes 00146 antenna -- Select data based on antenna/baseline 00147 default: '' (all) 00148 If antenna string is a non-negative integer, it is 00149 assumed to be an antenna index, otherwise, it is 00150 considered an antenna name. 00151 antenna='5&6'; baseline between antenna index 5 and 00152 index 6. 00153 antenna='VA05&VA06'; baseline between VLA antenna 5 00154 and 6. 00155 antenna='5&6;7&8'; baselines 5-6 and 7-8 00156 antenna='5'; all baselines with antenna index 5 00157 antenna='05'; all baselines with antenna number 05 00158 (VLA old name) 00159 antenna='5,6,9'; all baselines with antennas 5,6,9 00160 index number 00161 For multiple MS input, a list of antenna strings can be 00162 used: 00163 antenna=['5','5&6']; 00164 antenna='5'; antenna index 5 for all input MSes 00165 scan -- Scan number range. 00166 default: '' (all) 00167 example: scan='1~5' 00168 For multiple MS input, a list of scan strings can be used: 00169 scan=['0~100','10~200'] 00170 scan='0~100; scan ids 0-100 for all input MSes 00171 Check 'go listobs' to insure the scan numbers are in order. 00172 observation -- Observation ID range. 00173 default: '' (all) 00174 example: observation='1~5' 00175 mode -- Frequency Specification: 00176 NOTE: Channels deselected with spw parameter will contain all 00177 zeros. 00178 See examples below. 00179 default: 'mfs' 00180 mode = 'mfs' means produce one image from all 00181 specified data. 00182 mode = 'channel'; Use with nchan, start, width to specify 00183 output image cube. 00184 mode = 'velocity', channels are specified in velocity. 00185 mode = 'frequency', channels are specified in frequency. 00186 00187 >>> mode='mfs' expandable parameters 00188 Make a continuum image from the selected frequency 00189 channels/range using Multi-frequency synthesis 00190 algorithm for wide-band narrow field imaging. 00191 mode='mfs' examples: 00192 spw = '0,1'; mode = 'mfs' 00193 will produce one image made from all channels in spw 00194 0 and 1 00195 spw='0:5~28^2'; mode = 'mfs' 00196 will produce one image made with channels 00197 (5,7,9,...,25,27) 00198 00199 nterms -- Number of Taylor terms to be used to model the 00200 frequency dependence of the sky emission. nterms=1 is 00201 equivalent to assuming no frequency dependence. 00202 nterms>1 runs the MS-MFS algorithm, and the choice of nterms 00203 should depend on the expected shape and SNR of the spectral 00204 structure, across the chosen bandwidth. Output images 00205 represent taylor-coefficients of the sky spectrum 00206 (images with file-name extensions of tt0,tt1,etc). 00207 A spectral index map is also computed as the ratio of the 00208 first two terms (following the convention of I(nu) = I(ref_nu) x (nu/nu_0)^alpha). 00209 Additionally, a spectral-index error image is made 00210 by treating taylor-coefficient residuals as errors, and propagating 00211 them through the division used to compute spectral-index. 00212 It is meant to be a guide to which parts of the spectral-index 00213 image to trust, and the values may not always represent a 00214 statistically-correct error. 00215 00216 For more details about this algorithm, please refer to 00217 "A multi-scale multi-frequency deconvolution algorithm for synthesis 00218 imaging in radio interferometry", Rau and Cornwell, AA, Volume 532, 2011 00219 00220 ** Note that the software implementation of the MS-MFS algorithm 00221 for nterms>1 currently does not allow combination with 00222 mosaics, and pbcor.** 00223 00224 reffreq -- The reference frequency (for nterms>1) about which 00225 the Taylor expansion is done. reffreq='' defaults to the 00226 middle frequency of the selected range. 00227 00228 >>> mode='channel', 'velocity', and 'frequency' expandable parameters 00229 00230 nchan -- Total number of channels in the output image. 00231 Example: nchan=100. 00232 Default: -1; Automatically selects enough channels to cover 00233 data selected by 'spw' consistent with 'start' and 'width'. 00234 It is often easiest to leave nchan at the default value. 00235 00236 start -- First channel, velocity, or frequency. 00237 For mode='channel'; This selects the channel index number 00238 from the MS (0 based) that you want to correspond to the 00239 first channel of the output cube. The output cube will be 00240 in frequency space with the first channel having the 00241 frequency of the MS channel selected by start. start=0 00242 refers to the first channel in the first selected spw, even 00243 if that channel is de-selected in the spw parameter. 00244 Channels de-selected by the spw parameter will be filled with 00245 zeros if included by the start parameter. For example, 00246 spw=3~8:3~100 and start=2 will produce a cube that starts on 00247 the third channel (recall 0 based) of spw index 3, and the 00248 first channel will be blank. 00249 example:start=5 00250 For mode='velocity' or 'frequency': default=''; 00251 starts at first input channel of first input spw 00252 examples: start='5.0km/s', or start='22.3GHz'. 00253 00254 width -- Output channel width 00255 For mode='channel', default=1; >1 indicates channel averaging 00256 example: width=4. 00257 For mode= 'velocity' or 'frequency', default=''; width of 00258 first input channel, or more precisely, the difference 00259 in frequencies between the first two selected channels. 00260 -- For example if channels 1 and 3 are selected with spw, 00261 then the default width will be the difference between their 00262 frequencies, and not the width of channel 1. 00263 -- Similarly, if the selected data has uneven channel-spacing, 00264 the default width will be picked from the first two selected 00265 channels. In this case, please specify the desired width. 00266 When specifying the width, one must give units 00267 examples: width='1.0km/s', or width='24.2kHz'. 00268 Setting width>0 gives channels of increasing frequency for 00269 mode='frequency', and increasing velocity for mode='velocity'. 00270 00271 interpolation -- Interpolation type for spectral gridding onto 00272 the uv-plane. Options: 'nearest', 'linear', or 'cubic'. 00273 default = 'linear' 00274 Note : 'linear' and 'cubic' interpolation requires data 00275 points on both sides of each image frequency. Errors 00276 are therefore possible at edge channels, or near 00277 flagged data channels. 00278 For mode='channel', please use 'nearest'. 00279 00280 chaniter -- specify how spectral CLEAN is performed, 00281 default: chaniter=False; 00282 example: chaniter=True; step through channels 00283 00284 outframe -- For mode='velocity', 'frequency', or 'channel': 00285 velocity reference frame of output image 00286 Options: '','LSRK','LSRD','BARY','GEO','TOPO','GALACTO', 00287 'LGROUP','CMB' 00288 default: ''; same as input data 00289 example: frame='bary' for Barycentric frame 00290 00291 veltype -- for mode='velocity' gives the velocity definition 00292 Options: 'radio','optical' 00293 default: 'radio' 00294 NOTE: the viewer always defaults to displaying the 'radio' 00295 frame, but that can be changed in the position tracking 00296 pull down. 00297 00298 mode='channel' examples: 00299 spw = '0'; mode = 'channel': nchan=3; start=5; width=4 00300 will produce an image with 3 output planes 00301 plane 1 contains data from channels (5+6+7+8) 00302 plane 2 contains data from channels (9+10+11+12) 00303 plane 3 contains data from channels (13+14+15+16) 00304 spw = '0:0~63^3'; mode='channel'; nchan=21; start = 0; 00305 width = 1 00306 will produce an image with 20 output planes 00307 Plane 1 contains data from channel 0 00308 Plane 2 contains date from channel 2 00309 Plane 21 contains data from channel 61 00310 spw = '0:0~40^2'; mode = 'channel'; nchan = 3; start = 00311 5; width = 4 00312 will produce an image with three output planes 00313 plane 1 contains channels (5,7) 00314 plane 2 contains channels (13,15) 00315 plane 3 contains channels (21,23) 00316 00317 psfmode -- method of PSF calculation to use during minor cycles: 00318 default: 'clark': Options: 'clark','clarkstokes', 'hogbom' 00319 'clark' use smaller beam (faster, usually good enough); 00320 for stokes images clean components peaks are searched 00321 in the I^2+Q^2+U^2+V^2 domain 00322 'clarkstokes' locate clean components independently in 00323 each stokes image 00324 'hogbom' full-width of image (slower, better for poor 00325 uv-coverage) 00326 Note: psfmode will also be used to clean if imagermode = '' 00327 imagermode -- Advanced imaging e.g. mosaic or Cotton-Schwab clean 00328 default: imagermode='csclean': Options: '', 'csclean', 'mosaic' 00329 '' => psfmode cleaning algorithm used 00330 NOTE: imagermode 'mosaic' (and/or) any gridmode not blank 00331 (and/or) nterms>1 : will always use CS style clean. 00332 00333 >>> gridmode='' expandable parameters 00334 The default value of '' has no effect. 00335 00336 >>> gridmode='widefield' expandable parameters 00337 Apply corrections for non-coplanar effects during imaging 00338 using the W-Projection algorithm (Cornwell et al. IEEE JSTSP 00339 (2008)) or faceting or a combination of the two. 00340 00341 wprojplanes is the number of pre-computed w-planes used for 00342 the W-Projection algorithm. wprojplanes=1 disables 00343 correction for non-coplanar effects. 00344 facets is the number of facets on each side of the image 00345 (i.e. the total number of facets is 'facets x facets'). 00346 If wprojplanes>1, W-Projection is done for each facet. 00347 00348 >>> gridmode='aprojection' expandable parameters 00349 Corrects for the (E)VLA time-varying PB effects 00350 including polarization squint using the A-Projection 00351 algorithm (Bhatnagar et al., AandA, 487, 419 (2008)). 00352 This can optinally include w-projection also. 00353 00354 wprojplanes is the number of pre-computed w-planes used 00355 for W-Projection algorithm. wprojplanes=1 diables 00356 correction for non-coplanar effects. 00357 00358 cfcache is the name of the directory to store the 00359 convolution functions and weighted sensitivty pattern 00360 function. 00361 00362 00363 00364 00365 painc (in degrees) is the Parallactic Angle increment 00366 used to compute the convolution functions. 00367 00368 >>> imagermode='mosaic' expandable parameter(s): 00369 Make a mosaic of the different pointings (uses csclean style 00370 too) 00371 mosweight -- Individually weight the fields of the mosaic 00372 default: False; example: mosweight=True 00373 This can be useful if some of your fields are more 00374 sensitive than others (i.e. due to time spent 00375 on-source); this parameter will give more weight to 00376 higher sensitivity fields in the overlap regions. 00377 ftmachine -- Gridding method for the mosaic; 00378 Options: 'ft' (standard interferometric gridding), 'sd' 00379 (standard single dish), 00380 and 'mosaic' (grid using PB as convolution function). 00381 default: 'mosaic'; 00382 ONLY if imagermode='mosaic' is chosen and 00383 ftmachine='mosaic', is heterogeneous imaging (CARMA, ALMA) 00384 possible using the right convolution of primary beams for 00385 each baseline. 00386 scaletype -- Controls scaling of pixels in the image plane. 00387 (controls what is seen if interactive=True) 00388 It does *not* affect the scaling of the *final* image - 00389 that is done by pbcor. 00390 default='SAULT'; example: scaletype='PBCOR' 00391 Options: 'PBCOR','SAULT' 00392 'SAULT' when interactive=True shows the residual 00393 with constant noise across the mosaic. 00394 Can also be achieved by setting pbcor=False. 00395 'PBCOR' uses the SAULT scaling scheme for 00396 deconvolution, but if interactive=True shows the 00397 primary beam corrected image during interactive. 00398 00399 cyclefactor -- Controls the threshhold at which the 00400 deconvolution cycle will pause to degrid and subtract the 00401 model from the visibilities. 00402 With poor PSFs, reconcile often (cyclefactor=4 or 5) for 00403 reliability. 00404 With good PSFs, use cyclefactor = 1.5 to 2.0 for speed. 00405 Note: threshold = cyclefactor * max sidelobe * max residual 00406 default: 1.5; example: cyclefactor=4 00407 cyclespeedup -- The major cycle threshold doubles in this 00408 number of iterations. 00409 Default: -1 (no doubling) 00410 Example: cyclespeedup=3 00411 Try cyclespeedup = 50 to speed up cleaning. 00412 00413 flatnoise -- Controls whether searching for clean components 00414 is done in a constant noise residual image (True) or in an 00415 optimal signal-to-noise residual image (False) when 00416 ftmosaic='mosaic' is chosen. 00417 default=True 00418 00419 >>> imagermode='csclean' expandable parameter(s): 00420 Image using the Cotton-Schwab algorithm in between major cycles 00421 00422 cyclefactor -- See above, under imagermode='mosaic'. 00423 cyclespeedup -- See above, under imagermode='mosaic'. 00424 00425 multiscale -- set of scales to use in deconvolution. If set, 00426 cleans with several resolutions using Hogbom clean. The 00427 scale sizes are in units of cellsize. So if 00428 cell='2arcsec', a multiscale scale=10 => 20arcsec. The 00429 first scale is recommended to be 0 (point), we suggest the 00430 second be on the order of synthesized beam, the third 3-5 00431 times the synthesized beam, etc.. Avoid making the largest 00432 scale too large relative to the image width or the scale of 00433 the lowest measured spatial frequency. For example, if the 00434 synthesized beam is 10" FWHM and cell=2", try 00435 multiscale = [0,5,15]. 00436 00437 default: multiscale=[] (standard CLEAN with psfmode algorithm, 00438 no multi-scale). 00439 Example: multiscale = [0,5,15] 00440 00441 >>> multiscale expandable parameter(s): 00442 negcomponent -- Stop component search when the largest scale 00443 has found this number of negative components; 00444 -1 means continue component search even if the largest 00445 component is negative. default: -1; example: negcomponent=50 00446 smallscalebias -- A bias toward smaller scales. 00447 The peak flux found at each scale is weighted by 00448 a factor = 1 - smallscalebias*scale/max_scale, so 00449 that Fw = F*factor. 00450 Typically the values range from 0.2 to 1.0. 00451 default: 0.6 00452 00453 imsize -- Image size in pixels (x, y). DOES NOT HAVE TO BE A POWER 00454 OF 2 (but has to be even and factorizable to 2,3,5,7 only). 00455 default = [256,256]; example: imsize=[350,350] 00456 imsize = 500 is equivalent to [500,500] 00457 If include outlier fields, e.g., [[400,400],[100,100]] or 00458 use outlierfile. 00459 Avoid odd-numbered imsize. 00460 cell -- Cell size (x,y) 00461 default= '1.0arcsec'; 00462 example: cell=['0.5arcsec,'0.5arcsec'] or 00463 cell=['1arcmin', '1arcmin'] 00464 cell = '1arcsec' is equivalent to ['1arcsec','1arcsec'] 00465 NOTE:cell = 2.0 => ['2arcsec', '2arcsec'] 00466 phasecenter -- direction measure or fieldid for the mosaic center 00467 default: '' => first field selected ; 00468 example: phasecenter=6 00469 phasecenter='J2000 19h30m00 -40d00m00' 00470 phasecenter='J2000 292.5deg -40.0deg' 00471 phasecenter='J2000 5.105rad -0.698rad' 00472 If include outlier fields, 00473 e.g. ['J2000 19h30m00 -40d00m00',J2000 19h25m00 -38d40m00'] 00474 or use outlierfile. 00475 restfreq -- Specify rest frequency to use for output image 00476 default='' Occasionally it is necessary to set this (for 00477 example some VLA spectral line data). For example for 00478 NH_3 (1,1) put restfreq='23.694496GHz' 00479 stokes -- Stokes parameters to image 00480 default='I'; example: stokes='IQUV'; 00481 Options: 'I','Q','U','V','IV','QU','IQ','UV','IQU','IUV','IQUV','RR','LL','XX','YY','RRLL','XXYY' 00482 niter -- Maximum number iterations, 00483 if niter=0, then no CLEANing is done ("invert" only). 00484 (niter=0 can be used instead of the 'ft' task to predict/save a model) 00485 default: 500; example: niter=5000 00486 gain -- Loop gain for CLEANing 00487 default: 0.1; example: gain=0.5 00488 threshold -- Flux level at which to stop CLEANing 00489 default: '0.0mJy'; 00490 example: threshold='2.3mJy' (always include units) 00491 threshold = '0.0023Jy' 00492 threshold = '0.0023Jy/beam' (okay also) 00493 interactive -- use interactive clean (with GUI viewer) 00494 default: interactive=False 00495 example: interactive=True 00496 interactive clean allows the user to build the cleaning 00497 mask interactively using the viewer. The viewer will 00498 appear every npercycle interation, but modify as needed 00499 The final interactive mask is saved in the file 00500 imagename_interactive.mask. The initial masks use the 00501 union of mask and cleanbox (see below). 00502 00503 >>> interactive=True expandable parameters 00504 npercycle -- this is the number of iterations between each 00505 interactive update of the mask. It is important to modify 00506 this number interactively during the cleaning, starting with 00507 a low number like 20, but then increasing as more extended 00508 emission is encountered. 00509 00510 mask -- Specification of cleanbox(es), mask image(s), primary beam 00511 coverage level, and/or region(s) to be used for CLEANing. 00512 CLEAN tends to perform better, and is less likely to diverge, 00513 if the CLEAN component placement is limited by a mask to where 00514 real emission is expected to be. As long as the image has the 00515 same shape (size), mask images (e.g. from a previous interactive 00516 session) can be used for a new execution. NOTE: the initial 00517 clean mask actually used is the union of what is specified in mask 00518 and <imagename>.mask 00519 default: [] or '' : no masking; Possible specification types: 00520 (a) Cleanboxes, specified using the CASA region format 00521 (http://casaguides.nrao.edu/index.php?title=CASA_Region_Format) 00522 Example : mask='box [ [ 100pix , 130pix] , [120pix, 150pix ] ]' 00523 mask='circle [ [ 120pix , 40pix] ,6pix ]' 00524 mask='circle[[19h58m52.7s,+40d42m06.04s ], 30.0arcsec]' 00525 If used with a spectral cube, it will apply to all channels. 00526 Multiple regions may be specified as a list of pixel ranges. 00527 Example : mask= ['circle [ [ 120pix , 40pix] ,6pix ]', 00528 'box [ [ 100pix , 130pix] , [120pix, 150pix ] ]' ] 00529 (b) Filename with cleanbox shapes defined using the CASA region format. 00530 Example: mask='mycleanbox.txt' 00531 The file 'mycleanbox.txt' contains : 00532 box [ [ 100pix , 130pix ] , [ 120pix, 150pix ] ] 00533 circle [ [ 150pix , 150pix] ,10pix ] 00534 rotbox [ [ 60pix , 50pix ] , [ 30pix , 30pix ] , 30deg ] 00535 (c) Filename for image mask. Example: mask='myimage.mask' 00536 Multiple mask files may be specified. 00537 example : mask=[ 'mask1.mask', 'mask2.mask' ] 00538 (d) Filename for region specification (e.g. from viewer). 00539 Example: mask='myregion.rgn' 00540 (e) Combinations of the above options. 00541 Example: mask=['mycleanbox.txt', 'myimage.mask', 00542 'myregion.rgn','circle [ [ 120pix , 40pix] ,6pix ]'] 00543 (f) Threshold on primary-beam. 00544 A number between 0 and 1, used as a threshhold of primary 00545 beam coverage. The primary beam coverage map (imagename + 00546 '.flux(.pbcoverage)') will be made and the CLEAN component 00547 placement will be limited to where it is > the number. 00548 (g) True or False. 00549 True: like (f), but use minpb as the number. 00550 False: go maskless (and expect trouble). 00551 (For masks for multiple fields, please see 'HINTS ON CLEAN WITH FLANKING FIELDS' below) 00552 00553 uvtaper -- Apply additional uv tapering of the visibilities. 00554 default: uvtaper=False; example: uvtaper=True 00555 00556 >>> uvtaper=True expandable parameters 00557 outertaper -- uv-taper on outer baselines in uv-plane 00558 [bmaj, bmin, bpa] taper Gaussian scale in uv or 00559 angular units. NOTE: the on-sky FWHM in arcsec is roughly 00560 the uv taper/200 (klambda). 00561 default: outertaper=[]; no outer taper applied 00562 example: outertaper=['5klambda'] circular taper 00563 FWHM=5 kilo-lambda 00564 outertaper=['5klambda','3klambda','45.0deg'] 00565 outertaper=['10arcsec'] on-sky FWHM 10 arcseconds 00566 outertaper=['300.0'] default units are meters 00567 in aperture plane 00568 innertaper -- uv-taper in center of uv-plane 00569 [bmaj,bmin,bpa] Gaussian scale at which taper falls to 00570 zero at uv=0 00571 default: innertaper=[]; no inner taper applied 00572 NOT YET IMPLEMENTED 00573 modelimage -- Name of model image(s) to initialize cleaning. If 00574 multiple images, then these will be added together to 00575 form initial staring model NOTE: these are in addition 00576 to any initial model in the <imagename>.model image file 00577 default: '' (none); example: modelimage='orion.model' 00578 modelimage=['orion.model','sdorion.image'] Note: if the 00579 units in the image are Jy/beam as in a single-dish 00580 image, then it will be converted to Jy/pixel as in a 00581 model image, using the restoring beam in the image 00582 header. 00583 When nterms>1, a one-to-one mapping is done between images 00584 in this list and Taylor-coefficients. If more than nterms 00585 images are specified, only the first nterms are used. 00586 It is valid to supply fewer than nterms model images. 00587 Example : Supply an estimate of the continuum flux from a 00588 previous imaging run. 00589 weighting -- Weighting to apply to visibilities: 00590 default='natural'; example: weighting='uniform'; 00591 Options: 'natural','uniform','briggs', 00592 'superuniform','briggsabs','radial' 00593 00594 >>> Weighting expandable parameters 00595 For weighting='briggs' and 'briggsabs' 00596 robust -- Brigg's robustness parameter 00597 default=0.0; example: robust=0.5; 00598 Options: -2.0 to 2.0; -2 (uniform)/+2 (natural) 00599 For weighting='briggsabs' 00600 noise -- noise parameter to use for Briggs "abs" 00601 weighting 00602 example noise='1.0mJy' 00603 npixels -- uv-cell area used for weight calculation 00604 example npixels=1 00605 Default = 0 00606 superuniform: 0 Means 3x3 cells for weighting 00607 the cell weight is proportional to the weight of 00608 the 3x3 cells centered on it. 00609 superuniform = F means 1x1 cell for averaging weights. 00610 briggs/briggsabs: 0 is similar to 1x1 cell weight. 00611 1 may? be similar to 3X3 cells. 00612 Only npixels 0 or 1 recommended 00613 00614 restoringbeam -- Output Gaussian restoring beam for CLEAN image 00615 [bmaj, bmin, bpa] elliptical Gaussian restoring beam 00616 default units are in arc-seconds for bmaj,bmin, degrees 00617 for bpa default: restoringbeam=[]; Use PSF calculated 00618 from dirty beam. 00619 example: restoringbeam=['10arcsec'] circular Gaussian 00620 FWHM 10 arcseconds example: 00621 restoringbeam=['10.0','5.0','45.0deg'] 10"x5" 00622 at 45 degrees 00623 00624 pbcor -- Output primary beam-corrected image 00625 If pbcor=False, the final output image is NOT corrected for 00626 the PB pattern (particularly important for mosaics), and 00627 therefore is not "flux correct". Correction can also be 00628 done after the fact using immath to divide 00629 <imagename>.image by the <imagename>.flux image. 00630 default: pbcor=False; output un-corrected image 00631 example: pbcor=True; output pb-corrected image (masked outside 00632 minpb) 00633 00634 minpb -- Minimum PB level to use for pb-correction and pb-based masking. 00635 default=0.2; 00636 example: minpb=0.01 00637 When imagermode is *not* 'mosaic' : 00638 minpb is applied to the flux image (sensitivity-weighted pb). 00639 minpb is used to create a mask, only when pbcor=True 00640 When imagermode='mosaic' : 00641 minpb is applied to the flux.pbcoverage image 00642 (mosaic pb with equal weight per pointing) 00643 minpb is always used to create a mask (regardless of 00644 pbcor=True/False) 00645 00646 usescratch -- if True will create scratch columns if they are 00647 not there. And after clean completes the predicted model 00648 visibility is from the clean components are written to the ms. This increases 00649 the ms size by the data volume. if False then the model is saved in the ms 00650 header and the calculation of the visibilities is done on the fly when using 00651 calibration or plotms. Use True if you want to access the moedl visibilities 00652 in python, say. 00653 00654 allowchunk -- Partition the image cube by channel-chunks. 00655 default=False; 00656 False: Major cycle grids all channels. Minor cycle steps 00657 through all channels before the next major cycle. 00658 True: Major and minor cycles are performed one chunk 00659 at a time, and output images cubes are concatenated. 00660 async -- Run asynchronously 00661 default = False; do not run asychronously 00662 00663 00664 ====================================================================== 00665 00666 HINTS ON CLEAN WITH FLANKING FIELDS 00667 00668 There are two ways of specifying multi-field images for clean. 00669 00670 (a) Task parameters are used to define the first(main) field. 00671 A text file containing definitions of all additional fields is supplied 00672 to the 'outlierfile' task parameter. 00673 00674 This outlier file must contain the following parameters per field 00675 Required : imagename, imsize, phasecenter 00676 Optional : mask, modelimage 00677 The parameter set for each field must begin with 'imagename'. 00678 Parameters can be listed in a single line or span multiple lines. 00679 00680 Example : Three fields. 00681 00682 - Task Inputs : 00683 imagename = 'M1_0' 00684 outlierfile='outlier.txt' 00685 imsize = [1024,1024] 00686 phasecenter = 'J2000 13h27m20.98 43d26m28.0' 00687 00688 - Contents of outlier file 'outlier.txt': 00689 imagename = 'M1_1' 00690 imsize = [128,128] 00691 phasecenter = 'J2000 13h30m52.159 43d23m08.02' 00692 mask = ['out1.mask', 'circle[[40pix,40pix],5pix]' ] 00693 modelimage = 'out1.model' 00694 imagename = 'M1_2' 00695 imsize = [128,128] 00696 phasecenter = 'J2000 13h24m08.16 43d09m48.0' 00697 00698 In this example, the first field 'M1_0' is defined using 00699 main task parameters. The next two 'M1_1' and 'M1_2' 00700 are listed in the file 'newoutlier.txt'. A mask and modelimage 00701 has been supplied only for the second field (M1_1). Fields 00702 with unspecified masks will use the full field for cleaning. 00703 00704 00705 (b) Specify all fields as lists for each task parameter : 00706 00707 Parameters that support lists for multi-field specification : 00708 'imagename', 'imsize', 'phasecenter','mask','modelimage' 00709 00710 Example : Three fields (same as above) 00711 00712 imagename = ['M1_0','M1_1','M1_2] 00713 imsize = [[1024,1024],[128,128],[128,128]] 00714 phasecenter = ['J2000 13h27m20.98 43d26m28.0', 00715 'J2000 13h30m52.159 43d23m08.02', 00716 'J2000 13h24m08.16 43d09m48.0'] 00717 mask=[[''], ['out1.mask','circle[[40pix,40pix],5pix]'],['']] 00718 modelimage=[[''],['out1.model'],['']] 00719 00720 Note : All lists must have the same length. 00721 00722 In the examples for both (a) and (b), the following images will be made: 00723 M1_0.image, M1_1.image, M1_2.image cleaned images 00724 M1.0.model, M1_1.model, M1_2.model model images 00725 M1.0.residual, M1_1.residual, M1_2.residual residual images 00726 00727 00728 Note : The old AIPS-style outlier-file and boxfile formats have been deprecated. 00729 However, due to user-requests, they will continue be supported 00730 in CASA 3.4. Note that the old outlier file format does not support 00731 the specification of modelimage and mask for each field. 00732 The new format is more complete, and less ambiguous, so please 00733 consider updating your scripts. 00734 00735 00736 """ 00737 if not hasattr(self, "__globals__") or self.__globals__ == None : 00738 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00739 #casac = self.__globals__['casac'] 00740 casalog = self.__globals__['casalog'] 00741 #casalog = casac.casac.logsink() 00742 self.__globals__['__last_task'] = 'clean' 00743 self.__globals__['taskname'] = 'clean' 00744 ### 00745 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00746 ### 00747 ### 00748 #Handle globals or user over-ride of arguments 00749 # 00750 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00751 useLocalDefaults = False 00752 00753 for item in function_signature_defaults.iteritems(): 00754 key,val = item 00755 keyVal = eval(key) 00756 if (keyVal == None): 00757 #user hasn't set it - use global/default 00758 pass 00759 else: 00760 #user has set it - use over-ride 00761 if (key != 'self') : 00762 useLocalDefaults = True 00763 00764 myparams = {} 00765 if useLocalDefaults : 00766 for item in function_signature_defaults.iteritems(): 00767 key,val = item 00768 keyVal = eval(key) 00769 exec('myparams[key] = keyVal') 00770 self.parameters[key] = keyVal 00771 if (keyVal == None): 00772 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00773 keyVal = eval(key) 00774 if(type(keyVal) == dict) : 00775 if len(keyVal) > 0 : 00776 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00777 else : 00778 exec('myparams[key] = ' + key + ' = {}') 00779 00780 else : 00781 async = self.parameters['async'] 00782 myparams['vis'] = vis = self.parameters['vis'] 00783 myparams['imagename'] = imagename = self.parameters['imagename'] 00784 myparams['outlierfile'] = outlierfile = self.parameters['outlierfile'] 00785 myparams['field'] = field = self.parameters['field'] 00786 myparams['spw'] = spw = self.parameters['spw'] 00787 myparams['selectdata'] = selectdata = self.parameters['selectdata'] 00788 myparams['timerange'] = timerange = self.parameters['timerange'] 00789 myparams['uvrange'] = uvrange = self.parameters['uvrange'] 00790 myparams['antenna'] = antenna = self.parameters['antenna'] 00791 myparams['scan'] = scan = self.parameters['scan'] 00792 myparams['observation'] = observation = self.parameters['observation'] 00793 myparams['mode'] = mode = self.parameters['mode'] 00794 myparams['gridmode'] = gridmode = self.parameters['gridmode'] 00795 myparams['wprojplanes'] = wprojplanes = self.parameters['wprojplanes'] 00796 myparams['facets'] = facets = self.parameters['facets'] 00797 myparams['cfcache'] = cfcache = self.parameters['cfcache'] 00798 myparams['painc'] = painc = self.parameters['painc'] 00799 myparams['aterm'] = aterm = self.parameters['aterm'] 00800 myparams['psterm'] = psterm = self.parameters['psterm'] 00801 myparams['wbawp'] = wbawp = self.parameters['wbawp'] 00802 myparams['epjtable'] = epjtable = self.parameters['epjtable'] 00803 myparams['interpolation'] = interpolation = self.parameters['interpolation'] 00804 myparams['niter'] = niter = self.parameters['niter'] 00805 myparams['gain'] = gain = self.parameters['gain'] 00806 myparams['threshold'] = threshold = self.parameters['threshold'] 00807 myparams['psfmode'] = psfmode = self.parameters['psfmode'] 00808 myparams['imagermode'] = imagermode = self.parameters['imagermode'] 00809 myparams['ftmachine'] = ftmachine = self.parameters['ftmachine'] 00810 myparams['mosweight'] = mosweight = self.parameters['mosweight'] 00811 myparams['scaletype'] = scaletype = self.parameters['scaletype'] 00812 myparams['multiscale'] = multiscale = self.parameters['multiscale'] 00813 myparams['negcomponent'] = negcomponent = self.parameters['negcomponent'] 00814 myparams['smallscalebias'] = smallscalebias = self.parameters['smallscalebias'] 00815 myparams['interactive'] = interactive = self.parameters['interactive'] 00816 myparams['mask'] = mask = self.parameters['mask'] 00817 myparams['nchan'] = nchan = self.parameters['nchan'] 00818 myparams['start'] = start = self.parameters['start'] 00819 myparams['width'] = width = self.parameters['width'] 00820 myparams['outframe'] = outframe = self.parameters['outframe'] 00821 myparams['veltype'] = veltype = self.parameters['veltype'] 00822 myparams['imsize'] = imsize = self.parameters['imsize'] 00823 myparams['cell'] = cell = self.parameters['cell'] 00824 myparams['phasecenter'] = phasecenter = self.parameters['phasecenter'] 00825 myparams['restfreq'] = restfreq = self.parameters['restfreq'] 00826 myparams['stokes'] = stokes = self.parameters['stokes'] 00827 myparams['weighting'] = weighting = self.parameters['weighting'] 00828 myparams['robust'] = robust = self.parameters['robust'] 00829 myparams['uvtaper'] = uvtaper = self.parameters['uvtaper'] 00830 myparams['outertaper'] = outertaper = self.parameters['outertaper'] 00831 myparams['innertaper'] = innertaper = self.parameters['innertaper'] 00832 myparams['modelimage'] = modelimage = self.parameters['modelimage'] 00833 myparams['restoringbeam'] = restoringbeam = self.parameters['restoringbeam'] 00834 myparams['pbcor'] = pbcor = self.parameters['pbcor'] 00835 myparams['minpb'] = minpb = self.parameters['minpb'] 00836 myparams['usescratch'] = usescratch = self.parameters['usescratch'] 00837 myparams['noise'] = noise = self.parameters['noise'] 00838 myparams['npixels'] = npixels = self.parameters['npixels'] 00839 myparams['npercycle'] = npercycle = self.parameters['npercycle'] 00840 myparams['cyclefactor'] = cyclefactor = self.parameters['cyclefactor'] 00841 myparams['cyclespeedup'] = cyclespeedup = self.parameters['cyclespeedup'] 00842 myparams['nterms'] = nterms = self.parameters['nterms'] 00843 myparams['reffreq'] = reffreq = self.parameters['reffreq'] 00844 myparams['chaniter'] = chaniter = self.parameters['chaniter'] 00845 myparams['flatnoise'] = flatnoise = self.parameters['flatnoise'] 00846 myparams['allowchunk'] = allowchunk = self.parameters['allowchunk'] 00847 00848 if type(multiscale)==int: multiscale=[multiscale] 00849 if type(imsize)==int: imsize=[imsize] 00850 if type(cell)==float: cell=[cell] 00851 if type(outertaper)==str: outertaper=[outertaper] 00852 if type(innertaper)==str: innertaper=[innertaper] 00853 if type(restoringbeam)==str: restoringbeam=[restoringbeam] 00854 00855 result = None 00856 00857 # 00858 # The following is work around to avoid a bug with current python translation 00859 # 00860 mytmp = {} 00861 00862 mytmp['vis'] = vis 00863 mytmp['imagename'] = imagename 00864 mytmp['outlierfile'] = outlierfile 00865 mytmp['field'] = field 00866 mytmp['spw'] = spw 00867 mytmp['selectdata'] = selectdata 00868 mytmp['timerange'] = timerange 00869 mytmp['uvrange'] = uvrange 00870 mytmp['antenna'] = antenna 00871 mytmp['scan'] = scan 00872 mytmp['observation'] = observation 00873 mytmp['mode'] = mode 00874 mytmp['gridmode'] = gridmode 00875 mytmp['wprojplanes'] = wprojplanes 00876 mytmp['facets'] = facets 00877 mytmp['cfcache'] = cfcache 00878 mytmp['painc'] = painc 00879 mytmp['aterm'] = aterm 00880 mytmp['psterm'] = psterm 00881 mytmp['wbawp'] = wbawp 00882 mytmp['epjtable'] = epjtable 00883 mytmp['interpolation'] = interpolation 00884 mytmp['niter'] = niter 00885 mytmp['gain'] = gain 00886 if type(threshold) == str : 00887 mytmp['threshold'] = casac.casac.qa.quantity(threshold) 00888 else : 00889 mytmp['threshold'] = threshold 00890 mytmp['psfmode'] = psfmode 00891 mytmp['imagermode'] = imagermode 00892 mytmp['ftmachine'] = ftmachine 00893 mytmp['mosweight'] = mosweight 00894 mytmp['scaletype'] = scaletype 00895 mytmp['multiscale'] = multiscale 00896 mytmp['negcomponent'] = negcomponent 00897 mytmp['smallscalebias'] = smallscalebias 00898 mytmp['interactive'] = interactive 00899 mytmp['mask'] = mask 00900 mytmp['nchan'] = nchan 00901 mytmp['start'] = start 00902 mytmp['width'] = width 00903 mytmp['outframe'] = outframe 00904 mytmp['veltype'] = veltype 00905 mytmp['imsize'] = imsize 00906 if type(cell) == str : 00907 mytmp['cell'] = casac.casac.qa.quantity(cell) 00908 else : 00909 mytmp['cell'] = cell 00910 mytmp['phasecenter'] = phasecenter 00911 mytmp['restfreq'] = restfreq 00912 mytmp['stokes'] = stokes 00913 mytmp['weighting'] = weighting 00914 mytmp['robust'] = robust 00915 mytmp['uvtaper'] = uvtaper 00916 mytmp['outertaper'] = outertaper 00917 mytmp['innertaper'] = innertaper 00918 mytmp['modelimage'] = modelimage 00919 mytmp['restoringbeam'] = restoringbeam 00920 mytmp['pbcor'] = pbcor 00921 mytmp['minpb'] = minpb 00922 mytmp['usescratch'] = usescratch 00923 mytmp['noise'] = noise 00924 mytmp['npixels'] = npixels 00925 mytmp['npercycle'] = npercycle 00926 mytmp['cyclefactor'] = cyclefactor 00927 mytmp['cyclespeedup'] = cyclespeedup 00928 mytmp['nterms'] = nterms 00929 mytmp['reffreq'] = reffreq 00930 mytmp['chaniter'] = chaniter 00931 mytmp['flatnoise'] = flatnoise 00932 mytmp['allowchunk'] = allowchunk 00933 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00934 trec = casac.casac.utils().torecord(pathname+'clean.xml') 00935 00936 casalog.origin('clean') 00937 try : 00938 #if not trec.has_key('clean') or not casac.casac.utils().verify(mytmp, trec['clean']) : 00939 #return False 00940 00941 casac.casac.utils().verify(mytmp, trec['clean'], True) 00942 scriptstr=[''] 00943 saveinputs = self.__globals__['saveinputs'] 00944 saveinputs('clean', 'clean.last', myparams, self.__globals__,scriptstr=scriptstr) 00945 if async : 00946 count = 0 00947 keybase = time.strftime("%y%m%d.%H%M%S") 00948 key = keybase + "_" + str(count) 00949 while self.__async__.has_key(key) : 00950 count += 1 00951 key = keybase + "_" + str(count) 00952 result = tm.execute('clean', vis, imagename, outlierfile, field, spw, selectdata, timerange, uvrange, antenna, scan, observation, mode, gridmode, wprojplanes, facets, cfcache, painc, aterm, psterm, wbawp, epjtable, interpolation, niter, gain, threshold, psfmode, imagermode, ftmachine, mosweight, scaletype, multiscale, negcomponent, smallscalebias, interactive, mask, nchan, start, width, outframe, veltype, imsize, cell, phasecenter, restfreq, stokes, weighting, robust, uvtaper, outertaper, innertaper, modelimage, restoringbeam, pbcor, minpb, usescratch, noise, npixels, npercycle, cyclefactor, cyclespeedup, nterms, reffreq, chaniter, flatnoise, allowchunk) 00953 print "Use: " 00954 print " tm.retrieve(return_value) # to retrieve the status" 00955 print 00956 self.rkey = key 00957 self.__async__[key] = result 00958 else : 00959 tname = 'clean' 00960 spaces = ' '*(18-len(tname)) 00961 casalog.post('\n##########################################'+ 00962 '\n##### Begin Task: ' + tname + spaces + ' #####') 00963 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00964 result = clean(vis, imagename, outlierfile, field, spw, selectdata, timerange, uvrange, antenna, scan, observation, mode, gridmode, wprojplanes, facets, cfcache, painc, aterm, psterm, wbawp, epjtable, interpolation, niter, gain, threshold, psfmode, imagermode, ftmachine, mosweight, scaletype, multiscale, negcomponent, smallscalebias, interactive, mask, nchan, start, width, outframe, veltype, imsize, cell, phasecenter, restfreq, stokes, weighting, robust, uvtaper, outertaper, innertaper, modelimage, restoringbeam, pbcor, minpb, usescratch, noise, npixels, npercycle, cyclefactor, cyclespeedup, nterms, reffreq, chaniter, flatnoise, allowchunk) 00965 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00966 '\n##########################################') 00967 00968 except Exception, instance: 00969 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00970 raise 00971 else : 00972 #print '**** Error **** ',instance 00973 tname = 'clean' 00974 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00975 pass 00976 00977 gc.collect() 00978 return result 00979 # 00980 # 00981 # 00982 def paramgui(self, useGlobals=True, ipython_globals=None): 00983 """ 00984 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00985 """ 00986 import paramgui 00987 if not hasattr(self, "__globals__") or self.__globals__ == None : 00988 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00989 00990 if useGlobals: 00991 if ipython_globals == None: 00992 myf=self.__globals__ 00993 else: 00994 myf=ipython_globals 00995 00996 paramgui.setGlobals(myf) 00997 else: 00998 paramgui.setGlobals({}) 00999 01000 paramgui.runTask('clean', myf['_ip']) 01001 paramgui.setGlobals({}) 01002 01003 # 01004 # 01005 # 01006 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 01007 if not hasattr(self, "__globals__") or self.__globals__ == None : 01008 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 01009 if ipython_globals == None: 01010 myf=self.__globals__ 01011 else: 01012 myf=ipython_globals 01013 01014 a = odict() 01015 a['vis'] = '' 01016 a['imagename'] = '' 01017 a['outlierfile'] = '' 01018 a['field'] = '' 01019 a['spw'] = '' 01020 a['selectdata'] = True 01021 a['mode'] = 'mfs' 01022 a['gridmode'] = '' 01023 a['niter'] = 500 01024 a['gain'] = 0.1 01025 a['threshold'] = '0.0mJy' 01026 a['psfmode'] = 'clark' 01027 a['imagermode'] = 'csclean' 01028 a['multiscale'] = [0] 01029 a['interactive'] = False 01030 a['mask'] = [] 01031 a['imsize'] = [256, 256] 01032 a['cell'] = ['1.0arcsec'] 01033 a['phasecenter'] = '' 01034 a['restfreq'] = '' 01035 a['stokes'] = 'I' 01036 a['weighting'] = 'natural' 01037 a['uvtaper'] = False 01038 a['modelimage'] = '' 01039 a['restoringbeam'] = [''] 01040 a['pbcor'] = False 01041 a['minpb'] = 0.2 01042 a['usescratch'] = False 01043 a['allowchunk'] = False 01044 01045 a['async']=False 01046 a['selectdata'] = { 01047 0:{'value':False}, 01048 1:odict([{'value':True}, {'timerange':''}, {'uvrange':''}, {'antenna':''}, {'scan':''}, {'observation':''}])} 01049 a['multiscale'] = { 01050 0:odict([{'notvalue':[]}, {'negcomponent':-1}, {'smallscalebias':0.6}])} 01051 a['gridmode'] = { 01052 0:{'value':''}, 01053 1:odict([{'value':'widefield'}, {'wprojplanes':1}, {'facets':1}]), 01054 2:odict([{'value':'aprojection'}, {'wprojplanes':1}, {'cfcache':'cfcache.dir'}, {'painc':360.0}]), 01055 3:odict([{'value':'advancedaprojection'}, {'wprojplanes':1}, {'cfcache':'cfcache.dir'}, {'painc':360.0}, {'wbawp':False}, {'aterm':True}, {'psterm':True}, {'epjtable':''}])} 01056 a['mode'] = { 01057 0:odict([{'value':'mfs'}, {'nterms':1}, {'reffreq':''}]), 01058 1:odict([{'value':'channel'}, {'nchan':-1}, {'start':''}, {'width':1}, {'interpolation':'linear'}, {'chaniter':False}, {'outframe':''}]), 01059 2:odict([{'value':'velocity'}, {'nchan':-1}, {'start':''}, {'width':''}, {'interpolation':'linear'}, {'chaniter':False}, {'outframe':''}, {'veltype':'radio'}]), 01060 3:odict([{'value':'frequency'}, {'nchan':-1}, {'start':''}, {'width':''}, {'interpolation':'linear'}, {'chaniter':False}, {'outframe':''}])} 01061 a['weighting'] = { 01062 0:{'value':'natural'}, 01063 1:{'value':'uniform'}, 01064 2:odict([{'value':'briggs'}, {'robust':0.0}, {'npixels':0}]), 01065 3:odict([{'value':'briggsabs'}, {'robust':0.0}, {'noise':'1.0Jy'}, {'npixels':0}]), 01066 4:odict([{'value':'superuniform'}, {'npixels':0}])} 01067 a['uvtaper'] = { 01068 0:{'value':False}, 01069 1:odict([{'value':True}, {'outertaper':[]}, {'innertaper':[]}])} 01070 a['interactive'] = { 01071 0:{'value':False}, 01072 1:odict([{'value':True}, {'npercycle':100}])} 01073 a['imagermode'] = { 01074 0:odict([{'value':'csclean'}, {'cyclefactor':1.5}, {'cyclespeedup':-1}]), 01075 1:odict([{'value':'mosaic'}, {'mosweight':False}, {'ftmachine':'mosaic'}, {'scaletype':'SAULT'}, {'cyclefactor':1.5}, {'cyclespeedup':-1}, {'flatnoise':True}]), 01076 2:{'value':''}} 01077 01078 ### This function sets the default values but also will return the list of 01079 ### parameters or the default value of a given parameter 01080 if(param == None): 01081 myf['__set_default_parameters'](a) 01082 elif(param == 'paramkeys'): 01083 return a.keys() 01084 else: 01085 if(paramvalue==None and subparam==None): 01086 if(a.has_key(param)): 01087 return a[param] 01088 else: 01089 return self.itsdefault(param) 01090 else: 01091 retval=a[param] 01092 if(type(a[param])==dict): 01093 for k in range(len(a[param])): 01094 valornotval='value' 01095 if(a[param][k].has_key('notvalue')): 01096 valornotval='notvalue' 01097 if((a[param][k][valornotval])==paramvalue): 01098 retval=a[param][k].copy() 01099 retval.pop(valornotval) 01100 if(subparam != None): 01101 if(retval.has_key(subparam)): 01102 retval=retval[subparam] 01103 else: 01104 retval=self.itsdefault(subparam) 01105 else: 01106 retval=self.itsdefault(subparam) 01107 return retval 01108 01109 01110 # 01111 # 01112 def check_params(self, param=None, value=None, ipython_globals=None): 01113 if ipython_globals == None: 01114 myf=self.__globals__ 01115 else: 01116 myf=ipython_globals 01117 # print 'param:', param, 'value:', value 01118 try : 01119 if str(type(value)) != "<type 'instance'>" : 01120 value0 = value 01121 value = myf['cu'].expandparam(param, value) 01122 matchtype = False 01123 if(type(value) == numpy.ndarray): 01124 if(type(value) == type(value0)): 01125 myf[param] = value.tolist() 01126 else: 01127 #print 'value:', value, 'value0:', value0 01128 #print 'type(value):', type(value), 'type(value0):', type(value0) 01129 myf[param] = value0 01130 if type(value0) != list : 01131 matchtype = True 01132 else : 01133 myf[param] = value 01134 value = myf['cu'].verifyparam({param:value}) 01135 if matchtype: 01136 value = False 01137 except Exception, instance: 01138 #ignore the exception and just return it unchecked 01139 myf[param] = value 01140 return value 01141 # 01142 # 01143 def description(self, key='clean', subkey=None): 01144 desc={'clean': 'Invert and deconvolve images with selected algorithm', 01145 'vis': 'Name of input visibility file', 01146 'imagename': 'Pre-name of output images', 01147 'outlierfile': 'Text file with image names, sizes, centers for outliers', 01148 'field': 'Field Name or id', 01149 'spw': 'Spectral windows e.g. \'0~3\', \'\' is all', 01150 'selectdata': 'Other data selection parameters', 01151 'timerange': 'Range of time to select from data', 01152 'uvrange': 'Select data within uvrange ', 01153 'antenna': 'Select data based on antenna/baseline', 01154 'scan': 'Scan number range', 01155 'observation': 'Observation ID range', 01156 'mode': 'Spectral gridding type (mfs, channel, velocity, frequency)', 01157 'gridmode': 'Gridding kernel for FFT-based transforms, default=\'\' None', 01158 'wprojplanes': 'Number of w-projection planes for convolution ', 01159 'facets': 'Number of facets along each axis (main image only)', 01160 'cfcache': 'Convolution function cache directory', 01161 'painc': 'Parallactic angle bin increment (degrees)', 01162 'aterm': 'Switch-on the A-Term?', 01163 'psterm': 'Switch-on the PS-Term?', 01164 'wbawp': 'Trigger the wide-band A-Projection algorithm?', 01165 'epjtable': 'Table of EP-Jones parameters', 01166 'interpolation': 'Spectral interpolation (nearest, linear, cubic). Use nearest for mode=channel', 01167 'niter': 'Maximum number of iterations', 01168 'gain': 'Loop gain for cleaning', 01169 'threshold': 'Flux level to stop cleaning, must include units: \'1.0mJy\'', 01170 'psfmode': 'Method of PSF calculation to use during minor cycles', 01171 'imagermode': 'Options: \'csclean\' or \'mosaic\', \'\', uses psfmode', 01172 'ftmachine': 'Gridding method for the image', 01173 'mosweight': 'Individually weight the fields of the mosaic', 01174 'scaletype': 'Controls scaling of pixels in the image plane. default=\'SAULT\'; example: scaletype=\'PBCOR\' Options: \'PBCOR\',\'SAULT\'', 01175 'multiscale': 'Deconvolution scales (pixels); [] = standard clean', 01176 'negcomponent': 'Stop cleaning if the largest scale finds this number of neg components', 01177 'smallscalebias': 'a bias to give more weight toward smaller scales', 01178 'interactive': 'Use interactive clean (with GUI viewer)', 01179 'mask': 'Cleanbox(es), mask image(s), region(s), or a level', 01180 'nchan': 'Number of channels (planes) in output image; -1 = all', 01181 'start': 'start of output spectral dimension', 01182 'width': 'width of output spectral channels', 01183 'outframe': 'velocity frame of output image ', 01184 'veltype': 'velocity definition (radio, optical, true) ', 01185 'imsize': 'x and y image size in pixels. Single value: same for both', 01186 'cell': 'x and y cell size(s). Default unit arcsec.', 01187 'phasecenter': 'Image center: direction or field index', 01188 'restfreq': 'Rest frequency to assign to image (see help)', 01189 'stokes': 'Stokes params to image (eg I,IV,IQ,IQUV)', 01190 'weighting': 'Weighting of uv (natural, uniform, briggs, ...)', 01191 'robust': 'Briggs robustness parameter', 01192 'uvtaper': 'Apply additional uv tapering of visibilities', 01193 'outertaper': 'uv-taper on outer baselines in uv-plane', 01194 'innertaper': 'uv-taper in center of uv-plane (not implemented)', 01195 'modelimage': 'Name of model image(s) to initialize cleaning', 01196 'restoringbeam': 'Output Gaussian restoring beam for CLEAN image', 01197 'pbcor': 'Output primary beam-corrected image', 01198 'minpb': 'Minimum PB level to use', 01199 'usescratch': 'True if to save model visibilities in MODEL_DATA column', 01200 'noise': 'noise parameter for briggs abs mode weighting', 01201 'npixels': 'number of pixels for superuniform or briggs weighting', 01202 'npercycle': 'Clean iterations before interactive prompt (can be changed)', 01203 'cyclefactor': 'Controls how often major cycles are done. (e.g. 5 for frequently)', 01204 'cyclespeedup': 'Cycle threshold doubles in this number of iterations', 01205 'nterms': 'Number of Taylor coefficients to model the sky frequency dependence ', 01206 'reffreq': 'Reference frequency (nterms > 1),\'\' uses central data-frequency', 01207 'chaniter': 'Clean each channel to completion (True), or all channels each cycle (False)', 01208 'flatnoise': 'Controls whether searching for clean components is done in a constant noise residual image (True) or in an optimal signal-to-noise residual image (False) ', 01209 'allowchunk': 'Divide large image cubes into channel chunks for deconvolution ', 01210 01211 'async': 'If true the taskname must be started using clean(...)' 01212 } 01213 01214 # 01215 # Set subfields defaults if needed 01216 # 01217 if(subkey == 'channel'): 01218 desc['start'] = 'Begin the output cube at the frequency of this channel in the MS' 01219 if(subkey == 'channel'): 01220 desc['width'] = 'Width of output channel relative to MS channel (# to average)' 01221 if(subkey == 'velocity'): 01222 desc['start'] = 'Velocity of first channel: e.g \'0.0km/s\'(\'\'=first channel in first SpW of MS)' 01223 if(subkey == 'velocity'): 01224 desc['width'] = 'Channel width e.g \'-1.0km/s\' (\'\'=width of first channel in first SpW of MS)' 01225 if(subkey == 'velocity'): 01226 desc['outframe'] = 'Velocity reference frame of output image; \'\' =input' 01227 if(subkey == 'velocity'): 01228 desc['veltype'] = 'Velocity definition of output image' 01229 if(subkey == 'frequency'): 01230 desc['start'] = 'Frequency of first channel: e.g. \'1.4GHz\' (\'\'= first channel in first SpW of MS)' 01231 if(subkey == 'frequency'): 01232 desc['width'] = 'Channel width: e.g \'1.0kHz\'(\'\'=width of first channel in first SpW of MS)' 01233 if(subkey == 'briggs'): 01234 desc['npixels'] = 'number of pixels to determine uv-cell size 0=> field of view' 01235 if(subkey == 'briggsabs'): 01236 desc['npixels'] = 'number of pixels to determine uv-cell size 0=> field of view' 01237 if(subkey == 'superuniform'): 01238 desc['npixels'] = 'number of pixels to determine uv-cell size 0=> +/-3pixels' 01239 01240 if(desc.has_key(key)) : 01241 return desc[key] 01242 01243 def itsdefault(self, paramname) : 01244 a = {} 01245 a['vis'] = '' 01246 a['imagename'] = '' 01247 a['outlierfile'] = '' 01248 a['field'] = '' 01249 a['spw'] = '' 01250 a['selectdata'] = True 01251 a['timerange'] = '' 01252 a['uvrange'] = '' 01253 a['antenna'] = '' 01254 a['scan'] = '' 01255 a['observation'] = '' 01256 a['mode'] = 'mfs' 01257 a['gridmode'] = '' 01258 a['wprojplanes'] = 1 01259 a['facets'] = 1 01260 a['cfcache'] = 'cfcache.dir' 01261 a['painc'] = 360.0 01262 a['aterm'] = True 01263 a['psterm'] = True 01264 a['wbawp'] = False 01265 a['epjtable'] = '' 01266 a['interpolation'] = 'linear' 01267 a['niter'] = 500 01268 a['gain'] = 0.1 01269 a['threshold'] = '0.0mJy' 01270 a['psfmode'] = 'clark' 01271 a['imagermode'] = 'csclean' 01272 a['ftmachine'] = 'mosaic' 01273 a['mosweight'] = False 01274 a['scaletype'] = 'SAULT' 01275 a['multiscale'] = [0] 01276 a['negcomponent'] = -1 01277 a['smallscalebias'] = 0.6 01278 a['interactive'] = False 01279 a['mask'] = [] 01280 a['nchan'] = -1 01281 a['start'] = 0 01282 a['width'] = 1 01283 a['outframe'] = '' 01284 a['veltype'] = 'radio' 01285 a['imsize'] = [256, 256] 01286 a['cell'] = ['1.0arcsec'] 01287 a['phasecenter'] = '' 01288 a['restfreq'] = '' 01289 a['stokes'] = 'I' 01290 a['weighting'] = 'natural' 01291 a['robust'] = 0.0 01292 a['uvtaper'] = False 01293 a['outertaper'] = [''] 01294 a['innertaper'] = ['1.0'] 01295 a['modelimage'] = '' 01296 a['restoringbeam'] = [''] 01297 a['pbcor'] = False 01298 a['minpb'] = 0.2 01299 a['usescratch'] = False 01300 a['noise'] = '1.0Jy' 01301 a['npixels'] = 0 01302 a['npercycle'] = 100 01303 a['cyclefactor'] = 1.5 01304 a['cyclespeedup'] = -1 01305 a['nterms'] = 1 01306 a['reffreq'] = '' 01307 a['chaniter'] = False 01308 a['flatnoise'] = True 01309 a['allowchunk'] = False 01310 01311 #a = sys._getframe(len(inspect.stack())-1).f_globals 01312 01313 if self.parameters['selectdata'] == True: 01314 a['timerange'] = '' 01315 a['uvrange'] = '' 01316 a['antenna'] = '' 01317 a['scan'] = '' 01318 a['observation'] = '' 01319 01320 if self.parameters['multiscale'] != []: 01321 a['negcomponent'] = -1 01322 a['smallscalebias'] = 0.6 01323 01324 if self.parameters['gridmode'] == 'widefield': 01325 a['wprojplanes'] = 1 01326 a['facets'] = 1 01327 01328 if self.parameters['gridmode'] == 'aprojection': 01329 a['wprojplanes'] = 1 01330 a['cfcache'] = 'cfcache.dir' 01331 a['painc'] = 360.0 01332 01333 if self.parameters['gridmode'] == 'advancedaprojection': 01334 a['wprojplanes'] = 1 01335 a['cfcache'] = 'cfcache.dir' 01336 a['painc'] = 360.0 01337 a['wbawp'] = False 01338 a['aterm'] = True 01339 a['psterm'] = True 01340 a['epjtable'] = '' 01341 01342 if self.parameters['mode'] == 'mfs': 01343 a['nterms'] = 1 01344 a['reffreq'] = '' 01345 01346 if self.parameters['mode'] == 'channel': 01347 a['nchan'] = -1 01348 a['start'] = '' 01349 a['width'] = 1 01350 a['interpolation'] = 'linear' 01351 a['chaniter'] = False 01352 a['outframe'] = '' 01353 01354 if self.parameters['mode'] == 'velocity': 01355 a['nchan'] = -1 01356 a['start'] = '' 01357 a['width'] = '' 01358 a['interpolation'] = 'linear' 01359 a['chaniter'] = False 01360 a['outframe'] = '' 01361 a['veltype'] = 'radio' 01362 01363 if self.parameters['mode'] == 'frequency': 01364 a['nchan'] = -1 01365 a['start'] = '' 01366 a['width'] = '' 01367 a['interpolation'] = 'linear' 01368 a['chaniter'] = False 01369 a['outframe'] = '' 01370 01371 if self.parameters['weighting'] == 'briggs': 01372 a['robust'] = 0.0 01373 a['npixels'] = 0 01374 01375 if self.parameters['weighting'] == 'briggsabs': 01376 a['robust'] = 0.0 01377 a['noise'] = '1.0Jy' 01378 a['npixels'] = 0 01379 01380 if self.parameters['weighting'] == 'superuniform': 01381 a['npixels'] = 0 01382 01383 if self.parameters['uvtaper'] == True: 01384 a['outertaper'] = [] 01385 a['innertaper'] = [] 01386 01387 if self.parameters['interactive'] == True: 01388 a['npercycle'] = 100 01389 01390 if self.parameters['imagermode'] == 'csclean': 01391 a['cyclefactor'] = 1.5 01392 a['cyclespeedup'] = -1 01393 01394 if self.parameters['imagermode'] == 'mosaic': 01395 a['mosweight'] = False 01396 a['ftmachine'] = 'mosaic' 01397 a['scaletype'] = 'SAULT' 01398 a['cyclefactor'] = 1.5 01399 a['cyclespeedup'] = -1 01400 a['flatnoise'] = True 01401 01402 if a.has_key(paramname) : 01403 return a[paramname] 01404 clean_cli = clean_cli_()