Index: /trunk/doc/modules/ChangeLogSDRS.tex
===================================================================
--- /trunk/doc/modules/ChangeLogSDRS.tex	(revision 3214)
+++ /trunk/doc/modules/ChangeLogSDRS.tex	(revision 3215)
@@ -1,3 +1,3 @@
-%%% $Id: ChangeLogSDRS.tex,v 1.13 2005-02-08 04:56:24 eugene Exp $
+%%% $Id: ChangeLogSDRS.tex,v 1.14 2005-02-14 21:08:35 eugene Exp $
 
 \subsection{Changes from version 00 to version 01}
@@ -45,3 +45,5 @@
 \item added enum psSourceType
 \item Specified appropriate image types for the phase 2 modules (bug 258).
+\item clarified pmSourceRoughClass
+\item clarified pmSourceAddModel, pmSourceSubModel
 \end{itemize}
Index: /trunk/doc/modules/ModulesSDRS.tex
===================================================================
--- /trunk/doc/modules/ModulesSDRS.tex	(revision 3214)
+++ /trunk/doc/modules/ModulesSDRS.tex	(revision 3215)
@@ -1,3 +1,3 @@
-%%% $Id: ModulesSDRS.tex,v 1.30 2005-02-08 04:56:24 eugene Exp $
+%%% $Id: ModulesSDRS.tex,v 1.31 2005-02-14 21:08:35 eugene Exp $
 \documentclass[panstarrs]{panstarrs}
 
@@ -11,5 +11,5 @@
 \project{Pan-STARRS Image Processing Pipeline}
 \organization{Institute for Astronomy}
-\version{03}
+\version{04}
 \docnumber{PSDC-430-012}
 
@@ -31,4 +31,5 @@
 02 & 2004 Nov 30 & final for cycle 4 \\ \hline
 03 & 2005 Jan 21 & draft for cycle 5 \\ \hline
+04 & 2005 Feb 14 & final for cycle 5 \\ \hline
 \RevisionsEnd
 
@@ -1192,5 +1193,5 @@
 \end{verbatim}
 
-A given source may be identified as most-likey to be one of several
+A given source may be identified as most-likely to be one of several
 source types.  The \code{pmSource} entry \code{pmSourceType} defines
 the current best-guess for this source.  \tbd{The values given below
@@ -1203,8 +1204,24 @@
   PM_SOURCE_GALAXY;
   PM_SOURCE_DEFECT;
+  PM_SOURCE_SATURATED;
   PM_SOURCE_SATSTAR;
   PM_SOURCE_FAINTSTAR;
   PM_SOURCE_BRIGHTSTAR;
+  PM_SOURCE_OTHER;
 } pmSourceType; 
+\end{verbatim}
+
+\begin{verbatim}
+typedef enum {
+  PM_CONTOUR_CRUDE;
+} pmContourType; 
+\end{verbatim}
+
+Allocators for the above structures are defined as follows:
+\begin{verbatim}
+pmSource   *pmSourceAlloc ();
+pmPeak     *pmPeakAlloc (int x, int y, float counts, psPeakType class);
+pmMoments  *pmMomentsAlloc ();
+pmModel    *pmModelAlloc (pmModelType type);
 \end{verbatim}
 
@@ -1216,5 +1233,5 @@
 
 \begin{verbatim}
-psVector *pmFindVectorPeaks(const psVector vector, float threshold);
+psVector *pmFindVectorPeaks(const psVector *vector, float threshold);
 \end{verbatim}
 
@@ -1252,6 +1269,4 @@
 this function is a list of \code{pmPeak} entries.
 
-\tbd{do we need a function psVector *psImageRowVector (psImage *image, int row);}
-
 \begin{verbatim}
 psList *pmCullPeaks(psList *peaks, float maxvalue, const psRegion *valid);
@@ -1265,32 +1280,96 @@
 
 \begin{verbatim}
-pmSource *pmSourceLocalSky(const psImage *image, const pmPeak *peak, float inner_radius, float outer_radius), 
+pmSource *pmSourceLocalSky(const psImage *image, const pmPeak *peak, psStatsOptions statsOptions, float innerRadius, float outerRadius);
 \end{verbatim}
 
 Measure the local sky in the vicinity of the given \code{peak}.  The
