[fitswcs] WCS documents

Doug Tody tody at tucana.tuc.noao.edu
Tue Sep 25 13:18:41 EDT 2001


Hi Folks -

A number of people have quite reasonably asked what is the motivation for
our suggestion that the dimensionality of the image pixel matrix and WCS
be decoupled.  The document below analyzes the issue in some detail and
presents a number of examples illustrating how this would work and where
it would be useful.  The basic argument can however be summarized as
follows:

o   It has been proposed that degenerate axes be used to carry WCS
    information when the mathematical dimensionality of the WCS exceeds
    that of the physical image matrix.  For example a physically 2D image
    with a 3D WCS would be represented as 2 nondegenerate axes (NAXISi > 1)
    plus 1 degenerate axis (NAXISi == 1).

o   While this is a mathematically elegant and rigorous way to represent
    multidimensional images with associated WCS, we are overloading the
    meaning of the NAXIS keyword.  The fundamental purpose of the NAXIS
    keyword is to define the dimensionality of the image pixel matrix.

o   At least within some segments of astronomy (certainly, much of O/IR
    astronomy) it is common practice to assume that NAXIS refers to the
    number of "real" (nondegenerate) axes in the image.  For example,
    a 2D image is assumed to have NAXIS == 2.  A 1D image such as a
    spectrum is assumed to have NAXIS == 1.

o   Many programs use the value of NAXIS to check that the image they are
    presented with has the expected dimensionality.  One could argue that
    all programs should be fully general and able to deal with images of
    any dimensionality, but in reality whether this is practical depends
    upon what the program is doing.  For many programs it is a very
    reasonable assumption to require that the image have a certain
    dimensionality: "1D", "2D", "3D", etc., usually corresponding to the
    algorithm implemented by the program.

o   Requiring that degenerate axes be used to represent a WCS which has
    a dimensionality greater than the physical image matrix does not change
    the strict definition of NAXIS - it will always be possible for images
    to have degenerate axes.  But it does have a major impact on the way
    NAXIS is actually used.  The great simplifying concept of "1D" or "2D"
    images would be compromised or lost.  Many programs which currently
    deal with FITS images would be potentially affected by such a change
    of usage.

o   NAXIS is one of the most fundamental keywords in all of FITS.  What
    has been proposed would force a change in the usage of NAXIS, affecting
    large segments of the FITS user community.  We feel this would be the
    most fundamental, non-backwards compatible, change ever made in the
    history of FITS.

o   The only motivation yet established for degenerate axes and for
    overloading the meaning of NAXIS is to support multidimensional WCS.
    But is the use of degenerate axes the only way to solve the problem
    of a WCS of greater dimension than the physical image matrix it is
    associated with?

o   Of course not.  The same problem can be solved by decoupling the WCS
    dimensionality from that of the image matrix it is associated with.
    That is, the dimensionality of the WCS may exceed that of the image.

We feel that this is actually the more general solution - very much so.
The change is subtle: the meaning of the WCS keywords doesn't really change
at all, all we do is add a new concept that the WCS dimensionality may
differ from (exceed) that of the image.  A new keyword may be desirable
to make this concept explicit.  But by doing so we allow a WCS to exist
independently of an image; it can still be easily associated with an image,
but can be used for other purposes as well.  NAXIS preserves its simple
meaning and can still be used to define the physical image dimensionality
regardless of the complexity of any WCS (or other future abstraction)
associated with the image matrix.

An indication of the generality of this approach is that the degenerate
axis convention could still be used without change: it is a special case
of the more general representation.  Although we might have to adapt
existing data in terms of the WCS representation, the dimensionality of
existing (or future) images would not need to change.  Both the O/IR and
radio conventions could continue to be used.  The WCS would be fully
and rigorously defined in both cases.

The document below explores these issues in more detail and should help
to illustrate what is being proposed.  In reading this please bear in mind
that what is being proposed here is very simple: we merely allow the WCS
dimensionality to differ from that of the image with which it is
associated.  All of the WCS keywords are unchanged and are still used in
the same way as at present, although we propose a new keyword to explicitly
specify the WCS dimensionality.

	- Doug




		      Comments on the Issue of
	      Decoupling the WCS and Image Dimensionalities


A WCS is a mathematical object which specifies a transformation from one
coordinate system to another.  In FITS the WCS has traditionally been
associated with an image matrix and the independent variables have been
associated with pixel coordinates.  The usual FITS practice has been to
tightly couple the WCS and image matrix by requiring them to have the same
dimensionality, i.e., NAXIS, the dimensionality of the image matrix.  It
has been proposed that this convention be carried over for the general
FITS WCS standard.  However, this convention has complications which may
not be immediately obvious, mainly in the case of dimensional reduction
and degenerate axes (that is, pulling a subimage from an image of higher
dimension).  An alternate view is that the image pixel matrix and WCS are
actually separate objects which, while normally associated when
representing an image, can both be decoupled and treated independently.
Our analysis here explores this more general concept for representing the
WCS.

