CASA EVLA Scripts: Difference between revisions

From CASA Guides
Jump to navigationJump to search
No edit summary
No edit summary
 
(32 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:EVLA]]
[[Category:EVLA]]


== Temporary edit link ==
[http://casaguides.nrao.edu/index.php?title=CASA_EVLA_Scripts&action=edit edit me in CASA Guides]


== Overview ==
== Overview ==


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 nrao.edu).
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 Juergen Ott (jott at nrao.edu).


== Plotting the weather table, obtaining observation-specific opacity information ==
== Plotting the weather table, obtaining observation-specific opacity information ==


[[Image:PlotWX.png|200px|thumb|right|plotWX weather table figure]]
[[Image:PlotWX.png|200px|thumb|right|plotWX weather table figure]]
<span style="color:#FF0000"> NOTE: A revised version of this method is now available in the CASA task 'plotweather'.  Please use the new task for calibration purposes.  </span>


Download script: [[File:Script_plotWX.py]]
Download script: [[File:Script_plotWX.py]]


This script will plot weather table information in the MS (see example below) as well as return a list of estimated zenith opacity values for each spectral window.
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' + nrao.edu) 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:
#place Script_plotWX.py in your working directory
#open Script_plotWX.py in a text editor
#edit the last line of the script, replacing MSname.ms with the name of your measurement set, and save
#in CASA, execute the script:
 
 
<source lang="python">
# In CASA
execfile 'Script_plotWX.py'
</source>
 
 
Or, this script can be run within CASA as a function:
#place Script_plotWX.py in your working directory
#in CASA, import the function definition and call the function, replacing MSname.ms with the name of your measurement set:
 


<source lang="python">
<source lang="python">
# In CASA
# In CASA
from Script_plotWX import plotWX
from Script_plotWX import plotWX
myTau = plotwx('myVis.ms')
myTau = plotWX('MSname.ms')
</source>
</source>


== Importing, listing, plotting, and applying online flags ==
== Mosaicking Utilities ==
 
'''User beware: these are tested but not thoroughly vetted scripts provided without any guarantee.'''
 
* Download script: [[File:buildmosaic.py]]
* Download script: [[File:buildfluxmap.py]]
* Download supporting module: [[File:axisutils.py]]
* Download supporting module: [[File:constutils.py]]
* Download supporting module: [[File:geoutils.py]]


[[Image:PlotFlags.png|200px|thumb|right|plotflags figure]]
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.  


Download script: [[File:Readflags.py]]
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.


This script reads the Flags.xml table in the SDM directory, and parses the online antenna flags so that they can be listed, plotted, and applied to the MS.  Note that the <tt>tbuff</tt> parameter is a padding value (in seconds) for creating the flag time ranges.
The scripts are documented - please poke around to see more about the methodology or input parameters.


Here, flags are read in and listed, then plotted and applied. The plot file is saved to a file for future reference.
=== buildmosaic ===
 
