casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
splattotable_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_splattotable import splattotable
00016 from task_splattotable import casalog
00017 
00018 class splattotable_pg_:
00019     __name__ = "splattotable"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (splattotable_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, filenames=None, table=None, wantreturn=None, async=None):
00027 
00028         """Convert a downloaded Splatalogue spectral line list to a casa table.
00029 PARAMETER SUMMARY
00030 filenames   Files containing Splatalogue lists.
00031 table       Output table name.
00032 wantreturn  Do you want the task to return a spectralline tool attached to the results table? If not false is returned.
00033 
00034 This task reads a spectral line list(s) downloaded from Splatalogue (www.splatalogue.net) and loads it into a CASA table which
00035 can be queried via eg the slsearch task.
00036     
00037 REQUIRMENTS OF THE DOWNLOADED FILES
00038     
00039 The downloaded files must be in a specific format for this task to succeed. The columns are the
00040 important things; one can filter the results as one desires using Splatalogue, but the particular columns must be present as described
00041 below. The columns which must be present in the downloaded file in this exact order are: "Species", "NRAO Recommended", "Chemical Name",
00042 "Freq in GHz", "Resolved QNs", "CDMS/JPL Intensity", "Sijmu2 (D2)",
00043 "Log10 (Aij)", "EL (K)", "EU (K)", "Linelist". In order to get these columns in this order, one should
00044 select exactly the following items on the Splatalogue search interface. Under "Specify Ranges" one should select "GHz" for the frequency unit.
00045 Under "Line Strength Display" select exactly "CDMS/JPL Intensity",
00046 "Sij mu2", and "Aij". Under "Energy Levels", one should select exactly "Elower (K)" and "Eupper (K)". Under "Miscellaneous", one should
00047 select exactly "Display Ordered Frequency ONLY" and "Display NRAO Recommended Frequencies". One should then initiate the search and on
00048 the resulting page, one should select the Tab Field Separator and then export the list. The resulting list should be in the proper
00049 format for importing into CASA.
00050     
00051 RETURN VALUE
00052 This task returns an open spectralline tool which references the new table if wantarray=true. The new table can also be opened by 
00053 a spectralline tool using the open method (eg sl.open(tablename)). False is returned if wantarray=false.
00054 
00055 
00056 newsl = splattotable("mysplatlist.txt", "mynewsl.tbl", true)
00057 
00058 
00059 
00060         """
00061         a=inspect.stack()
00062         stacklevel=0
00063         for k in range(len(a)):
00064           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00065                 stacklevel=k
00066                 break
00067         myf=sys._getframe(stacklevel).f_globals
00068         myf['__last_task'] = 'splattotable'
00069         myf['taskname'] = 'splattotable'
00070         ###
00071         myf['update_params'](func=myf['taskname'],printtext=False)
00072         ###
00073         ###
00074         #Handle globals or user over-ride of arguments
00075         #
00076         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00077         useLocalDefaults = False
00078 
00079         for item in function_signature_defaults.iteritems():
00080                 key,val = item
00081                 keyVal = eval(key)
00082                 if (keyVal == None):
00083                         #user hasn't set it - use global/default
00084                         pass
00085                 else:
00086                         #user has set it - use over-ride
00087                         if (key != 'self') :
00088                            useLocalDefaults = True
00089                         #myf[key]=keyVal
00090 
00091         myparams = {}
00092         if useLocalDefaults :
00093            for item in function_signature_defaults.iteritems():
00094                key,val = item
00095                keyVal = eval(key)
00096                exec('myparams[key] = keyVal')
00097                if (keyVal == None):
00098                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00099                    keyVal = eval(key)
00100                    if(type(keyVal) == dict) :
00101                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00102 
00103         else :
00104             uselessvariable = None 
00105             myparams['filenames'] = filenames = myf['filenames']
00106             myparams['table'] = table = myf['table']
00107             myparams['wantreturn'] = wantreturn = myf['wantreturn']
00108 
00109         if type(filenames)==str: filenames=[filenames]
00110 
00111         result = None
00112 
00113 #
00114 #    The following is work around to avoid a bug with current python translation
00115 #
00116         mytmp = {}
00117 
00118         mytmp['filenames'] = filenames
00119         mytmp['table'] = table
00120         mytmp['wantreturn'] = wantreturn
00121         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00122         trec = casac.utils().torecord(pathname+'splattotable.xml')
00123 
00124         casalog.origin('splattotable')
00125         if not trec.has_key('splattotable') or not casac.utils().verify(mytmp, trec['splattotable']) :
00126             return False
00127 
00128 
00129         try :
00130           casalog.post('')
00131           casalog.post('##########################################')
00132           casalog.post('##### Begin Task: splattotable           #####')
00133           casalog.post('')
00134           result = splattotable(filenames, table, wantreturn)
00135           casalog.post('')
00136           casalog.post('##### End Task: splattotable           #####')
00137           casalog.post('##########################################')
00138 
00139 
00140 # saveinputs for individule engine has no use
00141 # saveinputs should alos be removed from casa_in_py.py
00142 #
00143 #
00144 #          saveinputs = myf['saveinputs']
00145 #          saveinputs('splattotable', 'splattotable.last', myparams)
00146 #
00147 #
00148         except Exception, instance:
00149           #print '**** Error **** ',instance
00150           pass
00151 
00152         gc.collect()
00153         return result
00154 #
00155 #
00156 ##
00157 #    def paramgui(self, useGlobals=True):
00158 #        """
00159 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00160 #        """
00161 #        import paramgui
00162 #
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 #
00171 #        if useGlobals:
00172 #            paramgui.setGlobals(myf)
00173 #        else:
00174 #            paramgui.setGlobals({})
00175 #
00176 #        paramgui.runTask('splattotable', myf['_ip'])
00177 #        paramgui.setGlobals({})
00178 #
00179 #
00180 #
00181 #
00182     def defaults(self, param=None):
00183         a=inspect.stack()
00184         stacklevel=0
00185         for k in range(len(a)):
00186           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00187                 stacklevel=k
00188                 break
00189         myf=sys._getframe(stacklevel).f_globals
00190         a = odict()
00191         a['filenames']  = ['']
00192         a['table']  = ''
00193         a['wantreturn']  = True
00194 
00195         a['async']=False
00196 
00197 ### This function sets the default values but also will return the list of
00198 ### parameters or the default value of a given parameter
00199         if(param == None):
00200                 myf['__set_default_parameters'](a)
00201         elif(param == 'paramkeys'):
00202                 return a.keys()
00203         else:
00204                 if(a.has_key(param)):
00205                    #if(type(a[param]) == dict) :
00206                    #   return a[param][len(a[param])-1]['value']
00207                    #else :
00208                       return a[param]
00209 
00210 
00211 #
00212 #
00213     def check_params(self, param=None, value=None):
00214       a=inspect.stack() 
00215       stacklevel=0
00216       for k in range(len(a)):
00217         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00218             stacklevel=k
00219             break
00220       myf=sys._getframe(stacklevel).f_globals
00221 
00222 #      print 'param:', param, 'value:', value
00223       try :
00224          if str(type(value)) != "<type 'instance'>" :
00225             value0 = value
00226             value = myf['cu'].expandparam(param, value)
00227             matchtype = False
00228             if(type(value) == numpy.ndarray):
00229                if(type(value) == type(value0)):
00230                   myf[param] = value.tolist()
00231                else:
00232                   #print 'value:', value, 'value0:', value0
00233                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00234                   myf[param] = value0
00235                   if type(value0) != list :
00236                      matchtype = True
00237             else :
00238                myf[param] = value
00239             value = myf['cu'].verifyparam({param:value})
00240             if matchtype:
00241                value = False
00242       except Exception, instance:
00243          #ignore the exception and just return it unchecked
00244          myf[param] = value
00245       return value
00246 
00247 #
00248 #
00249     def description(self, key='splattotable', subkey=None):
00250         desc={'splattotable': 'Convert a downloaded Splatalogue spectral line list to a casa table.',
00251                'filenames': 'Files containing Splatalogue lists.',
00252                'table': 'Output table name.',
00253                'wantreturn': 'Do you want the task to return a spectralline tool attached to the results table?',
00254 
00255                'async': 'If true the taskname must be started using splattotable(...)'
00256               }
00257 
00258         if(desc.has_key(key)) :
00259            return desc[key]
00260 
00261     def itsdefault(self, paramname) :
00262         a = {}
00263         a['filenames']  = ['']
00264         a['table']  = ''
00265         a['wantreturn']  = True
00266 
00267         if a.has_key(paramname) :
00268               return a[paramname]
00269 splattotable_pg = splattotable_pg_()