-image pixels in the square annulus with inner and outer radii as
-specified are used to measure the median \tbd{(clipped mean?)
-(statistic from psStats?)} in the vicinity of the the specified peak
-coordinates.  The resulting sky is applied to the \code{pmMoments}
-element of the allocated \code{pmSource} structure.  The input
-\code{peak} is also added to the \code{pmSource} element, which is
-returned.
-
-\begin{verbatim}
-pmSource *pmSourceMoments(pmSource *source, const psImage *image, float radius), 
+image pixels in the square annulus with inner and outer half-width
+('square-radii') as specified are used to measure the local background
+in the vicinity of the the specified peak coordinates.  The local
+background measurement uses the specified statistic passed in via the
+\code{stats} entry.  This function allocates a \code{pmSource}
+structure and uses the resulting sky to set the value of the
+\code{pmMoments.sky} element of that \code{pmSource} structure.  The
+input \code{peak} is also placed on the \code{pmSource} structure,
+which is then returned.
+
+\begin{verbatim}
+bool pmSourceMoments(pmSource *source, const psImage *image, float radius);
 \end{verbatim}
 
 Measure source moments for the given \code{source}, using the value of
-\code{source.moments.sky} provided as the local background value.  The
-resulting moment values are applied to the \code{source.moments}
-entry, and the source is returned.  The moments are measured within
-the given radius of the \code{source.peak} coordinates.
-
-\begin{verbatim}
-pmSource *pmSourceRoughClass(pmSource *source, float saturate, float SNlim, const psRegion *valid);
+\code{source.moments.sky} provided as the local background value and
+the peak coordinates as the initial source location.  The resulting
+moment values are applied to the \code{source.moments} entry, and the
+source is returned.  The moments are measured within the given
+circular radius of the \code{source.peak} coordinates.  The return
+value indicates the success (TRUE) of the operation.
+
+\begin{verbatim}
+bool pmSourceRoughClass(pmArray *source, psMetadata *metadata);
 \end{verbatim}
 
 Based on the specified data values, make a guess at the source
-classification.  
+classification.  The sources are provides as a \code{psArray} of
+\code{psSource} entries.  Definable parameters needed to make the
+classification are provided to the routine with the \code{psMetadata}
+structure.  The rules below refer to values which can be extracted
+from the metadata using the given keywords.  Except as noted, the data
+type for these parameters are \code{psF32}.
+
+The following rules are used to make the classification.  Sources with
+peak pixel above the value of \code{SATURATE} are identified as type
+\code{PM_SOURCE_SATURATED}.  For the remaining sources, the signal to
+noise of the detection is approximated by:
+\[
+SN = \frac{S \sqrt{g}}{\sqrt{S + A B + \frac{A R_e^2}{\sqrt{g}}}}
+\]
+where 
+\[
+A = \pi \sigma_x \sigma_y
+\]
+and $\sigma_x$ is \code{pmMoment.Sx}, $\sigma_y$ is
+\code{pmMoment.Sy}, $B$ is \code{pmMoment.Sky} and $S$ is
+\code{pmMoment.Sum}. The two parameters, $g$ and $R_e$ are the gain,
+stored with the metadata keyword \code{GAIN} and the read-noise in
+electrons, stored with the metadata keyword \code{READ_NOISE}.
+
+Sources with $SN$ less than \code{FAINT_SN_LIM} are identified as type
+\code{PM_SOURCE_FAINTSTAR}.  Sources with $SN$ greater than
+\code{PSF_SN_LIM} are then selected as possible PSF stars.  These
+sources are used to determine a guess at the shape of the PSF, based
+on the collection of $\sigma_x$ and $\sigma_y$ values.
+
+The goal is to identify and characterize the stellar clump within the
+$\sigma_x, \sigma_y$ plane.  To do this, an image is constructed to
+represent this plane.  The units of $\sigma_x$ and $\sigma_y$ are in
+image pixel.  A pixel in this analysis image represents 0.1 pixels in
+the input image.  The dimensions of the image need only be 10 pixels.
+The peak pixel in this image (above a threshold of half of the image
+maximum) is found.  The coordinates of this peak pixel represent the
+2D mode of the $\sigma_x, \sigma_y$ distribution.  The sources with
+$\sigma_x, \sigma_y$ within 0.2 pixels of this value are then used to
+calculate the median and standard deviation of the $\sigma_x,
+\sigma_y$ values.  These resulting values are placed back on the
+metadata structure with the metadata names \code{PSF_CLUMP_X},
+\code{PSF_CLUMP_dX} and \code{PSF_CLUMP_Y}, \code{PSF_CLUMP_dY}.
+
+All sources with:
+\[ |\sigma_x - \mbox{CLUMP}_x| < \mbox{CLUMP}_{dx}\]
+and
+\[ |\sigma_y - \mbox{CLUMP}_y| < \mbox{CLUMP}_{dy}\]
+should be identified as type \code{PM_SOURCE_PSFSTAR}.  Sources with 
+\[ \sigma_x < \mbox{CLUMP}_{x} - \mbox{CLUMP}_{dx}\]
+and 
+\[ \sigma_y < \mbox{CLUMP}_{y} - \mbox{CLUMP}_{dy}\]
+should be identified as type \code{PM_SOURCE_DEFECT}.  Sources with
+\[ \sigma_x > \mbox{CLUMP}_{x} + \mbox{CLUMP}_{dx}\]
+and 
+\[ \sigma_y > \mbox{CLUMP}_{y} + \mbox{CLUMP}_{dy}\]
+should be identified as type \code{PM_SOURCE_GALAXY}.  All other
+sources should be identified as type \code{PM_SOURCE_OTHER}.
+\tbd{need to exclude stars outside valid data region}.
+
+The return value indicates the success (TRUE) of the operation.
 
 \subsection{Object Fitting}
