From CASA Guides
Jump to navigationJump to search


This is a collection of Python scripts to help process and analyze EVLA data. Although they are not officially supported, some authors may choose to provide contact information. A brief description on how to run each script is provided by the author. If you would like to contribute, and do not have access to the CASA Guides Wiki, you may email Miriam Krauss (mkrauss at

Plotting the weather table, obtaining observation-specific opacity information

plotWX weather table figure

Download script: File:Script

This script will plot weather information contained in the MS (see example below) as well as estimate the zenith opacity for each spectral window. This script is only intended for use with the EVLA-- it contains hardcoded site parameters and EVLA-specific models. Feel free to contact Josh Marvil (jmarvil + 'at' + with questions or comments.

The plot will contain the following subfigures:

  • The Sun's elevation, calculated from the date and time of the observation
  • Wind speed and direction, as read from the weather table
  • Temperature and Dewpoint, as read from the weather table
  • Estimates of Precipitable Water Vapor (PWV), based upon:
    • A Seasonal model based on VLA measurements between 1998-2005 (See VLA Test Memo #232)
    • A calculation involving temperature and dewpoint (See VLA Scientific Memo #176)
    • The average of the above two methods (currently accepted as the best predictor)
  • Zenith optical depth from 1-50 GHz, calculated for each of the above three estimates of PWV, averaged over time. This calculation uses the atmospheric toolkit available within casa (see help(at) within CASA for more info)

This can be run from within CASA as a Script in the following way:

  1. place in your working directory
  2. open in a text editor
  3. edit the last line of the script, replacing with the name of your measurement set, and save
  4. in CASA, execute the script:

execfile ''

Or, this script can be run within CASA as a function:

  1. place in your working directory
  2. in CASA, import the function definition and call the function, replacing with the name of your measurement set:

from Script_plotWX import plotWX
myTau = plotWX('')

Mosaicking Utilities

User beware: these are tested but not thoroughly vetted scripts provided without any guarantee.

These are two potentially useful scripts ("buildmosaic" and "buildfluxmap") to aid in mosaic planning. A full-fledged GUI mosaic tool is under development by EVLA staff and RSRO participants but in the meantime these may be useful. They have been used but not heavily tested - please email aleroy at nrao dot edu to suggest improvements or report bugs.

In fact an email to report use would be appreciated, if people actually use these I can simplify the dependencies (put everything in one file), wrap them up in the XML for a task, and strengthen the error-checking.

The scripts are documented - please poke around to see more about the methodology or input parameters.


ds9 region output of "buildmosaic" overlaid on M31 IR map.
CASA viewer image of the mask "" used to constrain the above mosaic.

"buildmosaic" allows users to specify a hexagonally packed mosaic and then outputs this mosaic as a text file in one of three formats: EVLA proposal submission tool, simdata pointing file, or ds9 region file. "buildmosaic" is a python routine. To use it, make sure that "", "", "", and "" all sit in your casapy path (the easiest way to do this is to just drop them into your working directory). Then type

from buildmosaic import buildmosaic

then you can call "buildmosaic". Our test example was to build a large 2 GHz mosaic of M31 and the syntax we used to build this was something like this:

m31_dir = "00h42m44.3s +41d16m09s"

This long list of parameters tells "buildmosaic" how to build a hexagonally sampled mosaic - the center, spacing, orientation, and maximum extent - potentially subject to some spatial mask (an image of 1s and 0s, "buildmosaic" keeps only points coincident with a 1) and how to output the data to a text file.

The options to specify the mosaic itself are:

  • "direction" specifies the center of the mosaic as a string.
  • "mask" supplies an optional CASA image containing only 1s and 0s. Only pointings inside the mask are kept (this is an important feature!).
  • "calcspacing" asks the program to calculate the spacing between mosaic points from the frequency and diameter of the telescope.
    • "freq" gives the observing frequency in Hz (used to calculate the primary beam).
    • "diam" gives the diameter of the telescope.
    • "beamspacing" dictates the spacing of pointing centers in units of the FWHM of the primary beam.
  • "spacing_deg" specifies the spacing in degrees (if you don't use "calcspacing").
  • "posang" tilts the hexagonal pattern by this position angle.
  • "maxrad" gives the maximum distance from the center (in degrees) for a pointing to be considered.

The ouput file is specified by

  • "outfile" specifies the text file output.
    • "overwrite" the file if present?
    • "format" specifies the output format ("evlapst", "simdata", or "ds9") of the output file.
    • "sourceroot", "groupname", etc. just feed to the output (specifically when using the PST format). Experiment to see these in use and have a look inside "" to see the other options that can be passed to a text file (a ds9 tag, velocity frame, etc.).


CASA viewer image of predicted signal-to-noise map of above mosaic.

The second routine provided here gives a rough estimate of the sensitivity of a proposed mosaic. "buildfluxmap" accepts a template astrometry and a proposed mosaic and makes an image proportional to the expected signal-to-noise ratio. It does so by summing the square of the primary beam point by point and taking the square root of the resulting sum (see, e.g., Condon et al. 1998). "buildfluxmap" wants an input of the mosaic in ds9 format - this could be expanded if folks actually use it.

The syntax is to provide it the proposed mosaic "ptgfile", a template image "template" that will be used as the astrometry for the signal to noise file, then to specify the observing frequency "freq" in Hz and telescope diameter "diam" in meters.

from buildfluxmap import buildfluxmap

Align Two Cubes According to their Velocity Axes

Hopefully this will soon be deprecated by core CASA functionality. In the meantime please direct bug notes, suggestions, or just note use to aleroy at nrao dot edu.

This is also planned future functionality for CASA but in the interim users working with multiple transitions or multiple observations of the same transition may find it desirable to align one cube so that its velocity axis matches that of another. This allows one to readily overlay the two cubes in the CASA viewer (which aligns data cubes by their spectral pixel rather than their velocity value).

Download these scripts and follow the "buildmytasks" procedure described in the CASA Cookbook | here. You can also access the functionality in python directly by importing

Once you have the task, simply pick a "template" cube that holds the desired velocity axis, an "infile" that holds the cube to be aligned, and specify an "outfile" to hold the output CASA image file. For example you could align the CN and CO images from the ALMA SV data on NGC 3256 like so:

CN_im = ''
CO_im = ''
out = ''