casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
calstat_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_calstat import calstat
00016 from task_calstat import casalog
00017 
00018 class calstat_pg_:
00019     __name__ = "calstat"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (calstat_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, caltable=None, axis=None, datacolumn=None, useflags=None, async=None):
00027 
00028         """Displays statistical information on a calibration table
00029         This task returns statistical information about a column in a calibration table.
00030 
00031         The following values are computed: mean value, sum of values, sum of squared values,
00032         median, median absolute deviation, quartile, minimum, maximum,
00033         variance, standard deviation, root mean square.
00034 
00035         Keyword arguments:
00036 
00037         caltable -- Name of input calibration table
00038                   default: '', example: vis='ggtau.1mm.amp.gcal'
00039 
00040         axis -- Which data to analyze. The possible values are 'amp', 'amplitude', 'phase',
00041                 'real', 'imag', 'imaginary'. Also, the name of any real valued MS column can be 
00042                 given, e.g. TIME, POLY_COEFF_AMP, REF_ANT, ANTENNA1, FLAG, ...
00043 
00044                 default: 'amplitude'
00045                 axis='gain'
00046 
00047                 The phase of a complex number is in radians in the range [-pi; pi[.
00048 
00049 
00050         datacolumn -- Which data column to use if axis is 'amp', 'amplitude',
00051                       'phase', 'real', 'imag' or 'imaginary'.
00052                 default: 'gain'
00053                 datacolumn='gain'
00054 
00055         useflags -- Take MS flags into account (not implemented, this parameter 
00056                     has no effect!)
00057                 default: False
00058                 useflag=False
00059                 useflag=True
00060         If useflags=False, flagged values are included in the statistics.
00061         If useflags=True, any flagged values are not used in the statistics.
00062 
00063         """
00064         a=inspect.stack()
00065         stacklevel=0
00066         for k in range(len(a)):
00067           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00068                 stacklevel=k
00069                 break
00070         myf=sys._getframe(stacklevel).f_globals
00071         myf['__last_task'] = 'calstat'
00072         myf['taskname'] = 'calstat'
00073         ###
00074         myf['update_params'](func=myf['taskname'],printtext=False)
00075         ###
00076         ###
00077         #Handle globals or user over-ride of arguments
00078         #
00079         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00080         useLocalDefaults = False
00081 
00082         for item in function_signature_defaults.iteritems():
00083                 key,val = item
00084                 keyVal = eval(key)
00085                 if (keyVal == None):
00086                         #user hasn't set it - use global/default
00087                         pass
00088                 else:
00089                         #user has set it - use over-ride
00090                         if (key != 'self') :
00091                            useLocalDefaults = True
00092                         #myf[key]=keyVal
00093 
00094         myparams = {}
00095         if useLocalDefaults :
00096            for item in function_signature_defaults.iteritems():
00097                key,val = item
00098                keyVal = eval(key)
00099                exec('myparams[key] = keyVal')
00100                if (keyVal == None):
00101                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00102                    keyVal = eval(key)
00103                    if(type(keyVal) == dict) :
00104                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00105 
00106         else :
00107             uselessvariable = None 
00108             myparams['caltable'] = caltable = myf['caltable']
00109             myparams['axis'] = axis = myf['axis']
00110             myparams['datacolumn'] = datacolumn = myf['datacolumn']
00111             myparams['useflags'] = useflags = myf['useflags']
00112 
00113 
00114         result = None
00115 
00116 #
00117 #    The following is work around to avoid a bug with current python translation
00118 #
00119         mytmp = {}
00120 
00121         mytmp['caltable'] = caltable
00122         mytmp['axis'] = axis
00123         mytmp['datacolumn'] = datacolumn
00124         mytmp['useflags'] = useflags
00125         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00126         trec = casac.utils().torecord(pathname+'calstat.xml')
00127 
00128         casalog.origin('calstat')
00129         if not trec.has_key('calstat') or not casac.utils().verify(mytmp, trec['calstat']) :
00130             return False
00131 
00132 
00133         try :
00134           casalog.post('')
00135           casalog.post('##########################################')
00136           casalog.post('##### Begin Task: calstat           #####')
00137           casalog.post('')
00138           result = calstat(caltable, axis, datacolumn, useflags)
00139           casalog.post('')
00140           casalog.post('##### End Task: calstat           #####')
00141           casalog.post('##########################################')
00142 
00143 
00144 # saveinputs for individule engine has no use
00145 # saveinputs should alos be removed from casa_in_py.py
00146 #
00147 #
00148 #          saveinputs = myf['saveinputs']
00149 #          saveinputs('calstat', 'calstat.last', myparams)
00150 #
00151 #
00152         except Exception, instance:
00153           #print '**** Error **** ',instance
00154           pass
00155 
00156         gc.collect()
00157         return result
00158 #
00159 #
00160 ##
00161 #    def paramgui(self, useGlobals=True):
00162 #        """
00163 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00164 #        """
00165 #        import paramgui
00166 #
00167 #        a=inspect.stack()
00168 #        stacklevel=0
00169 #        for k in range(len(a)):
00170 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00171 #            stacklevel=k
00172 #            break
00173 #        myf = sys._getframe(stacklevel).f_globals
00174 #
00175 #        if useGlobals:
00176 #            paramgui.setGlobals(myf)
00177 #        else:
00178 #            paramgui.setGlobals({})
00179 #
00180 #        paramgui.runTask('calstat', myf['_ip'])
00181 #        paramgui.setGlobals({})
00182 #
00183 #
00184 #
00185 #
00186     def defaults(self, param=None):
00187         a=inspect.stack()
00188         stacklevel=0
00189         for k in range(len(a)):
00190           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00191                 stacklevel=k
00192                 break
00193         myf=sys._getframe(stacklevel).f_globals
00194         a = odict()
00195         a['caltable']  = ''
00196         a['axis']  = 'amplitude'
00197         a['useflags']  = True
00198 
00199         a['async']=False
00200         a['axis'] = {
00201                     0:odict([{'value':'amp'}, {'datacolumn':'gain'}]), 
00202                     1:odict([{'value':'amplitude'}, {'datacolumn':'gain'}]), 
00203                     2:odict([{'value':'phase'}, {'datacolumn':'gain'}]), 
00204                     3:odict([{'value':'real'}, {'datacolumn':'gain'}]), 
00205                     4:odict([{'value':'imag'}, {'datacolumn':'gain'}]), 
00206                     5:odict([{'value':'imaginary'}, {'datacolumn':'gain'}])}
00207 
00208 ### This function sets the default values but also will return the list of
00209 ### parameters or the default value of a given parameter
00210         if(param == None):
00211                 myf['__set_default_parameters'](a)
00212         elif(param == 'paramkeys'):
00213                 return a.keys()
00214         else:
00215                 if(a.has_key(param)):
00216                    #if(type(a[param]) == dict) :
00217                    #   return a[param][len(a[param])-1]['value']
00218                    #else :
00219                       return a[param]
00220 
00221 
00222 #
00223 #
00224     def check_params(self, param=None, value=None):
00225       a=inspect.stack() 
00226       stacklevel=0
00227       for k in range(len(a)):
00228         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00229             stacklevel=k
00230             break
00231       myf=sys._getframe(stacklevel).f_globals
00232 
00233 #      print 'param:', param, 'value:', value
00234       try :
00235          if str(type(value)) != "<type 'instance'>" :
00236             value0 = value
00237             value = myf['cu'].expandparam(param, value)
00238             matchtype = False
00239             if(type(value) == numpy.ndarray):
00240                if(type(value) == type(value0)):
00241                   myf[param] = value.tolist()
00242                else:
00243                   #print 'value:', value, 'value0:', value0
00244                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00245                   myf[param] = value0
00246                   if type(value0) != list :
00247                      matchtype = True
00248             else :
00249                myf[param] = value
00250             value = myf['cu'].verifyparam({param:value})
00251             if matchtype:
00252                value = False
00253       except Exception, instance:
00254          #ignore the exception and just return it unchecked
00255          myf[param] = value
00256       return value
00257 
00258 #
00259 #
00260     def description(self, key='calstat', subkey=None):
00261         desc={'calstat': 'Displays statistical information on a calibration table',
00262                'caltable': 'Name of input calibration table',
00263                'axis': 'Which values to use',
00264                'datacolumn': 'Which data column to use',
00265                'useflags': 'Take flagging into account? (not implemented)',
00266 
00267                'async': 'If true the taskname must be started using calstat(...)'
00268               }
00269 
00270 #
00271 # Set subfields defaults if needed
00272 #
00273 
00274         if(desc.has_key(key)) :
00275            return desc[key]
00276 
00277     def itsdefault(self, paramname) :
00278         a = {}
00279         a['caltable']  = ''
00280         a['axis']  = 'amplitude'
00281         a['datacolumn']  = 'gain'
00282         a['useflags']  = True
00283 
00284         if a.has_key(paramname) :
00285               return a[paramname]
00286 calstat_pg = calstat_pg_()