casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdcal_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_sdcal import sdcal
00018 class sdcal_cli_:
00019     __name__ = "sdcal"
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__ = (sdcal_cli_,)
00028        self.__doc__ = self.__call__.__doc__
00029 
00030        self.parameters={'infile':None, 'antenna':None, 'fluxunit':None, 'telescopeparm':None, 'specunit':None, 'frame':None, 'doppler':None, 'calmode':None, 'fraction':None, 'noff':None, 'width':None, 'elongated':None, 'markonly':None, 'plotpointings':None, 'scanlist':None, 'field':None, 'iflist':None, 'pollist':None, 'channelrange':None, 'scanaverage':None, 'timeaverage':None, 'tweight':None, 'averageall':None, 'polaverage':None, 'pweight':None, 'tau':None, 'verify':None, 'outfile':None, 'outform':None, 'overwrite':None, 'plotlevel':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, infile=None, antenna=None, fluxunit=None, telescopeparm=None, specunit=None, frame=None, doppler=None, calmode=None, fraction=None, noff=None, width=None, elongated=None, markonly=None, plotpointings=None, scanlist=None, field=None, iflist=None, pollist=None, channelrange=None, scanaverage=None, timeaverage=None, tweight=None, averageall=None, polaverage=None, pweight=None, tau=None, verify=None, outfile=None, outform=None, overwrite=None, plotlevel=None,  async=None):
00047 
00048         """ASAP SD task: do data selection, calibration, and averaging
00049   Keyword arguments:
00050         infile -- name of input SD dataset
00051         antenna -- antenna name or id (only effective for MS input). 
00052         fluxunit -- units for line flux
00053                 options: 'K','Jy',''
00054                 default: '' (keep current fluxunit)
00055                 WARNING: For GBT data, see description below.
00056 
00057             >>> fluxunit expandable parameter
00058                  telescopeparm -- the telescope characteristics
00059                          options: (str) name or (list) list of gain info
00060                          default: '' (none set)
00061                          example: if telescopeparm='', it tries to get the telescope
00062                                   name from the data.
00063                                   Full antenna parameters (diameter,ap.eff.) known
00064                                   to ASAP are
00065                                   'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43',
00066                                   'CEDUNA','HOBART'. For GBT, it fixes default fluxunit
00067                                   to 'K' first then convert to a new fluxunit.
00068                                   telescopeparm=[104.9,0.43] diameter(m), ap.eff.
00069                                   telescopeparm=[0.743] gain in Jy/K
00070                                   telescopeparm='FIX' to change default fluxunit
00071                                   see description below
00072 
00073         specunit -- units for spectral axis
00074                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz'
00075                 default: '' (=current)
00076                 example: this will be the units for masklist
00077         frame -- frequency frame for spectral axis
00078                 options: (str) 'LSRK','REST','TOPO','LSRD','BARY',
00079                          'GEO','GALACTO','LGROUP','CMB'
00080                 default: currently set frame in scantable
00081                 WARNING: frame='REST' not yet implemented
00082         doppler -- doppler mode
00083                 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA'
00084                 default: currently set doppler in scantable
00085         calmode -- calibration mode
00086                 options: 'ps','nod','otf','otfraster',
00087                          'fs','fsotf','quotient','none'
00088                 default: 'none'
00089                 example: choose mode 'none' if you have
00090                          already calibrated and want to
00091                          try averaging
00092                 WARNING: 'fsotf' is not implemented yet
00093             >>> calmode expandable parameter
00094                  fraction -- Edge marking parameter for 'otf' and 'otfraster'.
00095                              specify a number of OFF scans as a fraction of 
00096                              total number of data points. 
00097                          default: '10%'
00098                          options: '20%' in string style or float value less 
00099                                   than 1.0 (e.g. 0.15).
00100                                   'auto' is available only for 'otfraster'. 
00101                  noff -- Edge marking parameter for 'otfraster'.
00102                          It is used to specify a number of OFF scans near 
00103                          edge directly. Value of noff comes before setting 
00104                          by fraction.
00105                          default: -1 (use fraction)
00106                          options: any positive integer
00107                  width -- Edge marking parameter for 'otf'.
00108                           Pixel width with respect to a median spatial 
00109                           separation between neighboring two data in time.
00110                           Default will be fine in most cases.
00111                          default: 0.5
00112                          options: float value
00113                  elongated -- Edge marking parameter for 'otf'.
00114                               Set True only if observed area is elongeted 
00115                               in one direction.
00116                          default: False
00117                  markonly -- Set True if you want to save data just after 
00118                              edge marking (i.e. uncalibrated data) to see 
00119                              how OFF scans are defined.
00120                          default: False
00121         scanlist -- list of scan numbers to process
00122                 default: [] (use all scans)
00123                 example: [21,22,23,24]
00124                 this selection is in addition to field, iflist, and pollist
00125         field -- selection string for selecting scans by name
00126                 default: '' (no name selection)
00127                 example: 'FLS3a*'
00128                 this selection is in addition to scanlist, iflist, and pollist
00129         iflist -- list of IF id numbers to select
00130                 default: [] (use all IFs)
00131                 example: [15]
00132                 this selection is in addition to scanlist, field, and pollist
00133         pollist -- list of polarization id numbers to select
00134                 default: [] (use all polarizations)
00135                 example: [1]
00136                 this selection is in addition to scanlist, field, and iflist
00137         channelrange -- channel range selection
00138                 default: [] (use all channel)
00139                 example: [0,5000]
00140                 Note that specified values are recognized as 'channel'
00141                 regardless of the value of specunit 
00142         scanaverage -- average integrations within scans
00143                 options: (bool) True,False
00144                 default: False
00145         timeaverage -- average times for multiple scan cycles
00146                 options: (bool) True,False
00147                 default: False
00148                 example: if True, this happens after calibration
00149 
00150             >>>timeaverage expandable parameter
00151                  tweight -- weighting for time average
00152                          options: 'none' 
00153                                   'var'   (1/var(spec) weighted)
00154                                   'tsys'  (1/Tsys**2 weighted)
00155                                   'tint'  (integration time weighted)
00156                                   'tintsys'  (Tint/Tsys**2)
00157                                   'median'  ( median averaging)
00158                          default: 'none'
00159 
00160                  averageall -- average multi-resolution spectra
00161                                spectra are averaged by referring 
00162                                their frequency coverage
00163                          default: False
00164 
00165         polaverage -- average polarizations
00166                 options: (bool) True,False
00167                 default: False
00168 
00169             >>>polaverage expandable parameter
00170                  pweight -- weighting for polarization average
00171                          options: 'none'
00172                                   'var'  (1/var(spec) weighted)
00173                                   'tsys' (1/Tsys**2 weighted)
00174                          default: 'none'
00175 
00176         tau -- atmospheric optical depth
00177                 default: 0.0 (no correction)
00178         verify -- verify the results of calibration. Only effective if 
00179                   calmode is not 'none'.
00180                 options: (bool) True,False
00181                 default: False
00182                 WARNING: Currently this just asks whether you accept
00183                          the displayed calibration and if not, continues
00184                          without doing any calibration. 
00185         outfile -- Name of output file
00186                 default: '' (<infile>_cal)
00187         outform -- format of output file
00188                 options: 'ASCII','SDFITS','MS','ASAP'
00189                 default: 'ASAP'
00190                 example: the ASAP format is easiest for further sd
00191                          processing; use MS for CASA imaging.
00192                          If ASCII, then will append some stuff to
00193                          the outfile name
00194         overwrite -- overwrite the output file if already exists
00195                 options: (bool) True,False
00196                 default: False
00197                 WARNING: if outform='ASCII', this parameter is ignored
00198         plotlevel -- control for plotting of results
00199                 options: (int) 0=none, 1=some, 2=more, <0=hardcopy
00200                 default: 0 (no plotting)
00201                 example: plotlevel<0 as abs(plotlevel), e.g.
00202                          -1 => hardcopy of final plot (will be named
00203                          <outfile>_calspec.eps)
00204                 WARNING: be careful plotting in fsotf mode!
00205 
00206 
00207         DESCRIPTION:
00208 
00209         Task sdcal performs data selection, calibration for single-dish
00210         spectra.  By setting calmode='none', one can run sdcal on already 
00211         calibrated data, for further selection , averaging and atmospheric 
00212         optical depth correction. To save the output spectra in a certain
00213         range of channels, you set the range in channelrange.
00214 
00215         If you give multiple IFs in iflist, then your scantable will have
00216         multiple IFs by default. Averaging of multi-resolution (multi-IFs)
00217         spectra can be achieved by setting a sub-parameter in timeaverage, 
00218         averageall, to True. It handles multi-IFs by selecting overlaps in 
00219         frequency coverages and assigning new IFs in the output spectra.
00220 
00221         ASAP recognizes the data of the "AT" telescopes, but currently
00222         does not know about the GBT or any other telescope. This task
00223         does know about GBT. Telescope name is obtained from the data.
00224         If you wish to change the fluxunit (see below), by leaving
00225         the sub-parameter telescopeparm unset (telescopeparm=''),
00226         it will use internal telescope parameters for
00227         flux conversion for the data from AT telescopes and it will use an
00228         approximate aperture efficiency conversion for the GBT data.
00229         If you give telescopeparm a list, then if the list has a single 
00230         float it is assumed to be the gain in Jy/K, if two or more elements 
00231         they are assumed to be telescope diameter (m) and aperture efficiency
00232         respectively.
00233 
00234         Note that sdcal assumes that the fluxunit is set correctly in
00235         the data already.  If not, then set telescopeparm='FIX' and it
00236         will set the default units to fluxunit without conversion.
00237         NOTE: If the data in infile is an ms from GBT and the default flux
00238         unit is missing, this task automatically fixes the default fluxunit
00239         to 'K' before the conversion.
00240 
00241         Two new calmode, 'otf' and 'otfraster', are available. If you 
00242         specify those modes, the task first try to define several scans 
00243         near edge as OFF scans, then the data are calibrated using those 
00244         OFF scans. Those modes are designed for OTF observations without 
00245         explicit OFF scans. If the observing pattern is 'raster', you 
00246         should use the 'otfraster' mode to calibrate data. Otherwise, the 
00247         'otf' mode should be used. For detail about edge marking, see 
00248         online help of sd.edgemarker module.
00249 
00250         WARNING for the GBT raw SDFITS format data as input:
00251         SDtasks are able to handle GBT raw SDFITS format data since the 
00252         data filler is available. However, the functionality is not well 
00253         tested yet, so that there may be unknown bugs. 
00254 
00255   
00256         """
00257         if not hasattr(self, "__globals__") or self.__globals__ == None :
00258            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00259         #casac = self.__globals__['casac']
00260         casalog = self.__globals__['casalog']
00261         #casalog = casac.casac.logsink()
00262         self.__globals__['__last_task'] = 'sdcal'
00263         self.__globals__['taskname'] = 'sdcal'
00264         ###
00265         self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__)
00266         ###
00267         ###
00268         #Handle globals or user over-ride of arguments
00269         #
00270         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00271         useLocalDefaults = False
00272 
00273         for item in function_signature_defaults.iteritems():
00274                 key,val = item
00275                 keyVal = eval(key)
00276                 if (keyVal == None):
00277                         #user hasn't set it - use global/default
00278                         pass
00279                 else:
00280                         #user has set it - use over-ride
00281                         if (key != 'self') :
00282                            useLocalDefaults = True
00283 
00284         myparams = {}
00285         if useLocalDefaults :
00286            for item in function_signature_defaults.iteritems():
00287                key,val = item
00288                keyVal = eval(key)
00289                exec('myparams[key] = keyVal')
00290                self.parameters[key] = keyVal
00291                if (keyVal == None):
00292                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00293                    keyVal = eval(key)
00294                    if(type(keyVal) == dict) :
00295                       if len(keyVal) > 0 :
00296                          exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00297                       else :
00298                          exec('myparams[key] = ' + key + ' = {}')
00299 
00300         else :
00301             async = self.parameters['async']
00302             myparams['infile'] = infile = self.parameters['infile']
00303             myparams['antenna'] = antenna = self.parameters['antenna']
00304             myparams['fluxunit'] = fluxunit = self.parameters['fluxunit']
00305             myparams['telescopeparm'] = telescopeparm = self.parameters['telescopeparm']
00306             myparams['specunit'] = specunit = self.parameters['specunit']
00307             myparams['frame'] = frame = self.parameters['frame']
00308             myparams['doppler'] = doppler = self.parameters['doppler']
00309             myparams['calmode'] = calmode = self.parameters['calmode']
00310             myparams['fraction'] = fraction = self.parameters['fraction']
00311             myparams['noff'] = noff = self.parameters['noff']
00312             myparams['width'] = width = self.parameters['width']
00313             myparams['elongated'] = elongated = self.parameters['elongated']
00314             myparams['markonly'] = markonly = self.parameters['markonly']
00315             myparams['plotpointings'] = plotpointings = self.parameters['plotpointings']
00316             myparams['scanlist'] = scanlist = self.parameters['scanlist']
00317             myparams['field'] = field = self.parameters['field']
00318             myparams['iflist'] = iflist = self.parameters['iflist']
00319             myparams['pollist'] = pollist = self.parameters['pollist']
00320             myparams['channelrange'] = channelrange = self.parameters['channelrange']
00321             myparams['scanaverage'] = scanaverage = self.parameters['scanaverage']
00322             myparams['timeaverage'] = timeaverage = self.parameters['timeaverage']
00323             myparams['tweight'] = tweight = self.parameters['tweight']
00324             myparams['averageall'] = averageall = self.parameters['averageall']
00325             myparams['polaverage'] = polaverage = self.parameters['polaverage']
00326             myparams['pweight'] = pweight = self.parameters['pweight']
00327             myparams['tau'] = tau = self.parameters['tau']
00328             myparams['verify'] = verify = self.parameters['verify']
00329             myparams['outfile'] = outfile = self.parameters['outfile']
00330             myparams['outform'] = outform = self.parameters['outform']
00331             myparams['overwrite'] = overwrite = self.parameters['overwrite']
00332             myparams['plotlevel'] = plotlevel = self.parameters['plotlevel']
00333 
00334         if type(scanlist)==int: scanlist=[scanlist]
00335         if type(iflist)==int: iflist=[iflist]
00336         if type(pollist)==int: pollist=[pollist]
00337         if type(channelrange)==int: channelrange=[channelrange]
00338 
00339         result = None
00340 
00341 #
00342 #    The following is work around to avoid a bug with current python translation
00343 #
00344         mytmp = {}
00345 
00346         mytmp['infile'] = infile
00347         mytmp['antenna'] = antenna
00348         mytmp['fluxunit'] = fluxunit
00349         mytmp['telescopeparm'] = telescopeparm
00350         mytmp['specunit'] = specunit
00351         mytmp['frame'] = frame
00352         mytmp['doppler'] = doppler
00353         mytmp['calmode'] = calmode
00354         mytmp['fraction'] = fraction
00355         mytmp['noff'] = noff
00356         mytmp['width'] = width
00357         mytmp['elongated'] = elongated
00358         mytmp['markonly'] = markonly
00359         mytmp['plotpointings'] = plotpointings
00360         mytmp['scanlist'] = scanlist
00361         mytmp['field'] = field
00362         mytmp['iflist'] = iflist
00363         mytmp['pollist'] = pollist
00364         mytmp['channelrange'] = channelrange
00365         mytmp['scanaverage'] = scanaverage
00366         mytmp['timeaverage'] = timeaverage
00367         mytmp['tweight'] = tweight
00368         mytmp['averageall'] = averageall
00369         mytmp['polaverage'] = polaverage
00370         mytmp['pweight'] = pweight
00371         mytmp['tau'] = tau
00372         mytmp['verify'] = verify
00373         mytmp['outfile'] = outfile
00374         mytmp['outform'] = outform
00375         mytmp['overwrite'] = overwrite
00376         mytmp['plotlevel'] = plotlevel
00377         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00378         trec = casac.casac.utils().torecord(pathname+'sdcal.xml')
00379 
00380         casalog.origin('sdcal')
00381         try :
00382           #if not trec.has_key('sdcal') or not casac.casac.utils().verify(mytmp, trec['sdcal']) :
00383             #return False
00384 
00385           casac.casac.utils().verify(mytmp, trec['sdcal'], True)
00386           scriptstr=['']
00387           saveinputs = self.__globals__['saveinputs']
00388           saveinputs('sdcal', 'sdcal.last', myparams, self.__globals__,scriptstr=scriptstr)
00389           if async :
00390             count = 0
00391             keybase =  time.strftime("%y%m%d.%H%M%S")
00392             key = keybase + "_" + str(count)
00393             while self.__async__.has_key(key) :
00394                count += 1
00395                key = keybase + "_" + str(count)
00396             result = tm.execute('sdcal', infile, antenna, fluxunit, telescopeparm, specunit, frame, doppler, calmode, fraction, noff, width, elongated, markonly, plotpointings, scanlist, field, iflist, pollist, channelrange, scanaverage, timeaverage, tweight, averageall, polaverage, pweight, tau, verify, outfile, outform, overwrite, plotlevel)
00397             print "Use: "
00398             print "      tm.retrieve(return_value) # to retrieve the status"
00399             print 
00400             self.rkey = key
00401             self.__async__[key] = result
00402           else :
00403               tname = 'sdcal'
00404               spaces = ' '*(18-len(tname))
00405               casalog.post('\n##########################################'+
00406                            '\n##### Begin Task: ' + tname + spaces + ' #####')
00407               casalog.post(scriptstr[1][1:]+'\n', 'INFO')
00408               result = sdcal(infile, antenna, fluxunit, telescopeparm, specunit, frame, doppler, calmode, fraction, noff, width, elongated, markonly, plotpointings, scanlist, field, iflist, pollist, channelrange, scanaverage, timeaverage, tweight, averageall, polaverage, pweight, tau, verify, outfile, outform, overwrite, plotlevel)
00409               casalog.post('##### End Task: ' + tname + '  ' + spaces + ' #####'+
00410                            '\n##########################################')
00411 
00412         except Exception, instance:
00413           if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) :
00414              raise
00415           else :
00416              #print '**** Error **** ',instance
00417              tname = 'sdcal'
00418              casalog.post('An error occurred running task '+tname+'.', 'ERROR')
00419              pass
00420 
00421         gc.collect()
00422         return result
00423 #
00424 #
00425 #
00426     def paramgui(self, useGlobals=True, ipython_globals=None):
00427         """
00428         Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00429         """
00430         import paramgui
00431         if not hasattr(self, "__globals__") or self.__globals__ == None :
00432            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00433 
00434         if useGlobals:
00435             if ipython_globals == None:
00436                 myf=self.__globals__
00437             else:
00438                 myf=ipython_globals
00439 
00440             paramgui.setGlobals(myf)
00441         else:
00442             paramgui.setGlobals({})
00443 
00444         paramgui.runTask('sdcal', myf['_ip'])
00445         paramgui.setGlobals({})
00446 
00447 #
00448 #
00449 #
00450     def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None):
00451         if not hasattr(self, "__globals__") or self.__globals__ == None :
00452            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00453         if ipython_globals == None:
00454             myf=self.__globals__
00455         else:
00456             myf=ipython_globals
00457 
00458         a = odict()
00459         a['infile']  = ''
00460         a['antenna']  = 0
00461         a['fluxunit']  = ''
00462         a['specunit']  = ''
00463         a['frame']  = ''
00464         a['doppler']  = ''
00465         a['calmode']  = 'none'
00466         a['scanlist']  = []
00467         a['field']  = ''
00468         a['iflist']  = []
00469         a['pollist']  = []
00470         a['channelrange']  = []
00471         a['scanaverage']  = False
00472         a['timeaverage']  = False
00473         a['polaverage']  = False
00474         a['tau']  = 0.0
00475         a['verify']  = False
00476         a['outfile']  = ''
00477         a['outform']  = 'ASAP'
00478         a['overwrite']  = False
00479         a['plotlevel']  = 0
00480 
00481         a['async']=False
00482         a['fluxunit'] = {
00483                     0:{'value':''}, 
00484                     1:odict([{'value':'K'}, {'telescopeparm':''}]), 
00485                     2:odict([{'value':'k'}, {'telescopeparm':''}]), 
00486                     3:odict([{'value':'Jy'}, {'telescopeparm':''}]), 
00487                     4:odict([{'value':'jy'}, {'telescopeparm':''}])}
00488         a['timeaverage'] = {
00489                     0:{'value':False}, 
00490                     1:odict([{'value':True}, {'tweight':'none'}, {'averageall':False}])}
00491         a['polaverage'] = {
00492                     0:{'value':False}, 
00493                     1:odict([{'value':True}, {'pweight':'none'}])}
00494         a['calmode'] = {
00495                     0:{'value':'none'}, 
00496                     1:{'value':'ps'}, 
00497                     2:{'value':'nod'}, 
00498                     3:{'value':'fs'}, 
00499                     4:{'value':'fsotf'}, 
00500                     5:{'value':'quotient'}, 
00501                     6:odict([{'value':'otf'}, {'fraction':'10%'}, {'width':0.5}, {'elongated':False}, {'markonly':False}, {'plotpointings':False}]), 
00502                     7:odict([{'value':'otfraster'}, {'fraction':'10%'}, {'noff':-1}, {'markonly':False}, {'plotpointings':False}])}
00503 
00504 ### This function sets the default values but also will return the list of
00505 ### parameters or the default value of a given parameter
00506         if(param == None):
00507                 myf['__set_default_parameters'](a)
00508         elif(param == 'paramkeys'):
00509                 return a.keys()
00510         else:
00511             if(paramvalue==None and subparam==None):
00512                if(a.has_key(param)):
00513                   return a[param]
00514                else:
00515                   return self.itsdefault(param)
00516             else:
00517                retval=a[param]
00518                if(type(a[param])==dict):
00519                   for k in range(len(a[param])):
00520                      valornotval='value'
00521                      if(a[param][k].has_key('notvalue')):
00522                         valornotval='notvalue'
00523                      if((a[param][k][valornotval])==paramvalue):
00524                         retval=a[param][k].copy()
00525                         retval.pop(valornotval)
00526                         if(subparam != None):
00527                            if(retval.has_key(subparam)):
00528                               retval=retval[subparam]
00529                            else:
00530                               retval=self.itsdefault(subparam)
00531                      else:
00532                         retval=self.itsdefault(subparam)
00533                return retval
00534 
00535 
00536 #
00537 #
00538     def check_params(self, param=None, value=None, ipython_globals=None):
00539       if ipython_globals == None:
00540           myf=self.__globals__
00541       else:
00542           myf=ipython_globals
00543 #      print 'param:', param, 'value:', value
00544       try :
00545          if str(type(value)) != "<type 'instance'>" :
00546             value0 = value
00547             value = myf['cu'].expandparam(param, value)
00548             matchtype = False
00549             if(type(value) == numpy.ndarray):
00550                if(type(value) == type(value0)):
00551                   myf[param] = value.tolist()
00552                else:
00553                   #print 'value:', value, 'value0:', value0
00554                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00555                   myf[param] = value0
00556                   if type(value0) != list :
00557                      matchtype = True
00558             else :
00559                myf[param] = value
00560             value = myf['cu'].verifyparam({param:value})
00561             if matchtype:
00562                value = False
00563       except Exception, instance:
00564          #ignore the exception and just return it unchecked
00565          myf[param] = value
00566       return value
00567 #
00568 #
00569     def description(self, key='sdcal', subkey=None):
00570         desc={'sdcal': 'ASAP SD task: do data selection, calibration, and averaging',
00571                'infile': 'name of input SD dataset',
00572                'antenna': 'antenna name or id (only effective for MS input)',
00573                'fluxunit': 'units for line flux (K,Jy) (''=current)',
00574                'telescopeparm': 'param of telescope for flux conversion',
00575                'specunit': 'units for spectral axis (channel,km/s,GHz,''=current)',
00576                'frame': 'frequency reference frame, e.g. LSRK (''=current)',
00577                'doppler': 'doppler convention, e.g. RADIO (''=current)',
00578                'calmode': 'SD calibration mode (ps,nod,otf,otfraster,fs,fsotf,quotient,none)',
00579                'fraction': 'fraction of the OFF data to mark',
00580                'noff': 'number of the OFF data to mark',
00581                'width': 'width of the pixel for edge detection',
00582                'elongated': 'whether observed area is elongated in one direction or not',
00583                'markonly': 'do calibration (False) or just mark OFF (True)',
00584                'plotpointings': 'plot pointing direction for ON and OFF',
00585                'scanlist': 'list of scans to use (e.g. [1,2,3,4])',
00586                'field': 'string for selection by source name',
00587                'iflist': 'list of IF ids to select (e.g. [0,1])',
00588                'pollist': 'list of polarization ids to select (e.g. [0,1])',
00589                'channelrange': 'channel range selection (e.g. [0,5000])',
00590                'scanaverage': 'average integs within scans (True,False) ',
00591                'timeaverage': 'average scans over time (True,False)',
00592                'tweight': 'weighting for time averaging',
00593                'averageall': 'set True only when averaging spectra with different spectral resolutions',
00594                'polaverage': 'average over polarizations (True,False)',
00595                'pweight': 'weighting for polarization averaging',
00596                'tau': 'atmospheric optical depth for correction',
00597                'verify': 'verify the results of calibration',
00598                'outfile': 'output file name',
00599                'outform': 'output file format (ASCII,MS,SDFITS,ASAP)',
00600                'overwrite': 'overwrite the output file if already exists',
00601                'plotlevel': 'plot results (0=none,1+=some,<0=hardcopy)',
00602 
00603                'async': 'If true the taskname must be started using sdcal(...)'
00604               }
00605 
00606 #
00607 # Set subfields defaults if needed
00608 #
00609 
00610         if(desc.has_key(key)) :
00611            return desc[key]
00612 
00613     def itsdefault(self, paramname) :
00614         a = {}
00615         a['infile']  = ''
00616         a['antenna']  = 0
00617         a['fluxunit']  = ''
00618         a['telescopeparm']  = ''
00619         a['specunit']  = ''
00620         a['frame']  = ''
00621         a['doppler']  = ''
00622         a['calmode']  = 'none'
00623         a['fraction']  = '10%'
00624         a['noff']  = -1
00625         a['width']  = 0.5
00626         a['elongated']  = False
00627         a['markonly']  = False
00628         a['plotpointings']  = False
00629         a['scanlist']  = []
00630         a['field']  = ''
00631         a['iflist']  = []
00632         a['pollist']  = []
00633         a['channelrange']  = []
00634         a['scanaverage']  = False
00635         a['timeaverage']  = False
00636         a['tweight']  = 'none'
00637         a['averageall']  = False
00638         a['polaverage']  = False
00639         a['pweight']  = 'none'
00640         a['tau']  = 0.0
00641         a['verify']  = False
00642         a['outfile']  = ''
00643         a['outform']  = 'ASAP'
00644         a['overwrite']  = False
00645         a['plotlevel']  = 0
00646 
00647         #a = sys._getframe(len(inspect.stack())-1).f_globals
00648 
00649         if self.parameters['fluxunit']  == 'K':
00650             a['telescopeparm'] = ''
00651 
00652         if self.parameters['fluxunit']  == 'k':
00653             a['telescopeparm'] = ''
00654 
00655         if self.parameters['fluxunit']  == 'Jy':
00656             a['telescopeparm'] = ''
00657 
00658         if self.parameters['fluxunit']  == 'jy':
00659             a['telescopeparm'] = ''
00660 
00661         if self.parameters['timeaverage']  == True:
00662             a['tweight'] = 'none'
00663             a['averageall'] = False
00664 
00665         if self.parameters['polaverage']  == True:
00666             a['pweight'] = 'none'
00667 
00668         if self.parameters['calmode']  == 'otf':
00669             a['fraction'] = '10%'
00670             a['width'] = 0.5
00671             a['elongated'] = False
00672             a['markonly'] = False
00673             a['plotpointings'] = False
00674 
00675         if self.parameters['calmode']  == 'otfraster':
00676             a['fraction'] = '10%'
00677             a['noff'] = -1
00678             a['markonly'] = False
00679             a['plotpointings'] = False
00680 
00681         if a.has_key(paramname) :
00682               return a[paramname]
00683 sdcal_cli = sdcal_cli_()