casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
visstat_pg.py
Go to the documentation of this file.
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_visstat import visstat
00016 from task_visstat import casalog
00017 
00018 class visstat_pg_:
00019     __name__ = "visstat"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (visstat_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, vis=None, axis=None, datacolumn=None, useflags=None, spw=None, field=None, selectdata=None, antenna=None, uvrange=None, timerange=None, correlation=None, scan=None, array=None, observation=None, async=None):
00027 
00028         """Displays statistical information from a measurement set, or from a measurement set selection
00029 
00030         This task returns statistical information about data in a measurement
00031         set.
00032 
00033         The following values are computed: mean value, sum of values,
00034         sum of squared values, median, median absolute deviation, quartile,
00035         minimum, maximum, variance, standard deviation, and root mean square.
00036 
00037         The following axes are supported: uvw, flag, weight, sigma, antenna1,
00038         antenna2, feed1, feed2, field_id, array_id, data_desc_id, flag_row,
00039         interval, scan, scan_number, time, weight_spectrum, amp, amplitude,
00040         phase, real, imag, imaginary, and uvrange.
00041 
00042         Optionally, the statistical information can be computed based only
00043         on a given subset of the measurement set.
00044 
00045         Note: If the MS consists of inhomogeneous data, for example several
00046         spectral windows each having a different number of channels, it may be
00047         necessary to use selection parameters to select a homogeneous subset of
00048         the MS, e.g. spw='2'.
00049 
00050         Keyword arguments:
00051 
00052         vis  --- Name of input visibility file
00053                   default: '', example: vis='my.ms'
00054 
00055         axis -- Which data to analyze.
00056 
00057                 default: 'amplitude'
00058                 axis='phase'
00059                 axis='imag'
00060                 axis='scan_number'
00061                 axis='flag'
00062 
00063                 The phase of a complex number is in radians in the range [-pi; pi[.
00064 
00065 
00066         datacolumn -- Which data column to use for complex data.
00067                 default: 'data'
00068                 datacolumn='data'
00069                 datacolumn='corrected'
00070                 datacolumn='model'
00071 
00072         useflags -- Take MS flags into account?
00073                 default: True
00074                 useflag=False
00075                 useflag=True
00076         If useflags=False, flagged values are included in the statistics.
00077         If useflags=True, any flagged values are not used in the statistics.
00078 
00079         spw -- Select data based on spectral window and channels
00080                 default: '' (all); example: spw='1'
00081                 spw='<2' #spectral windows less than 2
00082                 spw='>1' #spectral windows greater than 1
00083                 spw='0:0~10' # first 10 channels from spw 0
00084                 spw='0:0~5;56~60' # multiple separated channel chunks.
00085 
00086         field -- Select data based on field id(s) or name(s)
00087                 default: '' (all); example: field='1'
00088                 field='0~2' # field ids inclusive from 0 to 2
00089                 field='3C*' # all field names starting with 3C
00090 
00091         selectdata -- Other data selection parameters
00092                 default: True
00093         antenna -- Select data based on baseline
00094                 default: '' (all); example: antenna='5&6' baseline 5-6
00095                 antenna='5&6;7&8' #baseline 5-6 and 7-8
00096                 antenna='5' # all baselines with antenna 5
00097                 antenna='5,6' # all baselines with antennas 5 and 6
00098         correlation -- Correlation types
00099                 default: '' (all);
00100                 example: correlation='RR LL'
00101         uvrange -- Select data within uvrange (default units meters)
00102                 default: '' (all); example:
00103                 uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda
00104                 uvrange='>4klambda';uvranges greater than 4 kilo-lambda
00105                 uvrange='0~1000km'; uvrange in kilometers
00106         timerange  -- Select data based on time range:
00107                 default = '' (all); example,
00108                 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00109                 Note: YYYY/MM/DD can be dropped as needed:
00110                 timerange='09:14:0~09:54:0' # this time range
00111                 timerange='09:44:00' # data within one integration of time
00112                 timerange='>10:24:00' # data after this time
00113                 timerange='09:44:00+00:13:00' #data 13 minutes after time
00114         scan -- Select data based on scan number
00115                 default: '' (all); example: scan='>3'
00116         array -- Selection based on the antenna array
00117         observation -- Selection by observation ID(s).
00118                        default: '' (all); example: observation='1~3'
00119 
00120 
00121         """
00122         a=inspect.stack()
00123         stacklevel=0
00124         for k in range(len(a)):
00125           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00126                 stacklevel=k
00127                 break
00128         myf=sys._getframe(stacklevel).f_globals
00129         myf['__last_task'] = 'visstat'
00130         myf['taskname'] = 'visstat'
00131         ###
00132         myf['update_params'](func=myf['taskname'],printtext=False)
00133         ###
00134         ###
00135         #Handle globals or user over-ride of arguments
00136         #
00137         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00138         useLocalDefaults = False
00139 
00140         for item in function_signature_defaults.iteritems():
00141                 key,val = item
00142                 keyVal = eval(key)
00143                 if (keyVal == None):
00144                         #user hasn't set it - use global/default
00145                         pass
00146                 else:
00147                         #user has set it - use over-ride
00148                         if (key != 'self') :
00149                            useLocalDefaults = True
00150                         #myf[key]=keyVal
00151 
00152         myparams = {}
00153         if useLocalDefaults :
00154            for item in function_signature_defaults.iteritems():
00155                key,val = item
00156                keyVal = eval(key)
00157                exec('myparams[key] = keyVal')
00158                if (keyVal == None):
00159                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00160                    keyVal = eval(key)
00161                    if(type(keyVal) == dict) :
00162                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00163 
00164         else :
00165             uselessvariable = None 
00166             myparams['vis'] = vis = myf['vis']
00167             myparams['axis'] = axis = myf['axis']
00168             myparams['datacolumn'] = datacolumn = myf['datacolumn']
00169             myparams['useflags'] = useflags = myf['useflags']
00170             myparams['spw'] = spw = myf['spw']
00171             myparams['field'] = field = myf['field']
00172             myparams['selectdata'] = selectdata = myf['selectdata']
00173             myparams['antenna'] = antenna = myf['antenna']
00174             myparams['uvrange'] = uvrange = myf['uvrange']
00175             myparams['timerange'] = timerange = myf['timerange']
00176             myparams['correlation'] = correlation = myf['correlation']
00177             myparams['scan'] = scan = myf['scan']
00178             myparams['array'] = array = myf['array']
00179             myparams['observation'] = observation = myf['observation']
00180 
00181 
00182         result = None
00183 
00184 #
00185 #    The following is work around to avoid a bug with current python translation
00186 #
00187         mytmp = {}
00188 
00189         mytmp['vis'] = vis
00190         mytmp['axis'] = axis
00191         mytmp['datacolumn'] = datacolumn
00192         mytmp['useflags'] = useflags
00193         mytmp['spw'] = spw
00194         mytmp['field'] = field
00195         mytmp['selectdata'] = selectdata
00196         mytmp['antenna'] = antenna
00197         mytmp['uvrange'] = uvrange
00198         mytmp['timerange'] = timerange
00199         mytmp['correlation'] = correlation
00200         mytmp['scan'] = scan
00201         mytmp['array'] = array
00202         mytmp['observation'] = observation
00203         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00204         trec = casac.utils().torecord(pathname+'visstat.xml')
00205 
00206         casalog.origin('visstat')
00207         if not trec.has_key('visstat') or not casac.utils().verify(mytmp, trec['visstat']) :
00208             return False
00209 
00210 
00211         try :
00212           casalog.post('')
00213           casalog.post('##########################################')
00214           casalog.post('##### Begin Task: visstat           #####')
00215           casalog.post('')
00216           result = visstat(vis, axis, datacolumn, useflags, spw, field, selectdata, antenna, uvrange, timerange, correlation, scan, array, observation)
00217           casalog.post('')
00218           casalog.post('##### End Task: visstat           #####')
00219           casalog.post('##########################################')
00220 
00221 
00222 # saveinputs for individule engine has no use
00223 # saveinputs should alos be removed from casa_in_py.py
00224 #
00225 #
00226 #          saveinputs = myf['saveinputs']
00227 #          saveinputs('visstat', 'visstat.last', myparams)
00228 #
00229 #
00230         except Exception, instance:
00231           #print '**** Error **** ',instance
00232           pass
00233 
00234         gc.collect()
00235         return result
00236 #
00237 #
00238 ##
00239 #    def paramgui(self, useGlobals=True):
00240 #        """
00241 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00242 #        """
00243 #        import paramgui
00244 #
00245 #        a=inspect.stack()
00246 #        stacklevel=0
00247 #        for k in range(len(a)):
00248 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00249 #            stacklevel=k
00250 #            break
00251 #        myf = sys._getframe(stacklevel).f_globals
00252 #
00253 #        if useGlobals:
00254 #            paramgui.setGlobals(myf)
00255 #        else:
00256 #            paramgui.setGlobals({})
00257 #
00258 #        paramgui.runTask('visstat', myf['_ip'])
00259 #        paramgui.setGlobals({})
00260 #
00261 #
00262 #
00263 #
00264     def defaults(self, param=None):
00265         a=inspect.stack()
00266         stacklevel=0
00267         for k in range(len(a)):
00268           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00269                 stacklevel=k
00270                 break
00271         myf=sys._getframe(stacklevel).f_globals
00272         a = odict()
00273         a['vis']  = ''
00274         a['axis']  = 'amplitude'
00275         a['useflags']  = True
00276         a['spw']  = ''
00277         a['field']  = ''
00278         a['selectdata']  = True
00279 
00280         a['async']=False
00281         a['axis'] = {
00282                     0:odict([{'value':'amp'}, {'datacolumn':'data'}]), 
00283                     1:odict([{'value':'amplitude'}, {'datacolumn':'data'}]), 
00284                     2:odict([{'value':'phase'}, {'datacolumn':'data'}]), 
00285                     3:odict([{'value':'real'}, {'datacolumn':'data'}]), 
00286                     4:odict([{'value':'imag'}, {'datacolumn':'data'}]), 
00287                     5:odict([{'value':'imaginary'}, {'datacolumn':'data'}])}
00288         a['selectdata'] = {
00289                     0:odict([{'value':True}, {'antenna':''}, {'timerange':''}, {'correlation':''}, {'scan':''}, {'array':''}, {'observation':''}, {'uvrange':''}]), 
00290                     1:{'value':False}}
00291 
00292 ### This function sets the default values but also will return the list of
00293 ### parameters or the default value of a given parameter
00294         if(param == None):
00295                 myf['__set_default_parameters'](a)
00296         elif(param == 'paramkeys'):
00297                 return a.keys()
00298         else:
00299                 if(a.has_key(param)):
00300                    #if(type(a[param]) == dict) :
00301                    #   return a[param][len(a[param])-1]['value']
00302                    #else :
00303                       return a[param]
00304 
00305 
00306 #
00307 #
00308     def check_params(self, param=None, value=None):
00309       a=inspect.stack() 
00310       stacklevel=0
00311       for k in range(len(a)):
00312         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00313             stacklevel=k
00314             break
00315       myf=sys._getframe(stacklevel).f_globals
00316 
00317 #      print 'param:', param, 'value:', value
00318       try :
00319          if str(type(value)) != "<type 'instance'>" :
00320             value0 = value
00321             value = myf['cu'].expandparam(param, value)
00322             matchtype = False
00323             if(type(value) == numpy.ndarray):
00324                if(type(value) == type(value0)):
00325                   myf[param] = value.tolist()
00326                else:
00327                   #print 'value:', value, 'value0:', value0
00328                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00329                   myf[param] = value0
00330                   if type(value0) != list :
00331                      matchtype = True
00332             else :
00333                myf[param] = value
00334             value = myf['cu'].verifyparam({param:value})
00335             if matchtype:
00336                value = False
00337       except Exception, instance:
00338          #ignore the exception and just return it unchecked
00339          myf[param] = value
00340       return value
00341 
00342 #
00343 #
00344     def description(self, key='visstat', subkey=None):
00345         desc={'visstat': 'Displays statistical information from a measurement set, or from a measurement set selection',
00346                'vis': 'Name of input visibility file',
00347                'axis': 'Which values to use',
00348                'datacolumn': 'Which data column to use (data, corrected, model)',
00349                'useflags': 'Take flagging into account?',
00350                'spw': 'spectral-window/frequency/channel',
00351                'field': 'Field names or field index numbers: \'\'==>all, field=\'0~2,3C286\'',
00352                'selectdata': 'More data selection parameters (antenna, timerange etc)',
00353                'antenna': 'antenna/baselines: \'\'==>all, antenna = \'3,VA04\'',
00354                'uvrange': 'uv range: \'\'==>all; uvrange = \'0~100klambda\', default units=meters',
00355                'timerange': 'time range: \'\'==>all, timerange=\'09:14:0~09:54:0\'',
00356                'correlation': 'Select data based on correlation',
00357                'scan': 'scan numbers: \'\'==>all',
00358                'array': '(sub)array numbers: \'\'==>all',
00359                'observation': 'observation ID number(s): \'\' = all',
00360 
00361                'async': 'If true the taskname must be started using visstat(...)'
00362               }
00363 
00364 #
00365 # Set subfields defaults if needed
00366 #
00367 
00368         if(desc.has_key(key)) :
00369            return desc[key]
00370 
00371     def itsdefault(self, paramname) :
00372         a = {}
00373         a['vis']  = ''
00374         a['axis']  = 'amplitude'
00375         a['datacolumn']  = 'data'
00376         a['useflags']  = True
00377         a['spw']  = ''
00378         a['field']  = ''
00379         a['selectdata']  = True
00380         a['antenna']  = ''
00381         a['uvrange']  = ''
00382         a['timerange']  = ''
00383         a['correlation']  = ''
00384         a['scan']  = ''
00385         a['array']  = ''
00386         a['observation']  = ''
00387 
00388         if a.has_key(paramname) :
00389               return a[paramname]
00390 visstat_pg = visstat_pg_()