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_concat import concat 00016 from task_concat import casalog 00017 00018 class concat_pg_: 00019 __name__ = "concat" 00020 00021 def __init__(self) : 00022 self.__bases__ = (concat_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, concatvis=None, freqtol=None, dirtol=None, respectname=None, timesort=None, copypointing=None, visweightscale=None, createmms=None, async=None): 00027 00028 """Concatenate several visibility data sets. 00029 00030 The list of data sets given in the vis argument are concatenated into an output 00031 data set in concatvis. If concatvis already exists (e.g., it is the same as the 00032 first input data set), then the other input data sets will be appended to the 00033 concatvis data set. There is no limit to the number of input data sets. 00034 00035 If none of the input data sets have any scratch columns (model and corrected 00036 columns), none are created in the concatvis. Otherwise these columns are 00037 created on output and initialized to their default value (1 in model column, 00038 data in corrected column) for those data with no input columns. 00039 00040 Spectral windows for each data set with the same chanelization, and within a 00041 specified frequency tolerance of another data set will be combined into one 00042 spectral window. 00043 00044 A field position in one data set that is within a specified direction tolerance 00045 of another field position in any other data set will be combined into one 00046 field. The field names need not be the same---only their position is used. 00047 00048 Each appended dataset is assigned a new observation id. 00049 00050 Keyword arguments: 00051 vis -- Name of input visibility files to be combined 00052 default: none; example: vis = ['src2.ms','ngc5921.ms','ngc315.ms'] 00053 concatvis -- Name of visibility file that will contain the concatenated data 00054 note: if this file exits on disk then the input files are 00055 added to this file. Otherwise the new file contains 00056 the concatenated data. Be careful here when concatenating to 00057 an existing file. 00058 default: none; example: concatvis='src2.ms' 00059 example: concatvis='outvis.ms' 00060 00061 other examples: 00062 concat(vis=['src2.ms','ngc5921.ms'], concatvis='src2.ms') 00063 will concatenate 'ngc5921.ms' into 'src2.ms', and the original 00064 src2.ms is lost 00065 00066 concat(vis=['src2.ms','ngc5921.ms'], concatvis='out.ms') 00067 will concatenate 'ngc5921.ms' and 'src2.ms' into a file named 00068 'out.ms'; the original 'ngc5921.ms' and 'src2.ms' are untouched. 00069 00070 concat(vis=['v1.ms','v2.ms'], concatvis = 'vall.ms') 00071 then 00072 concat(vis=['v3.ms','v4.ms'], concatvis = 'vall.ms') 00073 vall.ms will contains v1.ms+v2.ms+v3.ms+v4.ms 00074 00075 Note: run flagmanager to save flags in the concatvis 00076 00077 freqtol -- Frequency shift tolerance for considering data to be in the same 00078 spwid. The number of channels must also be the same. 00079 default: '' do not combine unless frequencies are equal 00080 example: freqtol='10MHz' will not combine spwid unless they are 00081 within 10 MHz. 00082 Note: This option is useful to conbine spectral windows with very slight 00083 frequency differences caused by Doppler tracking, for example. 00084 00085 dirtol -- Direction shift tolerance for considering data as the same field 00086 default: '' means always combine. 00087 example: dirtol='1.arcsec' will not combine data for a field unless 00088 their phase center differ by less than 1 arcsec. If the field names 00089 are different in the input data sets, the name in the output data 00090 set will be the first relevant data set in the list. 00091 00092 respectname -- If true, fields with a different name are not merged even if their 00093 direction agrees (within dirtol) 00094 default: False 00095 00096 timesort -- If true, the output visibility table will be sorted in time. 00097 default: false. Data in order as read in. 00098 example: timesort=true 00099 Note: There is no constraint on data that is simultaneously observed for 00100 more than one field; for example multi-source correlation of VLBA data. 00101 00102 copypointing -- Make a proper copy of the POINTING subtable (can be time consuming). 00103 If False, the result is an empty POINTING table. 00104 default: True 00105 00106 visweightscale -- The weights of the individual MSs will be scaled in the concatenated 00107 output MS by the factors in this list. Useful for handling heterogeneous arrays. 00108 Use plotms to inspect the "Wt" column as a reference for determining the scaling 00109 factors. See the cookbook for more details. 00110 example: [1.,3.,3.] - scale the weights of the second and third MS by a factor 3. 00111 default: [] (empty list) - no scaling 00112 00113 createmms -- disabled. Please use task virtualconcat. 00114 default: False 00115 00116 00117 """ 00118 a=inspect.stack() 00119 stacklevel=0 00120 for k in range(len(a)): 00121 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00122 stacklevel=k 00123 break 00124 myf=sys._getframe(stacklevel).f_globals 00125 myf['__last_task'] = 'concat' 00126 myf['taskname'] = 'concat' 00127 ### 00128 myf['update_params'](func=myf['taskname'],printtext=False) 00129 ### 00130 ### 00131 #Handle globals or user over-ride of arguments 00132 # 00133 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00134 useLocalDefaults = False 00135 00136 for item in function_signature_defaults.iteritems(): 00137 key,val = item 00138 keyVal = eval(key) 00139 if (keyVal == None): 00140 #user hasn't set it - use global/default 00141 pass 00142 else: 00143 #user has set it - use over-ride 00144 if (key != 'self') : 00145 useLocalDefaults = True 00146 #myf[key]=keyVal 00147 00148 myparams = {} 00149 if useLocalDefaults : 00150 for item in function_signature_defaults.iteritems(): 00151 key,val = item 00152 keyVal = eval(key) 00153 exec('myparams[key] = keyVal') 00154 if (keyVal == None): 00155 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00156 keyVal = eval(key) 00157 if(type(keyVal) == dict) : 00158 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00159 00160 else : 00161 uselessvariable = None 00162 myparams['vis'] = vis = myf['vis'] 00163 myparams['concatvis'] = concatvis = myf['concatvis'] 00164 myparams['freqtol'] = freqtol = myf['freqtol'] 00165 myparams['dirtol'] = dirtol = myf['dirtol'] 00166 myparams['respectname'] = respectname = myf['respectname'] 00167 myparams['timesort'] = timesort = myf['timesort'] 00168 myparams['copypointing'] = copypointing = myf['copypointing'] 00169 myparams['visweightscale'] = visweightscale = myf['visweightscale'] 00170 myparams['createmms'] = createmms = myf['createmms'] 00171 00172 if type(vis)==str: vis=[vis] 00173 if type(visweightscale)==float: visweightscale=[visweightscale] 00174 00175 result = None 00176 00177 # 00178 # The following is work around to avoid a bug with current python translation 00179 # 00180 mytmp = {} 00181 00182 mytmp['vis'] = vis 00183 mytmp['concatvis'] = concatvis 00184 mytmp['freqtol'] = freqtol 00185 mytmp['dirtol'] = dirtol 00186 mytmp['respectname'] = respectname 00187 mytmp['timesort'] = timesort 00188 mytmp['copypointing'] = copypointing 00189 mytmp['visweightscale'] = visweightscale 00190 mytmp['createmms'] = createmms 00191 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00192 trec = casac.utils().torecord(pathname+'concat.xml') 00193 00194 casalog.origin('concat') 00195 if not trec.has_key('concat') or not casac.utils().verify(mytmp, trec['concat']) : 00196 return False 00197 00198 00199 try : 00200 casalog.post('') 00201 casalog.post('##########################################') 00202 casalog.post('##### Begin Task: concat #####') 00203 casalog.post('') 00204 result = concat(vis, concatvis, freqtol, dirtol, respectname, timesort, copypointing, visweightscale, createmms) 00205 casalog.post('') 00206 casalog.post('##### End Task: concat #####') 00207 casalog.post('##########################################') 00208 00209 00210 # saveinputs for individule engine has no use 00211 # saveinputs should alos be removed from casa_in_py.py 00212 # 00213 # 00214 # saveinputs = myf['saveinputs'] 00215 # saveinputs('concat', 'concat.last', myparams) 00216 # 00217 # 00218 except Exception, instance: 00219 #print '**** Error **** ',instance 00220 pass 00221 00222 gc.collect() 00223 return result 00224 # 00225 # 00226 ## 00227 # def paramgui(self, useGlobals=True): 00228 # """ 00229 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00230 # """ 00231 # import paramgui 00232 # 00233 # a=inspect.stack() 00234 # stacklevel=0 00235 # for k in range(len(a)): 00236 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00237 # stacklevel=k 00238 # break 00239 # myf = sys._getframe(stacklevel).f_globals 00240 # 00241 # if useGlobals: 00242 # paramgui.setGlobals(myf) 00243 # else: 00244 # paramgui.setGlobals({}) 00245 # 00246 # paramgui.runTask('concat', myf['_ip']) 00247 # paramgui.setGlobals({}) 00248 # 00249 # 00250 # 00251 # 00252 def defaults(self, param=None): 00253 a=inspect.stack() 00254 stacklevel=0 00255 for k in range(len(a)): 00256 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00257 stacklevel=k 00258 break 00259 myf=sys._getframe(stacklevel).f_globals 00260 a = odict() 00261 a['vis'] = [''] 00262 a['concatvis'] = '' 00263 a['freqtol'] = '' 00264 a['dirtol'] = '' 00265 a['respectname'] = False 00266 a['timesort'] = False 00267 a['copypointing'] = True 00268 a['visweightscale'] = [] 00269 a['createmms'] = False 00270 00271 a['async']=False 00272 00273 ### This function sets the default values but also will return the list of 00274 ### parameters or the default value of a given parameter 00275 if(param == None): 00276 myf['__set_default_parameters'](a) 00277 elif(param == 'paramkeys'): 00278 return a.keys() 00279 else: 00280 if(a.has_key(param)): 00281 #if(type(a[param]) == dict) : 00282 # return a[param][len(a[param])-1]['value'] 00283 #else : 00284 return a[param] 00285 00286 00287 # 00288 # 00289 def check_params(self, param=None, value=None): 00290 a=inspect.stack() 00291 stacklevel=0 00292 for k in range(len(a)): 00293 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00294 stacklevel=k 00295 break 00296 myf=sys._getframe(stacklevel).f_globals 00297 00298 # print 'param:', param, 'value:', value 00299 try : 00300 if str(type(value)) != "<type 'instance'>" : 00301 value0 = value 00302 value = myf['cu'].expandparam(param, value) 00303 matchtype = False 00304 if(type(value) == numpy.ndarray): 00305 if(type(value) == type(value0)): 00306 myf[param] = value.tolist() 00307 else: 00308 #print 'value:', value, 'value0:', value0 00309 #print 'type(value):', type(value), 'type(value0):', type(value0) 00310 myf[param] = value0 00311 if type(value0) != list : 00312 matchtype = True 00313 else : 00314 myf[param] = value 00315 value = myf['cu'].verifyparam({param:value}) 00316 if matchtype: 00317 value = False 00318 except Exception, instance: 00319 #ignore the exception and just return it unchecked 00320 myf[param] = value 00321 return value 00322 00323 # 00324 # 00325 def description(self, key='concat', subkey=None): 00326 desc={'concat': 'Concatenate several visibility data sets.', 00327 'vis': 'Name of input visibility files to be concatenated', 00328 'concatvis': 'Name of output visibility file', 00329 'freqtol': 'Frequency shift tolerance for considering data as the same spwid', 00330 'dirtol': 'Direction shift tolerance for considering data as the same field', 00331 'respectname': 'If true, fields with a different name are not merged even if their direction agrees', 00332 'timesort': 'If true, sort by TIME in ascending order', 00333 'copypointing': 'Copy all rows of the POINTING table.', 00334 'visweightscale': 'List of the weight scaling factors to be applied to the individual MSs', 00335 'createmms': 'Should this create a multi-MS output', 00336 00337 'async': 'If true the taskname must be started using concat(...)' 00338 } 00339 00340 if(desc.has_key(key)) : 00341 return desc[key] 00342 00343 def itsdefault(self, paramname) : 00344 a = {} 00345 a['vis'] = [''] 00346 a['concatvis'] = '' 00347 a['freqtol'] = '' 00348 a['dirtol'] = '' 00349 a['respectname'] = False 00350 a['timesort'] = False 00351 a['copypointing'] = True 00352 a['visweightscale'] = [] 00353 a['createmms'] = False 00354 00355 if a.has_key(paramname) : 00356 return a[paramname] 00357 concat_pg = concat_pg_()