casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
listcal_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_listcal import listcal
00016 from task_listcal import casalog
00017 
00018 class listcal_pg_:
00019     __name__ = "listcal"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (listcal_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, vis=None, caltable=None, field=None, antenna=None, spw=None, listfile=None, pagerows=None, async=None):
00027 
00028         """List antenna gain solutions
00029 
00030 This task lists antenna gain solutions in tabular form.  The table
00031 is organized as follows.  Solutions are output by
00032     1) Spectral window,
00033     2) Antenna,
00034     3) Time,
00035     4) Channel,
00036     5) and Polarization;
00037 where the inner-most loop is over polarization.
00038 
00039 The listcal output table contains two table headers.  The top-level header
00040 is printed each time the spectral window changes.  This header lists
00041 the spectral window ID (SpwID), the date of observation (Date), 
00042 the calibration table name (CalTable), and the measurement set name (MS name).  
00043 
00044 A lower-level header is printed when the the top-level header is printed, 
00045 when the antenna names change, and every `pagerows' of output.
00046 The lower-level header columns are described here:
00047 
00048 Column Name    Description
00049 -----------    -----------
00050 Ant            Antenna name (contains sub-columns: Amp, Phs, F)
00051 Time           Visibility timestamp corresponding to gain solution
00052 Field          Field name
00053 Chn            Channel number
00054 Amp            Complex solution amplitude
00055 Phs            Complex solution  phase
00056 F              Flag
00057 
00058 Elements of the ``F'' column contain an `F' when the datum is flagged,
00059 and ` ' (whitespace) when the datum is not flagged.
00060 
00061 Presently, the polarization mode names (for example: R, L)
00062 are not given, but the ordering of the polrization modes (left-to-right) is
00063 equivalent to the order output by task listobs (see ``Feeds'' in listobs 
00064 output).
00065 
00066 Input Parameters:
00067 
00068 vis         Name of input visibility file
00069             default: none; example: vis='ngc5921.ms'
00070             
00071 caltable    Name of input calibration table
00072             default: none; example: caltable='ngc5921.gcal'
00073             
00074 field       Select data based on field ID(s) or name(s)
00075             default: ''==>all; example: field='1'
00076             field='0~2' field ids inclusive from 0 to 2
00077             field='3C*' all field names starting with 3C
00078             
00079 antenna     Select calibration data based on antenna name
00080             default: ''-->all; example: antenna='5';
00081             antenna='5,6' antenna index 5 and 6 solutions
00082             antenna='VA05','VA06'  VLA antenna 5 and 6
00083 
00084 spw         Select spectral window(s), channel(s) to list
00085             default: '' --> All spws and channels;
00086             spw='2:34' spectral window 2, channel 34;
00087             spw='1:5,3~5:7~9' spectral window 1, channel
00088             5 and spectral windows 3 thru 5, channels
00089             7 thru 9.
00090 
00091 listfile    write output to disk; will not overwrite
00092             default: '' --> write to screen
00093 
00094 pagerows    rows per page of listing 
00095             default: 50; 0 --> do not paginate 
00096 
00097 Example:
00098 
00099 # Get path to CASA home dir
00100 pathname=os.environ.get('CASAPATH').split()[0] 
00101 # Select uv-data (FITS) file
00102 fitsdata=pathname+'/data/demo/NGC5921.fits' 
00103 # MS name; write to current directory
00104 msdata='NGC5921.ms' 
00105 # import FITS data to MS
00106 importuvfits(fitsfile=fitsdata, vis=msdata) 
00107 # Create model data for flux calibrator
00108 setjy(vis=msdata) 
00109 # Calibration table name
00110 caldata=msdata+'.bcal' 
00111 # Bandpass calibration
00112 bandpass(vis=msdata, caltable=caldata) 
00113 # List a subset of calibration factors
00114 listcal(vis=msdata, caltable=caldata, field='N5921_2, 0, 1', 
00115         antenna='1,2,5;10~14', spw='0:1,0:22~25', pagerows=0)
00116 
00117 Example Output:
00118 
00119 SpwID = 0, Date = 1995/04/13,  CalTable = NGC5921.ms.bcal (B Jones), MS name = /users/jcrossle/NRAO/casa/NGC5921.ms                                    
00120 -------------------------------------------------------------------------------------------------------------------------------------------------------
00121                               | Ant = 1                     | Ant = 2                     | Ant = 5                     | Ant = 10                    |
00122 Time       Field           Chn|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|
00123 ----------|---------------|---|--------------|--------------|--------------|--------------|--------------|--------------|--------------|--------------|
00124 09:21:46.0 1331+30500002_0   1|0.165    7.9   0.117   21.3   0.168   98.8   0.161 -116.8   0.146  -24.6   0.153 -109.7   0.163 -158.6   0.139    3.9   
00125 10:05:27.9 1445+09900002_0   1|0.260   10.3   0.185   20.0   0.266  102.3   0.250 -116.1   0.233  -20.4   0.245 -108.6   0.255 -156.5   0.217    4.1   
00126 10:09:05.3         N5921_2   1|0.047   54.2   0.030   50.7   0.057  -64.6   0.041   36.5   0.050   93.5   0.035  -13.9   0.079   97.5   0.048 -107.0   
00127                               | Ant = 11                    | Ant = 12                    | Ant = 13                    | Ant = 14                    |
00128 Time       Field           Chn|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|
00129 ----------|---------------|---|--------------|--------------|--------------|--------------|--------------|--------------|--------------|--------------|
00130 09:21:46.0 1331+30500002_0   1|0.156 -112.6   0.128   -5.5   0.156 -178.4   0.169 -146.2   0.160 -177.4   0.148  -89.1   0.173 -117.0   0.145  141.5   
00131 10:05:27.9 1445+09900002_0   1|0.243 -110.6   0.199   -5.7   0.251 -175.4   0.272 -146.9   0.249 -175.0   0.238  -89.5   0.268 -113.5   0.228  142.5   
00132 10:09:05.3         N5921_2   1|0.054   47.1   0.056  105.5   0.042  -84.9   0.043  -18.9   0.058   72.4   0.055  155.6   0.040  -35.0   0.044 -153.6   
00133 SpwID = 0, Date = 1995/04/13,  CalTable = NGC5921.ms.bcal (B Jones), MS name = /users/jcrossle/NRAO/casa/NGC5921.ms                                    
00134 -------------------------------------------------------------------------------------------------------------------------------------------------------
00135                               | Ant = 1                     | Ant = 2                     | Ant = 5                     | Ant = 10                    |
00136 Time       Field           Chn|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|
00137 ----------|---------------|---|--------------|--------------|--------------|--------------|--------------|--------------|--------------|--------------|
00138 09:21:46.0 1331+30500002_0  22|0.319    4.6   0.323   -6.8   0.311  109.6   0.315 -109.0   0.286  -26.8   0.324 -106.8   0.303 -146.6   0.303    4.3   
00139 09:21:46.0 1331+30500002_0  23|0.318    4.4   0.323   -6.8   0.309  109.7   0.315 -108.8   0.285  -26.8   0.325 -106.5   0.304 -146.2   0.304    4.6   
00140 09:21:46.0 1331+30500002_0  24|0.318    4.2   0.323   -6.6   0.309  109.8   0.316 -108.6   0.285  -26.8   0.324 -106.6   0.302 -146.1   0.304    5.0   
00141 09:21:46.0 1331+30500002_0  25|0.319    4.3   0.323   -6.6   0.308  109.5   0.315 -108.4   0.285  -26.7   0.323 -106.7   0.301 -145.9   0.303    5.1   
00142 10:05:27.9 1445+09900002_0  22|0.502    7.0   0.508   -7.9   0.483  112.2   0.499 -108.5   0.451  -24.2   0.515 -106.2   0.481 -144.1   0.489    4.6   
00143 10:05:27.9 1445+09900002_0  23|0.498    7.2   0.509   -8.2   0.489  112.6   0.502 -108.8   0.455  -23.9   0.513 -106.2   0.477 -144.0   0.480    5.0   
00144 10:05:27.9 1445+09900002_0  24|0.496    6.3   0.506   -7.1   0.487  111.9   0.502 -108.3   0.450  -23.8   0.517 -106.1   0.473 -144.6   0.478    4.0   
00145 10:05:27.9 1445+09900002_0  25|0.489    6.3   0.512   -8.2   0.483  113.0   0.498 -108.7   0.456  -24.3   0.507 -105.5   0.470 -144.4   0.476    4.3   
00146 10:09:05.3         N5921_2  22|0.089   53.9   0.084   38.8   0.135  -84.0   0.148   54.9   0.100   94.2   0.112    4.4   0.112   90.6   0.115 -124.0   
00147 10:09:05.3         N5921_2  23|0.068   50.4   0.073   31.5   0.117  -80.7   0.150   50.5   0.103   90.3   0.120    2.6   0.104  103.6   0.104 -121.5   
00148 10:09:05.3         N5921_2  24|0.068   51.4   0.080   45.1   0.125  -89.0   0.146   47.3   0.106   99.9   0.122    8.8   0.102   95.9   0.099 -121.4   
00149 10:09:05.3         N5921_2  25|0.060   45.8   0.060   42.5   0.124  -85.4   0.146   47.8   0.110   93.4   0.125    7.2   0.088  100.9   0.096 -115.9   
00150                               | Ant = 11                    | Ant = 12                    | Ant = 13                    | Ant = 14                    |
00151 Time       Field           Chn|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|  Amp    Phs F   Amp    Phs F|
00152 ----------|---------------|---|--------------|--------------|--------------|--------------|--------------|--------------|--------------|--------------|
00153 09:21:46.0 1331+30500002_0  22|0.302  -99.8   0.301  -10.5   0.341  169.8   0.350 -137.6   0.306 -167.6   0.308  -84.8   0.319 -103.6   0.316  143.7   
00154 09:21:46.0 1331+30500002_0  23|0.301  -99.9   0.302  -10.6   0.341  169.7   0.349 -138.0   0.306 -167.4   0.307  -84.5   0.318 -103.6   0.316  143.8   
00155 09:21:46.0 1331+30500002_0  24|0.300 -100.0   0.301  -10.9   0.342  169.6   0.348 -138.4   0.305 -167.4   0.306  -84.3   0.319 -103.4   0.317  143.4   
00156 09:21:46.0 1331+30500002_0  25|0.301 -100.1   0.300  -11.0   0.339  169.9   0.347 -138.5   0.305 -167.4   0.306  -84.0   0.317 -103.2   0.315  143.5   
00157 10:05:27.9 1445+09900002_0  22|0.478  -97.3   0.482   -9.7   0.535  171.3   0.544 -138.1   0.480 -165.1   0.487  -86.0   0.502 -100.2   0.503  144.6   
00158 10:05:27.9 1445+09900002_0  23|0.481  -97.4   0.479  -10.4   0.531  171.4   0.549 -138.9   0.483 -165.3   0.489  -84.3   0.498  -99.7   0.501  144.7   
00159 10:05:27.9 1445+09900002_0  24|0.482  -97.6   0.484  -10.1   0.532  172.7   0.544 -139.3   0.489 -165.3   0.476  -84.6   0.498 -100.3   0.502  144.6   
00160 10:05:27.9 1445+09900002_0  25|0.479  -98.4   0.484  -10.1   0.534  172.4   0.553 -139.0   0.481 -165.4   0.479  -84.3   0.498 -100.3   0.497  145.0   
00161 10:09:05.3         N5921_2  22|0.127   44.8   0.142  128.9   0.090  -94.4   0.090  -48.5   0.112   41.3   0.103  109.0   0.075    7.2   0.095 -120.1   
00162 10:09:05.3         N5921_2  23|0.135   43.1   0.132  126.0   0.087  -89.3   0.103  -38.2   0.112   39.3   0.100  117.8   0.076   -3.4   0.098 -113.5   
00163 10:09:05.3         N5921_2  24|0.135   49.4   0.137  136.1   0.092  -95.9   0.084  -42.7   0.104   49.9   0.120  117.6   0.087    2.9   0.097 -121.2   
00164 10:09:05.3         N5921_2  25|0.144   49.8   0.119  130.0   0.086  -96.5   0.074  -42.8   0.109   41.5   0.124  120.8   0.087    0.4   0.104 -117.3   
00165 
00166 Listed 120 antenna solutions.
00167 
00168   
00169         """
00170         a=inspect.stack()
00171         stacklevel=0
00172         for k in range(len(a)):
00173           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00174                 stacklevel=k
00175                 break
00176         myf=sys._getframe(stacklevel).f_globals
00177         myf['__last_task'] = 'listcal'
00178         myf['taskname'] = 'listcal'
00179         ###
00180         myf['update_params'](func=myf['taskname'],printtext=False)
00181         ###
00182         ###
00183         #Handle globals or user over-ride of arguments
00184         #
00185         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00186         useLocalDefaults = False
00187 
00188         for item in function_signature_defaults.iteritems():
00189                 key,val = item
00190                 keyVal = eval(key)
00191                 if (keyVal == None):
00192                         #user hasn't set it - use global/default
00193                         pass
00194                 else:
00195                         #user has set it - use over-ride
00196                         if (key != 'self') :
00197                            useLocalDefaults = True
00198                         #myf[key]=keyVal
00199 
00200         myparams = {}
00201         if useLocalDefaults :
00202            for item in function_signature_defaults.iteritems():
00203                key,val = item
00204                keyVal = eval(key)
00205                exec('myparams[key] = keyVal')
00206                if (keyVal == None):
00207                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00208                    keyVal = eval(key)
00209                    if(type(keyVal) == dict) :
00210                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00211 
00212         else :
00213             uselessvariable = None 
00214             myparams['vis'] = vis = myf['vis']
00215             myparams['caltable'] = caltable = myf['caltable']
00216             myparams['field'] = field = myf['field']
00217             myparams['antenna'] = antenna = myf['antenna']
00218             myparams['spw'] = spw = myf['spw']
00219             myparams['listfile'] = listfile = myf['listfile']
00220             myparams['pagerows'] = pagerows = myf['pagerows']
00221 
00222 
00223         result = None
00224 
00225 #
00226 #    The following is work around to avoid a bug with current python translation
00227 #
00228         mytmp = {}
00229 
00230         mytmp['vis'] = vis
00231         mytmp['caltable'] = caltable
00232         mytmp['field'] = field
00233         mytmp['antenna'] = antenna
00234         mytmp['spw'] = spw
00235         mytmp['listfile'] = listfile
00236         mytmp['pagerows'] = pagerows
00237         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00238         trec = casac.utils().torecord(pathname+'listcal.xml')
00239 
00240         casalog.origin('listcal')
00241         if not trec.has_key('listcal') or not casac.utils().verify(mytmp, trec['listcal']) :
00242             return False
00243 
00244 
00245         try :
00246           casalog.post('')
00247           casalog.post('##########################################')
00248           casalog.post('##### Begin Task: listcal           #####')
00249           casalog.post('')
00250           result = listcal(vis, caltable, field, antenna, spw, listfile, pagerows)
00251           casalog.post('')
00252           casalog.post('##### End Task: listcal           #####')
00253           casalog.post('##########################################')
00254 
00255 
00256 # saveinputs for individule engine has no use
00257 # saveinputs should alos be removed from casa_in_py.py
00258 #
00259 #
00260 #          saveinputs = myf['saveinputs']
00261 #          saveinputs('listcal', 'listcal.last', myparams)
00262 #
00263 #
00264         except Exception, instance:
00265           #print '**** Error **** ',instance
00266           pass
00267 
00268         gc.collect()
00269         return result
00270 #
00271 #
00272 ##
00273 #    def paramgui(self, useGlobals=True):
00274 #        """
00275 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00276 #        """
00277 #        import paramgui
00278 #
00279 #        a=inspect.stack()
00280 #        stacklevel=0
00281 #        for k in range(len(a)):
00282 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00283 #            stacklevel=k
00284 #            break
00285 #        myf = sys._getframe(stacklevel).f_globals
00286 #
00287 #        if useGlobals:
00288 #            paramgui.setGlobals(myf)
00289 #        else:
00290 #            paramgui.setGlobals({})
00291 #
00292 #        paramgui.runTask('listcal', myf['_ip'])
00293 #        paramgui.setGlobals({})
00294 #
00295 #
00296 #
00297 #
00298     def defaults(self, param=None):
00299         a=inspect.stack()
00300         stacklevel=0
00301         for k in range(len(a)):
00302           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00303                 stacklevel=k
00304                 break
00305         myf=sys._getframe(stacklevel).f_globals
00306         a = odict()
00307         a['vis']  = ''
00308         a['caltable']  = ''
00309         a['field']  = ''
00310         a['antenna']  = ''
00311         a['spw']  = ''
00312         a['listfile']  = ''
00313         a['pagerows']  = 50
00314 
00315         a['async']=False
00316 
00317 ### This function sets the default values but also will return the list of
00318 ### parameters or the default value of a given parameter
00319         if(param == None):
00320                 myf['__set_default_parameters'](a)
00321         elif(param == 'paramkeys'):
00322                 return a.keys()
00323         else:
00324                 if(a.has_key(param)):
00325                    #if(type(a[param]) == dict) :
00326                    #   return a[param][len(a[param])-1]['value']
00327                    #else :
00328                       return a[param]
00329 
00330 
00331 #
00332 #
00333     def check_params(self, param=None, value=None):
00334       a=inspect.stack() 
00335       stacklevel=0
00336       for k in range(len(a)):
00337         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00338             stacklevel=k
00339             break
00340       myf=sys._getframe(stacklevel).f_globals
00341 
00342 #      print 'param:', param, 'value:', value
00343       try :
00344          if str(type(value)) != "<type 'instance'>" :
00345             value0 = value
00346             value = myf['cu'].expandparam(param, value)
00347             matchtype = False
00348             if(type(value) == numpy.ndarray):
00349                if(type(value) == type(value0)):
00350                   myf[param] = value.tolist()
00351                else:
00352                   #print 'value:', value, 'value0:', value0
00353                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00354                   myf[param] = value0
00355                   if type(value0) != list :
00356                      matchtype = True
00357             else :
00358                myf[param] = value
00359             value = myf['cu'].verifyparam({param:value})
00360             if matchtype:
00361                value = False
00362       except Exception, instance:
00363          #ignore the exception and just return it unchecked
00364          myf[param] = value
00365       return value
00366 
00367 #
00368 #
00369     def description(self, key='listcal', subkey=None):
00370         desc={'listcal': 'List antenna gain solutions',
00371                'vis': 'Name of input visibility file',
00372                'caltable': 'Input calibration table to list',
00373                'field': 'Field name or index; \'\'==>all',
00374                'antenna': 'Antenna name or index; \'\'==>all; antenna=\'3\'',
00375                'spw': 'Spectral window and channel: \'\'==>all; spw=\'5:0~10\'',
00376                'listfile': 'Disk file to write output: \'\'==>to terminal',
00377                'pagerows': 'Rows per page',
00378 
00379                'async': 'If true the taskname must be started using listcal(...)'
00380               }
00381 
00382         if(desc.has_key(key)) :
00383            return desc[key]
00384 
00385     def itsdefault(self, paramname) :
00386         a = {}
00387         a['vis']  = ''
00388         a['caltable']  = ''
00389         a['field']  = ''
00390         a['antenna']  = ''
00391         a['spw']  = ''
00392         a['listfile']  = ''
00393         a['pagerows']  = 50
00394 
00395         if a.has_key(paramname) :
00396               return a[paramname]
00397 listcal_pg = listcal_pg_()