casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
clean.py
Go to the documentation of this file.
00001 #
00002 # This file was generated using xslt from its XML file
00003 #
00004 # Copyright 2009, Associated Universities Inc., Washington DC
00005 #
00006 import sys
00007 import os
00008 from  casac import *
00009 import string
00010 from taskinit import casalog
00011 #from taskmanager import tm
00012 import task_clean
00013 def clean(vis='', imagename='', outlierfile='', field='', spw='', selectdata=True, timerange='', uvrange='', antenna='', scan='', observation='', mode='mfs', gridmode='', wprojplanes=1, facets=1, cfcache='cfcache.dir', painc=360.0, aterm=True, psterm=True, wbawp=False, epjtable='', interpolation='linear', niter=500, gain=0.1, threshold='0.0mJy', psfmode='clark', imagermode='csclean', ftmachine='mosaic', mosweight=False, scaletype='SAULT', multiscale=[0], negcomponent=-1, smallscalebias=0.6, interactive=False, mask=[], nchan=-1, start=0, width=1, outframe='', veltype='radio', imsize=[256, 256], cell=['1.0arcsec'], phasecenter='', restfreq='', stokes='I', weighting='natural', robust=0.0, uvtaper=False, outertaper=[''], innertaper=['1.0'], modelimage='', restoringbeam=[''], pbcor=False, minpb=0.2, usescratch=False, noise='1.0Jy', npixels=0, npercycle=100, cyclefactor=1.5, cyclespeedup=-1, nterms=1, reffreq='', chaniter=False, flatnoise=True, allowchunk=False):
00014 
00015         """Invert and deconvolve images with selected algorithm
00016        The clean task has many options:
00017  
00018         1)  Make 'dirty' image and 'dirty' beam (psf)
00019         2)  Multi-frequency-continuum images or spectral channel imaging
00020         3)  Full Stokes imaging
00021         4)  Mosaicking of several pointings
00022         5)  Multi-scale cleaning
00023         6)  Widefield cleaning
00024         7)  Interactive clean boxing
00025         8)  Use starting model (eg from single dish)
00026  
00027  
00028        vis -- Name(s) of input visibility file(s)
00029                default: none; 
00030                example: vis='ngc5921.ms'
00031                         vis=['ngc5921a.ms','ngc5921b.ms']; multiple MSes
00032        imagename -- Pre-name of output images:
00033                default: none; example: imagename='m2'
00034                output images are:
00035                  m2.image; cleaned and restored image
00036                         With or without primary beam correction
00037                  m2.psf; point-spread function (dirty beam)
00038                  m2.flux;  relative sky sensitivity over field
00039                  m2.flux.pbcoverage;  relative pb coverage over field 
00040                                       (gets created only for ft='mosaic')
00041                  m2.model; image of clean components
00042                  m2.residual; image of residuals
00043                  m2.interactive.mask; image containing clean regions
00044                To include outlier fields: 
00045                  imagename=['n5921','outlier1','outlier2'] 
00046        outlierfile --- Text file name which contains image names, sizes, field
00047                        centers (See 'HINTS ON CLEAN WITH FLANKING FIELDS' below 
00048                        for the format of this outlier file.)
00049        field -- Select fields to image or mosaic.  Use field id(s) or name(s).
00050                   ['go listobs' to obtain the list id's or names]
00051                default: ''= all fields
00052                  If field string is a non-negative integer, it is assumed to
00053                  be a field index otherwise, it is assumed to be a 
00054                  field name
00055                  field='0~2'; field ids 0,1,2
00056                  field='0,4,5~7'; field ids 0,4,5,6,7
00057                  field='3C286,3C295'; field named 3C286 and 3C295
00058                  field = '3,4C*'; field id 3, all names starting with 4C
00059                  For multiple MS input, a list of field strings can be used:
00060                  field = ['0~2','0~4']; field ids 0-2 for the first MS and 0-4
00061                          for the second 
00062                  field = '0~2'; field ids 0-2 for all input MSes
00063        spw -- Select spectral window/channels
00064                NOTE: channels de-selected here will contain all zeros if
00065                          selected by the parameter mode subparameters.    
00066                default: ''=all spectral windows and channels
00067                  spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00068                  spw='0:5~61'; spw 0, channels 5 to 61
00069                  spw='<2';   spectral windows less than 2 (i.e. 0,1)
00070                  spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, 
00071                                     channels 3 to 45.
00072                  spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
00073                  For multiple MS input, a list of spw strings can be used:
00074                  spw=['0','0~3']; spw ids 0 for the first MS and 0-3 for the second
00075                  spw='0~3' spw ids 0-3 for all input MS
00076                  spw='3:10~20;50~60' for multiple channel ranges within spw id 3
00077                  spw='3:10~20;50~60,4:0~30' for different channel ranges for spw ids 3 and 4
00078                  spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
00079                       spw 1, channels 20-30, and spw 2, channels, 1,2 and 3
00080                  spw='1~4;6:15~48' for channels 15 through 48 for spw ids 1,2,3,4 and 6
00081                   
00082        selectdata -- Other data selection parameters
00083                default: True
00084 
00085   >>> selectdata=True expandable parameters
00086                See help par.selectdata for more on these
00087 
00088                timerange  -- Select data based on time range:
00089                    default: '' (all); examples,
00090                    timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00091                    Note: if YYYY/MM/DD is missing date defaults to first 
00092                          day in data set
00093                    timerange='09:14:0~09:54:0' picks 40 min on first day
00094                    timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 
00095                              30min on NEXT day
00096                    timerange='09:44:00' pick data within one integration 
00097                              of time
00098                    timerange='>10:24:00' data after this time
00099                    For multiple MS input, a list of timerange strings can be
00100                    used:
00101                    timerange=['09:14:0~09:54:0','>10:24:00']
00102                    timerange='09:14:0~09:54:0''; apply the same timerange for
00103                                                  all input MSes 
00104                uvrange -- Select data within uvrange (default units meters)
00105                    default: '' (all); example:
00106                    uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda
00107                    uvrange='>4klambda';uvranges greater than 4 kilo lambda
00108                    For multiple MS input, a list of uvrange strings can be
00109                    used:
00110                    uvrange=['0~1000klambda','100~1000klamda']
00111                    uvrange='0~1000klambda'; apply 0-1000 kilo-lambda for all
00112                                             input MSes
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 number
00128                    For multiple MS input, a list of antenna strings can be
00129                    used:
00130                    antenna=['5','5&6'];
00131                    antenna='5'; antenna index 5 for all input MSes
00132                scan -- Scan number range.
00133                    default: '' (all)
00134                    example: scan='1~5'
00135                    For multiple MS input, a list of scan strings can be used:
00136                    scan=['0~100','10~200']
00137                    scan='0~100; scan ids 0-100 for all input MSes
00138                    Check 'go listobs' to insure the scan numbers are in order.
00139                observation -- Observation ID range.
00140                    default: '' (all)
00141                    example: observation='1~5'
00142        mode -- Frequency Specification:
00143                NOTE: Channels deselected with spw parameter will contain all
00144                      zeros. 
00145                See examples below.
00146                default: 'mfs'
00147                  mode = 'mfs' means produce one image from all 
00148                       specified data.
00149                  mode = 'channel'; Use with nchan, start, width to specify
00150                         output image cube. 
00151                  mode = 'velocity', channels are specified in velocity.
00152                  mode = 'frequency', channels are specified in frequency.
00153 
00154   >>> mode='mfs' expandable parameters 
00155                Make a continuum image from the selected frequency
00156                channels/range using Multi-frequency synthesis
00157                algorithm for wide-band narrow field imaging.  
00158                mode='mfs' examples:
00159                spw = '0,1'; mode = 'mfs'
00160                   will produce one image made from all channels in spw 
00161                        0 and 1
00162                spw='0:5~28^2'; mode = 'mfs'
00163                   will produce one image made with channels 
00164                        (5,7,9,...,25,27)
00165 
00166              nterms -- Number of Taylor terms to be used to model the
00167                frequency dependence of the sky emission.  nterms=1 is
00168                equivalent to assuming no frequency dependence.
00169                nterms>1 runs the MS-MFS algorithm, and the choice of nterms 
00170                should depend on the expected shape and SNR of the spectral
00171                structure, across the chosen bandwidth. Output images 
00172                represent taylor-coefficients of the sky spectrum
00173                (images with file-name extensions of tt0,tt1,etc). 
00174                A spectral index map is also  computed as the ratio of the 
00175                first two terms (following the convention of I(nu) = I(ref_nu) x (nu/nu_0)^alpha).
00176                Additionally, a spectral-index error image is made
00177                by treating taylor-coefficient residuals as errors, and propagating
00178                them through the division used to compute spectral-index. 
00179                It is meant to be a guide to which parts of the spectral-index 
00180                image to trust, and the values may not always represent a 
00181                statistically-correct error.
00182 
00183                For more details about this algorithm, please refer to 
00184                "A multi-scale multi-frequency deconvolution algorithm for synthesis
00185                  imaging in radio interferometry", Rau and Cornwell, AA, Volume 532, 2011     
00186   
00187                ** Note that the software implementation of the MS-MFS algorithm
00188                for nterms>1 currently does not allow combination with  
00189                mosaics, and pbcor.**
00190 
00191              reffreq -- The reference frequency (for nterms>1) about which
00192                 the Taylor expansion is done. reffreq='' defaults to the
00193                 middle frequency of the selected range. 
00194 
00195   >>> mode='channel', 'velocity', and 'frequency' expandable parameters
00196 
00197                nchan -- Total number of channels in the output image.
00198                  Example: nchan=100. 
00199                  Default: -1; Automatically selects enough channels to cover 
00200                  data selected by 'spw' consistent with 'start' and 'width'. 
00201                  It is often easiest to leave nchan at the default value. 
00202 
00203                start -- First channel, velocity, or frequency. 
00204                  For mode='channel'; This selects the channel index number 
00205                  from the MS (0 based) that you want to correspond to the
00206                  first channel of the output cube. The output cube will be
00207                  in frequency space with the first channel having the
00208                  frequency of the MS channel selected by start.  start=0
00209                  refers to the first channel in the first selected spw, even
00210                  if that channel is de-selected in the spw parameter.
00211                  Channels de-selected by the spw parameter will be filled with
00212                  zeros if included by the start parameter. For example,
00213                  spw=3~8:3~100 and start=2 will produce a cube that starts on
00214                  the third channel (recall 0 based) of spw index 3, and the
00215                  first channel will be blank.
00216                  example:start=5
00217                  For mode='velocity' or 'frequency': default=''; 
00218                  starts at first input channel of first input spw
00219                  examples: start='5.0km/s', or start='22.3GHz'.
00220 
00221                width -- Output channel width
00222                  For mode='channel', default=1; >1 indicates channel averaging
00223                  example: width=4.
00224                  For mode= 'velocity' or 'frequency', default=''; width of
00225                  first input channel, or more precisely, the difference 
00226                  in frequencies between the first two selected channels. 
00227                  -- For example if channels 1 and 3 are selected with spw, 
00228                   then the default width will be the difference between their
00229                   frequencies, and not the width of channel 1. 
00230                  -- Similarly, if the selected data has uneven channel-spacing,
00231                    the default width will be picked from the first two selected
00232                    channels. In this case, please specify the desired width.
00233                  When specifying the width, one must give units
00234                  examples: width='1.0km/s', or width='24.2kHz'.
00235                  Setting width>0 gives channels of increasing frequency for 
00236                  mode='frequency', and increasing velocity for mode='velocity'. 
00237 
00238                interpolation -- Interpolation type for spectral gridding onto 
00239                  the uv-plane. Options: 'nearest', 'linear', or 'cubic'.
00240                  default = 'linear' 
00241                  Note : 'linear' and 'cubic' interpolation requires data
00242                         points on both sides of each image frequency. Errors
00243                         are therefore possible at edge  channels, or near
00244                         flagged data channels.
00245                  For mode='channel', please use 'nearest'.
00246 
00247                chaniter -- specify how spectral CLEAN is performed, 
00248                  default: chaniter=False;
00249                  example: chaniter=True; step through channels 
00250 
00251                outframe -- For mode='velocity', 'frequency', or 'channel':
00252                              velocity reference frame of output image
00253                  Options: '','LSRK','LSRD','BARY','GEO','TOPO','GALACTO',
00254                           'LGROUP','CMB'
00255                  default: ''; same as input data
00256                  example: frame='bary' for Barycentric frame 
00257 
00258                veltype -- for mode='velocity' gives the velocity definition
00259                  Options: 'radio','optical' 
00260                  default: 'radio'
00261                  NOTE: the viewer always defaults to displaying the 'radio'
00262                    frame, but that can be changed in the position tracking
00263                    pull down.
00264 
00265            mode='channel' examples:
00266                spw = '0'; mode = 'channel': nchan=3; start=5; width=4
00267                   will produce an image with 3 output planes
00268                   plane 1 contains data from channels (5+6+7+8)
00269                   plane 2 contains data from channels (9+10+11+12)
00270                   plane 3 contains data from channels (13+14+15+16)
00271                spw = '0:0~63^3'; mode='channel'; nchan=21; start = 0; 
00272                    width = 1
00273                   will produce an image with 20 output planes
00274                   Plane 1 contains data from channel 0
00275                   Plane 2 contains date from channel 2
00276                   Plane 21 contains data from channel 61
00277                spw = '0:0~40^2'; mode = 'channel'; nchan = 3; start = 
00278                    5; width = 4
00279                   will produce an image with three output planes
00280                   plane 1 contains channels (5,7)
00281                   plane 2 contains channels (13,15)
00282                   plane 3 contains channels (21,23)
00283 
00284        psfmode -- method of PSF calculation to use during minor cycles:
00285                default: 'clark': Options: 'clark','clarkstokes', 'hogbom'
00286                'clark'  use smaller beam (faster, usually good enough);
00287                 for stokes images clean components peaks are searched
00288                in the I^2+Q^2+U^2+V^2 domain 
00289                'clarkstokes' locate clean components independently in
00290                each stokes image
00291                'hogbom' full-width of image (slower, better for poor 
00292                uv-coverage)
00293                Note:  psfmode will also be used to clean if imagermode = ''
00294        imagermode -- Advanced imaging e.g. mosaic or Cotton-Schwab clean
00295                default: imagermode='csclean': Options: '', 'csclean', 'mosaic'
00296                ''  => psfmode cleaning algorithm used
00297                NOTE: imagermode 'mosaic' (and/or) any gridmode not blank 
00298                          (and/or) nterms>1 : will always use CS style clean. 
00299 
00300   >>> gridmode='' expandable parameters
00301                The default value of '' has no effect.
00302         
00303   >>> gridmode='widefield' expandable parameters
00304                Apply corrections for non-coplanar effects during imaging
00305                using the W-Projection algorithm (Cornwell et al. IEEE JSTSP
00306                (2008)) or faceting or a combination of the two.
00307 
00308                wprojplanes is the number of pre-computed w-planes used for
00309                    the W-Projection algorithm.  wprojplanes=1 disables
00310                    correction for non-coplanar effects. 
00311                facets is the number of facets on each side of the image 
00312                    (i.e. the total number of facets is 'facets x facets'). 
00313                    If wprojplanes>1, W-Projection is done for each facet.
00314 
00315   >>> gridmode='aprojection' expandable parameters
00316                Corrects for the (E)VLA time-varying PB effects
00317                including polarization squint using the A-Projection
00318                algorithm (Bhatnagar et al., AandA, 487, 419 (2008)).
00319                This can optinally include w-projection also.
00320 
00321                wprojplanes is the number of pre-computed w-planes used
00322                for W-Projection algorithm.  wprojplanes=1 diables
00323                correction for non-coplanar effects.
00324 
00325                cfcache is the name of the directory to store the
00326                convolution functions and weighted sensitivty pattern
00327                function. 
00328                
00329                
00330                
00331 
00332                painc (in degrees) is the Parallactic Angle increment
00333                used to compute the convolution functions.
00334 
00335   >>> imagermode='mosaic' expandable parameter(s):
00336                Make a mosaic of the different pointings (uses csclean style
00337                too)
00338                mosweight -- Individually weight the fields of the mosaic
00339                    default: False; example: mosweight=True
00340                    This can be useful if some of your fields are more
00341                    sensitive than others (i.e. due to time spent 
00342                    on-source); this parameter will give more weight to 
00343                    higher sensitivity fields in the overlap regions.
00344                ftmachine -- Gridding method for the mosaic;
00345                    Options: 'ft' (standard interferometric gridding), 'sd'
00346                    (standard single dish), 
00347                    and 'mosaic' (grid using PB as convolution function).
00348                    default: 'mosaic'; 
00349                    ONLY if imagermode='mosaic' is chosen and
00350                    ftmachine='mosaic', is heterogeneous imaging (CARMA, ALMA)
00351                    possible using the right convolution of primary beams for
00352                    each baseline.
00353                scaletype -- Controls scaling of pixels in the image plane.
00354                    (controls what is seen if interactive=True)
00355                    It does *not* affect the scaling of the *final* image -
00356                    that is done by pbcor.
00357                    default='SAULT'; example: scaletype='PBCOR'
00358                    Options: 'PBCOR','SAULT'
00359                      'SAULT' when interactive=True shows the residual
00360                              with constant noise across the mosaic. 
00361                              Can also be achieved by setting pbcor=False.
00362                      'PBCOR' uses the SAULT scaling scheme for
00363                              deconvolution, but if interactive=True shows the
00364                              primary beam corrected image during interactive. 
00365 
00366                cyclefactor -- Controls the threshhold at which the
00367                    deconvolution cycle will pause to degrid and subtract the
00368                    model from the visibilities.
00369                    With poor PSFs, reconcile often (cyclefactor=4 or 5) for
00370                    reliability. 
00371                    With good PSFs, use cyclefactor = 1.5 to 2.0 for speed. 
00372                    Note: threshold = cyclefactor * max sidelobe * max residual
00373                    default: 1.5; example: cyclefactor=4
00374                cyclespeedup -- The major cycle threshold doubles in this
00375                    number of iterations.
00376                    Default: -1 (no doubling)
00377                    Example: cyclespeedup=3
00378                    Try cyclespeedup = 50 to speed up cleaning.
00379 
00380                flatnoise -- Controls whether searching for clean components
00381                    is done in a constant noise residual image (True) or in an
00382                    optimal signal-to-noise residual image (False) when
00383                    ftmosaic='mosaic' is chosen.
00384                    default=True
00385 
00386   >>> imagermode='csclean' expandable parameter(s): 
00387                Image using the Cotton-Schwab algorithm in between major cycles
00388 
00389                cyclefactor -- See above, under imagermode='mosaic'.
00390                cyclespeedup -- See above, under imagermode='mosaic'.
00391 
00392        multiscale -- set of scales to use in deconvolution.  If set,
00393                cleans with several resolutions using Hogbom clean. The
00394                scale sizes are in units of cellsize.  So if
00395                cell='2arcsec', a multiscale scale=10 => 20arcsec.  The
00396                first scale is recommended to  be 0 (point), we suggest the
00397                second be on the order of synthesized beam, the third 3-5
00398                times the synthesized beam, etc..  Avoid making the largest
00399                scale too large relative to the image width or the scale of
00400                the lowest measured spatial frequency.  For example, if the
00401                synthesized beam is 10" FWHM and cell=2", try
00402                multiscale = [0,5,15].
00403                
00404                default: multiscale=[] (standard CLEAN with psfmode algorithm,
00405                no multi-scale).
00406                Example: multiscale = [0,5,15] 
00407 
00408   >>> multiscale expandable parameter(s): 
00409                negcomponent -- Stop component search when the largest scale
00410                  has found this number of negative components;
00411                  -1 means continue component search even if the largest
00412                  component is negative.  default: -1; example: negcomponent=50
00413                smallscalebias -- A bias toward smaller scales. 
00414                    The peak flux found at each scale is weighted by 
00415                    a factor = 1 - smallscalebias*scale/max_scale, so
00416                    that Fw = F*factor.
00417                    Typically the values range from 0.2 to 1.0.
00418                    default: 0.6
00419 
00420        imsize -- Image size in pixels (x, y).  DOES NOT HAVE TO BE A POWER
00421                  OF 2 (but has to be even and factorizable to 2,3,5,7 only).
00422                default = [256,256]; example: imsize=[350,350]
00423                imsize = 500 is equivalent to [500,500]
00424                If include outlier fields, e.g., [[400,400],[100,100]] or
00425                use outlierfile.
00426                Avoid odd-numbered imsize.
00427        cell -- Cell size (x,y)
00428                default= '1.0arcsec';
00429                example: cell=['0.5arcsec,'0.5arcsec'] or
00430                cell=['1arcmin', '1arcmin']
00431                cell = '1arcsec' is equivalent to ['1arcsec','1arcsec']
00432                NOTE:cell = 2.0 => ['2arcsec', '2arcsec']
00433        phasecenter -- direction measure  or fieldid for the mosaic center
00434                default: '' => first field selected ; 
00435                example: phasecenter=6
00436                         phasecenter='J2000 19h30m00 -40d00m00'
00437                         phasecenter='J2000 292.5deg  -40.0deg'
00438                         phasecenter='J2000 5.105rad  -0.698rad'
00439                If include outlier fields, 
00440                 e.g. ['J2000 19h30m00 -40d00m00',J2000 19h25m00 -38d40m00']
00441                or use outlierfile.
00442        restfreq -- Specify rest frequency to use for output image
00443                default='' Occasionally it is necessary to set this (for
00444                example some VLA spectral line data).  For example for
00445                NH_3 (1,1) put restfreq='23.694496GHz'
00446        stokes -- Stokes parameters to image
00447                default='I'; example: stokes='IQUV';
00448                Options: 'I','Q','U','V','IV','QU','IQ','UV','IQU','IUV','IQUV','RR','LL','XX','YY','RRLL','XXYY'
00449        niter -- Maximum number iterations,
00450                if niter=0, then no CLEANing is done ("invert" only).
00451                (niter=0 can be used instead of the 'ft' task to predict/save a model)
00452                default: 500; example: niter=5000
00453        gain -- Loop gain for CLEANing
00454                default: 0.1; example: gain=0.5
00455        threshold -- Flux level at which to stop CLEANing
00456                default: '0.0mJy'; 
00457                example: threshold='2.3mJy'  (always include units)
00458                         threshold = '0.0023Jy'
00459                         threshold = '0.0023Jy/beam' (okay also)
00460        interactive -- use interactive clean (with GUI viewer)
00461                default: interactive=False
00462                example: interactive=True
00463                interactive clean allows the user to build the cleaning
00464                mask interactively using the viewer.  The viewer will
00465                appear every npercycle interation, but modify as needed
00466                The final interactive mask is saved in the file
00467                imagename_interactive.mask.  The initial masks use the
00468                union of mask and cleanbox (see below).
00469 
00470   >>> interactive=True expandable parameters
00471                npercycle -- this is the  number of iterations between each
00472                  interactive update of the mask.  It is important to modify
00473                  this number interactively during the cleaning, starting with
00474                  a low number like 20, but then increasing as more extended
00475                  emission is encountered.
00476 
00477        mask -- Specification of cleanbox(es), mask image(s), primary beam
00478                coverage level, and/or region(s) to be used for CLEANing.
00479                CLEAN tends to perform better, and is less likely to diverge,
00480                if the CLEAN component placement is limited by a mask to where
00481                real emission is expected to be.  As long as the image has the
00482                same shape (size), mask images (e.g. from a previous interactive
00483                session) can be used for a new execution.  NOTE: the initial
00484                clean mask actually used is the union of what is specified in mask
00485                and <imagename>.mask
00486                default: [] or '' : no masking; Possible specification types:
00487                (a) Cleanboxes, specified using the CASA region format
00488                     (http://casaguides.nrao.edu/index.php?title=CASA_Region_Format)
00489                     Example : mask='box [ [ 100pix , 130pix] , [120pix, 150pix ] ]'
00490                        mask='circle [ [ 120pix , 40pix] ,6pix ]'
00491                        mask='circle[[19h58m52.7s,+40d42m06.04s ], 30.0arcsec]'
00492                    If used with a spectral cube, it will apply to all channels.
00493                    Multiple regions may be specified as a list of pixel ranges.
00494                     Example :  mask= ['circle [ [ 120pix , 40pix] ,6pix ]', 
00495                                                  'box [ [ 100pix , 130pix] , [120pix, 150pix ] ]' ]
00496                (b) Filename with cleanbox shapes defined using the CASA region format.
00497                    Example: mask='mycleanbox.txt'
00498                      The file 'mycleanbox.txt' contains : 
00499                           box [ [ 100pix , 130pix ] , [ 120pix, 150pix ] ]
00500                           circle [ [ 150pix , 150pix] ,10pix ]
00501                           rotbox [ [ 60pix , 50pix ] , [ 30pix , 30pix ] , 30deg ]
00502                (c) Filename for image mask.  Example: mask='myimage.mask'
00503                    Multiple mask files may be specified.
00504                    example : mask=[ 'mask1.mask', 'mask2.mask' ]
00505                (d) Filename for region specification (e.g. from viewer).
00506                    Example: mask='myregion.rgn'
00507                (e) Combinations of the above options.
00508                    Example: mask=['mycleanbox.txt', 'myimage.mask',
00509                                   'myregion.rgn','circle [ [ 120pix , 40pix] ,6pix ]']
00510                (f) Threshold on primary-beam.
00511                    A number between 0 and 1, used as a threshhold of primary
00512                    beam coverage.  The primary beam coverage map (imagename +
00513                    '.flux(.pbcoverage)') will be made and the CLEAN component
00514                    placement will be limited to where it is > the number.
00515                (g) True or False.
00516                    True: like (f), but use minpb as the number.
00517                    False: go maskless (and expect trouble).
00518             (For masks for multiple fields, please see 'HINTS ON CLEAN WITH FLANKING FIELDS' below)
00519 
00520        uvtaper -- Apply additional uv tapering of the visibilities.
00521                default: uvtaper=False; example: uvtaper=True
00522 
00523   >>> uvtaper=True expandable parameters
00524                outertaper -- uv-taper on outer baselines in uv-plane
00525                    [bmaj, bmin, bpa] taper Gaussian scale in uv or 
00526                    angular units. NOTE: the on-sky FWHM in arcsec is roughly
00527                    the uv taper/200 (klambda).
00528                    default: outertaper=[]; no outer taper applied
00529                    example: outertaper=['5klambda']  circular taper 
00530                                 FWHM=5 kilo-lambda
00531                             outertaper=['5klambda','3klambda','45.0deg']
00532                             outertaper=['10arcsec'] on-sky FWHM 10 arcseconds
00533                             outertaper=['300.0'] default units are meters 
00534                                 in aperture plane
00535                innertaper -- uv-taper in center of uv-plane
00536                    [bmaj,bmin,bpa] Gaussian scale at which taper falls to 
00537                    zero at uv=0
00538                    default: innertaper=[]; no inner taper applied
00539                    NOT YET IMPLEMENTED                
00540        modelimage -- Name of model image(s) to initialize cleaning. If
00541                multiple images, then these will be added together to
00542                form initial staring model NOTE: these are in addition
00543                to any initial model in the <imagename>.model image file
00544                default: '' (none); example: modelimage='orion.model'
00545                modelimage=['orion.model','sdorion.image'] Note: if the
00546                units in the image are Jy/beam as in a single-dish
00547                image, then it will be converted to Jy/pixel as in a
00548                model image, using the restoring beam in the image
00549                header.  
00550                When nterms>1, a one-to-one mapping is done between images
00551                in this list and Taylor-coefficients. If more than nterms 
00552                images are  specified, only the first nterms are used.
00553                It is valid to supply fewer than nterms model images.
00554                Example : Supply an estimate of the continuum flux from a
00555                          previous imaging run. 
00556        weighting -- Weighting to apply to visibilities:
00557                default='natural'; example: weighting='uniform';
00558                Options: 'natural','uniform','briggs', 
00559                        'superuniform','briggsabs','radial'
00560 
00561   >>> Weighting expandable parameters
00562                For weighting='briggs' and 'briggsabs'
00563                    robust -- Brigg's robustness parameter
00564                    default=0.0; example: robust=0.5;
00565                    Options: -2.0 to 2.0; -2 (uniform)/+2 (natural)
00566                For weighting='briggsabs'
00567                    noise   -- noise parameter to use for Briggs "abs" 
00568                    weighting
00569                    example noise='1.0mJy'
00570                npixels -- uv-cell area used for weight calculation
00571                    example npixels=1
00572                    Default = 0
00573                    superuniform:  0 Means 3x3 cells for weighting
00574                      the cell weight is proportional to the weight of
00575                      the 3x3 cells centered on it.
00576                    superuniform = F means 1x1 cell for averaging weights.
00577                    briggs/briggsabs: 0 is similar to 1x1 cell weight.
00578                      1 may? be similar to 3X3 cells.
00579                    Only npixels 0 or 1 recommended
00580                    
00581        restoringbeam -- Output Gaussian restoring beam for CLEAN image
00582                [bmaj, bmin, bpa] elliptical Gaussian restoring beam
00583                default units are in arc-seconds for bmaj,bmin, degrees
00584                for bpa default: restoringbeam=[]; Use PSF calculated
00585                from dirty beam. 
00586                example: restoringbeam=['10arcsec'] circular Gaussian 
00587                         FWHM 10 arcseconds example:
00588                         restoringbeam=['10.0','5.0','45.0deg'] 10"x5" 
00589                         at 45 degrees
00590 
00591        pbcor -- Output primary beam-corrected image
00592                 If pbcor=False, the final output image is NOT corrected for
00593                 the PB pattern (particularly important for mosaics), and
00594                 therefore is not "flux correct". Correction can also be
00595                 done after the  fact using immath to divide
00596                 <imagename>.image by the <imagename>.flux image. 
00597                default: pbcor=False; output un-corrected image 
00598                example: pbcor=True; output pb-corrected image (masked outside
00599                         minpb) 
00600 
00601        minpb -- Minimum PB level to use for pb-correction and pb-based masking.
00602                     default=0.2;
00603                     example: minpb=0.01 
00604                When imagermode is *not* 'mosaic' :
00605                   minpb is applied to the flux image (sensitivity-weighted pb).
00606                   minpb is used to create a mask, only when pbcor=True
00607                When imagermode='mosaic' :
00608                   minpb is applied to the flux.pbcoverage image 
00609                         (mosaic pb with equal weight per pointing)
00610                    minpb is always used to create a mask (regardless of
00611                    pbcor=True/False) 
00612 
00613        usescratch -- if True will create scratch columns if they are 
00614                not there. And after clean completes the predicted model 
00615                visibility is from the clean components are written to the ms. This increases
00616                the ms size by the data volume. if False then the model is saved in the ms
00617                header and the calculation of the visibilities is done on the fly when using 
00618                calibration or plotms. Use True if you want to access the moedl visibilities 
00619                in python, say.
00620 
00621        allowchunk -- Partition the image cube by channel-chunks.
00622                default=False;  
00623                   False: Major cycle grids all channels.  Minor cycle steps 
00624                             through all channels before the next major cycle.
00625                   True:  Major and minor cycles are performed one chunk
00626                             at a time, and output images cubes are concatenated.
00627        async -- Run asynchronously 
00628                default = False; do not run asychronously
00629 
00630 
00631         ======================================================================
00632 
00633                              HINTS ON CLEAN WITH FLANKING FIELDS
00634 
00635               There are two ways of specifying multi-field images for clean.
00636 
00637               (a) Task parameters are used to define the first(main) field.
00638                    A text file containing definitions of all additional fields is supplied
00639                    to the 'outlierfile' task parameter.  
00640 
00641                    This outlier file must contain the following parameters per field
00642                      Required : imagename, imsize, phasecenter     
00643                      Optional : mask, modelimage
00644                    The parameter set for each field must begin with 'imagename'. 
00645                    Parameters can be listed in a single line or span multiple lines.
00646                     
00647                    Example : Three fields. 
00648                     
00649                     - Task Inputs :
00650                        imagename = 'M1_0'
00651                        outlierfile='outlier.txt'
00652                        imsize = [1024,1024]
00653                        phasecenter = 'J2000 13h27m20.98 43d26m28.0'
00654                    
00655                     - Contents of outlier file 'outlier.txt':
00656                        imagename = 'M1_1' 
00657                        imsize = [128,128]
00658                        phasecenter = 'J2000 13h30m52.159 43d23m08.02'
00659                        mask = ['out1.mask', 'circle[[40pix,40pix],5pix]' ]
00660                        modelimage = 'out1.model'
00661                        imagename = 'M1_2' 
00662                        imsize = [128,128]
00663                        phasecenter = 'J2000 13h24m08.16 43d09m48.0'
00664                     
00665                      In this example, the first field 'M1_0' is defined using
00666                      main task parameters. The next two 'M1_1' and 'M1_2' 
00667                      are listed in the file 'newoutlier.txt'.  A mask and modelimage 
00668                      has been supplied only for the second field (M1_1). Fields
00669                      with unspecified masks will use the full field for cleaning.
00670 
00671 
00672                 (b) Specify all fields as lists for each task parameter :
00673                      
00674                     Parameters that support lists for multi-field specification : 
00675                       'imagename', 'imsize', 'phasecenter','mask','modelimage'
00676 
00677                     Example : Three fields (same as above)
00678 
00679                        imagename = ['M1_0','M1_1','M1_2]
00680                        imsize = [[1024,1024],[128,128],[128,128]]
00681                        phasecenter = ['J2000 13h27m20.98 43d26m28.0',
00682                                       'J2000 13h30m52.159 43d23m08.02',
00683                                       'J2000 13h24m08.16 43d09m48.0']
00684                        mask=[[''], ['out1.mask','circle[[40pix,40pix],5pix]'],['']] 
00685                        modelimage=[[''],['out1.model'],['']]
00686 
00687                      Note : All lists must have the same length.
00688 
00689                 In the examples for both (a) and (b), the following images will be made:
00690                 M1_0.image, M1_1.image, M1_2.image     cleaned images
00691                 M1.0.model, M1_1.model, M1_2.model     model images
00692                 M1.0.residual, M1_1.residual, M1_2.residual     residual images
00693 
00694           
00695              Note : The old AIPS-style outlier-file and boxfile formats have been deprecated. 
00696                        However, due to user-requests, they will continue be supported
00697                        in CASA 3.4. Note that the old outlier file format does not support 
00698                        the specification of modelimage and mask for each field. 
00699                        The new format is more complete, and less ambiguous, so please 
00700                        consider updating your scripts.
00701 
00702   
00703         """
00704         if type(multiscale)==int: multiscale=[multiscale]
00705         if type(imsize)==int: imsize=[imsize]
00706         if type(cell)==float: cell=[cell]
00707         if type(outertaper)==str: outertaper=[outertaper]
00708         if type(innertaper)==str: innertaper=[innertaper]
00709         if type(restoringbeam)==str: restoringbeam=[restoringbeam]
00710 
00711 #
00712 #    The following is work around to avoid a bug with current python translation
00713 #
00714         mytmp = {}
00715 
00716         mytmp['vis'] = vis
00717         mytmp['imagename'] = imagename
00718         mytmp['outlierfile'] = outlierfile
00719         mytmp['field'] = field
00720         mytmp['spw'] = spw
00721         mytmp['selectdata'] = selectdata
00722         mytmp['timerange'] = timerange
00723         mytmp['uvrange'] = uvrange
00724         mytmp['antenna'] = antenna
00725         mytmp['scan'] = scan
00726         mytmp['observation'] = observation
00727         mytmp['mode'] = mode
00728         mytmp['gridmode'] = gridmode
00729         mytmp['wprojplanes'] = wprojplanes
00730         mytmp['facets'] = facets
00731         mytmp['cfcache'] = cfcache
00732         mytmp['painc'] = painc
00733         mytmp['aterm'] = aterm
00734         mytmp['psterm'] = psterm
00735         mytmp['wbawp'] = wbawp
00736         mytmp['epjtable'] = epjtable
00737         mytmp['interpolation'] = interpolation
00738         mytmp['niter'] = niter
00739         mytmp['gain'] = gain
00740         if type(threshold) == str :
00741            mytmp['threshold'] = casac.quanta().quantity(threshold)
00742         else :
00743            mytmp['threshold'] = threshold
00744         mytmp['psfmode'] = psfmode
00745         mytmp['imagermode'] = imagermode
00746         mytmp['ftmachine'] = ftmachine
00747         mytmp['mosweight'] = mosweight
00748         mytmp['scaletype'] = scaletype
00749         mytmp['multiscale'] = multiscale
00750         mytmp['negcomponent'] = negcomponent
00751         mytmp['smallscalebias'] = smallscalebias
00752         mytmp['interactive'] = interactive
00753         mytmp['mask'] = mask
00754         mytmp['nchan'] = nchan
00755         mytmp['start'] = start
00756         mytmp['width'] = width
00757         mytmp['outframe'] = outframe
00758         mytmp['veltype'] = veltype
00759         mytmp['imsize'] = imsize
00760         if type(cell) == str :
00761            mytmp['cell'] = casac.quanta().quantity(cell)
00762         else :
00763            mytmp['cell'] = cell
00764         mytmp['phasecenter'] = phasecenter
00765         mytmp['restfreq'] = restfreq
00766         mytmp['stokes'] = stokes
00767         mytmp['weighting'] = weighting
00768         mytmp['robust'] = robust
00769         mytmp['uvtaper'] = uvtaper
00770         mytmp['outertaper'] = outertaper
00771         mytmp['innertaper'] = innertaper
00772         mytmp['modelimage'] = modelimage
00773         mytmp['restoringbeam'] = restoringbeam
00774         mytmp['pbcor'] = pbcor
00775         mytmp['minpb'] = minpb
00776         mytmp['usescratch'] = usescratch
00777         mytmp['noise'] = noise
00778         mytmp['npixels'] = npixels
00779         mytmp['npercycle'] = npercycle
00780         mytmp['cyclefactor'] = cyclefactor
00781         mytmp['cyclespeedup'] = cyclespeedup
00782         mytmp['nterms'] = nterms
00783         mytmp['reffreq'] = reffreq
00784         mytmp['chaniter'] = chaniter
00785         mytmp['flatnoise'] = flatnoise
00786         mytmp['allowchunk'] = allowchunk
00787         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00788         trec = casac.utils().torecord(pathname+'clean.xml')
00789 
00790         casalog.origin('clean')
00791         if trec.has_key('clean') and casac.utils().verify(mytmp, trec['clean']) :
00792             result = task_clean.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)
00793 
00794         else :
00795           result = False
00796         return result