Apply a transform to the given data.
apply_transform(transform, data) The apply method of the transform object can also be used.
The function arguments.
|transform||A transform object.|
|data||An array of data values to be converted. For a one-dimensional transform it is an array of points; for two dimensional arrays it is an array of 2D values (e.g. [[x1,y1], [x2,y2], ...]).|
The apply_transform command applies the transform to the provided data. The return value has the same data type as the input (although it will be converted to a NumPy array), so it is best to ensure that the input is a floating-point value before calling apply_transform!
The command assumes that the data is appropriate for the transform definition. That is, if the transform is a simple scale, the data may be a list of scalars. If the transform expects a list of coordinate pairs, the input data must be a list of pairs.
What transformations are defined in a Crate?
For images, the get_axisnames() method of the Crate returns the list of transform names:
>>> cr = read_file('evt2.fits[bin sky=8]') >>> print(cr.get_axisnames()) ['sky', 'EQPOS']
and for tables it can be found by comparing the output of the get_colnames() method when rawonly=True and False:
>>> cr = read_file('evt2.fits[cols time,energy,det,sky]') >>> print(cr.get_colnames(rawonly=True)) ['time', 'energy', 'det(detx, dety)', 'sky(x, y)'] >>> print(cr.get_colnames(rawonly=False)) ['time', 'energy', 'det(detx, dety)', 'sky(x, y)', 'MSC(PHI, THETA)', 'EQPOS(RA, DEC)']
or, by taking advantage of the native set support in Python,
>>> n1 = set(cr.get_colnames(rawonly=True)) >>> n2 = set(cr.get_colnames(rawonly=False)) >>> print(n2.difference(n1)) set(['MSC(PHI, THETA)', 'EQPOS(RA, DEC)'])
Data type support
The output of the apply_transform routine or apply method has the same numeric data type as the input coordinates (although converted to a NumPy array if the input was a Python list). This means that it is possible to lose precision if the input values are integers, as shown below:
>>> print(apply_transform(trans, [[100,100]])) [[239 27]] >>> print(apply_transform(trans, [[100.0,100.0]])) [[ 239.24292436 27.51185138]]
>>> import pycrates as pyc >>> cr = pyc.read_file("img.fits") >>> sky = cr.get_transform("sky") >>> sky.apply([[0.5,0.5]]) array([[ 2008.5, 3148.5]])
Here we find out the SKY coordinates of the bottom-left corner of the image (the logical coordinates 1,1 refer to the center of the first pixel so 0.5,0.5 refers to the bottom-left corner of the pixel).
>>> import pycrates as pyc >>> import pytransform as pyt >>> cr = pyc.read_file("evt2.fits") >>> trans = cr.get_transform("MSC") >>> ivals = [[4000.0, 5000.0],[5500.0,3500.0]] >>> ovals = apply_transform(trans, ivals) >>> print(ovals)
[[ 9.60964703e+01 1.24180444e-01] [ 3.36974076e+02 2.08415725e-01]]
The "MSC" transform from the table evt2.fits is applied to the values (4000,5000) and (5500,3500).
Direct access via the object
Note that you can also use the apply method of the transform object - e.g.
>>> ovals = trans.apply(ivals)
as used in the preceeding example.
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.