casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
bandpass_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_bandpass import bandpass
00018 class bandpass_cli_:
00019     __name__ = "bandpass"
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__ = (bandpass_cli_,)
00028        self.__doc__ = self.__call__.__doc__
00029 
00030        self.parameters={'vis':None, 'caltable':None, 'field':None, 'spw':None, 'intent':None, 'selectdata':None, 'timerange':None, 'uvrange':None, 'antenna':None, 'scan':None, 'observation':None, 'msselect':None, 'solint':None, 'combine':None, 'refant':None, 'minblperant':None, 'minsnr':None, 'solnorm':None, 'bandtype':None, 'smodel':None, 'append':None, 'fillgaps':None, 'degamp':None, 'degphase':None, 'visnorm':None, 'maskcenter':None, 'maskedge':None, 'gaintable':None, 'gainfield':None, 'interp':None, 'spwmap':None, 'gaincurve':None, 'opacity':None, 'parang':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, caltable=None, field=None, spw=None, intent=None, selectdata=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, msselect=None, solint=None, combine=None, refant=None, minblperant=None, minsnr=None, solnorm=None, bandtype=None, smodel=None, append=None, fillgaps=None, degamp=None, degphase=None, visnorm=None, maskcenter=None, maskedge=None, gaintable=None, gainfield=None, interp=None, spwmap=None, gaincurve=None, opacity=None, parang=None,  async=None):
00047 
00048         """Calculates a bandpass calibration solution
00049 
00050        Determines the amplitude and phase as a function of frequency for
00051        each spectral window containing more than one channel.  Strong sources
00052        (or many observations of moderately strong sources) are needed to obtain
00053        accurate bandpass functions.  The two solution choices are: Individual
00054        antenna/based channel solutions 'B'; and a polynomial fit over the channels
00055        'BPOLY'.  The 'B' solutions can determined at any specified time interval, and
00056        is recommended if each channel has good signal-to-noise.  Other, 'BPOLY' is
00057        recommended.
00058 
00059       Keyword arguments:
00060       vis -- Name of input visibility file
00061               default: none; example: vis='ngc5921.ms'
00062       caltable -- Name of output bandpass calibration table
00063               default: none; example: caltable='ngc5921.bcal'
00064 
00065       --- Data Selection (see help par.selectdata for more detailed information)
00066 
00067       field -- Select field using field id(s) or field name(s).
00068                  [run listobs to obtain the list id's or names]
00069               default: ''=all fields
00070               If field string is a non-negative integer, it is assumed a field index
00071                 otherwise, it is assumed a field name
00072               field='0~2'; field ids 0,1,2
00073               field='0,4,5~7'; field ids 0,4,5,6,7
00074               field='3C286,3C295'; field named 3C286 adn 3C295
00075               field = '3,4C*'; field id 3, all names starting with 4C
00076       spw -- Select spectral window/channels
00077               default: ''=all spectral windows and channels
00078               spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00079               spw='<2';  spectral windows less than 2 (i.e. 0,1)
00080               spw='0:5~61'; spw 0, channels 5 to 61
00081               spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, channels 3 to 45.
00082               spw='0~2:2:6'; spw 0,1,2 with channels 2 through 6 in each.
00083               spw='0:0~10;15~60'; spectral window 0 with channels 0-10,15-60
00084                         NOTE: ';' to separate channel selections
00085               spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
00086                        spw 1, channels 20-30, and spw 2, channels, 1,2 and 3
00087       intent -- Select observing intent
00088                 default: ''  (no selection by intent)
00089                 intent='*BANDPASS*'  (selects data labelled with
00090                                       BANDPASS intent)
00091       selectdata -- Other data selection parameters
00092               default: True
00093       timerange  -- Select data based on time range:
00094               default = '' (all); examples,
00095               timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00096               Note: if YYYY/MM/DD is missing dat defaults to first day in data set
00097               timerange='09:14:0~09:54:0' picks 40 min on first day
00098               timerange= '25:00:00~27:30:00' picks 1 hr to 3 hr 30min on next day
00099               timerange='09:44:00' data within one integration of time
00100               timerange='>10:24:00' data after this time
00101       uvrange -- Select data within uvrange (default meters)
00102               default: '' (all); example:
00103               uvrange='0~1000kl'; uvrange from 0-1000 kilo-lamgda
00104               uvrange='>4kl';uvranges greater than 4 kilo-lambda
00105       antenna -- Select data based on antenna/baseline
00106               default: '' (all)
00107               If antenna string is a non-negative integer, it is assumed an antenna index
00108                 otherwise, it is assumed as an antenna name
00109               antenna='5&6'; baseline between antenna index 5 and index 6.
00110               antenna='VA05&VA06'; baseline between VLA antenna 5 and 6.
00111               antenna='5&6;7&8'; baseline 5-6 and 7-8
00112               antenna='5'; all baselines with antenna 5
00113               antenna='5,6,10'; all baselines with antennas 5, 6 and 10
00114        scan -- Select data based on scan number - New, under developement
00115                default: '' (all); example: scan='>3'
00116        observation -- Observation ID(s).
00117                       default: '' = all
00118                       example: '0~2,4'
00119        msselect -- Optional complex data selection (ignore for now)
00120 
00121        --- Solution parameters
00122        solint --  Solution interval in time (units optional), and (optionally)
00123                    in frequency.  Frequency pre-averaging can be
00124                    specified after a comma in units of channels or Hz.
00125                    If nothing is specified for frequency, no freq pre-averaging 
00126                    will be done.
00127        default: 'inf' (~infinite, up to boundaries controlled by combine,
00128                        with no pre-averaging in frequency)
00129               Options for time: 'inf' (~infinite), 'int' (per integration), any float
00130                        or integer value with or without units
00131               Options for freq: an integer with 'ch' suffix will enforce
00132                                 pre-averaging by the specified number
00133                                 of channels.
00134                                 a numeric value suffixed with frequency
00135                                 units (e.g., 'Hz','kHz','MHz') will enforce
00136                                 pre-averaging by an integral number of 
00137                                 channels amounting to no more than the
00138                                 specified bandwidth
00139               examples: solint='1min'; solint='60s', solint=60 --> 1 minute
00140                         solint='0s'; solint=0; solint='int' --> per integration
00141                         solint='-1s'; solint='inf' --> ~infinite, up to boundaries
00142                         enforced by combine
00143                         solint='inf,8Mhz' --> ~infinite in time, with 
00144                                                   8MHz pre-average in freq
00145                         solint='int,32ch' --> per-integration in time,
00146                                                   with 32-channel pre-average
00147                                                   in freq
00148        combine -- Data axes to combine for solving
00149               default: 'scan' --> solutions will break at field and spw boundaries,
00150                         but may extend over multiple scans (per field and spw) up
00151                         to solint.
00152               Options: '','scan','spw',field', or any comma-separated combination
00153               example: combine='scan,spw'  --> extend solutions over scan boundaries
00154                        (up to the solint), and combine spws for solving
00155        refant -- Reference antenna name(s); a prioritized list may be specified
00156                default: '' (no reference antenna)
00157                 example: refant='13' (antenna with index 13)
00158                          refant='VA04' (VLA antenna #4)
00159                          refant='EA02,EA23,EA13' (EVLA antenna EA02, use
00160                                 EA23 and EA13 as alternates if/when EA02
00161                                 drops out)
00162                Use 'go listobs' for antenna listing
00163        minblperant -- Minimum number of baselines required per antenna for each solve
00164                     Antennas with fewer baaselines are excluded from solutions. Amplitude
00165                     solutions with fewer than 4 baselines, and phase solutions with fewer 
00166                     than 3 baselines are only trivially constrained, and are no better
00167                     than baseline-based solutions.
00168                     default: 4
00169                     example: minblperant=10  => Antennas participating on 10 or more 
00170                              baselines are included in the solve
00171        minsnr -- Reject solutions below this SNR (only applies for bandtype = B)
00172                default: 3.0
00173        solnorm -- Normalize bandpass amplitudes and phase for each
00174                spw, pol, ant, and timestamp
00175                default: False (no normalization)
00176        bandtype -- Type of bandpass solution (B or BPOLY)
00177                default: 'B'; example: bandtype='BPOLY'
00178                'B' does a channel by channel solution for each
00179                    specified spw.
00180                'BPOLY' is somewhat experimental. It will fit an
00181                    nth order polynomial for the amplitude and phase
00182                    as a function of frequency. Only one fit is made
00183                    for all specified spw, and edge channels should be
00184                    omitted.
00185                 Use taskname=plotcal in order to compare the results from
00186                    B and BPOLY.
00187        fillgaps -- Fill flagged solution channels by interpolation
00188                default: 0 (don't interpolate)
00189                example: fillgaps=3 (interpolate gaps 3 channels wide and narrower)
00190        degamp -- Polynomial degree for BPOLY amplitude solution
00191                default: 3; example: degamp=2
00192        degphase -- Polynomial degree for BPOLY phase solution
00193                default: 3; example: degphase=2
00194        visnorm -- Normalize data prior to BPOLY solution
00195                default: False; example: visnorm=True
00196        maskcenter -- Number of channels to avoid in center of each band
00197                default: 0; example: maskcenter=5 (BPOLY only)
00198        maskedge -- Fraction of channels to avoid at each band edge (in %)
00199                default: 5; example: maskedge=3 (BPOLY only)
00200        append -- Append solutions to the (existing) table
00201                default: False; example: append=True
00202 
00203       --- Other calibrations to apply on the fly before determining bandpass solution
00204 
00205       gaintable -- Gain calibration table(s) to apply 
00206                default: '' (none);
00207                examples: gaintable='ngc5921.gcal'
00208                          gaintable=['ngc5921.ampcal','ngc5921.phcal']
00209       gainfield -- Select a subset of calibrators from gaintable(s)
00210                default:'' ==> all sources in table;
00211                'nearest' ==> nearest (on sky) available field in table
00212                otherwise, same syntax as field
00213                example: gainfield='0~3'
00214                         gainfield=['0~3','4~6']
00215       interp -- Interpolation type (in time[,freq]) to use for each gaintable.
00216                 When frequency interpolation is relevant (B, Df, Xf),
00217                 separate time-dependent and freq-dependent interp
00218                 types with a comma (freq _after_ the comma).                
00219                 Specifications for frequency are ignored when the
00220                 calibration table has no channel-dependence.
00221                 Time-dependent interp options ending in 'PD' enable a
00222                 "phase delay" correction per spw for non-channel-dependent
00223                 calibration types.
00224                 default: '' --> 'linear,linear' for all gaintable(s)
00225                 example: interp='nearest'   (in time, freq-dep will be
00226                                              linear, if relevant)
00227                          interp='linear,cubic'  (linear in time, cubic
00228                                                  in freq)
00229                          interp=',spline'  (spline in freq; linear in
00230                                             time by default)
00231                          interp=['nearest,spline','linear']  (for multiple gaintables)
00232                 Options: Time: 'nearest', 'linear'
00233                          Freq: 'nearest', 'linear', 'cubic', 'spline'
00234       spwmap -- Spectral windows combinations to form for gaintable(s)
00235                 default: [] (apply solutions from each spw to that spw only)
00236                 Example:  spwmap=[0,0,1,1] means apply the caltable solutions
00237                           from spw = 0 to the spw 0,1 and spw 1 to spw 2,3.
00238                           spwmap=[[0,0,1,1],[0,1,0,1]]
00239       gaincurve -- Apply internal VLA antenna gain curve correction  (True/False)
00240                default: False; 
00241                Use gaincurve=True ONLY for VLA data
00242       opacity -- Opacity correction to apply (nepers), per spw
00243                default: [] (no opacity correction for any spw)
00244                examples:
00245                    A global value for all spws:
00246                      opacity=0.051
00247                    Different values for spws 0,1,2:
00248                      opacity=[0.051, 0.055, 0.057]
00249                    (if more than 3 spws, spw 3 and higher will
00250                     be assigned the last specified value, or 0.057)
00251                Typical VLA values are: 5 GHz - 0.013, 8 GHz - 0.013
00252                15 GHz - 0.016, 23 GHz - 0.051, 43 GHz - 0.07
00253       parang -- If True, apply the parallactic angle correction (required
00254                for polarization calibration)
00255                default: False
00256 
00257 
00258         """
00259         if not hasattr(self, "__globals__") or self.__globals__ == None :
00260            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00261         #casac = self.__globals__['casac']
00262         casalog = self.__globals__['casalog']
00263         #casalog = casac.casac.logsink()
00264         self.__globals__['__last_task'] = 'bandpass'
00265         self.__globals__['taskname'] = 'bandpass'
00266         ###
00267         self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__)
00268         ###
00269         ###
00270         #Handle globals or user over-ride of arguments
00271         #
00272         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00273         useLocalDefaults = False
00274 
00275         for item in function_signature_defaults.iteritems():
00276                 key,val = item
00277                 keyVal = eval(key)
00278                 if (keyVal == None):
00279                         #user hasn't set it - use global/default
00280                         pass
00281                 else:
00282                         #user has set it - use over-ride
00283                         if (key != 'self') :
00284                            useLocalDefaults = True
00285 
00286         myparams = {}
00287         if useLocalDefaults :
00288            for item in function_signature_defaults.iteritems():
00289                key,val = item
00290                keyVal = eval(key)
00291                exec('myparams[key] = keyVal')
00292                self.parameters[key] = keyVal
00293                if (keyVal == None):
00294                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00295                    keyVal = eval(key)
00296                    if(type(keyVal) == dict) :
00297                       if len(keyVal) > 0 :
00298                          exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00299                       else :
00300                          exec('myparams[key] = ' + key + ' = {}')
00301 
00302         else :
00303             async = self.parameters['async']
00304             myparams['vis'] = vis = self.parameters['vis']
00305             myparams['caltable'] = caltable = self.parameters['caltable']
00306             myparams['field'] = field = self.parameters['field']
00307             myparams['spw'] = spw = self.parameters['spw']
00308             myparams['intent'] = intent = self.parameters['intent']
00309             myparams['selectdata'] = selectdata = self.parameters['selectdata']
00310             myparams['timerange'] = timerange = self.parameters['timerange']
00311             myparams['uvrange'] = uvrange = self.parameters['uvrange']
00312             myparams['antenna'] = antenna = self.parameters['antenna']
00313             myparams['scan'] = scan = self.parameters['scan']
00314             myparams['observation'] = observation = self.parameters['observation']
00315             myparams['msselect'] = msselect = self.parameters['msselect']
00316             myparams['solint'] = solint = self.parameters['solint']
00317             myparams['combine'] = combine = self.parameters['combine']
00318             myparams['refant'] = refant = self.parameters['refant']
00319             myparams['minblperant'] = minblperant = self.parameters['minblperant']
00320             myparams['minsnr'] = minsnr = self.parameters['minsnr']
00321             myparams['solnorm'] = solnorm = self.parameters['solnorm']
00322             myparams['bandtype'] = bandtype = self.parameters['bandtype']
00323             myparams['smodel'] = smodel = self.parameters['smodel']
00324             myparams['append'] = append = self.parameters['append']
00325             myparams['fillgaps'] = fillgaps = self.parameters['fillgaps']
00326             myparams['degamp'] = degamp = self.parameters['degamp']
00327             myparams['degphase'] = degphase = self.parameters['degphase']
00328             myparams['visnorm'] = visnorm = self.parameters['visnorm']
00329             myparams['maskcenter'] = maskcenter = self.parameters['maskcenter']
00330             myparams['maskedge'] = maskedge = self.parameters['maskedge']
00331             myparams['gaintable'] = gaintable = self.parameters['gaintable']
00332             myparams['gainfield'] = gainfield = self.parameters['gainfield']
00333             myparams['interp'] = interp = self.parameters['interp']
00334             myparams['spwmap'] = spwmap = self.parameters['spwmap']
00335             myparams['gaincurve'] = gaincurve = self.parameters['gaincurve']
00336             myparams['opacity'] = opacity = self.parameters['opacity']
00337             myparams['parang'] = parang = self.parameters['parang']
00338 
00339         if type(smodel)==float: smodel=[smodel]
00340         if type(gaintable)==str: gaintable=[gaintable]
00341         if type(gainfield)==str: gainfield=[gainfield]
00342         if type(interp)==str: interp=[interp]
00343         if type(spwmap)==int: spwmap=[spwmap]
00344         if type(opacity)==float: opacity=[opacity]
00345 
00346         result = None
00347 
00348 #
00349 #    The following is work around to avoid a bug with current python translation
00350 #
00351         mytmp = {}
00352 
00353         mytmp['vis'] = vis
00354         mytmp['caltable'] = caltable
00355         mytmp['field'] = field
00356         mytmp['spw'] = spw
00357         mytmp['intent'] = intent
00358         mytmp['selectdata'] = selectdata
00359         mytmp['timerange'] = timerange
00360         mytmp['uvrange'] = uvrange
00361         mytmp['antenna'] = antenna
00362         mytmp['scan'] = scan
00363         mytmp['observation'] = observation
00364         mytmp['msselect'] = msselect
00365         mytmp['solint'] = solint
00366         mytmp['combine'] = combine
00367         mytmp['refant'] = refant
00368         mytmp['minblperant'] = minblperant
00369         mytmp['minsnr'] = minsnr
00370         mytmp['solnorm'] = solnorm
00371         mytmp['bandtype'] = bandtype
00372         mytmp['smodel'] = smodel
00373         mytmp['append'] = append
00374         mytmp['fillgaps'] = fillgaps
00375         mytmp['degamp'] = degamp
00376         mytmp['degphase'] = degphase
00377         mytmp['visnorm'] = visnorm
00378         mytmp['maskcenter'] = maskcenter
00379         mytmp['maskedge'] = maskedge
00380         mytmp['gaintable'] = gaintable
00381         mytmp['gainfield'] = gainfield
00382         mytmp['interp'] = interp
00383         mytmp['spwmap'] = spwmap
00384         mytmp['gaincurve'] = gaincurve
00385         mytmp['opacity'] = opacity
00386         mytmp['parang'] = parang
00387         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00388         trec = casac.casac.utils().torecord(pathname+'bandpass.xml')
00389 
00390         casalog.origin('bandpass')
00391         try :
00392           #if not trec.has_key('bandpass') or not casac.casac.utils().verify(mytmp, trec['bandpass']) :
00393             #return False
00394 
00395           casac.casac.utils().verify(mytmp, trec['bandpass'], True)
00396           scriptstr=['']
00397           saveinputs = self.__globals__['saveinputs']
00398           saveinputs('bandpass', 'bandpass.last', myparams, self.__globals__,scriptstr=scriptstr)
00399           if async :
00400             count = 0
00401             keybase =  time.strftime("%y%m%d.%H%M%S")
00402             key = keybase + "_" + str(count)
00403             while self.__async__.has_key(key) :
00404                count += 1
00405                key = keybase + "_" + str(count)
00406             result = tm.execute('bandpass', vis, caltable, field, spw, intent, selectdata, timerange, uvrange, antenna, scan, observation, msselect, solint, combine, refant, minblperant, minsnr, solnorm, bandtype, smodel, append, fillgaps, degamp, degphase, visnorm, maskcenter, maskedge, gaintable, gainfield, interp, spwmap, gaincurve, opacity, parang)
00407             print "Use: "
00408             print "      tm.retrieve(return_value) # to retrieve the status"
00409             print 
00410             self.rkey = key
00411             self.__async__[key] = result
00412           else :
00413               tname = 'bandpass'
00414               spaces = ' '*(18-len(tname))
00415               casalog.post('\n##########################################'+
00416                            '\n##### Begin Task: ' + tname + spaces + ' #####')
00417               casalog.post(scriptstr[1][1:]+'\n', 'INFO')
00418               result = bandpass(vis, caltable, field, spw, intent, selectdata, timerange, uvrange, antenna, scan, observation, msselect, solint, combine, refant, minblperant, minsnr, solnorm, bandtype, smodel, append, fillgaps, degamp, degphase, visnorm, maskcenter, maskedge, gaintable, gainfield, interp, spwmap, gaincurve, opacity, parang)
00419               casalog.post('##### End Task: ' + tname + '  ' + spaces + ' #####'+
00420                            '\n##########################################')
00421 
00422         except Exception, instance:
00423           if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) :
00424              raise
00425           else :
00426              #print '**** Error **** ',instance
00427              tname = 'bandpass'
00428              casalog.post('An error occurred running task '+tname+'.', 'ERROR')
00429              pass
00430 
00431         gc.collect()
00432         return result
00433 #
00434 #
00435 #
00436     def paramgui(self, useGlobals=True, ipython_globals=None):
00437         """
00438         Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00439         """
00440         import paramgui
00441         if not hasattr(self, "__globals__") or self.__globals__ == None :
00442            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00443 
00444         if useGlobals:
00445             if ipython_globals == None:
00446                 myf=self.__globals__
00447             else:
00448                 myf=ipython_globals
00449 
00450             paramgui.setGlobals(myf)
00451         else:
00452             paramgui.setGlobals({})
00453 
00454         paramgui.runTask('bandpass', myf['_ip'])
00455         paramgui.setGlobals({})
00456 
00457 #
00458 #
00459 #
00460     def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None):
00461         if not hasattr(self, "__globals__") or self.__globals__ == None :
00462            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00463         if ipython_globals == None:
00464             myf=self.__globals__
00465         else:
00466             myf=ipython_globals
00467 
00468         a = odict()
00469         a['vis']  = ''
00470         a['caltable']  = ''
00471         a['field']  = ''
00472         a['spw']  = ''
00473         a['intent']  = ''
00474         a['selectdata']  = True
00475         a['solint']  = 'inf'
00476         a['combine']  = 'scan'
00477         a['refant']  = ''
00478         a['minblperant']  = 4
00479         a['minsnr']  = 3.0
00480         a['solnorm']  = False
00481         a['bandtype']  = 'B'
00482         a['smodel']  = []
00483         a['append']  = False
00484         a['gaintable']  = ['']
00485         a['gainfield']  = ['']
00486         a['interp']  = ['']
00487         a['spwmap']  = []
00488         a['gaincurve']  = False
00489         a['opacity']  = []
00490         a['parang']  = False
00491 
00492         a['async']=False
00493         a['selectdata'] = {
00494                     0:odict([{'value':True}, {'timerange':''}, {'uvrange':''}, {'antenna':''}, {'scan':''}, {'observation':''}, {'msselect':''}]), 
00495                     1:{'value':False}}
00496         a['bandtype'] = {
00497                     0:odict([{'value':'B'}, {'fillgaps':0}]), 
00498                     1:odict([{'value':'BPOLY'}, {'degamp':3}, {'degphase':3}, {'visnorm':False}, {'maskcenter':0}, {'maskedge':0}])}
00499 
00500 ### This function sets the default values but also will return the list of
00501 ### parameters or the default value of a given parameter
00502         if(param == None):
00503                 myf['__set_default_parameters'](a)
00504         elif(param == 'paramkeys'):
00505                 return a.keys()
00506         else:
00507             if(paramvalue==None and subparam==None):
00508                if(a.has_key(param)):
00509                   return a[param]
00510                else:
00511                   return self.itsdefault(param)
00512             else:
00513                retval=a[param]
00514                if(type(a[param])==dict):
00515                   for k in range(len(a[param])):
00516                      valornotval='value'
00517                      if(a[param][k].has_key('notvalue')):
00518                         valornotval='notvalue'
00519                      if((a[param][k][valornotval])==paramvalue):
00520                         retval=a[param][k].copy()
00521                         retval.pop(valornotval)
00522                         if(subparam != None):
00523                            if(retval.has_key(subparam)):
00524                               retval=retval[subparam]
00525                            else:
00526                               retval=self.itsdefault(subparam)
00527                      else:
00528                         retval=self.itsdefault(subparam)
00529                return retval
00530 
00531 
00532 #
00533 #
00534     def check_params(self, param=None, value=None, ipython_globals=None):
00535       if ipython_globals == None:
00536           myf=self.__globals__
00537       else:
00538           myf=ipython_globals
00539 #      print 'param:', param, 'value:', value
00540       try :
00541          if str(type(value)) != "<type 'instance'>" :
00542             value0 = value
00543             value = myf['cu'].expandparam(param, value)
00544             matchtype = False
00545             if(type(value) == numpy.ndarray):
00546                if(type(value) == type(value0)):
00547                   myf[param] = value.tolist()
00548                else:
00549                   #print 'value:', value, 'value0:', value0
00550                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00551                   myf[param] = value0
00552                   if type(value0) != list :
00553                      matchtype = True
00554             else :
00555                myf[param] = value
00556             value = myf['cu'].verifyparam({param:value})
00557             if matchtype:
00558                value = False
00559       except Exception, instance:
00560          #ignore the exception and just return it unchecked
00561          myf[param] = value
00562       return value
00563 #
00564 #
00565     def description(self, key='bandpass', subkey=None):
00566         desc={'bandpass': 'Calculates a bandpass calibration solution',
00567                'vis': 'Name of input visibility file',
00568                'caltable': 'Name of output gain calibration table',
00569                'field': 'Select field using field id(s) or field name(s)',
00570                'spw': 'Select spectral window/channels',
00571                'intent': 'Select observing intent',
00572                'selectdata': 'Other data selection parameters',
00573                'timerange': 'Select data based on time range',
00574                'uvrange': 'Select data within uvrange (default units meters)',
00575                'antenna': 'Select data based on antenna/baseline',
00576                'scan': 'Scan number range',
00577                'observation': 'Select by observation ID(s)',
00578                'msselect': 'Optional complex data selection (ignore for now)',
00579                'solint': 'Solution interval in time[,freq]',
00580                'combine': 'Data axes which to combine for solve (scan, spw, and/or field)',
00581                'refant': 'Reference antenna name(s)',
00582                'minblperant': 'Minimum baselines _per antenna_ required for solve',
00583                'minsnr': 'Reject solutions below this SNR (only applies for bandtype = B)',
00584                'solnorm': 'Normalize average solution amplitudes to 1.0 ',
00585                'bandtype': 'Type of bandpass solution (B or BPOLY)',
00586                'smodel': 'Point source Stokes parameters for source model.',
00587                'append': 'Append solutions to the (existing) table',
00588                'fillgaps': 'Fill flagged solution channels by interpolation',
00589                'degamp': 'Polynomial degree for BPOLY amplitude solution',
00590                'degphase': 'Polynomial degree for BPOLY phase solution',
00591                'visnorm': 'Normalize data prior to BPOLY solution',
00592                'maskcenter': 'Number of channels to avoid in center of each band',
00593                'maskedge': 'Fraction of channels to avoid at each band edge (in %)',
00594                'gaintable': 'Gain calibration table(s) to apply on the fly',
00595                'gainfield': 'Select a subset of calibrators from gaintable(s)',
00596                'interp': 'Interpolation mode (in time) to use for each gaintable',
00597                'spwmap': 'Spectral windows combinations to form for gaintables(s)',
00598                'gaincurve': 'Apply internal VLA antenna gain curve correction',
00599                'opacity': 'Opacity correction to apply (nepers), per spw',
00600                'parang': 'Apply parallactic angle correction',
00601 
00602                'async': 'If true the taskname must be started using bandpass(...)'
00603               }
00604 
00605 #
00606 # Set subfields defaults if needed
00607 #
00608 
00609         if(desc.has_key(key)) :
00610            return desc[key]
00611 
00612     def itsdefault(self, paramname) :
00613         a = {}
00614         a['vis']  = ''
00615         a['caltable']  = ''
00616         a['field']  = ''
00617         a['spw']  = ''
00618         a['intent']  = ''
00619         a['selectdata']  = True
00620         a['timerange']  = ''
00621         a['uvrange']  = ''
00622         a['antenna']  = ''
00623         a['scan']  = ''
00624         a['observation']  = ''
00625         a['msselect']  = ''
00626         a['solint']  = 'inf'
00627         a['combine']  = 'scan'
00628         a['refant']  = ''
00629         a['minblperant']  = 4
00630         a['minsnr']  = 3.0
00631         a['solnorm']  = False
00632         a['bandtype']  = 'B'
00633         a['smodel']  = []
00634         a['append']  = False
00635         a['fillgaps']  = 0
00636         a['degamp']  = 3
00637         a['degphase']  = 3
00638         a['visnorm']  = False
00639         a['maskcenter']  = 0
00640         a['maskedge']  = 5
00641         a['gaintable']  = ['']
00642         a['gainfield']  = ['']
00643         a['interp']  = ['']
00644         a['spwmap']  = []
00645         a['gaincurve']  = False
00646         a['opacity']  = []
00647         a['parang']  = False
00648 
00649         #a = sys._getframe(len(inspect.stack())-1).f_globals
00650 
00651         if self.parameters['selectdata']  == True:
00652             a['timerange'] = ''
00653             a['uvrange'] = ''
00654             a['antenna'] = ''
00655             a['scan'] = ''
00656             a['observation'] = ''
00657             a['msselect'] = ''
00658 
00659         if self.parameters['bandtype']  == 'B':
00660             a['fillgaps'] = 0
00661 
00662         if self.parameters['bandtype']  == 'BPOLY':
00663             a['degamp'] = 3
00664             a['degphase'] = 3
00665             a['visnorm'] = False
00666             a['maskcenter'] = 0
00667             a['maskedge'] = 0
00668 
00669         if a.has_key(paramname) :
00670               return a[paramname]
00671 bandpass_cli = bandpass_cli_()