NRAO Home > CASA > CASA Cookbook and User Reference Manual

6.23 Using the CASA Toolkit for Image Analysis

Inside the Toolkit:
The image analysis tool (ia) is the workhorse here. It appears in the User Reference Manual as the image tool. Other relevant tools for analysis and manipulation include measures (me), quanta (qa) and coordsys (cs).

Although this cookbook is aimed at general users employing the tasks, we include here a more detailed description of doing image analysis in the CASA toolkit. This is because there are currently only a few tasks geared towards image analysis, as well as due to the breadth of possible manipulations that the toolkit allows that more sophisticated users will appreciate.

To see a list of the ia methods available, use the CASA help command:

CASA <1>: help ia  
--------> help(ia)  
Help on image object:  
 
class image(__builtin__.object)  
 |  image object  
 |  
 |  Methods defined here:  
 |  
 |  __init__(...)  
 |      x.__init__(...) initializes x; see x.__class__.__doc__ for signature  
 |  
 |  __str__(...)  
 |      x.__str__() <==> str(x)  
 |  
 |  adddegaxes(...)  
 |      Add degenerate axes of the specified type to the image‘  :  
 |        outfile  
 |        direction = false  
 |        spectral  = false  
 |        stokes  
 |        linear    = false  
 |        tabular   = false  
 |        overwrite = false  
 |      ----------------------------------------  
 |  
 |  addnoise(...)  
 
...  
 
 |  
 |  unlock(...)  
 |      Release any lock on the image‘  :  
 |      ----------------------------------------  
 |  
 |  ----------------------------------------------------------------------  
 |  Data and other attributes defined here:  
 |  
 |  __new__ = <built-in method __new__ of type object at 0x55d0f20>  
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T  

or for a compact listing use <TAB> completion on ia., e.g.

CASA <5>: ia.  
Display all 105 possibilities? (y or n)  
ia.__class__                ia.deconvolvecomponentlist  ia.ispersistent             ia.reorder  
ia.__delattr__              ia.deconvolvefrombeam       ia.lock                     ia.replacemaskedpixels  
ia.__doc__                  ia.done                     ia.makearray                ia.restoringbeam  
ia.__getattribute__         ia.echo                     ia.makecomplex              ia.rotate  
ia.__hash__                 ia.fft                      ia.maketestimage            ia.sepconvolve  
ia.__init__                 ia.findsources              ia.maskhandler              ia.set  
ia.__new__                  ia.fitallprofiles           ia.maxfit                   ia.setboxregion  
ia.__reduce__               ia.fitcomponents            ia.miscinfo                 ia.setbrightnessunit  
ia.__reduce_ex__            ia.fitpolynomial            ia.modify                   ia.setcoordsys  
ia.__repr__                 ia.fitprofile               ia.moments                  ia.sethistory  
ia.__setattr__              ia.fromarray                ia.name                     ia.setmiscinfo  
ia.__str__                  ia.fromascii                ia.newimage                 ia.setrestoringbeam  
ia.adddegaxes               ia.fromfits                 ia.newimagefromarray        ia.shape  
ia.addnoise                 ia.fromimage                ia.newimagefromfile         ia.statistics  
ia.boundingbox              ia.fromrecord               ia.newimagefromfits         ia.subimage  
ia.brightnessunit           ia.fromshape                ia.newimagefromimage        ia.summary  
ia.calc                     ia.getchunk                 ia.newimagefromshape        ia.toASCII  
ia.calcmask                 ia.getregion                ia.open                     ia.tofits  
ia.close                    ia.getslice                 ia.outputvariant            ia.topixel  
ia.collapse                 ia.hanning                  ia.pixelvalue               ia.torecord  
ia.continuumsub             ia.haslock                  ia.putchunk                 ia.toworld  
ia.convertflux              ia.histograms               ia.putregion                ia.twopointcorrelation  
ia.convolve                 ia.history                  ia.rebin                    ia.type  
ia.convolve2d               ia.imagecalc                ia.regrid                   ia.unlock  
ia.coordmeasures            ia.imageconcat              ia.remove  
ia.coordsys                 ia.insert                   ia.removefile  
ia.decompose                ia.isopen                   ia.rename

A common use of the ia tool is to do region statistics on an image. The imhead task has mode=’stats’ to do this quickly over the entire image cube. The tool can do this on specific planes or sub-regions. Here is an example on how to use the ia tool to get on-source and off-source statistics:

# The variable clnimage points to the clean image name  
 
# Pull the max and rms from the clean image  
ia.open(clnimage)  
on_statistics=ia.statistics()  
thistest_immax=on_statistics[’max’][0]  
oldtest_immax = 1.07732224464  
print ’ Clean image ON-SRC max should be ’,oldtest_immax  
print ’ Found : Max in image = ’,thistest_immax  
diff_immax = abs((oldtest_immax-thistest_immax)/oldtest_immax)  
print ’ Difference (fractional) = ’,diff_immax  
 
print ’’  
# Now do stats in the lower right corner of the image  
box = ia.setboxregion([0.75,0.00],[1.00,0.25],frac=true)  
off_statistics=ia.statistics(region=box)  
thistest_imrms=off_statistics[’rms’][0]  
oldtest_imrms = 0.0010449  
print ’ Clean image OFF-SRC rms should be ’,oldtest_imrms  
print ’ Found : rms in image = ’,thistest_imrms  
diff_imrms = abs((oldtest_imrms-thistest_imrms)/oldtest_imrms)  
print ’ Difference (fractional) = ’,diff_imrms  
 
print ’’  
print ’ Final Clean image Dynamic Range = ’,thistest_immax/thistest_imrms  
print ’’  
print ’ =============== ’  
 
ia.close()  

Note: If you don’t close the file with, e.g., ia.close() the file will stay in a ’locked’ state. Other processes won’t be able to access the file until the file is properly closed.


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