FITS is conceived as a way to transport (interchange) data within
astronomy.  Originally such data was limited to raster images, but FITS
has grown to include representations for tabular data and even more complex
data structures.  We suggest that a WCS is a data object in it's own right
that we may want to represent and interchange the same way regardless of
the type of data with which it is ultimately associated, and indeed
regardless of whether or not it is immediately associated with other data.
The representation and transport of WCS information may be useful in many
future contexts and we should avoid building in unnecessary dependencies
on any particular data type such as an image pixel matrix.

By allowing the raster or table dimensionality, as described by the
standard NAXIS keywords, to differ from the WCS dimensionality, we can
represent a WCS which is associated with no data or with dimensionally
reduced images, and we can represent a dimensionally enhanced WCS which
defines coordinates which are not part of an actual physical image raster.
This is not a difficult thing to do.  It simply requires agreement on a
WCS dimensionality keyword and clarification of the meaning of CRPIX in
a WCS context.

In the examples which follow we use the keyword WCSDIM to specify the WCS
dimensionality, but the keyword name could be anything else such as the
WCSAXES, WCAXIS, etc., keyword names already suggested.


I. WCS which are Independent of Images

In some cases it might be desirable to store a WCS in a FITS header which
has no associated pixel matrix, but which makes use of the FITS WCS
formulation to store this information in a portable way.  The following
simple examples illustrate some possibilities.


Example 1.  Consider two 2D images of the same field which are shifted and
rotated with respect to each other.  Neither of these images contain world
coordinate information so stars common to both images are used to determine
the transformation from the pixel coordinate system of one image to that
of the other.  For the purposes of illustration assume that computed x
and y shifts are 10.0 and 20.0 pixels respectively, that the origin of
the rotation in one of the images is 256.0, 256.0, and that the relative
rotation is 30.0 degrees.  The resulting transformation would resemble
the following:


    x' =  (x - 256.0) * cos (30) - (y - 256.0) * sin (30) + 10.0
    y' =  (x - 256.0) * sin (30) + (y - 256.0) * cos (30) + 20.0


This transformation could be stored in an NAXIS = 0 FITS image (ignoring
formatting details) as follows:

    SIMPLE    = T
    BITPIX    = 8
    NAXIS     = 0
    ....

    WCSDIM    = 2
    CTYPE1    = 'LINEAR  '
    CTYPE2    = 'LINEAR  '
    CRPIX1    = 256.0
    CRPIX2    = 256.0
    CRVAL1    = 10.0 
    CRVAL2    = 20.0 
    CD1_1     = 0.866  / cos(30)
    CD1_2     = -0.5   / -sin(30)
    CD2_1     = 0.5    / sin(30)
    CD2_2     = 0.866  / cos(30)
    ....

    END

In this case the WCS is used to describe the transformation between two
images, rather than the coordinate system of any particular image.  The
WCS representation is unchanged, we merely use it in a different way.

More complicated, e.g. higher order polynomial, pixel-to-pixel mappings
could be represented using the proposed DCF.


Example 2.  Define the TAN projection required to map objects observed
around 5h+30 onto the tangent plane and store it in a FITS image.

    SIMPLE    = T
    BITPIX    = 8
    NAXIS     = 0
    ....

    WCSDIM    = 2
    CTYPE1    = 'RA---TAN'
    CTYPE2    = 'DEC--TAN'
    CRPIX1    = 0.0
    CRPIX2    = 0.0
    CRVAL1    = 75.0 
    CRVAL2    = 30.0 
    CD1_1     = 1.0
    CD1_2     = 0.0
    CD2_1     = 0.0
    CD2_2     = 1.0

    ....

    END

The inverse of the above transformation takes the equatorial sky coordinates
and projects them onto the tangent plane.


Example 3.  Flux transformations can be described by a WCS.  For example
the conversion of pixel flux values to linearized counts or to some
photometric system.  While we might need to define new CTYPEs and DCFs for
this purpose, once we have the mechanism for describing dataless
transformations and a general WCS model these new transformations could be
added in a future photometric WCS standard.


Example 4.  Suppose we want to transport or archive telescope distortions.
This could be useful for various purposes such as letting users model the
effects of the telescopes on their own detectors or remove distortions from
archived data which does not have a WCS.  This distortion WCS would
describe the mapping between millimeters on the focal plane to some other
coordinates such as arc seconds on the sky from the optical axes.


