Index: trunk/doc/release.2015/ps1.analysis/analysis.tex
===================================================================
--- trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 40559)
+++ trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 40584)
@@ -184,5 +184,5 @@
 
 The photometric and astrometric precision goals for the Pan-STARRS\,1
-surveys were quite stringent: photmetric accuracy of 10
+surveys were quite stringent: photometric accuracy of 10
 millimagnitudes, relative astrometric accuracy of 10 milliarcseconds
 and absolute astrometric accuracy of 100 milliarcseconds with respect
@@ -252,11 +252,10 @@
 In the process, the source analysis software was written using the
 data analysis C-code library written for the IPP, \code{psLib}
-\citep{psLib}.  Components of the photometry code were integrated into
-the IPP's mid-level astronomy data analysis toolkit called
-\code{psModules} \citep{psModules}.  The resulting software,
-`\code{psphot}', can be used either as a stand-alone C program, or as
-a set of library functions which may be integrated into other programs
-
-% \note{add refs to the psLib and psModules ADDs} : ref to online docs?
+\citep{magnier2017.datasystem}.  Components of the photometry code
+were integrated into the IPP's mid-level astronomy data analysis
+toolkit called \code{psModules} \citep{magnier2017.datasystem}.  The
+resulting software, `\code{psphot}', can be used either as a
+stand-alone C program, or as a set of library functions which may be
+integrated into other programs
 
 Several variants of \code{psphot} have been used in the PS1 PV3
@@ -703,16 +702,24 @@
 \begin{figure}[htbp]
   \begin{center}
-  \includegraphics[width=\hsize]{{pics/FWHM.smooth.trend.ps1}.\plotext}
-  \caption{\label{fig:moments.window} Example of the biases encountered when measuring the second
-    moments.  A simulated image was generated using the PS1 PSF
-    profile.  Each panel corresponds to a different value of
-    $\sigma_w$, as marked.  The solid red line is the true FWHM of the
-    PSF used to generate the stars.  The blue solid line is the FWHM
-    of the window function ($2.35\sigma_w$).  The gray dots are the
-    FWHM derived from the measured second moments for stars in the
-    image.  The dotted blue line is the target (65\% of the window
-    function).  In this example, we would choose $\sigma_w$ between
-    0.5 and 0.8 arcseconds so the dotted blue line would match the
-    bright end of the gray dots.}
+% \includegraphics[width=0.6\hsize]{{pics/FWHM.smooth.trend.ps1}.\plotext}
+  \includegraphics[width=0.95\hsize]{{pics/FWHM.smooth.trend.ps1}.png}
+  \caption{\label{fig:moments.window} Example of the biases
+    encountered when measuring the second moments.  A simulated image
+    was generated using the PS1 PSF profile.  Each panel corresponds
+    to a different value of $\sigma_w$, corresponding to the window
+    FWHM values as marked.  The solid red line is the true FWHM of the
+    PSF used to generate the stars (1.4 arcsec in all cases).  The
+    blue solid line is the FWHM of the window function.  The gray dots
+    are the FWHM derived from the measured second moments for stars in
+    the image.  The median of this distribution (mag $< -10$) is
+    listed as ``obs''.  The ratio of the median FWHM to the FWHM of
+    the window function is listed as ``ratio'', while the ratio of the
+    median FWHM to the true stellar FWHM is listed as ``bias''.  The
+    dotted blue line is the target (65\% of the window function).  In
+    this example, we would choose $\sigma_w$ between 0.5 and 0.8
+    arcseconds so the dotted blue line would match the bright end of
+    the gray dots.   See discussion in the text for the choice of
+    target window.
+}
   \end{center}
 \end{figure}
@@ -726,11 +733,11 @@
 appropriate aperture in which the moments are measured.  We also apply
 a ``window function'', down-weighting the pixels by a Gaussian,
-centered on the object, with size $\sigma_W$ chosen to be large
+centered on the object, with size $\sigma_w$ chosen to be large
 compared to the PSF size, $\sigma_{\rm PSF}$.  This window function
 reduces the noise of the measurement of the moments by suppressing the
 noisy pixels at high radial distance as well as by reducing the
-contaminating effects of neighboring stars.  The choice of $\sigma_W$
+contaminating effects of neighboring stars.  The choice of $\sigma_w$
 and the aperture is an iterative process: for a given value of
