casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
task_widefield.py
Go to the documentation of this file.
00001 import os
00002 #import pdb
00003 from taskinit import *
00004 from cleanhelper import *
00005 
00006 def 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):
00007         """Calculate a wide-field deconvolved image with selected algorithm:
00008 
00009         """
00010         ms1=mstool()
00011         ###
00012         #Python script
00013         try:
00014                 casalog.origin('widefield')
00015                 multims=False
00016                 if((type(vis)==list)):
00017                         if(len(vis) > 1):
00018                                 multims=True
00019                         else:
00020                                 vis=vis[0]
00021                 multifield=False
00022                 if(multims):
00023                         print ' multiple ms not handle for now'
00024                         return
00025 
00026 
00027                 if((type(imagename)==list) & (len(imagename) >1)):
00028                         multifield=True
00029                 else:
00030                         if((type(phasecenter) == list) and (len(phasecenter) >1)):
00031                                 raise TypeError, 'Number of phasecenters has be equal to number of images'
00032                         
00033         
00034 
00035 
00036 ###Set image parameters
00037                 casalog.origin('widefield')
00038                 im1=imtool()
00039                 if(multims):
00040                         imset=cleanhelper()
00041                 else:
00042                         imset=cleanhelper(im1, vis, calready)
00043 #
00044 #                if(multims):
00045 #                       visi=vis[len(vis)-1]
00046 #               else:
00047 #                       visi=vis
00048 
00049                 
00050 
00051 
00052 #               if(multifield):
00053 #                       if(type(phasecenter) != list):
00054 #                               raise TypeError, 'Number of phasecenters has be equal to number of images'
00055 #                       for k in range(len(phasecenter)):
00056 #                               pc=phasecenter[k]
00057 #                               phasecenter[k]=test_phasecenter(pc, visi)
00058 #               else:
00059 #                       phasecenter=test_phasecenter(phasecenter, visi)
00060 #
00061 #               spwindex=-1;
00062 #               spws=spw
00063 #               if(multims & (type(spw)==list)):
00064 #                       spws=spw[0]
00065 #               if( (spws==-1) or (spws=='-1')  or (spws=='') or (spws==[-1])):
00066 #                        spwindex=-1
00067 #                       spws=''
00068 #                else:
00069 #                       thems=vis
00070 #                       if(multims):
00071 #                               thems=vis[0]
00072 #                        spwindex=ms1.msseltoindex(thems, spw=spws)['spw'].tolist()
00073                 
00074 
00075                 
00076 
00077 #####
00078                 imageids=[]
00079                 imsizes=[]
00080                 phasecenters=[]
00081                 rootname=''
00082                 if(len(outlierfile) != 0):
00083                         
00084                         imsizes,phasecenters,imageids=imset.readoutlier(outlierfile)
00085                         if(type(rootname)==list):
00086                                 rootname=imagename[0]
00087                         else:
00088                                 rootname=imagename
00089                         if(len(imageids) > 1):
00090                                 multifield=True
00091                                 
00092                 else:
00093                         imsizes=imsize
00094                         phasecenters=phasecenter
00095                         imageids=imagename
00096 
00097                 
00098 
00099                 imset.definemultiimages(rootname, imsizes, cell, stokes, mode, spw, nchan, start,width, restfreq, field, phasecenters, imageids, facets)
00100 
00101 ############Data Selection
00102                 if(multims):
00103                         if(type(spw) == list):
00104                                 if(len(spw) != len(vis)):
00105                                         raise ValueError, 'Number of spw selection should match number of data sets'
00106                         if(type(field) == list):
00107                                 if(len(field) != len(vis)):
00108                                         raise ValueError, 'Number of field selection should match number of data sets'
00109                         for k in range(len(vis)):
00110                                 spws=spw
00111                                 if(type(spw) != list):
00112                                         spws=spw
00113                                 else:
00114                                         spws=spw[k]
00115                                 fields=field
00116                                 if(type(field) != list):
00117                                         fields=field
00118                                 else:
00119                                         fields=field[k]
00120                                 if(not os.path.exists(vis[k])):
00121                                         raise Exception, 'Visibility data %s set not found - please verify the name'%vis[k]
00122                                 im1.selectvis(vis=vis[k], spw=spws, field=fields)
00123                 elif ((type(vis)==str) & (os.path.exists(vis))):
00124                         imset.datselweightfilter(field=field, spw=spw,
00125                                          timerange=timerange, uvrange=uvrange,
00126                                          antenna=antenna, scan=scan,
00127                                          wgttype=weighting, robust=robust,
00128                                          noise=noise, npixels=npixels,
00129                                          mosweight=False,
00130                                          innertaper=innertaper,
00131                                          outertaper=outertaper,
00132                                                  calready=calready)
00133                 ############End of Data Selection
00134                 else:
00135                         raise Exception, 'Visibility data set not found - please verify the name'
00136 
00137 
00138 ###deal with masks
00139                 maskimage=''
00140                 if((mask==[]) or (mask=='')):
00141                         mask=['']
00142                 if (interactive):
00143                         if( (mask=='') or (mask==[''])or (mask==[])):
00144                                 if(type(imagename)==list):
00145                                         maskimage=[]
00146                                         for namoo in imagename:
00147                                                 maskimage.append(namoo+'.mask')
00148                                                 imset.maskimages[namoo]=namoo+'.mask'
00149                                 elif((type(imagename)==str) and (len(outlierfile) != 0)):
00150                                         maskimage=imagename+'.mask'
00151                                         imset.maskimages[imagename]=imagename+'.mask'
00152 
00153 
00154 
00155 
00156 ####
00157                 padd=1.0
00158                 if(facets > 1):
00159                         padd=1.2
00160                 im1.setoptions(ftmachine=ftmachine,padding=padd, wprojplanes=wprojplanes)
00161                 #im1.setmfcontrol(scaletype=scaletype,minpb=minpb)
00162                 im1.setmfcontrol(stoplargenegatives=negcomponent,cyclefactor=cyclefactor,cyclespeedup=cyclespeedup)
00163                 
00164                 ##do themask
00165                 if((maskimage=='') and (mask != [''])):
00166                         maskimage=imset.imagelist[0]+'.mask'
00167         
00168                 if(not multifield):
00169                         imset.makemaskimage(outputmask=maskimage, imagename=imagename,
00170                                                     maskobject=mask)
00171                         
00172                         
00173                 else:
00174                         imset.makemultifieldmask(mask)
00175                         maskimage=[]
00176                         for k in range(len(imset.maskimages)):
00177                                 maskimage.append(imset.maskimages[imset.imagelist[k]])
00178 
00179 
00180                 imset.setrestoringbeam(restoringbeam)
00181 
00182                 alg='mfclark'
00183 #####
00184 ###Determine algorithm to use
00185                 if((psfmode=='clark') or (psfmode=='hogbom')):
00186                         if(facets > 1):
00187                                 alg='wf'+psfmode
00188                         else:
00189                                 alg='mf'+psfmode
00190 
00191                 if(multiscale==[0]):
00192                         multiscale=[]
00193                 if((type(multiscale)==list) and (len(multiscale)>0)):
00194                         if(facets >1):
00195                                 raise Exception, 'multiscale with facets > 1 not allowed for now'
00196                         alg='mfmultiscale' 
00197                         im1.setscales(scalemethod='uservector',
00198                                         uservector=multiscale)
00199 
00200                 modelimage=[]
00201                 restoredimage=[]
00202                 residualimage=[]
00203                 for k in range(len(imset.imagelist)):
00204                         modelimage.append(imset.imagelist[k])
00205                         restoredimage.append(imset.imagelist[k]+'.image')
00206                         residualimage.append(imset.imagelist[k]+'.residual')
00207                         
00208                 ##will have to enable entropy later
00209                 if (alg=='mfentropy' or alg=='mfemptiness'):
00210                         im1.mem(algorithm=alg,niter=niter,sigma=sigma,targetflux=targetflux,constrainflux=constrainflux,keepfixed=[False],prior=prior,model=modelimage,residual=residualimage,image=restoredimage,mask=maskimage)
00211                 else:
00212                         im1.clean(algorithm=alg,niter=niter,gain=gain,threshold=qa.quantity(threshold,'mJy'),model=modelimage,residual=residualimage,image=restoredimage,mask=maskimage,interactive=interactive,npercycle=npercycle)
00213 
00214                 im1.done()
00215                 del im1
00216         #       del ms1
00217         
00218         except Exception, instance:
00219                 print '*** Error *** ',instance
00220                 raise Exception, instance
00221