In all these examples the WCSDIM keyword (or WCSAXES, or whatever we
eventually decide to call it), is used to define the dimensionality of
the WCS.  A value NAXIS=0 (NAXISi is allowed though less desirable),
indicates that there is no associated pixel matrix.  In principal it would
be possible to do without this keyword, by defining the dimension of the
WCS to be the highest axis index present in the standard keywords or just
in CTYPE.  We made this suggestion to avoid adding new keywords but we
think defining a separate keyword is preferable for clarity.


II. Pseudo-N Dimensional Images (Degenerate Axes)

Pseudo-N dimensional images are images where the pixel matrix has an actual
dimensionality less than N but extra dimensions of length 1 (degenerate
axes) have been added for the purpose of including parameters in the WCS
formulation, e.g., constant values for quantities such as the wavelength,
polarization, time of observation, and so forth.  This convention has been
widely adopted by the radio community but is not in wide use within the
optical community.

Separating the WCS representation from the image matrix would still permit
this convention to be used (image axes of length 1 are always possible),
while providing a more general mechanism which allows complex WCS to still
be represented while NAXIS can be used to simply indicate the array
dimension of the pixel matrix.  Hence a "2D" image would always be a simple
two dimensional image so far as pixel level operations are concerned, but
the associated WCS might mathematically describe three, four, or more
coordinate axes depending upon the origin of the image.  This simplifies
pixel level operations while still allowing a fully general WCS.


Optical and Radio Conventions

The optical convention for imaging data has traditionally been different
from the radio convention.  Most optical imaging data is 2D and frequency
information is often specified via a filter name.  Sometimes an effective
wavelength is included although not usually in a standard way.  Many
optical users would like to be able to make use of new spectral (or other)
WCS standards to define an effective wavelength without having to make
existing 2D images have 3 or more dimensions, and without having to modify
existing data acquisition systems (which could be difficult in some cases)
to write pseudo-3D images.  It would be a serious matter for the optical
community to be forced to change its conventions for writing imaging data
simply because of a new FITS WCS standard.  Much existing software,
including older programs which cannot easily be changed, would be affected.
Similarly the radio community should not be forced to change their
conventions for writing radio data.  Permitting the WCS to be decoupled
from the image matrix avoids this problem.  This is illustrated in the
following example, which is adapted from FITS paper II.

Example 1.

    SIMPLE   = T
    BITPIX   = -32
    NAXIS    = 2
    NAXIS1   = 512
    NAXIS2   = 512

    ...

    WCSDIM   = 3
    CTYPE1   = 'RA---TAN'
    CRPIX1   = 256
    CRVAL1   = 45.83
    CD1_1    = -0.003
    CTYPE2   = 'DEC--TAN'
    CRPIX2   = 257
    CRVAL2   = 63.57
    CD2_2    = -0.003
    CTYPE3   = 'VELOCITY'
    CRPIX3   = 1.0
    CRVAL3   = 500000.0
    CUNIT3   = 'm/s     '
    CD3_3    = 0.0

    ...

    END

Note that the dimensionality of the WCS is different from that of the
image as expressed by the WCSDIM keyword.  In the radio convention the
above header would look the same except that the WCSDIM keyword could
be omitted, NAXIS = 3, and an NAXIS3 = 1 keyword is required.  The
proposed WCS formulation can easily support both representations.


Parameter Representation in General

In principle one could extend the radio convention for representing WCS
parameters indefinitely.  This would require adding another dimension to
represent time, or even a quantity like temperature in the case of focus
sequences.  One could easily end up with 5, 6, or higher dimensioned images
with this approach.  This should not be required merely to represent more
complex world coordinate systems.

o Backwards compatibility problems

    Many existing programs (at least within the optical community) are
    written expressly for 1D or 2D images.  These programs may assume the
    image is a certain dimension, or may abort if NAXIS does not correspond
    to the dimensionality of image the program was written for.  Often
    these programs deal only with the pixel matrix and may not use the
    WCS at all.  An entire community should not be forced to change or
    upgrade old software because the new WCS standard forces observatories
    to begin writing their pixel data differently.  Decoupling the image
    matrix from the WCS avoids the problem.

o Some software does not care about the WCS

    Programs that only care about the pixel matrix not the WCS should not
    have to change because a new WCS convention forces the pixel format
    to change.  Decoupling the WCS and image matrix solves this problem.

o Some software cares about a WCS but not the image

    The extreme case of this is covered in section I.  However it is also
    true that some software might only care about the WCS not the image,
    i.e., they use the WCS or parts of it to compute some quantity of
    interest like the transformation in pixel space between two images.


III. Dimensionally Reduced Images

Dimensionally reduced images are images that were once part of a higher
dimensioned parent image, e.g., a 2D image that was once part of a
datacube, or a 1D image that was once a line or column in a 2D image.
The question of interest is how to describe the WCS of such an image.

