NRAO Home > CASA > CASA Cookbook and User Reference Manual

6.6.2 Using masks in immath

The mask parameter is used inside immath to apply a mask to all the images used in expr before calculations are done (if you are curious, it uses the ia.subimage tool method to make virtual images that are then input in the LEL to the ia.imagecalc method).

For example, let’s assume that we have made a single channel image using clean

  vis = ’’  
  imagename = ’ngc5921.demo.chan22.cleanimg’  
  mode = ’channel’  
  nchan = 1  
  start = 22  
  step = 1  
  field = ’’  
  spw = ’’  
  imsize = [256,256]  
  cell = [15.,15.]  
  psfalg = ’clark’  
  gain = 0.1  
  niter = 6000  
  weighting = ’briggs’  
  rmode = ’norm’  
  robust = 0.5  
  mask = [108,108,148,148]  

There is now a file ’ngc5921.demo.chan22.cleanimg.mask’ that is an image with values 1.0 inside the cleanbox region and 0.0 outside.

We can use this to mask the clean image:

  imagename = ’ngc5921.demo.chan22.cleanimg.image’  

Toolbox Tricks: Note that there are also pixel masks that can be contained in each image. These are Boolean masks, and are implicitly used in the calculation for each image in expr. If you want to use the mask in a different image not in expr, try it in mask:

  # First make a pixel mask inside ngc5921.demo.chan22.cleanimg.mask’ngc5921.demo.chan22.cleanimg.mask’)  
  # There is now a ’mask0’ mask in this image as reported by the summary  
  # Now apply this pixel mask in immath  

Note that nominally the axes of the mask must be congruent to the axes of the images in expr. However, one exception is that the image in mask can have fewer axes (but not axes that exist but are of the wrong lengths). In this case immath will extend the missing axes to cover the range in the images in expr. Thus, you can apply a mask made from a single channel to a whole cube.

  # drop degenerate stokes and freq axes from mask image’ngc5921.demo.chan22.cleanimg.mask’)  
  im2 = ia.subimage(outfile=’ngc5921.demo.chan22.cleanimg.mymask’,dropdeg=True)  
  # mymask has only RA and Dec axes  
  # Now apply this mask to the whole cube  

For more on masks as used in LEL, see

or in  6.1.4 above.

More information about CASA may be found at the CASA web page

Copyright 2010 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense

Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search