wiki:CCB_PixelAddrConvFunctions
Last modified 11 years ago Last modified on 11/04/2008 04:32:36 PM

Linked from Configuration Control Board

CCB Proposal: Standard Use of Pixel Addressing Conversion Functions

The issue is the mapping between pixel index and pixel position, e.g. when computing centroids.

The proposal is to supply (inline) functions that map between pixel index and pixel position (position on the CCD) and to require that these functions be used instead of hand-coding the conversion.

This has the following advantages:

  • It makes code clearer and more explicit. Indexing over pixels and computing positions are not the same thing, though they are closely coupled and are easily conflated. Using conversion functions makes the difference explicit, making the code easier to understand.

  • It avoids code duplication.
  • It avoids several kinds of errors:
    • Incorrect assumptions about our pixel position convention. There are two standards in widespread use and we are adding a third, so this is a non-negligible issue and (if we do not mandate use of conversion functions) one that is hard to find during a code review.
    • Incorrect conversion, despite trying to follow the correct convention. Some obvious choices may have subtle errors, especially if the user is computing positions that are off the CCD (and thus may have negative position or index).
  • If the pixels of a full CCD are not on a uniform grid (e.g. when binned) then such functions will be even more useful.
  • In addition (though this not a primary argument) use of such functions provides some isolation of our choice of pixel position convention. Other projects that wished to use our software framework but insisted on a different pixel position convention could simply modify the conversion functions.

The primary cost is added verbosity.

In my own experience the additional verbosity is slight and is more than made up for by increased clarity of the code. I find it helps me keep track of what I am doing while writing the code and helps me understand the same code later. In our project it is crucial that the code be as clear as possible.

Note that we will want at least one pair of conversion functions for mapping between our pixel position convention and FITS pixel position convention as well.

Comment by rowen on Tue 04 Nov 2008 05:32:36 PM CST

afw has functions indexToPosition and positionToIndex defined in ImageUtils.h

Add comment