NRAO Home > CASA > CASA Cookbook and User Reference Manual
6.5.1.1 Simple math

Select a single plane (channel 22) of the 3-D cube and subtract it from the original image:

  immath(imagename=’ngc5921.demo.cleanimg.image’,  
         expr=’IM0’,chans=’22’,  
         outfile=’ngc5921.demo.chan22.image’)

Double all values in our image:

  immath(imagename=[’ngc5921.demo.chan22.image’],  
         expr=’IM0*2.0’,  
         outfile=’ngc5921.demo.chan22double.image’ )

Square all values in our image:

  immath(imagename=[’ngc5921.demo.chan22.image’],  
         expr=’IM0^2’,  
         outfile=’ngc5921.demo.chan22squared.image’ )

Note that the units in the output image are still claimed to be “Jy/beam”, ie. immath will not correctly scale the units in the image for non-linear cases like this. Beware.

You can do other mathematical operations on an image (e.g. trigonometric functions) as well as use scalars results from an image (e.g. max, min, median, mean, variance). You also have access to constants such as e() and pi() (which are doubles internally, while most images are floats). For example: Take the sine of an image:

  immath(imagename=[’ngc5921.demo.chan22.image’,’ngc5921.demo.chan22squared.image’],  
         expr=’sin(float(pi())*IM0/sqrt(max(IM1)))’,  
         outfile=’ngc5921.demo.chan22sine.image’)

Note again that the units are again kept as they were.

Select a single plane (channel 22) of the 3-D cube and subtract it from the original image:

  immath(imagename=’ngc5921.demo.cleanimg.image’,  
         expr=’IM0’,chans=’22’,  
         outfile=’ngc5921.demo.chan22.image’)  
 
  immath(imagename=[’ngc5921.demo.cleanimg.image’,’ngc5921.demo.chan22.image’],  
         expr=’IM0-IM1’,  
         outfile=’ngc5921.demo.sub22.image’)

Note that in this example the 2-D plane gets extended in the third dimension and the 2-D values are applied to each plane in the 3-D cube.

Select and save the inner 1/4 of an image for channels 40,42,44 as well as channels 10 and below:

   default(’immath’)  
   imagename=[’ngc5921.demo.cleanimg.image’]  
   expr=’IM0’  
   region=’box[[64pix,64pix],[192pix,192pix]]’  
   chans=’<10;40,42,44’  
   outfile=’ngc5921.demo.inner.image’  
   immath()

ALERT: Note that if chan selects more than one channel then the output image has a number of channels given by the span from the lowest and highest channel selected in chan. In the example above, it will have 45 channels. The ones not selected will be masked in the output cube. If we had set

   chans = ’40,42,44’

then there would be 5 output channels corresponding to channels 40,41,42,43,44 of the MS with 41,43 masked. Also, the chans=’<10’ selects channels 0–9.

Note that the chans syntax allows the operators ’<’, ’<=’, ’>’, ’>’. For example,

   chans = ’<17,>79’  
   chans = ’<=16,>=80’

do the same thing.

Divide an image by another, with a threshold on one of the images:

  immath(imagename=[’ngc5921.demo.cleanimg.image’,’ngc5921.demo.chan22.image’],  
         expr=’IM0/IM1[IM1>0.008]’,  
         outfile=’ngc5921.demo.div22.image’)


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