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

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

make_image_crate

Context: contrib

Synopsis

Create an IMAGECrate from an array.

Syntax

make_image_crate(pixvals)

The return value is an IMAGECrate.

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> cr.name = 'ELGAUSS'
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 
ELGAUSS(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 

Example 3

chips> ds = CrateDataset()
chips> ivals = np.arange(12).reshape(3,4)
chips> col1 = np.arange(1, 5)
chips> col2 = np.random.randint(10, 20, size=col1.size)
chips> cr1 = make_image_crate(ivals)
chips> cr2 = make_table_crate(col1, col2, colnames=['INDEX', 'RANDVAL'])
chips> add_crate(ds, cr1)
chips> add_crate(ds, cr2)
chips> write_file(ds, 'blocks.fits')

Here we use a CrateDataset object to store two blocks - an image and then a table - which is written out to blocks.fits:

chips> !dmlist blocks.fits blocks
 
--------------------------------------------------------------------------------
Dataset: blocks.fits
--------------------------------------------------------------------------------
 
     Block Name                          Type         Dimensions
--------------------------------------------------------------------------------
Block    1: IMAGE                          Image      Int4(4x3)
Block    2: TABLE                          Table         2 cols x 4        rows

The NumPy randint routine is used to create random integers betwen 10 and 19 (inclusive).

Adding or changing metadata

The crate has a name of 'IMAGE' and contains two keywords, CREATOR and DATE. These can be changed, or other values added, using Crates routines.

chips> cr.name = 'HISTVALS'

will change the block name.

Keywords

The set_key() routine is an easy way to add or edit a keyword, while get_key() and add_key() provide a more powerful way of handling keywords. The delete_key() routine removes keywords.

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: December 2013
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:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.