casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
task_statwt.py
Go to the documentation of this file.
00001 from taskinit import mstool, tbtool, casalog, write_history
00002 
00003 def statwt(vis, dorms, byantenna, sepacs, fitspw, fitcorr, combine,
00004            timebin, minsamp, field, spw, antenna, timerange, scan, intent,
00005            array, correlation, obs, datacolumn):
00006     """
00007     Sets WEIGHT and SIGMA using the scatter of the visibilities.
00008     """
00009     casalog.origin('statwt')
00010     retval = True
00011     try:
00012         myms = mstool()
00013         mytb = tbtool()
00014         
00015         # parameter check for those not fully implemeted
00016         # (should be taken out once implemented)
00017         if byantenna:
00018           raise ValueError("byantenna=True is not supported yet")
00019         if fitcorr !='':
00020           raise ValueError("fitcorr is not supported yet")
00021         if timebin !='0s' and timebin !='-1s':
00022           raise ValueError("timebin is not supported yet")
00023                      
00024         datacol = 'DATA'
00025         mytb.open(vis)
00026         colnames  = mytb.colnames()
00027         mytb.close()
00028         for datacol in ['CORRECTED_DATA', 'DATA', 'junk']:
00029             if datacol in colnames:
00030                 break
00031         if datacol == 'junk':
00032             raise ValueError(vis + " does not have a data column")        
00033 
00034         if datacol != datacolumn: # no CORRECTED_DATA case (fall back to DATA)
00035            casalog.post("No %s column found, using %s column" % (datacolumn.upper()+'_DATA', datacol),'WARN')
00036            datacolumn = datacol
00037 
00038         if ':' in spw:
00039             casalog.post('The channel selection part of spw will be ignored.', 'WARN')
00040         
00041         myms.open(vis, nomodify=False)
00042         retval = myms.statwt(dorms, byantenna, sepacs, fitspw, fitcorr, combine,
00043                              timebin, minsamp, field, spw, antenna, timerange, scan, intent,
00044                              array, correlation, obs, datacolumn)
00045         myms.close()
00046     except Exception, e:
00047         casalog.post("Error setting WEIGHT and SIGMA for %s:" % vis, 'SEVERE')
00048         casalog.post("%s" % e, 'SEVERE')
00049         if False:  # Set True for debugging.
00050             for p in statwt.func_code.co_varnames[:statwt.func_code.co_argcount]:
00051                 v = eval(p)
00052                 print p, "=", v, ", type =", type(v)
00053         retval = False
00054 
00055     if retval:
00056         try:
00057             param_names = statwt.func_code.co_varnames[:statwt.func_code.co_argcount]
00058             param_vals = [eval(p) for p in param_names]
00059             retval &= write_history(myms, vis, 'statwt', param_names, param_vals,
00060                                     casalog)
00061         except Exception, instance:
00062             casalog.post("*** Error \'%s\' updating HISTORY" % (instance),
00063                          'WARN')        
00064     return retval
00065         
00066