casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
gencal.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_gencal
00013 def gencal(vis='', caltable='', caltype='', spw='', antenna='', pol='', parameter=[]):
00014 
00015         """Specify Calibration Values of Various Types
00016 
00017      The gencal task provides a means of specifying antenna-based
00018      calibration values manually.  The values are put in designated
00019      tables and applied to the data using applycal.  Several
00020      specialized calibrations are also generated with gencal.
00021 
00022      Current antenna-based gencal options (caltype) are:
00023         'amp'= amplitude correction
00024         'ph' = phase correction
00025         'sbd'= single-band delay (phase-frequency slope for each spw)
00026         'mbd'= multi-band delay (phase-frequency slope over all spw)
00027         'antpos' = ITRF antenna position corrections
00028         'antposvla' = VLA-centric antenna position corrections 
00029         'tsys' = Tsys from the SYSCAL table (ALMA)
00030         'swpow' = EVLA switched-power gains (experimental)
00031         'evlagain' (='swpow') (this syntax will deprecate)
00032         'rq' = EVLA requantizer gains _only_
00033         'swp/rq' = EVLA switched-power gains divided by requantizer gain
00034         'opac' = Tropospheric opacity
00035         'gc' = Gain curve (zenith-angle-dependent gain) (VLA only)
00036         'eff' = Antenna efficiency (sqrt(K/Jy)) (VLA only)
00037         'gceff' = Gain curve and efficiency (VLA only)
00038 
00039      The calibration specifications are not time-variable in the
00040      present implementation.  Calibration values can be assigned to
00041      each spw, antenna and pol selection, where applicable.  The 
00042      same caltable can be specified for multipl runs of gencal, 
00043      in which case the specified parameters will be incorporated 
00044      cumulatively.  E.g., amplitude parameters (caltype='amp')
00045      multiply and phase-like parameters ('ph', 'sbd','mbd','antpos') 
00046      add.  'amp' and 'ph' parameters can be incorporated into the 
00047      same caltable (in separate runs), but each of the other types
00048      require their own unique caltable.   A mechanism for
00049      specifying manual corrections via a text file will be provided in
00050      the future.
00051 
00052      The caltables are applied to the data by using applycal.  Other
00053      calibration tables must also be present, if applicable.
00054 
00055      For antenna position corrections (caltype='antpos'), the antenna 
00056      position offsets are specified in the ITRF frame. For EVLA, automated 
00057      lookup of the antenna position corrections is enabled when antenna is 
00058      unspecified (antenna='') for this caltype. Note that this requires 
00059      internet connection to access the EVLA antenna position correction 
00060      site. If no corrections are found, it will throw an exception 
00061      with the message, "no offsets found. no caltable created". The task
00062      may terminate with a SEVERE error message and may sound alarming, but 
00063      it simply means that it cannot produce the caltable.
00064      For VLA position corrections in the VLA-centric frame, use 
00065      caltype='antposvla', and gencal will rotate them to ITRF before 
00066      storing them in the output caltable.
00067 
00068      For Tsys (caltype='tsys', for ALMA) and EVLA switched power
00069      corrections (caltype='swpow'), the calibration parameters are
00070      derived from information contained in MS subtables.  In these
00071      cases, specification of spw, antenna, pol, and parameter will be
00072      ignored.
00073 
00074      EVLA switched power calibration is supported in three modes:  
00075      'swpow' (formerly 'evlagain', a syntax which will 
00076        deprecate) yields the formal EVLA switched power calibration 
00077        which describes voltage gain as sqrt(Pdif/Tcal) (used to 
00078        correct the visibility data) and Tsys as Psum*Tcal/Pdif/2 (used 
00079        to correct the weights).  'swpow' implicitly includes any 
00080        requantizer gain scale and adjustments.
00081      'rq' yields only the requantizer voltage gains (Tsys is set to
00082        1.0 to avoid weight adjustments).
00083      'swp/rq' yields the ordinary switched power voltage gains divided
00084        by the requantizer voltage gain (Tsys is calculate normally).
00085      The 'rq' and 'swp/rq' modes are are mainly intended for testing 
00086      and evaluating the EVLA switched power systems.
00087   
00088      For caltype='opac', specify the desired opacity(ies) in the parameter
00089      argument.  At this time, only constant (in time) opacities are
00090      supported via gencal.  
00091 
00092      For gaincurve and efficiency (caltype='gc', 'gceff', or 'eff'), 
00093      observatory-provided factors are determined per spw according
00094      to the observing frequencies.  The parameter argument is 
00095      ignored.  These caltypes are currently only supported
00096      for VLA processing.  (Appropriate factors for ALMA are TBD.)
00097 
00098      Keyword arguments:
00099 
00100      vis -- Name of input visibility file
00101              default: none.  example: vis='ngc5921.ms'
00102      caltable -- Name of input/output caltable.  If it does not
00103                   exist, it will be created.  Specifying an
00104                   existing table will result in the parameters
00105                   being applied cumulatively. Only a single
00106                   time-stamp for all calibrations are supported,
00107                   currently.  Do not use a caltable
00108                   created by gaincal, bandpass, etc.  
00109                   default: none.  example: caltable='test.G'
00110      caltype -- The calibration parameter type being specified.
00111                  Options include:
00112                  'amp' = gain (G) amplitude (1 real parameter per
00113                          pol, antenna, spw)
00114                  'ph'  = gain (G) phase (deg) (1 real parameter per
00115                          pol, antenna, spw)
00116                  'sbd' = single-band delays (nsec) (1 real parameter 
00117                          per pol, antenna, spw)
00118                  'mbd' = multi-band delay (nsec) (1 real parameter 
00119                          per pol, antenna, spw)
00120                  'antpos' = antenna position corrections (m) (3 real
00121                             ITRF offset parameters per antenna; spw, pol
00122                             selection will be ignored)
00123                             With antenna='', this triggers an automated lookup
00124                             of antenna positions for EVLA.
00125                  'antposvla' = antenna position corrections (m) specified
00126                                in the old VLA-centric coordinate system
00127                  'tsys' = Tsys from the SYSCAL table (ALMA)
00128                  'evlagain' = EVLA switched-power gains (experimental)
00129                  'opac' = Tropospheric opacity (1 real parameter 
00130                          per antenna, spw)
00131                  'gc' = Antenna zenith-angle dependent gain curve (auto-lookup)
00132                  'gceff' = Gain curve and efficiency (auto-lookup)
00133                  'eff' = Antenna efficiency (auto-lookup)
00134                  default: none.
00135                  example: caltype='ph'
00136      spw -- Spectral window selection for specified parameters. 
00137              default: spw='' (specified parameters apply to all spws)
00138              example: spw = '2,3,4'
00139      antenna -- Antenna selection for specified parameters. 
00140                  default: antenna='' (specified parameters apply to all antennas)
00141                  example: antenna='ea02, ea03' (specified parameter(s) to
00142                            apply to ea02 and ea03 only)
00143      pol -- Polarization selection for specified parameters.
00144              default: pol='' (specified parameters apply to all polarizations)
00145              example: pol='R' (specified parameters to apply to
00146                                  R only)
00147      parameter -- The calibration parameters, specified as a list, to 
00148                    store in the caltable for the spw, antenna, and pol 
00149                    selection.  The required length of the list is 
00150                    determined by the caltype and the spw, antenna, pol
00151                    selection.  One "set" of parameters (e.g., one value
00152                    for 'amp', 'ph', etc., three values for 'antpos')
00153                    specified the same value for all indicated spw, antenna,
00154                    and pol.
00155                    OR, 
00156                    When specifying a long list of calibration parameter values,
00157                    these should be ordered first (fastest) by pol (if pol!=''),
00158                    then by antenna (if antenna!=''), and finally (sloweset) by 
00159                    spw (if spw!='').  Unspecified selection axes must not be
00160                    enumerated in the parameter list
00161       
00162      Examples:
00163 
00164        gencal(vis='test.ms',caltable='test.G',caltype='amp',
00165               spw='',antenna='',pol='',
00166               parameter=[3])
00167 
00168          --> Antenna-based gain amplitude corrections for all spws, antennas, 
00169               and polarizations will be multiplied by 3.  When applied
00170               to visibility data, this correction will produce a
00171               corrected visibility than is (1/3*1/3) less than the 
00172               uncorrected visibility.
00173 
00174        gencal(vis='test.ms',caltable='test.G',caltype='ph',
00175               spw='',antenna='ea03,ea04',pol='',
00176               parameter=[45,120])
00177 
00178          --> Gain phase corrections for antennas ea03 and ea04
00179               will be adjusted (additive) by 45 and 120 
00180               degrees (respectively), for all spws and polarizations.
00181               When these phases are applied to visibility data, the
00182               visibility phases will decrease or increase by the
00183               specified amount where the selected antennas occur
00184               first or second (respectively) in each baseline.  E.g., 
00185               the phase of baseline ea03-ea04 will change by (-45+120)
00186               = + 75 degrees.  Baseline ea01-ea03's phase will change
00187               by +45 degrees; baseline ea04-ea05's phase will change
00188               by -120 degrees.  The same phase sign convention is
00189               used for delay and antenna position corrections.
00190 
00191        gencal(vis='test.ms',caltable='test.G',caltype='ph',
00192               spw='',antenna='ea05,ea06',pol='R',
00193               parameter=[63,-34])
00194 
00195          --> Gain phase corrections for antennas ea05 and ea06
00196               will be adjusted (additive) by 63 and -34 
00197               degrees (respectively), in R only, for all spws
00198 
00199        gencal(vis='test.ms',caltable='test.G',caltype='ph',
00200               spw='',antenna='ea09,ea10',pol='R,L',
00201               parameter=[14,-23,-130,145])
00202 
00203          --> Gain phase corrections in all spws will be adjusted for 
00204               antenna ea09 by 14 deg in R and -23 deg in L, and for
00205               antenna ea10 by -130 deg in R and 145 deg in L.
00206 
00207        gencal(vis='test.ms',caltable='test.G',caltype='ph',
00208               spw='2,3',antenna='ea09,ea10',pol='',
00209               parameter=[14,-23,-130,145])
00210 
00211          --> Gain phases corrections in both polarizations will be adjusted for 
00212               antenna ea09 by 14 deg in spw 2 and -23 deg in spw 3, and for
00213               antenna ea10 by -130 deg in spw 2 and 145 deg in spw 3.
00214 
00215        gencal(vis='test.ms',caltable='test.G',caltype='sbd',
00216               spw='2,3',antenna='ea09,ea10',pol='',
00217               parameter=[14,-23,-130,145])
00218 
00219          --> Delay corrections in both polarizations will be adjusted for 
00220               antenna ea09 by 14 nsec in spw 2 and -23 nsec in spw 3, and for
00221               antenna ea10 by -130 nsec in spw 2 and 145 nsec in spw
00222               3.  See the above example for caltype='ph' for details
00223               of the sign convention adopted when applying delay corrections.
00224 
00225        gencal(vis='test.ms',caltable='test.G',caltype='antpos',antenna='')
00226      
00227          --> *** Currently EVLA observations only ***
00228              Antenna position corrections will be retrieved automatically
00229              over internet to generate the caltable with antenna=''.
00230 
00231        gencal(vis='test.ms',caltable='test.G',caltype='antpos',
00232               antenna='ea09,ea10',
00233               parameter=[0.01,0.02,0.03, -0.03,-0.01,-0.02])
00234 
00235          --> Antenna position corrections in meters (in ITRF) for
00236               antenna ea09 (dBx=0.01, dBy=0.02, dBz=0.03) and for
00237               antenna ea10 (dBx=-0.03, dBy=-0.01, dBz=-0.02)
00238               See the above example for caltype='ph' for details
00239               of the sign convention adopted when applying antpos 
00240               corrections.
00241 
00242        gencal(vis='test.ms',caltable='test.G',caltype='antposvla',
00243               antenna='ea09,ea10',
00244               parameter=[0.01,0.02,0.03, -0.03,-0.01,-0.02])
00245 
00246          --> Antenna position corrections (in the traditional VLA-centric
00247               frame) will be introduced in meters for
00248               antenna ea09 (dBx=0.01, dBy=0.02, dBz=0.03) and for
00249               antenna ea10 (dBx=-0.03, dBy=-0.01, dBz=-0.02)
00250               These offsets will be rotated to the ITRF frame before
00251               storing them in the caltable.
00252               See the above example for caltype='ph' for details
00253               of the sign convention adopted when applying antpos 
00254               corrections.
00255 
00256  
00257         """
00258         if type(parameter)==float: parameter=[parameter]
00259 
00260 #
00261 #    The following is work around to avoid a bug with current python translation
00262 #
00263         mytmp = {}
00264 
00265         mytmp['vis'] = vis
00266         mytmp['caltable'] = caltable
00267         mytmp['caltype'] = caltype
00268         mytmp['spw'] = spw
00269         mytmp['antenna'] = antenna
00270         mytmp['pol'] = pol
00271         mytmp['parameter'] = parameter
00272         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00273         trec = casac.utils().torecord(pathname+'gencal.xml')
00274 
00275         casalog.origin('gencal')
00276         if trec.has_key('gencal') and casac.utils().verify(mytmp, trec['gencal']) :
00277             result = task_gencal.gencal(vis, caltable, caltype, spw, antenna, pol, parameter)
00278 
00279         else :
00280           result = False
00281         return result