casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdmath.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_sdmath
00013 def sdmath(expr='', varlist={}, antenna=0, fluxunit='', telescopeparm='', specunit='', frame='', doppler='', scanlist=[], field='', iflist=[], pollist=[], outfile='', outform='ASAP', overwrite=False):
00014 
00015         """ASAP SD task: do simple arithmatic (subtraction, addition, multiplication, and division) for spectra
00016   Keyword arguments:
00017         expr -- Mathematical expression using scantables 
00018         varlist -- Dictionary of variables in expr and their values.
00019                    Keys must be coincide with variables used in expr.
00020                    Values are substituted in each value in expr.
00021         antenna -- antenna name or id (only effective for MS input). 
00022         fluxunit -- units for line flux
00023                 options: 'K','Jy',''
00024                 default: '' (keep current fluxunit)
00025                 WARNING: For GBT data, see description below.
00026             >>> fluxunit expandable parameter
00027                  telescopeparm -- the telescope characteristics
00028                         options: (str) name or (list) list of gain info
00029                         default: '' (none set)
00030                         example: if telescopeparm='', it tries to get the telescope
00031                                  name from the data.
00032                                  Full antenna parameters (diameter,ap.eff.) known
00033                                  to ASAP are
00034                                  'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43',
00035                                  'CEDUNA','HOBART'. For GBT, it fixes default fluxunit
00036                                  to 'K' first then convert to a new fluxunit.
00037                                  telescopeparm=[104.9,0.43] diameter(m), ap.eff.
00038                                  telescopeparm=[0.743] gain in Jy/K
00039                                  telescopeparm='FIX' to change default fluxunit
00040                                  see description below
00041 
00042         specunit -- units for spectral axis
00043                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz'
00044                 default: '' (=current)
00045                 example: this will be the units for masklist
00046         frame -- frequency frame for spectral axis
00047                 options: (str) 'LSRK','REST','TOPO','LSRD','BARY',
00048                          'GEO','GALACTO','LGROUP','CMB'
00049                 default: currently set frame in scantable
00050                 WARNING: frame='REST' not yet implemented
00051         doppler -- doppler mode
00052                 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA'
00053                 default: currently set doppler in scantable
00054         scanlist -- list of scan numbers to process
00055                 default: [] (use all scans)
00056                 example: [21,22,23,24]
00057                 this selection is in addition to field, iflist, and pollist
00058         field -- selection string for selecting scans by name
00059                 default: '' (no name selection)
00060                 example: 'FLS3a*'
00061                 this selection is in addition to scanlist, iflist, and pollist
00062         iflist -- list of IF id numbers to select
00063                 default: [] (use all IFs)
00064                 example: [15]
00065                 this selection is in addition to scanlist, field, and pollist
00066         pollist -- list of polarization id numbers to select
00067                 default: [] (use all polarizations)
00068                 example: [1]
00069                 this selection is in addition to scanlist, field, and iflist
00070         outfile -- Name of output file
00071                 default: '' (<infile>_cal)
00072         outform -- format of output file
00073                 options: 'ASCII','SDFITS','MS','ASAP'
00074                 default: 'ASAP'
00075                 example: the ASAP format is easiest for further sd
00076                          processing; use MS for CASA imaging.
00077                          If ASCII, then will append some stuff to
00078                          the outfile name
00079         overwrite -- overwrite the output file if already exists
00080                 options: (bool) True,False
00081                 default: False
00082                 WARNING: if outform='ASCII', this parameter is ignored
00083 
00084 
00085         DESCRIPTION:
00086 
00087         Task sdmath execute a mathematical expression for single dish spectra.
00088         The spectral data file can be any of the formats supported by
00089         ASAP (scantable, MS, rpfits, and SDFITS). In the expression, 
00090         these file names should be put inside of sigle or double quotes.
00091 
00092         You can use variables in the expression. If you want to use, you 
00093         must define varlist dictionary. Name of variables should be simple, 
00094         e.g. V0, V1, etc., to avoid unexpected error. Keys of varlist must 
00095         be name of variables that you used in the expression, and their 
00096         values will be substituted for variables in the expression. Allowed 
00097         type for the value is numerical values, one- or two-dimensional lists 
00098         (Python list or numpy.ndarray), and filename strings that indicate 
00099         spectral data or ASCII text, which is space-separated list of 
00100         numerical values consisting of adequate number of rows and columns.  
00101 
00102         The fluxunit, specunit, and frame can be set, otherwise, the current
00103         settings of the first spectral data in the expression are used.  
00104         Other selections (e.g. scan No, . IF, Pol) also apply to all 
00105         the spectral data in the expression, so if any of the data does
00106         not contains selection, the task will produce no output. 
00107        
00108         WARNING for the GBT raw SDFITS format data as input:
00109         SDtasks are able to handle GBT raw SDFITS format data since the 
00110         data filler is available. However, the functionality is not well 
00111         tested yet, so that there may be unknown bugs.  
00112         
00113         Example:
00114         # do on-off/off calculation
00115         expr='("orion_on_data.asap"-"orion_off_data.asap")/"orion_off_data.asap"
00116         outfile='orion_cal.asap'
00117         sdmath()
00118 
00119         # do on-off/off calculation using varlist
00120         expr='V0/V1-V2'
00121         varlist['V0']="orion_on_data.asap"
00122         varlist['V1']="orion_off_data.asap"
00123         varlist['V2']=1.0
00124         outfile='orion_cal.asap'
00125         sdmath()
00126 
00127         # interpretation of ASCII file value for varlist
00128         If the contents of input ASCII file is shown as, 
00129 
00130            0.5 0.3 0.2
00131            1.0 0.2 0.9
00132 
00133         it is interpreted as a list [[0.5, 0.3, 0.2],[1.0, 0.2, 0.9]]. 
00134 
00135   
00136         """
00137         if type(scanlist)==int: scanlist=[scanlist]
00138         if type(iflist)==int: iflist=[iflist]
00139         if type(pollist)==int: pollist=[pollist]
00140 
00141 #
00142 #    The following is work around to avoid a bug with current python translation
00143 #
00144         mytmp = {}
00145 
00146         mytmp['expr'] = expr
00147         mytmp['varlist'] = varlist
00148         mytmp['antenna'] = antenna
00149         mytmp['fluxunit'] = fluxunit
00150         mytmp['telescopeparm'] = telescopeparm
00151         mytmp['specunit'] = specunit
00152         mytmp['frame'] = frame
00153         mytmp['doppler'] = doppler
00154         mytmp['scanlist'] = scanlist
00155         mytmp['field'] = field
00156         mytmp['iflist'] = iflist
00157         mytmp['pollist'] = pollist
00158         mytmp['outfile'] = outfile
00159         mytmp['outform'] = outform
00160         mytmp['overwrite'] = overwrite
00161         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00162         trec = casac.utils().torecord(pathname+'sdmath.xml')
00163 
00164         casalog.origin('sdmath')
00165         if trec.has_key('sdmath') and casac.utils().verify(mytmp, trec['sdmath']) :
00166             result = task_sdmath.sdmath(expr, varlist, antenna, fluxunit, telescopeparm, specunit, frame, doppler, scanlist, field, iflist, pollist, outfile, outform, overwrite)
00167 
00168         else :
00169           result = False
00170         return result