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