-$\sigma_W$, the PSF stars will have a measured value of the PSF size,
+$\sigma_w$, the PSF stars will have a measured value of the PSF size,
 $\sigma^{\prime}_{\rm PSF}$ which different from the true value due to
 the effect of the window function.  The measured value of the PSF size
@@ -743,9 +750,10 @@
 radial profile of the PS1 PSF model with $\sigma_{\rm PSF}$
 corresponding to a FWHM of 1.4 arcseconds.  As the window function
-$\sigma_W$ is increased, the measured FWHM for the bright simulated
-stars rises to meet the truth value.  For small values of $\sigma_W$,
+$\sigma_w$ is increased, the measured FWHM for the bright simulated
+stars rises to meet the truth value.  For small values of $\sigma_w$,
 fainter stars are biased to low measured values of the FWHM.  For
-large values of $\sigma_W$, the faint stars are biased to higher
-values and the scatter increases.
+large values of $\sigma_w$, the faint stars are biased to higher
+values and the scatter increases.  We attempt to minimize the scatter
+and trends with magnitude at the cost of overall bias.
 
 In a real image, we do not know the true value of the PSF size.  If we
@@ -763,10 +771,10 @@
 brightness.
 
-To choose the value of $\sigma_W$, we try a sequence of values
+To choose the value of $\sigma_w$, we try a sequence of values
 spanning a range guaranateed to contain any reasonable seeing values.
 The values are specified in the \code{psphot} recipe as
 \code{PSF.SIGMA.VALUES} and have the following values for PS1 PV3: (1,
 2, 3, 4.5, 6, 9, 12, 18) pixels $\approx$ (0.26, 0.51, 0.77, 1.15,
-1.54, 2.3, 3.1, 4.6) arcseconds.  For each of these $\sigma_W$ values,
+1.54, 2.3, 3.1, 4.6) arcseconds.  For each of these $\sigma_w$ values,
 we then select candidate PSF stars based on the distribution of the
 measured $\sigma^{\prime}_{\rm PSF}$ in the two principal directions:
@@ -776,5 +784,5 @@
 \frac{\sigma_{x} + \sigma{y}}{2 \sigma_w}$, i.e., the ratio of the
 window size to the observed PSF size.  We interpolate to find a value
-of $\sigma_W$ for which $\rho_\sigma$ is expected to be 0.65.  We use
+of $\sigma_w$ for which $\rho_\sigma$ is expected to be 0.65.  We use
 an aperture with a radius of 4$\sigma_w$ to select the pixels for the
 measurement of the moments.
@@ -849,4 +857,5 @@
 
 \subsubsection{PSF Model vs Source Model}
+\label{sec:Source.Model}
 
 The point-spread-function (PSF) of an image describes the shape of all
@@ -1007,10 +1016,10 @@
 selected by \code{psphot}, though sources which have more than a
 certain number of saturated pixels are excluded at this stage.  The
-program then examines the 2-D plane of $\sigma_x, \sigma_y$ in search
+program then examines the 2-D plane of $M_{x,x}, M_{y,y}$ in search
 of a concentrated clump of sources (see
 Figure~\ref{fig:moment.class}).  To do this, it constructs an
-artificial image with pixels representing the value of $\sigma_x,
-\sigma_y$, using $0.1 \sigma_w$ as the size of a pixel in this
-artificial image.  The binned $\sigma_x, \sigma_y$ plane is then
+artificial image with pixels representing the value of $M_{x,x},
+M_{y,y}$, using $0.1 \sigma^2_w$ as the size of a pixel in this
+artificial image.  The binned $M_{x,x}, M_{y,y}$ plane is then
 examined to find a significant peak.  Unless the image is extremely
 sparse, such a peak will be well-defined and should represent the
@@ -1027,6 +1036,4 @@
 % (\sigma_x^2) not \sigma_x,\sigma_y)
 
-\note{re-work wording above reflecting comment above}
-
 Once a peak has been detected in this plane, the centroid and second
 moments of this peak are measured.  All sources which land within 2
@@ -1037,6 +1044,6 @@
   \begin{center}
   \includegraphics[width=\hsize]{{pics/moment.class}.\plotext}
