casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
setjy.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_setjy
00013 def setjy(vis='', field='', spw='', selectdata=False, timerange='', scan='', observation='', modimage='', listmodels=False, scalebychan=True, fluxdensity=-1, spix=0.0, reffreq='1GHz', standard='Perley-Butler 2010', useephemdir=False, usescratch=False):
00014 
00015         """Fills the model column with the visibilities of a calibrator
00016 
00017     The task sets the model visibility amp and phase of a specified source
00018     (generally a calibrator).  The simplest way is to enter the flux density
00019     (I,Q,U,V) explicitly, but this is valid only for a point source.
00020 
00021     For an extended source, the clean model (image.model) can be
00022     specified and the model visibilities associated with this clean
00023     model is placed in the visibility model column.
00024 
00025     Models are available for 3C48, 3C138, 3C286 between 1.4 and 43 GHz.
00026     3C147 is available above 4 GHz.  These models are scaled to the precise
00027     frequency of the data.  Only I models are presently available.
00028 
00029     The location of the models is system dependent: At the AOC and CV, the
00030     models are in the directory::/usr/lib/casapy/data/nrao/VLA/CalModels or
00031     /usr/lib64/casapy/data/nrao/VLA/CalModels (depending on whether 32 or 64
00032     bit CASA was installed on the machine being used).  In general (using
00033     Python), the stock models should be in
00034     casa['dirs']['data'] + '/nrao/VLA/CalModels'
00035     setjy also looks for models in the current directory before trying
00036     casa['dirs']['data'] + '/nrao/VLA/CalModels'.
00037 
00038     setjy need only be run on the calibrator sources with a known flux
00039     density and/or model.
00040 
00041     
00042     Solar System Objects are supported via the 'Butler-JPL-Horizons 2012' 
00043     standard. This uses new brightness temperature models and a new flux
00044     calculation code that replace the 'Butler-JPL-Horizons 2010' standard.
00045     The older 'Butler-JPL-Horizons 2010' standard is still available
00046     for comparison. Users may want to use predictcomp task to see the differeces. 
00047     Currently they are modeled as uniform temperature disks based
00048     on their ephemerides at the time of observation (note that this may
00049     oversimply objects, in particular asteroids).  The object name is
00050     obtained from the 'field' parameter. Recognized objects are listed
00051     below, under 'standard'.
00052 
00053     Note that fluxdensity, modimage, and standard interact in a possibly
00054     confusing way!  Generally, if fluxdensity[0] (Stokes I) is <= 0, it
00055     will be ignored.  If it is < 0, standard (which has a default) will
00056     be used to calculate flux density as a function of frequency, even if
00057     modimage is specified.  If is is exactly 0 and modimage is given, the
00058     brightness of the model image will be used as is.  If fluxdensity([0])
00059     is > 0, it will be used.  The latter two options come at the price of
00060     disabling frequency scaling, i.e. the same fluxdensity will be used for
00061     all frequencies.
00062 
00063     Keyword arguments:
00064     vis -- Name of input visibility file
00065             default: none.  example: vis='ngc5921.ms'
00066     field -- Select field using field id(s) or field name(s).
00067            default: ''=all fields, but run setjy one field at a time.
00068               [run listobs to obtain the list id's or names of calibrators]
00069            If field is a non-negative integer, it is assumed to be a field
00070            index.  Otherwise, it is taken to be a field name (case sensitive
00071            - it must match the name as listed by listobs).
00072            field='0~2'; field ids 0,1,2
00073            field='0,4,5~7'; field ids 0,4,5,6,7
00074            field='3C286,3C295'; field named 3C286 and 3C295
00075            field = '3,4C*'; field id 3, all names starting with 4C
00076     spw -- Spectral window selection string.
00077            default: '' = all spectral windows
00078            Note that setjy only selects by spectral window, and ignores
00079            channel selections.  Fine-grained control could be achieved using
00080            (and possibly constructing) a cube for modimage.
00081 
00082     selectdata -- Other parameters for selecting part(s) of the MS
00083                   to operate on.
00084                   (Currently all time-oriented and most likely only of
00085                    interest when using a Solar System object as a calibrator.)
00086                   default: False
00087 
00088   >>> selectdata=True expandable parameters
00089                See help par.selectdata for more on these.
00090 
00091                timerange  -- Select data based on time range:
00092                    default: '' (all); examples,
00093                    timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
00094                    Note: if YYYY/MM/DD is missing date defaults to first 
00095                          day in data set
00096                    timerange='09:14:0~09:54:0' picks 40 min on first day
00097                    timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 
00098                              30min on NEXT day
00099                    timerange='09:44:00' pick data within one integration 
00100                              of time
00101                    timerange='>10:24:00' data after this time
00102                    For multiple MS input, a list of timerange strings can be
00103                    used:
00104                    timerange=['09:14:0~09:54:0','>10:24:00']
00105                    timerange='09:14:0~09:54:0''; apply the same timerange for
00106                                                  all input MSes
00107                scan -- Scan number range.
00108                    default: '' (all)
00109                    example: scan='1~5'
00110                    For multiple MS input, a list of scan strings can be used:
00111                    scan=['0~100','10~200']
00112                    scan='0~100; scan ids 0-100 for all input MSes
00113                    Check 'go listobs' to insure the scan numbers are in order.
00114                observation -- Observation ID range.
00115                    default: '' (all)
00116                    example: observation='1~5'
00117 
00118 
00119     modimage -- Model image (I only) for setting the model visibilities.
00120            modimage can be a cube, and its channels do not have to exactly
00121            match those of vis.  It is recommended to use modimage for
00122            sources that are resolved by the observation, but the
00123            Butler-JPL-Horizons standard supplies a basic model of what
00124            several Solar System objects look like.  default: '': do not use
00125            a model image.
00126     
00127            Each field must be done separately when using a model image.  The
00128            flux density of the image will be scaled from the frequency in
00129            the model to that actually used (ignoring fluxdensity), unless
00130            fluxdensity >= 0 (or fluxdensity[0] >= 0).  If
00131            fluxdensity([0]) is 0.0, the image's flux density will be used.
00132            If fluxdensity([0]) > 0.0, it will be used (and spix and
00133            reffreq if modimage is not a cube).  Since the spectral index
00134            usually varies with direction, applying a single spectral index
00135            to a 2D modimage is typically not as good as using a cube.
00136 
00137            Both the amplitude and phase are calculated.  At the AOC or CV,
00138            the models are located in casa['dirs']['data']
00139            + '/nrao/VLA/CalModels/', e.g.
00140            /usr/lib/casapy/data/nrao/VLA/CalModels/3C286_L.im
00141                 lib64
00142 
00143            If modimage does not start with '/', setjy will look for a match
00144            in '.', './CalModels', and any CalModels directories within
00145            the casa['dirs']['data'] tree (excluding certain branches).
00146 
00147            Note that modimage should be deconvolved, i.e. a set of clean
00148            components instead of an image that has been convolved with a
00149            clean beam.
00150 
00151     listmodels -- If True, do nothing but list candidates for modimage
00152            (for extragalactic calibrators) that are present on the system.  It looks for *.im* *.mod* in .,
00153            CalModels, and CalModels directories in the casa['dirs']['data']
00154            tree.  It does not check whether they are appropriate for the MS!
00155            If standard='Butler-JPL-Horizons 2012', Tb models (frequency-depended
00156            brightness temperature models) for Solar System objects used in the 
00157            standard.  For standard='Butler-JPL-Horizons 2010', the recognized
00158            Solar System objects are listed. 
00159 
00160     scalebychan -- This determines whether the fluxdensity set in the model is
00161             calculated on a per channel basis. If False then it only one
00162             fluxdensity value is calculated per spw.  (Either way, all channels
00163             in spw are modified.)  It is effectively True if fluxdensity[0] >
00164             0.0. 
00165             default: True
00166 
00167     fluxdensity -- Specified flux density [I,Q,U,V] in Jy
00168             default: -1, uses [1,0,0,0] flux density for unrecognized sources,
00169             and standard flux densities for ones recognized by 'standard',
00170             including 3C286, 3C48, 3C147, and several planets, moons, and
00171             asteroids.  setjy will try to use standard if fluxdensity is not
00172             positive.
00173 
00174             Only one flux density can be specified at a time.  The phases are
00175                set to zero.
00176             example   fluxdensity=-1  will use standard for recognized
00177                       calibrators (like 3C286, 3C147 and 3C48, depending on
00178                       standard) and insert 1.0 for selected fields with
00179                       unrecognized sources.
00180             example   field = '1'; fluxdensity=[3.2,0,0,0] wil put in 
00181                       a flux density of I=3.2 for field='1'
00182 
00183             At present (June 2000), this is the only method to insert a
00184             polarized flux density model.
00185             example:  fluxdensity=[2.63,0.21,-0.33,0.02]
00186                       will put in I,Q,U,V flux densities of 2.63,0.21,-0.33,
00187                       and 0.02, respectively, in the model column.
00188 
00189     spix -- Spectral index for fluxdensity:
00190                  S = fluxdensity * (freq/reffreq)**spix
00191             Default: 0 (no effect)
00192             Only used if fluxdensity is being used.
00193             N.B.: If fluxdensity is positive, and spix is nonzero, then reffreq
00194                   must be set too!  (See below)
00195 
00196                   It is applied in the same way to all polarizations, and does
00197                   not account for Faraday rotation or depolarization.
00198 
00199     reffreq -- The reference frequency for spix, given with units.
00200             Default: '1GHz'; this is only here to prevent division by 0!
00201             N.B.: If the flux density is being scaled by spectral index,
00202             then reffreq must be set to whatever reference frequency is
00203             correct for the given fluxdensity and spix.  It cannot be
00204             determined from vis.  On the other hand, if spix is 0, then any
00205             positive frequency can be used (and ignored).
00206 
00207             Examples: '86.0GHz', '4.65e9Hz'
00208 
00209     standard -- Flux density standard, used if fluxdensity[0] < 0.0
00210             default: 'Perley-Butler 2010'; example: standard='Baars'
00211             Options: 'Baars','Perley 90','Perley-Taylor 95',
00212                'Perley-Taylor 99', 'Perley-Butler 2010', 'Perley-Butler 2013',
00213                'Butler-JPL-Horizons 2010', and 'Butler-JPL-Horizons 2012'. 
00214             All but the last two are for extragalactic calibrators,
00215             and the final two are for Solar System objects.  
00216 
00217             Extragalactic calibrators:
00218             Following source names and their common aliases are recognized.
00219             The last column shows which standards support for each source.
00220             Note that the task does not do exact matching of the name and
00221             it recognizes as long as the field name  contains the string 
00222             listed below (e.g. 'PKS 1934-638' works). 
00223             -----------------------------------------------------------
00224             3C Name B1950 Name J2000 Name Alt. J2000 Name  standards*
00225             3C48    0134+329   0137+331   J0137+3309       1,3,4,5,6
00226             3C123   0433+295   0437+296   J0437+2940       2 
00227             3C138   0518+165   0521+166   J0521+1638       1,3,4,5,6
00228             3C147   0538+498   0542+498   J0542+4951       1,3,4,5,6
00229             3C196   0809+483   0813+482   J0813+4813       1,2 
00230             3C286   1328+307   1331+305   J1331+3030       1,2,3,4,5,6
00231             3C295   1409+524   1411+522   J1411+5212       1,2,3,4,5,6
00232               -     1934-638      -       J1939-6342       1,3,4,5,6
00233             ----------------------------------------------------------- 
00234             * supported in: 1 - Perley-Butler 2010, 2 - Perley-Butler 2013,
00235             3 - Perley-Taylor 99, 4 - Perley-Taylor 95, 5 - Perley 90, 6 - Baars 
00236 
00237             Solar system objects:
00238             The 'Butler-JPL-Horizons 2012' standard is recommended over 
00239             'Butler-JPL-Horizons 2010' as the former uses updated models.
00240             Recognized Solar System objects (for 'Butler-JPL-Horizons 2012') are: 
00241              
00242                
00243                Planets: Venus, Mars, Jupiter, Uranus, Neptune
00244                
00245                Moons: Jupiter: Io, Europa, Ganymede, Callisto
00246                    Saturn:  Titan 
00247 
00248                Asteroids: Ceres, Pallas**, Vesta**, Juno**
00249 
00250             * Venus: model for ~300MHz to 350GHz, no atmospheric lines (CO,H2O,HDO, etc)
00251             * Mars: tabulated as a function of time and frequency (30 - 1000GHz) based on 
00252                Rudy el tal (1988), no atmopheric lines (CO, H20, H2O2, HDO, etc)
00253             * Jupiter: model for 30-1020GHz, does not include synchrotron emission
00254             * Uranus: model for 60-1800GHz, contains no rings or synchrotron.
00255             * Neptune: model for 2-2000GHz, the broad CO absorption line
00256                is included, but contains no rings or syncrotron. 
00257             * Titan: model for 53.3-1024.1GHz, include many spectral lines
00258 
00259             **  not recommended (The temperature is not yet adjusted for
00260                 varying distance from the Sun.  The model data can be scaled
00261                 after running setjy, but it is an involved process.)
00262 
00263                The 'field' parameter must match the case of the field name(s)
00264                in vis (as shown by listobs).
00265 
00266             Flux density calculation with Solar System objects depends on
00267             ephemerides. The setjy task looks for the data in  
00268             
00269             os.getenv('CASAPATH').split()[0] + '/data/ephemerides/JPL-Horizons'.
00270 
00271             If no ephemeris for the right object at the right time is
00272             present, the calculation will fail.  Ask the helpdesk to make an
00273             ephemeris.  The very adventurous and well versed in python can
00274             try it using CASA's recipes.ephemerides package:
00275                  import recipes.ephemerides as eph
00276                  help eph
00277 
00278             CASA comes with ephemerides for several more objects, but they
00279             are intended for use with me.framecomet(), and are not (yet)
00280             suitable flux density calibrators.  It is up to the observer to
00281             pick a good flux density calibrator (bright, spherical and
00282             featureless, on a circular orbit, in the right part of the sky,
00283             and not too resolved).  Even some of the objects listed above
00284             may prove to require more sophisticated flux density models than
00285             are currently implemented in CASA.  For many objects running
00286             casalog.filter('INFO1') before running setjy will send more
00287             information to the logger.  The cookbook also has an appendix
00288             with descriptions of the models used by setjy (both
00289             extragalactic and Solar System).
00290 
00291        >>> standard="Butler-JPL-Horizons 2012" expandable parameter
00292 
00293             useephemdir -- If True: use the direction from the ephemeris table for 
00294                 the solar system object. 
00295                 default: False -use the direction information in the MS(i.e. Field table) 
00296 
00297         usescratch  -- If False: 'virtual' model is created. The model is saved in the header 
00298         and model visibilities are evaluated when calculating calibration or plotting in plotms.
00299         If True: the model visibility will be evaluated and saved on disk in the MODEL_DATA 
00300         column.  This will increase your ms in size by a factor of 1.5 (w.r.t. the case where 
00301         you only have the DATA and the CORRECTED_DATA column).  Use True if you need to interact 
00302         with the MODEL_DATA in python, say.
00303 
00304         *By running usescratch=T, it will remove the existing virtual model from previous runs.
00305         usescratch=F will not remove the existing MODEL_DATA but in subsequent process
00306         the virtual model with matching field and spw combination will be used if it exists
00307         regardless of the presence of the MODEL_DATA column.
00308          
00309         default: False        
00310             
00311 
00312         """
00313 
00314 #
00315 #    The following is work around to avoid a bug with current python translation
00316 #
00317         mytmp = {}
00318 
00319         mytmp['vis'] = vis
00320         mytmp['field'] = field
00321         mytmp['spw'] = spw
00322         mytmp['selectdata'] = selectdata
00323         mytmp['timerange'] = timerange
00324         mytmp['scan'] = scan
00325         mytmp['observation'] = observation
00326         mytmp['modimage'] = modimage
00327         mytmp['listmodels'] = listmodels
00328         mytmp['scalebychan'] = scalebychan
00329         mytmp['fluxdensity'] = fluxdensity
00330         mytmp['spix'] = spix
00331         mytmp['reffreq'] = reffreq
00332         mytmp['standard'] = standard
00333         mytmp['useephemdir'] = useephemdir
00334         mytmp['usescratch'] = usescratch
00335         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00336         trec = casac.utils().torecord(pathname+'setjy.xml')
00337 
00338         casalog.origin('setjy')
00339         if trec.has_key('setjy') and casac.utils().verify(mytmp, trec['setjy']) :
00340             result = task_setjy.setjy(vis, field, spw, selectdata, timerange, scan, observation, modimage, listmodels, scalebychan, fluxdensity, spix, reffreq, standard, useephemdir, usescratch)
00341 
00342         else :
00343           result = False
00344         return result