casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdcoadd_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_sdcoadd import sdcoadd
00016 from task_sdcoadd import casalog
00017 
00018 class sdcoadd_pg_:
00019     __name__ = "sdcoadd"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (sdcoadd_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, infiles=None, antenna=None, fluxunit=None, telescopeparm=None, specunit=None, frame=None, doppler=None, scanaverage=None, timeaverage=None, tweight=None, polaverage=None, pweight=None, outfile=None, outform=None, overwrite=None, async=None):
00027 
00028         """ASAP SD task: coadd multiple scantables into one
00029   Keyword arguments:
00030         infiles -- list of names of input SD dataset
00031         antenna -- antenna name or id (only effective for MS input). 
00032         fluxunit -- units for line flux
00033                 options: 'K','Jy',''
00034                 default: '' (keep current fluxunit of the first data in the infiles)
00035 
00036             >>> fluxunit expandable parameter
00037                  telescopeparm -- the telescope characteristics
00038                          options: (str) name or (list) list of gain info
00039                          default: '' (none set)
00040                          example: if telescopeparm='', it tries to get the telescope
00041                                   name from the data.
00042                                   Full antenna parameters (diameter,ap.eff.) known
00043                                   to ASAP are
00044                                   'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43',
00045                                   'CEDUNA','HOBART'. For GBT, it fixes default fluxunit
00046                                   to 'K' first then convert to a new fluxunit.
00047                                   telescopeparm=[104.9,0.43] diameter(m), ap.eff.
00048                                   telescopeparm=[0.743] gain in Jy/K
00049                                   telescopeparm='FIX' to change default fluxunit
00050                                   see description below
00051 
00052         specunit -- units for spectral axis
00053                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz'
00054                 default: '' (=current)
00055                 example: this will be the units for masklist
00056         frame -- frequency frame for spectral axis
00057                 options: (str) 'LSRK','REST','TOPO','LSRD','BARY',
00058                          'GEO','GALACTO','LGROUP','CMB'
00059                 default: currently set frame in scantable
00060                 WARNING: frame='REST' not yet implemented
00061         doppler -- doppler mode
00062                 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA'
00063                 default: currently set doppler in scantable
00064         scanaverage -- average integrations within scans
00065                 options: (bool) True,False
00066                 default: False
00067                 example: if True, this happens in read-in
00068                 For GBT, set False!
00069         timeaverage -- average times for multiple scan cycles
00070                 options: (bool) True,False
00071                 default: False
00072                 example: if True, this happens after calibration
00073 
00074             >>>timeaverage expandable parameter
00075                  tweight -- weighting for time average
00076                          options: 'none' 
00077                                   'var'   (1/var(spec) weighted)
00078                                   'tsys'  (1/Tsys**2 weighted)
00079                                   'tint'  (integration time weighted)
00080                                   'tintsys'  (Tint/Tsys**2)
00081                                   'median'  ( median averaging)
00082                          default: 'none'
00083 
00084         polaverage -- average polarizations
00085                 options: (bool) True,False
00086                 default: False
00087 
00088             >>>polaverage expandable parameter
00089                  pweight -- weighting for polarization average
00090                          options: 'none'
00091                                   'var'  (1/var(spec) weighted)
00092                                   'tsys' (1/Tsys**2 weighted)
00093                          default: 'none'
00094 
00095         outfile -- Name of output file
00096                 default: '' (scantable)
00097                 example:
00098         outform -- format of output file
00099                 options: 'ASCII','SDFITS','MS','ASAP'
00100                 default: 'ASAP'
00101                 example: the ASAP format is easiest for further sd
00102                          processing; use MS for CASA imaging.
00103                          If ASCII, then will append some stuff to
00104                          the outfile name
00105         overwrite -- overwrite the output file if already exists
00106                 options: (bool) True,False
00107                 default: False
00108                 WARNING: if outform='ASCII', this parameter is ignored 
00109 
00110 
00111 
00112         DESCRIPTION:
00113 
00114         Task sdcoadd performs co-add multiple single dish spectral data given by
00115         a list of spectral data file names in any of the following formats,
00116         ASAP, MS2,SDFITS, and ASCII.
00117         The units of line flux, the units of spectral axis, frame, and doppler
00118         are assumed to be those of the first one in the infiles if not
00119         specified.
00120         timaverage and polaverage are used to perform time
00121         and polarization averaging over scans on the co-added scantable before
00122         saving to a file on disk.
00123 
00124         WARNING for the GBT raw SDFITS format data as input:
00125         SDtasks are able to handle GBT raw SDFITS format data since the 
00126         data filler is available. However, the functionality is not well 
00127         tested yet, so that there may be unknown bugs.  
00128 
00129   
00130         """
00131         a=inspect.stack()
00132         stacklevel=0
00133         for k in range(len(a)):
00134           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00135                 stacklevel=k
00136                 break
00137         myf=sys._getframe(stacklevel).f_globals
00138         myf['__last_task'] = 'sdcoadd'
00139         myf['taskname'] = 'sdcoadd'
00140         ###
00141         myf['update_params'](func=myf['taskname'],printtext=False)
00142         ###
00143         ###
00144         #Handle globals or user over-ride of arguments
00145         #
00146         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00147         useLocalDefaults = False
00148 
00149         for item in function_signature_defaults.iteritems():
00150                 key,val = item
00151                 keyVal = eval(key)
00152                 if (keyVal == None):
00153                         #user hasn't set it - use global/default
00154                         pass
00155                 else:
00156                         #user has set it - use over-ride
00157                         if (key != 'self') :
00158                            useLocalDefaults = True
00159                         #myf[key]=keyVal
00160 
00161         myparams = {}
00162         if useLocalDefaults :
00163            for item in function_signature_defaults.iteritems():
00164                key,val = item
00165                keyVal = eval(key)
00166                exec('myparams[key] = keyVal')
00167                if (keyVal == None):
00168                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00169                    keyVal = eval(key)
00170                    if(type(keyVal) == dict) :
00171                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00172 
00173         else :
00174             uselessvariable = None 
00175             myparams['infiles'] = infiles = myf['infiles']
00176             myparams['antenna'] = antenna = myf['antenna']
00177             myparams['fluxunit'] = fluxunit = myf['fluxunit']
00178             myparams['telescopeparm'] = telescopeparm = myf['telescopeparm']
00179             myparams['specunit'] = specunit = myf['specunit']
00180             myparams['frame'] = frame = myf['frame']
00181             myparams['doppler'] = doppler = myf['doppler']
00182             myparams['scanaverage'] = scanaverage = myf['scanaverage']
00183             myparams['timeaverage'] = timeaverage = myf['timeaverage']
00184             myparams['tweight'] = tweight = myf['tweight']
00185             myparams['polaverage'] = polaverage = myf['polaverage']
00186             myparams['pweight'] = pweight = myf['pweight']
00187             myparams['outfile'] = outfile = myf['outfile']
00188             myparams['outform'] = outform = myf['outform']
00189             myparams['overwrite'] = overwrite = myf['overwrite']
00190 
00191         if type(infiles)==str: infiles=[infiles]
00192 
00193         result = None
00194 
00195 #
00196 #    The following is work around to avoid a bug with current python translation
00197 #
00198         mytmp = {}
00199 
00200         mytmp['infiles'] = infiles
00201         mytmp['antenna'] = antenna
00202         mytmp['fluxunit'] = fluxunit
00203         mytmp['telescopeparm'] = telescopeparm
00204         mytmp['specunit'] = specunit
00205         mytmp['frame'] = frame
00206         mytmp['doppler'] = doppler
00207         mytmp['scanaverage'] = scanaverage
00208         mytmp['timeaverage'] = timeaverage
00209         mytmp['tweight'] = tweight
00210         mytmp['polaverage'] = polaverage
00211         mytmp['pweight'] = pweight
00212         mytmp['outfile'] = outfile
00213         mytmp['outform'] = outform
00214         mytmp['overwrite'] = overwrite
00215         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00216         trec = casac.utils().torecord(pathname+'sdcoadd.xml')
00217 
00218         casalog.origin('sdcoadd')
00219         if not trec.has_key('sdcoadd') or not casac.utils().verify(mytmp, trec['sdcoadd']) :
00220             return False
00221 
00222 
00223         try :
00224           casalog.post('')
00225           casalog.post('##########################################')
00226           casalog.post('##### Begin Task: sdcoadd           #####')
00227           casalog.post('')
00228           result = sdcoadd(infiles, antenna, fluxunit, telescopeparm, specunit, frame, doppler, scanaverage, timeaverage, tweight, polaverage, pweight, outfile, outform, overwrite)
00229           casalog.post('')
00230           casalog.post('##### End Task: sdcoadd           #####')
00231           casalog.post('##########################################')
00232 
00233 
00234 # saveinputs for individule engine has no use
00235 # saveinputs should alos be removed from casa_in_py.py
00236 #
00237 #
00238 #          saveinputs = myf['saveinputs']
00239 #          saveinputs('sdcoadd', 'sdcoadd.last', myparams)
00240 #
00241 #
00242         except Exception, instance:
00243           #print '**** Error **** ',instance
00244           pass
00245 
00246         gc.collect()
00247         return result
00248 #
00249 #
00250 ##
00251 #    def paramgui(self, useGlobals=True):
00252 #        """
00253 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00254 #        """
00255 #        import paramgui
00256 #
00257 #        a=inspect.stack()
00258 #        stacklevel=0
00259 #        for k in range(len(a)):
00260 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00261 #            stacklevel=k
00262 #            break
00263 #        myf = sys._getframe(stacklevel).f_globals
00264 #
00265 #        if useGlobals:
00266 #            paramgui.setGlobals(myf)
00267 #        else:
00268 #            paramgui.setGlobals({})
00269 #
00270 #        paramgui.runTask('sdcoadd', myf['_ip'])
00271 #        paramgui.setGlobals({})
00272 #
00273 #
00274 #
00275 #
00276     def defaults(self, param=None):
00277         a=inspect.stack()
00278         stacklevel=0
00279         for k in range(len(a)):
00280           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00281                 stacklevel=k
00282                 break
00283         myf=sys._getframe(stacklevel).f_globals
00284         a = odict()
00285         a['infiles']  = ['']
00286         a['antenna']  = 0
00287         a['fluxunit']  = ''
00288         a['specunit']  = ''
00289         a['frame']  = ''
00290         a['doppler']  = ''
00291         a['scanaverage']  = False
00292         a['timeaverage']  = False
00293         a['polaverage']  = False
00294         a['outfile']  = ''
00295         a['outform']  = 'ASAP'
00296         a['overwrite']  = False
00297 
00298         a['async']=False
00299         a['fluxunit'] = {
00300                     0:{'value':''}, 
00301                     1:odict([{'value':'K'}, {'telescopeparm':''}]), 
00302                     2:odict([{'value':'k'}, {'telescopeparm':''}]), 
00303                     3:odict([{'value':'Jy'}, {'telescopeparm':''}]), 
00304                     4:odict([{'value':'jy'}, {'telescopeparm':''}])}
00305         a['timeaverage'] = {
00306                     0:{'value':False}, 
00307                     1:odict([{'value':True}, {'tweight':'none'}])}
00308         a['polaverage'] = {
00309                     0:{'value':False}, 
00310                     1:odict([{'value':True}, {'pweight':'none'}])}
00311 
00312 ### This function sets the default values but also will return the list of
00313 ### parameters or the default value of a given parameter
00314         if(param == None):
00315                 myf['__set_default_parameters'](a)
00316         elif(param == 'paramkeys'):
00317                 return a.keys()
00318         else:
00319                 if(a.has_key(param)):
00320                    #if(type(a[param]) == dict) :
00321                    #   return a[param][len(a[param])-1]['value']
00322                    #else :
00323                       return a[param]
00324 
00325 
00326 #
00327 #
00328     def check_params(self, param=None, value=None):
00329       a=inspect.stack() 
00330       stacklevel=0
00331       for k in range(len(a)):
00332         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00333             stacklevel=k
00334             break
00335       myf=sys._getframe(stacklevel).f_globals
00336 
00337 #      print 'param:', param, 'value:', value
00338       try :
00339          if str(type(value)) != "<type 'instance'>" :
00340             value0 = value
00341             value = myf['cu'].expandparam(param, value)
00342             matchtype = False
00343             if(type(value) == numpy.ndarray):
00344                if(type(value) == type(value0)):
00345                   myf[param] = value.tolist()
00346                else:
00347                   #print 'value:', value, 'value0:', value0
00348                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00349                   myf[param] = value0
00350                   if type(value0) != list :
00351                      matchtype = True
00352             else :
00353                myf[param] = value
00354             value = myf['cu'].verifyparam({param:value})
00355             if matchtype:
00356                value = False
00357       except Exception, instance:
00358          #ignore the exception and just return it unchecked
00359          myf[param] = value
00360       return value
00361 
00362 #
00363 #
00364     def description(self, key='sdcoadd', subkey=None):
00365         desc={'sdcoadd': 'ASAP SD task: coadd multiple scantables into one',
00366                'infiles': 'list of names of input SD dataset',
00367                'antenna': 'antenna name or id (only effective for MS input)',
00368                'fluxunit': 'units for line flux (K,Jy) (''=current)',
00369                'telescopeparm': 'param of telescope for flux conversion',
00370                'specunit': 'units for spectral axis (channel,km/s,GHz)',
00371                'frame': 'frequency reference frame, e.g. LSRK (''=current)',
00372                'doppler': 'doppler convention, e.g. RADIO (''=current)',
00373                'scanaverage': 'average integs within scans (True,False) ',
00374                'timeaverage': 'average scans over time (True,False)',
00375                'tweight': 'weighting for time averaging',
00376                'polaverage': 'average over polarizations (True,False)',
00377                'pweight': 'weighting for polarization averaging',
00378                'outfile': 'output file name',
00379                'outform': 'output file format (ASCII,MS,SDFITS,ASAP)',
00380                'overwrite': 'overwrite the output file if already exists',
00381 
00382                'async': 'If true the taskname must be started using sdcoadd(...)'
00383               }
00384 
00385 #
00386 # Set subfields defaults if needed
00387 #
00388 
00389         if(desc.has_key(key)) :
00390            return desc[key]
00391 
00392     def itsdefault(self, paramname) :
00393         a = {}
00394         a['infiles']  = ['']
00395         a['antenna']  = 0
00396         a['fluxunit']  = ''
00397         a['telescopeparm']  = ''
00398         a['specunit']  = ''
00399         a['frame']  = ''
00400         a['doppler']  = ''
00401         a['scanaverage']  = False
00402         a['timeaverage']  = False
00403         a['tweight']  = 'none'
00404         a['polaverage']  = False
00405         a['pweight']  = 'none'
00406         a['outfile']  = ''
00407         a['outform']  = 'ASAP'
00408         a['overwrite']  = False
00409 
00410         if a.has_key(paramname) :
00411               return a[paramname]
00412 sdcoadd_pg = sdcoadd_pg_()