casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
exportasdm_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_exportasdm import exportasdm
00016 from task_exportasdm import casalog
00017 
00018 class exportasdm_pg_:
00019     __name__ = "exportasdm"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (exportasdm_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, vis=None, asdm=None, datacolumn=None, archiveid=None, rangeid=None, subscanduration=None, sbduration=None, apcorrected=None, verbose=None, showversion=None, useversion=None, async=None):
00027 
00028         """Convert a CASA visibility file (MS) into an ALMA Science Data Model
00029 
00030   Keyword arguments:
00031   vis -- MS name,
00032          default: none
00033 
00034   asdm -- Name of output ASDM file (directory),
00035           default: none; example: asdm='ExecBlock3'
00036 
00037   datacolumn -- specifies which of the MS data columns (data,
00038            corrected, or model) should be used as the
00039            visibilities in the ASDM, default: data
00040 
00041   archiveid -- the X0 in uid://X0/X1/X<running>
00042                default: "S0"
00043 
00044   rangeid -- the X1 in uid://X0/X1/X<running>
00045              default: "X1"
00046 
00047   subscanduration -- maximum duration of a subscan in the output ASDM
00048                      default: "24h"
00049 
00050   sbduration -- maximum duration of a scheduling block in the output ASDM
00051                      default: "2700s"
00052 
00053   apcorrected -- If true, the data in column datacolumn will be marked
00054                  as having atmospheric phase correction, default: True
00055 
00056   verbose     -- produce log output, default: True
00057 
00058   showversion -- report the version of the ASDM class set, 
00059                  default: True
00060 
00061   useversion -- Selects the version of MS2asdm to be used (\'v3\' (default) or \'v2\' (version before May 2011))
00062                 default: v3
00063 
00064   exportasdm(vis='ngc4826.ms', asdm='uid___S021_X1418_X1', 
00065   datacolumn='corrected', archiveid='S021', rangeid='X1418', 
00066   verbose=False)
00067   will produce an ASDM named 'uid___S021_X1418_X1' using the 
00068   datacolumn 'corrected' in the MS 'ngc4826.ms' with minimal
00069   log output. 
00070 
00071   Note concerning ALMA data: exportasdm presently is not able to export 
00072   from MSs containing WVR data. If you attempt to export such an MS, you
00073   will receive an error message saying that you can only export data of
00074   processor type "CORRELATOR". It will also give you the list of SPWs
00075   which contain CORRELATOR data. You will then have to split out these
00076   SPWs using the task "split" and run exportasdm on the resulting MS. 
00077 
00078   
00079         """
00080         a=inspect.stack()
00081         stacklevel=0
00082         for k in range(len(a)):
00083           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00084                 stacklevel=k
00085                 break
00086         myf=sys._getframe(stacklevel).f_globals
00087         myf['__last_task'] = 'exportasdm'
00088         myf['taskname'] = 'exportasdm'
00089         ###
00090         myf['update_params'](func=myf['taskname'],printtext=False)
00091         ###
00092         ###
00093         #Handle globals or user over-ride of arguments
00094         #
00095         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00096         useLocalDefaults = False
00097 
00098         for item in function_signature_defaults.iteritems():
00099                 key,val = item
00100                 keyVal = eval(key)
00101                 if (keyVal == None):
00102                         #user hasn't set it - use global/default
00103                         pass
00104                 else:
00105                         #user has set it - use over-ride
00106                         if (key != 'self') :
00107                            useLocalDefaults = True
00108                         #myf[key]=keyVal
00109 
00110         myparams = {}
00111         if useLocalDefaults :
00112            for item in function_signature_defaults.iteritems():
00113                key,val = item
00114                keyVal = eval(key)
00115                exec('myparams[key] = keyVal')
00116                if (keyVal == None):
00117                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00118                    keyVal = eval(key)
00119                    if(type(keyVal) == dict) :
00120                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00121 
00122         else :
00123             uselessvariable = None 
00124             myparams['vis'] = vis = myf['vis']
00125             myparams['asdm'] = asdm = myf['asdm']
00126             myparams['datacolumn'] = datacolumn = myf['datacolumn']
00127             myparams['archiveid'] = archiveid = myf['archiveid']
00128             myparams['rangeid'] = rangeid = myf['rangeid']
00129             myparams['subscanduration'] = subscanduration = myf['subscanduration']
00130             myparams['sbduration'] = sbduration = myf['sbduration']
00131             myparams['apcorrected'] = apcorrected = myf['apcorrected']
00132             myparams['verbose'] = verbose = myf['verbose']
00133             myparams['showversion'] = showversion = myf['showversion']
00134             myparams['useversion'] = useversion = myf['useversion']
00135 
00136 
00137         result = None
00138 
00139 #
00140 #    The following is work around to avoid a bug with current python translation
00141 #
00142         mytmp = {}
00143 
00144         mytmp['vis'] = vis
00145         mytmp['asdm'] = asdm
00146         mytmp['datacolumn'] = datacolumn
00147         mytmp['archiveid'] = archiveid
00148         mytmp['rangeid'] = rangeid
00149         mytmp['subscanduration'] = subscanduration
00150         mytmp['sbduration'] = sbduration
00151         mytmp['apcorrected'] = apcorrected
00152         mytmp['verbose'] = verbose
00153         mytmp['showversion'] = showversion
00154         mytmp['useversion'] = useversion
00155         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00156         trec = casac.utils().torecord(pathname+'exportasdm.xml')
00157 
00158         casalog.origin('exportasdm')
00159         if not trec.has_key('exportasdm') or not casac.utils().verify(mytmp, trec['exportasdm']) :
00160             return False
00161 
00162 
00163         try :
00164           casalog.post('')
00165           casalog.post('##########################################')
00166           casalog.post('##### Begin Task: exportasdm           #####')
00167           casalog.post('')
00168           result = exportasdm(vis, asdm, datacolumn, archiveid, rangeid, subscanduration, sbduration, apcorrected, verbose, showversion, useversion)
00169           casalog.post('')
00170           casalog.post('##### End Task: exportasdm           #####')
00171           casalog.post('##########################################')
00172 
00173 
00174 # saveinputs for individule engine has no use
00175 # saveinputs should alos be removed from casa_in_py.py
00176 #
00177 #
00178 #          saveinputs = myf['saveinputs']
00179 #          saveinputs('exportasdm', 'exportasdm.last', myparams)
00180 #
00181 #
00182         except Exception, instance:
00183           #print '**** Error **** ',instance
00184           pass
00185 
00186         gc.collect()
00187         return result
00188 #
00189 #
00190 ##
00191 #    def paramgui(self, useGlobals=True):
00192 #        """
00193 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00194 #        """
00195 #        import paramgui
00196 #
00197 #        a=inspect.stack()
00198 #        stacklevel=0
00199 #        for k in range(len(a)):
00200 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00201 #            stacklevel=k
00202 #            break
00203 #        myf = sys._getframe(stacklevel).f_globals
00204 #
00205 #        if useGlobals:
00206 #            paramgui.setGlobals(myf)
00207 #        else:
00208 #            paramgui.setGlobals({})
00209 #
00210 #        paramgui.runTask('exportasdm', myf['_ip'])
00211 #        paramgui.setGlobals({})
00212 #
00213 #
00214 #
00215 #
00216     def defaults(self, param=None):
00217         a=inspect.stack()
00218         stacklevel=0
00219         for k in range(len(a)):
00220           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00221                 stacklevel=k
00222                 break
00223         myf=sys._getframe(stacklevel).f_globals
00224         a = odict()
00225         a['vis']  = ''
00226         a['asdm']  = ''
00227         a['datacolumn']  = 'data'
00228         a['archiveid']  = 'S0'
00229         a['rangeid']  = 'X1'
00230         a['subscanduration']  = '24h'
00231         a['sbduration']  = '2700s'
00232         a['apcorrected']  = True
00233         a['verbose']  = True
00234         a['showversion']  = True
00235         a['useversion']  = 'v3'
00236 
00237         a['async']=False
00238 
00239 ### This function sets the default values but also will return the list of
00240 ### parameters or the default value of a given parameter
00241         if(param == None):
00242                 myf['__set_default_parameters'](a)
00243         elif(param == 'paramkeys'):
00244                 return a.keys()
00245         else:
00246                 if(a.has_key(param)):
00247                    #if(type(a[param]) == dict) :
00248                    #   return a[param][len(a[param])-1]['value']
00249                    #else :
00250                       return a[param]
00251 
00252 
00253 #
00254 #
00255     def check_params(self, param=None, value=None):
00256       a=inspect.stack() 
00257       stacklevel=0
00258       for k in range(len(a)):
00259         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00260             stacklevel=k
00261             break
00262       myf=sys._getframe(stacklevel).f_globals
00263 
00264 #      print 'param:', param, 'value:', value
00265       try :
00266          if str(type(value)) != "<type 'instance'>" :
00267             value0 = value
00268             value = myf['cu'].expandparam(param, value)
00269             matchtype = False
00270             if(type(value) == numpy.ndarray):
00271                if(type(value) == type(value0)):
00272                   myf[param] = value.tolist()
00273                else:
00274                   #print 'value:', value, 'value0:', value0
00275                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00276                   myf[param] = value0
00277                   if type(value0) != list :
00278                      matchtype = True
00279             else :
00280                myf[param] = value
00281             value = myf['cu'].verifyparam({param:value})
00282             if matchtype:
00283                value = False
00284       except Exception, instance:
00285          #ignore the exception and just return it unchecked
00286          myf[param] = value
00287       return value
00288 
00289 #
00290 #
00291     def description(self, key='exportasdm', subkey=None):
00292         desc={'exportasdm': 'Convert a CASA visibility file (MS) into an ALMA Science Data Model',
00293                'vis': 'MS name',
00294                'asdm': 'Name of output ASDM directory (on disk)',
00295                'datacolumn': 'specifies which MS data column is used to fill the visibilites in the ASDM',
00296                'archiveid': 'the X0 in uid://X0/X1/X<running>',
00297                'rangeid': 'the X1 in uid://X0/X1/X<running>',
00298                'subscanduration': 'maximum duration of a subscan in the output ASDM',
00299                'sbduration': 'maximum duration of a scheduling block (and therefore exec block) in the output ASDM',
00300                'apcorrected': 'data to be marked as having atmospheric phase correction',
00301                'verbose': 'produce log output',
00302                'showversion': 'Report the version of ASDM class set being used',
00303                'useversion': 'Selects the version of MS2asdm to be used (\'v3\' (default and only option presently))',
00304 
00305                'async': 'If true the taskname must be started using exportasdm(...)'
00306               }
00307 
00308         if(desc.has_key(key)) :
00309            return desc[key]
00310 
00311     def itsdefault(self, paramname) :
00312         a = {}
00313         a['vis']  = ''
00314         a['asdm']  = ''
00315         a['datacolumn']  = 'data'
00316         a['archiveid']  = 'S0'
00317         a['rangeid']  = 'X1'
00318         a['subscanduration']  = '24h'
00319         a['sbduration']  = '2700s'
00320         a['apcorrected']  = True
00321         a['verbose']  = True
00322         a['showversion']  = True
00323         a['useversion']  = 'v3'
00324 
00325         if a.has_key(paramname) :
00326               return a[paramname]
00327 exportasdm_pg = exportasdm_pg_()