casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
autoclean.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_autoclean
00013 def autoclean(vis='', imagename='', field='', spw='', selectdata=True, timerange='', uvrange='', antenna='', scan='', mode='mfs', nchan=1, start=0, width=1, interpolation='linear', doconcat=True, psfmode='clark', imagermode='', cyclefactor=1.5, cyclespeedup=-1, imsize=[256, 256], cell=['1.0arcsec'], phasecenter='', restfreq='', stokes='I', weighting='natural', robust=0.0, noise='1.0Jy', npixels=0, interactive=False, mask=[], modelimage='', uvtaper=False, outertaper=[''], innertaper=['1.0'], niter=500, npercycle=100, npercycle_speedup=1.5, gain=0.1, pbcor=False, minpb=0.1, clean_threshold='0.0mJy', Nrms=6, eps_maxres=0.01, useabsresid=False, allow_maxres_inc=3, island_rms=4, diag=False, peak_rms=6, gain_threshold=0.1, Npeak=3, shape=1, boxstretch=1, irregsize=100):
00014 
00015         """CLEAN an image with automatically-chosen clean regions.
00016        This is a wrapper for clean which includes automatic clean boxing.
00017        Current capabilities include:
00018  
00019         1)  Multi-frequency-continuum images or spectral channel imaging
00020         2)  Stokes I imaging only
00021         3)  Use starting mask
00022  
00023  
00024        vis -- Name of input visibility file
00025                default: none; example: vis='ngc5921.ms'
00026        imagename -- Pre-name of output images:
00027                default: none; example: imagename='m2'
00028                output images are:
00029                  m2.image; cleaned and restored image
00030                         With or without primary beam correction
00031                  m2.psf; point-spread function (dirty beam)
00032                  m2.flux;  relative sky sensitivity over field
00033                  m2.mask;  total clean regions
00034                  m2.model; image of clean components
00035                  m2.residual; image of residuals
00036        field -- Select fields in mosaic.  Use field id(s) or field name(s).
00037                   ['go listobs' to obtain the list id's or names]
00038               default: ''= all fields
00039               If field string is a non-negative integer, it is assumed to
00040                   be a field index otherwise, it is assumed to be a 
00041                   field name
00042               field='0~2'; field ids 0,1,2
00043               field='0,4,5~7'; field ids 0,4,5,6,7
00044               field='3C286,3C295'; field named 3C286 and 3C295
00045               field = '3,4C*'; field id 3, all names starting with 4C
00046        spw -- Select spectral window/channels
00047               NOTE: This selects the data passed as the INPUT to mode
00048               default: ''=all spectral windows and channels
00049                 spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00050                 spw='0:5~61'; spw 0, channels 5 to 61
00051                 spw='<2';   spectral windows less than 2 (i.e. 0,1)
00052                 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, 
00053                                    channels 3 to 45.
00054                  spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
00055                  spw='0:0~10;15~60'; spectral window 0 with channels 
00056                                     0-10,15-60
00057                  spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
00058                       spw 1, channels 20-30, and spw 2, channels, 1,2 and 3
00059        selectdata -- Other data selection parameters
00060                default: True
00061 
00062   >>> selectdata=True expandable parameters
00063                See help par.selectdata for more on these
00064 
00065                timerange  -- Select data based on time range:
00066                    default: '' (all); examples,
00067                    timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00068                    Note: if YYYY/MM/DD is missing date defaults to first 
00069                          day in data set
00070                    timerange='09:14:0~09:54:0' picks 40 min on first day
00071                    timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 
00072                              30min on NEXT day
00073                    timerange='09:44:00' pick data within one integration 
00074                              of time
00075                    timerange='>10:24:00' data after this time
00076                uvrange -- Select data within uvrange (default units meters)
00077                    default: '' (all); example:
00078                    uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda
00079                    uvrange='>4klambda';uvranges greater than 4 kilo lambda
00080                antenna -- Select data based on antenna/baseline
00081                    default: '' (all)
00082                    If antenna string is a non-negative integer, it is 
00083                    assumed to be an antenna index, otherwise, it is
00084                    considered an antenna name.
00085                    antenna='5&6'; baseline between antenna index 5 and 
00086                                  index 6.
00087                    antenna='VA05&VA06'; baseline between VLA antenna 5 
00088                                        and 6.
00089                    antenna='5&6;7&8'; baselines 5-6 and 7-8
00090                    antenna='5'; all baselines with antenna index 5
00091                    antenna='05'; all baselines with antenna number 05 
00092                                 (VLA old name)
00093                    antenna='5,6,9'; all baselines with antennas 5,6,9 
00094                                    index numbers
00095               scan -- Scan number range.
00096                   default: '' (all)
00097                   example: scan='1~5'
00098                   Check 'go listobs' to insure the scan numbers are in 
00099                         order.
00100        mode -- Frequency Specification:
00101                NOTE: Channels deselected with spw parameter will contain all
00102                      zeros. 
00103                See examples below.
00104                default: 'mfs'
00105                  mode = 'mfs' means produce one image from all 
00106                       specified data.
00107                  mode = 'channel'; Use with nchan, start, width to specify
00108                          output image cube.  See examples below
00109                  mode = 'velocity', means channels are specified in 
00110                       velocity.
00111                  mode = 'frequency', means channels are specified in 
00112                       frequency.
00113 
00114   >>> mode expandable parameters (for modes other than 'mfs')
00115                Start, width are given in units of channels, frequency 
00116                   or velocity as indicated by mode (note: only nearest neighbour 
00117                   interpolation is available at this time).
00118                nchan -- Number of channels (planes) in output image
00119                  default: 1; example: nchan=3
00120                start -- Start input channel (relative-0)
00121                  default=0; example: start=5
00122                width -- Output channel width in units of the input
00123                      channel width (>1 indicates channel averaging)
00124                  default=1; example: width=4
00125                interpolation -- Interpolation type of spectral data when gridded on
00126                      the uv-plane
00127                  default = 'linear'
00128                doconcat -- Tells autoclean to concatenate multiple channel images into
00129                      single image at the end of its run.  (Autoclean makes an image
00130                      for each channel, and cleans/boxes them one at a time.)
00131                  default = 'True'
00132            examples:
00133                spw = '0,1'; mode = 'mfs'
00134                   will produce one image made from all channels in spw 
00135                        0 and 1
00136                spw='0:5~28^2'; mode = 'mfs'
00137                   will produce one image made with channels 
00138                        (5,7,9,...,25,27)
00139                spw = '0'; mode = 'channel': nchan=3; start=5; width=4
00140                   will produce an image with 3 output planes
00141                   plane 1 contains data from channels (5+6+7+8)
00142                   plane 2 contains data from channels (9+10+11+12)
00143                   plane 3 contains data from channels (13+14+15+16)
00144                spw = '0:0~63^3'; mode='channel'; nchan=21; start = 0; 
00145                    width = 1
00146                   will produce an image with 20 output planes
00147                   Plane 1 contains data from channel 0
00148                   Plane 2 contains date from channel 2
00149                   Plane 21 contains data from channel 61
00150                spw = '0:0~40^2'; mode = 'channel'; nchan = 3; start = 
00151                    5; width = 4
00152                   will produce an image with three output planes
00153                   plane 1 contains channels (5,7)
00154                   plane 2 contains channels (13,15)
00155                   plane 3 contains channels (21,23)
00156 
00157        psfmode -- method of PSF calculation to use during minor cycles:
00158                default: 'clark': Options: 'clark','clarkstokes', 'hogbom'
00159                'clark'  use smaller beam (faster, usually good enough);
00160                 for stokes images clean components peaks are searched in the I^2+Q^2+U^2+V^2 domain 
00161                'clarkstokes' locate clean components independently in each stokes image
00162                'hogbom' full-width of image (slower, better for poor 
00163                uv-coverage)
00164                Note:  psfmode will be used to clean is imagermode = ''
00165        imagermode -- Advanced imaging e.g mosaic or Cotton-Schwab clean
00166                default: imagermode='': Options: '', 'csclean'
00167                default ''  => psfmode cleaning algorithm used
00168 
00169   >>> imagermode='csclean' expandable parameter(s): 
00170             Image using the Cotton-Schwab algorithm in between major cycles
00171             cyclefactor -- Change the threshold at which
00172                           the deconvolution cycle will stop, degrid
00173                           and subtract from the visibilities.  For
00174                           poor PSFs, reconcile often (cyclefactor=4 or
00175                           5); For good PSFs, use cyclefactor 1.5 to
00176                           2.0. Note: threshold = cyclefactor * max
00177                           sidelobe * max residual.
00178                           default: 1.5; example: cyclefactor=4
00179             cyclespeedup -- Cycle threshold doubles in this
00180                           number of iterations default: -1;
00181                           example: cyclespeedup=3
00182                           try cyclespeedup = 50 to speed up cleaning 
00183              
00184        imsize -- Image pixel size (x,y).  DOES NOT HAVE TO BE A POWER OF 2
00185                default = [256,256]; example: imsize=[350,350]
00186                imsize = 500 is equivalent to [500,500]
00187                Avoid odd-numbered imsize.
00188        cell -- Cell size (x,y)
00189                default= '1.0arcsec';
00190                example: cell=['0.5arcsec,'0.5arcsec'] or
00191                cell=['1arcmin', '1arcmin']
00192                cell = '1arcsec' is equivalent to ['1arcsec','1arcsec']
00193                NOTE:cell = 2.0 => ['2arcsec', '2arcsec']
00194        phasecenter -- direction measure  or fieldid for the mosaic center
00195                default: '' => first field selected ; example: phasecenter=6
00196                or phasecenter='J2000 19h30m00 -40d00m00'
00197        restfreq -- Specify rest frequency to use for output image
00198                default='' Occasionally it is necessary to set this (for
00199                example some VLA spectral line data).  For example for
00200                NH_3 (1,1) put restfreq='23.694496GHz'
00201        stokes -- Stokes parameters to image
00202                default='I'; example: stokes='IQUV';
00203                Options: 'I','IV''QU','IQUV','RR','LL','XX','YY','RRLL','XXYY'
00204 
00205        weighting -- Weighting to apply to visibilities:
00206                default='natural'; example: weighting='uniform';
00207                Options: 'natural','uniform','briggs', 
00208                        'superuniform','briggsabs','radial'
00209 
00210   >>> Weighting expandable parameters
00211                For weighting='briggs' and 'briggsabs'
00212                    robust -- Brigg's robustness parameter
00213                    default=0.0; example: robust=0.5;
00214                    Options: -2.0 to 2.0; -2 (uniform)/+2 (natural)
00215                For weighting='briggsabs'
00216                    noise   -- noise parameter to use for Briggs "abs" 
00217                    weighting
00218                    example noise='1.0mJy'
00219                npixels -- uv-cell area used for weight calculation
00220                    example npixels=1
00221                    Default = 0
00222                    superuniform:  0 Means 3x3 cells for weighting
00223                      the cell weight is proportional to the weight of
00224                      the 3x3 cells centered on it.
00225                    superuniform = F means 1x1 cell for averaging weights.
00226                    briggs/briggsabs: 0 is similar to 1x1 cell weight.
00227                      1 may? be similar to 3X3 cells.
00228                    Only npixels 0 or 1 recommended
00229                    
00230        mask -- Initial specification of cleanbox(es), mask image(s), and/or
00231            region(s) to be used for CLEANing.  For channel data (image cubes),
00232            any initial mask will be applied to every channel. mask default: 
00233            [] (no masking); Possible specification types: (a) Explicit
00234            cleanbox pixel ranges example: mask=[110,110,150,145] clean
00235            region with blc=110,100; trc=150,145 (pixel values) (b)
00236            Filename with cleanbox pixel values with ascii format:
00237            example: mask='mycleanbox.txt' <fieldid blc-x blc-y
00238            trc-x trc-y> on each line 
00239            1 45 66 123 124 
00240            2 23 100 300 340
00241            (c) Filename for image mask example: mask='myimage.mask'
00242            (d) Filename for region specification (e.g. from viewer)
00243            example: mask='myregion.rgn' (e) Combinations of any of the
00244            above example: mask=[[110,110,150,145],'mycleanbox.txt',
00245            'myimage.mask','myregion.rgn']
00246            If include outlier fields, then mask need to be spefied in
00247            nested lists: e.g. mask=[[[110,110,150,145],'myimage.mask'],[],[20,20,40,40]]
00248            (A clean box with [110,110,150,145] and a image mask for main field, 
00249             no mask for 1st outlier field, 1 clean box for second outlier field.)
00250        modelimage -- Name of model image(s) to initialize cleaning. If
00251                multiple images, then these will be added together to
00252                form initial starting model NOTE: these are in addition
00253                to any initial model in the <imagename>.model image file
00254                default: '' (none); example: modelimage='orion.model'
00255                modelimage=['orion.model','sdorion.image'] Note: if the
00256                units in the image are Jy/beam as in a single-dish
00257                image, then it will be converted to Jy/pixel as in a
00258                model image, using the restoring beam in the image
00259                header
00260   >>> uvtaper=True expandable parameters
00261                outertaper -- uv-taper on outer baselines in uv-plane
00262                  [bmaj, bmin, bpa] taper Gaussian scale in uv or 
00263                  angular units. NOTE: uv taper in (klambda) is roughly on-sky 
00264                  FWHM(arcsec/200)
00265                  default: outertaper=[]; no outer taper applied
00266                  example: outertaper=['5klambda']  circular taper 
00267                                 FWHM=5 kilo-lambda
00268                          outertaper=['5klambda','3klambda','45.0deg']
00269                          outertaper=['10arcsec'] on-sky FWHM 10"
00270                          outertaper=['300.0'] default units are meters 
00271                                 in aperture plane
00272                innertaper -- uv-taper in center of uv-plane
00273                  [bmaj,bmin,bpa] Gaussian scale at which taper falls to 
00274                  zero at uv=0
00275                  default: innertaper=[]; no inner taper applied
00276                  NOT YET IMPLEMENTED                
00277        niter -- Maximum number iterations over all clean iterations.
00278                default: 500;  example: niter=5000
00279        npercycle -- Number of clean minor cycles before making new clean region
00280            selection. 
00281            default: 100;  example: npercycle = 100
00282        npercycle_speedup: If no new clean regions found during an iteration of
00283            clean region selections, increase npercycle by this factor.
00284            (Npercycle returns to initial value if new clean regions are later
00285             found.)
00286            default: 1.5;  example: npercycle_speedup = 2
00287        gain -- Loop gain for CLEANing
00288                default: 0.1; example: gain=0.5
00289        pbcor -- Output primary beam-corrected image 
00290               default: pbcor=False; output un-corrected image 
00291               example: pbcor=True; output pb-corrected image (masked outside
00292                minpb) Note: if you set pbcor=False, you can later
00293                recover the pbcor image by dividing by the .flux image
00294                (e.g. using immath)
00295        minpb -- Minimum PB level to use default=0.1;
00296                The flux image is used to determine this
00297                except for the case of mosaic with ft='mosaic'
00298                where the flux.pbcoverage image is used.
00299                example:
00300                minpb=0.01 Note: this minpb is always in effect
00301                (regardless of pbcor=True/False) 
00302        clean_threshold -- Flux level at which to stop CLEANing
00303                default: '0.0mJy'; 
00304                example: threshold='2.3mJy'  (always include units)
00305                         threshold = '0.0023Jy'
00306                         threshold = '0.0023Jy/beam' (okay also)
00307        Nrms -- Stop cleaning when maximum residual is below this value times
00308            the current rms (outside the current clean regions).
00309            default: 6
00310            example: Nrms=4
00311        eps_maxres -- Convergence parameter to stop cleaning: stop if maximum
00312            residual has changed by less than a factor of eps_maxres.
00313            default: 0.01  (one per cent change)
00314            example: eps_maxres = 0.05
00315        allow_maxres_inc -- Parameter to stop cleaning: stop if maximum residual
00316            has increased between clean iterations this number of times.
00317            default: 3
00318            example: allow_maxres_inc = 2
00319        island_rms: threshold (this value times current rms) at which to box the
00320            residual image when searching for new clean regions
00321            default: 4
00322            example:  island_rms = 3
00323        diag: T/F switch to declare if pixels connected on the diagonal belong
00324            to the same island, when selecting pixels for clean boxing
00325            default: False
00326            example: diag = True
00327        peak_rms: threshold (this value times current rms) for peak pixel flux
00328            to qualify an island for clean boxing
00329            default: 6
00330            example: peak_rms = 5
00331        gain_threshold: threshold (this value times current maximum residual) of
00332            peak pixel in island to qualify island for clean boxing. 
00333            default: 0.1
00334            example: gain_threshold = 0.5
00335        Npeak: maximum number of new clean regions to add each iteration
00336            default: 3
00337            example: Npeak = 5
00338        shape: parameter to determine shape of clean regions. 
00339            0: all circles
00340            1: all boxes
00341            2: choose according to island shape (circles if island has similar
00342            dimension in x and y direction, box otherwise)
00343            default: 1  
00344            example: shape=2
00345        boxstretch: number of pixels to increase outward size of clean region,
00346            can range from -1 to 5. 
00347            default: 1
00348            example: boxstretch = 3
00349        irregsize: for islands this large (dimension in pixels) or larger, fill
00350            in mask with island's actual shape rather than using a box or
00351            circle.  Set to 0 to ignore this parameter.
00352            default: 100
00353            example: irregsize = 50
00354 
00355   
00356         """
00357         if type(imsize)==int: imsize=[imsize]
00358         if type(cell)==float: cell=[cell]
00359         if type(outertaper)==str: outertaper=[outertaper]
00360         if type(innertaper)==str: innertaper=[innertaper]
00361 
00362 #
00363 #    The following is work around to avoid a bug with current python translation
00364 #
00365         mytmp = {}
00366 
00367         mytmp['vis'] = vis
00368         mytmp['imagename'] = imagename
00369         mytmp['field'] = field
00370         mytmp['spw'] = spw
00371         mytmp['selectdata'] = selectdata
00372         mytmp['timerange'] = timerange
00373         mytmp['uvrange'] = uvrange
00374         mytmp['antenna'] = antenna
00375         mytmp['scan'] = scan
00376         mytmp['mode'] = mode
00377         mytmp['nchan'] = nchan
00378         mytmp['start'] = start
00379         mytmp['width'] = width
00380         mytmp['interpolation'] = interpolation
00381         mytmp['doconcat'] = doconcat
00382         mytmp['psfmode'] = psfmode
00383         mytmp['imagermode'] = imagermode
00384         mytmp['cyclefactor'] = cyclefactor
00385         mytmp['cyclespeedup'] = cyclespeedup
00386         mytmp['imsize'] = imsize
00387         if type(cell) == str :
00388            mytmp['cell'] = casac.quanta().quantity(cell)
00389         else :
00390            mytmp['cell'] = cell
00391         mytmp['phasecenter'] = phasecenter
00392         mytmp['restfreq'] = restfreq
00393         mytmp['stokes'] = stokes
00394         mytmp['weighting'] = weighting
00395         mytmp['robust'] = robust
00396         mytmp['noise'] = noise
00397         mytmp['npixels'] = npixels
00398         mytmp['interactive'] = interactive
00399         mytmp['mask'] = mask
00400         mytmp['modelimage'] = modelimage
00401         mytmp['uvtaper'] = uvtaper
00402         mytmp['outertaper'] = outertaper
00403         mytmp['innertaper'] = innertaper
00404         mytmp['niter'] = niter
00405         mytmp['npercycle'] = npercycle
00406         mytmp['npercycle_speedup'] = npercycle_speedup
00407         mytmp['gain'] = gain
00408         mytmp['pbcor'] = pbcor
00409         mytmp['minpb'] = minpb
00410         if type(clean_threshold) == str :
00411            mytmp['clean_threshold'] = casac.quanta().quantity(clean_threshold)
00412         else :
00413            mytmp['clean_threshold'] = clean_threshold
00414         mytmp['Nrms'] = Nrms
00415         mytmp['eps_maxres'] = eps_maxres
00416         mytmp['useabsresid'] = useabsresid
00417         mytmp['allow_maxres_inc'] = allow_maxres_inc
00418         mytmp['island_rms'] = island_rms
00419         mytmp['diag'] = diag
00420         mytmp['peak_rms'] = peak_rms
00421         mytmp['gain_threshold'] = gain_threshold
00422         mytmp['Npeak'] = Npeak
00423         mytmp['shape'] = shape
00424         mytmp['boxstretch'] = boxstretch
00425         mytmp['irregsize'] = irregsize
00426         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00427         trec = casac.utils().torecord(pathname+'autoclean.xml')
00428 
00429         casalog.origin('autoclean')
00430         if trec.has_key('autoclean') and casac.utils().verify(mytmp, trec['autoclean']) :
00431             result = task_autoclean.autoclean(vis, imagename, field, spw, selectdata, timerange, uvrange, antenna, scan, mode, nchan, start, width, interpolation, doconcat, psfmode, imagermode, cyclefactor, cyclespeedup, imsize, cell, phasecenter, restfreq, stokes, weighting, robust, noise, npixels, interactive, mask, modelimage, uvtaper, outertaper, innertaper, niter, npercycle, npercycle_speedup, gain, pbcor, minpb, clean_threshold, Nrms, eps_maxres, useabsresid, allow_maxres_inc, island_rms, diag, peak_rms, gain_threshold, Npeak, shape, boxstretch, irregsize)
00432 
00433         else :
00434           result = False
00435         return result