NRAO Home > CASA > CASA Cookbook and User Reference Manual

6.9 Reordering the Axes of an Image Cube (imtrans)

Sometimes data cubes can be in axis orders that are not adequate for processing. The CASA task imtrans can change the ordering of the axis:

#  imtrans :: Reorder image axes  
imagename           =         ’’        #  Name of the input image  
outfile             =         ’’        #  Name of output CASA image.  
order               =         ’’        #  New zero-based axes order.  
wantreturn          =       True        #  Return an image tool referencing the  
                                        #   transposed image  
async               =      False        #  If true the taskname must be started  
                                        #   using imtrans(...)

The order parameter is the most important input here. It is a string of numbers that shows how axes 0, 1, 2, 3, ... are mapped onto the new cube (note that the first axis has the label 0, as typical in python). E.g.order=’1032’ will reorder the input axis 0 to be axis 1 in the output, input axis 1 to be output axis 0, input axis 2 to output axis 3 (the last axis) and input axis 3 to output axis 2. Alternatively, axes can be specified by their names. E.g., to reorder an image with right ascension, declination, and frequency and reverse the first two, order=[‘‘declination’’, ‘‘right ascension’’, ‘‘frequency’’] will work. The axes names can be found typing (ia.coordsys().names()). Minimum match is supported, so that order=["d", "f", "r"] will produce the same results.

Axes can simultaneously be transposed and reversed. To reverse an axis, precede it by a ”-”. For example, order=’-10-32’ will reverse the direction of the first and third axis of the input image (the zeroth and second axes in the output image).

Example:

Swap the stokes and spectral axes in an RA-Dec-Stokes-Frequency image

imagename = "myim.im"  
outfile = "outim.im"  
order = "0132"  
imtrans()

or

outfile = "myim_2.im"  
order = 132  
imtrans()

or

outfile = "myim_3.im"  
order = ["r", "d", "f", "s"]  
imtrans()

or

outfile = "myim_4.im"  
order = ["rig", "declin", "frequ", "stok"]  
imtrans()

If the outfile parameter is empty, only a temporary image is created; no output image is written to disk. The temporary image can be captured in the returned value (assuming wantreturn is true).


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