casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
widefield.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_widefield
00013 def widefield(vis=[''], imagename='', outlierfile='', field='', spw='', selectdata=False, timerange='', uvrange='', antenna='', scan='', mode='mfs', niter=500, gain=0.1, threshold='0.0Jy', psfmode='clark', ftmachine='', facets=3, wprojplanes=64, multiscale=[], negcomponent=0, interactive=False, mask=[], nchan=1, start=0, width=1, imsize=[256, 256], cell=['1.0arcsec', '1.0arcsec'], phasecenter='', restfreq='', stokes='I', weighting='natural', robust=0.0, npixels=0, noise='1.0Jy', cyclefactor=1.5, cyclespeedup=-1, npercycle=100, uvtaper=False, outertaper=[''], innertaper=['1.0'], restoringbeam=[''], calready=False):
00014 
00015         """Wide-field imaging and deconvolution with selected algorithm
00016 
00017         Wide-field imaging and deconvolution with selected algorithm:
00018 
00019         This is the main wide-field imaging/deconvolution task.  It
00020         uses the wprojection method for a large field of view, can
00021         make many facets, and can include outlier fields.  Several
00022         deconvolution algorithms are supported.  Interactive cleaning
00023         is also supported.
00024 
00025         For making large images (>2000 on a size), see hints at the
00026         end of the descriptions.  For making images larger than about
00027         5000x5000, the available memory must be larger than 2 Gbytes. For such 
00028         images therefore  a computer with a 64-bit operating system may be
00029         needed.
00030 
00031 
00032         Keyword arguments:
00033         vis -- Name of all input visibility files
00034                 default: none; example: vis='ngc5921.ms'
00035                 example: vis=['data01.ms', 'data02.ms']
00036         imagename -- Pre-name of output images:
00037                 default: none; example: imagename='n5921'
00038                 if outlier fields are included, then
00039                    imagename=['n5921', 'outlier1', outlier2']
00040                    and the first imagename is the wide-field image
00041                 output images names are: n5921.clean, n5921.residual,
00042                 n5921.model, n5921.interactive.mask
00043         mode -- Type of selection
00044                 default: 'mfs'; example: mode='channel';
00045                 Options: 'mfs', channel, velocity, frequency'
00046         alg -- Algorithm to use
00047                 default: 'clark';
00048                 Options: 'clark', 'hogbom','multiscale','entropy'
00049                     Strongly advise 'clark'.  multiscale and entropy
00050                     well-tested.
00051         imsize -- Image pixel size (x,y)
00052                 default = [256,256]; example: imsize=[500,500], or imsize=500
00053                 example for multiple fields: imsize=[(1000, 1000), (100, 100)]
00054         cell -- Cell size (x,y)
00055                 default=['1arcsec,'1arcsec']
00056                 example: cell=['0.5arcsec,'0.5arcsec'], or cell='0.5arcsec'
00057         phasecenter -- direction position or the field for the image center
00058                 A list of the above is needed for multiple-fields
00059                 default: '' -->field='0' as center; example: phasecenter='6'
00060                    phasecenter='J2000 19h30m00 -40d00m00'
00061                    phasecenter=['J2000 19h30m00 -40d00m00', 'J2000 19h57m00 40d00m00']
00062                       for wide-field, plus one outlier field.
00063         stokes -- Stokes parameters to image
00064                 default='I'; example: stokes='IQUV';
00065                 Options: 'I','IV','IQU','IQUV'
00066         niter -- Number iterations, set to zero for no CLEANing
00067                 default: 500; example: niter=500
00068         gain -- Loop gain for CLEANing
00069                 default: 0.1; example: gain=0.1
00070         threshold -- Flux level at which to stop CLEANing (units=mJy)
00071                 default: 0.0; example: threshold=0.0
00072         mask -- Name(s) of mask image(s) used for CLEANing
00073                 default: ''  example: mask='orion.mask'
00074                 Number of mask fields must equal number of imaged fields
00075         cleanbox -- List of [blc-x,blc-y,trc-x,trc-y] values
00076                 default: []; example: cleanbox=[110,110,150,145]
00077                 Note: This can also be a filename with clean values:
00078                 fieldindex blc-x blc-y trc-x trc-y
00079                 cleanbox = 'interactive' is very useful.
00080         --- Data Selection
00081         nchan -- Number of channels to select
00082                 default: 1; example: nchan=45
00083         start -- Start channel, 0-relative
00084                 default=0; example: start=5
00085                 if mode='frequency' then a frequency value e.g start='1.4GHz'
00086         width -- Channel width (value > 1 indicates channel averaging)
00087                 default=1; example: width=5
00088                 if mode='frequency' then a frequency value e.g  width='10kHz'
00089         step -- Step in channel number
00090                 default=1; example: step=2
00091         field -- Select field using field id(s) or field name(s).
00092                   [run listobs to obtain the list id's or names]
00093                default: ''=all fields
00094                If field string is a non-negative integer, it is assumed a field index
00095                  otherwise, it is assumed a field name
00096                field='0~2'; field ids 0,1,2
00097                field='0,4,5~7'; field ids 0,4,5,6,7
00098                field='3C286,3C295'; field named 3C286 adn 3C295
00099                field = '3,4C*'; field id 3, all names starting with 4C
00100                example for multiple ms in vis parameter:
00101                field=['0~2', '1,2']
00102         spw -- Select spectral window/channels
00103                default: ''=all spectral windows and channels
00104                spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00105                spw='<2';  spectral windows less than 2 (i.e. 0,1)
00106                spw='0:5~61'; spw 0, channels 5 to 61
00107                spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, channels 3 to 45.
00108                spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
00109                spw='0:0~10;15~60'; spectral window 0 with channels 0-10,15-60
00110                spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
00111                         spw 1, channels 20-30, and spw 2, channels, 1,2 and 3
00112                For multiple ms in vis parameter:
00113                spw=['0,10,3:3~45', '<2']
00114         timerange -- Select time range subset of data (not implemented yet)
00115             default='' meaning no time selection
00116             example: timerange='YYYY/MM/DD/HH:MM:SS.sss'
00117             timerange='< YYYY/MM/DD/HH:MM:SS.sss'
00118             timerange='> YYYY/MM/DD/HH:MM:SS.sss'
00119             timerange='ddd/HH:MM:SS.sss'
00120             timerange='< ddd/HH:MM:SS.sss'
00121             timerange='> ddd/HH:MM:SS.sss'
00122         restfreq -- Specify rest frequency to use for image
00123             default='' (i.e., try to use the restfreq specified in the visibility data)
00124 
00125         --- Weighting
00126         weighting -- Weighting to apply to visibilities
00127                 default='natural'; example: weighting='uniform';
00128                 Options: 'natural','uniform','briggs','briggsabs','radial', 'superuniform'
00129         robust -- 'briggs' and 'brigssabs' robustness parameter
00130                 default=0.0; example: robust=0.5;
00131                 Options: -2.0 to 2.0; -2 (uniform)/+2 (natural)
00132         npixels -- number of pixels to determine uv-cell size for weight calculation
00133                  -- Used with superuniform or briggs weighting schemes
00134                   example: npixels=3
00135 
00136         --- widefield controls
00137         ftmachine -- Gridding method for the image;
00138                 ft (standard interferometric gridding).
00139                 wproject (wprojection algorithm for gridding)
00140                 default: wproject
00141         wprojplanes -- Number w-projection planes to use for gridding
00142                 default: 256
00143                 example: wprojplanes=64
00144                    Good value = BMAX(klambda) * Map width(arcmin)^2 / 600
00145         facets   -- Number of facets along one axis on central image
00146                 image is divided in facets x facets rectangles.
00147                 default: 1
00148                 example: facets=3 makes 3x3 images to cover the field
00149                 if ftmachine = 'ft', only faceting is used
00150                 if ftmachine = 'wproject', both wplanes and faceting  
00151                          can be used  (see below).
00152 
00153         cyclefactor -- Change the threshold at which the deconvolution cycle will
00154                 stop and degrid and subtract from the visibilities. For bad PSFs,
00155                 reconcile often (cyclefactor=4 or 5); For good PSFs, use
00156                 cyclefactor 1.5 to 2.0.
00157                 default: 2.5; example: cyclefactor=4, but decreases speed considerably.
00158                 <cycle threshold = cyclefactor * max sidelobe * max residual>
00159         cyclespeedup -- Cycle threshold doubles in this number of iterations
00160                 default: -1; example: cyclespeedup=500
00161 
00162         --- MEM parameters (Experimental, not well-tested)
00163         sigma -- Target image sigma
00164                 default: '0.001Jy'; example: sigma='0.1Jy'
00165         targetflux -- Target flux for final image
00166                 default: '1.0Jy'; example: targetflux='200Jy'
00167         constrainflux -- Constrain image to match target flux;
00168                 otherwise, targetflux is used to initialize model only.
00169                 default: False; example: constrainflux=True
00170         prior -- Name of MEM prior images
00171                 default: ['']; example: prior='source_mem.image'
00172 
00173         --- Multi-scale parameters (Experimental, not well-tested)
00174         negcomponent -- Stop component search when the largest scale has found this
00175                 number of negative components; -1 means continue component search
00176                 even if the largest component is negative.
00177                 default: 2; example: negcomponent=-1
00178         scales -- Used for alg='multiscale'; set a number of scales or a vector
00179                 default: [0,3,10]; example: scales=[0.0,3.0,10.0, 30]
00180         --  interactive masking
00181         npercycle -- when cleanbox is set to 'interactive',
00182            this is the number of iterations between each clean to update mask
00183            interactively. However, this number can be adjusted during execution.
00184 
00185         uvtaper -- Apply additional uv tapering of the visibilities.
00186                default: uvtaper=False; example: uvtaper=True
00187                   uvtaper=True expandable parameters
00188                      outertaper -- uv-taper on outer baselines in uv-plane
00189                            [bmaj, bmin, bpa] taper Gaussian scale in uv or
00190                             angular units. NOTE: uv taper in (klambda) is  
00191                             roughly on-sky FWHM(arcsec/200)
00192                          default: outertaper=[]; no outer taper applied
00193                             example: outertaper=['5klambda']  circular taper
00194                                 FWHM=5 kilo-lambda
00195                                 outertaper=['5klambda','3klambda','45.0deg']
00196                                 outertaper=['10arcsec'] on-sky FWHM 10"
00197                                 outertaper=['300.0'] default units are meters
00198                                    in aperture plane
00199                      innertaper -- uv-taper in center of uv-plane
00200                              NOT YET IMPLEMENTED
00201 
00202         restoringbeam -- Output Gaussian restoring beam for CLEAN image
00203                 [bmaj, bmin, bpa] elliptical Gaussian restoring beam
00204                 default units are in arc-seconds for bmaj,bmin, degrees
00205                 for bpa default: restoringbeam=[]; Use PSF calculated
00206                 from dirty beam.
00207                 example: restoringbeam=['10arcsec'] circular Gaussian
00208                        FWHM 10" example:
00209                        restoringbeam=['10.0','5.0','45.0deg'] 10"x5"
00210                        at 45 degrees
00211 
00212         calready -- if True will create scratch columns if they are 
00213                 not there. And after clean completes the predicted model 
00214                 visibility is from the clean components are
00215                 written to the ms.        
00216 
00217         async --  Run asynchronously
00218                 default = False; do not run asychronously
00219 
00220  ======================================================================
00221 
00222                       HINTS ON RUNNING WIDEFIELD
00223 
00224       1.  Decide if the images will be specified directly in the  
00225           inputs or with an outlier file.  For more than a few fields,
00226           an outlier file more convenient.
00227 
00228          Direct Method:
00229 
00230             cell = ['1.0arcsec', '1.0arcsec']
00231             imagename = ['M1_0','M1_1','M1_2]
00232             imsize = [[1024,1024],[128,128],[128,128]]
00233             phasecenter = ['J2000 13h27m20.98 43d26m28.0', 
00234                       'J2000 13h30m52.159 43d23m08.02', 'J2000 13h24m08.16 43d09m48.0']
00235 
00236           Text file method  (in outlier.txt)
00237 
00238             imagename = 'M1'
00239             outlierfile = 'outlier.txt'
00240                [phasecenter, imsize ignored]
00241 
00242             Contents of outlier.txt
00243             C   0   1024 1024   13 27 20.98     43 26 28.0
00244             C   1    128  128   13 30 52.158    43 23 08.00
00245             C   2    128  128   13 24 08.163    43 09 48.00
00246 
00247          In both cases the following images will be made:
00248              M1_0.image, M1_1.image, M1_2.image     cleaned images
00249              M1.0.model, M1_1.model, M1_2.model     model images
00250              M1.0.residual, M1_1.residual, M1_2.residual     residual images
00251 
00252        2.  Wprojection:  It is fastest to use wprojection without faceting.
00253              ftmachine = 'wproject'
00254              wprojplane = NN
00255 
00256            The value of NN should be chosen as small as possible to reduce
00257            execution time.  The algorithm
00258                NN = BMAX(klambda) * imagewidth (arcmin)^2 / 600, with a minimum
00259                     of 16, should be adequate.
00260 
00261        3.  Depending on the memory of the computer, a limit of about
00262        5000x5000 may occur for example if a computer has 2Gbyte of
00263        RAM. Also a 32-bit computer has a maximum limit of 2Gbyte
00264        memory usable per process, irrespective of how much physical
00265        RAM is present. Hence it is recommended to move to a 64-bit
00266        computer with more than 2 GByte of RAM for >5000x5000 images
00267            
00268 
00269        4. For data with extremely large 'w' values, i.e low frequency,
00270        long baseline and very widefield image, the wprojection
00271        convolution can be very large and either not fit in memory or
00272        slow for processing.  In these cases you should consider using
00273        both ftmachine='wproject' and facets=xx where is 3.
00274 
00275   
00276         """
00277         if type(vis)==str: vis=[vis]
00278         if type(multiscale)==int: multiscale=[multiscale]
00279         if type(imsize)==int: imsize=[imsize]
00280         if type(cell)==float: cell=[cell]
00281         if type(outertaper)==str: outertaper=[outertaper]
00282         if type(innertaper)==str: innertaper=[innertaper]
00283         if type(restoringbeam)==str: restoringbeam=[restoringbeam]
00284 
00285 #
00286 #    The following is work around to avoid a bug with current python translation
00287 #
00288         mytmp = {}
00289 
00290         mytmp['vis'] = vis
00291         mytmp['imagename'] = imagename
00292         mytmp['outlierfile'] = outlierfile
00293         mytmp['field'] = field
00294         mytmp['spw'] = spw
00295         mytmp['selectdata'] = selectdata
00296         mytmp['timerange'] = timerange
00297         mytmp['uvrange'] = uvrange
00298         mytmp['antenna'] = antenna
00299         mytmp['scan'] = scan
00300         mytmp['mode'] = mode
00301         mytmp['niter'] = niter
00302         mytmp['gain'] = gain
00303         mytmp['threshold'] = threshold
00304         mytmp['psfmode'] = psfmode
00305         mytmp['ftmachine'] = ftmachine
00306         mytmp['facets'] = facets
00307         mytmp['wprojplanes'] = wprojplanes
00308         mytmp['multiscale'] = multiscale
00309         mytmp['negcomponent'] = negcomponent
00310         mytmp['interactive'] = interactive
00311         mytmp['mask'] = mask
00312         mytmp['nchan'] = nchan
00313         mytmp['start'] = start
00314         mytmp['width'] = width
00315         mytmp['imsize'] = imsize
00316         if type(cell) == str :
00317            mytmp['cell'] = casac.quanta().quantity(cell)
00318         else :
00319            mytmp['cell'] = cell
00320         mytmp['phasecenter'] = phasecenter
00321         mytmp['restfreq'] = restfreq
00322         mytmp['stokes'] = stokes
00323         mytmp['weighting'] = weighting
00324         mytmp['robust'] = robust
00325         mytmp['npixels'] = npixels
00326         mytmp['noise'] = noise
00327         mytmp['cyclefactor'] = cyclefactor
00328         mytmp['cyclespeedup'] = cyclespeedup
00329         mytmp['npercycle'] = npercycle
00330         mytmp['uvtaper'] = uvtaper
00331         mytmp['outertaper'] = outertaper
00332         mytmp['innertaper'] = innertaper
00333         mytmp['restoringbeam'] = restoringbeam
00334         mytmp['calready'] = calready
00335         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00336         trec = casac.utils().torecord(pathname+'widefield.xml')
00337 
00338         casalog.origin('widefield')
00339         if trec.has_key('widefield') and casac.utils().verify(mytmp, trec['widefield']) :
00340             result = task_widefield.widefield(vis, imagename, outlierfile, field, spw, selectdata, timerange, uvrange, antenna, scan, mode, niter, gain, threshold, psfmode, ftmachine, facets, wprojplanes, multiscale, negcomponent, interactive, mask, nchan, start, width, imsize, cell, phasecenter, restfreq, stokes, weighting, robust, npixels, noise, cyclefactor, cyclespeedup, npercycle, uvtaper, outertaper, innertaper, restoringbeam, calready)
00341 
00342         else :
00343           result = False
00344         return result