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