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