casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
predictcomp_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_predictcomp import predictcomp
00016 from task_predictcomp import casalog
00017 
00018 class predictcomp_pg_:
00019     __name__ = "predictcomp"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (predictcomp_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, objname=None, standard=None, epoch=None, minfreq=None, maxfreq=None, nfreqs=None, prefix=None, antennalist=None, showplot=None, savefig=None, symb=None, include0amp=None, include0bl=None, blunit=None, showbl0flux=None, async=None):
00027 
00028         """Make a component list for a known calibrator
00029 
00030     Writes a component list to disk and returns a dict of
00031     {'clist': filename of the component list,
00032      'objname': objname,
00033      'angdiam': angular diameter in radians (if used in clist),
00034      'standard': standard,
00035      'epoch': epoch,
00036      'freqs': pl.array of frequencies, in GHz,
00037      'antennalist': pl.array of baseline lengths, in m,
00038      'amps':  pl.array of predicted visibility amplitudes, in Jy,
00039      'savedfig': False or, if made, the filename of a plot.}
00040     or False on error.
00041 
00042     objname: An object supported by standard.
00043     standard: A standard for calculating flux densities, as in setjy.
00044               Default: 'Butler-JPL-Horizons 2010'
00045     epoch: The epoch to use for the calculations.   Irrelevant for
00046            extrasolar standards. (Uses UTC)
00047            Examples: '2011-12-31/5:34:12', '2011-12-31-5:34:12'
00048     minfreq: The minimum frequency to use.
00049              Example: '342.0GHz'
00050     maxfreq: The maximum frequency to use.
00051              Default: minfreq
00052              Example: '346.0GHz'
00053              Example: '', anything <= 0, or None: use minfreq.
00054     nfreqs:  The number of frequencies to use.
00055              Default: 1 if minfreq == maxfreq,
00056                       2 otherwise.
00057     prefix: The component list will be saved to
00058                prefix + 'spw0_<objname>_<minfreq><epoch>.cl'
00059             Default: '' 
00060             Example: "Bands3to7_"
00061                      (which could produce 'Bands3to7_spw0_Uranus_100GHz55877d.cl',
00062                       depending on the other parameters)
00063     antennalist: 'Observe' and plot the visibility amplitudes for this
00064                  antenna configuration.  The file should be in a format usable
00065                  by simdata.  The search path is:
00066                      .:casa['dirs']['data'] + '/alma/simmos/'
00067              Default: '' (None, just make clist.)
00068              Example: 'alma.cycle0.extended.cfg'
00069 
00070     Subparameters of antennalist:
00071     showplot: Whether or not to show a plot of S vs. |u| on screen.
00072               Subparameter of antennalist.
00073               Default: Necessarily False if antennalist is not specified.
00074                        True otherwise.
00075     savefig: Filename for saving a plot of S vs. |u|.
00076              Subparameter of antennalist.
00077              Default: False (necessarily if antennalist is not specified)
00078              Examples: ''           (do not save the plot)
00079                        'myplot.png' (save to myplot.png)
00080     symb: One of matplotlib's codes for plot symbols: .:,o^v<>s+xDd234hH|_
00081           Default: ',':  The smallest points I could find.
00082     include0amp: Force the amplitude axis to start at 0?
00083                  Default: False
00084     include0bl: Force the baseline axis to start at 0?
00085                 Default: False
00086     blunit: unit of the baseline axis ('' or 'klambda')
00087             Default:''=use a unit in the data
00088     showbl0flux: Print the zero baseline flux? 
00089                  Default: False 
00090 
00091      
00092 
00093         """
00094         a=inspect.stack()
00095         stacklevel=0
00096         for k in range(len(a)):
00097           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00098                 stacklevel=k
00099                 break
00100         myf=sys._getframe(stacklevel).f_globals
00101         myf['__last_task'] = 'predictcomp'
00102         myf['taskname'] = 'predictcomp'
00103         ###
00104         myf['update_params'](func=myf['taskname'],printtext=False)
00105         ###
00106         ###
00107         #Handle globals or user over-ride of arguments
00108         #
00109         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00110         useLocalDefaults = False
00111 
00112         for item in function_signature_defaults.iteritems():
00113                 key,val = item
00114                 keyVal = eval(key)
00115                 if (keyVal == None):
00116                         #user hasn't set it - use global/default
00117                         pass
00118                 else:
00119                         #user has set it - use over-ride
00120                         if (key != 'self') :
00121                            useLocalDefaults = True
00122                         #myf[key]=keyVal
00123 
00124         myparams = {}
00125         if useLocalDefaults :
00126            for item in function_signature_defaults.iteritems():
00127                key,val = item
00128                keyVal = eval(key)
00129                exec('myparams[key] = keyVal')
00130                if (keyVal == None):
00131                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00132                    keyVal = eval(key)
00133                    if(type(keyVal) == dict) :
00134                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00135 
00136         else :
00137             uselessvariable = None 
00138             myparams['objname'] = objname = myf['objname']
00139             myparams['standard'] = standard = myf['standard']
00140             myparams['epoch'] = epoch = myf['epoch']
00141             myparams['minfreq'] = minfreq = myf['minfreq']
00142             myparams['maxfreq'] = maxfreq = myf['maxfreq']
00143             myparams['nfreqs'] = nfreqs = myf['nfreqs']
00144             myparams['prefix'] = prefix = myf['prefix']
00145             myparams['antennalist'] = antennalist = myf['antennalist']
00146             myparams['showplot'] = showplot = myf['showplot']
00147             myparams['savefig'] = savefig = myf['savefig']
00148             myparams['symb'] = symb = myf['symb']
00149             myparams['include0amp'] = include0amp = myf['include0amp']
00150             myparams['include0bl'] = include0bl = myf['include0bl']
00151             myparams['blunit'] = blunit = myf['blunit']
00152             myparams['showbl0flux'] = showbl0flux = myf['showbl0flux']
00153 
00154 
00155         result = None
00156 
00157 #
00158 #    The following is work around to avoid a bug with current python translation
00159 #
00160         mytmp = {}
00161 
00162         mytmp['objname'] = objname
00163         mytmp['standard'] = standard
00164         mytmp['epoch'] = epoch
00165         mytmp['minfreq'] = minfreq
00166         mytmp['maxfreq'] = maxfreq
00167         mytmp['nfreqs'] = nfreqs
00168         mytmp['prefix'] = prefix
00169         mytmp['antennalist'] = antennalist
00170         mytmp['showplot'] = showplot
00171         mytmp['savefig'] = savefig
00172         mytmp['symb'] = symb
00173         mytmp['include0amp'] = include0amp
00174         mytmp['include0bl'] = include0bl
00175         mytmp['blunit'] = blunit
00176         mytmp['showbl0flux'] = showbl0flux
00177         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00178         trec = casac.utils().torecord(pathname+'predictcomp.xml')
00179 
00180         casalog.origin('predictcomp')
00181         if not trec.has_key('predictcomp') or not casac.utils().verify(mytmp, trec['predictcomp']) :
00182             return False
00183 
00184 
00185         try :
00186           casalog.post('')
00187           casalog.post('##########################################')
00188           casalog.post('##### Begin Task: predictcomp           #####')
00189           casalog.post('')
00190           result = predictcomp(objname, standard, epoch, minfreq, maxfreq, nfreqs, prefix, antennalist, showplot, savefig, symb, include0amp, include0bl, blunit, showbl0flux)
00191           casalog.post('')
00192           casalog.post('##### End Task: predictcomp           #####')
00193           casalog.post('##########################################')
00194 
00195 
00196 # saveinputs for individule engine has no use
00197 # saveinputs should alos be removed from casa_in_py.py
00198 #
00199 #
00200 #          saveinputs = myf['saveinputs']
00201 #          saveinputs('predictcomp', 'predictcomp.last', myparams)
00202 #
00203 #
00204         except Exception, instance:
00205           #print '**** Error **** ',instance
00206           pass
00207 
00208         gc.collect()
00209         return result
00210 #
00211 #
00212 ##
00213 #    def paramgui(self, useGlobals=True):
00214 #        """
00215 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00216 #        """
00217 #        import paramgui
00218 #
00219 #        a=inspect.stack()
00220 #        stacklevel=0
00221 #        for k in range(len(a)):
00222 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00223 #            stacklevel=k
00224 #            break
00225 #        myf = sys._getframe(stacklevel).f_globals
00226 #
00227 #        if useGlobals:
00228 #            paramgui.setGlobals(myf)
00229 #        else:
00230 #            paramgui.setGlobals({})
00231 #
00232 #        paramgui.runTask('predictcomp', myf['_ip'])
00233 #        paramgui.setGlobals({})
00234 #
00235 #
00236 #
00237 #
00238     def defaults(self, param=None):
00239         a=inspect.stack()
00240         stacklevel=0
00241         for k in range(len(a)):
00242           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00243                 stacklevel=k
00244                 break
00245         myf=sys._getframe(stacklevel).f_globals
00246         a = odict()
00247         a['objname']  = ''
00248         a['standard']  = 'Butler-JPL-Horizons 2010'
00249         a['epoch']  = ''
00250         a['minfreq']  = ''
00251         a['maxfreq']  = ''
00252         a['nfreqs']  = 2
00253         a['prefix']  = ''
00254         a['antennalist']  = ''
00255         a['symb']  = ','
00256 
00257         a['async']=False
00258         a['antennalist'] = {
00259                     0:odict([{'notvalue':''}, {'showplot':True}, {'savefig':''}, {'symb':','}, {'include0amp':False}, {'include0bl':False}, {'blunit':''}, {'showbl0flux':False}])}
00260 
00261 ### This function sets the default values but also will return the list of
00262 ### parameters or the default value of a given parameter
00263         if(param == None):
00264                 myf['__set_default_parameters'](a)
00265         elif(param == 'paramkeys'):
00266                 return a.keys()
00267         else:
00268                 if(a.has_key(param)):
00269                    #if(type(a[param]) == dict) :
00270                    #   return a[param][len(a[param])-1]['value']
00271                    #else :
00272                       return a[param]
00273 
00274 
00275 #
00276 #
00277     def check_params(self, param=None, value=None):
00278       a=inspect.stack() 
00279       stacklevel=0
00280       for k in range(len(a)):
00281         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00282             stacklevel=k
00283             break
00284       myf=sys._getframe(stacklevel).f_globals
00285 
00286 #      print 'param:', param, 'value:', value
00287       try :
00288          if str(type(value)) != "<type 'instance'>" :
00289             value0 = value
00290             value = myf['cu'].expandparam(param, value)
00291             matchtype = False
00292             if(type(value) == numpy.ndarray):
00293                if(type(value) == type(value0)):
00294                   myf[param] = value.tolist()
00295                else:
00296                   #print 'value:', value, 'value0:', value0
00297                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00298                   myf[param] = value0
00299                   if type(value0) != list :
00300                      matchtype = True
00301             else :
00302                myf[param] = value
00303             value = myf['cu'].verifyparam({param:value})
00304             if matchtype:
00305                value = False
00306       except Exception, instance:
00307          #ignore the exception and just return it unchecked
00308          myf[param] = value
00309       return value
00310 
00311 #
00312 #
00313     def description(self, key='predictcomp', subkey=None):
00314         desc={'predictcomp': 'Make a component list for a known calibrator',
00315                'objname': 'Object name',
00316                'standard': 'Flux density standard',
00317                'epoch': 'Epoch',
00318                'minfreq': 'Minimum frequency',
00319                'maxfreq': 'Maximum frequency',
00320                'nfreqs': 'Number of frequencies',
00321                'prefix': 'Prefix for the component list directory name.',
00322                'antennalist': 'Plot for this configuration',
00323                'showplot': 'Plot S vs |u| to the screen?',
00324                'savefig': 'Save a plot of S vs |u| to this filename',
00325                'symb': 'A matplotlib plot symbol code',
00326                'include0amp': 'Force the amplitude axis to start at 0?',
00327                'include0bl': 'Force the baseline axis to start at 0?',
00328                'blunit': 'unit of the baseline axis',
00329                'showbl0flux': 'Print the zero baseline flux ?',
00330 
00331                'async': 'If true the taskname must be started using predictcomp(...)'
00332               }
00333 
00334 #
00335 # Set subfields defaults if needed
00336 #
00337 
00338         if(desc.has_key(key)) :
00339            return desc[key]
00340 
00341     def itsdefault(self, paramname) :
00342         a = {}
00343         a['objname']  = ''
00344         a['standard']  = 'Butler-JPL-Horizons 2010'
00345         a['epoch']  = ''
00346         a['minfreq']  = ''
00347         a['maxfreq']  = ''
00348         a['nfreqs']  = 2
00349         a['prefix']  = ''
00350         a['antennalist']  = ''
00351         a['showplot']  = False
00352         a['savefig']  = ''
00353         a['symb']  = ','
00354         a['include0amp']  = False
00355         a['include0bl']  = False
00356         a['blunit']  = ''
00357         a['showbl0flux']  = False
00358 
00359         if a.has_key(paramname) :
00360               return a[paramname]
00361 predictcomp_pg = predictcomp_pg_()