casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
msview_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_msview import msview
00016 from task_msview import casalog
00017 
00018 class msview_pg_:
00019     __name__ = "msview"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (msview_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, infile=None, displaytype=None, channel=None, zoom=None, outfile=None, outscale=None, outdpi=None, outformat=None, outlandscape=None, gui=None, async=None):
00027 
00028         """View a visibility data set
00029 
00030         examples of usage:
00031 
00032         msview
00033         msview "mymeasurementset.ms"
00034         msview "myrestorefile.rstr"
00035         
00036         Keyword arguments:
00037         infile -- Name of file to visualize
00038                 default: ''
00039                 example: infile='my.ms'
00040                 If no infile is specified the Load Data window
00041                 will appear for selecting data.
00042         displaytype -- (optional): method of rendering data
00043                 visually (raster, contour, vector or marker).  
00044                 You can also set this parameter to 'lel' and
00045                 provide an lel expression for infile (advanced).
00046                 default: 'raster'
00047 
00048         Note: there is no longer a filetype parameter; typing of
00049         data files is now done automatically.
00050                 example:  msview infile='my.ms'
00051                 obsolete: msview infile='my.ms', filetype='ms'
00052 
00053         
00054         """
00055         a=inspect.stack()
00056         stacklevel=0
00057         for k in range(len(a)):
00058           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00059                 stacklevel=k
00060                 break
00061         myf=sys._getframe(stacklevel).f_globals
00062         myf['__last_task'] = 'msview'
00063         myf['taskname'] = 'msview'
00064         ###
00065         myf['update_params'](func=myf['taskname'],printtext=False)
00066         ###
00067         ###
00068         #Handle globals or user over-ride of arguments
00069         #
00070         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00071         useLocalDefaults = False
00072 
00073         for item in function_signature_defaults.iteritems():
00074                 key,val = item
00075                 keyVal = eval(key)
00076                 if (keyVal == None):
00077                         #user hasn't set it - use global/default
00078                         pass
00079                 else:
00080                         #user has set it - use over-ride
00081                         if (key != 'self') :
00082                            useLocalDefaults = True
00083                         #myf[key]=keyVal
00084 
00085         myparams = {}
00086         if useLocalDefaults :
00087            for item in function_signature_defaults.iteritems():
00088                key,val = item
00089                keyVal = eval(key)
00090                exec('myparams[key] = keyVal')
00091                if (keyVal == None):
00092                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00093                    keyVal = eval(key)
00094                    if(type(keyVal) == dict) :
00095                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00096 
00097         else :
00098             uselessvariable = None 
00099             myparams['infile'] = infile = myf['infile']
00100             myparams['displaytype'] = displaytype = myf['displaytype']
00101             myparams['channel'] = channel = myf['channel']
00102             myparams['zoom'] = zoom = myf['zoom']
00103             myparams['outfile'] = outfile = myf['outfile']
00104             myparams['outscale'] = outscale = myf['outscale']
00105             myparams['outdpi'] = outdpi = myf['outdpi']
00106             myparams['outformat'] = outformat = myf['outformat']
00107             myparams['outlandscape'] = outlandscape = myf['outlandscape']
00108             myparams['gui'] = gui = myf['gui']
00109 
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['infile'] = infile
00119         mytmp['displaytype'] = displaytype
00120         mytmp['channel'] = channel
00121         mytmp['zoom'] = zoom
00122         mytmp['outfile'] = outfile
00123         mytmp['outscale'] = outscale
00124         mytmp['outdpi'] = outdpi
00125         mytmp['outformat'] = outformat
00126         mytmp['outlandscape'] = outlandscape
00127         mytmp['gui'] = gui
00128         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00129         trec = casac.utils().torecord(pathname+'msview.xml')
00130 
00131         casalog.origin('msview')
00132         if not trec.has_key('msview') or not casac.utils().verify(mytmp, trec['msview']) :
00133             return False
00134 
00135 
00136         try :
00137           casalog.post('')
00138           casalog.post('##########################################')
00139           casalog.post('##### Begin Task: msview           #####')
00140           casalog.post('')
00141           result = msview(infile, displaytype, channel, zoom, outfile, outscale, outdpi, outformat, outlandscape, gui)
00142           casalog.post('')
00143           casalog.post('##### End Task: msview           #####')
00144           casalog.post('##########################################')
00145 
00146 
00147 # saveinputs for individule engine has no use
00148 # saveinputs should alos be removed from casa_in_py.py
00149 #
00150 #
00151 #          saveinputs = myf['saveinputs']
00152 #          saveinputs('msview', 'msview.last', myparams)
00153 #
00154 #
00155         except Exception, instance:
00156           #print '**** Error **** ',instance
00157           pass
00158 
00159         gc.collect()
00160         return result
00161 #
00162 #
00163 ##
00164 #    def paramgui(self, useGlobals=True):
00165 #        """
00166 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00167 #        """
00168 #        import paramgui
00169 #
00170 #        a=inspect.stack()
00171 #        stacklevel=0
00172 #        for k in range(len(a)):
00173 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00174 #            stacklevel=k
00175 #            break
00176 #        myf = sys._getframe(stacklevel).f_globals
00177 #
00178 #        if useGlobals:
00179 #            paramgui.setGlobals(myf)
00180 #        else:
00181 #            paramgui.setGlobals({})
00182 #
00183 #        paramgui.runTask('msview', myf['_ip'])
00184 #        paramgui.setGlobals({})
00185 #
00186 #
00187 #
00188 #
00189     def defaults(self, param=None):
00190         a=inspect.stack()
00191         stacklevel=0
00192         for k in range(len(a)):
00193           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00194                 stacklevel=k
00195                 break
00196         myf=sys._getframe(stacklevel).f_globals
00197         a = odict()
00198         a['infile']  = ''
00199         a['displaytype']  = 'raster'
00200         a['channel']  = 0
00201         a['zoom']  = 1
00202         a['outfile']  = ''
00203         a['outscale']  = 1.0
00204         a['outdpi']  = 300
00205         a['outformat']  = 'jpg'
00206         a['outlandscape']  = False
00207         a['gui']  = True
00208 
00209         a['async']=False
00210 
00211 ### This function sets the default values but also will return the list of
00212 ### parameters or the default value of a given parameter
00213         if(param == None):
00214                 myf['__set_default_parameters'](a)
00215         elif(param == 'paramkeys'):
00216                 return a.keys()
00217         else:
00218                 if(a.has_key(param)):
00219                    #if(type(a[param]) == dict) :
00220                    #   return a[param][len(a[param])-1]['value']
00221                    #else :
00222                       return a[param]
00223 
00224 
00225 #
00226 #
00227     def check_params(self, param=None, value=None):
00228       a=inspect.stack() 
00229       stacklevel=0
00230       for k in range(len(a)):
00231         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00232             stacklevel=k
00233             break
00234       myf=sys._getframe(stacklevel).f_globals
00235 
00236 #      print 'param:', param, 'value:', value
00237       try :
00238          if str(type(value)) != "<type 'instance'>" :
00239             value0 = value
00240             value = myf['cu'].expandparam(param, value)
00241             matchtype = False
00242             if(type(value) == numpy.ndarray):
00243                if(type(value) == type(value0)):
00244                   myf[param] = value.tolist()
00245                else:
00246                   #print 'value:', value, 'value0:', value0
00247                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00248                   myf[param] = value0
00249                   if type(value0) != list :
00250                      matchtype = True
00251             else :
00252                myf[param] = value
00253             value = myf['cu'].verifyparam({param:value})
00254             if matchtype:
00255                value = False
00256       except Exception, instance:
00257          #ignore the exception and just return it unchecked
00258          myf[param] = value
00259       return value
00260 
00261 #
00262 #
00263     def description(self, key='msview', subkey=None):
00264         desc={'msview': 'View a visibility data set',
00265                'infile': ' (Optional)  Name of file to visualize.',
00266                'displaytype': ' (Optional)  Type of visual rendering (raster, contour, vector or marker).  lel  if an lel expression is given for infile  (advanced).',
00267                'channel': ' (Optional)  access a specific channel in the image cube',
00268                'zoom': ' (Optional)  zoom in/out by increments',
00269                'outfile': ' (Optional)  name of the output file to generate',
00270                'outscale': ' (Optional)  amount to scale output bitmap formats (non-PS, non-PDF)',
00271                'outdpi': ' (Optional)  output DPI for PS/PDF',
00272                'outformat': ' (Optional)  format of the output e.g. jpg or pdf (this is overridden by the output files extension',
00273                'outlandscape': ' (Optional)  should the output mode be landscape (PS or PDF)',
00274                'gui': ' (Optional)  Display the panel in a GUI.',
00275 
00276                'async': 'If true the taskname must be started using msview(...)'
00277               }
00278 
00279 #
00280 # Set subfields defaults if needed
00281 #
00282 
00283         if(desc.has_key(key)) :
00284            return desc[key]
00285 
00286     def itsdefault(self, paramname) :
00287         a = {}
00288         a['infile']  = ''
00289         a['displaytype']  = 'raster'
00290         a['channel']  = 0
00291         a['zoom']  = 1
00292         a['outfile']  = ''
00293         a['outscale']  = 1.0
00294         a['outdpi']  = 300
00295         a['outformat']  = 'jpg'
00296         a['outlandscape']  = False
00297         a['gui']  = True
00298 
00299         if a.has_key(paramname) :
00300               return a[paramname]
00301 msview_pg = msview_pg_()