Image Import and Export

Reading and writing images between CASA and fits


The exportfits and importfits tasks will allow you to write your CASA image to a FITS file that other packages can read, and to import existing FITS files into CASA as an image.

 

FITS Image Export (exportfits)

To export your images to fits format use the exportfits task. The inputs are:

#  exportfits :: Convert a CASA image to a FITS file
imagename           =         ''        #  Name of input CASA image
fitsimage           =         ''        #  Name of output image FITS file
velocity            =      False        #  Use velocity (rather than frequency)
                                        #   as spectral axis
optical             =      False        #  Use the optical (rather than radio)
                                        #   velocity convention
bitpix              =        -32        #  Bits per pixel
minpix              =          0        #  Minimum pixel value (if minpix >
                                        #   maxpix, value is automatically
                                        #   determined)
maxpix              =         -1        #  Maximum pixel value (if minpix >
                                        #   maxpix, value is automatically
                                        #   determined)
overwrite           =      False        #  Overwrite pre-existing imagename
dropstokes          =      False        #  Drop the Stokes axis?
stokeslast          =       True        #  Put Stokes axis last in header?
history             =       True        #  Write history to the FITS image?
dropdeg             =      False        #  Drop all degenerate axes (e.g. Stokes
                                        #   and/or Frequency)?

The dropstokes or stokeslast parameter may be needed to make the FITS image compatible with an external application.

For example,

exportfits('ngc5921.demo.cleanimg.image','ngc5921.demo.cleanimg.image.fits')

Alert: CASA images typically always keep their spectral axis in frequency units. Velocities are only a secondary mapping of the spectral channels. FITS images, on the other hand, do not allow multiple versions of spectral coordinate systems. exportfits will therefore by default write the spectral axis in frequency units. If velocity units are desired, select velocity=True.

FITS Image Import (importfits)

 You can also use the importfits task to import a FITS image into CASA image table format. Note, the CASA viewer can read fits images so you don’t need to do this if you just want to look at the image. The inputs for importfits are:

#  importfits :: Convert an image FITS file into a CASA image
fitsimage           =         ''        #  Name of input image FITS file
imagename           =         ''        #  Name of output CASA image
whichrep            =          0        #  If fits image has multiple
                                        #   coordinate reps, choose one.
whichhdu            =          0        #  If its file contains
                                        #    multiple images, choose one.
zeroblanks          =       True        #  Set blanked pixels to zero (not NaN)
overwrite           =      False        #  Overwrite pre-existing imagename
defaultaxes         =      False        #  Add the default 4D
                                        #   coordinate axes where they are missing
defaultaxesvalues   =         []        #  List of values to assign to
                                        #   added degenerate axes when
                                        #   defaultaxes=True (ra,dec,freq,stokes)

For example, we can read the above image back in

importfits('ngc5921.demo.cleanimg.image.fits','ngc5921.demo.cleanimage')