Index: /trunk/doc/modules/ModulesSDRS.tex
===================================================================
--- /trunk/doc/modules/ModulesSDRS.tex	(revision 1109)
+++ /trunk/doc/modules/ModulesSDRS.tex	(revision 1110)
@@ -1,3 +1,3 @@
-%%% $Id: ModulesSDRS.tex,v 1.3 2004-06-26 00:34:15 price Exp $
+%%% $Id: ModulesSDRS.tex,v 1.4 2004-06-26 03:42:48 price Exp $
 \documentclass[panstarrs]{panstarrs}
 
@@ -394,14 +394,12 @@
 
 Given an input image and region to keep, \code{psPhase2Trim} shall
-trim the input image, leaving only the specified region.  The API
-shall be the following:
-\begin{verbatim}
-/** Trims the input image to remove the edges corrupted by OT shifting, and the overscan. */
-psReadout *psPhase2Trim(psReadout *in,  ///< Input image to be trimmed, and output
-                        const psImageRegion *region ///< Region to keep
-                        );
-\end{verbatim}
-
-Note that the trim shall be performed on the input image in-place.
+trim the input image, \code{in}, leaving only the specified region,
+\code{region}.  The API shall be the following:
+\begin{verbatim}
+psReadout *psPhase2Trim(psReadout *in, const psImageRegion *region);
+\end{verbatim}
+
+Note that the trim shall be performed on the input image in-place, so
+that the input image is modified.
 
 The offset of the input image (\code{in->x0} and \code{in->y0}) shall
@@ -420,13 +418,16 @@
 \subsection{Non-linearity}
 
-Given an input image, and the coefficients of a polynomial,
-\code{psPhase2CorrectNonLinearity} shall correct the input image for
-non-linearity by applying the polynomial to the flux of each pixel.
+We shall specify two functions to perform the non-linearity
+correction, in order to implement the possible methods of specifying
+the correction.
+
+The first, \code{psPhase2NonLinearityPolynomial} shall correct the
+input image for non-linearity by applying the given polynomial,
+\code{coeff}, to the flux of each pixel in the input image, \code{in}.
 The API shall be the following:
+
 \begin{verbatim}
 /** Applies the correction for detector non-linearity. */
-psReadout *psPhase2CorrectNonLinearity(psReadout *in, ///< Input image to be corrected, and output
-                                       const psPolynomial1D *coeff ///< Polynomial with which to correct
-                                       );
+psReadout *psPhase2CorrectNonLinearity(psReadout *in, const psPolynomial1D *coeff);
 \end{verbatim}
 
@@ -434,13 +435,31 @@
 caller, likely from the image metadata.
 
+The second function, \code{psPhase2NonLinearityLookup} shall correct
+the input image for non-linearity by using a lookup table.  The API
+shall be the following:
+
+\begin{verbatim}
+psReadout *psPhase2NonLinearityLookup(psReadout *in, const psVector *inFlux, const psVector *outFlux);
+\end{verbatim}
+
+For each pixel in the input image, the function shall find the flux
+value in the \code{inFlux} vector, and replace the flux with the
+corresponding value in the \code{outFlux} vector.  If the sizes of the
+\code{inFlux} and \code{outFlux} vectors differ, then the function
+shall generate a warning, and the longer vector shall be truncated to
+the length of the shorter.  The \code{inFlux} vector may be assumed
+to be pre-sorted.
+
+Both \code{psPhase2NonLinearityPolynomial} and
+\code{psPhase2NonLinearityLookup} shall modify the input image
+in-place.
+
 \subsection{Flat-fielding}
 
 Given an input image and a flat-field image, \code{psPhase2FlatField}
-shall divide the input image by the flat-field image.  The API shall be the following:
-\begin{verbatim}
-/** Flat-fields the image. */
-psReadout *psPhase2FlatField(psReadout *in, ///< Input image to be flat-fielded, and output
-                             const psImage *flat ///< Flat-field image
-                             );
+shall divide the input image by the flat-field image.  The API shall
+be the following:
+\begin{verbatim}
+psReadout *psPhase2FlatField(psReadout *in, const psImage *flat);
 \end{verbatim}
 
@@ -456,8 +475,10 @@
 
 Pixels which are negative or zero in the \code{flat} shall be masked
-in the input image.
+in the input image with the value \code{PS_MASK_FLAT} (see
+\S\ref{sec:maskValues}).
 
 The function shall not normalise the \code{flat}; this responsibility
-is left to the caller.
+is left to the caller.  This function is basically equivalent to a
+divide, but with care for the region that is divided.
 
 \subsection{Subtract sky}
@@ -484,6 +505,8 @@
 \end{verbatim}
 
-Note that the input image shall be subtracted in-place.  The function
-shall return the subtracted image, and also update the polynomial,
+The polynomial specification, \code{poly}, specifies the order of the
+polynomial to be used in fitting the background.  Note that the input
+image, \code{in}, shall be subtracted in-place.  The function shall
+return the subtracted image, and also update the polynomial,
 \code{poly}, to hold the polynomial coefficients used in the
 subtraction, and update the vector \code{outNorms} to hold the
@@ -491,5 +514,6 @@
 subtraction.  The \code{outNorms} vector shall be resized if necessary
 to match the number of template sky images in the list
-\code{skyImages}.
+\code{skyImages}.  If the polynomial specification is \code{NULL}, then
+no polynomial shall be fit to the input image.
 
 Note that the input image, \code{in}, and the template sky images,
@@ -503,10 +527,14 @@
 function shall generate an error.
 
-If the size of a source in the \code{catalog} is \code{size}, then the
-radius to mask around the source before fitting the background shall
-be \code{radiusMultiply} $\times$ \code{size} + \code{radiusAdd}.
+The \code{catalog} shall be a linked list of \code{psObject} which
+corresponds to objects on the input image.  If the size of a source in
+the \code{catalog} is \code{size}, then the radius to mask around the
+source before fitting the background shall be \code{radiusMultiply}
+$\times$ \code{size} + \code{radiusAdd}.
 
 \tbd{Are the catalog stars in celestial or pixel coordinates?  I lean
 to pixel coordinates.}
+
+\tbd{What size do we use?  FWHM?}
 
 When fitting a polynomial, the function shall bin the input image by
@@ -529,4 +557,24 @@
 The following modules mask various defects on an image.
 
+\subsection{Mask values}
+\label{sec:maskValues}
+
+We define several mask values for use in the phase 2 processing:
+\begin{verbatim}
+/** Mask values */
+typedef enum {
+    PS_MASK_TRAP,			// The pixel is a charge trap
+    PS_MASK_BADCOL,			// The pixel is a bad column
+    PS_MASK_SAT,			// The pixel is saturated
+    PS_MASK_FLAT,			// The pixel is non-positive in the flat-field
+    PS_MASK_CR_MORPH			// The pixel is determined to be a cosmic ray, based on its morphology
+} psMaskValue;
+\end{verbatim}
+
+Of these, masks for the charge traps need to be grown by the
+extent of the OT convolution kernel.  For other pixel types,
+orthogonal transfer of the flux in this pixel will not (necessarily)
+affect the flux in neighbouring pixels
+
 \subsection{Bad pixels}
 
