casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdreduce_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_sdreduce import sdreduce
00018 class sdreduce_cli_:
00019     __name__ = "sdreduce"
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__ = (sdreduce_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, 'calmode':None, 'fraction':None, 'noff':None, 'width':None, 'elongated':None, 'markonly':None, 'plotpointings':None, 'scanlist':None, 'field':None, 'iflist':None, 'pollist':None, 'channelrange':None, 'average':None, 'scanaverage':None, 'timeaverage':None, 'tweight':None, 'averageall':None, 'polaverage':None, 'pweight':None, 'tau':None, 'kernel':None, 'kwidth':None, 'chanwidth':None, 'masklist':None, 'maskmode':None, 'thresh':None, 'avg_limit':None, 'edge':None, 'blfunc':None, 'order':None, 'npiece':None, 'applyfft':None, 'fftmethod':None, 'fftthresh':None, 'addwn':None, 'rejwn':None, 'clipthresh':None, 'clipniter':None, 'verifycal':None, 'verifysm':None, 'verifybl':None, 'verbosebl':None, 'bloutput':None, 'blformat':None, 'showprogress':None, 'minnrow':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, restfreq=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, average=None, scanaverage=None, timeaverage=None, tweight=None, averageall=None, polaverage=None, pweight=None, tau=None, kernel=None, kwidth=None, chanwidth=None, masklist=None, maskmode=None, thresh=None, avg_limit=None, edge=None, blfunc=None, order=None, npiece=None, applyfft=None, fftmethod=None, fftthresh=None, addwn=None, rejwn=None, clipthresh=None, clipniter=None, verifycal=None, verifysm=None, verifybl=None, verbosebl=None, bloutput=None, blformat=None, showprogress=None, minnrow=None, outfile=None, outform=None, overwrite=None, plotlevel=None,  async=None):
00047 
00048         """ASAP SD task: do sdcal, sdsmooth, and sdbaseline in one task
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             >>> fluxunit expandable parameter
00057                  telescopeparm -- the telescope characteristics
00058                         options: (str) name or (list) list of gain info
00059                         default: '' (none set)
00060                         example: if telescopeparm='', it tries to get the telescope
00061                                  name from the data.
00062                                  Full antenna parameters (diameter,ap.eff.) known
00063                                  to ASAP are
00064                                  'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43',
00065                                  'CEDUNA','HOBART'. For GBT, it fixes default fluxunit
00066                                  to 'K' first then convert to a new fluxunit.
00067                                  telescopeparm=[104.9,0.43] diameter(m), ap.eff.
00068                                  telescopeparm=[0.743] gain in Jy/K
00069                                  telescopeparm='FIX' to change default fluxunit
00070                                  see description below
00071 
00072         specunit -- units for spectral axis
00073                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz',''
00074                 default: '' (=current)
00075                 example: this will be the units for masklist
00076             >>> specunit expandable parameters
00077                  restfreq -- rest frequency
00078                          available type includes float, int, string, list of float, 
00079                          list of int, list of string, and list of dictionary. the 
00080                          default unit of restfreq in case of float, int, or string 
00081                          without unit is Hz. string input can be a value only 
00082                          (treated as Hz) or a value followed by unit for which 'GHz',
00083                          'MHz','kHz',and 'Hz' are available. 
00084                          a list can be used to set different rest frequencies for 
00085                          each IF. the length of list input must be nIF. dictionary 
00086                          input should be a pair of molecule name and frequency with 
00087                          keys of 'name' and 'value', respectively. values in the 
00088                          dictionary input follows the same manner as for single 
00089                          float or string input. 
00090                          example: 345.796
00091                                   '1420MHz'
00092                                   [345.8, 347.0, 356.7]
00093                                   ['345.8MHz', '347.0MHz', '356.7MHz']
00094                                   [{'name':'CO','value':345}]
00095         frame -- frequency frame for spectral axis
00096                 options: (str) 'LSRK','REST','TOPO','LSRD','BARY',
00097                          'GEO','GALACTO','LGROUP','CMB'
00098                 default: currently set frame in scantable
00099                 WARNING: frame='REST' not yet implemented
00100         doppler -- doppler mode
00101                 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA'
00102                 default: currently set doppler in scantable
00103         calmode -- calibration mode
00104                 options: 'ps','nod','fs','fsotf','quotient','none'
00105                 default: 'none'
00106                 example: choose mode 'none' if you have
00107                          already calibrated and want to
00108                          try baselines or averaging
00109             >>> calmode expandable parameter
00110                  fraction -- Edge marking parameter for 'otf' and 'otfraster'.
00111                              specify a number of OFF scans as a fraction of 
00112                              total number of data points. 
00113                          default: '10%'
00114                          options: '20%' in string style or float value less 
00115                                   than 1.0 (e.g. 0.15).
00116                                   'auto' is available only for 'otfraster'. 
00117                  noff -- Edge marking parameter for 'otfraster'.
00118                          It is used to specify a number of OFF scans near 
00119                          edge directly. Value of noff comes before setting 
00120                          by fraction.
00121                          default: -1 (use fraction)
00122                          options: any positive integer
00123                  width -- Edge marking parameter for 'otf'.
00124                           Pixel width with respect to a median spatial 
00125                           separation between neighboring two data in time.
00126                           Default will be fine in most cases.
00127                          default: 0.5
00128                          options: float value
00129                  elongated -- Edge marking parameter for 'otf'.
00130                               Set True only if observed area is elongeted 
00131                               in one direction.
00132                          default: False
00133                  markonly -- Set True if you want to save data just after 
00134                              edge marking (i.e. uncalibrated data) to see 
00135                              how OFF scans are defined.
00136                          default: False
00137         scanlist -- list of scan numbers to process
00138                 default: [] (use all scans)
00139                 example: [21,22,23,24]
00140                 this selection is in addition to field, iflist, and pollist
00141         field -- selection string for selecting scans by name
00142                 default: '' (no name selection)
00143                 example: 'FLS3a*'
00144                 this selection is in addition to scanlist, iflist, and pollist
00145         iflist -- list of IF id numbers to select
00146                 default: [] (use all IFs)
00147                 example: [15]
00148                 this selection is in addition to scanlist, field, and pollist
00149         pollist -- list of polarization id numbers to select
00150                 default: [] (use all polarizations)
00151                 example: [1]
00152                 this selection is in addition to scanlist, field, and iflist
00153         channelrange -- channel range selection
00154                 default: [] (use all channel)
00155                 example: [0,5000]
00156                 Note that specified values are recognized as 'channel' 
00157                 regardless of the value of specunit 
00158         average -- averaging on spectral data 
00159                 options: (bool) True,False
00160                 default: False
00161 
00162             >>>average expandable parameter
00163                  scanaverage -- average integrations within scans
00164                          options: (bool) True,False
00165                          default: False
00166                          example: if True, this happens in read-in
00167                          For GBT, set False!
00168                  timeaverage -- average times for multiple scan cycles
00169                          options: (bool) True,False
00170                          default: False
00171                          example: if True, this happens after calibration
00172                  tweight -- weighting for time average
00173                          options: 'none'
00174                                   'var'   (1/var(spec) weighted)
00175                                   'tsys'  (1/Tsys**2 weighted)
00176                                   'tint'  (integration time weighted)
00177                                   'tintsys'  (Tint/Tsys**2)
00178                                   'median'  ( median averaging)
00179                          default: 'none'
00180                  averageall -- average multi-resolution spectra
00181                                spectra are averaged by referring 
00182                                their frequency coverage
00183                          default: False
00184                  polaverage -- average polarizations
00185                          options: (bool) True,False
00186                          default: False
00187                  pweight -- weighting for polarization average
00188                          options: 'none'
00189                                   'var'  (1/var(spec) weighted)
00190                                   'tsys' (1/Tsys**2 weighted)
00191 
00192         tau -- atmospheric optical depth
00193                 default: 0.0 (no correction)
00194         kernel -- type of spectral smoothing
00195                 options: 'none','hanning','gaussian','boxcar','regrid'
00196                 default: 'none' (no smoothing)
00197 
00198             >>>kernel expandable parameter
00199                  kwidth -- width of spectral smoothing kernel
00200                          options: (int) in channels
00201                          default: 5
00202                          example: 5 or 10 seem to be popular for boxcar
00203                                   ignored for hanning (fixed at 5 chans)
00204                                   (0 will turn off gaussian or boxcar)
00205                  chanwidth -- channel width of regridded spectra
00206                          default: '5' (in channels)
00207                          example: '500MHz', '0.2km/s'
00208         masklist -- list or string of mask regions to INCLUDE in BASELINE fit
00209                     a string masklist allows per IF selection of channels.
00210                 default: [] (entire spectrum)
00211                 example: [[1000,3000],[5000,7000]]
00212                          '0:1000~3000;5000~7000, 1:200~350;450~600'
00213                          when maskmode is 'auto' or 'interact', this mask 
00214                          will be applied first before fitting as base mask
00215         maskmode -- mode of setting additional channel masks for baselining
00216                 options: (str) 'auto','list','interact'
00217                 default: 'auto'
00218                 example: maskmode='auto' runs linefinder to detect line regions 
00219                          to be excluded from fitting. this mode requires three 
00220                          expandable parameters: thresh, avg_limit, and edge.
00221                          USE WITH CARE! May need to tweak the expandable parameters.
00222                          maskmode='list' uses the given masklist only: 
00223                          no additional masks applied.
00224                          maskmode='interact' allows users to manually modify the 
00225                          mask regions by dragging mouse on the spectrum plotter GUI.
00226                          use LEFT or RIGHT button to add or delete regions, 
00227                          respectively.
00228 
00229             >>> maskmode expandable parameters
00230                  thresh -- S/N threshold for linefinder
00231                          default: 5
00232                          example: a single channel S/N ratio above which the channel is
00233                                   considered to be a detection
00234                  avg_limit -- channel averaging for broad lines
00235                          default: 4
00236                          example: a number of consecutive channels not greater than
00237                                   this parameter can be averaged to search for broad lines
00238                  edge -- channels to drop at beginning and end of spectrum
00239                          default: 0
00240                          example: [1000] drops 1000 channels at beginning AND end
00241                                   [1000,500] drops 1000 from beginning and 500 from end
00242 
00243                  Note: For bad baselines threshold should be increased,
00244                  and avg_limit decreased (or even switched off completely by
00245                  setting this parameter to 1) to avoid detecting baseline
00246                  undulations instead of real lines.
00247 
00248         blfunc -- baseline model function
00249                 options: (str) 'none','poly','chebyshev','cspline','sinusoid'
00250                 default: 'none' (no baselining)
00251                 example: blfunc='poly' uses a single polynomial line of 
00252                          any order which should be given as an expandable 
00253                          parameter 'order' to fit baseline. 
00254                          blfunc='chebyshev' uses Chebyshev polynomials. 
00255                          blfunc='cspline' uses a cubic spline function, a piecewise 
00256                          cubic polynomial having C2-continuity (i.e., the second 
00257                          derivative is continuous at the joining points).
00258                          blfunc='sinusoid' uses a combination of sinusoidal curves. 
00259             >>> blfunc expandable parameters
00260                  order -- order of baseline polynomial
00261                          options: (int) (<0 turns off baseline fitting)
00262                          default: 5
00263                          example: typically in range 2-9 (higher values
00264                                   seem to be needed for GBT)
00265                  npiece -- number of the element polynomials of cubic spline curve
00266                          options: (int) (<0 turns off baseline fitting)
00267                          default: 2
00268                  applyfft -- automatically set wave numbers of sinusoidal functions
00269                          for fitting by applying some method like FFT.
00270                          options: (bool) True, False
00271                          default: True
00272                  fftmethod -- method to be used when applyfft=True. Now only
00273                          'fft' is available and it is the default.
00274                  fftthresh -- threshold to select wave numbers to be used for
00275                          sinusoidal fitting. both (float) and (str) accepted.
00276                          given a float value, the unit is set to sigma.
00277                          for string values, allowed formats include:
00278                              'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or
00279                              'topx' (= the x strongest ones, e.g. 'top5').
00280                          default is 3.0 (unit: sigma).
00281                  addwn -- additional wave number(s) of sinusoids to be used
00282                          for fitting.
00283                          (list) and (int) are accepted to specify every
00284                          wave numbers. also (str) can be used in case
00285                          you need to specify wave numbers in a certain range,
00286                          e.g., 'a-b' (= a, a+1, a+2, ..., b-1, b),
00287                                '<a'  (= 0,1,...,a-2,a-1),
00288                                '>=a' (= a, a+1, ... up to the maximum wave
00289                                       number corresponding to the Nyquist
00290                                       frequency for the case of FFT).
00291                          default: []
00292                  rejwn -- wave number(s) of sinusoid NOT to be used for fitting.
00293                          can be set just as addwn but has higher priority:
00294                          wave numbers which are specified both in addwn
00295                          and rejwn will NOT be used.
00296                          default: []
00297                  clipthresh -- clipping threshold for iterative fitting
00298                          default: 3
00299                  clipniter -- maximum iteration number
00300                          default: 0 (no iteration, i.e., no clipping)
00301 
00302         verifycal -- verify the results of calibration
00303                 options: (bool) True,False
00304                 default: False
00305                 WARNING: Currently verifying parameters just asks whether you 
00306                          accept the displayed calibraion/fit and if not, 
00307                          continues without doing any calibraion/baseline fit.
00308         verifysm -- verify the results of smoothing
00309                 options: (bool) True,False
00310                 default: False
00311                 Note: verification is not yet available for kernel='regrid'
00312         verifybl -- verify the results of baseline fitting
00313                 options: (bool) True,False
00314                 default: False
00315                 NOTE: Currently available only when blfunc='poly'
00316         verbosebl -- output fitting results to logger
00317                 default: True
00318                 example: If False, the fitting results including coefficients, 
00319                          residual rms, etc., are not output to the CASA logger, 
00320                          while the processing speed gets faster
00321         bloutput -- output fitting results to a text file
00322                 default: True
00323                 example: If False, the fitting results including coefficients, 
00324                          residual rms, etc., are not output to a text file 
00325                          (<outfile>_blparam.txt), while the processing 
00326                          speed gets faster
00327         blformat -- format of the logger output and text file specified with bloutput
00328                 options: '', 'csv'
00329                 default: '' (same as in the past, easy to read but huge)
00330         showprogress -- show progress status for large data
00331                 default: True
00332         minnrow -- minimum number of input spectra to show progress status
00333                 default: 1000
00334         outfile -- Name of output file
00335                 default: '' (<infile>_cal)
00336         outform -- format of output file
00337                 options: 'ASCII','SDFITS','MS','ASAP'
00338                 default: 'ASAP'
00339                 example: the ASAP format is easiest for further sd
00340                          processing; use MS for CASA imaging.
00341                          If ASCII, then will append some stuff to
00342                          the outfile name
00343         overwrite -- overwrite the output file if already exists
00344                 options: (bool) True,False
00345                 default: False
00346                 WARNING: if outform='ASCII', this parameter is ignored
00347         plotlevel -- control for plotting of results
00348                 options: (int) 0=none, 1=some, 2=more, <0=hardcopy
00349                 default: 0 (no plotting)
00350                 example: plotlevel<0 as abs(plotlevel), e.g.
00351                          -1 => hardcopy of final plot (will be named
00352                          <outfile>_calspec.eps)
00353                 WARNING: be careful plotting in fsotf mode!
00354 
00355 
00356         DESCRIPTION:
00357 
00358         Task sdreduce performs data selection, calibration, and/or spectral
00359         baseline fitting for single-dish spectra. This task internally calls the
00360         tasks, sdcal, sdsmooth, and sdbaseline and it can be used to run all the
00361         three steps in one task execution.
00362         By setting calmode='none', one can run sdreduce on already calibrated data,
00363         for further selection, averaging and atmospheric optical depth correction.
00364         To save the output spectra in a certain range of channels, you set the 
00365         range in channelrange.
00366 
00367         If you give multiple IFs in iflist, then your scantable will have
00368         multiple IFs by default. Averaging of multi-resolution (multi-IFs)
00369         spectra can be achieved by setting a sub-parameter of average, 
00370         averageall, to True. It handles multi-IFs by selecting overlaps in 
00371         frequency coverages and assigning new IFs in the output spectra.
00372 
00373         ASAP recognizes the data of the "AT" telescopes, but currently
00374         does not know about the GBT or any other telescope. This task
00375         does know about GBT. Telescope name is obtained from the data.
00376         If you wish to change the fluxunit (see below), by leaving
00377         the sub-parameter telescopeparm unset (telescopeparm=''),
00378         it will use internal telescope parameters for
00379         flux conversion for the data from AT telescopes and it will use an
00380         approximate aperture efficiency conversion for the GBT data.
00381         If you give telescopeparm a list, then if the list has a single float it
00382         is assumed to be the gain in Jy/K, if two or more elements they are assumed
00383         to be telescope diameter (m) and aperture efficiency
00384         respectively.
00385 
00386         Note that sdreduce assumes that the fluxunit is set correctly in
00387         the data already.  If not, then set telescopeparm='FIX' and it
00388         will set the default units to fluxunit without conversion.
00389         NOTE: If the data in infile is an ms from GBT and the default flux
00390         unit is missing and this task automatically fixes the default fluxunit
00391         to 'K' before the conversion.
00392 
00393         WARNING for the GBT raw SDFITS format data as input:
00394         SDtasks are able to handle GBT raw SDFITS format data since the 
00395         data filler is available. However, the functionality is not well 
00396         tested yet, so that there may be unknown bugs.  
00397 
00398   
00399         """
00400         if not hasattr(self, "__globals__") or self.__globals__ == None :
00401            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00402         #casac = self.__globals__['casac']
00403         casalog = self.__globals__['casalog']
00404         #casalog = casac.casac.logsink()
00405         self.__globals__['__last_task'] = 'sdreduce'
00406         self.__globals__['taskname'] = 'sdreduce'
00407         ###
00408         self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__)
00409         ###
00410         ###
00411         #Handle globals or user over-ride of arguments
00412         #
00413         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00414         useLocalDefaults = False
00415 
00416         for item in function_signature_defaults.iteritems():
00417                 key,val = item
00418                 keyVal = eval(key)
00419                 if (keyVal == None):
00420                         #user hasn't set it - use global/default
00421                         pass
00422                 else:
00423                         #user has set it - use over-ride
00424                         if (key != 'self') :
00425                            useLocalDefaults = True
00426 
00427         myparams = {}
00428         if useLocalDefaults :
00429            for item in function_signature_defaults.iteritems():
00430                key,val = item
00431                keyVal = eval(key)
00432                exec('myparams[key] = keyVal')
00433                self.parameters[key] = keyVal
00434                if (keyVal == None):
00435                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00436                    keyVal = eval(key)
00437                    if(type(keyVal) == dict) :
00438                       if len(keyVal) > 0 :
00439                          exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00440                       else :
00441                          exec('myparams[key] = ' + key + ' = {}')
00442 
00443         else :
00444             async = self.parameters['async']
00445             myparams['infile'] = infile = self.parameters['infile']
00446             myparams['antenna'] = antenna = self.parameters['antenna']
00447             myparams['fluxunit'] = fluxunit = self.parameters['fluxunit']
00448             myparams['telescopeparm'] = telescopeparm = self.parameters['telescopeparm']
00449             myparams['specunit'] = specunit = self.parameters['specunit']
00450             myparams['restfreq'] = restfreq = self.parameters['restfreq']
00451             myparams['frame'] = frame = self.parameters['frame']
00452             myparams['doppler'] = doppler = self.parameters['doppler']
00453             myparams['calmode'] = calmode = self.parameters['calmode']
00454             myparams['fraction'] = fraction = self.parameters['fraction']
00455             myparams['noff'] = noff = self.parameters['noff']
00456             myparams['width'] = width = self.parameters['width']
00457             myparams['elongated'] = elongated = self.parameters['elongated']
00458             myparams['markonly'] = markonly = self.parameters['markonly']
00459             myparams['plotpointings'] = plotpointings = self.parameters['plotpointings']
00460             myparams['scanlist'] = scanlist = self.parameters['scanlist']
00461             myparams['field'] = field = self.parameters['field']
00462             myparams['iflist'] = iflist = self.parameters['iflist']
00463             myparams['pollist'] = pollist = self.parameters['pollist']
00464             myparams['channelrange'] = channelrange = self.parameters['channelrange']
00465             myparams['average'] = average = self.parameters['average']
00466             myparams['scanaverage'] = scanaverage = self.parameters['scanaverage']
00467             myparams['timeaverage'] = timeaverage = self.parameters['timeaverage']
00468             myparams['tweight'] = tweight = self.parameters['tweight']
00469             myparams['averageall'] = averageall = self.parameters['averageall']
00470             myparams['polaverage'] = polaverage = self.parameters['polaverage']
00471             myparams['pweight'] = pweight = self.parameters['pweight']
00472             myparams['tau'] = tau = self.parameters['tau']
00473             myparams['kernel'] = kernel = self.parameters['kernel']
00474             myparams['kwidth'] = kwidth = self.parameters['kwidth']
00475             myparams['chanwidth'] = chanwidth = self.parameters['chanwidth']
00476             myparams['masklist'] = masklist = self.parameters['masklist']
00477             myparams['maskmode'] = maskmode = self.parameters['maskmode']
00478             myparams['thresh'] = thresh = self.parameters['thresh']
00479             myparams['avg_limit'] = avg_limit = self.parameters['avg_limit']
00480             myparams['edge'] = edge = self.parameters['edge']
00481             myparams['blfunc'] = blfunc = self.parameters['blfunc']
00482             myparams['order'] = order = self.parameters['order']
00483             myparams['npiece'] = npiece = self.parameters['npiece']
00484             myparams['applyfft'] = applyfft = self.parameters['applyfft']
00485             myparams['fftmethod'] = fftmethod = self.parameters['fftmethod']
00486             myparams['fftthresh'] = fftthresh = self.parameters['fftthresh']
00487             myparams['addwn'] = addwn = self.parameters['addwn']
00488             myparams['rejwn'] = rejwn = self.parameters['rejwn']
00489             myparams['clipthresh'] = clipthresh = self.parameters['clipthresh']
00490             myparams['clipniter'] = clipniter = self.parameters['clipniter']
00491             myparams['verifycal'] = verifycal = self.parameters['verifycal']
00492             myparams['verifysm'] = verifysm = self.parameters['verifysm']
00493             myparams['verifybl'] = verifybl = self.parameters['verifybl']
00494             myparams['verbosebl'] = verbosebl = self.parameters['verbosebl']
00495             myparams['bloutput'] = bloutput = self.parameters['bloutput']
00496             myparams['blformat'] = blformat = self.parameters['blformat']
00497             myparams['showprogress'] = showprogress = self.parameters['showprogress']
00498             myparams['minnrow'] = minnrow = self.parameters['minnrow']
00499             myparams['outfile'] = outfile = self.parameters['outfile']
00500             myparams['outform'] = outform = self.parameters['outform']
00501             myparams['overwrite'] = overwrite = self.parameters['overwrite']
00502             myparams['plotlevel'] = plotlevel = self.parameters['plotlevel']
00503 
00504         if type(scanlist)==int: scanlist=[scanlist]
00505         if type(iflist)==int: iflist=[iflist]
00506         if type(pollist)==int: pollist=[pollist]
00507         if type(channelrange)==int: channelrange=[channelrange]
00508         if type(edge)==int: edge=[edge]
00509 
00510         result = None
00511 
00512 #
00513 #    The following is work around to avoid a bug with current python translation
00514 #
00515         mytmp = {}
00516 
00517         mytmp['infile'] = infile
00518         mytmp['antenna'] = antenna
00519         mytmp['fluxunit'] = fluxunit
00520         mytmp['telescopeparm'] = telescopeparm
00521         mytmp['specunit'] = specunit
00522         mytmp['restfreq'] = restfreq
00523         mytmp['frame'] = frame
00524         mytmp['doppler'] = doppler
00525         mytmp['calmode'] = calmode
00526         mytmp['fraction'] = fraction
00527         mytmp['noff'] = noff
00528         mytmp['width'] = width
00529         mytmp['elongated'] = elongated
00530         mytmp['markonly'] = markonly
00531         mytmp['plotpointings'] = plotpointings
00532         mytmp['scanlist'] = scanlist
00533         mytmp['field'] = field
00534         mytmp['iflist'] = iflist
00535         mytmp['pollist'] = pollist
00536         mytmp['channelrange'] = channelrange
00537         mytmp['average'] = average
00538         mytmp['scanaverage'] = scanaverage
00539         mytmp['timeaverage'] = timeaverage
00540         mytmp['tweight'] = tweight
00541         mytmp['averageall'] = averageall
00542         mytmp['polaverage'] = polaverage
00543         mytmp['pweight'] = pweight
00544         mytmp['tau'] = tau
00545         mytmp['kernel'] = kernel
00546         mytmp['kwidth'] = kwidth
00547         mytmp['chanwidth'] = chanwidth
00548         mytmp['masklist'] = masklist
00549         mytmp['maskmode'] = maskmode
00550         mytmp['thresh'] = thresh
00551         mytmp['avg_limit'] = avg_limit
00552         mytmp['edge'] = edge
00553         mytmp['blfunc'] = blfunc
00554         mytmp['order'] = order
00555         mytmp['npiece'] = npiece
00556         mytmp['applyfft'] = applyfft
00557         mytmp['fftmethod'] = fftmethod
00558         mytmp['fftthresh'] = fftthresh
00559         mytmp['addwn'] = addwn
00560         mytmp['rejwn'] = rejwn
00561         mytmp['clipthresh'] = clipthresh
00562         mytmp['clipniter'] = clipniter
00563         mytmp['verifycal'] = verifycal
00564         mytmp['verifysm'] = verifysm
00565         mytmp['verifybl'] = verifybl
00566         mytmp['verbosebl'] = verbosebl
00567         mytmp['bloutput'] = bloutput
00568         mytmp['blformat'] = blformat
00569         mytmp['showprogress'] = showprogress
00570         mytmp['minnrow'] = minnrow
00571         mytmp['outfile'] = outfile
00572         mytmp['outform'] = outform
00573         mytmp['overwrite'] = overwrite
00574         mytmp['plotlevel'] = plotlevel
00575         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00576         trec = casac.casac.utils().torecord(pathname+'sdreduce.xml')
00577 
00578         casalog.origin('sdreduce')
00579         try :
00580           #if not trec.has_key('sdreduce') or not casac.casac.utils().verify(mytmp, trec['sdreduce']) :
00581             #return False
00582 
00583           casac.casac.utils().verify(mytmp, trec['sdreduce'], True)
00584           scriptstr=['']
00585           saveinputs = self.__globals__['saveinputs']
00586           saveinputs('sdreduce', 'sdreduce.last', myparams, self.__globals__,scriptstr=scriptstr)
00587           if async :
00588             count = 0
00589             keybase =  time.strftime("%y%m%d.%H%M%S")
00590             key = keybase + "_" + str(count)
00591             while self.__async__.has_key(key) :
00592                count += 1
00593                key = keybase + "_" + str(count)
00594             result = tm.execute('sdreduce', infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, calmode, fraction, noff, width, elongated, markonly, plotpointings, scanlist, field, iflist, pollist, channelrange, average, scanaverage, timeaverage, tweight, averageall, polaverage, pweight, tau, kernel, kwidth, chanwidth, masklist, maskmode, thresh, avg_limit, edge, blfunc, order, npiece, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, verifycal, verifysm, verifybl, verbosebl, bloutput, blformat, showprogress, minnrow, outfile, outform, overwrite, plotlevel)
00595             print "Use: "
00596             print "      tm.retrieve(return_value) # to retrieve the status"
00597             print 
00598             self.rkey = key
00599             self.__async__[key] = result
00600           else :
00601               tname = 'sdreduce'
00602               spaces = ' '*(18-len(tname))
00603               casalog.post('\n##########################################'+
00604                            '\n##### Begin Task: ' + tname + spaces + ' #####')
00605               casalog.post(scriptstr[1][1:]+'\n', 'INFO')
00606               result = sdreduce(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, calmode, fraction, noff, width, elongated, markonly, plotpointings, scanlist, field, iflist, pollist, channelrange, average, scanaverage, timeaverage, tweight, averageall, polaverage, pweight, tau, kernel, kwidth, chanwidth, masklist, maskmode, thresh, avg_limit, edge, blfunc, order, npiece, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, verifycal, verifysm, verifybl, verbosebl, bloutput, blformat, showprogress, minnrow, outfile, outform, overwrite, plotlevel)
00607               casalog.post('##### End Task: ' + tname + '  ' + spaces + ' #####'+
00608                            '\n##########################################')
00609 
00610         except Exception, instance:
00611           if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) :
00612              raise
00613           else :
00614              #print '**** Error **** ',instance
00615              tname = 'sdreduce'
00616              casalog.post('An error occurred running task '+tname+'.', 'ERROR')
00617              pass
00618 
00619         gc.collect()
00620         return result
00621 #
00622 #
00623 #
00624     def paramgui(self, useGlobals=True, ipython_globals=None):
00625         """
00626         Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00627         """
00628         import paramgui
00629         if not hasattr(self, "__globals__") or self.__globals__ == None :
00630            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00631 
00632         if useGlobals:
00633             if ipython_globals == None:
00634                 myf=self.__globals__
00635             else:
00636                 myf=ipython_globals
00637 
00638             paramgui.setGlobals(myf)
00639         else:
00640             paramgui.setGlobals({})
00641 
00642         paramgui.runTask('sdreduce', myf['_ip'])
00643         paramgui.setGlobals({})
00644 
00645 #
00646 #
00647 #
00648     def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None):
00649         if not hasattr(self, "__globals__") or self.__globals__ == None :
00650            self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals
00651         if ipython_globals == None:
00652             myf=self.__globals__
00653         else:
00654             myf=ipython_globals
00655 
00656         a = odict()
00657         a['infile']  = ''
00658         a['antenna']  = 0
00659         a['fluxunit']  = ''
00660         a['specunit']  = ''
00661         a['frame']  = ''
00662         a['doppler']  = ''
00663         a['calmode']  = 'none'
00664         a['scanlist']  = []
00665         a['field']  = ''
00666         a['iflist']  = []
00667         a['pollist']  = []
00668         a['channelrange']  = []
00669         a['average']  = False
00670         a['tau']  = 0.0
00671         a['kernel']  = 'none'
00672         a['masklist']  = []
00673         a['maskmode']  = 'auto'
00674         a['blfunc']  = 'none'
00675         a['verifycal']  = False
00676         a['verifysm']  = False
00677         a['verifybl']  = False
00678         a['verbosebl']  = True
00679         a['bloutput']  = True
00680         a['blformat']  = ''
00681         a['showprogress']  = True
00682         a['outfile']  = ''
00683         a['outform']  = 'ASAP'
00684         a['overwrite']  = False
00685         a['plotlevel']  = 0
00686 
00687         a['async']=False
00688         a['fluxunit'] = {
00689                     0:{'value':''}, 
00690                     1:odict([{'value':'K'}, {'telescopeparm':""}]), 
00691                     2:odict([{'value':'k'}, {'telescopeparm':""}]), 
00692                     3:odict([{'value':'Jy'}, {'telescopeparm':""}]), 
00693                     4:odict([{'value':'jy'}, {'telescopeparm':""}])}
00694         a['specunit'] = {
00695                     0:{'value':''}, 
00696                     1:{'value':'channel'}, 
00697                     2:{'value':'GHz'}, 
00698                     3:{'value':'MHz'}, 
00699                     4:{'value':'kHz'}, 
00700                     5:{'value':'Hz'}, 
00701                     6:odict([{'value':'km/s'}, {'restfreq':''}])}
00702         a['average'] = {
00703                     0:{'value':False}, 
00704                     1:odict([{'value':True}, {'scanaverage':False}, {'timeaverage':False}, {'tweight':'none'}, {'averageall':False}, {'polaverage':False}, {'pweight':'none'}])}
00705         a['kernel'] = {
00706                     0:{'value':'none'}, 
00707                     1:{'value':'hanning'}, 
00708                     2:odict([{'value':'gaussian'}, {'kwidth':5}]), 
00709                     3:odict([{'value':'boxcar'}, {'kwidth':5}]), 
00710                     4:odict([{'value':'regrid'}, {'chanwidth':'5'}])}
00711         a['maskmode'] = {
00712                     0:odict([{'value':'auto'}, {'thresh':5.0}, {'avg_limit':4}, {'edge':[0]}]), 
00713                     1:{'value':'list'}, 
00714                     2:{'value':'interact'}}
00715         a['blfunc'] = {
00716                     0:{'value':'none'}, 
00717                     1:odict([{'value':'poly'}, {'order':5}]), 
00718                     2:odict([{'value':'cspline'}, {'npiece':2}, {'clipthresh':3.0}, {'clipniter':0}]), 
00719                     3:odict([{'value':'sinusoid'}, {'applyfft':True}, {'fftmethod':'fft'}, {'fftthresh':3.0}, {'addwn':[]}, {'rejwn':[]}, {'clipthresh':3.0}, {'clipniter':0}])}
00720         a['showprogress'] = {
00721                     0:odict([{'value':True}, {'minnrow':1000}])}
00722         a['calmode'] = {
00723                     0:{'value':'none'}, 
00724                     1:{'value':'ps'}, 
00725                     2:{'value':'nod'}, 
00726                     3:{'value':'fs'}, 
00727                     4:{'value':'fsotf'}, 
00728                     5:{'value':'quotient'}, 
00729                     6:odict([{'value':'otf'}, {'fraction':'10%'}, {'width':0.5}, {'elongated':False}, {'markonly':False}, {'plotpointings':False}]), 
00730                     7:odict([{'value':'otfraster'}, {'fraction':'10%'}, {'noff':-1}, {'markonly':False}, {'plotpointings':False}])}
00731 
00732 ### This function sets the default values but also will return the list of
00733 ### parameters or the default value of a given parameter
00734         if(param == None):
00735                 myf['__set_default_parameters'](a)
00736         elif(param == 'paramkeys'):
00737                 return a.keys()
00738         else:
00739             if(paramvalue==None and subparam==None):
00740                if(a.has_key(param)):
00741                   return a[param]
00742                else:
00743                   return self.itsdefault(param)
00744             else:
00745                retval=a[param]
00746                if(type(a[param])==dict):
00747                   for k in range(len(a[param])):
00748                      valornotval='value'
00749                      if(a[param][k].has_key('notvalue')):
00750                         valornotval='notvalue'
00751                      if((a[param][k][valornotval])==paramvalue):
00752                         retval=a[param][k].copy()
00753                         retval.pop(valornotval)
00754                         if(subparam != None):
00755                            if(retval.has_key(subparam)):
00756                               retval=retval[subparam]
00757                            else:
00758                               retval=self.itsdefault(subparam)
00759                      else:
00760                         retval=self.itsdefault(subparam)
00761                return retval
00762 
00763 
00764 #
00765 #
00766     def check_params(self, param=None, value=None, ipython_globals=None):
00767       if ipython_globals == None:
00768           myf=self.__globals__
00769       else:
00770           myf=ipython_globals
00771 #      print 'param:', param, 'value:', value
00772       try :
00773          if str(type(value)) != "<type 'instance'>" :
00774             value0 = value
00775             value = myf['cu'].expandparam(param, value)
00776             matchtype = False
00777             if(type(value) == numpy.ndarray):
00778                if(type(value) == type(value0)):
00779                   myf[param] = value.tolist()
00780                else:
00781                   #print 'value:', value, 'value0:', value0
00782                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00783                   myf[param] = value0
00784                   if type(value0) != list :
00785                      matchtype = True
00786             else :
00787                myf[param] = value
00788             value = myf['cu'].verifyparam({param:value})
00789             if matchtype:
00790                value = False
00791       except Exception, instance:
00792          #ignore the exception and just return it unchecked
00793          myf[param] = value
00794       return value
00795 #
00796 #
00797     def description(self, key='sdreduce', subkey=None):
00798         desc={'sdreduce': 'ASAP SD task: do sdcal, sdsmooth, and sdbaseline in one task',
00799                'infile': 'name of input SD dataset',
00800                'antenna': 'antenna name or id (only effective for MS input)',
00801                'fluxunit': 'units for line flux (K,Jy) (''=current)',
00802                'telescopeparm': 'param of telescope for flux conversion',
00803                'specunit': 'units for spectral axis (channel,km/s,GHz)',
00804                'restfreq': 'rest frequency (default unit: Hz)',
00805                'frame': 'frequency reference frame, e.g. LSRK (''=current)',
00806                'doppler': 'doppler convention, e.g. RADIO (''=current)',
00807                'calmode': 'SD calibration mode (ps,nod,otf,otfraster,fs,fsotf,none)',
00808                'fraction': 'fraction of the OFF data to mark',
00809                'noff': 'number of the OFF data to mark',
00810                'width': 'width of the pixel for edge detection',
00811                'elongated': 'whether observed area is elongated in one direction or not',
00812                'markonly': 'do calibration (False) or just mark OFF (True)',
00813                'plotpointings': 'plot pointing direction for ON and OFF',
00814                'scanlist': 'list of scans to use (e.g. [1,2,3,4])',
00815                'field': 'string for selection by source name',
00816                'iflist': 'list of IF ids to select (e.g. [0,1])',
00817                'pollist': 'list of polarization ids to select (e.g. [0,1])',
00818                'channelrange': 'channel range selection (e.g. [0,5000])',
00819                'average': 'data averaging (True,False) ',
00820                'scanaverage': 'average integs within scans (True,False) ',
00821                'timeaverage': 'average scans over time (True,False)',
00822                'tweight': 'weighting for time averaging',
00823                'averageall': 'set True only when averaging spectra with different spectral resolutions',
00824                'polaverage': 'average over polarizations (True,False)',
00825                'pweight': '',
00826                'tau': 'atmospheric optical depth for correction',
00827                'kernel': 'type of spectral smoothing',
00828                'kwidth': 'width of spectral kernel in channels',
00829                'chanwidth': 'width of regridded channels',
00830                'masklist': 'list or string of mask regions to INCLUDE in BASELINE fit',
00831                'maskmode': 'mode of setting additional channel masks for baselining',
00832                'thresh': 'S/N threshold for linefinder',
00833                'avg_limit': 'channel averaging for broad lines',
00834                'edge': 'channels to drop at beginning and end of spectrum',
00835                'blfunc': 'baseline model function',
00836                'order': 'order of baseline polynomial',
00837                'npiece': 'number of element polynomials of spline',
00838                'applyfft': 'automatically set wave numbers of sinusoids',
00839                'fftmethod': 'method for automatically set wave numbers of sinusoids',
00840                'fftthresh': 'threshold to select wave numbers of sinusoids',
00841                'addwn': 'additional wave numbers to use',
00842                'rejwn': 'wave numbers NOT to use',
00843                'clipthresh': 'clipping threshold for iterative fitting',
00844                'clipniter': 'maximum iteration number',
00845                'verifycal': 'verify the results of calibration',
00846                'verifysm': 'verify the results of smoothing [not available for kernel="regrid"]',
00847                'verifybl': 'verify the results of baseline fitting (only for blfunc="poly")',
00848                'verbosebl': 'output fitting results to logger',
00849                'bloutput': 'output fitting results to a text file',
00850                'blformat': 'format of the text file specified with bloutput',
00851                'showprogress': 'show progress status for large data',
00852                'minnrow': 'minimum number of input spectra to show progress status',
00853                'outfile': 'output file name',
00854                'outform': 'output file format (ASCII,MS,SDFITS,ASAP)',
00855                'overwrite': 'overwrite the output file if already exists',
00856                'plotlevel': 'plot results (0=none,1+=some,<0=hardcopy)',
00857 
00858                'async': 'If true the taskname must be started using sdreduce(...)'
00859               }
00860 
00861 #
00862 # Set subfields defaults if needed
00863 #
00864 
00865         if(desc.has_key(key)) :
00866            return desc[key]
00867 
00868     def itsdefault(self, paramname) :
00869         a = {}
00870         a['infile']  = ''
00871         a['antenna']  = 0
00872         a['fluxunit']  = ''
00873         a['telescopeparm']  = ''
00874         a['specunit']  = ''
00875         a['restfreq']  = ''
00876         a['frame']  = ''
00877         a['doppler']  = ''
00878         a['calmode']  = 'none'
00879         a['fraction']  = '10%'
00880         a['noff']  = -1
00881         a['width']  = 0.5
00882         a['elongated']  = False
00883         a['markonly']  = False
00884         a['plotpointings']  = False
00885         a['scanlist']  = []
00886         a['field']  = ''
00887         a['iflist']  = []
00888         a['pollist']  = []
00889         a['channelrange']  = []
00890         a['average']  = False
00891         a['scanaverage']  = False
00892         a['timeaverage']  = False
00893         a['tweight']  = 'none'
00894         a['averageall']  = False
00895         a['polaverage']  = False
00896         a['pweight']  = 'none'
00897         a['tau']  = 0.0
00898         a['kernel']  = 'none'
00899         a['kwidth']  = 5
00900         a['chanwidth']  = '5'
00901         a['masklist']  = []
00902         a['maskmode']  = 'auto'
00903         a['thresh']  = 5.0
00904         a['avg_limit']  = 4
00905         a['edge']  = [0]
00906         a['blfunc']  = 'none'
00907         a['order']  = 5
00908         a['npiece']  = 2
00909         a['applyfft']  = True
00910         a['fftmethod']  = 'fft'
00911         a['fftthresh']  = 3.0
00912         a['addwn']  = []
00913         a['rejwn']  = []
00914         a['clipthresh']  = 3.0
00915         a['clipniter']  = 0
00916         a['verifycal']  = False
00917         a['verifysm']  = False
00918         a['verifybl']  = False
00919         a['verbosebl']  = True
00920         a['bloutput']  = True
00921         a['blformat']  = ''
00922         a['showprogress']  = True
00923         a['minnrow']  = 1000
00924         a['outfile']  = ''
00925         a['outform']  = 'ASAP'
00926         a['overwrite']  = False
00927         a['plotlevel']  = 0
00928 
00929         #a = sys._getframe(len(inspect.stack())-1).f_globals
00930 
00931         if self.parameters['fluxunit']  == 'K':
00932             a['telescopeparm'] = ""
00933 
00934         if self.parameters['fluxunit']  == 'k':
00935             a['telescopeparm'] = ""
00936 
00937         if self.parameters['fluxunit']  == 'Jy':
00938             a['telescopeparm'] = ""
00939 
00940         if self.parameters['fluxunit']  == 'jy':
00941             a['telescopeparm'] = ""
00942 
00943         if self.parameters['specunit']  == 'km/s':
00944             a['restfreq'] = ''
00945 
00946         if self.parameters['average']  == True:
00947             a['scanaverage'] = False
00948             a['timeaverage'] = False
00949             a['tweight'] = 'none'
00950             a['averageall'] = False
00951             a['polaverage'] = False
00952             a['pweight'] = 'none'
00953 
00954         if self.parameters['kernel']  == 'gaussian':
00955             a['kwidth'] = 5
00956 
00957         if self.parameters['kernel']  == 'boxcar':
00958             a['kwidth'] = 5
00959 
00960         if self.parameters['kernel']  == 'regrid':
00961             a['chanwidth'] = '5'
00962 
00963         if self.parameters['maskmode']  == 'auto':
00964             a['thresh'] = 5.0
00965             a['avg_limit'] = 4
00966             a['edge'] = [0]
00967 
00968         if self.parameters['blfunc']  == 'poly':
00969             a['order'] = 5
00970 
00971         if self.parameters['blfunc']  == 'cspline':
00972             a['npiece'] = 2
00973             a['clipthresh'] = 3.0
00974             a['clipniter'] = 0
00975 
00976         if self.parameters['blfunc']  == 'sinusoid':
00977             a['applyfft'] = True
00978             a['fftmethod'] = 'fft'
00979             a['fftthresh'] = 3.0
00980             a['addwn'] = []
00981             a['rejwn'] = []
00982             a['clipthresh'] = 3.0
00983             a['clipniter'] = 0
00984 
00985         if self.parameters['showprogress']  == True:
00986             a['minnrow'] = 1000
00987 
00988         if self.parameters['calmode']  == 'otf':
00989             a['fraction'] = '10%'
00990             a['width'] = 0.5
00991             a['elongated'] = False
00992             a['markonly'] = False
00993             a['plotpointings'] = False
00994 
00995         if self.parameters['calmode']  == 'otfraster':
00996             a['fraction'] = '10%'
00997             a['noff'] = -1
00998             a['markonly'] = False
00999             a['plotpointings'] = False
01000 
01001         if a.has_key(paramname) :
01002               return a[paramname]
01003 sdreduce_cli = sdreduce_cli_()