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