casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
statwt.py
Go to the documentation of this file.
00001 #
00002 # This file was generated using xslt from its XML file
00003 #
00004 # Copyright 2009, Associated Universities Inc., Washington DC
00005 #
00006 import sys
00007 import os
00008 from  casac import *
00009 import string
00010 from taskinit import casalog
00011 #from taskmanager import tm
00012 import task_statwt
00013 def statwt(vis='', dorms=False, byantenna=False, sepacs=True, fitspw='', fitcorr='', combine='', timebin='0s', minsamp=2, field='', spw='', antenna='', timerange='', scan='', intent='', array='', correlation='', observation='', datacolumn='corrected'):
00014 
00015         """ Reweight visibilities according to their scatter (Experimental)
00016 
00017     The WEIGHT and SIGMA columns of measurement sets are often set to arbitrary
00018     values (e.g. 1), or theoretically estimated from poorly known antenna and
00019     receiver properties.  Many tasks (e.g. clean) are insensitive to an overall
00020     scale error in WEIGHT, but are affected by errors in the relative weights
00021     between visibilities.  Other tasks, such as uvmodelfit, or anything which
00022     depends on theoretical estimates of the noise, require (reasonably) correct
00023     weights and sigmas.  statwt empirically measures the visibility scatter
00024     (typically as a function of time, antenna, and/or baseline) and uses that
00025     to set WEIGHT and SIGMA. It is important that all necessary calibrations 
00026     are applied to the data prior to running this task for correct determination of
00027     weights and sigmas. 
00028     
00029     Note: Some of the parameters (byantenna, sepacs, fitcorr, and timebin) 
00030           are not fully implemeted for CASA 3.4.
00031           
00032 
00033         Keyword arguments:
00034         vis -- Name of the measurement set.
00035                 default: none; example: vis='ngc5921.ms'
00036 
00037         dorms -- Estimate the scatter using rms instead of the standard
00038                  deviation?
00039 
00040                  Ideally the visibilities used to estimate the scatter, as
00041                  selected by fitspw and fitcorr, should be pure noise.  If you
00042                  know for certain that they are, then setting dorms to True
00043                  will give the best result.  Otherwise, use False (standard
00044                  sample standard deviation).  More robust scatter estimates
00045                  like the interquartile range or median absolute deviation from
00046                  the median are not offered because they require sorting by
00047                  value, which is not possible for complex numbers.
00048                default: False
00049 
00050         byantenna -- Assume that the noise is factorable by antenna (feed).
00051                      If false, treat it seperately for each baseline
00052                      (recommended if there is strong signal).
00053                default: False (*** byantenna=True is not yet implemented)
00054 
00055         sepacs -- If solving by antenna, treat autocorrelations separately.
00056                   (Acknowledge that what autocorrelations "see" is very
00057                    different from what crosscorrelations see.)
00058                default: True (*** not yet implemented)
00059 
00060 
00061         --- Data Selection (see help par.selectdata for more detailed
00062             information)
00063 
00064         fitspw -- The (ideally) signal-free spectral window:channels to
00065                   estimate the scatter from.
00066                default: '' (All)
00067 
00068         fitcorr -- The (ideally) signal-free correlations to
00069                    estimate the scatter from.
00070                default: '' (All) 
00071                *** not yet implemented 
00072 
00073         combine -- Let samples span multiple spws, corrs, scans, and/or states.
00074                    combine = 'spw': Recommended when a line spans an entire spw 
00075                                     - set fitspw to the neighboring spws and
00076                                     apply their weight to the line spw(s).
00077                                     However, the effect of the line signal per
00078                                     visibility may be relatively harmless
00079                                     compared to the noise difference between
00080                                     spws.
00081                    combine = 'scan': Can be useful when the scan number
00082                                      goes up with each integration,
00083                                      as in many WSRT MSes.
00084                    combine = ['scan', 'spw']: disregard scan and spw
00085                                               numbers when gathering samples.
00086                    combine = 'spw,scan': Same as above.
00087               default: '' (None)
00088 
00089         timebin -- Sample interval.
00090                    default: '0s' or '-1s' (1 integration at a time)
00091                    example: timebin='30s'
00092                             '10' means '10s'
00093                    *** not yet implemented 
00094 
00095         minsamp -- Minimum number of unflagged visibilities for estimating the
00096                    scatter.  Selected visibilities for which the weight cannot
00097                    be estimated will be flagged.  Note that minsamp is
00098                    effectively at least 2 if dorms is False, and 1 if it is
00099                    True.
00100 
00101         field -- Select field using field id(s) or field name(s).
00102                   [run listobs to obtain the list id's or names]
00103                default: ''=all fields If field string is a non-negative
00104                integer, it is assumed to be a field index
00105                otherwise, it is assumed to be a field name
00106                field='0~2'; field ids 0,1,2
00107                field='0,4,5~7'; field ids 0,4,5,6,7
00108                field='3C286,3C295'; fields named 3C286 and 3C295
00109                field = '3,4C*'; field id 3, all names starting with 4C
00110 
00111         spw -- Select spectral window/channels for changing WEIGHT and SIGMA.
00112                default: ''=all spectral windows and channels
00113                spw='0~2,4'; spectral windows 0,1,2,4 (all channels)
00114                spw='<2';  spectral windows less than 2 (i.e. 0,1)
00115                spw='0:5~61'; spw 0, channels 5 to 61
00116                spw='0,10,3:3~45'; spw 0,10 all channels, spw 3 - chans 3 to 45.
00117                spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
00118                spw = '*:3~64'  channels 3 through 64 for all sp id's
00119                        spw = ' :3~64' will NOT work.
00120                statwt does not support multiple channel ranges per spectral
00121                window (';') because it is not clear whether to keep the ranges
00122                in the original spectral window or make a new spectral window
00123                for each additional range.
00124 
00125         antenna -- Select antennas/baselines for changing WEIGHT and SIGMA.
00126                default: '' (all)
00127                 Non-negative integers are assumed to be antenna indices, and
00128                 anything else is taken as an antenna name.
00129 
00130                 Examples:
00131                 antenna='5&6': baseline between antenna index 5 and index 6.
00132                 antenna='VA05&VA06': baseline between VLA antenna 5 and 6.
00133                 antenna='5&6;7&8': baselines 5-6 and 7-8
00134                 antenna='5': all baselines with antenna 5
00135                 antenna='5,6,10': all baselines including antennas 5, 6, or 10
00136                 antenna='5,6,10&': all baselines with *only* antennas 5, 6, or
00137                                        10.  (cross-correlations only.  Use &&
00138                                        to include autocorrelations, and &&&
00139                                        to get only autocorrelations.)
00140                 antenna='!ea03,ea12,ea17': all baselines except those that
00141                                            include EVLA antennas ea03, ea12, or
00142                                            ea17.
00143         timerange -- Select data based on time range:
00144                default = '' (all); examples,
00145                timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00146                Note: if YYYY/MM/DD is missing date, timerange defaults to the
00147                first day in the dataset
00148                timerange='09:14:0~09:54:0' picks 40 min on first day
00149                timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 30min
00150                on next day
00151                timerange='09:44:00' data within one integration of time
00152                timerange='>10:24:00' data after this time
00153         scan -- Scan number range
00154             default: ''=all
00155         intent -- Select by scan intent (state).  Case sensitive.
00156             default: '' = all
00157             Examples:
00158             intent = 'CALIBRATE_ATMOSPHERE_REFERENCE'
00159             intent = 'calibrate_atmosphere_reference'.upper() # same as above
00160             # Select states that include one or both of CALIBRATE_WVR.REFERENCE
00161             # or OBSERVE_TARGET_ON_SOURCE.
00162             intent = 'CALIBRATE_WVR.REFERENCE, OBSERVE_TARGET_ON_SOURCE'
00163         array -- (Sub)array number range
00164             default: ''=all
00165         correlation -- Select correlations, e.g. 'rr, ll' or ['XY', 'YX'].
00166                        default '' (all).
00167         observation -- Select by observation ID(s).
00168                        default: '' = all
00169        datacolumn -- Which data column to calculate the scatter from
00170                   default='corrected'; example: datacolumn='data'
00171                   Options: 'data', 'corrected', 'model', 'float_data'
00172                   note: 'corrected' will fall back to DATA if CORRECTED_DATA
00173                         is absent.
00174 
00175 
00176         """
00177 
00178 #
00179 #    The following is work around to avoid a bug with current python translation
00180 #
00181         mytmp = {}
00182 
00183         mytmp['vis'] = vis
00184         mytmp['dorms'] = dorms
00185         mytmp['byantenna'] = byantenna
00186         mytmp['sepacs'] = sepacs
00187         mytmp['fitspw'] = fitspw
00188         mytmp['fitcorr'] = fitcorr
00189         mytmp['combine'] = combine
00190         mytmp['timebin'] = timebin
00191         mytmp['minsamp'] = minsamp
00192         mytmp['field'] = field
00193         mytmp['spw'] = spw
00194         mytmp['antenna'] = antenna
00195         mytmp['timerange'] = timerange
00196         mytmp['scan'] = scan
00197         mytmp['intent'] = intent
00198         mytmp['array'] = array
00199         mytmp['correlation'] = correlation
00200         mytmp['observation'] = observation
00201         mytmp['datacolumn'] = datacolumn
00202         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00203         trec = casac.utils().torecord(pathname+'statwt.xml')
00204 
00205         casalog.origin('statwt')
00206         if trec.has_key('statwt') and casac.utils().verify(mytmp, trec['statwt']) :
00207             result = task_statwt.statwt(vis, dorms, byantenna, sepacs, fitspw, fitcorr, combine, timebin, minsamp, field, spw, antenna, timerange, scan, intent, array, correlation, observation, datacolumn)
00208 
00209         else :
00210           result = False
00211         return result