casa
$Rev:20696$
|
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 string 00010 import time 00011 import inspect 00012 import gc 00013 import numpy 00014 from odict import odict 00015 from task_sdbaseline import sdbaseline 00016 from task_sdbaseline import casalog 00017 00018 class sdbaseline_pg_: 00019 __name__ = "sdbaseline" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdbaseline_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 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, tau=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, verify=None, verbose=None, bloutput=None, blformat=None, showprogress=None, minnrow=None, outfile=None, outform=None, overwrite=None, plotlevel=None, async=None): 00027 00028 """ASAP SD task: fit/subtract a spectral baseline 00029 Keyword arguments: 00030 infile -- name of input SD dataset 00031 antenna -- antenna name or id (only effective for MS input). 00032 fluxunit -- units for line flux 00033 options: 'K','Jy','' 00034 default: '' (keep current fluxunit) 00035 WARNING: For GBT data, see description below. 00036 >>> fluxunit expandable parameter 00037 telescopeparm -- the telescope characteristics 00038 options: (str) name or (list) list of gain info 00039 default: '' (none set) 00040 example: if telescopeparm='', it tries to get the telescope 00041 name from the data. 00042 Full antenna parameters (diameter,ap.eff.) known 00043 to ASAP are 00044 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43', 00045 'CEDUNA','HOBART'. For GBT, it fixes default fluxunit 00046 to 'K' first then convert to a new fluxunit. 00047 telescopeparm=[104.9,0.43] diameter(m), ap.eff. 00048 telescopeparm=[0.743] gain in Jy/K 00049 telescopeparm='FIX' to change default fluxunit 00050 see description below 00051 specunit -- units for spectral axis 00052 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz','' 00053 default: '' (=current) 00054 example: this will be the units for masklist 00055 >>> specunit expandable parameters 00056 restfreq -- rest frequency 00057 available type includes float, int, string, list of float, 00058 list of int, list of string, and list of dictionary. the 00059 default unit of restfreq in case of float, int, or string 00060 without unit is Hz. string input can be a value only 00061 (treated as Hz) or a value followed by unit for which 'GHz', 00062 'MHz','kHz',and 'Hz' are available. 00063 a list can be used to set different rest frequencies for 00064 each IF. the length of list input must be nIF. dictionary 00065 input should be a pair of molecule name and frequency with 00066 keys of 'name' and 'value', respectively. values in the 00067 dictionary input follows the same manner as for single 00068 float or string input. 00069 example: 345.796 00070 '1420MHz' 00071 [345.8, 347.0, 356.7] 00072 ['345.8MHz', '347.0MHz', '356.7MHz'] 00073 [{'name':'CO','value':345}] 00074 frame -- frequency frame for spectral axis 00075 options: (str) 'LSRK','REST','TOPO','LSRD','BARY', 00076 'GEO','GALACTO','LGROUP','CMB' 00077 default: currently set frame in scantable 00078 WARNING: frame='REST' not yet implemented 00079 doppler -- doppler mode 00080 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA' 00081 default: currently set doppler in scantable 00082 scanlist -- list of scan numbers to process 00083 default: [] (use all scans) 00084 example: [21,22,23,24] 00085 this selection is in addition to field, iflist, and pollist 00086 field -- selection string for selecting scans by name 00087 default: '' (no name selection) 00088 example: 'FLS3a*' 00089 this selection is in addition to scanlist, iflist, and pollist 00090 iflist -- list of IF id numbers to select 00091 default: [] (use all IFs) 00092 example: [15] 00093 this selection is in addition to scanlist, field, and pollist 00094 pollist -- list of polarization id numbers to select 00095 default: [] (use all polarizations) 00096 example: [1] 00097 this selection is in addition to scanlist, field, and iflist 00098 tau -- atmospheric optical depth 00099 default: 0.0 (no correction) 00100 masklist -- list or string of mask regions to INCLUDE in BASELINE fit 00101 a string masklist allows per IF selection of channels. 00102 default: [] (entire spectrum) 00103 example: [[1000,3000],[5000,7000]] 00104 '0:1000~3000;5000~7000, 1:200~350;450~600' 00105 when maskmode is 'auto' or 'interact', this mask 00106 will be applied first before fitting as base mask 00107 maskmode -- mode of setting additional channel masks 00108 options: (str) 'auto','list','interact' 00109 default: 'auto' 00110 example: maskmode='auto' runs linefinder to detect line regions 00111 to be excluded from fitting. this mode requires three 00112 expandable parameters: thresh, avg_limit, and edge. 00113 USE WITH CARE! May need to tweak the expandable parameters. 00114 maskmode='list' uses the given masklist only: no additional 00115 masks applied. 00116 maskmode='interact' allows users to manually modify the 00117 mask regions by dragging mouse on the spectrum plotter GUI. 00118 use LEFT or RIGHT button to add or delete regions, 00119 respectively. 00120 00121 >>> maskmode expandable parameters 00122 thresh -- S/N threshold for linefinder 00123 default: 5 00124 example: a single channel S/N ratio above which the channel is 00125 considered to be a detection 00126 avg_limit -- channel averaging for broad lines 00127 default: 4 00128 example: a number of consecutive channels not greater than 00129 this parameter can be averaged to search for broad lines 00130 edge -- channels to drop at beginning and end of spectrum 00131 default: 0 00132 example: [1000] drops 1000 channels at beginning AND end 00133 [1000,500] drops 1000 from beginning and 500 from end 00134 Note: For bad baselines threshold should be increased, 00135 and avg_limit decreased (or even switched off completely by 00136 setting this parameter to 1) to avoid detecting baseline 00137 undulations instead of real lines. 00138 blfunc -- baseline model function 00139 options: (str) 'poly','chebyshev','cspline','sinusoid' 00140 default: 'poly' 00141 example: blfunc='poly' uses a single polynomial line of 00142 any order which should be given as an expandable 00143 parameter 'order' to fit baseline. 00144 blfunc='chebyshev' uses Chebyshev polynomials. 00145 blfunc='cspline' uses a cubic spline function, a piecewise 00146 cubic polynomial having C2-continuity (i.e., the second 00147 derivative is continuous at the joining points). 00148 blfunc='sinusoid' uses a combination of sinusoidal curves. 00149 >>> blfunc expandable parameters 00150 order -- order of baseline polynomial 00151 options: (int) (<0 turns off baseline fitting) 00152 default: 5 00153 example: typically in range 2-9 (higher values 00154 seem to be needed for GBT) 00155 npiece -- number of the element polynomials of cubic spline curve 00156 options: (int) (<0 turns off baseline fitting) 00157 default: 2 00158 applyfft -- automatically set wave numbers of sinusoidal functions 00159 for fitting by applying some method like FFT. 00160 options: (bool) True, False 00161 default: True 00162 fftmethod -- method to be used when applyfft=True. Now only 00163 'fft' is available and it is the default. 00164 fftthresh -- threshold to select wave numbers to be used for 00165 sinusoidal fitting. both (float) and (str) accepted. 00166 given a float value, the unit is set to sigma. 00167 for string values, allowed formats include: 00168 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 00169 'topx' (= the x strongest ones, e.g. 'top5'). 00170 default is 3.0 (unit: sigma). 00171 addwn -- additional wave number(s) of sinusoids to be used 00172 for fitting. 00173 (list) and (int) are accepted to specify every 00174 wave numbers. also (str) can be used in case 00175 you need to specify wave numbers in a certain range, 00176 e.g., 'a-b' (= a, a+1, a+2, ..., b-1, b), 00177 '<a' (= 0,1,...,a-2,a-1), 00178 '>=a' (= a, a+1, ... up to the maximum wave 00179 number corresponding to the Nyquist 00180 frequency for the case of FFT). 00181 default: [0] (i.e., constant is subtracted at least) 00182 rejwn -- wave number(s) of sinusoid NOT to be used for fitting. 00183 can be set just as addwn but has higher priority: 00184 wave numbers which are specified both in addwn 00185 and rejwn will NOT be used. 00186 default: [] 00187 clipthresh -- clipping threshold for iterative fitting 00188 default: 3 00189 clipniter -- maximum iteration number 00190 default: 0 (no iteration, i.e., no clipping) 00191 verify -- verify the results of baseline fitting 00192 options: (bool) True,False 00193 default: False 00194 NOTE: Currently available only when blfunc='poly' 00195 WARNING: Currently this just asks whether you accept 00196 the displayed fit and if not, continues 00197 without doing any baseline fit. 00198 verbose -- output fitting results to logger 00199 default: True 00200 example: If False, the fitting results including coefficients, 00201 residual rms, etc., are not output to the CASA logger, 00202 while the processing speed gets faster 00203 bloutput -- output fitting results to a text file 00204 default: True 00205 example: If False, the fitting results including coefficients, 00206 residual rms, etc., are not output to a text file 00207 (<outfile>_blparam.txt), while the processing 00208 speed gets faster 00209 blformat -- format of the logger output and text file specified with bloutput 00210 options: '', 'csv' 00211 default: '' (same as in the past, easy to read but huge) 00212 showprogress -- show progress status for large data 00213 default: True 00214 minnrow -- minimum number of input spectra to show progress status 00215 default: 1000 00216 outfile -- Name of output file 00217 default: '' (<infile>_bs) 00218 outform -- format of output file 00219 options: 'ASCII','SDFITS','MS','ASAP' 00220 default: 'ASAP' 00221 example: the ASAP format is easiest for further sd 00222 processing; use MS for CASA imaging. 00223 If ASCII, then will append some stuff to 00224 the outfile name 00225 overwrite -- overwrite the output file if already exists 00226 options: (bool) True,False 00227 default: False 00228 WARNING: if outform='ASCII', this parameter is ignored 00229 plotlevel -- control for plotting of results 00230 options: (int) 0=none, 1=some, 2=more, <0=hardcopy 00231 default: 0 (no plotting) 00232 example: plotlevel<0 as abs(plotlevel), e.g. 00233 -1 => hardcopy of final plot (will be named 00234 <outfile>_bspec.eps) 00235 WARNING: be careful plotting in fsotf mode! 00236 00237 00238 00239 DESCRIPTION: 00240 00241 Task sdbaseline performs baseline fitting/removal for single-dish spectra. 00242 The fit parameters, terms and rms of base-line are saved to an ascii 00243 file, '<outfile>_blparam.txt'. 00244 00245 ASAP recognizes the data of the "AT" telescopes, but currently 00246 does not know about the GBT or any other telescope. This task 00247 does know about GBT. Telescope name is obtained from the data. 00248 If you wish to change the fluxunit (see below), and telescopeparm='', 00249 for the AT telescopes it will use internal telescope parameters for 00250 flux conversion. For GBT, it will use an approximate aperture 00251 efficiency conversion. If you give telescopeparm a list , 00252 then if the list has a single float it is assumed to 00253 be the gain in Jy/K, if two or more elements they are assumed 00254 to be telescope diameter (m) and aperture efficiency 00255 respectively. 00256 00257 Note that sdbaseline assumes that the fluxunit is set correctly in 00258 the data already. If not, then set telescopeparm='FIX' and it 00259 will set the default units to fluxunit without conversion. 00260 NOTE: If the data in infile is an ms from GBT and the default flux 00261 unit is missing and this task automatically fixes the default fluxunit 00262 to 'K' before the conversion. 00263 00264 WARNING for the GBT raw SDFITS format data as input: 00265 SDtasks are able to handle GBT raw SDFITS format data since the 00266 data filler is available. However, the functionality is not well 00267 tested yet, so that there may be unknown bugs. 00268 00269 00270 """ 00271 a=inspect.stack() 00272 stacklevel=0 00273 for k in range(len(a)): 00274 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00275 stacklevel=k 00276 break 00277 myf=sys._getframe(stacklevel).f_globals 00278 myf['__last_task'] = 'sdbaseline' 00279 myf['taskname'] = 'sdbaseline' 00280 ### 00281 myf['update_params'](func=myf['taskname'],printtext=False) 00282 ### 00283 ### 00284 #Handle globals or user over-ride of arguments 00285 # 00286 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00287 useLocalDefaults = False 00288 00289 for item in function_signature_defaults.iteritems(): 00290 key,val = item 00291 keyVal = eval(key) 00292 if (keyVal == None): 00293 #user hasn't set it - use global/default 00294 pass 00295 else: 00296 #user has set it - use over-ride 00297 if (key != 'self') : 00298 useLocalDefaults = True 00299 #myf[key]=keyVal 00300 00301 myparams = {} 00302 if useLocalDefaults : 00303 for item in function_signature_defaults.iteritems(): 00304 key,val = item 00305 keyVal = eval(key) 00306 exec('myparams[key] = keyVal') 00307 if (keyVal == None): 00308 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00309 keyVal = eval(key) 00310 if(type(keyVal) == dict) : 00311 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00312 00313 else : 00314 uselessvariable = None 00315 myparams['infile'] = infile = myf['infile'] 00316 myparams['antenna'] = antenna = myf['antenna'] 00317 myparams['fluxunit'] = fluxunit = myf['fluxunit'] 00318 myparams['telescopeparm'] = telescopeparm = myf['telescopeparm'] 00319 myparams['specunit'] = specunit = myf['specunit'] 00320 myparams['restfreq'] = restfreq = myf['restfreq'] 00321 myparams['frame'] = frame = myf['frame'] 00322 myparams['doppler'] = doppler = myf['doppler'] 00323 myparams['scanlist'] = scanlist = myf['scanlist'] 00324 myparams['field'] = field = myf['field'] 00325 myparams['iflist'] = iflist = myf['iflist'] 00326 myparams['pollist'] = pollist = myf['pollist'] 00327 myparams['tau'] = tau = myf['tau'] 00328 myparams['masklist'] = masklist = myf['masklist'] 00329 myparams['maskmode'] = maskmode = myf['maskmode'] 00330 myparams['thresh'] = thresh = myf['thresh'] 00331 myparams['avg_limit'] = avg_limit = myf['avg_limit'] 00332 myparams['edge'] = edge = myf['edge'] 00333 myparams['blfunc'] = blfunc = myf['blfunc'] 00334 myparams['order'] = order = myf['order'] 00335 myparams['npiece'] = npiece = myf['npiece'] 00336 myparams['applyfft'] = applyfft = myf['applyfft'] 00337 myparams['fftmethod'] = fftmethod = myf['fftmethod'] 00338 myparams['fftthresh'] = fftthresh = myf['fftthresh'] 00339 myparams['addwn'] = addwn = myf['addwn'] 00340 myparams['rejwn'] = rejwn = myf['rejwn'] 00341 myparams['clipthresh'] = clipthresh = myf['clipthresh'] 00342 myparams['clipniter'] = clipniter = myf['clipniter'] 00343 myparams['verify'] = verify = myf['verify'] 00344 myparams['verbose'] = verbose = myf['verbose'] 00345 myparams['bloutput'] = bloutput = myf['bloutput'] 00346 myparams['blformat'] = blformat = myf['blformat'] 00347 myparams['showprogress'] = showprogress = myf['showprogress'] 00348 myparams['minnrow'] = minnrow = myf['minnrow'] 00349 myparams['outfile'] = outfile = myf['outfile'] 00350 myparams['outform'] = outform = myf['outform'] 00351 myparams['overwrite'] = overwrite = myf['overwrite'] 00352 myparams['plotlevel'] = plotlevel = myf['plotlevel'] 00353 00354 if type(scanlist)==int: scanlist=[scanlist] 00355 if type(iflist)==int: iflist=[iflist] 00356 if type(pollist)==int: pollist=[pollist] 00357 if type(edge)==int: edge=[edge] 00358 00359 result = None 00360 00361 # 00362 # The following is work around to avoid a bug with current python translation 00363 # 00364 mytmp = {} 00365 00366 mytmp['infile'] = infile 00367 mytmp['antenna'] = antenna 00368 mytmp['fluxunit'] = fluxunit 00369 mytmp['telescopeparm'] = telescopeparm 00370 mytmp['specunit'] = specunit 00371 mytmp['restfreq'] = restfreq 00372 mytmp['frame'] = frame 00373 mytmp['doppler'] = doppler 00374 mytmp['scanlist'] = scanlist 00375 mytmp['field'] = field 00376 mytmp['iflist'] = iflist 00377 mytmp['pollist'] = pollist 00378 mytmp['tau'] = tau 00379 mytmp['masklist'] = masklist 00380 mytmp['maskmode'] = maskmode 00381 mytmp['thresh'] = thresh 00382 mytmp['avg_limit'] = avg_limit 00383 mytmp['edge'] = edge 00384 mytmp['blfunc'] = blfunc 00385 mytmp['order'] = order 00386 mytmp['npiece'] = npiece 00387 mytmp['applyfft'] = applyfft 00388 mytmp['fftmethod'] = fftmethod 00389 mytmp['fftthresh'] = fftthresh 00390 mytmp['addwn'] = addwn 00391 mytmp['rejwn'] = rejwn 00392 mytmp['clipthresh'] = clipthresh 00393 mytmp['clipniter'] = clipniter 00394 mytmp['verify'] = verify 00395 mytmp['verbose'] = verbose 00396 mytmp['bloutput'] = bloutput 00397 mytmp['blformat'] = blformat 00398 mytmp['showprogress'] = showprogress 00399 mytmp['minnrow'] = minnrow 00400 mytmp['outfile'] = outfile 00401 mytmp['outform'] = outform 00402 mytmp['overwrite'] = overwrite 00403 mytmp['plotlevel'] = plotlevel 00404 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00405 trec = casac.utils().torecord(pathname+'sdbaseline.xml') 00406 00407 casalog.origin('sdbaseline') 00408 if not trec.has_key('sdbaseline') or not casac.utils().verify(mytmp, trec['sdbaseline']) : 00409 return False 00410 00411 00412 try : 00413 casalog.post('') 00414 casalog.post('##########################################') 00415 casalog.post('##### Begin Task: sdbaseline #####') 00416 casalog.post('') 00417 result = sdbaseline(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, tau, masklist, maskmode, thresh, avg_limit, edge, blfunc, order, npiece, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, verify, verbose, bloutput, blformat, showprogress, minnrow, outfile, outform, overwrite, plotlevel) 00418 casalog.post('') 00419 casalog.post('##### End Task: sdbaseline #####') 00420 casalog.post('##########################################') 00421 00422 00423 # saveinputs for individule engine has no use 00424 # saveinputs should alos be removed from casa_in_py.py 00425 # 00426 # 00427 # saveinputs = myf['saveinputs'] 00428 # saveinputs('sdbaseline', 'sdbaseline.last', myparams) 00429 # 00430 # 00431 except Exception, instance: 00432 #print '**** Error **** ',instance 00433 pass 00434 00435 gc.collect() 00436 return result 00437 # 00438 # 00439 ## 00440 # def paramgui(self, useGlobals=True): 00441 # """ 00442 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00443 # """ 00444 # import paramgui 00445 # 00446 # a=inspect.stack() 00447 # stacklevel=0 00448 # for k in range(len(a)): 00449 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00450 # stacklevel=k 00451 # break 00452 # myf = sys._getframe(stacklevel).f_globals 00453 # 00454 # if useGlobals: 00455 # paramgui.setGlobals(myf) 00456 # else: 00457 # paramgui.setGlobals({}) 00458 # 00459 # paramgui.runTask('sdbaseline', myf['_ip']) 00460 # paramgui.setGlobals({}) 00461 # 00462 # 00463 # 00464 # 00465 def defaults(self, param=None): 00466 a=inspect.stack() 00467 stacklevel=0 00468 for k in range(len(a)): 00469 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00470 stacklevel=k 00471 break 00472 myf=sys._getframe(stacklevel).f_globals 00473 a = odict() 00474 a['infile'] = '' 00475 a['antenna'] = 0 00476 a['fluxunit'] = '' 00477 a['specunit'] = '' 00478 a['frame'] = '' 00479 a['doppler'] = '' 00480 a['scanlist'] = [] 00481 a['field'] = '' 00482 a['iflist'] = [] 00483 a['pollist'] = [] 00484 a['tau'] = 0.0 00485 a['masklist'] = [] 00486 a['maskmode'] = '' 00487 a['blfunc'] = 'poly' 00488 a['verify'] = False 00489 a['verbose'] = True 00490 a['bloutput'] = True 00491 a['blformat'] = '' 00492 a['showprogress'] = True 00493 a['outfile'] = '' 00494 a['outform'] = 'ASAP' 00495 a['overwrite'] = False 00496 a['plotlevel'] = 0 00497 00498 a['async']=False 00499 a['fluxunit'] = { 00500 0:{'value':''}, 00501 1:odict([{'value':'K'}, {'telescopeparm':''}]), 00502 2:odict([{'value':'k'}, {'telescopeparm':''}]), 00503 3:odict([{'value':'Jy'}, {'telescopeparm':''}]), 00504 4:odict([{'value':'jy'}, {'telescopeparm':''}])} 00505 a['specunit'] = { 00506 0:{'value':''}, 00507 1:{'value':'channel'}, 00508 2:{'value':'GHz'}, 00509 3:{'value':'MHz'}, 00510 4:{'value':'kHz'}, 00511 5:{'value':'Hz'}, 00512 6:odict([{'value':'km/s'}, {'restfreq':''}])} 00513 a['maskmode'] = { 00514 0:odict([{'value':'auto'}, {'thresh':5.0}, {'avg_limit':4}, {'edge':[0]}]), 00515 1:{'value':'list'}, 00516 2:{'value':'interact'}} 00517 a['blfunc'] = { 00518 0:odict([{'value':'poly'}, {'order':5}]), 00519 1:odict([{'value':'chebyshev'}, {'order':5}, {'clipthresh':3.0}, {'clipniter':0}]), 00520 2:odict([{'value':'cspline'}, {'npiece':2}, {'clipthresh':3.0}, {'clipniter':0}]), 00521 3:odict([{'value':'sinusoid'}, {'applyfft':True}, {'fftmethod':'fft'}, {'fftthresh':3.0}, {'addwn':[0]}, {'rejwn':[]}, {'clipthresh':3.0}, {'clipniter':0}])} 00522 a['showprogress'] = { 00523 0:odict([{'value':True}, {'minnrow':1000}])} 00524 00525 ### This function sets the default values but also will return the list of 00526 ### parameters or the default value of a given parameter 00527 if(param == None): 00528 myf['__set_default_parameters'](a) 00529 elif(param == 'paramkeys'): 00530 return a.keys() 00531 else: 00532 if(a.has_key(param)): 00533 #if(type(a[param]) == dict) : 00534 # return a[param][len(a[param])-1]['value'] 00535 #else : 00536 return a[param] 00537 00538 00539 # 00540 # 00541 def check_params(self, param=None, value=None): 00542 a=inspect.stack() 00543 stacklevel=0 00544 for k in range(len(a)): 00545 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00546 stacklevel=k 00547 break 00548 myf=sys._getframe(stacklevel).f_globals 00549 00550 # print 'param:', param, 'value:', value 00551 try : 00552 if str(type(value)) != "<type 'instance'>" : 00553 value0 = value 00554 value = myf['cu'].expandparam(param, value) 00555 matchtype = False 00556 if(type(value) == numpy.ndarray): 00557 if(type(value) == type(value0)): 00558 myf[param] = value.tolist() 00559 else: 00560 #print 'value:', value, 'value0:', value0 00561 #print 'type(value):', type(value), 'type(value0):', type(value0) 00562 myf[param] = value0 00563 if type(value0) != list : 00564 matchtype = True 00565 else : 00566 myf[param] = value 00567 value = myf['cu'].verifyparam({param:value}) 00568 if matchtype: 00569 value = False 00570 except Exception, instance: 00571 #ignore the exception and just return it unchecked 00572 myf[param] = value 00573 return value 00574 00575 # 00576 # 00577 def description(self, key='sdbaseline', subkey=None): 00578 desc={'sdbaseline': 'ASAP SD task: fit/subtract a spectral baseline ', 00579 'infile': 'name of input SD dataset', 00580 'antenna': 'antenna name or id (only effective for MS input)', 00581 'fluxunit': 'units for line flux (K,Jy) (''=current)', 00582 'telescopeparm': 'param of telescope for flux conversion', 00583 'specunit': 'units for spectral axis (channel,km/s,GHz)', 00584 'restfreq': 'rest frequency (default unit: Hz)', 00585 'frame': 'frequency reference frame, e.g. LSRK (''=current)', 00586 'doppler': 'doppler convention, e.g. RADIO (''=current)', 00587 'scanlist': 'list of scans to use (e.g. [1,2,3,4])', 00588 'field': 'string for selection by source name', 00589 'iflist': 'list of IF ids to select (e.g. [0,1])', 00590 'pollist': 'list of polarization ids to select (e.g. [0,1])', 00591 'tau': 'atmospheric optical depth for correction', 00592 'masklist': 'list or string of mask regions to INCLUDE in BASELINE fit', 00593 'maskmode': 'mode of setting additional channel masks', 00594 'thresh': 'S/N threshold for linefinder', 00595 'avg_limit': 'channel averaging for broad lines', 00596 'edge': 'channels to drop at beginning and end of spectrum', 00597 'blfunc': 'baseline model function', 00598 'order': 'order of baseline polynomial', 00599 'npiece': 'number of element polynomials of spline', 00600 'applyfft': 'automatically set wave numbers of sinusoids', 00601 'fftmethod': 'method for automatically set wave numbers of sinusoids', 00602 'fftthresh': 'threshold to select wave numbers of sinusoids', 00603 'addwn': 'additional wave numbers to use', 00604 'rejwn': 'wave numbers NOT to use', 00605 'clipthresh': 'clipping threshold for iterative fitting', 00606 'clipniter': 'maximum iteration number', 00607 'verify': 'verify the results of baseline fitting (only for blfunc="poly")', 00608 'verbose': 'output fitting results to logger', 00609 'bloutput': 'output fitting results to a text file', 00610 'blformat': 'format of the text file specified with bloutput', 00611 'showprogress': 'show progress status for large data', 00612 'minnrow': 'minimum number of input spectra to show progress status', 00613 'outfile': 'output file name', 00614 'outform': 'output file format (ASCII,MS,SDFITS,ASAP)', 00615 'overwrite': 'overwrite the output file if already exists', 00616 'plotlevel': 'plot results (0=none,1+=some,<0=hardcopy)', 00617 00618 'async': 'If true the taskname must be started using sdbaseline(...)' 00619 } 00620 00621 # 00622 # Set subfields defaults if needed 00623 # 00624 00625 if(desc.has_key(key)) : 00626 return desc[key] 00627 00628 def itsdefault(self, paramname) : 00629 a = {} 00630 a['infile'] = '' 00631 a['antenna'] = 0 00632 a['fluxunit'] = '' 00633 a['telescopeparm'] = '' 00634 a['specunit'] = '' 00635 a['restfreq'] = '' 00636 a['frame'] = '' 00637 a['doppler'] = '' 00638 a['scanlist'] = [] 00639 a['field'] = '' 00640 a['iflist'] = [] 00641 a['pollist'] = [] 00642 a['tau'] = 0.0 00643 a['masklist'] = [] 00644 a['maskmode'] = '' 00645 a['thresh'] = 5.0 00646 a['avg_limit'] = 4 00647 a['edge'] = [0] 00648 a['blfunc'] = 'poly' 00649 a['order'] = 5 00650 a['npiece'] = 2 00651 a['applyfft'] = True 00652 a['fftmethod'] = 'fft' 00653 a['fftthresh'] = 3.0 00654 a['addwn'] = [0] 00655 a['rejwn'] = [] 00656 a['clipthresh'] = 3.0 00657 a['clipniter'] = 0 00658 a['verify'] = False 00659 a['verbose'] = True 00660 a['bloutput'] = True 00661 a['blformat'] = '' 00662 a['showprogress'] = True 00663 a['minnrow'] = 1000 00664 a['outfile'] = '' 00665 a['outform'] = 'ASAP' 00666 a['overwrite'] = False 00667 a['plotlevel'] = 0 00668 00669 if a.has_key(paramname) : 00670 return a[paramname] 00671 sdbaseline_pg = sdbaseline_pg_()