Chandra X-Ray Observatory
Skip to the navigation links
Last modified: September 2011

Jump to: Description · Examples · Bugs · See Also

AHELP for CIAO 4.9


Context: contrib


Smooth the pixel values in an IMAGE crate (useful for add_image)


smooth_image_crate(crate, type, arguments...)


This routines smoothes the pixel values stored in an image crate. It is useful if you want to display the Crate using add_crate or make_figure, so that the WCS information is retained. If you want to smooth an image and save it to disk it is suggested that the aconvolve tool be used rather than this one.

The smoothing options are given below:

Smoothing routines

type Other parameters Description
gauss sigma, nsigma=5 Smooth with a gaussian; sigma is in pixels and nsigma gives the half-width of the box over which the gaussian should be calculated.
boxcar radius Smooth with a box-car kernel of the given radius (in pixels). This is a square kernel with all pixels set to the same value.
tophat radius Smooth with a top-hat kernel of the given radius (in pixels). This is a circlular kernel where all pixels within the radius are set to the same value and those outside are set to 0.
image kernel, norm=True, origin=None Smooth with the given image (a 2D numpy array). The kernel is normalized by default (each pixel in the kernel is divided by the total signal in the kernel); this can be turned off by setting norm to False. The origin of the kernel is taken to be the image center; to change this set the origin parameter to the location of the pixel using (y,x), with x and y starting at 0 for the first pixel in the kernel. See "ahelp ciao_smooth" for more information on these parameters.
file filename, norm=True, origin=None Smooth with the image in the given file. The norm and origin parameters have the same meaning as the image option above.
none Leaves the pixel values unchanged.


This routine modifies the data in the crate; it does not return a modified copy. There is no way to undo the changes made by this routine other than to use read_file() to re-read in the original data.

Loading the routine

The routine can be loaded into a ChIPS, Sherpa or a Python script by saying:

from crates_contrib.utils import *

Writing the data out to file

The write_file() command can be used to write the smoothed data out to a new file. As mentioned above, the aconvolve tool is more appropriate if you wish to use the smoothed image with other CIAO tools.

Example 1

chips> from crates_contrib.utils import *
chips> cr = read_file("img.fits")
chips> smooth_image_crate(cr, "gauss", 5)
chips> add_image(cr)
chips> set_plot_title(r"gaussian smoothing (\sigma=5)")

The gaussian-smoothed version of the data in img.fits is displayed using the ChIPS add_image() command.

Example 2

chips> cr = read_file("img.fits")
chips> smooth_image_crate(cr, "tophat", 3)
chips> add_image(cr)

Here the image is smoothed with a 3-pixel radius top-hat kernel.

Example 3

chips> cr = read_file("img.fits")
chips> smooth_image_crate(cr, "file", "psf.fits")

Here the image is smoothed by the contents of the image file "psf.fits".

Example 4

chips> cr = read_file("img.fits")
chips> k = np.asarray([0,1,0,1,2,1,0,1,0]).reshape(3,3)
chips> smooth_image_crate(cr, "image", k)

The image is smoothed by a user-supplied kernel, in this case:

chips> print(k)
[[0 1 0]
 [1 2 1]
 [0 1 0]]

Example 5

chips> cr = read_file("img.fits")
chips> smooth_image_crate(cr, "gauss", 3)
chips> scale_image_crate(cr, "arcsinh")
chips> make_figure(cr, "image")

Here we smooth an image and then apply an arcsinh transform before displaying it in ChIPS.

Example 6

In this example we create a routine called getfile which reads in an image from a file, smooths it with a 3-pixel radius top-hat function, applies square-root scaling to it, and then returns the crate.

chips> def getfile(fname):
           cr = read_file(fname)
           smooth_image_crate(cr, "tophat", 3)
           scale_image_crate(cr, "sqrt")
           return cr

This routine can then be used to create a three-color image using the following set of commands:

chips> r = getfile("evt2.fits[energy=500:1500][bin sky=::4]")
chips> g = getfile("evt2.fits[energy=1500:3500][bin sky=::4]")
chips> b = getfile("evt2.fits[energy=3500:700][bin sky=::4]")
chips> add_image(r, g, b)


See the bug pages on the CIAO website for an up-to-date listing of known bugs.

Refer to the CIAO bug pages for an up-to-date listing of known issues.

See Also

make_image_crate, make_table_crate, scale_image_crate, write_arrays, write_columns
add_col, add_key, add_piximg, delete_col, delete_key, delete_piximg, read_file, read_pha, read_rmf, write_file, write_pha, write_rmf

Last modified: September 2011
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.