casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdplot.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_sdplot
00013 def sdplot(infile='', antenna=0, fluxunit='', telescopeparm='', specunit='', restfreq='', frame='', doppler='', scanlist=[], field='', iflist=[], pollist=[], beamlist=[], scanaverage=False, timeaverage=False, tweight='tintsys', polaverage=False, pweight='tsys', kernel='none', kwidth=5, plottype='spectra', stack='p', panel='i', flrange=[], sprange=[], linecat='none', linedop=0.0, subplot=-1, colormap='none', linestyles='none', linewidth=1, histogram=False, center='', cell=[], header=True, headsize=9, plotstyle=False, margin=[], legendloc=1, outfile='', overwrite=False):
00014 
00015         """ASAP SD plotting task 
00016   Keyword arguments:
00017         infile -- name of input SD dataset
00018         antenna -- antenna name or id (only effective for MS input). 
00019         fluxunit -- units for line flux
00020                 options: 'K','Jy',''
00021                 default: '' (keep current fluxunit)
00022                 WARNING: For GBT data, see description below.
00023             >>> fluxunit expandable parameter
00024                  telescopeparm -- the telescope characteristics
00025                         options: (str) name or (list) list of gain info
00026                         default: '' (none set)
00027                         example: if telescopeparm='', it tries to get the telescope
00028                                  name from the data.
00029                                  Full antenna parameters (diameter,ap.eff.) known
00030                                  to ASAP are
00031                                  'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43',
00032                                  'CEDUNA','HOBART'. For GBT, it fixes default fluxunit
00033                                  to 'K' first then convert to a new fluxunit.
00034                                  telescopeparm=[104.9,0.43] diameter(m), ap.eff.
00035                                  telescopeparm=[0.743] gain in Jy/K
00036                                  telescopeparm='FIX' to change default fluxunit
00037                                  see description below
00038 
00039         specunit -- units for spectral axis
00040                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz'
00041                 default: '' (=current)
00042                 example: this will be the units for masklist
00043             >>> specunit expandable parameter
00044                  restfreq -- rest frequency
00045                          default: '' (use current setting)
00046                          example: 4.6e10 (float value in Hz),
00047                                   '46GHz' (string with unit),
00048                                   ['345.8GHz', 347.0e9, 356.7e9] (for each IF)
00049                                   [{'name':'CO','value':345e9}] (a value with name)
00050         frame -- frequency frame for spectral axis
00051                 options: (str) 'LSRK','REST','TOPO','LSRD','BARY',
00052                          'GEO','GALACTO','LGROUP','CMB'
00053                 default: currently set frame in scantable
00054                 WARNING: frame='REST' not yet implemented
00055         doppler -- doppler mode
00056                 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA'
00057                 default: currently set doppler in scantable
00058         scanlist -- list or string of scan numbers to process
00059                 default: [] (use all scans)
00060                 example: [21,22,23,24], or "21~24"
00061                 this selection is in addition to field, iflist, pollist,
00062                 and beamlist
00063         field -- selection string for selecting scans by name
00064                 default: '' (no name selection)
00065                 example: 'FLS3a*'
00066                 this selection is in addition to scanlist, iflist, pollist,
00067                 and beamlist
00068         iflist -- list or string of IF id numbers to select
00069                 default: [] (use all IFs)
00070                 example: [15]
00071                 this selection is in addition to scanlist, field, pollist,
00072                 and beamlist
00073         pollist -- list or string of polarization id numbers to select
00074                 default: [] (use all polarizations)
00075                 example: [1]
00076                 this selection is in addition to scanlist, field, iflist,
00077                 and beamlist
00078         beamlist -- list or string of beam id numbers to select
00079                 default: [] (use all beams)
00080                 example: [1]
00081                 this selection is in addition to scanlist, field, iflist,
00082                 and pollist
00083         scanaverage -- average integs within scans
00084                 options: (bool) True,False
00085                 default: False
00086         timeaverage -- average times for multiple scan cycles
00087                 options: (bool) True,False
00088                 default: False
00089                 example: if True, this happens after calibration
00090                 >>>timeaverage expandable parameter
00091                  tweight -- weighting for time average
00092                          options: 'var'   (1/var(spec) weighted)
00093                                   'tsys'  (1/Tsys**2 weighted)
00094                                   'tint'  (integration time weighted)
00095                                   'tintsys'  (Tint/Tsys**2)
00096                                   'median'  ( median averaging)
00097                          default: 'tintsys'
00098         polaverage -- average polarizations
00099                 options: (bool) True,False
00100                 default: False
00101                 >>>polaverage expandable parameter
00102                  pweight -- weighting for polarization average
00103                          options: 'var'  (1/var(spec) weighted)
00104                                   'tsys' (1/Tsys**2 weighted)
00105                          default: 'tsys'
00106         kernel -- type of spectral smoothing
00107                 options: 'hanning','gaussian','boxcar', 'none'
00108                 default: 'none'
00109                 >>>kernel expandable parameter
00110                  kwidth -- width of spectral smoothing kernel
00111                          options: (int) in channels
00112                          default: 5
00113                          example: 5 or 10 seem to be popular for boxcar
00114                                   ignored for hanning (fixed at 5 chans)
00115                                   (0 will turn off gaussian or boxcar)
00116         plottype -- type of plot
00117                  options: 'spectra','totalpower','pointing','azel','grid'
00118                  default: 'spectra'
00119             >>> plottype expandable parameters
00120                 stack -- code for stacking on single plot for spectral plotting
00121                         options: 'p','b','i','t','s','r' or
00122                                  'pol', 'beam', 'if', 'time', 'scan', 'row'
00123                         default: 'p'
00124                         example: maximum of 16 stacked spectra
00125                                  stack by pol, beam, if, time, scan
00126                         Note stack selection is ignored when panel='r'.
00127                 panel -- code for splitting into multiple panels for spectral plotting
00128                         options: 'p','b','i','t','s','r' or
00129                                  'pol', 'beam', 'if', 'time', 'scan', 'row'
00130                         default: 'i'
00131                         example: maximum of 16 panels
00132                                  panel by pol, beam, if, time, scan
00133                         Note panel selection is ignored when stack='r'.
00134                 flrange -- range for flux axis of plot for spectral plotting
00135                         options: (list) [min,max]
00136                         default: [] (full range)
00137                         example: flrange=[-0.1,2.0] if 'K'
00138                                  assumes current fluxunit
00139                 sprange -- range for spectral axis of plot
00140                         options: (list) [min,max]
00141                         default: [] (full range)
00142                         example: sprange=[42.1,42.5] if 'GHz'
00143                                  assumes current specunit
00144                 linecat -- control for line catalog plotting for spectral plotting
00145                         options: (str) 'all','none' or by molecule
00146                         default: 'none' (no lines plotted)
00147                         example: linecat='SiO' for SiO lines
00148                                  linecat='*OH' for alcohols
00149                                  uses sprange to limit catalog
00150                         WARNING: specunit must be in frequency (*Hz)
00151                                  to plot from the line catalog!
00152                                  and must be 'GHz' or 'MHz' to use
00153                                  sprange to limit catalog
00154                 linedop -- doppler offset for line catalog plotting (spectral plotting)
00155                         options: (float) doppler velocity (km/s)
00156                         default: 0.0
00157                         example: linedop=-30.0
00158                 center -- the central direction of gridding
00159                         default: '' (map center)
00160                         example: 'J2000 19h30m00 -40d00m00'
00161                         Note currently only supports 'J2000' as direction frame
00162                 cell -- x and y cell size of gridding
00163                         default: [] (map extent devided by # of subplots in x and y)
00164                         example: cell=['1.0arcmin','1.0arcmin']
00165                                  cell='1.0arcmin' (equivalent to the example above)
00166                         Note default number of subplots is 1 x 1 in plottype='grid'.
00167                 subplot -- number of subplots (row and column) on a page
00168                            NOTICE plotter will slow down when a large number is specified
00169                            default: -1 (auto. for plottype='spectra', 1x1 for plottype='grid')
00170                            example: 23 (2 rows by 3 columns)
00171                 colormap -- the colours to be used for plot lines. 
00172                         default: None
00173                         example: colormap="green red black cyan magenta" (html standard)
00174                                  colormap="g r k c m" (abbreviation)
00175                                  colormap="#008000 #00FFFF #FF0090" (RGB tuple)
00176                                  The plotter will cycle through these colours 
00177                                  when lines are overlaid (stacking mode).
00178                 linestyles -- the linestyles to be used for plot lines. 
00179                         default: None
00180                         example: linestyles="line dashed dotted dashdot dashdotdot dashdashdot". 
00181                                  The plotter will cycle through these linestyles 
00182                                  when lines are overlaid (stacking mode). 
00183                         WARNING: Linestyles can be specified only one color has been set. 
00184                 linewidth -- width of plotted lines. 
00185                         default: 1
00186                         example: linewidth=1 (integer)
00187                                  linewidth=0.75 (double)
00188                 histogram -- plot histogram
00189                         options: (bool) True, False
00190                         default: False
00191         header -- print header information on the plot
00192                 options: (bool) True, False
00193                 default: True
00194                 The header information is printed only on the logger when 
00195                 plottype = 'azel' and 'pointing'. 
00196             >>> header expandable parameter
00197                 headsize -- header font size
00198                         options: (int)
00199                         default: 9
00200         plotstyle -- customise plot settings
00201                 options: (bool) True, False
00202                 default: False
00203             >>> plotstyle expandable parameter
00204                 margin -- a list of subplot margins in figure coordinate (0-1), 
00205                           i.e., fraction of the figure width or height.
00206                           The order of elements should be:
00207                           [left, bottom, right, top, horizontal space btw panels,
00208                           vertical space btw panels]
00209                         example: margin = [0.125, 0.1, 0.9, 0.9, 0.2, 0.2]
00210                 legendloc -- legend location on the axes (0-10)
00211                            options: (integer) 0 -10 
00212                                     see help of "sd.plotter.set_legend" for 
00213                                     the detail of location. Note that 0 ('best')
00214                                     is very slow. 
00215                            default: 1 ('upper right')
00216         outfile -- file name for hardcopy output
00217                 options: (str) filename.eps,.ps,.png
00218                 default: '' (no hardcopy)
00219                 example: 'specplot.eps','specplot.png'
00220                 Note this autodetects the format from the suffix (.eps,.ps,.png).
00221         overwrite -- overwrite the output file if already exists
00222                 options: (bool) True,False
00223                 default: False
00224 
00225 
00226         DESCRIPTION:
00227 
00228         Task sdplot displays single-dish spectra, total power,
00229         or pointing direction of input data.
00230         It assumes that the spectra have been calibrated.
00231         It does allow selection of scans, IFs, polarizations, and
00232         some time and channel averaging/smoothing options also,
00233         but does not write out this data.
00234 
00235         This task adds an additional toolbar to Matplotlib plotter. 
00236         See the cookbook for details of its capability.
00237 
00238         *** Data selection ***
00239         This task allows data selection via field name, scan, IF,
00240         polarization and beam IDs. Selection of field allows pattern
00241         matching using asterisk, e.g., 'FLS3a*'. Selection of scans,
00242         IFs, polarizations, and beams, is possible either by a list
00243         of IDs or by a CASA type selection syntax using a string of 
00244         comma separated numbers with operaters, i.e., '~', '>', '>=',
00245         '<', and '<='.
00246         For example, the following two selections are equivalent:
00247         scanlist = [0, 1, 2, 7, 8, 9, 15]
00248         scanlist = "<3,7~9,15"
00249 
00250         *** control of plot lines in 'spectra' and 'grid' plottype ***
00251         Note that colormap and linestyles cannot be controlled at a time.
00252         The 'linestyles' is ignored if both of them are specified.
00253         Some plot options, like changing titles, legends, fonts,
00254         and the like are not supported in this task.  You should use
00255         sd.plotter from the ASAP toolkit directly for this.
00256 
00257         *** available plottypes ***
00258         * plottype = 'spectra' plots single dish spectra. Multiple scans,
00259           IFs, polarizations, and beams can be handles through stacking
00260           and panelling.
00261           This task uses the JPL line catalog as supplied by ASAP.
00262           If you wish to use a different catalog, or have it plot
00263           the line IDs from top or bottom (rather than alternating),
00264           then you will need to explore the sd toolkit also.
00265         * plottype = 'grid' plots spectra based on their pointing direction.
00266           The spectra are gridded by direction before plotting.
00267           Multiple IFs and polarizations are not handled in this mode. Only
00268           the first IF and polarizaion is gridded and plotted if data 
00269           includes multiple IDs after selections are applied. Hence, over
00270           plotting is not available
00271 
00272         Currently most of the parameters are ignored in the following modes.
00273 
00274         * plottype='totalpower' is used to plot the total power data.
00275           and only plot option is amplitude versus data row number.
00276         * plottype='azel' plots azimuth and elevation tracks of the source.
00277         * plottype='pointing' plots antenna poinitings.
00278 
00279         ASAP recognizes the data of the "AT" telescopes, but currently
00280         does not know about the GBT or any other telescope. This task
00281         does know about GBT. Telescope name is obtained from the data.
00282         If you wish to change the fluxunit (see below), and telescopeparm='',
00283         for the AT telescopes it will use internal telescope parameters for
00284         flux conversion. For GBT, it will use an approximate aperture
00285         efficiency conversion.  If you give telescopeparm a list,
00286         then if the list has a single float it is assumed to
00287         be the gain in Jy/K, if two or more elements they are assumed
00288         to be telescope diameter (m) and aperture efficiency
00289         respectively.
00290 
00291         WARNING: be careful plotting otf data with lots of fields!
00292 
00293         WARNING for the GBT raw SDFITS format data as input:
00294         SDtasks are able to handle GBT raw SDFITS format data since the 
00295         data filler is available. However, the functionality is not well 
00296         tested yet, so that there may be unknown bugs.  
00297 
00298   
00299         """
00300         if type(flrange)==float: flrange=[flrange]
00301         if type(cell)==float: cell=[cell]
00302         if type(margin)==float: margin=[margin]
00303 
00304 #
00305 #    The following is work around to avoid a bug with current python translation
00306 #
00307         mytmp = {}
00308 
00309         mytmp['infile'] = infile
00310         mytmp['antenna'] = antenna
00311         mytmp['fluxunit'] = fluxunit
00312         mytmp['telescopeparm'] = telescopeparm
00313         mytmp['specunit'] = specunit
00314         mytmp['restfreq'] = restfreq
00315         mytmp['frame'] = frame
00316         mytmp['doppler'] = doppler
00317         mytmp['scanlist'] = scanlist
00318         mytmp['field'] = field
00319         mytmp['iflist'] = iflist
00320         mytmp['pollist'] = pollist
00321         mytmp['beamlist'] = beamlist
00322         mytmp['scanaverage'] = scanaverage
00323         mytmp['timeaverage'] = timeaverage
00324         mytmp['tweight'] = tweight
00325         mytmp['polaverage'] = polaverage
00326         mytmp['pweight'] = pweight
00327         mytmp['kernel'] = kernel
00328         mytmp['kwidth'] = kwidth
00329         mytmp['plottype'] = plottype
00330         mytmp['stack'] = stack
00331         mytmp['panel'] = panel
00332         mytmp['flrange'] = flrange
00333         mytmp['sprange'] = sprange
00334         mytmp['linecat'] = linecat
00335         mytmp['linedop'] = linedop
00336         mytmp['subplot'] = subplot
00337         mytmp['colormap'] = colormap
00338         mytmp['linestyles'] = linestyles
00339         mytmp['linewidth'] = linewidth
00340         mytmp['histogram'] = histogram
00341         mytmp['center'] = center
00342         mytmp['cell'] = cell
00343         mytmp['header'] = header
00344         mytmp['headsize'] = headsize
00345         mytmp['plotstyle'] = plotstyle
00346         mytmp['margin'] = margin
00347         mytmp['legendloc'] = legendloc
00348         mytmp['outfile'] = outfile
00349         mytmp['overwrite'] = overwrite
00350         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00351         trec = casac.utils().torecord(pathname+'sdplot.xml')
00352 
00353         casalog.origin('sdplot')
00354         if trec.has_key('sdplot') and casac.utils().verify(mytmp, trec['sdplot']) :
00355             result = task_sdplot.sdplot(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, beamlist, scanaverage, timeaverage, tweight, polaverage, pweight, kernel, kwidth, plottype, stack, panel, flrange, sprange, linecat, linedop, subplot, colormap, linestyles, linewidth, histogram, center, cell, header, headsize, plotstyle, margin, legendloc, outfile, overwrite)
00356 
00357         else :
00358           result = False
00359         return result