casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
caltabconvert_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_caltabconvert import caltabconvert
00016 from task_caltabconvert import casalog
00017 
00018 class caltabconvert_pg_:
00019     __name__ = "caltabconvert"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (caltabconvert_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, caltabold=None, vis=None, ptype=None, caltabnew=None, async=None):
00027 
00028         """Convert old-style caltables into new-style caltables.\n
00029     This task converts old-style (up to CASA 3.3.0) caltables into new-style 
00030     (CASA 3.4.0 and later) caltables. It is provided as a convenience and 
00031     is strictly temporary. The information transferred should be enough 
00032     for most calibration purposes. BPOLY and GSPLINE versions are not 
00033     supported. Only simple bugs will be fixed. If there are other issues, 
00034     it is suggested that a new-style caltable be created directly.
00035 
00036     Arguments:
00037 
00038     caltabold -- Name of the old-style caltable.
00039     default: none
00040     example: caltabold='gronk.g0'
00041 
00042     vis -- Name of the visibility file (MS) associated with the old-style
00043         caltable.
00044     default: none
00045     example: vis='blurp.ms'
00046 
00047     ptype -- Type of data in the new-format caltable.
00048     default: "complex"; allowed values: "complex" or "float"
00049     example: ptype="complex"
00050 
00051     NB: The old-style caltables do not have this information, so it is
00052     imperative that users get it correct.  "complex" refers to caltables that
00053     have complex gains (e.g., produced by gaincal, bpcal, etc.).  "float" refers
00054     to caltables that real numbers such as delays (e.g., produced by gencal).
00055 
00056     caltabnew -- Name of the new-style caltable.
00057     default: "" --> the suffix ".new" is appended to the name of the old-style
00058         caltable
00059     example: caltabold='gronk_new.g0'
00060   
00061         """
00062         a=inspect.stack()
00063         stacklevel=0
00064         for k in range(len(a)):
00065           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00066                 stacklevel=k
00067                 break
00068         myf=sys._getframe(stacklevel).f_globals
00069         myf['__last_task'] = 'caltabconvert'
00070         myf['taskname'] = 'caltabconvert'
00071         ###
00072         myf['update_params'](func=myf['taskname'],printtext=False)
00073         ###
00074         ###
00075         #Handle globals or user over-ride of arguments
00076         #
00077         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00078         useLocalDefaults = False
00079 
00080         for item in function_signature_defaults.iteritems():
00081                 key,val = item
00082                 keyVal = eval(key)
00083                 if (keyVal == None):
00084                         #user hasn't set it - use global/default
00085                         pass
00086                 else:
00087                         #user has set it - use over-ride
00088                         if (key != 'self') :
00089                            useLocalDefaults = True
00090                         #myf[key]=keyVal
00091 
00092         myparams = {}
00093         if useLocalDefaults :
00094            for item in function_signature_defaults.iteritems():
00095                key,val = item
00096                keyVal = eval(key)
00097                exec('myparams[key] = keyVal')
00098                if (keyVal == None):
00099                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00100                    keyVal = eval(key)
00101                    if(type(keyVal) == dict) :
00102                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00103 
00104         else :
00105             uselessvariable = None 
00106             myparams['caltabold'] = caltabold = myf['caltabold']
00107             myparams['vis'] = vis = myf['vis']
00108             myparams['ptype'] = ptype = myf['ptype']
00109             myparams['caltabnew'] = caltabnew = myf['caltabnew']
00110 
00111 
00112         result = None
00113 
00114 #
00115 #    The following is work around to avoid a bug with current python translation
00116 #
00117         mytmp = {}
00118 
00119         mytmp['caltabold'] = caltabold
00120         mytmp['vis'] = vis
00121         mytmp['ptype'] = ptype
00122         mytmp['caltabnew'] = caltabnew
00123         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00124         trec = casac.utils().torecord(pathname+'caltabconvert.xml')
00125 
00126         casalog.origin('caltabconvert')
00127         if not trec.has_key('caltabconvert') or not casac.utils().verify(mytmp, trec['caltabconvert']) :
00128             return False
00129 
00130 
00131         try :
00132           casalog.post('')
00133           casalog.post('##########################################')
00134           casalog.post('##### Begin Task: caltabconvert           #####')
00135           casalog.post('')
00136           result = caltabconvert(caltabold, vis, ptype, caltabnew)
00137           casalog.post('')
00138           casalog.post('##### End Task: caltabconvert           #####')
00139           casalog.post('##########################################')
00140 
00141 
00142 # saveinputs for individule engine has no use
00143 # saveinputs should alos be removed from casa_in_py.py
00144 #
00145 #
00146 #          saveinputs = myf['saveinputs']
00147 #          saveinputs('caltabconvert', 'caltabconvert.last', myparams)
00148 #
00149 #
00150         except Exception, instance:
00151           #print '**** Error **** ',instance
00152           pass
00153 
00154         gc.collect()
00155         return result
00156 #
00157 #
00158 ##
00159 #    def paramgui(self, useGlobals=True):
00160 #        """
00161 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00162 #        """
00163 #        import paramgui
00164 #
00165 #        a=inspect.stack()
00166 #        stacklevel=0
00167 #        for k in range(len(a)):
00168 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00169 #            stacklevel=k
00170 #            break
00171 #        myf = sys._getframe(stacklevel).f_globals
00172 #
00173 #        if useGlobals:
00174 #            paramgui.setGlobals(myf)
00175 #        else:
00176 #            paramgui.setGlobals({})
00177 #
00178 #        paramgui.runTask('caltabconvert', myf['_ip'])
00179 #        paramgui.setGlobals({})
00180 #
00181 #
00182 #
00183 #
00184     def defaults(self, param=None):
00185         a=inspect.stack()
00186         stacklevel=0
00187         for k in range(len(a)):
00188           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00189                 stacklevel=k
00190                 break
00191         myf=sys._getframe(stacklevel).f_globals
00192         a = odict()
00193         a['caltabold']  = ''
00194         a['vis']  = ''
00195         a['ptype']  = 'complex'
00196         a['caltabnew']  = ''
00197 
00198         a['async']=False
00199 
00200 ### This function sets the default values but also will return the list of
00201 ### parameters or the default value of a given parameter
00202         if(param == None):
00203                 myf['__set_default_parameters'](a)
00204         elif(param == 'paramkeys'):
00205                 return a.keys()
00206         else:
00207                 if(a.has_key(param)):
00208                    #if(type(a[param]) == dict) :
00209                    #   return a[param][len(a[param])-1]['value']
00210                    #else :
00211                       return a[param]
00212 
00213 
00214 #
00215 #
00216     def check_params(self, param=None, value=None):
00217       a=inspect.stack() 
00218       stacklevel=0
00219       for k in range(len(a)):
00220         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00221             stacklevel=k
00222             break
00223       myf=sys._getframe(stacklevel).f_globals
00224 
00225 #      print 'param:', param, 'value:', value
00226       try :
00227          if str(type(value)) != "<type 'instance'>" :
00228             value0 = value
00229             value = myf['cu'].expandparam(param, value)
00230             matchtype = False
00231             if(type(value) == numpy.ndarray):
00232                if(type(value) == type(value0)):
00233                   myf[param] = value.tolist()
00234                else:
00235                   #print 'value:', value, 'value0:', value0
00236                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00237                   myf[param] = value0
00238                   if type(value0) != list :
00239                      matchtype = True
00240             else :
00241                myf[param] = value
00242             value = myf['cu'].verifyparam({param:value})
00243             if matchtype:
00244                value = False
00245       except Exception, instance:
00246          #ignore the exception and just return it unchecked
00247          myf[param] = value
00248       return value
00249 
00250 #
00251 #
00252     def description(self, key='caltabconvert', subkey=None):
00253         desc={'caltabconvert': 'Convert old-style caltables into new-style caltables.\n',
00254                'caltabold': 'Name of the old-style caltable.',
00255                'vis': 'Name of the visibility file (MS) associated with the old-style caltable.',
00256                'ptype': 'Type of data in the new-format caltable ("complex" or "float"; default is "complex").',
00257                'caltabnew': 'Name of the new-style caltable.  If not specified, the suffix ".new" is appended to the name of old-style caltable.',
00258 
00259                'async': 'If true the taskname must be started using caltabconvert(...)'
00260               }
00261 
00262         if(desc.has_key(key)) :
00263            return desc[key]
00264 
00265     def itsdefault(self, paramname) :
00266         a = {}
00267         a['caltabold']  = ''
00268         a['vis']  = ''
00269         a['ptype']  = 'complex'
00270         a['caltabnew']  = ''
00271 
00272         if a.has_key(paramname) :
00273               return a[paramname]
00274 caltabconvert_pg = caltabconvert_pg_()