casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
pointcal.py
Go to the documentation of this file.
00001 import sys
00002 import string
00003 import inspect
00004 from odict import odict
00005 
00006 from parameter_check import *
00007 
00008 def pointcal(vis=None,model=None,caltable=None,
00009              field=None,spw=None,
00010              selectdata=None,timerange=None,uvrange=None,antenna=None,scan=None,msselect=None,
00011              gaincurve=None,opacity=None,solint=None):
00012         """Solve for pointing error calibration:
00013 
00014         This program is under development.  Please do not use.
00015 
00016         Keyword arguments:
00017         vis -- Name of input visibility file (MS)
00018                 default: <unset>; example: vis='ngc5921.ms'
00019         model -- Name of input model (component list or image)
00020                 default: <unset>; example: model='ngc5921.im'
00021         caltable -- Name of output Pointing calibration table
00022                 default: <unset>; example: caltable='ngc5921.gcal'
00023 
00024         --- Data Selection (see help par.selectdata for more detailed information)
00025 
00026        field -- Select field using field id(s) or field name(s).
00027                   [run listobs to obtain the list id's or names]
00028                default: ''=all fields
00029                If field string is a non-negative integer, it is assumed a field index
00030                  otherwise, it is assumed a field name
00031                field='0~2'; field ids 0,1,2
00032                field='0,4,5~7'; field ids 0,4,5,6,7
00033                field='3C286,3C295'; field named 3C286 adn 3C295
00034                field = '3,4C*'; field id 3, all names starting with 4C
00035        spw -- Select spectral window/channels
00036                default: ''=all spectral windows and channels
00037                spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00038                spw='<2';  spectral windows less than 2 (i.e. 0,1)
00039                spw='0:5~61'; spw 0, channels 5 to 61
00040                spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, channels 3 to 45.
00041                spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
00042                spw='0:0~10;15~60'; spectral window 0 with channels 0-10,15-60
00043                spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
00044                         spw 1, channels 20-30, and spw 2, channels, 1,2 and 3
00045 
00046        selectdata -- Other data selection parameters
00047                default: True
00048        timerange  -- Select data based on time range:
00049                default = '' (all); examples,
00050                timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00051                Note: if YYYY/MM/DD is missing dat defaults to first day in data set
00052                timerange='09:14:0~09:54:0' picks 40 min on first day
00053                timerange= '25:00:00~27:30:00' picks 1 hr to 3 hr 30min on next day
00054                timerange='09:44:00' data within one integration of time
00055                timerange='>10:24:00' data after this time
00056        uvrange -- Select data within uvrange (default units kilo-lambda)
00057                default: '' (all); example:
00058                uvrange='0~1000'; uvrange from 0-1000 kilo-lamgda
00059                uvrange='>4';uvranges greater than 4 kilo lambda
00060        antenna -- Select data based on antenna/baseline
00061                default: '' (all)
00062                If antenna string is a non-negative integer, it is assumed an antenna index
00063                  otherwise, it is assumed as an antenna name
00064                antenna='5&6'; baseline between antenna index 5 and index 6.
00065                antenna='VA05&VA06'; baseline between VLA antenna 5 and 6.
00066                antenna='5&6;7&8'; baseline 5-6 and 7-8
00067                antenna='5'; all baselines with antenna 5
00068                antenna='5,6,10'; all baselines with antennas 5 and 6
00069        scan -- Scan number range - New, under developement
00070        msselect -- Optional complex data selection (ignore for now)
00071 
00072         gaincurve -- Apply VLA antenna gain curve correction (True/False)
00073                 default: False; 
00074                 Use gaincurve=True ONLY for VLA data
00075         opacity -- Opacity correction to apply
00076                 default: 0.0 (no opacity correction)
00077                 example: opacity=0.051
00078         solint --  Solution interval (sec)
00079                 default: 0.0 (scan based); example: solint=60.
00080 
00081         """
00082         a=inspect.stack()
00083         stacklevel=0
00084         for k in range(len(a)):
00085           if (string.find(a[k][1], 'ipython console') > 0):
00086                 stacklevel=k
00087         myf=sys._getframe(stacklevel).f_globals
00088         myf['taskname']='pointcal'
00089         ###fill unfilled parameters with defaults
00090         myf['update_params'](func=myf['taskname'], printtext=False)
00091         ####local params 
00092         cb = myf['cb']
00093         selectantenna=myf['selectantenna']
00094         ###
00095         #Handle globals or user over-ride of arguments
00096         #
00097         function_signature_defaults=dict(zip(pointcal.func_code.co_varnames,pointcal.func_defaults))
00098         for item in function_signature_defaults.iteritems():
00099                 key,val = item
00100                 keyVal = eval(key)
00101                 if (keyVal == None):
00102                         #user hasn't set it - use global/default
00103                         pass
00104                 else:
00105                         myf[key]=keyVal
00106                         #user has set it - use over-ride
00107 
00108         vis=myf['vis']
00109         model=myf['model']
00110         caltable=myf['caltable']
00111         field=myf['field']
00112         spw=myf['spw']
00113         selectdata=myf['selectdata']
00114         if (selectdata):
00115                 timerange=myf['timerange']
00116                 uvrange=myf['uvrange']
00117                 antenna=myf['antenna']
00118                 scan=myf['scan']
00119                 msselect=myf['msselect']
00120         else:
00121                 timerange=''
00122                 uvrange=''
00123                 antenna=''
00124                 scan=''
00125                 msselect=''
00126         gaincurve=myf['gaincurve']
00127         opacity=myf['opacity']
00128         solint=myf['solint']
00129         #sys._getframe(1).f_globals[key]=keyVal
00130 
00131         #Add type/menu/range error checking here
00132         arg_names=['vis','model','caltable',
00133                    'field','spw',
00134                    'selectdata','timerange','uvrange','antenna','scan','msselect',
00135                    'gaincurve','opacity','solint']
00136         arg_values=[vis,model,caltable,
00137                     field,spw,
00138                     selectdata,timerange,uvrange,antenna,scan,msselect,
00139                     gaincurve,opacity,solint]
00140         arg_types=[str,str,str,
00141                    str,str,
00142                    bool,str,str,str,str,str,
00143                    bool,float,float]
00144         try:
00145                 parameter_checktype(arg_names,arg_values,arg_types)
00146         except TypeError, e:
00147                 print "pointcal -- TypeError: ", e
00148                 return
00149         except ValueError, e:
00150                 print "pointcal -- OptionError: ", e
00151                 return
00152         ###
00153 
00154 
00155         #Python script
00156         #parameter_printvalues(arg_names,arg_values,arg_types)
00157         try:
00158                 cb.open(vis)
00159                 cb.reset()
00160 
00161                 cb.selectvis(time=timerange,spw=spw,scan=scan,field=field,
00162                              baseline=antenna,uvrange=uvrange,chanmode='none',
00163                              nchan=nchan,start=start,step=step,
00164                              msselect=msselect);
00165 
00166                 if (opacity>0.0): cb.setapply2(type='TOPAC',t=-1,opacity=opacity)
00167                 if gaincurve: cb.setapply2(type='GAINCURVE',t=-1)
00168                 cb.setsolve2(type='POINTCAL',t=solint,refant='',table=caltable)
00169                 #cb.state()
00170                 cb.solve()
00171                 cb.close()
00172         except Exception, instance:
00173                 print '*** Error ***',instance
00174         saveinputs=myf['saveinputs']
00175         saveinputs('pointcal','pointcal.last')
00176 
00177 
00178 def pointcal_defaults(param=None):
00179         a=inspect.stack()
00180         stacklevel=0
00181         for k in range(len(a)):
00182           if (string.find(a[k][1], 'ipython console') > 0):
00183                 stacklevel=k
00184         myf=sys._getframe(stacklevel).f_globals
00185         a=odict()
00186         a['vis']=''
00187         a['model']=''
00188         a['caltable']=''
00189         a['field']=''
00190         a['spw']=''
00191         a['selectdata']={1:{'value':False},
00192                          0:odict([{'value':True},
00193                                   {'timerange':''},
00194                                   {'uvrange':''},
00195                                   {'antenna':''},
00196                                   {'scan':''},
00197                                   {'msselect':''}])
00198                          }
00199         a['gaincurve']=False
00200         a['opacity']=0.0
00201         a['solint']=0.0
00202         if(param == None):
00203                 myf['__set_default_parameters'](a)
00204         elif(param == 'paramkeys'):
00205                 return a.keys()                     
00206         else:
00207                 if(a.has_key(param)):
00208                         return a[param]
00209 
00210 
00211 def pointcal_description(key='pointcal',subkey=None):
00212         desc={'pointcal': 'Solve for pointing error calibration:\n',
00213         'vis': 'This program is under development.  Please do not use. \n\n\t\t\t\t\t\t Name of input visibility file (MS)',
00214         'model': 'Name of input model (component list or image)',
00215         'caltable': 'Name of output Gain calibration table',
00216         'field': 'Select data based on field name or index',
00217         'spw': 'Select data based on spectral window',
00218         'selectdata': 'Activate data selection details',
00219         'timerange': 'Select data based on time',
00220         'uvrange': 'Select data based on uv range',
00221         'antenna': 'Select data based on antenna/baseline',
00222         'scan': 'Select data based on scan number',
00223         'msselect': 'Optional data selection (see help)',
00224         'gaincurve': 'Apply VLA antenna gain curve correction',
00225         'opacity':'Opacity correction to apply (nepers)',
00226         'gaintable': 'Gain calibration solutions to apply',
00227         'gainselect': 'Select subset of calibration solutions from gaintable',
00228         'solint': 'Solution interval (sec)',
00229         }
00230         if(desc.has_key(key)):
00231                 return desc[key]
00232         return ''