casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
setjy_cli.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 casac
00010 import string
00011 import time
00012 import inspect
00013 import gc
00014 import numpy
00015 from odict import odict
00016 from taskmanager import tm
00017 from task_setjy import setjy
00018 class setjy_cli_:
00019     __name__ = "setjy"
00020     __async__ = {}
00021     rkey = None
00022     i_am_a_casapy_task = None
00023     # The existence of the i_am_a_casapy_task attribute allows help()
00024     # (and other) to treat casapy tasks as a special case.
00025 
00026     def __init__(self) :
00027        self.__bases__ = (setjy_cli_,)
00028        self.__doc__ = self.__call__.__doc__
00029 
00030        self.parameters={'vis':None, 'field':None, 'spw':None, 'selectdata':None, 'timerange':None, 'scan':None, 'observation':None, 'modimage':None, 'listmodels':None, 'scalebychan':None, 'fluxdensity':None, 'spix':None, 'reffreq':None, 'standard':None, 'useephemdir':None, 'usescratch':None,  'async':None}
00031 
00032 
00033     def result(self, key=None):
00034             #### here we will scan the task-ids in __async__
00035             #### and add any that have completed...
00036             if key is not None and self.__async__.has_key(key) and self.__async__[key] is not None:
00037                ret = tm.retrieve(self.__async__[key])
00038                if ret['state'] == "done" :
00039                   self.__async__[key] = None
00040                elif ret['state'] == 'crashed' :
00041                   self.__async__[key] = None
00042                return ret
00043             return None
00044 
00045 
00046     def __call__(self, vis=None, field=None, spw=None, selectdata=None, timerange=None, scan=None, observation=None, modimage=None, listmodels=None, scalebychan=None, fluxdensity=None, spix=None, reffreq=None, standard=None, useephemdir=None, usescratch=None,  async=None):
00047 
00048         """Fills the model column with the visibilities of a calibrator
00049 
00050     The task sets the model visibility amp and phase of a specified source
00051     (generally a calibrator).  The simplest way is to enter the flux density
00052     (I,Q,U,V) explicitly, but this is valid only for a point source.
00053 
00054     For an extended source, the clean model (image.model) can be
00055     specified and the model visibilities associated with this clean
00056     model is placed in the visibility model column.
00057 
00058     Models are available for 3C48, 3C138, 3C286 between 1.4 and 43 GHz.
00059     3C147 is available above 4 GHz.  These models are scaled to the precise
00060     frequency of the data.  Only I models are presently available.
00061 
00062     The location of the models is system dependent: At the AOC and CV, the
00063     models are in the directory::/usr/lib/casapy/data/nrao/VLA/CalModels or
00064     /usr/lib64/casapy/data/nrao/VLA/CalModels (depending on whether 32 or 64
00065     bit CASA was installed on the machine being used).  In general (using
00066     Python), the stock models should be in
00067     casa['dirs']['data'] + '/nrao/VLA/CalModels'
00068     setjy also looks for models in the current directory before trying
00069     casa['dirs']['data'] + '/nrao/VLA/CalModels'.
00070 
00071     setjy need only be run on the calibrator sources with a known flux
00072     density and/or model.
00073 
00074     
00075     Solar System Objects are supported via the 'Butler-JPL-Horizons 2012' 
00076     standard. This uses new brightness temperature models and a new flux
00077     calculation code that replace the 'Butler-JPL-Horizons 2010' standard.
00078     The older 'Butler-JPL-Horizons 2010' standard is still available
00079     for comparison. Users may want to use predictcomp task to see the differeces. 
00080     Currently they are modeled as uniform temperature disks based
00081     on their ephemerides at the time of observation (note that this may
00082     oversimply objects, in particular asteroids).  The object name is
00083     obtained from the 'field' parameter. Recognized objects are listed
00084     below, under 'standard'.
00085 
00086     Note that fluxdensity, modimage, and standard interact in a possibly
00087     confusing way!  Generally, if fluxdensity[0] (Stokes I) is <= 0, it
00088     will be ignored.  If it is < 0, standard (which has a default) will
00089     be used to calculate flux density as a function of frequency, even if
00090     modimage is specified.  If is is exactly 0 and modimage is given, the
00091     brightness of the model image will be used as is.  If fluxdensity([0])
00092     is > 0, it will be used.  The latter two options come at the price of
00093     disabling frequency scaling, i.e. the same fluxdensity will be used for
00094     all frequencies.
00095 
00096     Keyword arguments:
00097     vis -- Name of input visibility file
00098             default: none.  example: vis='ngc5921.ms'
00099     field -- Select field using field id(s) or field name(s).
00100            default: ''=all fields, but run setjy one field at a time.
00101               [run listobs to obtain the list id's or names of calibrators]
00102            If field is a non-negative integer, it is assumed to be a field
00103            index.  Otherwise, it is taken to be a field name (case sensitive
00104            - it must match the name as listed by listobs).
00105            field='0~2'; field ids 0,1,2
00106            field='0,4,5~7'; field ids 0,4,5,6,7
00107            field='3C286,3C295'; field named 3C286 and 3C295
00108            field = '3,4C*'; field id 3, all names starting with 4C
00109     spw -- Spectral window selection string.
00110            default: '' = all spectral windows
00111            Note that setjy only selects by spectral window, and ignores
00112            channel selections.  Fine-grained control could be achieved using
00113            (and possibly constructing) a cube for modimage.
00114 
00115     selectdata -- Other parameters for selecting part(s) of the MS
00116                   to operate on.
00117                   (Currently all time-oriented and most likely only of
00118                    interest when using a Solar System object as a calibrator.)
00119                   default: False
00120 
00121   >>> selectdata=True expandable parameters
00122                See help par.selectdata for more on these.
00123 
00124                timerange  -- Select data based on time range:
00125                    default: '' (all); examples,
00126                    timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00127                    Note: if YYYY/MM/DD is missing date defaults to first 
00128                          day in data set
00129                    timerange='09:14:0~09:54:0' picks 40 min on first day
00130                    timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 
00131                              30min on NEXT day
00132                    timerange='09:44:00' pick data within one integration 
00133                              of time
00134                    timerange='>10:24:00' data after this time
00135                    For multiple MS input, a list of timerange strings can be
00136                    used:
00137                    timerange=['09:14:0~09:54:0','>10:24:00']
00138                    timerange='09:14:0~09:54:0''; apply the same timerange for
00139                                                  all input MSes
00140                scan -- Scan number range.
00141                    default: '' (all)
00142                    example: scan='1~5'
00143                    For multiple MS input, a list of scan strings can be used:
00144                    scan=['0~100','10~200']
00145                    scan='0~100; scan ids 0-100 for all input MSes
00146                    Check 'go listobs' to insure the scan numbers are in order.
00147                observation -- Observation ID range.
00148                    default: '' (all)
00149                    example: observation='1~5'
00150 
00151 
00152     modimage -- Model image (I only) for setting the model visibilities.
00153            modimage can be a cube, and its channels do not have to exactly
00154            match those of vis.  It is recommended to use modimage for
00155            sources that are resolved by the observation, but the
00156            Butler-JPL-Horizons standard supplies a basic model of what
00157            several Solar System objects look like.  default: '': do not use
00158            a model image.
00159     
00160            Each field must be done separately when using a model image.  The
00161            flux density of the image will be scaled from the frequency in
00162            the model to that actually used (ignoring fluxdensity), unless
00163            fluxdensity >= 0 (or fluxdensity[0] >= 0).  If
00164            fluxdensity([0]) is 0.0, the image's flux density will be used.
00165            If fluxdensity([0]) > 0.0, it will be used (and spix and
00166            reffreq if modimage is not a cube).  Since the spectral index
00167            usually varies with direction, applying a single spectral index
00168            to a 2D modimage is typically not as good as using a cube.
00169 
00170            Both the amplitude and phase are calculated.  At the AOC or CV,
00171            the models are located in casa['dirs']['data']
00172            + '/nrao/VLA/CalModels/', e.g.
00173            /usr/lib/casapy/data/nrao/VLA/CalModels/3C286_L.im
00174                 lib64
00175 
00176            If modimage does not start with '/', setjy will look for a match
00177            in '.', './CalModels', and any CalModels directories within
00178            the casa['dirs']['data'] tree (excluding certain branches).
00179 
00180            Note that modimage should be deconvolved, i.e. a set of clean
00181            components instead of an image that has been convolved with a
00182            clean beam.
00183 
00184     listmodels -- If True, do nothing but list candidates for modimage
00185            (for extragalactic calibrators) that are present on the system.  It looks for *.im* *.mod* in .,
00186            CalModels, and CalModels directories in the casa['dirs']['data']
00187            tree.  It does not check whether they are appropriate for the MS!
00188            If standard='Butler-JPL-Horizons 2012', Tb models (frequency-depended
00189            brightness temperature models) for Solar System objects used in the 
00190            standard.  For standard='Butler-JPL-Horizons 2010', the recognized
00191            Solar System objects are listed. 
00192 
00193     scalebychan -- This determines whether the fluxdensity set in the model is
00194             calculated on a per channel basis. If False then it only one
00195             fluxdensity value is calculated per spw.  (Either way, all channels
00196             in spw are modified.)  It is effectively True if fluxdensity[0] >
00197             0.0. 
00198             default: True
00199 
00200     fluxdensity -- Specified flux density [I,Q,U,V] in Jy
00201             default: -1, uses [1,0,0,0] flux density for unrecognized sources,
00202             and standard flux densities for ones recognized by 'standard',
00203             including 3C286, 3C48, 3C147, and several planets, moons, and
00204             asteroids.  setjy will try to use standard if fluxdensity is not
00205             positive.
00206 
00207             Only one flux density can be specified at a time.  The phases are
00208                set to zero.
00209             example   fluxdensity=-1  will use standard for recognized
00210                       calibrators (like 3C286, 3C147 and 3C48, depending on
00211                       standard) and insert 1.0 for selected fields with
00212                       unrecognized sources.
00213             example   field = '1'; fluxdensity=[3.2,0,0,0] wil put in 
00214                       a flux density of I=3.2 for field='1'
00215 
00216             At present (June 2000), this is the only method to insert a
00217             polarized flux density model.
00218             example:  fluxdensity=[2.63,0.21,-0.33,0.02]
00219                       will put in I,Q,U,V flux densities of 2.63,0.21,-0.33,
00220                       and 0.02, respectively, in the model column.
00221 
00222     spix -- Spectral index for fluxdensity:
00223                  S = fluxdensity * (freq/reffreq)**spix
00224             Default: 0 (no effect)
00225             Only used if fluxdensity is being used.
00226             N.B.: If fluxdensity is positive, and spix is nonzero, then reffreq
00227                   must be set too!  (See below)
00228 
00229                   It is applied in the same way to all polarizations, and does
00230                   not account for Faraday rotation or depolarization.
00231 
00232     reffreq -- The reference frequency for spix, given with units.
00233             Default: '1GHz'; this is only here to prevent division by 0!
00234             N.B.: If the flux density is being scaled by spectral index,
00235             then reffreq must be set to whatever reference frequency is
00236             correct for the given fluxdensity and spix.  It cannot be
00237             determined from vis.  On the other hand, if spix is 0, then any
00238             positive frequency can be used (and ignored).
00239 
00240             Examples: '86.0GHz', '4.65e9Hz'
00241 
00242     standard -- Flux density standard, used if fluxdensity[0] < 0.0
00243             default: 'Perley-Butler 2010'; example: standard='Baars'
00244             Options: 'Baars','Perley 90','Perley-Taylor 95',
00245                'Perley-Taylor 99', 'Perley-Butler 2010', 'Perley-Butler 2013',
00246                'Butler-JPL-Horizons 2010', and 'Butler-JPL-Horizons 2012'. 
00247             All but the last two are for extragalactic calibrators,
00248             and the final two are for Solar System objects.  
00249 
00250             Extragalactic calibrators:
00251             Following source names and their common aliases are recognized.
00252             The last column shows which standards support for each source.
00253             Note that the task does not do exact matching of the name and
00254             it recognizes as long as the field name  contains the string 
00255             listed below (e.g. 'PKS 1934-638' works). 
00256             -----------------------------------------------------------
00257             3C Name B1950 Name J2000 Name Alt. J2000 Name  standards*
00258             3C48    0134+329   0137+331   J0137+3309       1,3,4,5,6
00259             3C123   0433+295   0437+296   J0437+2940       2 
00260             3C138   0518+165   0521+166   J0521+1638       1,3,4,5,6
00261             3C147   0538+498   0542+498   J0542+4951       1,3,4,5,6
00262             3C196   0809+483   0813+482   J0813+4813       1,2 
00263             3C286   1328+307   1331+305   J1331+3030       1,2,3,4,5,6
00264             3C295   1409+524   1411+522   J1411+5212       1,2,3,4,5,6
00265               -     1934-638      -       J1939-6342       1,3,4,5,6
00266             ----------------------------------------------------------- 
00267             * supported in: 1 - Perley-Butler 2010, 2 - Perley-Butler 2013,
00268             3 - Perley-Taylor 99, 4 - Perley-Taylor 95, 5 - Perley 90, 6 - Baars 
00269 
00270             Solar system objects:
00271             The 'Butler-JPL-Horizons 2012' standard is recommended over 
00272             'Butler-JPL-Horizons 2010' as the former uses updated models.
00273             Recognized Solar System objects (for 'Butler-JPL-Horizons 2012') are: 
00274              
00275                
00276                Planets: Venus, Mars, Jupiter, Uranus, Neptune
00277                
00278                Moons: Jupiter: Io, Europa, Ganymede, Callisto
00279                    Saturn:  Titan 
00280 
00281                Asteroids: Ceres, Pallas**, Vesta**, Juno**
00282 
00283             * Venus: model for ~300MHz to 350GHz, no atmospheric lines (CO,H2O,HDO, etc)
00284             * Mars: tabulated as a function of time and frequency (30 - 1000GHz) based on 
00285                Rudy el tal (1988), no atmopheric lines (CO, H20, H2O2, HDO, etc)
00286             * Jupiter: model for 30-1020GHz, does not include synchrotron emission
00287             * Uranus: model for 60-1800GHz, contains no rings or synchrotron.
00288             * Neptune: model for 2-2000GHz, the broad CO absorption line
00289                is included, but contains no rings or syncrotron. 
00290             * Titan: model for 53.3-1024.1GHz, include many spectral lines
00291 
00292             **  not recommended (The temperature is not yet adjusted for
00293                 varying distance from the Sun.  The model data can be scaled
00294                 after running setjy, but it is an involved process.)
00295 
00296                The 'field' parameter must match the case of the field name(s)
00297                in vis (as shown by listobs).
00298 
00299             Flux density calculation with Solar System objects depends on
00300             ephemerides. The setjy task looks for the data in  
00301             
00302             os.getenv('CASAPATH').split()[0] + '/data/ephemerides/JPL-Horizons'.
00303 
00304             If no ephemeris for the right object at the right time is
00305             present, the calculation will fail.  Ask the helpdesk to make an
00306             ephemeris.  The very adventurous and well versed in python can
00307             try it using CASA's recipes.ephemerides package:
00308                  import recipes.ephemerides as eph
00309                  help eph
00310 
00311             CASA comes with ephemerides for several more objects, but they
00312             are intended for use with me.framecomet(), and are not (yet)
00313             suitable flux density calibrators.  It is up to the observer to
00314             pick a good flux density calibrator (bright, spherical and
00315             featureless, on a circular orbit, in the right part of the sky,
00316             and not too resolved).  Even some of the objects listed above
00317             may prove to require more sophisticated flux density models than
00318             are currently implemented in CASA.  For many objects running
00319             casalog.filter('INFO1') before running setjy will send more
00320             information to the logger.  The cookbook also has an appendix
00321             with descriptions of the models used by setjy (both
00322             extragalactic and Solar System).
00323 
00324        >>> standard="Butler-JPL-Horizons 2012" expandable parameter
00325 
00326             useephemdir -- If True: use the direction from the ephemeris table for 
00327                 the solar system object. 
00328                 default: False -use the direction information in the MS(i.e. Field table) 
00329 
00330         usescratch  -- If False: 'virtual' model is created. The model is saved in the header 
00331         and model visibilities are evaluated when calculating calibration or plotting in plotms.
00332         If True: the model visibility will be evaluated and saved on disk in the MODEL_DATA 
00333         column.  This will increase your ms in size by a factor of 1.5 (w.r.t. the case where 
00334         you only have the DATA and the CORRECTED_DATA column).  Use True if you need to interact 
00335         with the MODEL_DATA in python, say.
00336 
00337         *By running usescratch=T, it will remove the existing virtual model from previous runs.
00338         usescratch=F will not remove the existing MODEL_DATA but in subsequent process
00339         the virtual model with matching field and spw combination will be used if it exists
00340         regardless of the presence of the MODEL_DATA column.
00341          
00342         default: False        
00343             
00344 
00345         """
00346         if not hasattr(self, "__globals__") or self.__globals__ == None :
00347            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00348         #casac = self.__globals__['casac']
00349         casalog = self.__globals__['casalog']
00350         #casalog = casac.casac.logsink()
00351         self.__globals__['__last_task'] = 'setjy'
00352         self.__globals__['taskname'] = 'setjy'
00353         ###
00354         self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__)
00355         ###
00356         ###
00357         #Handle globals or user over-ride of arguments
00358         #
00359         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00360         useLocalDefaults = False
00361 
00362         for item in function_signature_defaults.iteritems():
00363                 key,val = item
00364                 keyVal = eval(key)
00365                 if (keyVal == None):
00366                         #user hasn't set it - use global/default
00367                         pass
00368                 else:
00369                         #user has set it - use over-ride
00370                         if (key != 'self') :
00371                            useLocalDefaults = True
00372 
00373         myparams = {}
00374         if useLocalDefaults :
00375            for item in function_signature_defaults.iteritems():
00376                key,val = item
00377                keyVal = eval(key)
00378                exec('myparams[key] = keyVal')
00379                self.parameters[key] = keyVal
00380                if (keyVal == None):
00381                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00382                    keyVal = eval(key)
00383                    if(type(keyVal) == dict) :
00384                       if len(keyVal) > 0 :
00385                          exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00386                       else :
00387                          exec('myparams[key] = ' + key + ' = {}')
00388 
00389         else :
00390             async = self.parameters['async']
00391             myparams['vis'] = vis = self.parameters['vis']
00392             myparams['field'] = field = self.parameters['field']
00393             myparams['spw'] = spw = self.parameters['spw']
00394             myparams['selectdata'] = selectdata = self.parameters['selectdata']
00395             myparams['timerange'] = timerange = self.parameters['timerange']
00396             myparams['scan'] = scan = self.parameters['scan']
00397             myparams['observation'] = observation = self.parameters['observation']
00398             myparams['modimage'] = modimage = self.parameters['modimage']
00399             myparams['listmodels'] = listmodels = self.parameters['listmodels']
00400             myparams['scalebychan'] = scalebychan = self.parameters['scalebychan']
00401             myparams['fluxdensity'] = fluxdensity = self.parameters['fluxdensity']
00402             myparams['spix'] = spix = self.parameters['spix']
00403             myparams['reffreq'] = reffreq = self.parameters['reffreq']
00404             myparams['standard'] = standard = self.parameters['standard']
00405             myparams['useephemdir'] = useephemdir = self.parameters['useephemdir']
00406             myparams['usescratch'] = usescratch = self.parameters['usescratch']
00407 
00408 
00409         result = None
00410 
00411 #
00412 #    The following is work around to avoid a bug with current python translation
00413 #
00414         mytmp = {}
00415 
00416         mytmp['vis'] = vis
00417         mytmp['field'] = field
00418         mytmp['spw'] = spw
00419         mytmp['selectdata'] = selectdata
00420         mytmp['timerange'] = timerange
00421         mytmp['scan'] = scan
00422         mytmp['observation'] = observation
00423         mytmp['modimage'] = modimage
00424         mytmp['listmodels'] = listmodels
00425         mytmp['scalebychan'] = scalebychan
00426         mytmp['fluxdensity'] = fluxdensity
00427         mytmp['spix'] = spix
00428         mytmp['reffreq'] = reffreq
00429         mytmp['standard'] = standard
00430         mytmp['useephemdir'] = useephemdir
00431         mytmp['usescratch'] = usescratch
00432         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00433         trec = casac.casac.utils().torecord(pathname+'setjy.xml')
00434 
00435         casalog.origin('setjy')
00436         try :
00437           #if not trec.has_key('setjy') or not casac.casac.utils().verify(mytmp, trec['setjy']) :
00438             #return False
00439 
00440           casac.casac.utils().verify(mytmp, trec['setjy'], True)
00441           scriptstr=['']
00442           saveinputs = self.__globals__['saveinputs']
00443           saveinputs('setjy', 'setjy.last', myparams, self.__globals__,scriptstr=scriptstr)
00444           if async :
00445             count = 0
00446             keybase =  time.strftime("%y%m%d.%H%M%S")
00447             key = keybase + "_" + str(count)
00448             while self.__async__.has_key(key) :
00449                count += 1
00450                key = keybase + "_" + str(count)
00451             result = tm.execute('setjy', vis, field, spw, selectdata, timerange, scan, observation, modimage, listmodels, scalebychan, fluxdensity, spix, reffreq, standard, useephemdir, usescratch)
00452             print "Use: "
00453             print "      tm.retrieve(return_value) # to retrieve the status"
00454             print 
00455             self.rkey = key
00456             self.__async__[key] = result
00457           else :
00458               tname = 'setjy'
00459               spaces = ' '*(18-len(tname))
00460               casalog.post('\n##########################################'+
00461                            '\n##### Begin Task: ' + tname + spaces + ' #####')
00462               casalog.post(scriptstr[1][1:]+'\n', 'INFO')
00463               result = setjy(vis, field, spw, selectdata, timerange, scan, observation, modimage, listmodels, scalebychan, fluxdensity, spix, reffreq, standard, useephemdir, usescratch)
00464               casalog.post('##### End Task: ' + tname + '  ' + spaces + ' #####'+
00465                            '\n##########################################')
00466 
00467         except Exception, instance:
00468           if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) :
00469              raise
00470           else :
00471              #print '**** Error **** ',instance
00472              tname = 'setjy'
00473              casalog.post('An error occurred running task '+tname+'.', 'ERROR')
00474              pass
00475 
00476         gc.collect()
00477         return result
00478 #
00479 #
00480 #
00481     def paramgui(self, useGlobals=True, ipython_globals=None):
00482         """
00483         Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00484         """
00485         import paramgui
00486         if not hasattr(self, "__globals__") or self.__globals__ == None :
00487            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00488 
00489         if useGlobals:
00490             if ipython_globals == None:
00491                 myf=self.__globals__
00492             else:
00493                 myf=ipython_globals
00494 
00495             paramgui.setGlobals(myf)
00496         else:
00497             paramgui.setGlobals({})
00498 
00499         paramgui.runTask('setjy', myf['_ip'])
00500         paramgui.setGlobals({})
00501 
00502 #
00503 #
00504 #
00505     def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None):
00506         if not hasattr(self, "__globals__") or self.__globals__ == None :
00507            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00508         if ipython_globals == None:
00509             myf=self.__globals__
00510         else:
00511             myf=ipython_globals
00512 
00513         a = odict()
00514         a['vis']  = ''
00515         a['field']  = ''
00516         a['spw']  = ''
00517         a['selectdata']  = False
00518         a['modimage']  = ''
00519         a['listmodels']  = False
00520         a['scalebychan']  = True
00521         a['fluxdensity']  = -1
00522         a['standard']  = 'Perley-Butler 2010'
00523         a['usescratch']  = False
00524 
00525         a['async']=False
00526         a['selectdata'] = {
00527                     0:{'value':False}, 
00528                     1:odict([{'value':True}, {'timerange':''}, {'scan':''}, {'observation':''}])}
00529         a['fluxdensity'] = {
00530                     0:odict([{'notvalue':-1}, {'spix':0}, {'reffreq':'1GHz'}])}
00531         a['standard'] = {
00532                     0:{'value':'Perley-Butler 2010'}, 
00533                     1:{'value':'Perley-Butler 2013'}, 
00534                     2:{'value':'Perley-Taylor 99'}, 
00535                     3:{'value':'Baars'}, 
00536                     4:{'value':'Perley 90'}, 
00537                     5:{'value':'Perley-Taylor 95'}, 
00538                     6:odict([{'value':'Butler-JPL-Horizons 2012'}, {'useephemdir':False}]), 
00539                     7:{'value':'Butler-JPL-Horizons 2010'}}
00540 
00541 ### This function sets the default values but also will return the list of
00542 ### parameters or the default value of a given parameter
00543         if(param == None):
00544                 myf['__set_default_parameters'](a)
00545         elif(param == 'paramkeys'):
00546                 return a.keys()
00547         else:
00548             if(paramvalue==None and subparam==None):
00549                if(a.has_key(param)):
00550                   return a[param]
00551                else:
00552                   return self.itsdefault(param)
00553             else:
00554                retval=a[param]
00555                if(type(a[param])==dict):
00556                   for k in range(len(a[param])):
00557                      valornotval='value'
00558                      if(a[param][k].has_key('notvalue')):
00559                         valornotval='notvalue'
00560                      if((a[param][k][valornotval])==paramvalue):
00561                         retval=a[param][k].copy()
00562                         retval.pop(valornotval)
00563                         if(subparam != None):
00564                            if(retval.has_key(subparam)):
00565                               retval=retval[subparam]
00566                            else:
00567                               retval=self.itsdefault(subparam)
00568                      else:
00569                         retval=self.itsdefault(subparam)
00570                return retval
00571 
00572 
00573 #
00574 #
00575     def check_params(self, param=None, value=None, ipython_globals=None):
00576       if ipython_globals == None:
00577           myf=self.__globals__
00578       else:
00579           myf=ipython_globals
00580 #      print 'param:', param, 'value:', value
00581       try :
00582          if str(type(value)) != "<type 'instance'>" :
00583             value0 = value
00584             value = myf['cu'].expandparam(param, value)
00585             matchtype = False
00586             if(type(value) == numpy.ndarray):
00587                if(type(value) == type(value0)):
00588                   myf[param] = value.tolist()
00589                else:
00590                   #print 'value:', value, 'value0:', value0
00591                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00592                   myf[param] = value0
00593                   if type(value0) != list :
00594                      matchtype = True
00595             else :
00596                myf[param] = value
00597             value = myf['cu'].verifyparam({param:value})
00598             if matchtype:
00599                value = False
00600       except Exception, instance:
00601          #ignore the exception and just return it unchecked
00602          myf[param] = value
00603       return value
00604 #
00605 #
00606     def description(self, key='setjy', subkey=None):
00607         desc={'setjy': 'Fills the model column with the visibilities of a calibrator',
00608                'vis': 'Name of input visibility file',
00609                'field': 'Field name(s)',
00610                'spw': 'Spectral window identifier (list)',
00611                'selectdata': 'Other data selection parameters',
00612                'timerange': 'Time range to operate on',
00613                'scan': 'Scan number range',
00614                'observation': 'Observation ID range',
00615                'modimage': 'File location for field model',
00616                'listmodels': 'List the available modimages for VLA calibrators or Tb models for Solar System objects',
00617                'scalebychan': 'scale the flux density on a per channel basis or else on a per spw basis',
00618                'fluxdensity': 'Specified flux density [I,Q,U,V]; -1 will lookup values',
00619                'spix': 'Spectral index of fluxdensity',
00620                'reffreq': 'Reference frequency for spix',
00621                'standard': 'Flux density standard',
00622                'useephemdir': 'use directions in the ephemeris table',
00623                'usescratch': 'Will create if necessary and use the MODEL_DATA ',
00624 
00625                'async': 'If true the taskname must be started using setjy(...)'
00626               }
00627 
00628 #
00629 # Set subfields defaults if needed
00630 #
00631 
00632         if(desc.has_key(key)) :
00633            return desc[key]
00634 
00635     def itsdefault(self, paramname) :
00636         a = {}
00637         a['vis']  = ''
00638         a['field']  = ''
00639         a['spw']  = ''
00640         a['selectdata']  = False
00641         a['timerange']  = ''
00642         a['scan']  = ''
00643         a['observation']  = ''
00644         a['modimage']  = ''
00645         a['listmodels']  = False
00646         a['scalebychan']  = True
00647         a['fluxdensity']  = -1
00648         a['spix']  = 0.0
00649         a['reffreq']  = '1GHz'
00650         a['standard']  = 'Perley-Butler 2010'
00651         a['useephemdir']  = False
00652         a['usescratch']  = False
00653 
00654         #a = sys._getframe(len(inspect.stack())-1).f_globals
00655 
00656         if self.parameters['selectdata']  == True:
00657             a['timerange'] = ''
00658             a['scan'] = ''
00659             a['observation'] = ''
00660 
00661         if self.parameters['fluxdensity']  != -1:
00662             a['spix'] = 0
00663             a['reffreq'] = '1GHz'
00664 
00665         if self.parameters['standard']  == 'Butler-JPL-Horizons 2012':
00666             a['useephemdir'] = False
00667 
00668         if a.has_key(paramname) :
00669               return a[paramname]
00670 setjy_cli = setjy_cli_()