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_sdsave import sdsave 00016 from task_sdsave import casalog 00017 00018 class sdsave_pg_: 00019 __name__ = "sdsave" 00020 00021 def __init__(self) : 00022 self.__bases__ = (sdsave_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infile=None, antenna=None, getpt=None, rowlist=None, scanlist=None, field=None, iflist=None, pollist=None, scanaverage=None, timeaverage=None, tweight=None, polaverage=None, pweight=None, restfreq=None, outfile=None, outform=None, overwrite=None, async=None): 00027 00028 """ASAP SD task: save the sd spectra in various format 00029 Keyword arguments: 00030 infile -- name of input SD dataset 00031 antenna -- antenna name or id (only effective for MS input). 00032 getpt -- fill DIRECTION column properly, or reuse POINTING table 00033 in original MS (only effective for MS input) 00034 default: True 00035 options: True (fill DIRECTION column properly) 00036 False (reuse POINTING table in original MS) 00037 rowlist -- list of row numbers to process 00038 default: [] (use all rows) 00039 example: [0,2,4,6] 00040 For expert users only! 00041 this selection is applied first, and then followed by 00042 the selection with scans, fields, ifs, and polarizations. 00043 scanlist -- list of to process 00044 default: [] (use all scans) 00045 example: [21,22,23,24] 00046 this selection is in addition to field, iflist, and pollist 00047 field -- selection string for selecting scans by name 00048 default: '' (no name selection) 00049 example: 'FLS3a*' 00050 this selection is in addition to scanlist, iflist, and pollist 00051 iflist -- list of IF id numbers to select 00052 default: [] (use all IFs) 00053 example: [15] 00054 this selection is in addition to scanlist, field, and pollist 00055 pollist -- list of polarization id numbers to select 00056 default: [] (use all polarizations) 00057 example: [1] 00058 this selection is in addition to scanlist, field, and iflist 00059 scanaverage -- average integrations within scans 00060 options: (bool) True,False 00061 default: False 00062 example: if True, average integrations before it is saved 00063 timeaverage -- average times for multiple scan cycles 00064 options: (bool) True,False 00065 default: False 00066 >>>timeaverage expandable parameter 00067 tweight -- weighting for time average 00068 options: 'none' 00069 'var' (1/var(spec) weighted) 00070 'tsys' (1/Tsys**2 weighted) 00071 'tint' (integration time weighted) 00072 'tintsys' (Tint/Tsys**2) 00073 'median' ( median averaging) 00074 default: 'none' 00075 00076 polaverage -- average polarizations 00077 options: (bool) True,False 00078 default: False 00079 >>>polaverage expandable parameter 00080 pweight -- weighting for polarization average 00081 options: 'none' 00082 'var' (1/var(spec) weighted) 00083 'tsys' (1/Tsys**2 weighted) 00084 restfreq -- rest frequencies of output data 00085 Available types are a number, string, a list of numbers or 00086 strings (see examples below), and list of dictionaries. 00087 The default unit of restfreq is Hz, if not specified. 00088 A list can be used to set different rest frequencies to 00089 each IF. the length of list input must be nIF. Dictionary 00090 input should be a pair of molecule name and frequency with 00091 keys of 'name' and 'value', respectively. The 'value's in the 00092 dictionary input follows the same manner as for single 00093 float or string input. 00094 default: '' (use current setting) 00095 example: 4.6e10 (float value in Hz), 00096 '46GHz' (string with unit), 00097 ['345.8GHz', '347.0GHz', 356.7e9] (for each IF) 00098 [{'name':'CO','value':345e9}] (a value with name) 00099 outfile -- name of output dataset 00100 default: '' 00101 outform -- output data format 00102 default: 'ASAP' 00103 Options: 'ASAP', 'MS2', 'SDFITS', 'ASCII' 00104 overwrite -- overwrite the output file if already exists 00105 options: (bool) True,False 00106 default: False 00107 WARNING: if outform='ASCII', this parameter is ignored 00108 00109 00110 DESCRIPTION: 00111 00112 Task sdsave writes the single dish data to a disk file in 00113 specified format (ASAP, MS2, SDFITS, ASCII). It is possible to 00114 save the subset of the data by selecting row numbers, scan numbers, 00115 IF ids, polarization ids and field names. The ASAP (scantable) format 00116 is recommended for further analysis using Sd tool. For further 00117 imaging using imager, save the data to the Measurement Set (MS2). 00118 00119 Note that setting getpt=False needs a lot of attention. 00120 If you set getpt=False, the task retrieves pointing direction from 00121 MS's FIELD table, which might not be correct for single dish 00122 observation, instead to check MS's POINTING table, which is the 00123 default behavior of the task (getpt=True). To compensate this, 00124 absolute path to MS's POINTING table is stored, and it will be used 00125 for POINTING table when the data is converted back to MS format. 00126 In general, getpt=False is faster especially for large data. However, 00127 MS created from Scantable cannot have correct POINTING table if 00128 original MS's POINTING table doesn't exist. Such situation will 00129 happen when original MS is removed or renamed, or imported Scantable 00130 is moved to other computer alone. 00131 00132 WARNING for the GBT raw SDFITS format data as input: 00133 SDtasks are able to handle GBT raw SDFITS format data since the 00134 data filler is available. However, the functionality is not well 00135 tested yet, so that there may be unknown bugs. 00136 00137 00138 """ 00139 a=inspect.stack() 00140 stacklevel=0 00141 for k in range(len(a)): 00142 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00143 stacklevel=k 00144 break 00145 myf=sys._getframe(stacklevel).f_globals 00146 myf['__last_task'] = 'sdsave' 00147 myf['taskname'] = 'sdsave' 00148 ### 00149 myf['update_params'](func=myf['taskname'],printtext=False) 00150 ### 00151 ### 00152 #Handle globals or user over-ride of arguments 00153 # 00154 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00155 useLocalDefaults = False 00156 00157 for item in function_signature_defaults.iteritems(): 00158 key,val = item 00159 keyVal = eval(key) 00160 if (keyVal == None): 00161 #user hasn't set it - use global/default 00162 pass 00163 else: 00164 #user has set it - use over-ride 00165 if (key != 'self') : 00166 useLocalDefaults = True 00167 #myf[key]=keyVal 00168 00169 myparams = {} 00170 if useLocalDefaults : 00171 for item in function_signature_defaults.iteritems(): 00172 key,val = item 00173 keyVal = eval(key) 00174 exec('myparams[key] = keyVal') 00175 if (keyVal == None): 00176 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00177 keyVal = eval(key) 00178 if(type(keyVal) == dict) : 00179 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00180 00181 else : 00182 uselessvariable = None 00183 myparams['infile'] = infile = myf['infile'] 00184 myparams['antenna'] = antenna = myf['antenna'] 00185 myparams['getpt'] = getpt = myf['getpt'] 00186 myparams['rowlist'] = rowlist = myf['rowlist'] 00187 myparams['scanlist'] = scanlist = myf['scanlist'] 00188 myparams['field'] = field = myf['field'] 00189 myparams['iflist'] = iflist = myf['iflist'] 00190 myparams['pollist'] = pollist = myf['pollist'] 00191 myparams['scanaverage'] = scanaverage = myf['scanaverage'] 00192 myparams['timeaverage'] = timeaverage = myf['timeaverage'] 00193 myparams['tweight'] = tweight = myf['tweight'] 00194 myparams['polaverage'] = polaverage = myf['polaverage'] 00195 myparams['pweight'] = pweight = myf['pweight'] 00196 myparams['restfreq'] = restfreq = myf['restfreq'] 00197 myparams['outfile'] = outfile = myf['outfile'] 00198 myparams['outform'] = outform = myf['outform'] 00199 myparams['overwrite'] = overwrite = myf['overwrite'] 00200 00201 if type(rowlist)==int: rowlist=[rowlist] 00202 if type(scanlist)==int: scanlist=[scanlist] 00203 if type(iflist)==int: iflist=[iflist] 00204 if type(pollist)==int: pollist=[pollist] 00205 00206 result = None 00207 00208 # 00209 # The following is work around to avoid a bug with current python translation 00210 # 00211 mytmp = {} 00212 00213 mytmp['infile'] = infile 00214 mytmp['antenna'] = antenna 00215 mytmp['getpt'] = getpt 00216 mytmp['rowlist'] = rowlist 00217 mytmp['scanlist'] = scanlist 00218 mytmp['field'] = field 00219 mytmp['iflist'] = iflist 00220 mytmp['pollist'] = pollist 00221 mytmp['scanaverage'] = scanaverage 00222 mytmp['timeaverage'] = timeaverage 00223 mytmp['tweight'] = tweight 00224 mytmp['polaverage'] = polaverage 00225 mytmp['pweight'] = pweight 00226 mytmp['restfreq'] = restfreq 00227 mytmp['outfile'] = outfile 00228 mytmp['outform'] = outform 00229 mytmp['overwrite'] = overwrite 00230 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00231 trec = casac.utils().torecord(pathname+'sdsave.xml') 00232 00233 casalog.origin('sdsave') 00234 if not trec.has_key('sdsave') or not casac.utils().verify(mytmp, trec['sdsave']) : 00235 return False 00236 00237 00238 try : 00239 casalog.post('') 00240 casalog.post('##########################################') 00241 casalog.post('##### Begin Task: sdsave #####') 00242 casalog.post('') 00243 result = sdsave(infile, antenna, getpt, rowlist, scanlist, field, iflist, pollist, scanaverage, timeaverage, tweight, polaverage, pweight, restfreq, outfile, outform, overwrite) 00244 casalog.post('') 00245 casalog.post('##### End Task: sdsave #####') 00246 casalog.post('##########################################') 00247 00248 00249 # saveinputs for individule engine has no use 00250 # saveinputs should alos be removed from casa_in_py.py 00251 # 00252 # 00253 # saveinputs = myf['saveinputs'] 00254 # saveinputs('sdsave', 'sdsave.last', myparams) 00255 # 00256 # 00257 except Exception, instance: 00258 #print '**** Error **** ',instance 00259 pass 00260 00261 gc.collect() 00262 return result 00263 # 00264 # 00265 ## 00266 # def paramgui(self, useGlobals=True): 00267 # """ 00268 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00269 # """ 00270 # import paramgui 00271 # 00272 # a=inspect.stack() 00273 # stacklevel=0 00274 # for k in range(len(a)): 00275 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00276 # stacklevel=k 00277 # break 00278 # myf = sys._getframe(stacklevel).f_globals 00279 # 00280 # if useGlobals: 00281 # paramgui.setGlobals(myf) 00282 # else: 00283 # paramgui.setGlobals({}) 00284 # 00285 # paramgui.runTask('sdsave', myf['_ip']) 00286 # paramgui.setGlobals({}) 00287 # 00288 # 00289 # 00290 # 00291 def defaults(self, param=None): 00292 a=inspect.stack() 00293 stacklevel=0 00294 for k in range(len(a)): 00295 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00296 stacklevel=k 00297 break 00298 myf=sys._getframe(stacklevel).f_globals 00299 a = odict() 00300 a['infile'] = '' 00301 a['antenna'] = 0 00302 a['getpt'] = True 00303 a['rowlist'] = [] 00304 a['scanlist'] = [] 00305 a['field'] = '' 00306 a['iflist'] = [] 00307 a['pollist'] = [] 00308 a['scanaverage'] = False 00309 a['timeaverage'] = False 00310 a['polaverage'] = False 00311 a['restfreq'] = '' 00312 a['outfile'] = '' 00313 a['outform'] = 'ASAP' 00314 a['overwrite'] = False 00315 00316 a['async']=False 00317 a['timeaverage'] = { 00318 0:{'value':False}, 00319 1:odict([{'value':True}, {'tweight':'none'}])} 00320 a['polaverage'] = { 00321 0:{'value':False}, 00322 1:odict([{'value':True}, {'pweight':'none'}])} 00323 00324 ### This function sets the default values but also will return the list of 00325 ### parameters or the default value of a given parameter 00326 if(param == None): 00327 myf['__set_default_parameters'](a) 00328 elif(param == 'paramkeys'): 00329 return a.keys() 00330 else: 00331 if(a.has_key(param)): 00332 #if(type(a[param]) == dict) : 00333 # return a[param][len(a[param])-1]['value'] 00334 #else : 00335 return a[param] 00336 00337 00338 # 00339 # 00340 def check_params(self, param=None, value=None): 00341 a=inspect.stack() 00342 stacklevel=0 00343 for k in range(len(a)): 00344 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00345 stacklevel=k 00346 break 00347 myf=sys._getframe(stacklevel).f_globals 00348 00349 # print 'param:', param, 'value:', value 00350 try : 00351 if str(type(value)) != "<type 'instance'>" : 00352 value0 = value 00353 value = myf['cu'].expandparam(param, value) 00354 matchtype = False 00355 if(type(value) == numpy.ndarray): 00356 if(type(value) == type(value0)): 00357 myf[param] = value.tolist() 00358 else: 00359 #print 'value:', value, 'value0:', value0 00360 #print 'type(value):', type(value), 'type(value0):', type(value0) 00361 myf[param] = value0 00362 if type(value0) != list : 00363 matchtype = True 00364 else : 00365 myf[param] = value 00366 value = myf['cu'].verifyparam({param:value}) 00367 if matchtype: 00368 value = False 00369 except Exception, instance: 00370 #ignore the exception and just return it unchecked 00371 myf[param] = value 00372 return value 00373 00374 # 00375 # 00376 def description(self, key='sdsave', subkey=None): 00377 desc={'sdsave': 'ASAP SD task: save the sd spectra in various format', 00378 'infile': 'name of input SD dataset', 00379 'antenna': 'antenna name or id (only effective for MS input)', 00380 'getpt': 'fill DIRECTION column properly, or reuse POINTING table in original MS (only effective for MS input)', 00381 'rowlist': 'list of row numbers to process (e.g. [0,2,4,6])', 00382 'scanlist': 'list of scan to process (e.g. [20,21,22,23])', 00383 'field': 'string for selection by source name', 00384 'iflist': 'list of IF ids to select (e.g. [0,1])', 00385 'pollist': 'list of polarization ids to select (e.g. [0,1])', 00386 'scanaverage': 'average integs within scans (True,False) ', 00387 'timeaverage': 'average scans over time (True,False)', 00388 'tweight': 'weighting for time averaging', 00389 'polaverage': 'average over polarizations (True,False)', 00390 'pweight': '', 00391 'restfreq': 'rest frequency (default unit: Hz)', 00392 'outfile': 'output file name', 00393 'outform': 'output file format (ASCII,MS2,SDFITS,ASAP)', 00394 'overwrite': 'overwrite the output file if already exists', 00395 00396 'async': 'If true the taskname must be started using sdsave(...)' 00397 } 00398 00399 # 00400 # Set subfields defaults if needed 00401 # 00402 00403 if(desc.has_key(key)) : 00404 return desc[key] 00405 00406 def itsdefault(self, paramname) : 00407 a = {} 00408 a['infile'] = '' 00409 a['antenna'] = 0 00410 a['getpt'] = True 00411 a['rowlist'] = [] 00412 a['scanlist'] = [] 00413 a['field'] = '' 00414 a['iflist'] = [] 00415 a['pollist'] = [] 00416 a['scanaverage'] = False 00417 a['timeaverage'] = False 00418 a['tweight'] = 'none' 00419 a['polaverage'] = False 00420 a['pweight'] = 'none' 00421 a['restfreq'] = '' 00422 a['outfile'] = '' 00423 a['outform'] = 'ASAP' 00424 a['overwrite'] = False 00425 00426 if a.has_key(paramname) : 00427 return a[paramname] 00428 sdsave_pg = sdsave_pg_()