Last modified: December 2023

URL: https://cxc.cfa.harvard.edu/ciao/ahelp/simplecoordtransform.html
AHELP for CIAO 4.17

simplecoordtransform

Context: contrib

Synopsis

Convert between the different coordinate systems of an image.

Syntax

tr = SimpleCoordTransform(input)
(xout, yout) = tr.convert(fromsys, tosys, xin, yin)

Description

The SimpleCoordTransform class allows you to easily convert between the different coordinate systems of a CIAO-produced image (it may work on some non-CIAO data).

Loading the routine

The routine can be loaded into a Python session by saying:

from crates_contrib.utils import *

Coordinate conversion

An object is created using the SimpleCoordTransform constructor, which takes a single argument: the name of an image file or an image crate. The object has a single method - convert - which can then be used to convert between one of three coordinate systems: world, physical, or logical.

The fromsys and tosys arguments define the input and output coordinate systems respectivelty and can be one of:

The fromsys and tosys arguments

Value Description
"world" or "eqpos" The WCS coordinate systems supported by CIAO
"physical" or "sky" The physical coordinate system
"logical" or "image" The logical coordinate system

The xin and yin arguments can be of a single point or multiple points.


Examples

Example 1

>>> tr = SimpleCoordTransform("img.fits")
>>> (r0, d0) = tr.convert("sky", "world", 4096.5, 4096.5)

Here the sky coordinate (4096.5, 4096.5) is converted into Ra and Dec coordinates (assuming the "world" system represents an equatorial coordinate system).

Example 2

>>> tcr = read_file('sources.fits[cols ra,dec]')
>>> ra = tcr.get_column('ra').values
>>> dec = tcr.get_column('dec').values
>>> icr = read_file('img.fits')
>>> tr = SimpleCoordTransform('img.fits')
>>> (x, y) = tr.convert('world', 'image', ra, dec)

Here Ra and Dec coordiantes from the file "sources.fits" are converted into image (a.k.a. logical) coordinates of the image stored in img.fits.

The points can then be overlaid on the iage using the following Matplotlib code:

>>> import matplotlib.pyplot as plt
>>> plt.imshow(icr.get_image().values, origin='lower')
>>> plt.scatter(x, y, color='orange')

Notes

Coordinate-system support

The coordinate-transform code has been written and tested for use with images created by CIAO tools. Please let the CXC HelpDesk know if it does not work for your image file(s).

Changes in the scripts 4.6.4 (April 2014) release

The error where SimpleCoordTransform would fail, claiming that it was "Unable to find the world system", has been fixed.


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.