[fitsbits] top or buttom

Stephen Walton swalton at sfo.csun.edu
Tue Apr 25 14:12:58 EDT 2000


Steve Allen wrote:
> 
> On Thu 2000-04-20T13:44:18 -0700, Stephen Walton hath writ:
> 
> > One point about this which I've always found somewhat confusing (though
> > maybe I'm the only one):  We usually consider the indices of an array
> > stored in memory as being (row,column) by analogy to mathematical
> > matrices.  But, if we adopt the convention that the first axis of a FITS
> > image is displayed horizontally and the second vertically, the first index
> > of the array is, in effect, the column index;  i.e., the Y coordinate.
> 
> The first axis?
> 
> Actually, around here we all think of the FITS coordinates of a 2-d
> image like this:
>         array [ NAXIS2 ][ NAXIS1 ]

Ack.  In other words, in your C software the first index of the array is
the second FITS axis and vice versa. In Fortran, I always use
ARRAY(NAXIS1,NAXIS2). Here's a question:  if I call the Fortran 90
MATMUL intrinsic viz:

	C = MATMUL(A,B)

where A is dimensioned (L,M) and B is dimensioned (M,N), I will get
C(I,J) = A(I,K)*B(K,J) (with summation implicit over K) for I=1 to L and
J=1 to N.  Thus, C will be dimensioned (L,N).  This is standard
mathematical matrix multiplication carried over into Fortran, where the
first index of a matrix is the row index and the second is the column
index.  Is there any equivalent convention in C/C++?

When we display FITS images with the first index varying horizontally
and the second vertically, the first index is, in effect, the column
index if we think (erroneously, I suppose) of the FITS data as a matrix
in the mathematical sense.  MATLAB thinks of an array representing image
data as a mathematical matrix and its Image Toolbox displays the array
with its first index increasing vertically downward, consistent with the
way a mathematics text displays a matrix.

How do you all normally treat the CD matrix?  This is supposed to be a
true mathematical matrix with CD1_2 being the element in the first row,
second column.  Does this get stored in your programs as element [1,2]
or as element [2,1]?  It seems to me that either choice gives a
problem.  Suppose I write a standard matrix-vector multiplication
routine which takes an array A(M,N) and a vector V(N) and computes as
output D(I) = A(I,K)*V(K) for I=1 to M.  I can compute the (x,y) WCS
coordinates from pixel coordinates (I,J) if I set A(I,J) = CD_IJ, V(1) =
I, V(2) = J.  However, now the corresponding (x,y) are for element
ARRAY[J,I] if you dimension ARRAY[NAXIS2,NAXIS1], aren't they?

--
Stephen Walton, Professor, Dept. of Physics & Astronomy
Cal State Northridge
stephen.walton at csun.edu



More information about the fitsbits mailing list