Index: /trunk/doc/pslib/ChangeLogSDRS.tex
===================================================================
--- /trunk/doc/pslib/ChangeLogSDRS.tex	(revision 3068)
+++ /trunk/doc/pslib/ChangeLogSDRS.tex	(revision 3069)
@@ -1,3 +1,3 @@
-%%% $Id: ChangeLogSDRS.tex,v 1.56 2005-01-20 03:46:53 price Exp $
+%%% $Id: ChangeLogSDRS.tex,v 1.57 2005-01-20 08:25:45 price Exp $
 
 \subsection{Changes from version 00 to version 01}
@@ -426,4 +426,11 @@
     of \code{const psList} in \code{psListIteratorAlloc}.
   \end{itemize}
-
-\end{itemize}
+\item Added \code{psPlaneTransformInvert},
+  \code{psPlaneTransformCombine} and \code{psPlaneTransformFit}.
+\item Added \code{psAstrometryReadWCS}, \code{psAstrometryWriteWCS},
+  and \code{psAstrometrySimplify}.
+\item Added additional modes to \code{psImageInterpolateMode} to deal
+  with variances: \code{PS_INTERPOLATE_BILINEAR_VARIANCE,
+  PS_INTERPOLATE_BICUBIC_VARIANCE, PS_INTERPOLATE_SINC_VARIANCE}.
+\item Added \code{psImageTransform}.
+\end{itemize}
Index: /trunk/doc/pslib/psLibSDRS.tex
===================================================================
--- /trunk/doc/pslib/psLibSDRS.tex	(revision 3068)
+++ /trunk/doc/pslib/psLibSDRS.tex	(revision 3069)
@@ -1,3 +1,3 @@
-%%% $Id: psLibSDRS.tex,v 1.167 2005-01-20 03:46:48 price Exp $
+%%% $Id: psLibSDRS.tex,v 1.168 2005-01-20 08:25:55 price Exp $
 \documentclass[panstarrs,spec]{panstarrs}
 
@@ -2717,7 +2717,19 @@
     PS_INTERPOLATE_BILINEAR, 
     PS_INTERPOLATE_BICUBIC, 
-    PS_INTERPOLATE_SINC 
+    PS_INTERPOLATE_SINC,
+    PS_INTERPOLATE_BILINEAR_VARIANCE,
+    PS_INTERPOLATE_BICUBIC_VARIANCE,
+    PS_INTERPOLATE_SINC_VARIANCE
 } psImageInterpolateMode mode;
 \end{verbatim}
+
+The first four are fairly straightforward.  The last three, however,
+require some explanation.  When attempting to account for noise in a
+CCD image, it is customary to carry an additional image containing the
+variance for each pixel.  When operating on the CCD image (performing
+some transformation), we want to perform the same operation on the
+variance image, but the weights of the different input pixels
+contributing to the output pixel must be squared in order to propagate
+the noise (adding in quadrature).
 
 \begin{verbatim}
@@ -2792,4 +2804,31 @@
 \code{psU16}, \code{psS8}, \code{psS16}, \code{psF32}, \code{psF64},
 \code{psC32}, \code{psC64}.
+
+\begin{verbatim}
+psImage *psImageTransform(psImage *output, const psImage *input, const psImage *inputMask, int inputMaskVal,
+                          const psPlaneTransform *outToIn, const psImage *combineMask, int combineMaskVal);
+\end{verbatim}
+Transform the \code{input} image according the supplied
+transformation.  In the event that the \code{output} is \code{NULL},
+the smallest possible image capable of containing the entire
+transformed \code{input} image is to be returned; otherwise only the
+image size specified in the \code{output} image is to be used.  If the
+\code{inputMask} is not \code{NULL}, those pixels in the
+\code{inputMask} matching \code{inputMaskVal} are to be ignored in the
+transformation.  The \code{inputMask} must be of type \code{psU8}, and
+of the same size as the \code{input}, otherwise the function shall
+generate an error and return \code{NULL}.  The transformation
+\code{outToIn} specifies the coordinates in the input image of a pixel
+in the output image --- note that this is the reverse of what might be
+naively expected, but it is what is required in order to use
+\code{psImagePixelInterpolate}.  If \code{combineMask} is not
+\code{NULL}, then those pixels that match \code{combineMaskVal} are
+not transformed.  \code{combineMask} must be of type \code{psU8} and
+of the same size as the \code{output}, otherwise the function shall
+generate an error and return \code{NULL}.  This function must be
+capable of handling the following types for the \code{input} (with
+corresponding types for the \code{output}): \code{psF32},
+\code{psF64}.
+
 
 \subsubsection{Image Statistical Functions}
@@ -4554,4 +4593,52 @@
                              float mag, float color);
 \end{verbatim}
