casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2009, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 from taskinit import casalog 00011 #from taskmanager import tm 00012 import task_sdbaseline 00013 def sdbaseline(infile='', antenna=0, fluxunit='', telescopeparm='', specunit='', restfreq='', frame='', doppler='', scanlist=[], field='', iflist=[], pollist=[], tau=0.0, masklist=[], maskmode='', thresh=5.0, avg_limit=4, edge=[0], blfunc='poly', order=5, npiece=2, applyfft=True, fftmethod='fft', fftthresh=3.0, addwn=[0], rejwn=[], clipthresh=3.0, clipniter=0, verify=False, verbose=True, bloutput=True, blformat='', showprogress=True, minnrow=1000, outfile='', outform='ASAP', overwrite=False, plotlevel=0): 00014 00015 """ASAP SD task: fit/subtract a spectral baseline 00016 Keyword arguments: 00017 infile -- name of input SD dataset 00018 antenna -- antenna name or id (only effective for MS input). 00019 fluxunit -- units for line flux 00020 options: 'K','Jy','' 00021 default: '' (keep current fluxunit) 00022 WARNING: For GBT data, see description below. 00023 >>> fluxunit expandable parameter 00024 telescopeparm -- the telescope characteristics 00025 options: (str) name or (list) list of gain info 00026 default: '' (none set) 00027 example: if telescopeparm='', it tries to get the telescope 00028 name from the data. 00029 Full antenna parameters (diameter,ap.eff.) known 00030 to ASAP are 00031 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43', 00032 'CEDUNA','HOBART'. For GBT, it fixes default fluxunit 00033 to 'K' first then convert to a new fluxunit. 00034 telescopeparm=[104.9,0.43] diameter(m), ap.eff. 00035 telescopeparm=[0.743] gain in Jy/K 00036 telescopeparm='FIX' to change default fluxunit 00037 see description below 00038 specunit -- units for spectral axis 00039 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz','' 00040 default: '' (=current) 00041 example: this will be the units for masklist 00042 >>> specunit expandable parameters 00043 restfreq -- rest frequency 00044 available type includes float, int, string, list of float, 00045 list of int, list of string, and list of dictionary. the 00046 default unit of restfreq in case of float, int, or string 00047 without unit is Hz. string input can be a value only 00048 (treated as Hz) or a value followed by unit for which 'GHz', 00049 'MHz','kHz',and 'Hz' are available. 00050 a list can be used to set different rest frequencies for 00051 each IF. the length of list input must be nIF. dictionary 00052 input should be a pair of molecule name and frequency with 00053 keys of 'name' and 'value', respectively. values in the 00054 dictionary input follows the same manner as for single 00055 float or string input. 00056 example: 345.796 00057 '1420MHz' 00058 [345.8, 347.0, 356.7] 00059 ['345.8MHz', '347.0MHz', '356.7MHz'] 00060 [{'name':'CO','value':345}] 00061 frame -- frequency frame for spectral axis 00062 options: (str) 'LSRK','REST','TOPO','LSRD','BARY', 00063 'GEO','GALACTO','LGROUP','CMB' 00064 default: currently set frame in scantable 00065 WARNING: frame='REST' not yet implemented 00066 doppler -- doppler mode 00067 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA' 00068 default: currently set doppler in scantable 00069 scanlist -- list of scan numbers to process 00070 default: [] (use all scans) 00071 example: [21,22,23,24] 00072 this selection is in addition to field, iflist, and pollist 00073 field -- selection string for selecting scans by name 00074 default: '' (no name selection) 00075 example: 'FLS3a*' 00076 this selection is in addition to scanlist, iflist, and pollist 00077 iflist -- list of IF id numbers to select 00078 default: [] (use all IFs) 00079 example: [15] 00080 this selection is in addition to scanlist, field, and pollist 00081 pollist -- list of polarization id numbers to select 00082 default: [] (use all polarizations) 00083 example: [1] 00084 this selection is in addition to scanlist, field, and iflist 00085 tau -- atmospheric optical depth 00086 default: 0.0 (no correction) 00087 masklist -- list or string of mask regions to INCLUDE in BASELINE fit 00088 a string masklist allows per IF selection of channels. 00089 default: [] (entire spectrum) 00090 example: [[1000,3000],[5000,7000]] 00091 '0:1000~3000;5000~7000, 1:200~350;450~600' 00092 when maskmode is 'auto' or 'interact', this mask 00093 will be applied first before fitting as base mask 00094 maskmode -- mode of setting additional channel masks 00095 options: (str) 'auto','list','interact' 00096 default: 'auto' 00097 example: maskmode='auto' runs linefinder to detect line regions 00098 to be excluded from fitting. this mode requires three 00099 expandable parameters: thresh, avg_limit, and edge. 00100 USE WITH CARE! May need to tweak the expandable parameters. 00101 maskmode='list' uses the given masklist only: no additional 00102 masks applied. 00103 maskmode='interact' allows users to manually modify the 00104 mask regions by dragging mouse on the spectrum plotter GUI. 00105 use LEFT or RIGHT button to add or delete regions, 00106 respectively. 00107 00108 >>> maskmode expandable parameters 00109 thresh -- S/N threshold for linefinder 00110 default: 5 00111 example: a single channel S/N ratio above which the channel is 00112 considered to be a detection 00113 avg_limit -- channel averaging for broad lines 00114 default: 4 00115 example: a number of consecutive channels not greater than 00116 this parameter can be averaged to search for broad lines 00117 edge -- channels to drop at beginning and end of spectrum 00118 default: 0 00119 example: [1000] drops 1000 channels at beginning AND end 00120 [1000,500] drops 1000 from beginning and 500 from end 00121 Note: For bad baselines threshold should be increased, 00122 and avg_limit decreased (or even switched off completely by 00123 setting this parameter to 1) to avoid detecting baseline 00124 undulations instead of real lines. 00125 blfunc -- baseline model function 00126 options: (str) 'poly','chebyshev','cspline','sinusoid' 00127 default: 'poly' 00128 example: blfunc='poly' uses a single polynomial line of 00129 any order which should be given as an expandable 00130 parameter 'order' to fit baseline. 00131 blfunc='chebyshev' uses Chebyshev polynomials. 00132 blfunc='cspline' uses a cubic spline function, a piecewise 00133 cubic polynomial having C2-continuity (i.e., the second 00134 derivative is continuous at the joining points). 00135 blfunc='sinusoid' uses a combination of sinusoidal curves. 00136 >>> blfunc expandable parameters 00137 order -- order of baseline polynomial 00138 options: (int) (<0 turns off baseline fitting) 00139 default: 5 00140 example: typically in range 2-9 (higher values 00141 seem to be needed for GBT) 00142 npiece -- number of the element polynomials of cubic spline curve 00143 options: (int) (<0 turns off baseline fitting) 00144 default: 2 00145 applyfft -- automatically set wave numbers of sinusoidal functions 00146 for fitting by applying some method like FFT. 00147 options: (bool) True, False 00148 default: True 00149 fftmethod -- method to be used when applyfft=True. Now only 00150 'fft' is available and it is the default. 00151 fftthresh -- threshold to select wave numbers to be used for 00152 sinusoidal fitting. both (float) and (str) accepted. 00153 given a float value, the unit is set to sigma. 00154 for string values, allowed formats include: 00155 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 00156 'topx' (= the x strongest ones, e.g. 'top5'). 00157 default is 3.0 (unit: sigma). 00158 addwn -- additional wave number(s) of sinusoids to be used 00159 for fitting. 00160 (list) and (int) are accepted to specify every 00161 wave numbers. also (str) can be used in case 00162 you need to specify wave numbers in a certain range, 00163 e.g., 'a-b' (= a, a+1, a+2, ..., b-1, b), 00164 '<a' (= 0,1,...,a-2,a-1), 00165 '>=a' (= a, a+1, ... up to the maximum wave 00166 number corresponding to the Nyquist 00167 frequency for the case of FFT). 00168 default: [0] (i.e., constant is subtracted at least) 00169 rejwn -- wave number(s) of sinusoid NOT to be used for fitting. 00170 can be set just as addwn but has higher priority: 00171 wave numbers which are specified both in addwn 00172 and rejwn will NOT be used. 00173 default: [] 00174 clipthresh -- clipping threshold for iterative fitting 00175 default: 3 00176 clipniter -- maximum iteration number 00177 default: 0 (no iteration, i.e., no clipping) 00178 verify -- verify the results of baseline fitting 00179 options: (bool) True,False 00180 default: False 00181 NOTE: Currently available only when blfunc='poly' 00182 WARNING: Currently this just asks whether you accept 00183 the displayed fit and if not, continues 00184 without doing any baseline fit. 00185 verbose -- output fitting results to logger 00186 default: True 00187 example: If False, the fitting results including coefficients, 00188 residual rms, etc., are not output to the CASA logger, 00189 while the processing speed gets faster 00190 bloutput -- output fitting results to a text file 00191 default: True 00192 example: If False, the fitting results including coefficients, 00193 residual rms, etc., are not output to a text file 00194 (<outfile>_blparam.txt), while the processing 00195 speed gets faster 00196 blformat -- format of the logger output and text file specified with bloutput 00197 options: '', 'csv' 00198 default: '' (same as in the past, easy to read but huge) 00199 showprogress -- show progress status for large data 00200 default: True 00201 minnrow -- minimum number of input spectra to show progress status 00202 default: 1000 00203 outfile -- Name of output file 00204 default: '' (<infile>_bs) 00205 outform -- format of output file 00206 options: 'ASCII','SDFITS','MS','ASAP' 00207 default: 'ASAP' 00208 example: the ASAP format is easiest for further sd 00209 processing; use MS for CASA imaging. 00210 If ASCII, then will append some stuff to 00211 the outfile name 00212 overwrite -- overwrite the output file if already exists 00213 options: (bool) True,False 00214 default: False 00215 WARNING: if outform='ASCII', this parameter is ignored 00216 plotlevel -- control for plotting of results 00217 options: (int) 0=none, 1=some, 2=more, <0=hardcopy 00218 default: 0 (no plotting) 00219 example: plotlevel<0 as abs(plotlevel), e.g. 00220 -1 => hardcopy of final plot (will be named 00221 <outfile>_bspec.eps) 00222 WARNING: be careful plotting in fsotf mode! 00223 00224 00225 00226 DESCRIPTION: 00227 00228 Task sdbaseline performs baseline fitting/removal for single-dish spectra. 00229 The fit parameters, terms and rms of base-line are saved to an ascii 00230 file, '<outfile>_blparam.txt'. 00231 00232 ASAP recognizes the data of the "AT" telescopes, but currently 00233 does not know about the GBT or any other telescope. This task 00234 does know about GBT. Telescope name is obtained from the data. 00235 If you wish to change the fluxunit (see below), and telescopeparm='', 00236 for the AT telescopes it will use internal telescope parameters for 00237 flux conversion. For GBT, it will use an approximate aperture 00238 efficiency conversion. If you give telescopeparm a list , 00239 then if the list has a single float it is assumed to 00240 be the gain in Jy/K, if two or more elements they are assumed 00241 to be telescope diameter (m) and aperture efficiency 00242 respectively. 00243 00244 Note that sdbaseline assumes that the fluxunit is set correctly in 00245 the data already. If not, then set telescopeparm='FIX' and it 00246 will set the default units to fluxunit without conversion. 00247 NOTE: If the data in infile is an ms from GBT and the default flux 00248 unit is missing and this task automatically fixes the default fluxunit 00249 to 'K' before the conversion. 00250 00251 WARNING for the GBT raw SDFITS format data as input: 00252 SDtasks are able to handle GBT raw SDFITS format data since the 00253 data filler is available. However, the functionality is not well 00254 tested yet, so that there may be unknown bugs. 00255 00256 00257 """ 00258 if type(scanlist)==int: scanlist=[scanlist] 00259 if type(iflist)==int: iflist=[iflist] 00260 if type(pollist)==int: pollist=[pollist] 00261 if type(edge)==int: edge=[edge] 00262 00263 # 00264 # The following is work around to avoid a bug with current python translation 00265 # 00266 mytmp = {} 00267 00268 mytmp['infile'] = infile 00269 mytmp['antenna'] = antenna 00270 mytmp['fluxunit'] = fluxunit 00271 mytmp['telescopeparm'] = telescopeparm 00272 mytmp['specunit'] = specunit 00273 mytmp['restfreq'] = restfreq 00274 mytmp['frame'] = frame 00275 mytmp['doppler'] = doppler 00276 mytmp['scanlist'] = scanlist 00277 mytmp['field'] = field 00278 mytmp['iflist'] = iflist 00279 mytmp['pollist'] = pollist 00280 mytmp['tau'] = tau 00281 mytmp['masklist'] = masklist 00282 mytmp['maskmode'] = maskmode 00283 mytmp['thresh'] = thresh 00284 mytmp['avg_limit'] = avg_limit 00285 mytmp['edge'] = edge 00286 mytmp['blfunc'] = blfunc 00287 mytmp['order'] = order 00288 mytmp['npiece'] = npiece 00289 mytmp['applyfft'] = applyfft 00290 mytmp['fftmethod'] = fftmethod 00291 mytmp['fftthresh'] = fftthresh 00292 mytmp['addwn'] = addwn 00293 mytmp['rejwn'] = rejwn 00294 mytmp['clipthresh'] = clipthresh 00295 mytmp['clipniter'] = clipniter 00296 mytmp['verify'] = verify 00297 mytmp['verbose'] = verbose 00298 mytmp['bloutput'] = bloutput 00299 mytmp['blformat'] = blformat 00300 mytmp['showprogress'] = showprogress 00301 mytmp['minnrow'] = minnrow 00302 mytmp['outfile'] = outfile 00303 mytmp['outform'] = outform 00304 mytmp['overwrite'] = overwrite 00305 mytmp['plotlevel'] = plotlevel 00306 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00307 trec = casac.utils().torecord(pathname+'sdbaseline.xml') 00308 00309 casalog.origin('sdbaseline') 00310 if trec.has_key('sdbaseline') and casac.utils().verify(mytmp, trec['sdbaseline']) : 00311 result = task_sdbaseline.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) 00312 00313 else : 00314 result = False 00315 return result