|AHELP for CIAO 4.9||
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.
For images, the get_axisnames() method of the Crate returns the list of transform names:
chips> cr = read_file('evt2.fits[bin sky=8]') chips> 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:
chips> cr = read_file('evt2.fits[cols time,energy,det,sky]') chips> print(cr.get_colnames(rawonly=True)) ['time', 'energy', 'det(detx, dety)', 'sky(x, y)'] chips> 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,
chips> n1 = set(cr.get_colnames(rawonly=True)) chips> n2 = set(cr.get_colnames(rawonly=False)) chips> print(n2.difference(n1)) set(['MSC(PHI, THETA)', 'EQPOS(RA, DEC)'])
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:
chips> print(apply_transform(trans, [[100,100]])) [[239 27]] chips> print(apply_transform(trans, [[100.0,100.0]])) [[ 239.24292436 27.51185138]]
chips> import pycrates as pyc chips> cr = pyc.read_file("img.fits") chips> sky = cr.get_transform("sky") chips> 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).
chips> import pycrates as pyc chips> import pytransform as pyt chips> cr = pyc.read_file("evt2.fits") chips> trans = cr.get_transform("MSC") chips> ivals = [[4000.0, 5000.0],[5500.0,3500.0]] chips> ovals = apply_transform(trans, ivals) chips> 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).
Note that you can also use the apply method of the transform object - e.g.
chips> 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.