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_msmoments import msmoments 00016 from task_msmoments import casalog 00017 00018 class msmoments_pg_: 00019 __name__ = "msmoments" 00020 00021 def __init__(self) : 00022 self.__bases__ = (msmoments_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infile=None, moments=None, antenna=None, field=None, spw=None, includemask=None, excludemask=None, outfile=None, overwrite=None, async=None): 00027 00028 """Compute moments from an MS 00029 The spectral moment distributions at each row in input MS are 00030 determined. Input MS must have FLOAT_DATA column, i.e. 00031 autocorrelation data. 00032 See the cookbook and User Reference Manual for 00033 mathematical details. 00034 00035 The main control of the calculation is given by parameter 00036 moments: 00037 00038 moments=-1 - mean value of the spectrum 00039 moments=0 - integrated value of the spectrum 00040 moments=1 - intensity weighted coordinate;traditionally used to get 00041 'velocity fields' 00042 moments=2 - intensity weighted dispersion of the coordinate; traditionally 00043 used to get "velocity dispersion" 00044 moments=3 - median of I 00045 moments=4 - median coordinate 00046 moments=5 - standard deviation about the mean of the spectrum 00047 moments=6 - root mean square of the spectrum 00048 moments=7 - absolute mean deviation of the spectrum 00049 moments=8 - maximum value of the spectrum 00050 moments=9 - coordinate of the maximum value of the spectrum 00051 moments=10 - minimum value of the spectrum 00052 moments=11 - coordinate of the minimum value of the spectrum 00053 00054 Note that includemask and excludemask cannot set simultaneously. 00055 00056 Keyword arguments: 00057 infile -- Name of input MS data 00058 default: none; example: infile="OrionS_rawACSmod" 00059 moments -- List of moments you would like to compute 00060 default: 0 (integrated spectrum);example: moments=[0,1] 00061 see list above 00062 antenna -- antenna name or id that the user wants to compute moments 00063 default: '' (all antennae) 00064 field -- field name or id that the user wants to compute moments 00065 default: '' (all fields) 00066 spw -- spectral window id that the user wants to compute moments 00067 default: '' (all spectral windows) 00068 00069 includemask -- List of masks to include 00070 default: [-1] (include all channels); example=[2,100] 00071 excludemask -- List of masks to exclude 00072 default: [-1] (don't exclude channels); example=[100,200] 00073 outfile -- Output MS file name (or root for multiple moments) 00074 default: '' (input+auto-determined suffix);example: outfile='source_moment' 00075 overwrite -- Overwrite existing output files 00076 default: false 00077 00078 Example for finding the 1-momment, intensity-weighted 00079 coordinate, often used for finding velocity fields. 00080 msmoments( infile='mydata', moment=1, outfile='velocityfields' ) 00081 00082 00083 """ 00084 a=inspect.stack() 00085 stacklevel=0 00086 for k in range(len(a)): 00087 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00088 stacklevel=k 00089 break 00090 myf=sys._getframe(stacklevel).f_globals 00091 myf['__last_task'] = 'msmoments' 00092 myf['taskname'] = 'msmoments' 00093 ### 00094 myf['update_params'](func=myf['taskname'],printtext=False) 00095 ### 00096 ### 00097 #Handle globals or user over-ride of arguments 00098 # 00099 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00100 useLocalDefaults = False 00101 00102 for item in function_signature_defaults.iteritems(): 00103 key,val = item 00104 keyVal = eval(key) 00105 if (keyVal == None): 00106 #user hasn't set it - use global/default 00107 pass 00108 else: 00109 #user has set it - use over-ride 00110 if (key != 'self') : 00111 useLocalDefaults = True 00112 #myf[key]=keyVal 00113 00114 myparams = {} 00115 if useLocalDefaults : 00116 for item in function_signature_defaults.iteritems(): 00117 key,val = item 00118 keyVal = eval(key) 00119 exec('myparams[key] = keyVal') 00120 if (keyVal == None): 00121 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00122 keyVal = eval(key) 00123 if(type(keyVal) == dict) : 00124 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00125 00126 else : 00127 uselessvariable = None 00128 myparams['infile'] = infile = myf['infile'] 00129 myparams['moments'] = moments = myf['moments'] 00130 myparams['antenna'] = antenna = myf['antenna'] 00131 myparams['field'] = field = myf['field'] 00132 myparams['spw'] = spw = myf['spw'] 00133 myparams['includemask'] = includemask = myf['includemask'] 00134 myparams['excludemask'] = excludemask = myf['excludemask'] 00135 myparams['outfile'] = outfile = myf['outfile'] 00136 myparams['overwrite'] = overwrite = myf['overwrite'] 00137 00138 if type(moments)==int: moments=[moments] 00139 00140 result = None 00141 00142 # 00143 # The following is work around to avoid a bug with current python translation 00144 # 00145 mytmp = {} 00146 00147 mytmp['infile'] = infile 00148 mytmp['moments'] = moments 00149 mytmp['antenna'] = antenna 00150 mytmp['field'] = field 00151 mytmp['spw'] = spw 00152 mytmp['includemask'] = includemask 00153 mytmp['excludemask'] = excludemask 00154 mytmp['outfile'] = outfile 00155 mytmp['overwrite'] = overwrite 00156 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00157 trec = casac.utils().torecord(pathname+'msmoments.xml') 00158 00159 casalog.origin('msmoments') 00160 if not trec.has_key('msmoments') or not casac.utils().verify(mytmp, trec['msmoments']) : 00161 return False 00162 00163 00164 try : 00165 casalog.post('') 00166 casalog.post('##########################################') 00167 casalog.post('##### Begin Task: msmoments #####') 00168 casalog.post('') 00169 result = msmoments(infile, moments, antenna, field, spw, includemask, excludemask, outfile, overwrite) 00170 casalog.post('') 00171 casalog.post('##### End Task: msmoments #####') 00172 casalog.post('##########################################') 00173 00174 00175 # saveinputs for individule engine has no use 00176 # saveinputs should alos be removed from casa_in_py.py 00177 # 00178 # 00179 # saveinputs = myf['saveinputs'] 00180 # saveinputs('msmoments', 'msmoments.last', myparams) 00181 # 00182 # 00183 except Exception, instance: 00184 #print '**** Error **** ',instance 00185 pass 00186 00187 gc.collect() 00188 return result 00189 # 00190 # 00191 ## 00192 # def paramgui(self, useGlobals=True): 00193 # """ 00194 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00195 # """ 00196 # import paramgui 00197 # 00198 # a=inspect.stack() 00199 # stacklevel=0 00200 # for k in range(len(a)): 00201 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00202 # stacklevel=k 00203 # break 00204 # myf = sys._getframe(stacklevel).f_globals 00205 # 00206 # if useGlobals: 00207 # paramgui.setGlobals(myf) 00208 # else: 00209 # paramgui.setGlobals({}) 00210 # 00211 # paramgui.runTask('msmoments', myf['_ip']) 00212 # paramgui.setGlobals({}) 00213 # 00214 # 00215 # 00216 # 00217 def defaults(self, param=None): 00218 a=inspect.stack() 00219 stacklevel=0 00220 for k in range(len(a)): 00221 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00222 stacklevel=k 00223 break 00224 myf=sys._getframe(stacklevel).f_globals 00225 a = odict() 00226 a['infile'] = '' 00227 a['moments'] = [0] 00228 a['antenna'] = '' 00229 a['field'] = '' 00230 a['spw'] = '' 00231 a['includemask'] = -1 00232 a['excludemask'] = -1 00233 a['outfile'] = '' 00234 a['overwrite'] = False 00235 00236 a['async']=False 00237 00238 ### This function sets the default values but also will return the list of 00239 ### parameters or the default value of a given parameter 00240 if(param == None): 00241 myf['__set_default_parameters'](a) 00242 elif(param == 'paramkeys'): 00243 return a.keys() 00244 else: 00245 if(a.has_key(param)): 00246 #if(type(a[param]) == dict) : 00247 # return a[param][len(a[param])-1]['value'] 00248 #else : 00249 return a[param] 00250 00251 00252 # 00253 # 00254 def check_params(self, param=None, value=None): 00255 a=inspect.stack() 00256 stacklevel=0 00257 for k in range(len(a)): 00258 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00259 stacklevel=k 00260 break 00261 myf=sys._getframe(stacklevel).f_globals 00262 00263 # print 'param:', param, 'value:', value 00264 try : 00265 if str(type(value)) != "<type 'instance'>" : 00266 value0 = value 00267 value = myf['cu'].expandparam(param, value) 00268 matchtype = False 00269 if(type(value) == numpy.ndarray): 00270 if(type(value) == type(value0)): 00271 myf[param] = value.tolist() 00272 else: 00273 #print 'value:', value, 'value0:', value0 00274 #print 'type(value):', type(value), 'type(value0):', type(value0) 00275 myf[param] = value0 00276 if type(value0) != list : 00277 matchtype = True 00278 else : 00279 myf[param] = value 00280 value = myf['cu'].verifyparam({param:value}) 00281 if matchtype: 00282 value = False 00283 except Exception, instance: 00284 #ignore the exception and just return it unchecked 00285 myf[param] = value 00286 return value 00287 00288 # 00289 # 00290 def description(self, key='msmoments', subkey=None): 00291 desc={'msmoments': 'Compute moments from an MS', 00292 'infile': 'Name of the input MS data', 00293 'moments': 'List of moments you want to compute', 00294 'antenna': 'antenna name or id', 00295 'field': 'field name or id', 00296 'spw': 'spectral window id', 00297 'includemask': 'Range of rows to include', 00298 'excludemask': 'Range of rows to exclude', 00299 'outfile': 'Output file name (or root for multiple moments) ', 00300 'overwrite': 'Overwrite existing output files', 00301 00302 'async': 'If true the taskname must be started using msmoments(...)' 00303 } 00304 00305 if(desc.has_key(key)) : 00306 return desc[key] 00307 00308 def itsdefault(self, paramname) : 00309 a = {} 00310 a['infile'] = '' 00311 a['moments'] = [0] 00312 a['antenna'] = '' 00313 a['field'] = '' 00314 a['spw'] = '' 00315 a['includemask'] = -1 00316 a['excludemask'] = -1 00317 a['outfile'] = '' 00318 a['overwrite'] = False 00319 00320 if a.has_key(paramname) : 00321 return a[paramname] 00322 msmoments_pg = msmoments_pg_()