[[Image:Ds9_m31_1.png|200px|thumb|right|ds9 region output of "buildmosaic" overlaid on M31 IR map.]]
[[Image:M31_mask.png|200px|thumb|right|CASA viewer image of the mask "mask_m31.im" 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 "buildmosaic.py", "axisutils.py", "constutils.py", and "geoutils.py" all sit in your casapy path (the easiest way to do this is to just drop them into your working directory). Then type
 
<source lang="python">
# In CASA
from buildmosaic import buildmosaic
</source>
 
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:


<source lang="python">
<source lang="python">
# In CASA
# In CASA
from Readflags import listflags, readflags, plotflags, useflags
m31_dir = "00h42m44.3s +41d16m09s"
myFlags = readflags('mySDMfile', tbuff=1.5)
buildmosaic(direction=m31_dir,
listflags(myFlags)
              format="evlapst",
plotflags(myFlags)
              outfile="m31.pst",
pl.savefig('mySDMfile_onlineFlags.png')
              overwrite=True,
useflags('myVis.ms', myFlags)
              freq=2.0e9,
              diam=25.0,
              posang=12.0,
              beamspacing=0.5,
              calcspacing=True,
              maxrad=10.0,
              mask="mask_m31.im",
              sourceroot="M31FIELD_",
              groupname="M31MOSAIC")
</source>
</source>


== Listing observation information directly from the SDM files ==
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 "buildmosaic.py" to see the other options that can be passed to a text file (a ds9 tag, velocity frame, etc.).


Download script: [[File:List_sdm.py]]
=== buildfluxmap ===


This script lists information directly from the SDM directory's XML tables and prints this information to the CASA log.  Formatting is similar to the task {{listobs}}; however, list_sdm is much faster for larger datasets, and can be run before (or while) importing to an MS.
[[Image:m31_snr.png|200px|thumb|right|CASA viewer image of predicted signal-to-noise map of above mosaic.]]


It will also return a dictionary keyed on scan number. The dictionary contains the following information, which can be useful for scan selection prior to import:
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.


        'baseband'  list of baseband name(s)
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.
        'chanwidth'  list of channel widths (Hz)
        'end'        observation end time (UTC)
        'field'      field ID
        'intent'    scan intent(s)
        'nchan'      list of number of channels
        'nsubs'      number of subscans
        'reffreq'    list of reference frequencies (Hz)
        'source'    source name
        'spws'      list of spectral windows
        'start'      observation start time (UTC)
        'timerange'  start time - end time range (UTC)


<source lang="python">
<source lang="python">
# In CASA
# In CASA
from List_sdm import list_sdm
from buildfluxmap import buildfluxmap
myScanDict = list_sdm('mySDMfile')
buildfluxmap(ptgfile="m31_ds9.reg",
                template="mask_m31.im",
                outfile="snr_m31.im",
                freq=1.5e9,
                diam=25.0,
                overwrite=True)
</source>
</source>


Representative log output:
== 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 script: [[File:alignbyvel.xml]]
* Download script: [[File:alignbyvel.py]]
* Download script: [[File:task_alignbyvel.py]]


<pre style="background-color: #ffe4b5;">
Download these scripts and follow the "buildmytasks" procedure described in the CASA Cookbook [http://casa.nrao.edu/docs/UserMan/UserManap7.html | here]. You can also access the functionality in python directly by importing task_alignbyvel.py.
2011-01-02 02:26:32 INFO listsdm ================================================================================
2011-01-02 02:26:32 INFO listsdm   SDM File: AS1039_sb1382796_2_000.55368.51883247685
2011-01-02 02:26:32 INFO listsdm ================================================================================
2011-01-02 02:26:32 INFO listsdm   Observer: Michael P. Rupen
2011-01-02 02:26:32 INFO listsdm   Facility: EVLA, D-configuration
2011-01-02 02:26:32 INFO listsdm       Observed from 2010/06/21/12:27:08.17 to 2010/06/21/13:26:55.70 (UTC)
2011-01-02 02:26:32 INFO listsdm       Total integration time = 3587.53 seconds (1.00 hours)
2011-01-02 02:26:32 INFO listsdm
2011-01-02 02:26:32 INFO listsdm Scan listing:
2011-01-02 02:26:32 INFO listsdm   Timerange (UTC)          Scan FldID  FieldName      SpwIDs        Intent(s)
2011-01-02 02:26:32 INFO listsdm   12:27:08.17 - 12:28:05.36    1    0  J2038+5119      [0, 1]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   12:28:05.36 - 12:29:05.20    2    0  J2038+5119      [2, 3]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   12:29:05.20 - 12:30:05.04    3    0  J2038+5119      [0, 1]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   12:30:05.04 - 12:36:04.05    4    1  V407 Cyg+4amin  [0, 1]  OBSERVE_TARGET
2011-01-02 02:26:32 INFO listsdm   12:36:04.05 - 12:37:23.83    5    0  J2038+5119      [0, 1]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   12:37:23.83 - 12:50:21.71    6    1  V407 Cyg+4amin  [0, 1]  OBSERVE_TARGET
2011-01-02 02:26:32 INFO listsdm   12:50:21.71 - 12:51:41.49    7    0  J2038+5119      [0, 1]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   12:51:41.49 - 12:53:01.27    8    2  J2048+4310      [2, 3]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   12:53:01.27 - 12:59:00.29    9    3  V407 Cyg+1amin  [2, 3]  OBSERVE_TARGET
2011-01-02 02:26:32 INFO listsdm   12:59:00.29 - 13:00:20.07  10    2  J2048+4310      [2, 3]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   13:00:20.07 - 13:06:19.08  11    3  V407 Cyg+1amin  [2, 3]  OBSERVE_TARGET
2011-01-02 02:26:32 INFO listsdm   13:06:19.08 - 13:07:38.86  12    2  J2048+4310      [2, 3]  CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   13:07:38.86 - 13:13:37.88  13    3  V407 Cyg+1amin  [2, 3]  OBSERVE_TARGET
2011-01-02 02:26:32 INFO listsdm   13:13:37.88 - 13:14:57.66  14    2  J2048+4310      [2, 3] CALIBRATE_PHASE
2011-01-02 02:26:32 INFO listsdm   13:14:57.66 - 13:19:56.84  15    4  J0137+3309      [0, 1]  CALIBRATE_PHASE UNSPECIFIED CALIBRATE_BANDPASS CALIBRATE_AMPLI
2011-01-02 02:26:32 INFO listsdm   13:19:56.84 - 13:21:56.52  16    4  J0137+3309      [2, 3]  CALIBRATE_PHASE UNSPECIFIED CALIBRATE_BANDPASS CALIBRATE_AMPLI
2011-01-02 02:26:32 INFO listsdm   13:21:56.52 - 13:24:56.02  17    5  J0319+4130      [0, 1]  CALIBRATE_PHASE CALIBRATE_BANDPASS UNSPECIFIED
2011-01-02 02:26:32 INFO listsdm   13:24:56.02 - 13:26:55.70  18    5  J0319+4130      [2, 3]  CALIBRATE_PHASE CALIBRATE_BANDPASS UNSPECIFIED
2011-01-02 02:26:32 INFO listsdm
2011-01-02 02:26:32 INFO listsdm Spectral window information:
2011-01-02 02:26:32 INFO listsdm   SpwID  #Chans  Ch0(MHz)  ChWidth(kHz) TotBW(MHz)  Baseband
2011-01-02 02:26:32 INFO listsdm   0      64      1388.0    2000.0      128.0      BB_4   
2011-01-02 02:26:32 INFO listsdm   1      64      1756.0    2000.0      128.0      BB_8   
2011-01-02 02:26:32 INFO listsdm   2      64      4736.0    2000.0      128.0      BB_4   
2011-01-02 02:26:32 INFO listsdm   3      64      7836.0    2000.0      128.0      BB_8   
2011-01-02 02:26:32 INFO listsdm
2011-01-02 02:26:32 INFO listsdm Field information:
2011-01-02 02:26:32 INFO listsdm   FldID  Code  Name            RA            Dec            SrcID
2011-01-02 02:26:32 INFO listsdm   0      D      J2038+5119      20:38:37.03  +051.19.12.663  0   
2011-01-02 02:26:32 INFO listsdm   1      NONE  V407 Cyg+4amin  21:02:09.80  +045.50.32.980  1   
2011-01-02 02:26:32 INFO listsdm   2      D      J2048+4310      20:48:19.53  +043.10.42.073  2   
2011-01-02 02:26:32 INFO listsdm   3      NONE  V407 Cyg+1amin  21:02:09.80  +045.47.32.980  3   
2011-01-02 02:26:32 INFO listsdm   4      Z      J0137+3309      01:37:41.30  +033.09.35.133  4   
2011-01-02 02:26:32 INFO listsdm   5      Z      J0319+4130      03:19:48.16  +041.30.42.103  5   
2011-01-02 02:26:32 INFO listsdm
2011-01-02 02:26:32 INFO listsdm Antennas (26):
2011-01-02 02:26:32 INFO listsdm   ID    Name  Station  Diam.(m)  Lat.          Long.
2011-01-02 02:26:32 INFO listsdm   0    ea01  W09      25.0      +000.00.00.0  +000.00.00.0
2011-01-02 02:26:32 INFO listsdm   1    ea02  E02      25.0      +033.53.51.0  -107.37.25.2
2011-01-02 02:26:32 INFO listsdm   2    ea03  E09      25.0      +033.54.01.1  -107.37.04.4
2011-01-02 02:26:32 INFO listsdm   3    ea04  W01      25.0      +033.53.53.6  -107.36.45.1
2011-01-02 02:26:32 INFO listsdm   4    ea05  W08      25.0      +033.54.00.5  -107.37.05.9
2011-01-02 02:26:32 INFO listsdm   5    ea08  N01      25.0      +033.53.53.0  -107.37.21.6
2011-01-02 02:26:32 INFO listsdm   6    ea09  E06      25.0      +033.54.01.8  -107.37.06.0
2011-01-02 02:26:32 INFO listsdm   7    ea10  N03      25.0      +033.53.57.7  -107.36.55.6
2011-01-02 02:26:32 INFO listsdm   8    ea11  E04      25.0      +033.54.04.8  -107.37.06.3
2011-01-02 02:26:32 INFO listsdm   9    ea12  E08      25.0      +033.53.59.7  -107.37.00.8
2011-01-02 02:26:32 INFO listsdm   10    ea13  N07      25.0      +033.53.55.1  -107.36.48.9
2011-01-02 02:26:32 INFO listsdm   11    ea14  E05      25.0      +033.54.12.9  -107.37.07.2
2011-01-02 02:26:32 INFO listsdm   12    ea15  W06      25.0      +033.53.58.8  -107.36.58.4
2011-01-02 02:26:32 INFO listsdm   13    ea16  W02      25.0      +033.53.56.4  -107.37.15.6
2011-01-02 02:26:32 INFO listsdm   14    ea17  W07      25.0      +033.54.00.9  -107.37.07.5
2011-01-02 02:26:32 INFO listsdm   15    ea18  N09      25.0      +033.53.54.8  -107.37.18.4
2011-01-02 02:26:32 INFO listsdm   16    ea19  W04      25.0      +033.54.19.0  -107.37.07.8
2011-01-02 02:26:32 INFO listsdm   17    ea20  N05      25.0      +033.53.59.1  -107.37.10.8
2011-01-02 02:26:32 INFO listsdm   18    ea21  E01      25.0      +033.54.08.0  -107.37.06.7
2011-01-02 02:26:32 INFO listsdm   19    ea22  N04      25.0      +033.53.59.2  -107.37.05.7
2011-01-02 02:26:32 INFO listsdm   20    ea23  E07      25.0      +033.54.06.1  -107.37.06.5
2011-01-02 02:26:32 INFO listsdm   21    ea24  W05      25.0      +033.53.56.5  -107.36.52.4
2011-01-02 02:26:32 INFO listsdm   22    ea25  N02      25.0      +033.53.57.8  -107.37.13.0
2011-01-02 02:26:32 INFO listsdm   23    ea26  W03      25.0      +033.54.03.5  -107.37.06.2
2011-01-02 02:26:32 INFO listsdm   24    ea27  E03      25.0      +033.54.00.1  -107.37.08.9
2011-01-02 02:26:32 INFO listsdm   25    ea28  N08      25.0      +033.54.00.5  -107.37.02.8
</pre>


An entry from the scan dictionary:
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:


<pre style="background-color: #ffe4b5;">
<source lang="python">
CASA <16>: myScanDict
# In CASA
  Out[16]:
CN_im = 'n3256_CNlo.im/'
{1: {'baseband': ['BB_4', 'BB_8'],
CO_im = 'n3256_CO.im/'
    'chanwidth': [2000000.0, 2000000.0],
out = 'n3256_CNlo_to_CO.im/'
    'end': '2010/06/21/12:28:05.36',
alignbyvel(infile=CN_im,
    'field': 0,
          outfile=out,
    'intent': 'CALIBRATE_PHASE',
          template=CO_im,
    'nchan': [64, 64],
          overwrite=True)
    'nsubs': 1,
</source>
    'reffreq': [1388000000.0, 1756000000.0],
    'source': 'J2038+5119',
    'spws': [0, 1],
    'start': '2010/06/21/12:27:08.17',
    'timerange': '2010/06/21/12:27:08.17~2010/06/21/12:28:05.36'},
</pre>

Latest revision as of 11:40, 26 July 2013


Overview

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 Juergen Ott (jott at nrao.edu).

Plotting the weather table, obtaining observation-specific opacity information

plotWX weather table figure

NOTE: A revised version of this method is now available in the CASA task 'plotweather'. Please use the new task for calibration purposes.

Download script: File:Script plotWX.py

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' + nrao.edu) 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 Script_plotWX.py in your working directory
  2. open Script_plotWX.py in a text editor
  3. edit the last line of the script, replacing MSname.ms with the name of your measurement set, and save
  4. in CASA, execute the script:


# In CASA
execfile 'Script_plotWX.py'


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

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


# In CASA
from Script_plotWX import plotWX
myTau = plotWX('MSname.ms')

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.

buildmosaic

ds9 region output of "buildmosaic" overlaid on M31 IR map.
CASA viewer image of the mask "mask_m31.im" 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 "buildmosaic.py", "axisutils.py", "constutils.py", and "geoutils.py" all sit in your casapy path (the easiest way to do this is to just drop them into your working directory). Then type

# In CASA
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:

# In CASA
m31_dir = "00h42m44.3s +41d16m09s"
buildmosaic(direction=m31_dir,
               format="evlapst",
               outfile="m31.pst",
               overwrite=True,
               freq=2.0e9, 
               diam=25.0, 
               posang=12.0,
               beamspacing=0.5,
               calcspacing=True,
               maxrad=10.0,
               mask="mask_m31.im",
               sourceroot="M31FIELD_",
               groupname="M31MOSAIC")

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 "buildmosaic.py" to see the other options that can be passed to a text file (a ds9 tag, velocity frame, etc.).

buildfluxmap

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.

# In CASA
from buildfluxmap import buildfluxmap
buildfluxmap(ptgfile="m31_ds9.reg",
                template="mask_m31.im",
                outfile="snr_m31.im",
                freq=1.5e9,
                diam=25.0,
                overwrite=True)

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 task_alignbyvel.py.

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:

# In CASA
CN_im = 'n3256_CNlo.im/'
CO_im = 'n3256_CO.im/'
out = 'n3256_CNlo_to_CO.im/'
alignbyvel(infile=CN_im,
           outfile=out,
           template=CO_im,
           overwrite=True)