NRAO Home > CASA > CASA Cookbook and User Reference Manual

6.5.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, lets assume that we have made a single channel image using clean for the NGC5921 data (see Appendix F.1).

  default(’clean’)  
 
  vis = ’ngc5921.demo.src.split.ms.contsub’  
  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  
  threshold=’8.0mJy’  
  weighting = ’briggs’  
  rmode = ’norm’  
  robust = 0.5  
 
  mask = [108,108,148,148]  
 
  clean()

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:

  default(’immath’)  
  imagename = ’ngc5921.demo.chan22.cleanimg.image’  
  expr=’IM0’  
  mask=’"ngc5921.demo.chan22.cleanimg.mask">0.5’  
  outfile=’ngc5921.demo.chan22.cleanimg.imasked’  
  immath()

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  
  ia.open(’ngc5921.demo.chan22.cleanimg.mask’)  
  ia.calcmask(’"ngc5921.demo.chan22.cleanimg.mask">0.5’)  
  ia.summary()  
  ia.close()  
  # There is now a ’mask0’ mask in this image as reported by the summary  
 
  # Now apply this pixel mask in immath  
  default(’immath’)  
  imagename=’ngc5921.demo.chan22.cleanimg.image’  
  expr=’IM0’  
  mask=’mask(ngc5921.demo.chan22.cleanimg.mask)’  
  outfile=’ngc5921.demo.chan22.cleanimg.imasked1’  
  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  
  ia.open(’ngc5921.demo.chan22.cleanimg.mask’)  
  im2 = ia.subimage(outfile=’ngc5921.demo.chan22.cleanimg.mymask’,dropdeg=True)  
  im2.summary()  
  im2.close()  
  ia.close()  
  # mymask has only RA and Dec axes  
 
  # Now apply this mask to the whole cube  
  default(’immath’)  
  imagename=’ngc5921.demo.cleanimg.image’  
  expr=’IM0’  
  mask=’"ngc5921.demo.chan22.cleanimg.mymask">0.5’  
  outfile=’ngc5921.demo.cleanimg.imasked’  
  immath()

For more on masks as used in LEL, see

http://aips2.nrao.edu/docs/notes/223/223.html

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