o Option 1: don't dimensionally reduce images

    One response to the dimensional reduction problem is don't really do
    it.  In this case the "reduced" dimensions all have length 1 but don't
    disappear (this the approach adopted by the radio community).  In this
    case a plane extracted from a 3D cube would still be a 3D image.  The
    WCS zero points would have to be adjusted but nothing else.

    However, one of the reasons for dimensionally reducing an image is to
    obtain a lower dimensional pixel grid to simplify the image for naive
    software that, for instance, requires a two dimensional pixel matrix.

o Option 2: actually do the dimensional reduction

    In this case the image matrix dimensions really are reduced
    although the WCS retains the dimensionality of the original image.

An example of how dimensional reduction might work in the case of a line
or column extracted from a 2D image is shown below.

Original 2D image WCS:

    NAXIS   =                    2
    NAXIS1  =                  512 
    NAXIS2  =                  512 
    ...

    WCSDIM  =                    2
    CRPIX1  =     250.255640043397
    CRPIX2  =     266.308757582063
    CRVAL1  =       202.4719695444
    CRVAL2  =     47.1967667056703
    CTYPE1  = 'LINEAR  '
    CTYPE2  = 'LINEAR  '
    CD1_1   =  -2.1224568721689E-4
    CD1_2   =  -3.8136851047801E-6
    CD2_1   =  -3.2384199796514E-6
    CD2_2   =  2.12935798198135E-4

    ...

    END


Line 255 of original 2D image extracted, y coordinate assumed to be 1:

    NAXIS   =                    1
    NAXIS1  =                  512

    WCSDIM  =                    2
    CRPIX1  =     250.255640043397
    CRPIX2  =      12.308757582063
    CRVAL1  =       202.4719695444
    CRVAL2  =     47.1967667056703
    CTYPE1  = 'LINEAR  '
    CTYPE2  = 'LINEAR  '
    CD1_1   =  -2.1224568721689E-4
    CD1_2   =  -3.8136851047801E-6
    CD2_1   =  -3.2384199796514E-6
    CD2_2   =  2.12935798198135E-4


Column 255 of original 2D image extracted, y coordinate assumed to be 1:

    NAXIS   =                    1
    NAXIS1  =                  512

    WCSDIM  =                    2
    CRPIX1  =     266.308757582063
    CRPIX2  =    -3.74435995660301
    CRVAL1  =     47.1967667056703
    CRVAL2  =       202.4719695444
    CTYPE1  = 'LINEAR  '
    CTYPE2  = 'LINEAR  '
    CD1_1   =  2.12935798198135E-4
    CD1_2   =  -3.2384199796514E-6
    CD2_1   =  -3.8136851047801E-6
    CD2_2   =  -2.1224568721689E-4


Extraction of a line from a 2D image is very simple: NAXIS changes, NAXIS2
disappears, and CRPIX2 changes.  Extracting a column is a bit more
complicated because it is necessary to interchange the roles of axes 1
and 2, but is still not difficult.  An alternate approach would be to use
an axis map to map the axes of the image to the axes of the WCS.  This
would eliminate the need to modify the WCS in the column extraction above,
but given the static nature of FITS images it is probably simplest to just
modify the WCS.

Although the examples above show a linear WCS, the same approach will work
for any nonlinear WCS as well.  For example with a tangent projection the
tangent point does not change merely due to subsetting an image.  The
reference pixel coordinates will change in all cases.  Axes may have to
be swapped in some cases, but this can be done consistently for any WCS
without need to understand the specific WCS used.  The process is also
reversible: dimensionally reduced image subsets can be used to reconstruct
the original image, merely by using the WCS for a subset to determine
where to place it in the output image (the WCS of the output image is
unaffected).



IV. Summary

In summary the ability to separate the dimensionality of the image from
that of the WCS is recommended for the following reasons:

    o	Overloading the meaning of the NAXIS keyword is avoided.  NAXIS
	will simply refer to the physical dimensionality of the image
	matrix, regardless of the complexity of any associated image
	attributes such as a WCS.

    o   A WCS can be stored in a FITS header which does not have a pixel
	matrix to allow interchange of general WCS information in a
	standardized way.

    o   It is not necessary to write pseudo-N dimensional images in order
	to be able to include additional pseudo-axis parameters (i.e.,
	constant values) in the WCS.

    o   Dimensionally reduced images are permitted without compromising
	the generality of the WCS.

This more general scheme would still permit the radio convention, which
would be automatically supported by software written to deal with images
of any dimension.  But programs which would benefit from the assumption
of a simple 1D or 2D image would still be able to make use of a fully
general multidimensional WCS.


Lindsey Davis, Frank Valdes, Doug Tody



More information about the fitswcs mailing list