casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
importfits_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_importfits import importfits
00016 from task_importfits import casalog
00017 
00018 class importfits_pg_:
00019     __name__ = "importfits"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (importfits_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, fitsimage=None, imagename=None, whichrep=None, whichhdu=None, zeroblanks=None, overwrite=None, async=None):
00027 
00028         """Convert an image FITS file into a CASA image
00029 
00030         Standard image FITS files are processed into a Casa image
00031 
00032         Keyword arguments:
00033         fitsimage -- Name of input image FITS file
00034                 default: none; example='3C273XC1.fits'
00035         imagename -- Name of output CASA image
00036                 default: none; example: imagename='3C273XC1.image'
00037         whichrep -- If fits image has multiple coordinate reps,
00038                 choose one.
00039                 default: 0 means first; example: whichrep=1
00040         whichhdu -- If fits file contains multiple images,
00041                 choose this one
00042                 default=0 mean first; example: whichhdu=1
00043         zeroblanks -- Set blanked pixels to zero (not NaN)
00044                 default=True; example: zeroblanks=True
00045         overwrite -- Overwrite pre-existing imagename
00046                 default=False; example: overwrite=True
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'] = 'importfits'
00058         myf['taskname'] = 'importfits'
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['fitsimage'] = fitsimage = myf['fitsimage']
00095             myparams['imagename'] = imagename = myf['imagename']
00096             myparams['whichrep'] = whichrep = myf['whichrep']
00097             myparams['whichhdu'] = whichhdu = myf['whichhdu']
00098             myparams['zeroblanks'] = zeroblanks = myf['zeroblanks']
00099             myparams['overwrite'] = overwrite = myf['overwrite']
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['fitsimage'] = fitsimage
00110         mytmp['imagename'] = imagename
00111         mytmp['whichrep'] = whichrep
00112         mytmp['whichhdu'] = whichhdu
00113         mytmp['zeroblanks'] = zeroblanks
00114         mytmp['overwrite'] = overwrite
00115         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00116         trec = casac.utils().torecord(pathname+'importfits.xml')
00117 
00118         casalog.origin('importfits')
00119         if not trec.has_key('importfits') or not casac.utils().verify(mytmp, trec['importfits']) :
00120             return False
00121 
00122 
00123         try :
00124           casalog.post('')
00125           casalog.post('##########################################')
00126           casalog.post('##### Begin Task: importfits           #####')
00127           casalog.post('')
00128           result = importfits(fitsimage, imagename, whichrep, whichhdu, zeroblanks, overwrite)
00129           casalog.post('')
00130           casalog.post('##### End Task: importfits           #####')
00131           casalog.post('##########################################')
00132 
00133 
00134 # saveinputs for individule engine has no use
00135 # saveinputs should alos be removed from casa_in_py.py
00136 #
00137 #
00138 #          saveinputs = myf['saveinputs']
00139 #          saveinputs('importfits', 'importfits.last', myparams)
00140 #
00141 #
00142         except Exception, instance:
00143           #print '**** Error **** ',instance
00144           pass
00145 
00146         gc.collect()
00147         return result
00148 #
00149 #
00150 ##
00151 #    def paramgui(self, useGlobals=True):
00152 #        """
00153 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00154 #        """
00155 #        import paramgui
00156 #
00157 #        a=inspect.stack()
00158 #        stacklevel=0
00159 #        for k in range(len(a)):
00160 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00161 #            stacklevel=k
00162 #            break
00163 #        myf = sys._getframe(stacklevel).f_globals
00164 #
00165 #        if useGlobals:
00166 #            paramgui.setGlobals(myf)
00167 #        else:
00168 #            paramgui.setGlobals({})
00169 #
00170 #        paramgui.runTask('importfits', myf['_ip'])
00171 #        paramgui.setGlobals({})
00172 #
00173 #
00174 #
00175 #
00176     def defaults(self, param=None):
00177         a=inspect.stack()
00178         stacklevel=0
00179         for k in range(len(a)):
00180           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00181                 stacklevel=k
00182                 break
00183         myf=sys._getframe(stacklevel).f_globals
00184         a = odict()
00185         a['fitsimage']  = ''
00186         a['imagename']  = ''
00187         a['whichrep']  = 0
00188         a['whichhdu']  = 0
00189         a['zeroblanks']  = True
00190         a['overwrite']  = False
00191 
00192         a['async']=False
00193 
00194 ### This function sets the default values but also will return the list of
00195 ### parameters or the default value of a given parameter
00196         if(param == None):
00197                 myf['__set_default_parameters'](a)
00198         elif(param == 'paramkeys'):
00199                 return a.keys()
00200         else:
00201                 if(a.has_key(param)):
00202                    #if(type(a[param]) == dict) :
00203                    #   return a[param][len(a[param])-1]['value']
00204                    #else :
00205                       return a[param]
00206 
00207 
00208 #
00209 #
00210     def check_params(self, param=None, value=None):
00211       a=inspect.stack() 
00212       stacklevel=0
00213       for k in range(len(a)):
00214         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00215             stacklevel=k
00216             break
00217       myf=sys._getframe(stacklevel).f_globals
00218 
00219 #      print 'param:', param, 'value:', value
00220       try :
00221          if str(type(value)) != "<type 'instance'>" :
00222             value0 = value
00223             value = myf['cu'].expandparam(param, value)
00224             matchtype = False
00225             if(type(value) == numpy.ndarray):
00226                if(type(value) == type(value0)):
00227                   myf[param] = value.tolist()
00228                else:
00229                   #print 'value:', value, 'value0:', value0
00230                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00231                   myf[param] = value0
00232                   if type(value0) != list :
00233                      matchtype = True
00234             else :
00235                myf[param] = value
00236             value = myf['cu'].verifyparam({param:value})
00237             if matchtype:
00238                value = False
00239       except Exception, instance:
00240          #ignore the exception and just return it unchecked
00241          myf[param] = value
00242       return value
00243 
00244 #
00245 #
00246     def description(self, key='importfits', subkey=None):
00247         desc={'importfits': 'Convert an image FITS file into a CASA image',
00248                'fitsimage': 'Name of input image FITS file',
00249                'imagename': 'Name of output CASA image',
00250                'whichrep': 'If fits image has multiple coordinate reps, choose one.',
00251                'whichhdu': 'If its file contains multiple images,, choose one.',
00252                'zeroblanks': 'Set blanked pixels to zero (not NaN)',
00253                'overwrite': 'Overwrite pre-existing imagename',
00254 
00255                'async': 'If true the taskname must be started using importfits(...)'
00256               }
00257 
00258         if(desc.has_key(key)) :
00259            return desc[key]
00260 
00261     def itsdefault(self, paramname) :
00262         a = {}
00263         a['fitsimage']  = ''
00264         a['imagename']  = ''
00265         a['whichrep']  = 0
00266         a['whichhdu']  = 0
00267         a['zeroblanks']  = True
00268         a['overwrite']  = False
00269 
00270         if a.has_key(paramname) :
00271               return a[paramname]
00272 importfits_pg = importfits_pg_()