@@ -1320,5 +1399,5 @@
 
 \begin{verbatim}
-bool pmSourceSetPixelsCircle(pmSource *source, const psImage *image, float radius);
+bool pmSourceSetPixelsCircle(pmSource *source, const psImage *image, float radius, int maskVal);
 \end{verbatim}
 
@@ -1326,32 +1405,35 @@
 This operation creates the \code{source.pixels} and \code{source.mask}
 entries for the source based on a circular aperture centered on the
-source centroid (or peak?).  The \code{source.pixels} is a subimage of
-the input image.  The function returns \code{TRUE} on success or
-\code{FALSE} on failure.
-
-\begin{verbatim}
-bool pmSourceModelGuess(pmSource *source, const psImage *image);
-\end{verbatim}
-
-Convert available data to an initial guess for the given model.  The
-method of defining the model parameter guesses are specified for each
-model below.  The guess values are placed in the model parameters.  The
+source centroid, if the \code{pmSource.pmMoments} entry exists, or
+\code{pmSource.pmPeak} if it does not.  The \code{source.pixels} is a
+subimage of the input image.  The function returns \code{TRUE} on
+success or \code{FALSE} on failure.
+
+\begin{verbatim}
+bool pmSourceModelGuess(pmSource *source, const psImage *image, pmModelType model);
+\end{verbatim}
+
+Convert available data to an initial guess for the given model.  This
+function allocates a \code{pmModel} entry for the \code{pmSource}
+structure based on the provided model selection.  The method of
+defining the model parameter guesses are specified for each model
+below.  The guess values are placed in the model parameters.  The
 function returns \code{TRUE} on success or \code{FALSE} on failure.
 
 \begin{verbatim}
-psArray *pmSourceContour(const pmSource *source, const psImage *image, float level, int mode);
+psArray *pmSourceContour(const pmSource *source, const psImage *image, float level, pmContourType type);
 \end{verbatim}
 
 Find points in a contour for the given source at the given level.  If
-mode is \code{PM_CONTOUR_CRUDE}, the contour is found by starting at
+\code{type} is \code{PM_CONTOUR_CRUDE}, the contour is found by starting at
 the source peak, running along each pixel row until the level is
 crossed, then interpolating to the level coordinate for that row.
 This is done for each row, with the starting point determined by the
 midpoint of the previous row, until the starting point has a value
-below the contour level.  The resulting contour consists of two
-vectors giving the x and y coordinates of the contour levels.  This
-function may be used as part of the model guess inputs.
-
-\tbd{Other modes may be specified in the future for more refined contours}
+below the contour level.  The returned contour consists of two vectors
+giving the x and y coordinates of the contour levels.  This function
+may be used as part of the model guess inputs.
+
+\tbd{Other contour types may be specified in the future for more refined contours}
 
 \begin{verbatim}
@@ -1367,19 +1449,15 @@
 
 \begin{verbatim}
-bool pmSourceAddModel(psImage *image, pmSource *source, bool center);
-\end{verbatim}
-
-Add the given source model flux to the provided image.  The boolean
-option center selects if the source is recentered to the image center
-or if it is placed at its centroid location.  The pixel range in the
-target image is at most the pixel range specified by the
-\code{source.pixels} image.  The success status is returned.  
-
-\begin{verbatim}
-bool pmSourceSubModel(pmSource *source);
-\end{verbatim}
-
-Subtract the model from its image pixels given by
-\code{source.pixels}.  The success status is returned.  
+bool pmSourceAddModel(psImage *image, pmSource *source, bool center, bool sky);
+bool pmSourceSubModel(psImage *image, pmSource *source, bool center, bool sky);
+\end{verbatim}
+
+Add or subtract the given source model flux to/from the provided
+image.  The boolean option \code{center} selects if the source is
+recentered to the image center or if it is placed at its centroid
+location.  The boolean option \code{sky} selects if the background sky
+is applied (\code{TRUE}) or not.  The pixel range in the target image
+is at most the pixel range specified by the \code{source.pixels}
+image.  The success status is returned.
 
 \subsection{Basic Object Models}
