Chandra X-Ray Observatory (CXC)
Skip to the navigation links
Last modified: January 2012

URL: http://cxc.harvard.edu/ciao/make_image_crate.html
AHELP for CIAO 4.4

make_image_crate

Context: contrib

Synopsis

Create an IMAGE Crate from an array.

Syntax

crate = make_image_crate(pixvals)

Description

This routine provides a quick means of creating an IMAGE Crate from an array of values.

Loading the routine

The routine can be loaded into a ChIPS or Sherpa session by saying:

from crates_contrib.utils import *

Writing the data out to file

The write_file() command can be used to write the data out to file in FITS binary or ASCII formats.

Example 1

chips> cr = make_image_crate([1, 2, 3, 4, 5])
chips> write_file(cr, "img.fits")

The one-dimensional array of integers 1 to 5 is written out to the file img.fits:

chips> !dmlist img.fits blocks
 
--------------------------------------------------------------------------------
Dataset: img.fits
--------------------------------------------------------------------------------
 
     Block Name                          Type         Dimensions
--------------------------------------------------------------------------------
Block    1: IMAGE                          Image      Int4(5)

Example 2

chips> (y, x) = np.mgrid[1:251, 1:201]
chips> dx = x - 100
chips> dy = y - 120
chips> a = np.pi * 3 / 4
chips> xn = dx * np.cos(a) + dy * np.sin(a)
chips> yn = dy * np.cos(a) - dx * np.sin(a)
chips> r2 = (xn**2 * 0.8**2 + yn**2) / 0.8**2
chips> z = np.exp(-r2 / (20*20))
chips> cr = make_image_crate(z)
chips> write_file(cr, "z.img")

Here we create a 2D elliptical gaussian, centered at (100,120) with an ellipticity of 0.2 and rotated by 135 degrees, within an array of size (200,250). The mgrid call creates two 2-D arrays set to the x and y coordinates of the array; we start at 1 rather than 0 since the FITS coordinate system has 1,1 as the center of the lower-left pixel. The formula for the gaussian is taken from "ahelp gauss2d".

chips> !dmstat z.img 
IMAGE(X, Y)
    min:	4.3649283641e-46 	      @:	( 200 250 )
    max:	1 	      @:	( 100 120 )
cntrd[log] :	( 100 120 )
cntrd[phys]:	( 100 120 )
sigma_cntrd:	( 14.292603045 17.109341909 )
   good:	50000 
   null:	0 

Integer arrays

On 64-bit build machines, a NumPy array with a dataype of np.int32 will be converted to np.int64 before being added to the crate. This is to work around a bug in CIAO 4.4 release 1, where np.int32 values are written out incorrectly by the write method of the crate or the write_file() routine.

Changes in the January 2012 Release

The make_image_crate routine is new in this release.

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_table_crate, scale_image_crate, smooth_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

Last modified: January 2012
CXC logo

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