+
+
+The following functions perform operations on transformations:
+
+\begin{verbatim}
+psPlaneTransform *psPlaneTransformInvert(psPlaneTransform *out, const psPlaneTransform *in, float xMin,
+                                         float xMax, float yMin, float yMax, int nSamples);
+psPlaneTransform *psPlaneTransformCombine(psPlaneTransform *out, const psPlaneTransform *trans1,
+                                          const psPlaneTransform *trans2);
+bool psPlaneTranformFit(psPlaneTransform *trans, const psArray *source, const psArray *dest, int nRejIter,
+                        float sigmaClip);
+\end{verbatim}
+
+\code{psPlaneTransformInvert} shall return the transformation that
+inverts the given transformation.  It may assume that the input
+transformation is one-to-one, and that the inverse transformation may
+be specified through using polynomials of the same type and order as
+the forward transformation.  In the event that the input
+transformation is linear, an exact solution may be calculated;
+otherwise \code{nSamples} samples in each axis, ranging from
+\code{xMin} to \code{xMax} and \code{yMin} to \code{yMax} shall be
+used as a grid to fit the best inverse transformation.  The function
+shall return \code{NULL} if it was unable to generate the inverse
+transformation; otherwise it shall return the inverse transformation.
+In the event that \code{out} is \code{NULL}, a new
+\code{psPlaneTransform} shall be allocated and returned.
+
+\code{psPlaneTransformSubsume} takes two transformations
+(\code{trans1} and \code{trans2}) and returns a single transformation
+that has the effect of performing \code{trans1} followed by
+\code{trans2}.  The function shall return \code{NULL} if it was unable
+to generate the transformation; otherwise it shall return the
+transformation.  \tbd{Not sure on the algorithm yet --- it may be the
+same as for \code{psPlaneTransformInvert}, in which case we will need
+the ranges and number of samples as well.}
+
+\code{psPlaneTransform} takes two arrays containing matched
+coordinates (i.e., coordinates the \code{source} correspond to the
+appropriate coordinates in the \code{dest}) and returns the
+best-fitting transformation.  The \code{source} and \code{dest} will
+contain \code{psCoord}s.  In the event that the number of coordinates
+in each is not identical, the function shall generate a warning, and
+extra coordinates in the longer of the two shall be ignored.  The
+\code{trans} transform may not be \code{NULL}, since it specifies the
+desired order, polynomial type and any polynomial terms to mask.
+\code{nRejIter} rejection iterations shall be performed, wherein
+coordinates lying more than \code{sigmaClip} standard deviations from
+the fit shall be rejected.
 
 \subsubsection{Celestial Coordinate Conversions}
Index: /trunk/doc/pslib/psLibSDRS_Astrom.tex
===================================================================
--- /trunk/doc/pslib/psLibSDRS_Astrom.tex	(revision 3068)
+++ /trunk/doc/pslib/psLibSDRS_Astrom.tex	(revision 3069)
@@ -694,2 +694,62 @@
 \end{verbatim}
 Calculate the parallax factor for the given exposure.  \tbd{Why do we need this?}.
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\subsection{Astrometry and World Coordinate System}
+
+The FITS World Coordinate System (WCS) headers are commonly employed
+with astronomical images in order to relate pixels to celestial (or
+otherwise) coordinates.  Since it is a FITS standard, we must be able
+to read and write from WCS into our internal format.  For the time
+being, we will consider only celestial WCS (i.e., no spectral
+wavelength calibrations, etc).  Because WCS does not support the
+multiple layers that we have built for \PS{}, we will use a simple
+internal representation: a transformation, which handles any
+distortions (i.e., goes directly from the coordinate frame of the
+image to the tangent plane); and the projection.
+
+The FITS WCS standard is described in Calabretta \& Greisen, A\&A,
+2002, 395, 1077.  An extension to the standard, the TNX projection, is
+described at \url{http://iraf.noao.edu/projects/ccdmosaic/tnx.html}.
+This extension is in widespread use and must also be supported for
+both reading and writing.
+
+\begin{verbatim}
+bool psAstrometryReadWCS(psPlaneTransform **transform, // Output transformation
+                         psProjection **projection, // Output projection
+                         psMetadata *header // Input FITS header
+                         );
+bool psAstrometryWriteWCS(psMetadata *header, // Output FITS header
+                          psPlaneTransform *transform, // Input transformation
+		          psProjection *projection // Input projection
+                          );
+bool psAstrometrySimplify(psPlaneTransform **transform, // Output transformation
+                          psProjection **projection, // Output projection
+			  psCell *cell // Cell for which to generate transform and projection
+                          );
+\end{verbatim}			
+
+\code{pmReadAstrometry} shall parse the specified FITS \code{header},
+returning new instances of the \code{transform} and \code{projection}
+that represent the WCS.  The function shall return \code{true} if it
+was able to successfully generate the outputs; otherwise it shall
+return \code{false}.
+
+\code{pmWriteAstrometry} shall add WCS keywords to the supplied FITS
+\code{header} that implement the given \code{transform} and
+\code{projection}.  The function shall return \code{true} if it was
+able to successfully generate the output; otherwise it shall return
+\code{false}.
+
+\code{pmSimplifyAstrometry} shall take a \code{cell} and simplify the
+internal astrometric representation (\code{cell->toFPA} or equivalent,
+\code{cell->parent->parent->toTangentPlane} and
+\code{cell->parent->parent->grommit}) to a single \code{transform} and
+\code{projection}.  This allows the subsequent use of
+\code{pmWriteAstrometry} in the case that we have only the
+multi-layered \PS{} internal astrometric representation.  The function
+shall return \code{true} if it was able to successfully generate the
+output; otherwise it shall return \code{false}.
+
