casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
widebandpbcor.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_widebandpbcor
00013 def widebandpbcor(vis='', imagename='', nterms=2, threshold='', action='pbcor', reffreq='', pbmin=0.2, field='', spwlist=[], chanlist=[], weightlist=[]):
00014 
00015         """Wideband PB-correction on the output of the MS-MFS algorithm
00016 
00017    Wide-band Primary-beam correction
00018 
00019     (1) Compute a set of Primary Beams at the specified frequencies
00020     (2) Calculate Taylor-coefficient images that represent the PB spectrum
00021     (3) Perform a polynomial division to PB-correct the output Taylor-coefficient
00022           images from the MS-MFS algorithm ( clean(nterms>1) )
00023     (4) Recompute spectral index (and curvature) using the corrected Taylor-coefficient images.
00024 
00025    [ Optionally, skip PB-correction, and only recalculate spectral index
00026       with a different threshold ]
00027 
00028    This is a temporary task, meant for use until projection-based gridding algorithms
00029    are available via the 'clean' task.
00030 
00031    An output directory named imagename.pbcor.workdirectory is created, and filled with
00032    an image-cube of the evaluated primary beams at all specified frequencies,
00033    Taylor-coefficients, and a 'spectral index' due to the primary beam.  
00034    Note that for the actual pb-correction, only the Taylor-coefficient images are used.
00035  
00036    Task parameters :
00037 
00038    vis -- Name of input visibility file
00039            example : vis = 'ngc5921.ms'
00040               Only one MS can be specified here, and it must contain at-least one
00041                timestep of data at all frequencies required to calculate the PB spectrum. 
00042               ( In case of multiple MSs with different spectral windows, for now, 
00043                 please split/concat a small fraction of the data to form such an MS )
00044 
00045    imagename -- Pre-name of input and output images. Same as in the clean task.           
00046            example : imagename = 'run1'
00047               Restored-images ( run1.image.tt0,etc) and residual images ( run1.residual.tt0, etc.. )
00048               must be available on disk. 
00049 
00050    nterms -- Number of Taylor terms to be used to model the frequency-dependence 
00051                  of the primary beam.
00052            example : nterms = 2
00053                 nterms must be less than or equal to the number of frequencies specified via
00054                 spwlist, chanlist and weightlist.
00055                 nterms=1 will do a standard division by the average PB computed over all
00056                 specified frequencies.
00057 
00058    threshold -- Flux level in the restored intensity map, below which to not 
00059                      recalculate spectral index. 
00060            example : threshold = '0.1Jy'
00061 
00062    action -- Choice of PB-correction with spectral-index recalculation
00063                 or only spectral-index recalculation (using the specified threshold)
00064            example : action='pbcor'  or action='calcalpha'
00065                
00066            With action='pbcor', the following output images are created/overwritten.
00067 
00068               - imagename.pbcor.workdirectory  :  This directory contains an image cube with
00069                 PBs at the list of specified frequencies, and Taylor-coefficient images that
00070                 describe the PB spectrum.
00071                    -  imagename.pb.cube : Concatenated cube of PBs 
00072                    -  imagename.pb.tt0, tt1, ... : Taylor coefficients describing the PB spectrum
00073                    -  imagename.pb.alpha : Spectral index of the PB (for information only)
00074               - imagename.image.pbcor.tt0,tt1,... : Corrected Taylor coefficients
00075               - imagename.pbcor.image.alpha : Corrected Spectral Index
00076               - imagename.pbcor.image.alpha.error : New error map.
00077 
00078             With action='calcalpha', the following output images are created/overwritten
00079               - imagename.image.alpha : Corrected Spectral Index
00080               - imagename.image.alpha.error : New error map.
00081 
00082    reffreq -- Reference frequency about which the Taylor-expansion is defined.
00083             example : reffreq = '1.5GHz'
00084                  If left unspecified, it is picked from the input restored image.
00085                  Note : If reffreq was specified during task clean to produce the images
00086                            it must be specified here. 
00087 
00088    pbmin -- PB gain level below which to not compute Taylor-coefficients or
00089                 apply PB-corrections.
00090             example : pbmin = 0.1
00091 
00092    field -- Field selection for the Primary Beam calculation. 
00093             example : field = '3C291'
00094                 This field selection must be identical to that used in 'clean'
00095 
00096    spwlist -- List of SPW ids for which to make separate Primary Beams
00097    chanlist -- List of channel ids, within the above SPW ids, at which to make PBs.
00098 
00099              example :  spwlist=[0,1,2], chanlist=[32,32,32] 
00100                           Make PBs at frequencies corresponding to channel 32 of
00101                           spws 0,1 and 2.
00102              example :  spwlist=[0,0,0], chanlist=[0,10,20]
00103                            Make PBs at frequencies corresponding to channels 0,10,20
00104                            of spw 0
00105  
00106                    Primary beams are computed at these specified frequencies and 
00107                    for pointings selected by 'field'.  Taylor-coefficients that represent
00108                    the PB spectrum are computed from these images.
00109 
00110    weightlist -- List of relative weights to apply to the PBs selected via the
00111                      spwlist,chanlist parameters. Weights should approximately represent the
00112                      sum-of-weights applicable during imaging each of these frequencies.
00113               example : weightlist=[0.5,1.0,1.0] 
00114                                  The first frequency had less usable data due to flagged RFI,
00115                                  but the other two had relatively equal weight.
00116                      These weights are applied to the PB spectrum while computing
00117                      PB Taylor-coefficients. Setting weights to anything other than 1.0
00118                      makes a difference only with very lop-sided weights. 
00119 
00120   
00121         """
00122         if type(spwlist)==int: spwlist=[spwlist]
00123         if type(chanlist)==int: chanlist=[chanlist]
00124         if type(weightlist)==float: weightlist=[weightlist]
00125 
00126 #
00127 #    The following is work around to avoid a bug with current python translation
00128 #
00129         mytmp = {}
00130 
00131         mytmp['vis'] = vis
00132         mytmp['imagename'] = imagename
00133         mytmp['nterms'] = nterms
00134         mytmp['threshold'] = threshold
00135         mytmp['action'] = action
00136         mytmp['reffreq'] = reffreq
00137         mytmp['pbmin'] = pbmin
00138         mytmp['field'] = field
00139         mytmp['spwlist'] = spwlist
00140         mytmp['chanlist'] = chanlist
00141         mytmp['weightlist'] = weightlist
00142         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00143         trec = casac.utils().torecord(pathname+'widebandpbcor.xml')
00144 
00145         casalog.origin('widebandpbcor')
00146         if trec.has_key('widebandpbcor') and casac.utils().verify(mytmp, trec['widebandpbcor']) :
00147             result = task_widebandpbcor.widebandpbcor(vis, imagename, nterms, threshold, action, reffreq, pbmin, field, spwlist, chanlist, weightlist)
00148 
00149         else :
00150           result = False
00151         return result