-  \caption{\label{fig:moment.class} Illustration of PSF star selection using the FWHM derived
-    from the second moments in $X_{\rm ccd}$ and $Y_{\rm ccd}$
+  \caption{\label{fig:moment.class} Illustration of PSF star selection
+    using the second moments in $X_{\rm ccd}$ and $Y_{\rm ccd}$
     directions.  The dominant clump is located in this diagram.
     Galaxies tend to have a range of sizes and thus spread out above
@@ -1088,5 +1095,5 @@
 \begin{table}
 \caption{\label{tab:psf.order.nstars} Minimum number of stars required
-  for a given order of the PSF 2D variations.}\vspace{-0.5cm}
+  for a given order of the PSF 2D variations.} % \vspace{-0.5cm}
 \begin{center}
 \begin{tabular}{llll}
@@ -1215,108 +1222,68 @@
 PSF.
 
-\subsubsection{Full PSF Model Fitting}
-
-% \note{review the discussion below}
-
-Once a PSF model has been selected for an image, \code{psphot} attempts to
-fit all of the detected sources, above a user-defined signal-to-noise
-ratio with the PSF model.  For these fits, the dependent parameters
-are fixed by the PSF model and only the 4 independent source model
-parameters are allowed to vary in the fit.  \code{psphot} again uses
-Levenberg-Marquardt minimization for the non-linear fitting.  The
-sources are fitted in their S/N order, starting with the brightest and
-working down to the user-specified limit, with the other sources
-subtracted as discussed above.
-
-\note{code review for the next bit}
-
-Once a solution has been achieved for a source, \code{psphot} attempts to
-judge the quality of the PSF model as a representation of the source
-shape.  To do this, it calculates the next step of the minimization
-{\em allowing the shape parameters to vary}.  This step, essentially
-the Gauss-Newton minimization distance from the current local minimum,
-should be very small if the source is well represented by the PSF, but
-large if the PSF is not a good representation of the source flux.  The
-model quality is judged by the change in the two shape parameters
-which represent the 2D size of the source.  For the case of the
-elliptical Gaussian, these two parameters are $\sigma_x$ and
-$\sigma_y$.  For a generic model, the shape parameters may be defined
-differently, but there should always be two parameters which scale the
-source size in two dimensions.  Currently, \code{psphot} requires the two
-relevant shape parameters to be the first two dependent parameters in
-the list of model parameters (ie, parameters 4 \& 5).
-
-The expected distribution of the variation of the two shape parameters
-will be a function of the signal-to-noise of the source in question
-and the value of the shape parameter itself.  The expected standard
-deviation on the shape parameter is, eg, $\sigma_x / {\rm S/N}$.  If
-the source is well-represented by the PSF, then the shape parameter
-values should be close to their minimization value.  We can thus ask,
-for each source, given the measured amplitude of the Gauss-Newton
-step, how many standard deviations from the expected value (of 0.0) is
-this particular value?  Sources for which the variation in the shape
-parameters is a large positive number of standard deviations are
-likely to be better represented by a larger flux distribution than the
-PSF (eg, a Galaxy or Comet, etc).  Sources for which the variation in
-the shape parameters is a large negative number of standard deviations
-are likely to be better represented by a smaller flux distribution
-than the PSF (ie, a cosmic ray or other defect).  A user-defined
-number of standard deviations is used to select these two cases, and
-to flag the source as a likely galaxy (really meaning 'extended') or
-as a likely defect.  
-
-At this stage of the analysis, \code{psphot} uses two additional indicators
-to identify good and poor PSF fits.  The first of these is the
-signal-to-noise ratio.  It is possible for the peak finding algorithm
-to identify peaks in locations which are not actually a normal peak.
-Some of these cases are in the edges of saturated, bleeding columns
-from bright stars, in the nearly flat halos of very bright stars, and
-so on.  In these cases, a local peak exists, with a lower nearby sky
-region.  However, the fitted PSF model cannot converge on the peak
-because it is very poorly defined (perhaps only existing in the
-smoothed image).  The fit can either fail to converge or it can
-converge on a fit with very low or negative peak flux / flux
-normalization.  \code{psphot} will flag any non-convergent PSF fit and any
-source with PSF S/N ratio lower than a user-defined cutoff.  It is
-also useful to identify very poor fits by setting a maximum Chi-Square
-cutoff for sources.  
-
-As the sources are fitted to the PSF model, those which survive the
-exclusion stage are subtracted from the image.  The subtraction
-process modifies the image pixels (removing the fitted flux, though
-not the locally fitted background) but does not modify the mask or the
-variance images.  The signal-to-noise ratio in the image after
-subtraction represents the significance of the remaining flux.  If the
-subtractions are sufficiently accurate models of the PSF flux
-distribution, the remaining flux should be below 1 $\sigma$
-significance.  In practice the cores of bright stars are poorly
-represented and may have larger residual significance. 
-
-\subsubsection{Blended Sources}
-
-Sources which are blended with other sources are fitted together as a set of
-PSFs.  A single multi-source fit is performed on all blended peaks.
-The resulting fits are evaluated independently and any which are
-determined to be PSFs are subtracted from the image.
-
-\subsubsection{Double Sources}
-
-Sources which are judged to be non-PSF-like are confronted with two
-possible alternative choices.  First, the source is fitted with a
-double-source model.  In this pass, the assumption is made that there
-are two neighboring sources, but the peaks are blended together, or
-otherwise not distinguished.  The initial guess for the two peaks is
-made by splitting the flux of the single source in half and locating
-the two starting peaks at +/- 2 pixels from the original peak along
-the direction of the semi-major axis of the sources, as measured from
-the second moments.  In order for the two-source model to be accepted,
-both sources must be judged as a valid PSF source.  Otherwise, the
-double-PSF model is rejected and the source is fitted with the
-available non-PSF model or models.
+\subsubsection{Radial Profile Wings}
+
+We attempt to measure the radial profile of sources in order to find
+the radius at which the flux of the source is matches the sky.  In
+this analysis, a series of up to 25 radial bins with power-law spacing
+are defined and the flux of the source in each annulus is measured.
+The ``sky radius'' is defined to be the radius at which the (robust
+median) flux in the annulus is within 1 $\sigma$ of the local sky
+level.  If this limit is not reached before the slope of the flux from
+one annulus to the next is less than a user-defined limit, then the
+annulus at which the slope reaches this limit is used to define the
+sky radius.  These values are saved in the output smf / cmf files, but
+not sent to the PSPS.  The sky radius value is used below in the
+calculation of the Kron magnitude.
+
+\subsubsection{Kron Magnitudes}
+\label{sec:kron.mags}
+
+Preliminary Kron radius and flux values \citep{1980ApJS...43..305K}
+are calculated soon after sources are detected
+(Section~\ref{sec:moments}).  However, these preliminary values are
+not accurate due to the window-functions applied.  After sources have
+been characterized and the PSF model is well-determined, the Kron
+parameters are re-calculated more carefully.  In this version of the
+calculation, following the algorithm described by \cite{sextractor},
+the image is first smoothed by Gaussian kernel with $\sigma = 1.7$
+pixels, corresponding to a FWHM of 1.0\arcsec\ in the PS1 stack
+images.  Next, the Kron radius is determined in an iterative process:
+the first radial moment is measured using the pixels in an aperture
+6$\times$ the first radial moment from the previous iteration.  On the
+first iteration, the sky radius is used in place of the first radial
+moment.  By default, 2 iterations are performed.  The Kron radius is
+defined to be 2.5$\times$ the first radial moment.  The Kron flux is
+the sum of pixel fluxes within the Kron radius.  We also calculate the
+flux in two related annular apertures: the Kron inner flux is the sum
+of pixel values for the annulus $R_1 < r < 2.5 R_1$, while the Kron
+outer flux is the sum of pixel values for $2.5 R_1 < r < 4 R_1$.
+
+Two details in the calculation above should be noted.  First, for
+faint sources, noise in the measurement of the 1st radial moment may
+result in an excessively small aperture for the successive
+calculations.  The window used for the calculations is constrained to
+be at least the size of the aperture based on the PSF stars
+(Section~\ref{sec:moments}).  At the other extreme, noise may make the radius
+grow excessively, resulting in an unrealistically low effective
+surface brightness.  The aperture is constrained to be less than a
+maximum value defined such that the minimum surface brightness is
+1/2$times$ the effective surface brightness of a point source detected at the
+$5\sigma$ limit.
+
+Second, the measurement of the 1st radial moment includes a filter to
+reduce contamination from outlier pixels.  Pairs of pixels on
+opposites sides of the central pixel are considered together.  The
+geometric mean of the two fluxes is used to replace the flux values.
+If the source has 180\degree\ symmetry, this operation has no impact.
+However, if one of the two pixels is unusually high, the value will be
+surpressed by the matched pixel on the other side.  This trick has the
+effect of reducing the impact of pixels which include flux from near
+neighbors.
+
+\note{give a test example}
 
 \subsubsection{Source Size Assessment}
 \label{sec:source.size}
-
-\note{is this in the right place?}
 
 After the PSF model has been fitted to all sources, and the Kron flux
@@ -1353,39 +1320,195 @@
 \note{how are / were these parameters set?}
 
+\subsubsection{Full PSF Model Fitting}
+
+% \note{review the discussion below}
+
+% gaussSigma = MOMENTS_GAUSS_SIGMA from recipe (initially)
+% gaussSigma = Sigma used for window function, $\sigma_w$
+
+% fitRadius, apRadius = (fitScale, apScale) * gaussSigma
+% fitScale = 7.0
+% apScale = 4.5
+
+Once a PSF model has been selected for an image, \code{psphot}
+attempts to fit all of the detected sources, with signal-to-noise
+ratio greater than a user-defined limit, with the PSF model.  In the
+PV3 analysis of the $3\pi$ survey data, this limit was set to a
+signal-to-noise ratio of 20.0 for all analysis stages.  In these fits,
+the dependent parameters are fixed by the PSF model and only the 4
+independent source model parameters are allowed to vary in the fit.
+\code{psphot} again uses Levenberg-Marquardt minimization for the
+non-linear fitting.  The sources are fitted in their S/N order,
+starting with the brightest and working down to the user-specified
+limit, with the other sources subtracted as discussed above.
+
+For the PSF model fitting, only pixels within a circular aperture
+scaled based on the seeing are used.  The radius of the circular
+aperture is set to be a fixed multiple of $\sigma_w$, the width of the
+Gaussian window function determined based on the analysis of the
+second moments (see Section~\ref{sec:moments}).  For the PV3 $3\pi$
+analysis, the PSF fit window radius is $7 \times \sigma_w$.  
+
+Sources which are blended with other sources are fitted together as a
+set of PSFs.  Blended objects are identified by first searching for
+objects for which the PSF fit windows overlap.  For a group of such
+neighboring objects, a contour is determined in the flux image at
+$25\%$ of the peak of the brightest source in the group.  All objects
+lying within this contour are treated as blends of this brightest
+source.  If other objects in this group exist, the brightest object
+not already assigned to a blend is used to define the contour for
+blends of this next object.  All objects in the image are tested as
+possible blends.  A single multi-source fit is performed on each group
+of blended peaks.
+
+%% Once a solution has been achieved for a source, \code{psphot} attempts to
+%% judge the quality of the PSF model as a representation of the source
+%% shape.  To do this, it calculates the next step of the minimization
+%% {\em allowing the shape parameters to vary}.  This step, essentially
+%% the Gauss-Newton minimization distance from the current local minimum,
+%% should be very small if the source is well represented by the PSF, but
+%% large if the PSF is not a good representation of the source flux.  The
+%% model quality is judged by the change in the two shape parameters
+%% which represent the 2D size of the source.  For the case of the
+%% elliptical Gaussian, these two parameters are $\sigma_x$ and
+%% $\sigma_y$.  For a generic model, the shape parameters may be defined
+%% differently, but there should always be two parameters which scale the
+%% source size in two dimensions.  Currently, \code{psphot} requires the two
+%% relevant shape parameters to be the first two dependent parameters in
+%% the list of model parameters (ie, parameters 4 \& 5).
+%% 
+%% The expected distribution of the variation of the two shape parameters
+%% will be a function of the signal-to-noise of the source in question
+%% and the value of the shape parameter itself.  The expected standard
+%% deviation on the shape parameter is, eg, $\sigma_x / {\rm S/N}$.  If
+%% the source is well-represented by the PSF, then the shape parameter
+%% values should be close to their minimization value.  We can thus ask,
+%% for each source, given the measured amplitude of the Gauss-Newton
+%% step, how many standard deviations from the expected value (of 0.0) is
+%% this particular value?  Sources for which the variation in the shape
+%% parameters is a large positive number of standard deviations are
+%% likely to be better represented by a larger flux distribution than the
+%% PSF (eg, a Galaxy or Comet, etc).  Sources for which the variation in
+%% the shape parameters is a large negative number of standard deviations
+%% are likely to be better represented by a smaller flux distribution
+%% than the PSF (ie, a cosmic ray or other defect).  A user-defined
+%% number of standard deviations is used to select these two cases, and
+%% to flag the source as a likely galaxy (really meaning 'extended') or
+%% as a likely defect.  
+
+After the PSF model is fitted to each object, \code{psphot} makes an
+assessment of the quality of the PSF fits.  First, it checks that the
+non-linear fitting process has converged with a valid fit.  The fit
+for an object can fail if there are too few valid pixels, due to
+masking or proximity to an edge, or if the parameters are driven to
+extreme values which are not permitted.  In addition, it is possible
+for the peak finding algorithm to identify peaks in locations which
+are not actually a normal peak.  Some of these cases are in the edges
+of saturated, bleeding columns from bright stars, in the nearly flat
+halos of very bright stars, and so on.  In these cases, a local peak
+exists, with a lower nearby sky region.  However, the fitted PSF model
+cannot converge on the peak because it is very poorly defined (perhaps
+only existing in the smoothed image).  In these cases, \code{psphot}
+flags the object with the bad bit \code{PM_SOURCE_MODE_FAIL}.  It is
+also possible in this type of case for the fit to result in a very low
+or negative value for the flux normalization parameter.  Source for
+which the peak is less than 0.02 are also marked as failing the
+non-linear PSF fit (\code{PM_SOURCE_MODE_FAIL}).
+
+Poor fits are also identified by the signal-to-noise and the $\chi^2$
+value of the resulting fit.  If a source has a PSF S/N ratio lower
+than a user-defined cutoff (set to 2.0 for the PV3 analysis of the
+$3\pi$ survey), the non-linear PSF fit will be rejected.  If the
+Chi-Square per degree of freedom is greater than a user-defined limit
+(set to 50.0 for the PV3 analysis of the $3\pi$ survey), the
+non-linear PSF fit will be rejected.  These sources are marked with
+the flag bit (\code{PM_SOURCE_MODE_POOR}).
+
+Sources which are pass the above tests are marked as having a valid
+non-linear PSF model fit (\code{PM_SOURCE_MODE_SATSTAR}).  Among these
+sources, those for which the peak flux is greater than the saturation
+limit are marked as saturated stars (\code{PM_SOURCE_MODE_SATSTAR}).
+These model fits should be consisdered with caution, but the fluxes
+and positions may have some validity (see Section~\ref{Saturation}).
+
+As the sources are fitted to the PSF model, those which survive the
+exclusion stage are subtracted from the image.  The subtraction
+process modifies the image pixels (removing the fitted flux, though
+not the locally fitted background) but does not modify the mask or the
+variance images.  The signal-to-noise ratio in the image after
+subtraction represents the significance of the remaining flux.  If the
+subtractions are sufficiently accurate models of the PSF flux
+distribution, the remaining flux should be below 1 $\sigma$
+significance.  In practice the cores of bright stars are poorly
+represented and may have larger residual significance.
+
+For sources in groups of blended stars, the resulting fits are
+evaluated independently.  Any which are determined to be valid PSF
+fits are subtracted from the image and kept for future analysis.
+
+\subsubsection{Double and Extended Sources}
+
+Sources which are judged to be non-PSF-like are confronted with two
+possible alternative choices.  First, the source is fitted with a
+double-source model.  In this pass, the assumption is made that there
+are two neighboring sources, but the peaks are not resolved.  The
+initial guess for the two peaks is made by splitting the flux of the
+single source in half and locating the two starting peaks at +/- 2
+pixels from the original peak along the direction of the semi-major
+axis of the sources, as measured from the second moments.  In order
+for the two-source model to be accepted, both sources must be judged
+as a valid PSF source.  Otherwise, the double-PSF model is rejected
+and the source is fitted with the available non-PSF model or models.
+
 \subsubsection{Non-PSF Sources}
 
 Once every source (above the S/N cutoff) has been confronted with the
-PSF model, the sources which are thought to be galaxies (extended) can
-now be fit with appropriate models for the galaxies (or other likely
-extended shapes).  Again, the fitting stage starts with the brightest
-sources (as judged by the rough S/N measured from the moments
-aperture) and working to a user defined S/N limit.  
-
-\code{psphot} will use the user-selected galaxy model to attempt the galaxy
-model fits.  In the configuration system, the keyword \code{GAL_MODEL}
-is set to the model of interest.  All suspected extended sources are
-fitted with the model, allowing all of the parameters to float.  The
-initial parameter guesses are critical here to achieving convergence
-on the model fits in a reasonable time.  The moments and the pixel
-flux distribution are used to make the initial parameter guess.  Many
-of the source parameters can be accurately guessed from the first and
-second moments.  The power-law slope can be guessed by measuring the
-isophotal level at two elliptical radii and comparing the ratio to
-that expected.
-
-For each of the galaxy models (in fact for all source models), a
-function is defined which examines the fit results and determines if
-the fit can be consider as a success or a failure.  The exact criteria
-for this decision will depend on the details of the model, and so this
-level of abstraction is needed.  For example, in some case, the range
-of valid values for each of the parameters must be considered in the
-fit assessment.  In other cases, we may choose to use only the
-parameter errors and the fit Chi-Square value.
-
-All galaxy model fits which are successful are then subtracted from
-the image as is done for the successful PSF model fits.  Of course,
-the background flux is retained, with the result that only the source
-is subtracted from the image.  Again, the variance image is (currently)
-not modified.  
+PSF model, the sources which are thought to be extended (resolved) can
+now be fit with an appropriate model (e.g., galaxy profile or other
+likely extended shapes).  Again, the fitting stage starts with the
+brightest sources (as judged by the rough S/N measured from the
+moments aperture) and working to a user defined S/N limit.
+
+\code{psphot} will use the user-selected extended source model to
+attempt these fits.  In the configuration system, the keyword
+\code{EXT_MODEL} is set to the model of interest.  All suspected
+extended sources are fitted with the model, allowing all of the
+parameters to float.  The initial parameter guesses are critical here
+to achieving convergence on the model fits in a reasonable time.  The
+moments and the pixel flux distribution are used to make the initial
+parameter guess.  Many of the source parameters can be accurately
+guessed from the first and second moments.  The power-law slope can be
+guessed by measuring the isophotal level at two elliptical radii and
+comparing the ratio to that expected.
+
+For each type of extended source model (in fact for all source
+models), a function is defined which examines the fit results and
+determines if the fit can be consider as a success or a failure.  The
+exact criteria for this decision depends on the details of the model,
+and so this level of abstraction is needed.  For example, in some
+case, the range of valid values for each of the parameters must be
+considered in the fit assessment.  In other cases, we may choose to
+use only the parameter errors and the fit Chi-Square value.
+
+All extended source model fits which are successful are then
+subtracted from the image as is done for the successful PSF model
+fits.  The background flux is retained, with the result that only the
+source is subtracted from the image.  At this stage, the variance
+image is not modified.  
+
+For the single exposure (\ippstage{camera}) and \ippstage{stack} image
+analysis, these galaxy model fits are only used internally to generate
+a clean object-subtracted residual image.  For the PV3 analysis of the
+$3\pi$ survey, these model fits were saved in the output catalog
+files, but not loaded to the public database.  The \code{QGAUSS}
+extended source model was used for the PV3 analysis (see
+Section~\ref{sec:Source.Model}).  The convolved galaxy model fits (see
+Section~\ref{sec:galaxy.conv.fit}) and the forced galaxy model fits
+(see Section~\ref{sec:galaxy.forced.fit}) provide more reliable and
+physically-motivated galaxy models.
+
+For the difference image analysis, a trailed object model is used for
+the extended sources; these model fit parameters are passed to the
+Moving Object Processing System \citep[MOPS][]{2013PASP..125..357D}.
 
 \subsection{Faint Source Analysis}
@@ -1518,67 +1641,6 @@
 Petrosian flux is contained.  
 
-\subsubsection{Radial Profile Wings}
-
-We attempt to measure the radial profile of sources in order to find
-the radius at which the flux of the source is matches the sky.  In
-this analysis, a series of up to 25 radial bins with power-law spacing
-are defined and the flux of the source in each annulus is measured.
-The ``sky radius'' is defined to be the radius at which the (robust
-median) flux in the annulus is within 1 $\sigma$ of the local sky
-level.  If this limit is not reached before the slope of the flux from
-one annulus to the next is less than a user-defined limit, then the
-annulus at which the slope reaches this limit is used to define the
-sky radius.  These values are saved in the output smf / cmf files, but
-not sent to the PSPS.  The sky radius value is used below in the
-calculation of the kron magnitude.
-
-\subsubsection{Kron Magnitudes}
-\label{sec:kron.mags}
-
-Preliminary Kron radius and flux values \citep{1980ApJS...43..305K}
-are calculated soon after sources are detected
-(Section~\ref{sec:moments}).  However, these preliminary values are
-not accurate due to the window-functions applied.  After sources have
-been characterized and the PSF model is well-determined, the Kron
-parameters are re-calculated more carefully.  In this version of the
-calculation, following the algorithm described by \cite{sextractor},
-the image is first smoothed by Gaussian kernel with $\sigma = 1.7$
-pixels, corresponding to a FWHM of 1.0\arcsec\ in the PS1 stack
-images.  Next, the Kron radius is determined in an iterative process:
-the first radial moment is measured using the pixels in an aperture
-6$\times$ the first radial moment from the previous iteration.  On the
-first iteration, the sky radius is used in place of the first radial
-moment.  By default, 2 iterations are performed.  The Kron radius is
-defined the be 2.5$\times$ the first radial moment.  The Kron flux is
-the sum of pixel fluxes within the Kron radius.  We also calculate the
-flux in two related annular apertures: the Kron inner flux is the sum
-of pixel values for the annulus $R_1 < r < 2.5 R_1$, while the Kron
-outer flux is the sum of pixel values for $2.5 R_1 < r < 4 R_1$.
-
-Two details in the calculation above should be noted.  First, for
-faint sources, noise in the measurement of the 1st radial moment may
-result in an excessively small aperture for the successive
-calculations.  The window used for the calculations is constrained to
-be at least the size of the aperture based on the PSF stars
-(Section~\ref{sec:moments}).  At the other extreme, noise may make the radius
-grow excessively, resulting in an unrealistically low effective
-surface brightness.  The aperture is constrained to be less than a
-maximum value defined such that the minimum surface brightness is
-1/2$times$ the effective surface brightness of a source detected at the
-$5\sigma$ limit.
-
-Second, the measurement of the 1st radial moment includes a filter to
-reduce contamination from outlier pixels.  Pairs of pixels on
-opposites sides of the central pixel are considered together.  The
-geometric mean of the two fluxes is used to replace the flux values.
-If the source has 180\degree\ symmetry, this operation has no impact.
-However, if one of the two pixels is unusually high, the value will be
-surpressed by the matched pixel on the other side.  This trick has the
-effect of reducing the impact of pixels which include flux from near
-neighbors.
-
-\note{give a test example}
-
 \subsubsection{Convolved Galaxy Model Fits}
+\label{sec:galaxy.conv.fit}
 
 In the galaxy model fittting stage, sources which meet certain
@@ -1874,4 +1936,41 @@
 tested.
 
+\begin{table*}
+\begin{center}
+\caption{\label{tab:measurements} \nocode{psphot} measurements performed} % \vspace{-0.5cm}
+\begin{tabular}{lcccc}
+\hline
+\hline
+{\bf Measurement} & {\bf Camera} & {\bf Stack} & {\bf Forced Warp} & {\bf Diff} \\
+\hline
+  Background                 & Y & Y & Y & N$^1$ \\
+  Peaks                      & Y & Y & N & Y \\
+  Footprints                 & Y & Y & N & Y \\
+  Moments                    & Y & Y & Y & Y \\
+  PSF Model                  & Y & Y & Y & N$^2$ \\
+  Bright Star Profile        & Y & Y & N & Y \\
+  Non-Linear PSF Fits        & Y & Y & N & N \\
+  Source-Size Tests          & Y & Y & N & Y \\
+  Unconvolved Galaxy Model   & Y & Y & N & N \\
+  Unconvolved Streak Model   & N & N & N & Y \\
+  Linear PSF Fits            & Y & Y & Y & Y \\
+  Radial Profiles            & Y & Y & N & Y \\
+  Petrosian Fluxes           & N & Y & Y & N \\
+  Kron Fluxes                & Y & Y & Y & Y \\
+  Convolved Galaxy Models    & N & Y & N & N \\
+  Fixed Aperture Photometry  & N & Y & Y & N \\
+  Convolved, Fixed Apertures & N & Y & N & N \\
+  Aperture Corrections       & Y & Y & Y & N \\
+  Forced PSF Fluxes          & N & N & Y & N \\
+  Forced Galaxy Models       & N & N & Y & N \\
+  Lensing Parameters         & N & Y & Y & N \\
+\hline
+\hline
+\multicolumn{5}{l}{$^1$ Background subtraction is performed by {\tt ppSub} before calling {\tt psphot}} \\
+\multicolumn{5}{l}{$^2$ PSF modeling is perfom by {\tt ppSub} on the input warps before calling {\tt psphot}} \\
+\end{tabular}
+\end{center}
+\end{table*}
+
 \subsection{Output Formats}
 
@@ -1973,7 +2072,6 @@
 is marked as completed.
 
-\subsection{Forced Photometry : PSFs}
-
-\subsection{Forced Photometry : galaxies}
+\subsection{Forced Galaxy Models}
+\label{sec:galaxy.forced.fit}
 
 The convolved galaxy models are also re-measured on the
@@ -2149,2 +2247,3 @@
 
 * background model description (see waters)
+
