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_importasdm import importasdm 00016 from task_importasdm import casalog 00017 00018 class importasdm_pg_: 00019 __name__ = "importasdm" 00020 00021 def __init__(self) : 00022 self.__bases__ = (importasdm_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, asdm=None, vis=None, singledish=None, antenna=None, corr_mode=None, srt=None, time_sampling=None, ocorr_mode=None, compression=None, asis=None, wvr_corrected_data=None, scans=None, ignore_time=None, process_syspower=None, process_caldevice=None, process_pointing=None, process_flags=None, tbuff=None, applyflags=None, savecmds=None, outfile=None, verbose=None, overwrite=None, showversion=None, useversion=None, async=None): 00027 00028 """Convert an ALMA Science Data Model observation into a CASA visibility file (MS) or single-dish data format (Scantable) 00029 Keyword arguments: 00030 asdm -- Name of input ASDM file (directory) 00031 default: none; example: asdm='ExecBlock3' 00032 00033 vis -- Root ms or scantable name, note a prefix (.ms or .asap) is NOT appended to this name 00034 default: none 00035 00036 singledish -- Set True to write data as single-dish format (Scantable) 00037 default: False 00038 00039 >>> singledish expandable parameter 00040 antenna -- antenna name or id. 00041 00042 corr_mode -- correlation mode to be considered on input. Could 00043 be one or more of the following, ao, co, ac, or all 00044 default: 'all' 00045 00046 srt -- spectral resolution type. Could be one or more of 00047 the following, fr, ca, bw, or all 00048 default: 'all' 00049 00050 time_sampling -- specifies the time sampling, INTEGRATION and/or 00051 SUBINTEGRAION. could be one or more of the following 00052 i, si, or all. 00053 default: 'all' 00054 00055 ocorr_mode -- output data for correlation mode AUTO_ONLY 00056 (ao) or CROSS_ONLY (co) or CROSS_AND_AUTO (ca) 00057 default: 'ca' 00058 00059 00060 compression -- produces comrpressed columns in the resulting measurement set. 00061 default: False 00062 00063 00064 asis -- creates verbatim copies of the ASDM tables in 00065 the output measurement set. The value given to 00066 this option must be a list of table names separated 00067 by space characters; the wildcard character '*' is 00068 allowed in table names. 00069 default: none 00070 00071 wvr_corrected_data -- specifies wich values are considered in the 00072 ASDM binary data to fill the DATA column in 00073 the MAIN table of the MS. Expected values for 00074 this option are 'no' for the uncorrected data 00075 (this is the default), 'yes' for the corrected 00076 data and 'both' for corrected and uncorrected 00077 data. In the latter case, two measurement sets 00078 are created, one containing the uncorrected 00079 data and the other one, whose name is suffixed 00080 by '-wvr-corrected', containing the corrected 00081 data. 00082 default: 'no' 00083 00084 scans -- processes only the scans specified in the option's value. This value is a semicolon 00085 separated list of scan specifications. A scan specification consists in an exec bock index 00086 followed by the character ':' followed by a comma separated list of scan indexes or scan 00087 index ranges. A scan index is relative to the exec block it belongs to. Scan indexes are 00088 1-based while exec blocks's are 0-based. '0:1' or '2:2~6' or '0:1,1:2~6,8;2:,3:24~30' '1,2' 00089 are valid values for the option. '3:' alone will be interpreted as 'all the scans of the 00090 exec block#3'. An scan index or a scan index range not preceded by an exec block index will 00091 be interpreted as 'all the scans with such indexes in all the exec blocks'. By default 00092 all the scans are considered. 00093 default: none (all scans) 00094 00095 ignore_time -- All the rows of the tables Feed, History, Pointing, Source, SysCal, CalDevice, SysPower, 00096 and Weather are processed independently of the time range of the selected exec block / scan. 00097 default: False 00098 00099 process_syspower -- The SysPower table is processed if and only if this parameter is set to True. 00100 default: True 00101 00102 process_caldevice -- The CalDevice table is processed if and only if this parameter is set to True. 00103 default: True 00104 00105 process_pointing -- The Pointing table is processed if and only if this parameter is set to True. 00106 default: True 00107 00108 process_flags -- Create online flags based on the Flag.xml, Antenna.xml and SpectralWindow.xml files 00109 and copy them to the FLAG_CMD sub-table of the MS. The flags will NOT be applied unless 00110 the parameter applyflags is set to True. Optionally, the flags can also be saved to 00111 an external ASCII file if savecmds is set to True. 00112 default: True 00113 00114 >>> process_flags expandable parameter 00115 tbuff -- Time padding buffer (in seconds) 00116 default: 0.0 00117 00118 NOTE: this time is in seconds. You should currently 00119 set the value of tbuff to be 1.5x the correlator 00120 integration time if greater than 1 second. For 00121 example, if the SDM has integrations of 3 seconds, 00122 set tbuff=4.5. Likewise, set tbuff=15.0 for 10-sec 00123 integrations. 00124 00125 applyflags -- Apply the online flags to the MS. 00126 default: False 00127 00128 00129 savecmds -- Save the flag commands to an ASCII file given by the parameter outfile. 00130 default: False 00131 00132 outfile -- Filename where to save the flag commands. 00133 default: ' ' --> by default it will save on a filename composed from the MS name. 00134 Example: vis='uid_A02.ms', the outfile will be 'uid_A02_cmd.txt'. 00135 00136 NOTE: The file is open to save in append mode. 00137 00138 00139 verbose -- produce log output as asdm2MS is being run 00140 default: False 00141 00142 showversion -- report the version of the asdm2MS being used. 00143 default: False 00144 00145 useversion -- Selects the version of asdm2MS to be used (\'v3\' (default, should work for all data)) 00146 default: v3 00147 00148 00149 """ 00150 a=inspect.stack() 00151 stacklevel=0 00152 for k in range(len(a)): 00153 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00154 stacklevel=k 00155 break 00156 myf=sys._getframe(stacklevel).f_globals 00157 myf['__last_task'] = 'importasdm' 00158 myf['taskname'] = 'importasdm' 00159 ### 00160 myf['update_params'](func=myf['taskname'],printtext=False) 00161 ### 00162 ### 00163 #Handle globals or user over-ride of arguments 00164 # 00165 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00166 useLocalDefaults = False 00167 00168 for item in function_signature_defaults.iteritems(): 00169 key,val = item 00170 keyVal = eval(key) 00171 if (keyVal == None): 00172 #user hasn't set it - use global/default 00173 pass 00174 else: 00175 #user has set it - use over-ride 00176 if (key != 'self') : 00177 useLocalDefaults = True 00178 #myf[key]=keyVal 00179 00180 myparams = {} 00181 if useLocalDefaults : 00182 for item in function_signature_defaults.iteritems(): 00183 key,val = item 00184 keyVal = eval(key) 00185 exec('myparams[key] = keyVal') 00186 if (keyVal == None): 00187 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00188 keyVal = eval(key) 00189 if(type(keyVal) == dict) : 00190 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00191 00192 else : 00193 uselessvariable = None 00194 myparams['asdm'] = asdm = myf['asdm'] 00195 myparams['vis'] = vis = myf['vis'] 00196 myparams['singledish'] = singledish = myf['singledish'] 00197 myparams['antenna'] = antenna = myf['antenna'] 00198 myparams['corr_mode'] = corr_mode = myf['corr_mode'] 00199 myparams['srt'] = srt = myf['srt'] 00200 myparams['time_sampling'] = time_sampling = myf['time_sampling'] 00201 myparams['ocorr_mode'] = ocorr_mode = myf['ocorr_mode'] 00202 myparams['compression'] = compression = myf['compression'] 00203 myparams['asis'] = asis = myf['asis'] 00204 myparams['wvr_corrected_data'] = wvr_corrected_data = myf['wvr_corrected_data'] 00205 myparams['scans'] = scans = myf['scans'] 00206 myparams['ignore_time'] = ignore_time = myf['ignore_time'] 00207 myparams['process_syspower'] = process_syspower = myf['process_syspower'] 00208 myparams['process_caldevice'] = process_caldevice = myf['process_caldevice'] 00209 myparams['process_pointing'] = process_pointing = myf['process_pointing'] 00210 myparams['process_flags'] = process_flags = myf['process_flags'] 00211 myparams['tbuff'] = tbuff = myf['tbuff'] 00212 myparams['applyflags'] = applyflags = myf['applyflags'] 00213 myparams['savecmds'] = savecmds = myf['savecmds'] 00214 myparams['outfile'] = outfile = myf['outfile'] 00215 myparams['verbose'] = verbose = myf['verbose'] 00216 myparams['overwrite'] = overwrite = myf['overwrite'] 00217 myparams['showversion'] = showversion = myf['showversion'] 00218 myparams['useversion'] = useversion = myf['useversion'] 00219 00220 00221 result = None 00222 00223 # 00224 # The following is work around to avoid a bug with current python translation 00225 # 00226 mytmp = {} 00227 00228 mytmp['asdm'] = asdm 00229 mytmp['vis'] = vis 00230 mytmp['singledish'] = singledish 00231 mytmp['antenna'] = antenna 00232 mytmp['corr_mode'] = corr_mode 00233 mytmp['srt'] = srt 00234 mytmp['time_sampling'] = time_sampling 00235 mytmp['ocorr_mode'] = ocorr_mode 00236 mytmp['compression'] = compression 00237 mytmp['asis'] = asis 00238 mytmp['wvr_corrected_data'] = wvr_corrected_data 00239 mytmp['scans'] = scans 00240 mytmp['ignore_time'] = ignore_time 00241 mytmp['process_syspower'] = process_syspower 00242 mytmp['process_caldevice'] = process_caldevice 00243 mytmp['process_pointing'] = process_pointing 00244 mytmp['process_flags'] = process_flags 00245 mytmp['tbuff'] = tbuff 00246 mytmp['applyflags'] = applyflags 00247 mytmp['savecmds'] = savecmds 00248 mytmp['outfile'] = outfile 00249 mytmp['verbose'] = verbose 00250 mytmp['overwrite'] = overwrite 00251 mytmp['showversion'] = showversion 00252 mytmp['useversion'] = useversion 00253 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00254 trec = casac.utils().torecord(pathname+'importasdm.xml') 00255 00256 casalog.origin('importasdm') 00257 if not trec.has_key('importasdm') or not casac.utils().verify(mytmp, trec['importasdm']) : 00258 return False 00259 00260 00261 try : 00262 casalog.post('') 00263 casalog.post('##########################################') 00264 casalog.post('##### Begin Task: importasdm #####') 00265 casalog.post('') 00266 result = importasdm(asdm, vis, singledish, antenna, corr_mode, srt, time_sampling, ocorr_mode, compression, asis, wvr_corrected_data, scans, ignore_time, process_syspower, process_caldevice, process_pointing, process_flags, tbuff, applyflags, savecmds, outfile, verbose, overwrite, showversion, useversion) 00267 casalog.post('') 00268 casalog.post('##### End Task: importasdm #####') 00269 casalog.post('##########################################') 00270 00271 00272 # saveinputs for individule engine has no use 00273 # saveinputs should alos be removed from casa_in_py.py 00274 # 00275 # 00276 # saveinputs = myf['saveinputs'] 00277 # saveinputs('importasdm', 'importasdm.last', myparams) 00278 # 00279 # 00280 except Exception, instance: 00281 #print '**** Error **** ',instance 00282 pass 00283 00284 gc.collect() 00285 return result 00286 # 00287 # 00288 ## 00289 # def paramgui(self, useGlobals=True): 00290 # """ 00291 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00292 # """ 00293 # import paramgui 00294 # 00295 # a=inspect.stack() 00296 # stacklevel=0 00297 # for k in range(len(a)): 00298 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00299 # stacklevel=k 00300 # break 00301 # myf = sys._getframe(stacklevel).f_globals 00302 # 00303 # if useGlobals: 00304 # paramgui.setGlobals(myf) 00305 # else: 00306 # paramgui.setGlobals({}) 00307 # 00308 # paramgui.runTask('importasdm', myf['_ip']) 00309 # paramgui.setGlobals({}) 00310 # 00311 # 00312 # 00313 # 00314 def defaults(self, param=None): 00315 a=inspect.stack() 00316 stacklevel=0 00317 for k in range(len(a)): 00318 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00319 stacklevel=k 00320 break 00321 myf=sys._getframe(stacklevel).f_globals 00322 a = odict() 00323 a['asdm'] = '' 00324 a['vis'] = '' 00325 a['singledish'] = False 00326 a['corr_mode'] = 'all' 00327 a['srt'] = 'all' 00328 a['time_sampling'] = 'all' 00329 a['ocorr_mode'] = 'ca' 00330 a['compression'] = False 00331 a['asis'] = '' 00332 a['wvr_corrected_data'] = 'no' 00333 a['scans'] = '' 00334 a['ignore_time'] = False 00335 a['process_syspower'] = True 00336 a['process_caldevice'] = True 00337 a['process_pointing'] = True 00338 a['process_flags'] = True 00339 a['verbose'] = False 00340 a['overwrite'] = False 00341 a['showversion'] = False 00342 a['useversion'] = 'v3' 00343 00344 a['async']=False 00345 a['singledish'] = { 00346 0:{'value':False}, 00347 1:odict([{'value':True}, {'antenna':0}])} 00348 a['process_flags'] = { 00349 0:odict([{'value':True}, {'tbuff':0.0}, {'applyflags':False}, {'savecmds':False}, {'outfile':''}]), 00350 1:{'value':False}} 00351 00352 ### This function sets the default values but also will return the list of 00353 ### parameters or the default value of a given parameter 00354 if(param == None): 00355 myf['__set_default_parameters'](a) 00356 elif(param == 'paramkeys'): 00357 return a.keys() 00358 else: 00359 if(a.has_key(param)): 00360 #if(type(a[param]) == dict) : 00361 # return a[param][len(a[param])-1]['value'] 00362 #else : 00363 return a[param] 00364 00365 00366 # 00367 # 00368 def check_params(self, param=None, value=None): 00369 a=inspect.stack() 00370 stacklevel=0 00371 for k in range(len(a)): 00372 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00373 stacklevel=k 00374 break 00375 myf=sys._getframe(stacklevel).f_globals 00376 00377 # print 'param:', param, 'value:', value 00378 try : 00379 if str(type(value)) != "<type 'instance'>" : 00380 value0 = value 00381 value = myf['cu'].expandparam(param, value) 00382 matchtype = False 00383 if(type(value) == numpy.ndarray): 00384 if(type(value) == type(value0)): 00385 myf[param] = value.tolist() 00386 else: 00387 #print 'value:', value, 'value0:', value0 00388 #print 'type(value):', type(value), 'type(value0):', type(value0) 00389 myf[param] = value0 00390 if type(value0) != list : 00391 matchtype = True 00392 else : 00393 myf[param] = value 00394 value = myf['cu'].verifyparam({param:value}) 00395 if matchtype: 00396 value = False 00397 except Exception, instance: 00398 #ignore the exception and just return it unchecked 00399 myf[param] = value 00400 return value 00401 00402 # 00403 # 00404 def description(self, key='importasdm', subkey=None): 00405 desc={'importasdm': 'Convert an ALMA Science Data Model observation into a CASA visibility file (MS) or single-dish data format (Scantable)', 00406 'asdm': 'Name of input asdm directory (on disk)', 00407 'vis': 'Root name of the ms to be created. Note the .ms is NOT added ', 00408 'singledish': 'Set true to output single-dish data format ', 00409 'antenna': 'antenna name or id', 00410 'corr_mode': 'specifies the correlation mode to be considered on input. A quoted string containing a sequence of ao, co, ac,or all separated by whitespaces is expected', 00411 'srt': 'specifies the spectral resolution type to be considered on input. A quoted string containing a sequence of fr, ca, bw, or all separated by whitespaces is expected', 00412 'time_sampling': 'specifies the time sampling (INTEGRATION and/or SUBINTEGRATION) to be considered on input. A quoted string containing a sequence of i, si, or all separated by whitespaces is expected', 00413 'ocorr_mode': 'output data for correlation mode AUTO_ONLY (ao) or CROSS_ONLY (co) or CROSS_AND_AUTO (ca)', 00414 'compression': 'Flag for turning on data compression', 00415 'asis': 'Creates verbatim copies of the ASDMtables in the ouput measurement set. Value given must be a string of table names separated by spaces; A * wildcard is allowed.', 00416 'wvr_corrected_data': ' Specifies which values are considerd in the SDM binary data to fill the DATA column in the MAIN table of the MS. Expected values for this option are: no, for uncorrected data (default), yes, for the corrected data, and both, for for corrected and uncorrected data. Note if both is selected two measurement sets are created, one with uncorrected data and the other with corrected data. ', 00417 'scans': 'processes only the specified scans. This value is a semicolon separated list of scan specifications. A scan specification consists in an exec bock index followed by the : character; followed by a comma separated list of scan indexes or scan index ranges. A scan index is relative to the exec block it belongs to. Scan indexes are 1-based while exec blocks are 0-based. "0:1" or "2:2~6" or "0:1,1:2~6,8;2:,3:24~30" "1,2" are valid values for the option. "3:" alone will be interpreted as, all the scans of the exec block#3. An scan index or a scan index range not preceded by an exec block index will be interpreted as, all the scans with such indexes in all the exec blocks. By default all the scans are considered. ', 00418 'ignore_time': 'All the rows of the tables Feed, History, Pointing, Source, SysCal, CalDevice, SysPower, and Weather are processed independently of the time range of the selected exec block / scan.', 00419 'process_syspower': ' The SysPower table is processed if and only if this parameter is set to true.', 00420 'process_caldevice': ' The CalDevice table is processed if and only if this parameter is set to true.', 00421 'process_pointing': ' The Pointing table is processed if and only if this parameter is set to true.', 00422 'process_flags': ' Create online flags in the FLAG_CMD sub-table.', 00423 'tbuff': ' Time padding buffer (seconds)', 00424 'applyflags': ' Apply the flags to the MS.', 00425 'savecmds': 'Save flag commands to an ASCII file', 00426 'outfile': 'Name of ASCII file to save flag commands', 00427 'verbose': 'Output lots of information while the filler is working', 00428 'overwrite': 'Over write an existing MS', 00429 'showversion': 'Report the version of asdm2MS being used', 00430 'useversion': 'Version of asdm2MS to be used (\'v3\' (default, should work for all data))', 00431 00432 'async': 'If true the taskname must be started using importasdm(...)' 00433 } 00434 00435 # 00436 # Set subfields defaults if needed 00437 # 00438 00439 if(desc.has_key(key)) : 00440 return desc[key] 00441 00442 def itsdefault(self, paramname) : 00443 a = {} 00444 a['asdm'] = '' 00445 a['vis'] = '' 00446 a['singledish'] = False 00447 a['antenna'] = 0 00448 a['corr_mode'] = 'all' 00449 a['srt'] = 'all' 00450 a['time_sampling'] = 'all' 00451 a['ocorr_mode'] = 'ca' 00452 a['compression'] = False 00453 a['asis'] = '' 00454 a['wvr_corrected_data'] = 'no' 00455 a['scans'] = '' 00456 a['ignore_time'] = False 00457 a['process_syspower'] = True 00458 a['process_caldevice'] = True 00459 a['process_pointing'] = True 00460 a['process_flags'] = True 00461 a['tbuff'] = 0.0 00462 a['applyflags'] = False 00463 a['savecmds'] = True 00464 a['outfile'] = '' 00465 a['verbose'] = False 00466 a['overwrite'] = False 00467 a['showversion'] = False 00468 a['useversion'] = 'v3' 00469 00470 if a.has_key(paramname) : 00471 return a[paramname] 00472 importasdm_pg = importasdm_pg_()