casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdfit_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_sdfit import sdfit
00018 class sdfit_cli_:
00019     __name__ = "sdfit"
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__ = (sdfit_cli_,)
00028        self.__doc__ = self.__call__.__doc__
00029 
00030        self.parameters={'infile':None, 'antenna':None, 'fluxunit':None, 'telescopeparm':None, 'specunit':None, 'restfreq':None, 'frame':None, 'doppler':None, 'scanlist':None, 'field':None, 'iflist':None, 'pollist':None, 'fitfunc':None, 'fitmode':None, 'maskline':None, 'invertmask':None, 'nfit':None, 'thresh':None, 'min_nchan':None, 'avg_limit':None, 'box_size':None, 'edge':None, 'outfile':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, restfreq=None, frame=None, doppler=None, scanlist=None, field=None, iflist=None, pollist=None, fitfunc=None, fitmode=None, maskline=None, invertmask=None, nfit=None, thresh=None, min_nchan=None, avg_limit=None, box_size=None, edge=None, outfile=None, overwrite=None, plotlevel=None,  async=None):
00047 
00048         """ASAP SD task: fit a spectral line
00049         Keyword arguments:
00050         infile -- name of input SD dataset
00051                 default: none - must input file name
00052                 example: 'mysd.asap'
00053                          See sdcal for allowed formats.
00054         antenna -- antenna name or id (only effective for MS input). 
00055         fluxunit -- units for line flux
00056                 options: (str) 'K','Jy',''
00057                 default: '' (keep current fluxunit)
00058                 WARNING: For GBT data, see description below.
00059             >>> fluxunit expandable parameter
00060                  telescopeparm -- the telescope characteristics
00061                         options: (str) name or (list) list of gain info
00062                         default: '' (none set)
00063                         example: if telescopeparm='', it tries to get the telescope
00064                                  name from the data.
00065                                  Full antenna parameters (diameter,ap.eff.) known
00066                                  to ASAP are
00067                                  'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43',
00068                                  'CEDUNA','HOBART'. For GBT, it fixes default fluxunit
00069                                  to 'K' first then convert to a new fluxunit.
00070                                  telescopeparm=[104.9,0.43] diameter(m), ap.eff.
00071                                  telescopeparm=[0.743] gain in Jy/K
00072                                  telescopeparm='FIX' to change default fluxunit
00073                                  see description below
00074 
00075         specunit -- units for spectral axis
00076                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz',''
00077                 default: '' (=current)
00078                 example: this will be the units for maskline
00079             >>> specunit expandable parameters
00080                  restfreq -- rest frequency
00081                          available type includes float, int, string, list of float, 
00082                          list of int, list of string, and list of dictionary. the 
00083                          default unit of restfreq in case of float, int, or string 
00084                          without unit is Hz. string input can be a value only 
00085                          (treated as Hz) or a value followed by unit for which 'GHz',
00086                          'MHz','kHz',and 'Hz' are available. 
00087                          a list can be used to set different rest frequencies for 
00088                          each IF. the length of list input must be nIF. dictionary 
00089                          input should be a pair of molecule name and frequency with 
00090                          keys of 'name' and 'value', respectively. values in the 
00091                          dictionary input follows the same manner as for single 
00092                          float or string input. 
00093                          example: 345.796
00094                                   '1420MHz'
00095                                   [345.8, 347.0, 356.7]
00096                                   ['345.8MHz', '347.0MHz', '356.7MHz']
00097                                   [{'name':'CO','value':345}]
00098         frame -- frequency frame for spectral axis
00099                 options: (str) 'LSRK','REST','TOPO','LSRD','BARY',
00100                          'GEO','GALACTO','LGROUP','CMB'
00101                 default: currently set frame in scantable
00102                 WARNING: frame='REST' not yet implemented
00103         doppler -- doppler mode
00104                 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA'
00105                 default: currently set doppler in scantable
00106         scanlist -- list of scan numbers to process
00107                 default: [] (use all scans)
00108                 example: [21,22,23,24]
00109         field -- selection string for selecting scans by name
00110                 default: '' (no name selection)
00111                 example: 'FLS3a*'
00112                 this selection is in addition to scanlist and iflist
00113         iflist -- list of IF id numbers to select
00114                 default: [] (use all IFs)
00115                 example: [15]
00116         pollist -- list of polarization id numbers to select
00117                 default: [] (use all polarizations)
00118                 example: [1]
00119         fitfunc -- function for fitting
00120                 options: (str) 'gauss','lorentz'
00121                 default: 'gauss'
00122         fitmode -- mode for fitting
00123                 options: (str) 'list','auto','interact'
00124                 default: 'auto'
00125                 example: 'list' will use maskline to define regions to
00126                                 fit for lines with nfit in each
00127                          'auto' will use the linefinder to fit for lines
00128                                 using the following parameters
00129                          'interact' allows adding and deleting mask 
00130                                 regions by drawing rectangles on the plot 
00131                                 with mouse. Draw a rectangle with LEFT-mouse 
00132                                 to ADD the region to the mask and with RIGHT-mouse 
00133                                 to DELETE the region. 
00134 
00135             >>> fitmode expandable parameters             
00136                  thresh -- S/N threshold for linefinder
00137                          default: 5
00138                          example: a single channel S/N ratio above which the channel is
00139                                   considered to be a detection
00140                  min_nchan -- minimum number of consecutive channels for linefinder
00141                          default: 3
00142                          example: minimum number of consecutive channels required to pass threshold
00143                  avg_limit -- channel averaging for broad lines
00144                          default: 4
00145                          example: a number of consecutive channels not greater than
00146                                   this parameter can be averaged to search for broad lines
00147                  box_size -- running mean box size
00148                          default: 0.2
00149                          example: a running mean box size specified as a fraction
00150                                   of the total spectrum length
00151                  edge -- channels to drop at beginning and end of spectrum
00152                          default: 0
00153                          example: [1000] drops 1000 channels at beginning AND end
00154                                   [1000,500] drops 1000 from beginning and 500 from end
00155 
00156                  Note: For bad baselines threshold should be increased,
00157                  and avg_limit decreased (or even switched off completely by
00158                  setting this parameter to 1) to avoid detecting baseline
00159                  undulations instead of real lines.
00160 
00161         maskline -- list of mask regions to INCLUDE in LINE fitting
00162                 default: all
00163                 example: maskline=[[3900,4300]] for a single region, or
00164                          maskline=[[3900,4300],[5000,5400]] for two, etc.
00165         invertmask -- invert mask (EXCLUDE masklist instead)
00166                 options: (bool) True, False
00167                 default: False
00168                 example: invertmask=True, then will make one region that is
00169                          the exclusion of the maskline regions
00170         nfit -- list of number of gaussian/lorentzian lines to fit in in maskline region (ignored when fitmode='auto')
00171                 default: 0 (no fitting)
00172                 example: nfit=[1] for single line in single region,
00173                          nfit=[2] for two lines in single region,
00174                          nfit=[1,1] for single lines in each of two regions, etc.
00175         outfile -- name of output file for fit results
00176                 default: no output fit file
00177                 example: 'mysd.fit'
00178         overwrite -- overwrite the outfile if already exists
00179                 options: (bool) True, False
00180                 default: False
00181         plotlevel -- control for plotting of results
00182                 options: (int) 0=none, 1=some, 2=more
00183                 default: 0 (no plotting)
00184                 example: plotlevel=1 plots fit
00185                          plotlevel=2 plots fit and residual 
00186                          no hardcopy available for fitter
00187                 WARNING: be careful plotting OTF data with lots of fields
00188 
00189         -------------------------------------------------------------------
00190         Returns a Python dictionary of line statistics
00191                 keys:    'peak','cent','fwhm','nfit'
00192                 example: each value is a list of lists with one list of
00193                          2 entries [fitvalue,error] per component.
00194                          e.g. xstat['peak']=[[234.9, 4.8],[234.2, 5.3]]
00195                          for 2 components.
00196 
00197 
00198         DESCRIPTION:
00199 
00200         Task sdfit is a basic line-fitter for single-dish spectra.
00201         It assumes that the spectra have been calibrated in sdcal
00202         or sdreduce.
00203 
00204         Furthermore, it assumes that any selection of scans, IFs,
00205         polarizations, and time and channel averaging/smoothing has
00206         also already been done (in other sd tasks) as there are no controls
00207         for these.  Note that you can use sdsave to do selection, writing
00208         out a new scantable.
00209 
00210         Note that multiple scans, IFs, and polarizations can in principle 
00211         be handled, but we recommend that you use scanlist, field, iflist, 
00212         and pollist to give a single selection for each fit.
00213 
00214         Currently, you can choose Gaussian or Lorentzian profile as a 
00215         fitting model. 
00216 
00217         For complicated spectra, sdfit does not do a good job of
00218         "auto-guessing" the starting model for the fit.  We recommend
00219         you use sd.fitter in the toolkit which has more options, such
00220         as fixing components in the fit and supplying starting guesses
00221         by hand.
00222 
00223         WARNING: sdfit will currently return the fit for the first
00224         row in the scantable.
00225 
00226         ASAP recognizes the data of the "AT" telescopes, but currently
00227         does not know about the GBT or any other telescope. This task
00228         does know about GBT. Telescope name is obtained from the data.
00229         If you wish to change the fluxunit (see below), and telescopeparm='',
00230         for the AT telescopes it will use internal telescope parameters for
00231         flux conversion. For GBT, it will use an approximate aperture
00232         efficiency conversion.  If you give telescopeparm a list, then 
00233         if the list has a single float it is assumed to be the gain in Jy/K, 
00234         if two or more elements they are assumed to be telescope diameter (m) 
00235         and aperture efficiency respectively.
00236 
00237         WARNING for the GBT raw SDFITS format data as input:
00238         SDtasks are able to handle GBT raw SDFITS format data since the 
00239         data filler is available. However, the functionality is not well 
00240         tested yet, so that there may be unknown bugs.  
00241 
00242   
00243         """
00244         if not hasattr(self, "__globals__") or self.__globals__ == None :
00245            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00246         #casac = self.__globals__['casac']
00247         casalog = self.__globals__['casalog']
00248         #casalog = casac.casac.logsink()
00249         self.__globals__['__last_task'] = 'sdfit'
00250         self.__globals__['taskname'] = 'sdfit'
00251         ###
00252         self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__)
00253         ###
00254         ###
00255         #Handle globals or user over-ride of arguments
00256         #
00257         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00258         useLocalDefaults = False
00259 
00260         for item in function_signature_defaults.iteritems():
00261                 key,val = item
00262                 keyVal = eval(key)
00263                 if (keyVal == None):
00264                         #user hasn't set it - use global/default
00265                         pass
00266                 else:
00267                         #user has set it - use over-ride
00268                         if (key != 'self') :
00269                            useLocalDefaults = True
00270 
00271         myparams = {}
00272         if useLocalDefaults :
00273            for item in function_signature_defaults.iteritems():
00274                key,val = item
00275                keyVal = eval(key)
00276                exec('myparams[key] = keyVal')
00277                self.parameters[key] = keyVal
00278                if (keyVal == None):
00279                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00280                    keyVal = eval(key)
00281                    if(type(keyVal) == dict) :
00282                       if len(keyVal) > 0 :
00283                          exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00284                       else :
00285                          exec('myparams[key] = ' + key + ' = {}')
00286 
00287         else :
00288             async = self.parameters['async']
00289             myparams['infile'] = infile = self.parameters['infile']
00290             myparams['antenna'] = antenna = self.parameters['antenna']
00291             myparams['fluxunit'] = fluxunit = self.parameters['fluxunit']
00292             myparams['telescopeparm'] = telescopeparm = self.parameters['telescopeparm']
00293             myparams['specunit'] = specunit = self.parameters['specunit']
00294             myparams['restfreq'] = restfreq = self.parameters['restfreq']
00295             myparams['frame'] = frame = self.parameters['frame']
00296             myparams['doppler'] = doppler = self.parameters['doppler']
00297             myparams['scanlist'] = scanlist = self.parameters['scanlist']
00298             myparams['field'] = field = self.parameters['field']
00299             myparams['iflist'] = iflist = self.parameters['iflist']
00300             myparams['pollist'] = pollist = self.parameters['pollist']
00301             myparams['fitfunc'] = fitfunc = self.parameters['fitfunc']
00302             myparams['fitmode'] = fitmode = self.parameters['fitmode']
00303             myparams['maskline'] = maskline = self.parameters['maskline']
00304             myparams['invertmask'] = invertmask = self.parameters['invertmask']
00305             myparams['nfit'] = nfit = self.parameters['nfit']
00306             myparams['thresh'] = thresh = self.parameters['thresh']
00307             myparams['min_nchan'] = min_nchan = self.parameters['min_nchan']
00308             myparams['avg_limit'] = avg_limit = self.parameters['avg_limit']
00309             myparams['box_size'] = box_size = self.parameters['box_size']
00310             myparams['edge'] = edge = self.parameters['edge']
00311             myparams['outfile'] = outfile = self.parameters['outfile']
00312             myparams['overwrite'] = overwrite = self.parameters['overwrite']
00313             myparams['plotlevel'] = plotlevel = self.parameters['plotlevel']
00314 
00315         if type(scanlist)==int: scanlist=[scanlist]
00316         if type(iflist)==int: iflist=[iflist]
00317         if type(pollist)==int: pollist=[pollist]
00318         if type(nfit)==int: nfit=[nfit]
00319         if type(edge)==int: edge=[edge]
00320 
00321         result = None
00322 
00323 #
00324 #    The following is work around to avoid a bug with current python translation
00325 #
00326         mytmp = {}
00327 
00328         mytmp['infile'] = infile
00329         mytmp['antenna'] = antenna
00330         mytmp['fluxunit'] = fluxunit
00331         mytmp['telescopeparm'] = telescopeparm
00332         mytmp['specunit'] = specunit
00333         mytmp['restfreq'] = restfreq
00334         mytmp['frame'] = frame
00335         mytmp['doppler'] = doppler
00336         mytmp['scanlist'] = scanlist
00337         mytmp['field'] = field
00338         mytmp['iflist'] = iflist
00339         mytmp['pollist'] = pollist
00340         mytmp['fitfunc'] = fitfunc
00341         mytmp['fitmode'] = fitmode
00342         mytmp['maskline'] = maskline
00343         mytmp['invertmask'] = invertmask
00344         mytmp['nfit'] = nfit
00345         mytmp['thresh'] = thresh
00346         mytmp['min_nchan'] = min_nchan
00347         mytmp['avg_limit'] = avg_limit
00348         mytmp['box_size'] = box_size
00349         mytmp['edge'] = edge
00350         mytmp['outfile'] = outfile
00351         mytmp['overwrite'] = overwrite
00352         mytmp['plotlevel'] = plotlevel
00353         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00354         trec = casac.casac.utils().torecord(pathname+'sdfit.xml')
00355 
00356         casalog.origin('sdfit')
00357         try :
00358           #if not trec.has_key('sdfit') or not casac.casac.utils().verify(mytmp, trec['sdfit']) :
00359             #return False
00360 
00361           casac.casac.utils().verify(mytmp, trec['sdfit'], True)
00362           scriptstr=['']
00363           saveinputs = self.__globals__['saveinputs']
00364           saveinputs('sdfit', 'sdfit.last', myparams, self.__globals__,scriptstr=scriptstr)
00365           if async :
00366             count = 0
00367             keybase =  time.strftime("%y%m%d.%H%M%S")
00368             key = keybase + "_" + str(count)
00369             while self.__async__.has_key(key) :
00370                count += 1
00371                key = keybase + "_" + str(count)
00372             result = tm.execute('sdfit', infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, fitfunc, fitmode, maskline, invertmask, nfit, thresh, min_nchan, avg_limit, box_size, edge, outfile, overwrite, plotlevel)
00373             print "Use: "
00374             print "      tm.retrieve(return_value) # to retrieve the status"
00375             print 
00376             self.rkey = key
00377             self.__async__[key] = result
00378           else :
00379               tname = 'sdfit'
00380               spaces = ' '*(18-len(tname))
00381               casalog.post('\n##########################################'+
00382                            '\n##### Begin Task: ' + tname + spaces + ' #####')
00383               casalog.post(scriptstr[1][1:]+'\n', 'INFO')
00384               result = sdfit(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, fitfunc, fitmode, maskline, invertmask, nfit, thresh, min_nchan, avg_limit, box_size, edge, outfile, overwrite, plotlevel)
00385               casalog.post('##### End Task: ' + tname + '  ' + spaces + ' #####'+
00386                            '\n##########################################')
00387 
00388         except Exception, instance:
00389           if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) :
00390              raise
00391           else :
00392              #print '**** Error **** ',instance
00393              tname = 'sdfit'
00394              casalog.post('An error occurred running task '+tname+'.', 'ERROR')
00395              pass
00396 
00397         gc.collect()
00398         return result
00399 #
00400 #
00401 #
00402     def paramgui(self, useGlobals=True, ipython_globals=None):
00403         """
00404         Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00405         """
00406         import paramgui
00407         if not hasattr(self, "__globals__") or self.__globals__ == None :
00408            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00409 
00410         if useGlobals:
00411             if ipython_globals == None:
00412                 myf=self.__globals__
00413             else:
00414                 myf=ipython_globals
00415 
00416             paramgui.setGlobals(myf)
00417         else:
00418             paramgui.setGlobals({})
00419 
00420         paramgui.runTask('sdfit', myf['_ip'])
00421         paramgui.setGlobals({})
00422 
00423 #
00424 #
00425 #
00426     def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None):
00427         if not hasattr(self, "__globals__") or self.__globals__ == None :
00428            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00429         if ipython_globals == None:
00430             myf=self.__globals__
00431         else:
00432             myf=ipython_globals
00433 
00434         a = odict()
00435         a['infile']  = ''
00436         a['antenna']  = 0
00437         a['fluxunit']  = ''
00438         a['specunit']  = ''
00439         a['frame']  = ''
00440         a['doppler']  = ''
00441         a['scanlist']  = []
00442         a['field']  = ''
00443         a['iflist']  = []
00444         a['pollist']  = []
00445         a['fitfunc']  = 'gauss'
00446         a['fitmode']  = 'auto'
00447         a['maskline']  = []
00448         a['invertmask']  = False
00449         a['nfit']  = []
00450         a['outfile']  = ''
00451         a['overwrite']  = False
00452         a['plotlevel']  = 0
00453 
00454         a['async']=False
00455         a['fluxunit'] = {
00456                     0:{'value':''}, 
00457                     1:odict([{'value':'K'}, {'telescopeparm':''}]), 
00458                     2:odict([{'value':'k'}, {'telescopeparm':''}]), 
00459                     3:odict([{'value':'Jy'}, {'telescopeparm':''}]), 
00460                     4:odict([{'value':'jy'}, {'telescopeparm':''}])}
00461         a['specunit'] = {
00462                     0:{'value':''}, 
00463                     1:{'value':'channel'}, 
00464                     2:{'value':'GHz'}, 
00465                     3:{'value':'MHz'}, 
00466                     4:{'value':'kHz'}, 
00467                     5:{'value':'Hz'}, 
00468                     6:odict([{'value':'km/s'}, {'restfreq':''}])}
00469         a['fitmode'] = {
00470                     0:odict([{'value':'auto'}, {'thresh':5.0}, {'min_nchan':3}, {'avg_limit':4}, {'box_size':0.2}, {'edge':[0]}]), 
00471                     1:{'value':'list'}, 
00472                     2:{'value':'interact'}}
00473 
00474 ### This function sets the default values but also will return the list of
00475 ### parameters or the default value of a given parameter
00476         if(param == None):
00477                 myf['__set_default_parameters'](a)
00478         elif(param == 'paramkeys'):
00479                 return a.keys()
00480         else:
00481             if(paramvalue==None and subparam==None):
00482                if(a.has_key(param)):
00483                   return a[param]
00484                else:
00485                   return self.itsdefault(param)
00486             else:
00487                retval=a[param]
00488                if(type(a[param])==dict):
00489                   for k in range(len(a[param])):
00490                      valornotval='value'
00491                      if(a[param][k].has_key('notvalue')):
00492                         valornotval='notvalue'
00493                      if((a[param][k][valornotval])==paramvalue):
00494                         retval=a[param][k].copy()
00495                         retval.pop(valornotval)
00496                         if(subparam != None):
00497                            if(retval.has_key(subparam)):
00498                               retval=retval[subparam]
00499                            else:
00500                               retval=self.itsdefault(subparam)
00501                      else:
00502                         retval=self.itsdefault(subparam)
00503                return retval
00504 
00505 
00506 #
00507 #
00508     def check_params(self, param=None, value=None, ipython_globals=None):
00509       if ipython_globals == None:
00510           myf=self.__globals__
00511       else:
00512           myf=ipython_globals
00513 #      print 'param:', param, 'value:', value
00514       try :
00515          if str(type(value)) != "<type 'instance'>" :
00516             value0 = value
00517             value = myf['cu'].expandparam(param, value)
00518             matchtype = False
00519             if(type(value) == numpy.ndarray):
00520                if(type(value) == type(value0)):
00521                   myf[param] = value.tolist()
00522                else:
00523                   #print 'value:', value, 'value0:', value0
00524                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00525                   myf[param] = value0
00526                   if type(value0) != list :
00527                      matchtype = True
00528             else :
00529                myf[param] = value
00530             value = myf['cu'].verifyparam({param:value})
00531             if matchtype:
00532                value = False
00533       except Exception, instance:
00534          #ignore the exception and just return it unchecked
00535          myf[param] = value
00536       return value
00537 #
00538 #
00539     def description(self, key='sdfit', subkey=None):
00540         desc={'sdfit': 'ASAP SD task: fit a spectral line',
00541                'infile': 'name of input SD dataset',
00542                'antenna': 'antenna name or id (only effective for MS input)',
00543                'fluxunit': 'units for line flux (K,Jy) (''=current)',
00544                'telescopeparm': 'param of telescope for flux conversion',
00545                'specunit': 'units for spectral axis (channel,km/s,GHz)',
00546                'restfreq': 'rest frequency (default unit: Hz)',
00547                'frame': 'frequency reference frame, e.g. LSRK (''=current)',
00548                'doppler': 'doppler convention, e.g. RADIO (''=current)',
00549                'scanlist': 'list of scans to use (e.g. [1,2,3,4])',
00550                'field': 'string for selection by source name',
00551                'iflist': 'list of IF ids to select (e.g. [0,1])',
00552                'pollist': 'list of polarization ids to select (e.g. [1])',
00553                'fitfunc': 'function for fitting',
00554                'fitmode': 'mode for fitting',
00555                'maskline': 'list of mask regions to INCLUDE in LINE fitting',
00556                'invertmask': 'invert mask (EXCLUDE masklist instead)',
00557                'nfit': 'list of number of gaussian/lorentzian lines to fit in in maskline region (ignored when fitmode="auto")',
00558                'thresh': 'S/N threshold for linefinder',
00559                'min_nchan': 'minimum number of consecutive channels for linefinder',
00560                'avg_limit': 'channel averaging for broad lines',
00561                'box_size': 'running mean box size',
00562                'edge': 'channels to drop at beginning and end of spectrum',
00563                'outfile': 'name of output file for fit results',
00564                'overwrite': 'overwrite the outfile if already exists',
00565                'plotlevel': 'control for plotting of results',
00566 
00567                'async': 'If true the taskname must be started using sdfit(...)'
00568               }
00569 
00570 #
00571 # Set subfields defaults if needed
00572 #
00573 
00574         if(desc.has_key(key)) :
00575            return desc[key]
00576 
00577     def itsdefault(self, paramname) :
00578         a = {}
00579         a['infile']  = ''
00580         a['antenna']  = 0
00581         a['fluxunit']  = ''
00582         a['telescopeparm']  = ''
00583         a['specunit']  = ''
00584         a['restfreq']  = ''
00585         a['frame']  = ''
00586         a['doppler']  = ''
00587         a['scanlist']  = []
00588         a['field']  = ''
00589         a['iflist']  = []
00590         a['pollist']  = []
00591         a['fitfunc']  = 'gauss'
00592         a['fitmode']  = 'auto'
00593         a['maskline']  = []
00594         a['invertmask']  = False
00595         a['nfit']  = []
00596         a['thresh']  = 5.0
00597         a['min_nchan']  = 3
00598         a['avg_limit']  = 4
00599         a['box_size']  = 0.2
00600         a['edge']  = [0]
00601         a['outfile']  = ''
00602         a['overwrite']  = False
00603         a['plotlevel']  = 0
00604 
00605         #a = sys._getframe(len(inspect.stack())-1).f_globals
00606 
00607         if self.parameters['fluxunit']  == 'K':
00608             a['telescopeparm'] = ''
00609 
00610         if self.parameters['fluxunit']  == 'k':
00611             a['telescopeparm'] = ''
00612 
00613         if self.parameters['fluxunit']  == 'Jy':
00614             a['telescopeparm'] = ''
00615 
00616         if self.parameters['fluxunit']  == 'jy':
00617             a['telescopeparm'] = ''
00618 
00619         if self.parameters['specunit']  == 'km/s':
00620             a['restfreq'] = ''
00621 
00622         if self.parameters['fitmode']  == 'auto':
00623             a['thresh'] = 5.0
00624             a['min_nchan'] = 3
00625             a['avg_limit'] = 4
00626             a['box_size'] = 0.2
00627             a['edge'] = [0]
00628 
00629         if a.has_key(paramname) :
00630               return a[paramname]
00631 sdfit_cli = sdfit_cli_()