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_testconcat import testconcat 00016 from task_testconcat import casalog 00017 00018 class testconcat_pg_: 00019 __name__ = "testconcat" 00020 00021 def __init__(self) : 00022 self.__bases__ = (testconcat_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, testconcatvis=None, freqtol=None, dirtol=None, copypointing=None, async=None): 00027 00028 """Concatenate the subtables of several visibility data sets, not the MAIN bulk data. 00029 00030 The list of data sets given in the vis argument are concatenated into an output 00031 data set in testconcatvis without the bulk data of the MAIN table. 00032 This is useful for obtaining the information in the merged subtables without 00033 actually performing a time-consuming concatenation of the MAIN tables on disk. 00034 00035 00036 Keyword arguments: 00037 vis -- Name of input visibility files for which the subtables are to be combined 00038 default: none; example: vis = 'mydata.ms', 00039 vis=['src2.ms','ngc5921.ms','ngc315.ms'] 00040 testconcatvis -- Name of MS that will contain the concatenated subtables 00041 default: none; example: testconcatvis='test.ms' 00042 00043 freqtol -- Frequency shift tolerance for considering data to be in the same 00044 spwid. The number of channels must also be the same. 00045 default: '' do not combine unless frequencies are equal 00046 example: freqtol='10MHz' will not combine spwid unless they are 00047 within 10 MHz. 00048 Note: This option is useful to conbine spectral windows with very slight 00049 frequency differences caused by Doppler tracking, for example. 00050 00051 dirtol -- Direction shift tolerance for considering data as the same field 00052 default: '' means always combine. 00053 example: dirtol='1.arcsec' will not combine data for a field unless 00054 their phase center differ by less than 1 arcsec. If the field names 00055 are different in the input data sets, the name in the output data 00056 set will be the first relevant data set in the list. 00057 00058 copypointing -- Make a proper copy of the POINTING subtable (can be time consuming). 00059 If False, the result is an empty POINTING table. 00060 default: True 00061 00062 00063 """ 00064 a=inspect.stack() 00065 stacklevel=0 00066 for k in range(len(a)): 00067 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00068 stacklevel=k 00069 break 00070 myf=sys._getframe(stacklevel).f_globals 00071 myf['__last_task'] = 'testconcat' 00072 myf['taskname'] = 'testconcat' 00073 ### 00074 myf['update_params'](func=myf['taskname'],printtext=False) 00075 ### 00076 ### 00077 #Handle globals or user over-ride of arguments 00078 # 00079 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00080 useLocalDefaults = False 00081 00082 for item in function_signature_defaults.iteritems(): 00083 key,val = item 00084 keyVal = eval(key) 00085 if (keyVal == None): 00086 #user hasn't set it - use global/default 00087 pass 00088 else: 00089 #user has set it - use over-ride 00090 if (key != 'self') : 00091 useLocalDefaults = True 00092 #myf[key]=keyVal 00093 00094 myparams = {} 00095 if useLocalDefaults : 00096 for item in function_signature_defaults.iteritems(): 00097 key,val = item 00098 keyVal = eval(key) 00099 exec('myparams[key] = keyVal') 00100 if (keyVal == None): 00101 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00102 keyVal = eval(key) 00103 if(type(keyVal) == dict) : 00104 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00105 00106 else : 00107 uselessvariable = None 00108 myparams['vis'] = vis = myf['vis'] 00109 myparams['testconcatvis'] = testconcatvis = myf['testconcatvis'] 00110 myparams['freqtol'] = freqtol = myf['freqtol'] 00111 myparams['dirtol'] = dirtol = myf['dirtol'] 00112 myparams['copypointing'] = copypointing = myf['copypointing'] 00113 00114 if type(vis)==str: vis=[vis] 00115 00116 result = None 00117 00118 # 00119 # The following is work around to avoid a bug with current python translation 00120 # 00121 mytmp = {} 00122 00123 mytmp['vis'] = vis 00124 mytmp['testconcatvis'] = testconcatvis 00125 mytmp['freqtol'] = freqtol 00126 mytmp['dirtol'] = dirtol 00127 mytmp['copypointing'] = copypointing 00128 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00129 trec = casac.utils().torecord(pathname+'testconcat.xml') 00130 00131 casalog.origin('testconcat') 00132 if not trec.has_key('testconcat') or not casac.utils().verify(mytmp, trec['testconcat']) : 00133 return False 00134 00135 00136 try : 00137 casalog.post('') 00138 casalog.post('##########################################') 00139 casalog.post('##### Begin Task: testconcat #####') 00140 casalog.post('') 00141 result = testconcat(vis, testconcatvis, freqtol, dirtol, copypointing) 00142 casalog.post('') 00143 casalog.post('##### End Task: testconcat #####') 00144 casalog.post('##########################################') 00145 00146 00147 # saveinputs for individule engine has no use 00148 # saveinputs should alos be removed from casa_in_py.py 00149 # 00150 # 00151 # saveinputs = myf['saveinputs'] 00152 # saveinputs('testconcat', 'testconcat.last', myparams) 00153 # 00154 # 00155 except Exception, instance: 00156 #print '**** Error **** ',instance 00157 pass 00158 00159 gc.collect() 00160 return result 00161 # 00162 # 00163 ## 00164 # def paramgui(self, useGlobals=True): 00165 # """ 00166 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00167 # """ 00168 # import paramgui 00169 # 00170 # a=inspect.stack() 00171 # stacklevel=0 00172 # for k in range(len(a)): 00173 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00174 # stacklevel=k 00175 # break 00176 # myf = sys._getframe(stacklevel).f_globals 00177 # 00178 # if useGlobals: 00179 # paramgui.setGlobals(myf) 00180 # else: 00181 # paramgui.setGlobals({}) 00182 # 00183 # paramgui.runTask('testconcat', myf['_ip']) 00184 # paramgui.setGlobals({}) 00185 # 00186 # 00187 # 00188 # 00189 def defaults(self, param=None): 00190 a=inspect.stack() 00191 stacklevel=0 00192 for k in range(len(a)): 00193 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00194 stacklevel=k 00195 break 00196 myf=sys._getframe(stacklevel).f_globals 00197 a = odict() 00198 a['vis'] = [''] 00199 a['testconcatvis'] = '' 00200 a['freqtol'] = '' 00201 a['dirtol'] = '' 00202 a['copypointing'] = True 00203 00204 a['async']=False 00205 00206 ### This function sets the default values but also will return the list of 00207 ### parameters or the default value of a given parameter 00208 if(param == None): 00209 myf['__set_default_parameters'](a) 00210 elif(param == 'paramkeys'): 00211 return a.keys() 00212 else: 00213 if(a.has_key(param)): 00214 #if(type(a[param]) == dict) : 00215 # return a[param][len(a[param])-1]['value'] 00216 #else : 00217 return a[param] 00218 00219 00220 # 00221 # 00222 def check_params(self, param=None, value=None): 00223 a=inspect.stack() 00224 stacklevel=0 00225 for k in range(len(a)): 00226 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00227 stacklevel=k 00228 break 00229 myf=sys._getframe(stacklevel).f_globals 00230 00231 # print 'param:', param, 'value:', value 00232 try : 00233 if str(type(value)) != "<type 'instance'>" : 00234 value0 = value 00235 value = myf['cu'].expandparam(param, value) 00236 matchtype = False 00237 if(type(value) == numpy.ndarray): 00238 if(type(value) == type(value0)): 00239 myf[param] = value.tolist() 00240 else: 00241 #print 'value:', value, 'value0:', value0 00242 #print 'type(value):', type(value), 'type(value0):', type(value0) 00243 myf[param] = value0 00244 if type(value0) != list : 00245 matchtype = True 00246 else : 00247 myf[param] = value 00248 value = myf['cu'].verifyparam({param:value}) 00249 if matchtype: 00250 value = False 00251 except Exception, instance: 00252 #ignore the exception and just return it unchecked 00253 myf[param] = value 00254 return value 00255 00256 # 00257 # 00258 def description(self, key='testconcat', subkey=None): 00259 desc={'testconcat': 'Concatenate the subtables of several visibility data sets, not the MAIN bulk data.', 00260 'vis': 'Name(s) of input visibility files to be test-concatenated', 00261 'testconcatvis': 'Name of output MS containing the merged subtables', 00262 'freqtol': 'Frequency shift tolerance for considering data as the same spwid', 00263 'dirtol': 'Direction shift tolerance for considering data as the same field', 00264 'copypointing': 'Copy all rows of the POINTING table.', 00265 00266 'async': 'If true the taskname must be started using testconcat(...)' 00267 } 00268 00269 if(desc.has_key(key)) : 00270 return desc[key] 00271 00272 def itsdefault(self, paramname) : 00273 a = {} 00274 a['vis'] = [''] 00275 a['testconcatvis'] = '' 00276 a['freqtol'] = '' 00277 a['dirtol'] = '' 00278 a['copypointing'] = True 00279 00280 if a.has_key(paramname) : 00281 return a[paramname] 00282 testconcat_pg = testconcat_pg_()