casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
importevla.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_importevla
00013 def importevla(asdm='', vis='', ocorr_mode='co', compression=False, asis='', scans='', verbose=False, overwrite=False, online=True, tbuff=0.0, flagzero=True, flagpol=True, shadow=True, tolerance=0.0, addantenna='', applyflags=False, savecmds=False, outfile='', flagbackup=True):
00014 
00015         """Convert an Science Data Model observation into a CASA Measurement Set
00016 Convert a Science Data Model (SDM) dataset into a CASA Measurement Set (MS).  
00017 Will place online flags and specified clip/shadow flags into FLAG_CMD table 
00018 and optionally apply to MS.
00019 
00020 Warning: This version is under development and is geared to handling EVLA 
00021 specific flag and system files, and is otherwise identical to importasdm.
00022                                           
00023         HISTORY: Task created v1.0 S.T. Myers 2010-03-11 (3.0.1)
00024                  Last updated v9.0 S.M. Castro 2012-03-13 (3.4) code+doc
00025 
00026 Keyword arguments:
00027 asdm         -- Name of input SDM file (directory)
00028                 default: none; 
00029                     Example: asdm='ExecBlock3'
00030 
00031 vis          -- Root ms or scantable name, note a .ms is NOT appended to name
00032                 default: none
00033 
00034 ocorr_mode   -- output data for correlation mode AUTO_ONLY 
00035                 (ao) or CROSS_ONLY (co) or CROSS_AND_AUTO (ca)
00036                 default: co (for EVLA)
00037 
00038 compression  -- produces comrpressed columns in the resulting measurement set.
00039                 default: False
00040 
00041 asis         -- creates verbatim copies of the ASDM tables in 
00042                 the output measurement set. The value given to
00043                 this option must be a list of table names separated
00044                 by space characters; the wildcard character '*' is 
00045                 allowed in table names.
00046 
00047 scans        -- processes the scans requested in this parameter (default is
00048                 all scans).  For simplest use provide a comma-separated list of 
00049                 scan ranges, e.g. scans='1~3,5,10~20'.
00050                 default: '' = all scans
00051 
00052                 NOTE: A scan specification tecnically consists of an ExecBlock 
00053                 index followed by the character ':' followed by a comma
00054                 separated list of scan indexes or scan index ranges. The EVLA
00055                 does not currently include more than one ExecBlock in a SDM
00056                 so this specification prefix is not needed.
00057 
00058                 By default all the scans are considered. 
00059 
00060 overwrite    -- Over write an existing MS
00061 
00062 verbose      -- produce log output as asdm2MS is being run
00063 
00064 EVLA-specific parameters:
00065 -------------------------
00066 
00067 online       -- create flagging commands for online flags. The commands will be saved to the FLAG_CMD 
00068                 sub-table of the MS. Optionally, it can also be saved to an ASCII file when savecmds is set
00069                 to True.
00070                 default: True
00071  
00072             >>> online expandable parameters
00073                  tbuff -- (float) time padding buffer (in seconds)
00074                  default: 0.0
00075 
00076                  NOTE: this time is in seconds. You should currently
00077                  set the value of tbuff to be 1.5x the correlator
00078                  integration time if greater than 1 second.  For
00079                  example, if the SDM has integrations of 3 seconds,
00080                  set tbuff=4.5.  Likewise, set tbuff=15.0 for 10-sec
00081                  integrations.
00082                                   
00083  
00084 flagzero     -- create flags to clip out visibilities with zero values. The command will be saved to the FLAG_CMD 
00085                 sub-table of the MS. Optionally, it can also be saved to an ASCII file when savecmds is set
00086                 to True.
00087                 default: True
00088  
00089             >>> flagzero expandable parameter(s) 
00090                  flagpol -- (boolean) also zero-clip on cross-hands (default=False)
00091  
00092 shadow       -- create flags for antennas that are shadowed. The command will be saved to the FLAG_CMD 
00093                 sub-table of the MS. Optionally, it can also be saved to an ASCII file when savecmds is set
00094                 to True.
00095                 default: True
00096  
00097             >>> shadow expandable parameter
00098                  tolerance -- Amount of shadowing allowed in meters.
00099                    default: 0.0
00100 
00101                  addantenna -- It can be either a file name with additional antenna names, positions 
00102                                and diameters, or a Python dictionary with the same information. 
00103                                You can use the flaghelper functions to create the dictionary from a file.  
00104                    default: ''
00105                    
00106                    To create a dictionary inside casapy.
00107                    > import flaghelper as fh
00108                    > antdic = fh.readAntennaList(antfile)
00109                    
00110                    Where antfile is a text file in disk that contains information such as:
00111                     name=VLA01
00112                     diameter=25.0
00113                     position=[-1601144.96146691, -5041998.01971858, 3554864.76811967]
00114                     name=VLA02
00115                     diameter=25.0
00116                     position=[-1601105.7664601889, -5042022.3917835914, 3554847.245159178]
00117                    
00118  
00119 applyflags   -- apply the online and specified flags to the MS
00120                 default: False
00121 
00122 
00123 savecmds   -- Save the flag commands to an ASCII file given by the parameter outfile. It will save the
00124               flag commands from online, flagzero and/or shadow if they are set to True. 
00125                 default: False
00126                     
00127             >>> savecmds expandable parameter
00128                 outfile      -- Filename where to save the flag commands.
00129                 default: ' ' --> by default it will save on a filename composed from the MS name.
00130                     Example: vis='evla.ms', the outfile will be 'evla_cmd.txt'. 
00131                     
00132                     NOTE: The file is open to save in append mode.
00133 
00134 
00135 flagbackup   -- Backup original flags in >ms<.flagversions 
00136                 default: True
00137 
00138        Examples:
00139 
00140 
00141         1)  Produces MS CLowTest_000.ms with autocorrelations.
00142             You will find the online, zero, and shadow flags in the FLAG_CMD table
00143             for later application.  Does not apply any flags.
00144                 
00145              importevla(asdm='CLowTest_000',ocorr_mode='ca')
00146                 
00147 
00148         2)  Produces MS CLowTest_000.ms without autocorrelations.  
00149                
00150              importevla(asdm='CLowTest_000')
00151                 
00152 
00153         3)  Will apply online flags and uses a more conservative 2sec buffer
00154                 before the start and after the end timeranges.
00155                 
00156              importevla(asdm='CLowTest_000',online=True,tbuff=2.0,applyflags=True)
00157                 
00158 
00159         4)  This will create the FLAG_CMD sub-table using online flags only,
00160             but will not apply them to the MS.
00161 
00162             importevla(asdm='CLowTest_000',online=True,flagzero=False,shadow=False)
00163 
00164 
00165         5)  This will write the online flags to the FLAG_CMD table. It will also save commands
00166             to clip zeros and to flag shadowed antennas to the table. The commands will be further 
00167             applied to the data and the APPLIED column of the FLAG_CMD will be updated to True.
00168 
00169             importevla(asdm='CLowTest_000',online=True,flagzero=True,shadow=True,applyflags=True)
00170 
00171 
00172         6)  Import only scans 1, 2, 3, 5, 7, 9, save the online, shadow and clip commands to an ASCII file and
00173             do not apply the flags. The commands will be saved to CLowTest_000_cmd.txt.
00174 
00175             importevla(asdm='CLowTest_000',scans='1~3,5,7,9',online=True,flagzero=True,shadow=True,
00176                                 applyflags=False, savecmds=True)
00177                 
00178                 You can use either flagdata or flagcmd to apply the flags later with the following commands:
00179                 
00180                 Apply all the flags in the file using flagdata
00181                 flagdata('CLowTest_000.ms', mode='list', inpfile='CLowTest_000_cmd.txt')
00182 
00183                 Select by reason on the file
00184                 flagdata('CLowTest_000.ms',mode='list', inpfile='CLowTest_000_cmd.txt', 
00185                            reason=['ANTENNA_NOT_POINTING','CORRELATOR_DATA_INVALID'])
00186                 
00187                 Apply all the flags in the file using flagcmd
00188                 flagcmd('CLowTest_000.ms',inpmode='list',inpfile='CLTest_000_cmd.txt',action='apply')
00189                                 
00190 
00191 HISTORY: Task last updated v9.0 S.M. Castro 2012-03-8 (3.4.0)
00192          Docs last updated v9.0 S.M. Castro 2012-03-13 (3.4.0)
00193 
00194   
00195         """
00196 
00197 #
00198 #    The following is work around to avoid a bug with current python translation
00199 #
00200         mytmp = {}
00201 
00202         mytmp['asdm'] = asdm
00203         mytmp['vis'] = vis
00204         mytmp['ocorr_mode'] = ocorr_mode
00205         mytmp['compression'] = compression
00206         mytmp['asis'] = asis
00207         mytmp['scans'] = scans
00208         mytmp['verbose'] = verbose
00209         mytmp['overwrite'] = overwrite
00210         mytmp['online'] = online
00211         mytmp['tbuff'] = tbuff
00212         mytmp['flagzero'] = flagzero
00213         mytmp['flagpol'] = flagpol
00214         mytmp['shadow'] = shadow
00215         mytmp['tolerance'] = tolerance
00216         mytmp['addantenna'] = addantenna
00217         mytmp['applyflags'] = applyflags
00218         mytmp['savecmds'] = savecmds
00219         mytmp['outfile'] = outfile
00220         mytmp['flagbackup'] = flagbackup
00221         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00222         trec = casac.utils().torecord(pathname+'importevla.xml')
00223 
00224         casalog.origin('importevla')
00225         if trec.has_key('importevla') and casac.utils().verify(mytmp, trec['importevla']) :
00226             result = task_importevla.importevla(asdm, vis, ocorr_mode, compression, asis, scans, verbose, overwrite, online, tbuff, flagzero, flagpol, shadow, tolerance, addantenna, applyflags, savecmds, outfile, flagbackup)
00227 
00228         else :
00229           result = False
00230         return result