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_listpartition import listpartition 00016 from task_listpartition import casalog 00017 00018 class listpartition_pg_: 00019 __name__ = "listpartition" 00020 00021 def __init__(self) : 00022 self.__bases__ = (listpartition_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, createdict=None, listfile=None, async=None): 00027 00028 """List the summary of a multi-MS data set in the logger or in a file 00029 00030 A multi-measurement set (MMS) is an MS that has been split into sub-MSs. 00031 An MMS contains a reference MS in the top directory and the sub-MSs are 00032 located in a directory called SUBMSS inside the MMS directory. 00033 Example of a MS that was 'split' in two scans using the task partition: 00034 00035 > ls pScan.mms/ 00036 SUBMSS/ table.dat table.info 00037 00038 > ls pScan.mms/SUBMSS/ 00039 pScan.0000.ms/ pScan.0001.ms/ 00040 00041 00042 The task lists the following properties of a multi-MS or MS: 00043 sub-MS name, scan, spw list, list of number of channels per spw, 00044 number of rows for each scan and the size in disk. Example of logger output: 00045 00046 Sub-MS Scan Spw Nchan Nrows Size 00047 pScan.0000.ms 31 [ 0 1 2 3 4] [64 64 64 64 64] 8640 42M 00048 pScan.0001.ms 30 [ 0 1 2 3 4] [64 64 64 64 64] 8544 42M 00049 00050 00051 00052 Keyword arguments: 00053 vis -- Name of multi-MS or normal MS. 00054 default: ''. 00055 example: vis='pScan.mms' 00056 00057 createdict -- Create and return a dictionary containing scan summaries of each 00058 sub-MS. 00059 default: False 00060 00061 If set to True, the returned dictionary will contain information from 00062 ms.getscansummary() and ms.getspectralwindowinfo(), with the addition of an 00063 index as the top key and the sub-MS name. 00064 Example: 00065 00066 {0: {'MS': 'pScan.0000.ms', 00067 'scanId': {31: {'nchans': array([64, 64, 64, 64, 64]), 00068 'nrows': 8640, 00069 'spwIds': array([ 0, 1, 2, 3, 4])}}, 00070 'size': '42M'}, 00071 1: {'MS': 'pScan.0001.ms', 00072 'scanId': {30: {'nchans': array([64, 64, 64, 64, 64]), 00073 'nrows': 8544, 00074 'spwIds': array([ 0, 1, 2, 3, 4])}}, 00075 'size': '42M'}} 00076 00077 00078 listfile -- Name of ASCII file to save output to. If empty, it will 00079 list on the logger/terminal. 00080 default: '' 00081 example: listfile='pscan.txt' 00082 00083 00084 """ 00085 a=inspect.stack() 00086 stacklevel=0 00087 for k in range(len(a)): 00088 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00089 stacklevel=k 00090 break 00091 myf=sys._getframe(stacklevel).f_globals 00092 myf['__last_task'] = 'listpartition' 00093 myf['taskname'] = 'listpartition' 00094 ### 00095 myf['update_params'](func=myf['taskname'],printtext=False) 00096 ### 00097 ### 00098 #Handle globals or user over-ride of arguments 00099 # 00100 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00101 useLocalDefaults = False 00102 00103 for item in function_signature_defaults.iteritems(): 00104 key,val = item 00105 keyVal = eval(key) 00106 if (keyVal == None): 00107 #user hasn't set it - use global/default 00108 pass 00109 else: 00110 #user has set it - use over-ride 00111 if (key != 'self') : 00112 useLocalDefaults = True 00113 #myf[key]=keyVal 00114 00115 myparams = {} 00116 if useLocalDefaults : 00117 for item in function_signature_defaults.iteritems(): 00118 key,val = item 00119 keyVal = eval(key) 00120 exec('myparams[key] = keyVal') 00121 if (keyVal == None): 00122 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00123 keyVal = eval(key) 00124 if(type(keyVal) == dict) : 00125 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00126 00127 else : 00128 uselessvariable = None 00129 myparams['vis'] = vis = myf['vis'] 00130 myparams['createdict'] = createdict = myf['createdict'] 00131 myparams['listfile'] = listfile = myf['listfile'] 00132 00133 00134 result = None 00135 00136 # 00137 # The following is work around to avoid a bug with current python translation 00138 # 00139 mytmp = {} 00140 00141 mytmp['vis'] = vis 00142 mytmp['createdict'] = createdict 00143 mytmp['listfile'] = listfile 00144 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00145 trec = casac.utils().torecord(pathname+'listpartition.xml') 00146 00147 casalog.origin('listpartition') 00148 if not trec.has_key('listpartition') or not casac.utils().verify(mytmp, trec['listpartition']) : 00149 return False 00150 00151 00152 try : 00153 casalog.post('') 00154 casalog.post('##########################################') 00155 casalog.post('##### Begin Task: listpartition #####') 00156 casalog.post('') 00157 result = listpartition(vis, createdict, listfile) 00158 casalog.post('') 00159 casalog.post('##### End Task: listpartition #####') 00160 casalog.post('##########################################') 00161 00162 00163 # saveinputs for individule engine has no use 00164 # saveinputs should alos be removed from casa_in_py.py 00165 # 00166 # 00167 # saveinputs = myf['saveinputs'] 00168 # saveinputs('listpartition', 'listpartition.last', myparams) 00169 # 00170 # 00171 except Exception, instance: 00172 #print '**** Error **** ',instance 00173 pass 00174 00175 gc.collect() 00176 return result 00177 # 00178 # 00179 ## 00180 # def paramgui(self, useGlobals=True): 00181 # """ 00182 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00183 # """ 00184 # import paramgui 00185 # 00186 # a=inspect.stack() 00187 # stacklevel=0 00188 # for k in range(len(a)): 00189 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00190 # stacklevel=k 00191 # break 00192 # myf = sys._getframe(stacklevel).f_globals 00193 # 00194 # if useGlobals: 00195 # paramgui.setGlobals(myf) 00196 # else: 00197 # paramgui.setGlobals({}) 00198 # 00199 # paramgui.runTask('listpartition', myf['_ip']) 00200 # paramgui.setGlobals({}) 00201 # 00202 # 00203 # 00204 # 00205 def defaults(self, param=None): 00206 a=inspect.stack() 00207 stacklevel=0 00208 for k in range(len(a)): 00209 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00210 stacklevel=k 00211 break 00212 myf=sys._getframe(stacklevel).f_globals 00213 a = odict() 00214 a['vis'] = '' 00215 a['createdict'] = False 00216 a['listfile'] = '' 00217 00218 a['async']=False 00219 00220 ### This function sets the default values but also will return the list of 00221 ### parameters or the default value of a given parameter 00222 if(param == None): 00223 myf['__set_default_parameters'](a) 00224 elif(param == 'paramkeys'): 00225 return a.keys() 00226 else: 00227 if(a.has_key(param)): 00228 #if(type(a[param]) == dict) : 00229 # return a[param][len(a[param])-1]['value'] 00230 #else : 00231 return a[param] 00232 00233 00234 # 00235 # 00236 def check_params(self, param=None, value=None): 00237 a=inspect.stack() 00238 stacklevel=0 00239 for k in range(len(a)): 00240 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00241 stacklevel=k 00242 break 00243 myf=sys._getframe(stacklevel).f_globals 00244 00245 # print 'param:', param, 'value:', value 00246 try : 00247 if str(type(value)) != "<type 'instance'>" : 00248 value0 = value 00249 value = myf['cu'].expandparam(param, value) 00250 matchtype = False 00251 if(type(value) == numpy.ndarray): 00252 if(type(value) == type(value0)): 00253 myf[param] = value.tolist() 00254 else: 00255 #print 'value:', value, 'value0:', value0 00256 #print 'type(value):', type(value), 'type(value0):', type(value0) 00257 myf[param] = value0 00258 if type(value0) != list : 00259 matchtype = True 00260 else : 00261 myf[param] = value 00262 value = myf['cu'].verifyparam({param:value}) 00263 if matchtype: 00264 value = False 00265 except Exception, instance: 00266 #ignore the exception and just return it unchecked 00267 myf[param] = value 00268 return value 00269 00270 # 00271 # 00272 def description(self, key='listpartition', subkey=None): 00273 desc={'listpartition': 'List the summary of a multi-MS data set in the logger or in a file', 00274 'vis': 'Name of multi-MS or normal MS.', 00275 'createdict': 'Create and return a dictionary with sub-MS information', 00276 'listfile': 'Name of ASCII file to save output: \'\'==>to terminal', 00277 00278 'async': 'If true the taskname must be started using listpartition(...)' 00279 } 00280 00281 if(desc.has_key(key)) : 00282 return desc[key] 00283 00284 def itsdefault(self, paramname) : 00285 a = {} 00286 a['vis'] = '' 00287 a['createdict'] = False 00288 a['listfile'] = '' 00289 00290 if a.has_key(paramname) : 00291 return a[paramname] 00292 listpartition_pg = listpartition_pg_()