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_sdfit 00013 def sdfit(infile='', antenna=0, fluxunit='', telescopeparm='', specunit='', restfreq='', frame='', doppler='', scanlist=[], field='', iflist=[], pollist=[], fitfunc='gauss', fitmode='auto', maskline=[], invertmask=False, nfit=[], thresh=5.0, min_nchan=3, avg_limit=4, box_size=0.2, edge=[0], outfile='', overwrite=False, plotlevel=0): 00014 00015 """ASAP SD task: fit a spectral line 00016 Keyword arguments: 00017 infile -- name of input SD dataset 00018 default: none - must input file name 00019 example: 'mysd.asap' 00020 See sdcal for allowed formats. 00021 antenna -- antenna name or id (only effective for MS input). 00022 fluxunit -- units for line flux 00023 options: (str) 'K','Jy','' 00024 default: '' (keep current fluxunit) 00025 WARNING: For GBT data, see description below. 00026 >>> fluxunit expandable parameter 00027 telescopeparm -- the telescope characteristics 00028 options: (str) name or (list) list of gain info 00029 default: '' (none set) 00030 example: if telescopeparm='', it tries to get the telescope 00031 name from the data. 00032 Full antenna parameters (diameter,ap.eff.) known 00033 to ASAP are 00034 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43', 00035 'CEDUNA','HOBART'. For GBT, it fixes default fluxunit 00036 to 'K' first then convert to a new fluxunit. 00037 telescopeparm=[104.9,0.43] diameter(m), ap.eff. 00038 telescopeparm=[0.743] gain in Jy/K 00039 telescopeparm='FIX' to change default fluxunit 00040 see description below 00041 00042 specunit -- units for spectral axis 00043 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz','' 00044 default: '' (=current) 00045 example: this will be the units for maskline 00046 >>> specunit expandable parameters 00047 restfreq -- rest frequency 00048 available type includes float, int, string, list of float, 00049 list of int, list of string, and list of dictionary. the 00050 default unit of restfreq in case of float, int, or string 00051 without unit is Hz. string input can be a value only 00052 (treated as Hz) or a value followed by unit for which 'GHz', 00053 'MHz','kHz',and 'Hz' are available. 00054 a list can be used to set different rest frequencies for 00055 each IF. the length of list input must be nIF. dictionary 00056 input should be a pair of molecule name and frequency with 00057 keys of 'name' and 'value', respectively. values in the 00058 dictionary input follows the same manner as for single 00059 float or string input. 00060 example: 345.796 00061 '1420MHz' 00062 [345.8, 347.0, 356.7] 00063 ['345.8MHz', '347.0MHz', '356.7MHz'] 00064 [{'name':'CO','value':345}] 00065 frame -- frequency frame for spectral axis 00066 options: (str) 'LSRK','REST','TOPO','LSRD','BARY', 00067 'GEO','GALACTO','LGROUP','CMB' 00068 default: currently set frame in scantable 00069 WARNING: frame='REST' not yet implemented 00070 doppler -- doppler mode 00071 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA' 00072 default: currently set doppler in scantable 00073 scanlist -- list of scan numbers to process 00074 default: [] (use all scans) 00075 example: [21,22,23,24] 00076 field -- selection string for selecting scans by name 00077 default: '' (no name selection) 00078 example: 'FLS3a*' 00079 this selection is in addition to scanlist and iflist 00080 iflist -- list of IF id numbers to select 00081 default: [] (use all IFs) 00082 example: [15] 00083 pollist -- list of polarization id numbers to select 00084 default: [] (use all polarizations) 00085 example: [1] 00086 fitfunc -- function for fitting 00087 options: (str) 'gauss','lorentz' 00088 default: 'gauss' 00089 fitmode -- mode for fitting 00090 options: (str) 'list','auto','interact' 00091 default: 'auto' 00092 example: 'list' will use maskline to define regions to 00093 fit for lines with nfit in each 00094 'auto' will use the linefinder to fit for lines 00095 using the following parameters 00096 'interact' allows adding and deleting mask 00097 regions by drawing rectangles on the plot 00098 with mouse. Draw a rectangle with LEFT-mouse 00099 to ADD the region to the mask and with RIGHT-mouse 00100 to DELETE the region. 00101 00102 >>> fitmode expandable parameters 00103 thresh -- S/N threshold for linefinder 00104 default: 5 00105 example: a single channel S/N ratio above which the channel is 00106 considered to be a detection 00107 min_nchan -- minimum number of consecutive channels for linefinder 00108 default: 3 00109 example: minimum number of consecutive channels required to pass threshold 00110 avg_limit -- channel averaging for broad lines 00111 default: 4 00112 example: a number of consecutive channels not greater than 00113 this parameter can be averaged to search for broad lines 00114 box_size -- running mean box size 00115 default: 0.2 00116 example: a running mean box size specified as a fraction 00117 of the total spectrum length 00118 edge -- channels to drop at beginning and end of spectrum 00119 default: 0 00120 example: [1000] drops 1000 channels at beginning AND end 00121 [1000,500] drops 1000 from beginning and 500 from end 00122 00123 Note: For bad baselines threshold should be increased, 00124 and avg_limit decreased (or even switched off completely by 00125 setting this parameter to 1) to avoid detecting baseline 00126 undulations instead of real lines. 00127 00128 maskline -- list of mask regions to INCLUDE in LINE fitting 00129 default: all 00130 example: maskline=[[3900,4300]] for a single region, or 00131 maskline=[[3900,4300],[5000,5400]] for two, etc. 00132 invertmask -- invert mask (EXCLUDE masklist instead) 00133 options: (bool) True, False 00134 default: False 00135 example: invertmask=True, then will make one region that is 00136 the exclusion of the maskline regions 00137 nfit -- list of number of gaussian/lorentzian lines to fit in in maskline region (ignored when fitmode='auto') 00138 default: 0 (no fitting) 00139 example: nfit=[1] for single line in single region, 00140 nfit=[2] for two lines in single region, 00141 nfit=[1,1] for single lines in each of two regions, etc. 00142 outfile -- name of output file for fit results 00143 default: no output fit file 00144 example: 'mysd.fit' 00145 overwrite -- overwrite the outfile if already exists 00146 options: (bool) True, False 00147 default: False 00148 plotlevel -- control for plotting of results 00149 options: (int) 0=none, 1=some, 2=more 00150 default: 0 (no plotting) 00151 example: plotlevel=1 plots fit 00152 plotlevel=2 plots fit and residual 00153 no hardcopy available for fitter 00154 WARNING: be careful plotting OTF data with lots of fields 00155 00156 ------------------------------------------------------------------- 00157 Returns a Python dictionary of line statistics 00158 keys: 'peak','cent','fwhm','nfit' 00159 example: each value is a list of lists with one list of 00160 2 entries [fitvalue,error] per component. 00161 e.g. xstat['peak']=[[234.9, 4.8],[234.2, 5.3]] 00162 for 2 components. 00163 00164 00165 DESCRIPTION: 00166 00167 Task sdfit is a basic line-fitter for single-dish spectra. 00168 It assumes that the spectra have been calibrated in sdcal 00169 or sdreduce. 00170 00171 Furthermore, it assumes that any selection of scans, IFs, 00172 polarizations, and time and channel averaging/smoothing has 00173 also already been done (in other sd tasks) as there are no controls 00174 for these. Note that you can use sdsave to do selection, writing 00175 out a new scantable. 00176 00177 Note that multiple scans, IFs, and polarizations can in principle 00178 be handled, but we recommend that you use scanlist, field, iflist, 00179 and pollist to give a single selection for each fit. 00180 00181 Currently, you can choose Gaussian or Lorentzian profile as a 00182 fitting model. 00183 00184 For complicated spectra, sdfit does not do a good job of 00185 "auto-guessing" the starting model for the fit. We recommend 00186 you use sd.fitter in the toolkit which has more options, such 00187 as fixing components in the fit and supplying starting guesses 00188 by hand. 00189 00190 WARNING: sdfit will currently return the fit for the first 00191 row in the scantable. 00192 00193 ASAP recognizes the data of the "AT" telescopes, but currently 00194 does not know about the GBT or any other telescope. This task 00195 does know about GBT. Telescope name is obtained from the data. 00196 If you wish to change the fluxunit (see below), and telescopeparm='', 00197 for the AT telescopes it will use internal telescope parameters for 00198 flux conversion. For GBT, it will use an approximate aperture 00199 efficiency conversion. If you give telescopeparm a list, then 00200 if the list has a single float it is assumed to be the gain in Jy/K, 00201 if two or more elements they are assumed to be telescope diameter (m) 00202 and aperture efficiency respectively. 00203 00204 WARNING for the GBT raw SDFITS format data as input: 00205 SDtasks are able to handle GBT raw SDFITS format data since the 00206 data filler is available. However, the functionality is not well 00207 tested yet, so that there may be unknown bugs. 00208 00209 00210 """ 00211 if type(scanlist)==int: scanlist=[scanlist] 00212 if type(iflist)==int: iflist=[iflist] 00213 if type(pollist)==int: pollist=[pollist] 00214 if type(nfit)==int: nfit=[nfit] 00215 if type(edge)==int: edge=[edge] 00216 00217 # 00218 # The following is work around to avoid a bug with current python translation 00219 # 00220 mytmp = {} 00221 00222 mytmp['infile'] = infile 00223 mytmp['antenna'] = antenna 00224 mytmp['fluxunit'] = fluxunit 00225 mytmp['telescopeparm'] = telescopeparm 00226 mytmp['specunit'] = specunit 00227 mytmp['restfreq'] = restfreq 00228 mytmp['frame'] = frame 00229 mytmp['doppler'] = doppler 00230 mytmp['scanlist'] = scanlist 00231 mytmp['field'] = field 00232 mytmp['iflist'] = iflist 00233 mytmp['pollist'] = pollist 00234 mytmp['fitfunc'] = fitfunc 00235 mytmp['fitmode'] = fitmode 00236 mytmp['maskline'] = maskline 00237 mytmp['invertmask'] = invertmask 00238 mytmp['nfit'] = nfit 00239 mytmp['thresh'] = thresh 00240 mytmp['min_nchan'] = min_nchan 00241 mytmp['avg_limit'] = avg_limit 00242 mytmp['box_size'] = box_size 00243 mytmp['edge'] = edge 00244 mytmp['outfile'] = outfile 00245 mytmp['overwrite'] = overwrite 00246 mytmp['plotlevel'] = plotlevel 00247 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00248 trec = casac.utils().torecord(pathname+'sdfit.xml') 00249 00250 casalog.origin('sdfit') 00251 if trec.has_key('sdfit') and casac.utils().verify(mytmp, trec['sdfit']) : 00252 result = task_sdfit.sdfit(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, fitfunc, fitmode, maskline, invertmask, nfit, thresh, min_nchan, avg_limit, box_size, edge, outfile, overwrite, plotlevel) 00253 00254 else : 00255 result = False 00256 return result