Last modified: June 2019

URL: https://cxc.cfa.harvard.edu/ciao/ahelp/smooth_image_crate.html
Jump to: Description · Examples · Bugs · See Also


AHELP for CIAO 4.16

smooth_image_crate

Context: contrib

Synopsis

Smooth the pixel values in an IMAGE crate.

Syntax

smooth_image_crate(crate, type, arguments...)

Description

This routines smoothes the pixel values stored in an image crate. 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.

WARNING

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 Python 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.


Examples

Example 1

>>> from crates_contrib.utils import *
>>> cr = read_file("img.fits")
>>> smooth_image_crate(cr, "gauss", 5)

The data in img.fits is smoothed with a gaussian.

Example 2

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

Here the image is smoothed with a 3-pixel radius top-hat kernel. Note that the data is re-loaded from the file (otherwise the previously-smoothed image would have been used).

Example 3

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

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

Example 4

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

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

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

Example 5

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

Here we smooth an image and then apply an arcsinh transform to the smoothed data.

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.

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


Bugs

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

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