casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
uvcontsub2_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_uvcontsub2 import uvcontsub2
00016 from task_uvcontsub2 import casalog
00017 
00018 class uvcontsub2_pg_:
00019     __name__ = "uvcontsub2"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (uvcontsub2_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, vis=None, field=None, fitspw=None, combine=None, solint=None, fitorder=None, spw=None, want_cont=None, async=None):
00027 
00028         """Temporarily a clone of uvcontsub
00029   
00030         uvcontsub2 has been renamed to uvcontsub.  For now uvcontsub2 is an
00031         alias for uvcontsub, but that may change.
00032         
00033         For parameter descriptions, please see the help of uvcontsub.
00034 
00035 
00036         """
00037         a=inspect.stack()
00038         stacklevel=0
00039         for k in range(len(a)):
00040           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00041                 stacklevel=k
00042                 break
00043         myf=sys._getframe(stacklevel).f_globals
00044         myf['__last_task'] = 'uvcontsub2'
00045         myf['taskname'] = 'uvcontsub2'
00046         ###
00047         myf['update_params'](func=myf['taskname'],printtext=False)
00048         ###
00049         ###
00050         #Handle globals or user over-ride of arguments
00051         #
00052         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00053         useLocalDefaults = False
00054 
00055         for item in function_signature_defaults.iteritems():
00056                 key,val = item
00057                 keyVal = eval(key)
00058                 if (keyVal == None):
00059                         #user hasn't set it - use global/default
00060                         pass
00061                 else:
00062                         #user has set it - use over-ride
00063                         if (key != 'self') :
00064                            useLocalDefaults = True
00065                         #myf[key]=keyVal
00066 
00067         myparams = {}
00068         if useLocalDefaults :
00069            for item in function_signature_defaults.iteritems():
00070                key,val = item
00071                keyVal = eval(key)
00072                exec('myparams[key] = keyVal')
00073                if (keyVal == None):
00074                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00075                    keyVal = eval(key)
00076                    if(type(keyVal) == dict) :
00077                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00078 
00079         else :
00080             uselessvariable = None 
00081             myparams['vis'] = vis = myf['vis']
00082             myparams['field'] = field = myf['field']
00083             myparams['fitspw'] = fitspw = myf['fitspw']
00084             myparams['combine'] = combine = myf['combine']
00085             myparams['solint'] = solint = myf['solint']
00086             myparams['fitorder'] = fitorder = myf['fitorder']
00087             myparams['spw'] = spw = myf['spw']
00088             myparams['want_cont'] = want_cont = myf['want_cont']
00089 
00090 
00091         result = None
00092 
00093 #
00094 #    The following is work around to avoid a bug with current python translation
00095 #
00096         mytmp = {}
00097 
00098         mytmp['vis'] = vis
00099         mytmp['field'] = field
00100         mytmp['fitspw'] = fitspw
00101         mytmp['combine'] = combine
00102         mytmp['solint'] = solint
00103         mytmp['fitorder'] = fitorder
00104         mytmp['spw'] = spw
00105         mytmp['want_cont'] = want_cont
00106         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00107         trec = casac.utils().torecord(pathname+'uvcontsub2.xml')
00108 
00109         casalog.origin('uvcontsub2')
00110         if not trec.has_key('uvcontsub2') or not casac.utils().verify(mytmp, trec['uvcontsub2']) :
00111             return False
00112 
00113 
00114         try :
00115           casalog.post('')
00116           casalog.post('##########################################')
00117           casalog.post('##### Begin Task: uvcontsub2           #####')
00118           casalog.post('')
00119           result = uvcontsub2(vis, field, fitspw, combine, solint, fitorder, spw, want_cont)
00120           casalog.post('')
00121           casalog.post('##### End Task: uvcontsub2           #####')
00122           casalog.post('##########################################')
00123 
00124 
00125 # saveinputs for individule engine has no use
00126 # saveinputs should alos be removed from casa_in_py.py
00127 #
00128 #
00129 #          saveinputs = myf['saveinputs']
00130 #          saveinputs('uvcontsub2', 'uvcontsub2.last', myparams)
00131 #
00132 #
00133         except Exception, instance:
00134           #print '**** Error **** ',instance
00135           pass
00136 
00137         gc.collect()
00138         return result
00139 #
00140 #
00141 ##
00142 #    def paramgui(self, useGlobals=True):
00143 #        """
00144 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00145 #        """
00146 #        import paramgui
00147 #
00148 #        a=inspect.stack()
00149 #        stacklevel=0
00150 #        for k in range(len(a)):
00151 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00152 #            stacklevel=k
00153 #            break
00154 #        myf = sys._getframe(stacklevel).f_globals
00155 #
00156 #        if useGlobals:
00157 #            paramgui.setGlobals(myf)
00158 #        else:
00159 #            paramgui.setGlobals({})
00160 #
00161 #        paramgui.runTask('uvcontsub2', myf['_ip'])
00162 #        paramgui.setGlobals({})
00163 #
00164 #
00165 #
00166 #
00167     def defaults(self, param=None):
00168         a=inspect.stack()
00169         stacklevel=0
00170         for k in range(len(a)):
00171           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00172                 stacklevel=k
00173                 break
00174         myf=sys._getframe(stacklevel).f_globals
00175         a = odict()
00176         a['vis']  = ''
00177         a['field']  = ''
00178         a['fitspw']  = ''
00179         a['combine']  = ''
00180         a['solint']  = 'int'
00181         a['fitorder']  = 0
00182         a['spw']  = ''
00183         a['want_cont']  = False
00184 
00185         a['async']=False
00186 
00187 ### This function sets the default values but also will return the list of
00188 ### parameters or the default value of a given parameter
00189         if(param == None):
00190                 myf['__set_default_parameters'](a)
00191         elif(param == 'paramkeys'):
00192                 return a.keys()
00193         else:
00194                 if(a.has_key(param)):
00195                    #if(type(a[param]) == dict) :
00196                    #   return a[param][len(a[param])-1]['value']
00197                    #else :
00198                       return a[param]
00199 
00200 
00201 #
00202 #
00203     def check_params(self, param=None, value=None):
00204       a=inspect.stack() 
00205       stacklevel=0
00206       for k in range(len(a)):
00207         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00208             stacklevel=k
00209             break
00210       myf=sys._getframe(stacklevel).f_globals
00211 
00212 #      print 'param:', param, 'value:', value
00213       try :
00214          if str(type(value)) != "<type 'instance'>" :
00215             value0 = value
00216             value = myf['cu'].expandparam(param, value)
00217             matchtype = False
00218             if(type(value) == numpy.ndarray):
00219                if(type(value) == type(value0)):
00220                   myf[param] = value.tolist()
00221                else:
00222                   #print 'value:', value, 'value0:', value0
00223                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00224                   myf[param] = value0
00225                   if type(value0) != list :
00226                      matchtype = True
00227             else :
00228                myf[param] = value
00229             value = myf['cu'].verifyparam({param:value})
00230             if matchtype:
00231                value = False
00232       except Exception, instance:
00233          #ignore the exception and just return it unchecked
00234          myf[param] = value
00235       return value
00236 
00237 #
00238 #
00239     def description(self, key='uvcontsub2', subkey=None):
00240         desc={'uvcontsub2': 'Temporarily a clone of uvcontsub',
00241                'vis': 'Name of input MS.  Output goes to vis + ".contsub"',
00242                'field': 'Select field(s) using id(s) or name(s)',
00243                'fitspw': 'Spectral window:channel selection for fitting the continuum',
00244                'combine': 'Data axes to combine for the continuum estimation (none or spw and/or scan)',
00245                'solint': 'Continuum fit timescale (stick to int!)',
00246                'fitorder': 'Polynomial order for the fits',
00247                'spw': 'Spectral window selection for output',
00248                'want_cont': 'Create vis + ".cont" to hold the continuum estimate.',
00249 
00250                'async': 'If true the taskname must be started using uvcontsub2(...)'
00251               }
00252 
00253         if(desc.has_key(key)) :
00254            return desc[key]
00255 
00256     def itsdefault(self, paramname) :
00257         a = {}
00258         a['vis']  = ''
00259         a['field']  = ''
00260         a['fitspw']  = ''
00261         a['combine']  = ''
00262         a['solint']  = 'int'
00263         a['fitorder']  = 0
00264         a['spw']  = ''
00265         a['want_cont']  = False
00266 
00267         if a.has_key(paramname) :
00268               return a[paramname]
00269 uvcontsub2_pg = uvcontsub2_pg_()