casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
pclean_pg.py
Go to the documentation of this file.
00001 #
00002 # This file was generated using xslt from its XML file
00003 #
00004 # Copyright 2008, Associated Universities Inc., Washington DC
00005 #
00006 import sys
00007 import os
00008 from casac import *
00009 import string
00010 import time
00011 import inspect
00012 import gc
00013 import numpy
00014 from odict import odict
00015 from task_pclean import pclean
00016 from task_pclean import casalog
00017 
00018 class pclean_pg_:
00019     __name__ = "pclean"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (pclean_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, vis=None, imagename=None, imsize=None, cell=None, phasecenter=None, stokes=None, mask=None, field=None, spw=None, ftmachine=None, alg=None, scales=None, cyclefactor=None, majorcycles=None, niter=None, gain=None, threshold=None, weighting=None, robust=None, npixels=None, mode=None, nterms=None, start=None, nchan=None, width=None, restfreq=None, interactive=None, npercycle=None, wprojplanes=None, facets=None, overwrite=None, uvtaper=None, outertaper=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, pbcor=None, minpb=None, clusterdef=None, async=None):
00027 
00028         """Invert and deconvolve images with parallel engines
00029 
00030         Keyword arguments:
00031         Invert and deconvolve images with parallel engines
00032         Form images from visibilities. Handles continuum and spectral line 
00033         cubes using module pcont and pcube respectively.
00034  
00035         vis -- Name of input visibility file
00036                default: none; example: vis='ngc5921.ms'    
00037     
00038         imagename -- Pre-name of output CASA image. (only the prefix)
00039                default: none; 
00040                example: imagename='m2', output images are:
00041                  m2.image; cleaned and restored image
00042                            With or without primary beam correction
00043                  m2.psf; point-spread function (dirty beam)
00044                  m2.model; image of clean components
00045                  m2.mask; image containing clean regions, when interative=True
00046 
00047         imsize -- Image pixel size (x,y).  DOES NOT HAVE TO BE A POWER OF 2
00048                default: [256,256]; 
00049                example: imsize=[350,350]
00050                imsize=500 is equivalent to imsize=[500, 500]
00051                Avoid odd-numbered imsize.
00052     
00053         cell -- Cell size (x,y)
00054                default: '1.0arcsec';
00055                example: cell=['0.5arcsec', '0.5arcsec'] or
00056                         cell=['1arcmin', '1arcmin']
00057                cell='1arcsec' is equivalent to cell=['1arcsec', '1arcsec']
00058                NOTE:cell=2.0 => cell=['2arcsec', '2arcsec']
00059 
00060         phasecenter -- direction measure  or fieldid for the mosaic center
00061                default: '' => first field selected; 
00062                example: phasecenter=6
00063                      or phasecenter='J2000 19h30m00 -40d00m00'
00064         
00065         mask -- mask image to be used for CLEANing. As long as the image has
00066                the same shape (size), mask images from a previous
00067                interactive session can be used for a new execution.
00068                Only an image mask is allowed at this stage. Text formats not allowed yet.
00069 
00070         field -- Select fields in MS.  Use field id(s) or field name(s).
00071                     ['go listobs' to obtain the list id's or names]
00072                default: ''= all fields
00073                If field string is a non-negative integer, it is assumed to
00074                be a field index otherwise, it is assumed to be a field name
00075                examples:
00076                  field='0~2'; field ids 0,1,2
00077                  field='0,4,5~7'; field ids 0,4,5,6,7
00078                  field='3C286,3C295'; field named 3C286 and 3C295
00079                  field = '3,4C*'; field id 3, all names starting with 4C
00080     
00081         spw --Select spectral window/channels
00082                NOTE: This selects the data passed as the INPUT to mode
00083                default: ''=all spectral windows and channels
00084                examples:
00085                  spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00086                  spw='0:5~61'; spw 0, channels 5 to 61
00087                  spw='< 2';   spectral windows less than 2 (i.e. 0,1)
00088                  spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, 
00089                                      channels 3 to 45.
00090                  spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
00091                  spw='0:0~10;15~60'; spectral window 0 with channels 
00092                                       0-10,15-60
00093                  spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
00094                        spw 1, channels 20-30, and spw 2, channels, 1,2 and 3
00095 
00096         ftmachine -- Fourier Transform Engine (Gridding method)
00097                Options: 
00098                  'ft' (standard interferometric gridding), 
00099                  'sd' (standard single dish),
00100                  'mosaic' (grid using PB as convolution function).
00101                  'wproject' (wprojection gridder to correct for widefield 'w' term errors)
00102                default: 'ft'
00103  
00104         alg -- Deconvolution algorithm
00105                Options: 'clark', 'hogbom', 'multiscale'
00106                default: 'clark'
00107 
00108          cyclefactor -- Controls the threshhold at which the
00109                    deconvolution cycle will pause to degrid and subtract the
00110                    model from the visibilities (Cotton-Schwab (CS) major cycle).
00111                    With poor PSFs, reconcile often (cyclefactor=4 or 5) for
00112                    reliability. 
00113                    With good PSFs, use cyclefactor = 1.5 to 2.0 for speed. 
00114                    Note: threshold = cyclefactor * max sidelobe * max residual
00115                    default: 1.5; example: cyclefactor=4
00116                    cyclefactor=0 allows the user to control number of CS major cycle 
00117          >>>  majorcycles -- integer number of CS major cycles to do 
00118                default: 1; 
00119                example: majorcycles=10
00120     
00121         niter -- Maximum number iterations,
00122                if niter=0, then no CLEANing is done ("invert" only)
00123                default: 500; 
00124                example: niter=5000
00125 
00126         threshold -- Flux level (residual peak) at which to stop CLEANing
00127                default: '0.0mJy';
00128                example: 
00129                  threshold='2.3mJy'  (always include units)
00130                  threshold='0.0023Jy'
00131                  threshold='0.0023Jy/beam' (okay also)
00132     
00133         weighting -- Weighting to apply to visibilities:
00134                Options: 'natural','uniform','briggs', 
00135                         'superuniform','radial'
00136                default: 'natural'; 
00137                example: weighting='uniform';
00138 
00139         scales -- list of scales in pixel for multiscale clean 
00140                default: [0]
00141                example: scales=[0, 3, 10]
00142 
00143         mode -- type of image to be generated 
00144                Options: 'continuum', 'cube'
00145                default: 'continuum'
00146                example:
00147                  mode='cube'; Use with nchan, start, step to specify
00148                         output image cube.
00149                NOTE: mode='velocity' or 'channel' or 'frequency'
00150                are aliased to mode='cube' for backward compatibility 
00151                and comfort.
00152 
00153   >>> mode='cube' expandable parameters
00154            nchan -- Total number of channels in the output image.
00155               Example: nchan=100.
00156               Default: -1; Automatically selects enough channels to cover
00157               data selected by 'spw' and consistent with 'start' and 'step'
00158               It is often easiest to leave nchan at the default value.
00159            start -- First channel, velocity, or frequency.
00160               if start is an integer pclean will assume it is the a channel index
00161               if start is in units of velocity or frequency it will take it as such
00162               
00163               If the user use the the ms channel as starting pclean will assign 
00164               the first channel of the image to the data channel frequency in LSRK 
00165               of the first 
00166               spw selected at the first time seen in the data and the direction of the 
00167               source selected. 
00168               If the data is not in the LSRK frame the user should be aware that the 
00169               data channel indicated may not fall on the first image channel as time goes.
00170 
00171               example:start=5
00172              start can be in units of frequency or velocity too
00173              When velocity units is used it is obvious then that it is referring to the line
00174              whose restfrequency is provided by the user or is default one for the source 
00175              in the MS/SOURCE table.
00176              examples: start='5.0km/s', or start='22.3GHz'.
00177            width -- Output channel width
00178               should be in the same units as start 
00179               default=1; >1 indicates channel averaging
00180               if start is an integer, width has to be an integer defining the image channel 
00181               width by the number of channels of first spectral window selected
00182               example: width=4.
00183               when start is in frequency or velocity units then the width has to be in the same units.  default=''; 
00184              
00185               examples: width='1.0km/s', or width='24.2kHz'.
00186 
00187            
00188         interactive -- Create a mask interactively or not.
00189               interactive clean allows the user to build the cleaning
00190               mask interactively using the viewer.  
00191 
00192               default: False; 
00193               example: interactive=True
00194                 The viewer will open with the image displayed. Select the
00195                 region for the mask and double click in the middle of it.
00196 
00197          >>> npercycle -- Number of iteration in between viewer interactions.
00198                default=100
00199 
00200         pbcor -- Output primary beam-corrected image
00201                 If pbcor=False, the final output image is NOT corrected for
00202                 the PB pattern (particularly important for mosaics), and
00203                 therefore is not "flux correct". Correction can also be
00204                 done after the  fact using immath to divide
00205                 <imagename>.image by the <imagename>.flux image. 
00206                default: pbcor=False; output un-corrected image 
00207                example: pbcor=True; output pb-corrected image (masked outside
00208                         minpb) 
00209 
00210        >>> minpb -- Minimum PB level to use for pb-correction and pb-based masking.
00211                     default=0.2;
00212                     example: minpb=0.01 
00213                When ftmachine is *not* 'mosaic' :
00214                   minpb is applied to the flux image (sensitivity-weighted pb).
00215                When ftmachine='mosaic' :
00216                   minpb is applied to the flux.pbcoverage image 
00217  
00218         overwrite -- If False use existing model image of same name to continue clean 
00219                if True the imagename.model and other associated images are overwitten 
00220                if they exist
00221                default: True
00222 
00223 
00224          timerange  -- Select data based on time range:
00225                  default: '' (all); examples,
00226                  timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00227                    Note: if YYYY/MM/DD is missing date defaults to first 
00228                    day in data set
00229                    timerange='09:14:0~09:54:0' picks 40 min on first day
00230                    timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 
00231                    30min on NEXT day
00232                    timerange='09:44:00' pick data within one integration 
00233                    of time
00234                    timerange='>10:24:00' data after this time
00235                    For multiple MS input, a list of timerange strings can be
00236                  used:
00237           uvrange -- Select data within uvrange (default units meters)
00238                    default: '' (all); example:
00239                    uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda
00240                    uvrange='>4klambda';uvranges greater than 4 kilo lambda
00241           antenna -- Select data based on antenna/baseline
00242                    default: '' (all)
00243                    If antenna string is a non-negative integer, it is 
00244                    assumed to be an antenna index, otherwise, it is
00245                    considered an antenna name.
00246                    antenna='5&6'; baseline between antenna index 5 and 
00247                                  index 6.
00248                    antenna='VA05&VA06'; baseline between VLA antenna 5 
00249                                        and 6.
00250                    antenna='5&6;7&8'; baselines 5-6 and 7-8
00251                    antenna='5'; all baselines with antenna index 5
00252                    antenna='05'; all baselines with antenna number 05 
00253                                 (VLA old name)
00254                    antenna='5,6,9'; all baselines with antennas 5,6,9 
00255                                    index number
00256                scan -- Scan number range.
00257                    default: '' (all)
00258                    example: scan='1~5
00259                observation -- Observation ID range.
00260                    default: '' (all)
00261                    example: observation='1~5'
00262 
00263 
00264         clusterdef -- Name of a file that contains the cluster definition.
00265                       NOTE: there is a chapter in the cookbook on how to 
00266                       define this file
00267                        If clusterdef='' (the default) then all the cores, if possible, 
00268                        of the machine on 
00269                        which casapy is run will be used.
00270                   
00271           Example of a cube imaging run:
00272           
00273           pclean(vis="ngc5921.ms.contsub",imagename="loulou",imsize=[2500, 2500],
00274           cell=['15.0arcsec', '15.0arcsec'],phasecenter="",stokes="I",field="0",spw="*",
00275           ftmachine="ft",alg="hogbom",majorcycles=2, niter=6000,gain=0.1,
00276           threshold="8mJy",weighting="briggs",robust=0.5,npixels=0,mode="cube",
00277           start=5,nchan=46,width=1,interactive=True,overwrite=True,uvtaper=False,
00278           outertaper=[''],pbcor=True)              
00279                        
00280           Example of a continuum run:
00281 
00282           pclean(vis='sim100g_4chan15kRows.ms',
00283           imagename='hundredG_cont', imsize=[1500, 1500],
00284           cell=['0.135arcsec', '0.135arcsec'], mode='continuum', phasecenter='0',
00285           field='0', spw='*', ftmachine='wproject', wprojplanes=128,
00286           threshold='0.1mJy', 
00287           majorcycles=4, niter=10000, alg='clark',
00288           weighting='natural',
00289           overwrite=True)
00290 
00291  
00292         """
00293         a=inspect.stack()
00294         stacklevel=0
00295         for k in range(len(a)):
00296           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00297                 stacklevel=k
00298                 break
00299         myf=sys._getframe(stacklevel).f_globals
00300         myf['__last_task'] = 'pclean'
00301         myf['taskname'] = 'pclean'
00302         ###
00303         myf['update_params'](func=myf['taskname'],printtext=False)
00304         ###
00305         ###
00306         #Handle globals or user over-ride of arguments
00307         #
00308         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00309         useLocalDefaults = False
00310 
00311         for item in function_signature_defaults.iteritems():
00312                 key,val = item
00313                 keyVal = eval(key)
00314                 if (keyVal == None):
00315                         #user hasn't set it - use global/default
00316                         pass
00317                 else:
00318                         #user has set it - use over-ride
00319                         if (key != 'self') :
00320                            useLocalDefaults = True
00321                         #myf[key]=keyVal
00322 
00323         myparams = {}
00324         if useLocalDefaults :
00325            for item in function_signature_defaults.iteritems():
00326                key,val = item
00327                keyVal = eval(key)
00328                exec('myparams[key] = keyVal')
00329                if (keyVal == None):
00330                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00331                    keyVal = eval(key)
00332                    if(type(keyVal) == dict) :
00333                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00334 
00335         else :
00336             uselessvariable = None 
00337             myparams['vis'] = vis = myf['vis']
00338             myparams['imagename'] = imagename = myf['imagename']
00339             myparams['imsize'] = imsize = myf['imsize']
00340             myparams['cell'] = cell = myf['cell']
00341             myparams['phasecenter'] = phasecenter = myf['phasecenter']
00342             myparams['stokes'] = stokes = myf['stokes']
00343             myparams['mask'] = mask = myf['mask']
00344             myparams['field'] = field = myf['field']
00345             myparams['spw'] = spw = myf['spw']
00346             myparams['ftmachine'] = ftmachine = myf['ftmachine']
00347             myparams['alg'] = alg = myf['alg']
00348             myparams['scales'] = scales = myf['scales']
00349             myparams['cyclefactor'] = cyclefactor = myf['cyclefactor']
00350             myparams['majorcycles'] = majorcycles = myf['majorcycles']
00351             myparams['niter'] = niter = myf['niter']
00352             myparams['gain'] = gain = myf['gain']
00353             myparams['threshold'] = threshold = myf['threshold']
00354             myparams['weighting'] = weighting = myf['weighting']
00355             myparams['robust'] = robust = myf['robust']
00356             myparams['npixels'] = npixels = myf['npixels']
00357             myparams['mode'] = mode = myf['mode']
00358             myparams['nterms'] = nterms = myf['nterms']
00359             myparams['start'] = start = myf['start']
00360             myparams['nchan'] = nchan = myf['nchan']
00361             myparams['width'] = width = myf['width']
00362             myparams['restfreq'] = restfreq = myf['restfreq']
00363             myparams['interactive'] = interactive = myf['interactive']
00364             myparams['npercycle'] = npercycle = myf['npercycle']
00365             myparams['wprojplanes'] = wprojplanes = myf['wprojplanes']
00366             myparams['facets'] = facets = myf['facets']
00367             myparams['overwrite'] = overwrite = myf['overwrite']
00368             myparams['uvtaper'] = uvtaper = myf['uvtaper']
00369             myparams['outertaper'] = outertaper = myf['outertaper']
00370             myparams['timerange'] = timerange = myf['timerange']
00371             myparams['uvrange'] = uvrange = myf['uvrange']
00372             myparams['antenna'] = antenna = myf['antenna']
00373             myparams['scan'] = scan = myf['scan']
00374             myparams['observation'] = observation = myf['observation']
00375             myparams['pbcor'] = pbcor = myf['pbcor']
00376             myparams['minpb'] = minpb = myf['minpb']
00377             myparams['clusterdef'] = clusterdef = myf['clusterdef']
00378 
00379         if type(imsize)==int: imsize=[imsize]
00380         if type(cell)==float: cell=[cell]
00381         if type(scales)==int: scales=[scales]
00382         if type(outertaper)==str: outertaper=[outertaper]
00383 
00384         result = None
00385 
00386 #
00387 #    The following is work around to avoid a bug with current python translation
00388 #
00389         mytmp = {}
00390 
00391         mytmp['vis'] = vis
00392         mytmp['imagename'] = imagename
00393         mytmp['imsize'] = imsize
00394         if type(cell) == str :
00395            mytmp['cell'] = casac.quanta().quantity(cell)
00396         else :
00397            mytmp['cell'] = cell
00398         mytmp['phasecenter'] = phasecenter
00399         mytmp['stokes'] = stokes
00400         mytmp['mask'] = mask
00401         mytmp['field'] = field
00402         mytmp['spw'] = spw
00403         mytmp['ftmachine'] = ftmachine
00404         mytmp['alg'] = alg
00405         mytmp['scales'] = scales
00406         mytmp['cyclefactor'] = cyclefactor
00407         mytmp['majorcycles'] = majorcycles
00408         mytmp['niter'] = niter
00409         mytmp['gain'] = gain
00410         mytmp['threshold'] = threshold
00411         mytmp['weighting'] = weighting
00412         mytmp['robust'] = robust
00413         mytmp['npixels'] = npixels
00414         mytmp['mode'] = mode
00415         mytmp['nterms'] = nterms
00416         mytmp['start'] = start
00417         mytmp['nchan'] = nchan
00418         mytmp['width'] = width
00419         mytmp['restfreq'] = restfreq
00420         mytmp['interactive'] = interactive
00421         mytmp['npercycle'] = npercycle
00422         mytmp['wprojplanes'] = wprojplanes
00423         mytmp['facets'] = facets
00424         mytmp['overwrite'] = overwrite
00425         mytmp['uvtaper'] = uvtaper
00426         mytmp['outertaper'] = outertaper
00427         mytmp['timerange'] = timerange
00428         mytmp['uvrange'] = uvrange
00429         mytmp['antenna'] = antenna
00430         mytmp['scan'] = scan
00431         mytmp['observation'] = observation
00432         mytmp['pbcor'] = pbcor
00433         mytmp['minpb'] = minpb
00434         mytmp['clusterdef'] = clusterdef
00435         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00436         trec = casac.utils().torecord(pathname+'pclean.xml')
00437 
00438         casalog.origin('pclean')
00439         if not trec.has_key('pclean') or not casac.utils().verify(mytmp, trec['pclean']) :
00440             return False
00441 
00442 
00443         try :
00444           casalog.post('')
00445           casalog.post('##########################################')
00446           casalog.post('##### Begin Task: pclean           #####')
00447           casalog.post('')
00448           result = pclean(vis, imagename, imsize, cell, phasecenter, stokes, mask, field, spw, ftmachine, alg, scales, cyclefactor, majorcycles, niter, gain, threshold, weighting, robust, npixels, mode, nterms, start, nchan, width, restfreq, interactive, npercycle, wprojplanes, facets, overwrite, uvtaper, outertaper, timerange, uvrange, antenna, scan, observation, pbcor, minpb, clusterdef)
00449           casalog.post('')
00450           casalog.post('##### End Task: pclean           #####')
00451           casalog.post('##########################################')
00452 
00453 
00454 # saveinputs for individule engine has no use
00455 # saveinputs should alos be removed from casa_in_py.py
00456 #
00457 #
00458 #          saveinputs = myf['saveinputs']
00459 #          saveinputs('pclean', 'pclean.last', myparams)
00460 #
00461 #
00462         except Exception, instance:
00463           #print '**** Error **** ',instance
00464           pass
00465 
00466         gc.collect()
00467         return result
00468 #
00469 #
00470 ##
00471 #    def paramgui(self, useGlobals=True):
00472 #        """
00473 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00474 #        """
00475 #        import paramgui
00476 #
00477 #        a=inspect.stack()
00478 #        stacklevel=0
00479 #        for k in range(len(a)):
00480 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00481 #            stacklevel=k
00482 #            break
00483 #        myf = sys._getframe(stacklevel).f_globals
00484 #
00485 #        if useGlobals:
00486 #            paramgui.setGlobals(myf)
00487 #        else:
00488 #            paramgui.setGlobals({})
00489 #
00490 #        paramgui.runTask('pclean', myf['_ip'])
00491 #        paramgui.setGlobals({})
00492 #
00493 #
00494 #
00495 #
00496     def defaults(self, param=None):
00497         a=inspect.stack()
00498         stacklevel=0
00499         for k in range(len(a)):
00500           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00501                 stacklevel=k
00502                 break
00503         myf=sys._getframe(stacklevel).f_globals
00504         a = odict()
00505         a['vis']  = ''
00506         a['imagename']  = ''
00507         a['imsize']  = [256, 256]
00508         a['cell']  = ['1.0arcsec', '1.0arcsec']
00509         a['phasecenter']  = ''
00510         a['stokes']  = 'I'
00511         a['mask']  = ''
00512         a['field']  = ''
00513         a['spw']  = ''
00514         a['ftmachine']  = 'ft'
00515         a['alg']  = 'clark'
00516         a['cyclefactor']  = 1.5
00517         a['niter']  = 500
00518         a['gain']  = 0.1
00519         a['threshold']  = '0.0Jy'
00520         a['weighting']  = 'natural'
00521         a['mode']  = 'continuum'
00522         a['interactive']  = False
00523         a['overwrite']  = True
00524         a['uvtaper']  = False
00525         a['timerange']  = ''
00526         a['uvrange']  = ''
00527         a['antenna']  = ''
00528         a['scan']  = ''
00529         a['observation']  = ''
00530         a['pbcor']  = False
00531         a['minpb']  = 0.2
00532         a['clusterdef']  = ''
00533 
00534         a['async']=False
00535         a['mode'] = {
00536                     0:odict([{'value':'continuum'}, {'nterms':1}]), 
00537                     1:odict([{'value':'mfs'}, {'nterms':1}]), 
00538                     2:odict([{'value':'cube'}, {'start':0}, {'nchan':2}, {'width':1}, {'restfreq':''}]), 
00539                     3:odict([{'value':'channel'}, {'start':0}, {'nchan':2}, {'width':1}, {'restfreq':''}]), 
00540                     4:odict([{'value':'frequency'}, {'start':'0GHz'}, {'nchan':2}, {'width':'1Hz'}, {'restfreq':''}]), 
00541                     5:odict([{'value':'velocity'}, {'start':'0km/s'}, {'nchan':2}, {'width':'1m/s'}, {'restfreq':''}])}
00542         a['cyclefactor'] = {
00543                     0:{'value':1.5}, 
00544                     1:odict([{'value':0.0}, {'majorcycles':1}])}
00545         a['ftmachine'] = {
00546                     0:{'value':'ft'}, 
00547                     1:odict([{'value':'wproject'}, {'wprojplanes':128}, {'facets':1}]), 
00548                     2:{'value':'mosaic'}, 
00549                     3:{'value':'sd'}}
00550         a['alg'] = {
00551                     0:{'value':'clark'}, 
00552                     1:{'value':'hogbom'}, 
00553                     2:odict([{'value':'multiscale'}, {'scales':[1]}])}
00554         a['weighting'] = {
00555                     0:{'value':'natural'}, 
00556                     1:{'value':'radial'}, 
00557                     2:{'value':'uniform'}, 
00558                     3:odict([{'value':'briggs'}, {'robust':0.0}, {'npixels':0}]), 
00559                     4:odict([{'value':'briggsabs'}, {'npixels':0}, {'robust':0.0}]), 
00560                     5:{'value':'radial'}, 
00561                     6:odict([{'value':'superuniform'}, {'npixels':0}])}
00562         a['uvtaper'] = {
00563                     0:{'value':False}, 
00564                     1:odict([{'value':True}, {'outertaper':[]}])}
00565         a['interactive'] = {
00566                     0:{'value':False}, 
00567                     1:odict([{'value':True}, {'npercycle':100}])}
00568 
00569 ### This function sets the default values but also will return the list of
00570 ### parameters or the default value of a given parameter
00571         if(param == None):
00572                 myf['__set_default_parameters'](a)
00573         elif(param == 'paramkeys'):
00574                 return a.keys()
00575         else:
00576                 if(a.has_key(param)):
00577                    #if(type(a[param]) == dict) :
00578                    #   return a[param][len(a[param])-1]['value']
00579                    #else :
00580                       return a[param]
00581 
00582 
00583 #
00584 #
00585     def check_params(self, param=None, value=None):
00586       a=inspect.stack() 
00587       stacklevel=0
00588       for k in range(len(a)):
00589         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00590             stacklevel=k
00591             break
00592       myf=sys._getframe(stacklevel).f_globals
00593 
00594 #      print 'param:', param, 'value:', value
00595       try :
00596          if str(type(value)) != "<type 'instance'>" :
00597             value0 = value
00598             value = myf['cu'].expandparam(param, value)
00599             matchtype = False
00600             if(type(value) == numpy.ndarray):
00601                if(type(value) == type(value0)):
00602                   myf[param] = value.tolist()
00603                else:
00604                   #print 'value:', value, 'value0:', value0
00605                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00606                   myf[param] = value0
00607                   if type(value0) != list :
00608                      matchtype = True
00609             else :
00610                myf[param] = value
00611             value = myf['cu'].verifyparam({param:value})
00612             if matchtype:
00613                value = False
00614       except Exception, instance:
00615          #ignore the exception and just return it unchecked
00616          myf[param] = value
00617       return value
00618 
00619 #
00620 #
00621     def description(self, key='pclean', subkey=None):
00622         desc={'pclean': 'Invert and deconvolve images with parallel engines',
00623                'vis': 'Name of input visibility file',
00624                'imagename': 'Pre-name of output images',
00625                'imsize': 'Image size in pixels (nx,ny), symmetric for single value',
00626                'cell': 'The image cell size in arcseconds. ',
00627                'phasecenter': 'Image center: direction or field index',
00628                'stokes': 'Stokes params to image (eg I,IV,IQ,IQUV)',
00629                'mask': 'mask image',
00630                'field': 'Field Name or id',
00631                'spw': 'Spectral windows e.g. \'0~3\', \'\' is all',
00632                'ftmachine': 'Fourier Transform Engine (\'ft\', \'sd\', \'mosaic\' or \'wproject\')',
00633                'alg': 'Deconvolution algorithm (\'clark\', \'hogbom\', \'multiscale\')',
00634                'scales': 'Scales to use in deconvolution',
00635                'cyclefactor': 'Control number of major cycle, threshold of cycle=residualPeak*psfSidelobe*cyclefactor ',
00636                'majorcycles': 'Number of major cycles',
00637                'niter': 'Maximum number of iterations',
00638                'gain': 'Gain to use in deconvolution',
00639                'threshold': 'Flux level to stop cleaning, must include units: \'1.0mJy\'',
00640                'weighting': 'Type of weighting',
00641                'robust': 'Briggs robustness parameter',
00642                'npixels': 'number of pixels for superuniform or briggs weighting',
00643                'mode': 'Clean mode (\'continuum\', \'cube\')',
00644                'nterms': 'number of terms for multifrequency synthesis',
00645                'start': 'Begin the output cube at the frequency of this channel in the MS in channel number or frequency or velocity',
00646                'nchan': 'Number of channels (planes) in output image',
00647                'width': 'width of output channel ',
00648                'restfreq': 'rest frequency to assign to image cube for velocity translattion',
00649                'interactive': 'Interactive clean',
00650                'npercycle': 'niter per cycle of interactive clean',
00651                'wprojplanes': 'Number of w-projection planes for convolution',
00652                'facets': 'Number of facats along each axis',
00653                'overwrite': 'Overwrite an existing model image',
00654                'uvtaper': 'Apply additional uv tapering of visibilities',
00655                'outertaper': 'uv-taper on outer baselines in uv-plane',
00656                'timerange': 'Range of time to select from data',
00657                'uvrange': 'Select data within uvrange ',
00658                'antenna': 'Select data based on antenna/baseline',
00659                'scan': 'Scan number range',
00660                'observation': 'Observation ID range',
00661                'pbcor': 'Correct for the primary beam post deconvolution',
00662                'minpb': 'Fractional of peak of pb coverage where to stop the  pb correction',
00663                'clusterdef': 'File that contains cluster definition',
00664 
00665                'async': 'If true the taskname must be started using pclean(...)'
00666               }
00667 
00668 #
00669 # Set subfields defaults if needed
00670 #
00671 
00672         if(desc.has_key(key)) :
00673            return desc[key]
00674 
00675     def itsdefault(self, paramname) :
00676         a = {}
00677         a['vis']  = ''
00678         a['imagename']  = ''
00679         a['imsize']  = [256, 256]
00680         a['cell']  = ['1.0arcsec', '1.0arcsec']
00681         a['phasecenter']  = ''
00682         a['stokes']  = 'I'
00683         a['mask']  = ''
00684         a['field']  = ''
00685         a['spw']  = ''
00686         a['ftmachine']  = 'ft'
00687         a['alg']  = 'clark'
00688         a['scales']  = [0]
00689         a['cyclefactor']  = 1.5
00690         a['majorcycles']  = 1
00691         a['niter']  = 500
00692         a['gain']  = 0.1
00693         a['threshold']  = '0.0Jy'
00694         a['weighting']  = 'natural'
00695         a['robust']  = 0.0
00696         a['npixels']  = 0
00697         a['mode']  = 'continuum'
00698         a['nterms']  = 1
00699         a['start']  = 0
00700         a['nchan']  = 1
00701         a['width']  = 1
00702         a['restfreq']  = ''
00703         a['interactive']  = False
00704         a['npercycle']  = 100
00705         a['wprojplanes']  = 128
00706         a['facets']  = 1
00707         a['overwrite']  = True
00708         a['uvtaper']  = False
00709         a['outertaper']  = ['']
00710         a['timerange']  = ''
00711         a['uvrange']  = ''
00712         a['antenna']  = ''
00713         a['scan']  = ''
00714         a['observation']  = ''
00715         a['pbcor']  = False
00716         a['minpb']  = 0.2
00717         a['clusterdef']  = ''
00718 
00719         if a.has_key(paramname) :
00720               return a[paramname]
00721 pclean_pg = pclean_pg_()