casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
plotweather_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_plotweather import plotweather
00016 from task_plotweather import casalog
00017 
00018 class plotweather_pg_:
00019     __name__ = "plotweather"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (plotweather_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, vis=None, seasonal_weight=None, doPlot=None, plotName=None, async=None):
00027 
00028         """Plot elements of the weather table; estimate opacity.
00029 Generates opacity estimates from both the weather data and a seasonal model; intended for VLA use only. 
00030 By default the returned opacity is the mean of these predictions, but this can be adjusted with seasonal_weight.
00031 
00032 These methods and models are described in detail in EVLA Memo 143, VLA Test Memo 232, VLA Scientific Memo 176, and references therein.
00033 
00034 Saves the plot to the following default file:  MS name + .plotweather.png
00035 Custom plot filenames must end in one of: .png, .pdf, .ps, .eps or .svg
00036 
00037 If run as a function, will return the mean zenith opacity per spectral window
00038 
00039 Written by Josh Marvil, revised 02/06/12
00040 Please direct questions/comments/bug reports to: jmarvil@aoc.nrao.edu
00041 
00042 
00043 example:
00044 myTau = plotweather(vis='myMS.ms',seasonal_weight=0.5, doPlot=True)
00045 
00046         """
00047         a=inspect.stack()
00048         stacklevel=0
00049         for k in range(len(a)):
00050           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00051                 stacklevel=k
00052                 break
00053         myf=sys._getframe(stacklevel).f_globals
00054         myf['__last_task'] = 'plotweather'
00055         myf['taskname'] = 'plotweather'
00056         ###
00057         myf['update_params'](func=myf['taskname'],printtext=False)
00058         ###
00059         ###
00060         #Handle globals or user over-ride of arguments
00061         #
00062         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00063         useLocalDefaults = False
00064 
00065         for item in function_signature_defaults.iteritems():
00066                 key,val = item
00067                 keyVal = eval(key)
00068                 if (keyVal == None):
00069                         #user hasn't set it - use global/default
00070                         pass
00071                 else:
00072                         #user has set it - use over-ride
00073                         if (key != 'self') :
00074                            useLocalDefaults = True
00075                         #myf[key]=keyVal
00076 
00077         myparams = {}
00078         if useLocalDefaults :
00079            for item in function_signature_defaults.iteritems():
00080                key,val = item
00081                keyVal = eval(key)
00082                exec('myparams[key] = keyVal')
00083                if (keyVal == None):
00084                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00085                    keyVal = eval(key)
00086                    if(type(keyVal) == dict) :
00087                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00088 
00089         else :
00090             uselessvariable = None 
00091             myparams['vis'] = vis = myf['vis']
00092             myparams['seasonal_weight'] = seasonal_weight = myf['seasonal_weight']
00093             myparams['doPlot'] = doPlot = myf['doPlot']
00094             myparams['plotName'] = plotName = myf['plotName']
00095 
00096 
00097         result = None
00098 
00099 #
00100 #    The following is work around to avoid a bug with current python translation
00101 #
00102         mytmp = {}
00103 
00104         mytmp['vis'] = vis
00105         mytmp['seasonal_weight'] = seasonal_weight
00106         mytmp['doPlot'] = doPlot
00107         mytmp['plotName'] = plotName
00108         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00109         trec = casac.utils().torecord(pathname+'plotweather.xml')
00110 
00111         casalog.origin('plotweather')
00112         if not trec.has_key('plotweather') or not casac.utils().verify(mytmp, trec['plotweather']) :
00113             return False
00114 
00115 
00116         try :
00117           casalog.post('')
00118           casalog.post('##########################################')
00119           casalog.post('##### Begin Task: plotweather           #####')
00120           casalog.post('')
00121           result = plotweather(vis, seasonal_weight, doPlot, plotName)
00122           casalog.post('')
00123           casalog.post('##### End Task: plotweather           #####')
00124           casalog.post('##########################################')
00125 
00126 
00127 # saveinputs for individule engine has no use
00128 # saveinputs should alos be removed from casa_in_py.py
00129 #
00130 #
00131 #          saveinputs = myf['saveinputs']
00132 #          saveinputs('plotweather', 'plotweather.last', myparams)
00133 #
00134 #
00135         except Exception, instance:
00136           #print '**** Error **** ',instance
00137           pass
00138 
00139         gc.collect()
00140         return result
00141 #
00142 #
00143 ##
00144 #    def paramgui(self, useGlobals=True):
00145 #        """
00146 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00147 #        """
00148 #        import paramgui
00149 #
00150 #        a=inspect.stack()
00151 #        stacklevel=0
00152 #        for k in range(len(a)):
00153 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00154 #            stacklevel=k
00155 #            break
00156 #        myf = sys._getframe(stacklevel).f_globals
00157 #
00158 #        if useGlobals:
00159 #            paramgui.setGlobals(myf)
00160 #        else:
00161 #            paramgui.setGlobals({})
00162 #
00163 #        paramgui.runTask('plotweather', myf['_ip'])
00164 #        paramgui.setGlobals({})
00165 #
00166 #
00167 #
00168 #
00169     def defaults(self, param=None):
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         a = odict()
00178         a['vis']  = ''
00179         a['seasonal_weight']  = 0.5
00180         a['doPlot']  = True
00181         a['plotName']  = ''
00182 
00183         a['async']=False
00184 
00185 ### This function sets the default values but also will return the list of
00186 ### parameters or the default value of a given parameter
00187         if(param == None):
00188                 myf['__set_default_parameters'](a)
00189         elif(param == 'paramkeys'):
00190                 return a.keys()
00191         else:
00192                 if(a.has_key(param)):
00193                    #if(type(a[param]) == dict) :
00194                    #   return a[param][len(a[param])-1]['value']
00195                    #else :
00196                       return a[param]
00197 
00198 
00199 #
00200 #
00201     def check_params(self, param=None, value=None):
00202       a=inspect.stack() 
00203       stacklevel=0
00204       for k in range(len(a)):
00205         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00206             stacklevel=k
00207             break
00208       myf=sys._getframe(stacklevel).f_globals
00209 
00210 #      print 'param:', param, 'value:', value
00211       try :
00212          if str(type(value)) != "<type 'instance'>" :
00213             value0 = value
00214             value = myf['cu'].expandparam(param, value)
00215             matchtype = False
00216             if(type(value) == numpy.ndarray):
00217                if(type(value) == type(value0)):
00218                   myf[param] = value.tolist()
00219                else:
00220                   #print 'value:', value, 'value0:', value0
00221                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00222                   myf[param] = value0
00223                   if type(value0) != list :
00224                      matchtype = True
00225             else :
00226                myf[param] = value
00227             value = myf['cu'].verifyparam({param:value})
00228             if matchtype:
00229                value = False
00230       except Exception, instance:
00231          #ignore the exception and just return it unchecked
00232          myf[param] = value
00233       return value
00234 
00235 #
00236 #
00237     def description(self, key='plotweather', subkey=None):
00238         desc={'plotweather': 'Plot elements of the weather table; estimate opacity.',
00239                'vis': 'MS name',
00240                'seasonal_weight': 'weight of the seasonal model',
00241                'doPlot': 'set this to True to create a plot',
00242                'plotName': '(Optional) the name of the plot file',
00243 
00244                'async': 'If true the taskname must be started using plotweather(...)'
00245               }
00246 
00247         if(desc.has_key(key)) :
00248            return desc[key]
00249 
00250     def itsdefault(self, paramname) :
00251         a = {}
00252         a['vis']  = ''
00253         a['seasonal_weight']  = 0.5
00254         a['doPlot']  = True
00255         a['plotName']  = ''
00256 
00257         if a.has_key(paramname) :
00258               return a[paramname]
00259 plotweather_pg = plotweather_pg_()