Index: trunk/doc/release.2015/ps1.detrend/detrend.tex
===================================================================
--- trunk/doc/release.2015/ps1.detrend/detrend.tex	(revision 40709)
+++ trunk/doc/release.2015/ps1.detrend/detrend.tex	(revision 40710)
@@ -476,5 +476,5 @@
     A-mode dark instead results in the third (blue) curve, which shows
     a significant increase in gradients across the cells.  The fourth
-    (red) curve is the result of applying the PATTERN.CONTINUITY
+    (red) curve is the result of applying the \nocode{PATTERN.CONTINUITY}
     correction along with the B-mode dark model.  Although this
     creates a larger gradient across the mosaicked images, it
@@ -1461,5 +1461,5 @@
   \tablecolumns{3}
   \tablewidth{0pc}
-  \tablecaption{Cells which have PATTERN.ROW correction applied}
+  \tablecaption{Cells which have \nocode{PATTERN.ROW} correction applied}
   \tablehead{\colhead{OTA} & \colhead{Cell columns} & \colhead{Additional cells}}
   \startdata
@@ -1510,5 +1510,5 @@
 correction cannot fully remove this structure from the images, and the
 noisemap value only indicates the level of the average variance added
-by these bias offsets.  Therefore, we apply the PATTERN.ROW correction
+by these bias offsets.  Therefore, we apply the \ippmisc{PATTERN.ROW} correction
 in an attempt to mitigate the offsets and correct the image values.
 To force the rows to agree, a second order clipped polynomial is
@@ -1528,5 +1528,9 @@
   \centering
   \includegraphics[width=0.9\hsize,angle=0,clip]{images/pattern_row_edit.png}
-  \caption{Diagram illustrating in red which cells on GPC1 require the PATTERN.ROW correction to be applied.  The footprint of each OTA is outlined, and cell xy00 is marked with either a filled box or an outline.  The labeling of the non-existent corner OTAs is provided to orient the focal plane.}
+  \caption{Diagram illustrating in red which cells on GPC1 require the
+    \nocode{PATTERN.ROW} correction to be applied.  The footprint of
+    each OTA is outlined, and cell xy00 is marked with either a filled
+    box or an outline.  The labeling of the non-existent corner OTAs
+    is provided to orient the focal plane.}
   \label{fig: pattern row cells}
 \end{figure}
@@ -1535,5 +1539,5 @@
 the \gps{} filter, as the read noise is the dominant noise source in
 that filter.  At longer wavelengths, the noise from the Poissonian
-variation in the sky level increases.  The PATTERN.ROW correction is
+variation in the sky level increases.  The \ippmisc{PATTERN.ROW} correction is
 still applied to data taken in the other filters, as the increase in
 sky noise does not fully obscure the row-by-row noise.
@@ -1569,9 +1573,44 @@
     \includegraphics[width=0.9\hsize,angle=0,clip]{images/o5379g0103o_wpt_XY57_sm.png}
   \end{minipage}
-  \caption{{\bf Correlated Noise:} Example of the PATTERN.ROW correction on exposure o5379g0103o OTA57 cell xy01 (\ips{} filter 45s).  The left panel shows the cell with all appropriate detrending except the PATTERN.ROW, and the right shows the same cell with PATTERN.ROW applied.  The correction reduces the correlated noise on the right side, which is most distant from the read out amplifier.  There is a slight over subtraction along the rows near the bright star.}
+  \caption{{\bf Correlated Noise:} Example of the
+    \nocode{PATTERN.ROW} correction on exposure o5379g0103o OTA57
+    cell xy01 (\ips{} filter 45s).  The left panel shows the cell with
+    all appropriate detrending except the \nocode{PATTERN.ROW}, and
+    the right shows the same cell with \nocode{PATTERN.ROW} applied.
+    The correction reduces the correlated noise on the right side,
+    which is most distant from the read out amplifier.  There is a
+    slight over subtraction along the rows near the bright star.}
   \label{fig: pattern row example}
 \end{figure*}
 
 \subsubsection{Pattern Continuity}
+
+\begin{figure*}[htpb]
+  \centering
+  \includegraphics[width=0.9\hsize,angle=0,clip]{images/{N157.v1}.png}
+  \caption{These four panels illustrate the impact of the
+    \nocode{PATTERN.ROW}, \nocode{PATTERN.CONTINUITY}, and background
+    subtraction steps on a large galaxy.  Upper-left: all detrends
+    except \nocode{PATTERN.ROW}, \nocode{PATTERN.CONTINUITY}, and background
+    subtraction applied to a single GPC1 image of NGC 157.
+    Upper-right: same image as upper-left with \nocode{PATTERN.ROW} applied.
+    Lower-right: same image as upper-right with
+    \nocode{PATTERN.CONTINUITY} applied.  Lower-left: same image as
+    lower-right with background subtraction.}
+  \label{fig:ngc157.with.pattern}
+\end{figure*}
+
+\begin{figure*}[htpb]
+  \centering
+  \includegraphics[width=0.9\hsize,angle=0,clip]{images/{N157.v2}.png}
+  \caption{These two panels illustrate the impact of the
+    \nocode{PATTERN.CONTINUITY}, and background subtraction steps on a
+    large galaxy, without \nocode{PATTERN.ROW}.  Left: all detrends
+    and \nocode{PATTERN.CONTINUITY}, but not \nocode{PATTERN.ROW} and
+    background subtraction, applied to a single GPC1 image of NGC 157.
+    Right: same image as left with background subtraction.  Without
+    the \nocode{PATTERN.ROW} correction, the background is much less affected.}
+  \label{fig:ngc157.without.pattern}
+\end{figure*}
 
 The background sky levels of cells on a single OTA do not always have
@@ -1586,5 +1625,5 @@
 the cell boundaries.
 
-The PATTERN.CONTINUITY correction, attempts to match the edges of a
+The \ippmisc{PATTERN.CONTINUITY} correction, attempts to match the edges of a
 cell to those of its neighbors.  For each cell, a thin box 10 pixels
 wide running the full length of each edge is extracted and the median
@@ -1612,4 +1651,93 @@
 effect of this correction on an image profile is shown in Figure
 \ref{fig:dark switching}.
+
+\subsection{Background (``Sky'') Subtraction}
+
+During the \IPPstage{chip}-stage processing, after the detrending
+steps are done but before source detection begins, a model of the
+background light is subtracted from each chip image.  The decision to
+subtract a background model is somewhat tricky as the trade-offs are
+not clear in all possible cases.  It is helpful to consider the types
+of sources which contribute to the background light in astronomical
+images.
+
+First, there is ``scattered light'', which means flux that reaches the
+detector from a path that is different from the path through the
+optics taken by the light from the imaged stars.  In an ideal
+telescope, no light could ever reach the detector without being imaged
+by the optics.  However, in a real telescope, especially in wide-field
+systems such as the Pan-STARRS telescopes, it is impossible to
+sufficiently baffle the optical path to prevent ``scattered''
+light\footnote{We put the term ``scattered'' in quotes because this
+  background may include light which reaches the detector directly
+  from the sky or other light source rather than scattering off
+  elements of the optical system.}  from reaching the detector without
+blocking the main optical path.  This class of background light may
+include sharp features such as the glints discussed
+above(Section~\ref{sec:glints}), but in this discussion we are
+primarily concerned with large-scale structures.  Another type of
+``scattered'' background light source would be the large out-of-focus
+pupil image observed in \eg, the NOAO and CTIO wide-field imagers
+\citep{2007ASPC..376..269S}.
+
+Second, there are direct terrestrial contributions to the background
+light.  This source of light follows the same path as the light from
+the stars to the detector, but has an origin much closer to the
+telescope.  This may include glow from emission lines in the
+atmosphere, light from the moon or terrestrial sources scattered off
+thin (or thick!) clouds or just scattered in the clear atmosphere via
+Rayleigh off dust particles and gas molecules in the atmosphere.  Both
+``scattered'' and direct terrestrial contributions to the background
+light are not expected to be consistent for a given location on the
+sky, though the pupil ghost image may well be the same for a fixed
+telescope pointing and night sky brighness.
+
+Finally, there are astrophysical contributions to the background
+light.  These range from the nearby zodiacal light to the
+extragalactic background.  Depending on the context and the source
+being measured, astrophysical background sources may even include the
+diffuse flux from large galaxies.  When measuring the flux of point
+sources, it is necessary to subtract (or otherwise model) any
+large-scale diffuse background component.  When measuring a larger
+object, e.g., a well-resolved galaxy, it is necessary to make a
+decision what portion of the large-scale flux is a background and what
+is part of the flux of the object being measured.
+
+When one measures the flux of an object in an image, two approaches to
+the background light are possible.  On the one hand, one could attempt
+to include the background as part of the model-fitting parameters at
+the time of the analysis.  Alternatively, one could attempt to model
+and subtract the background first and not include it in the per-object
+model fit.  For the IPP analysis, we choose the later method for two
+reasons.  First, in tests of the former method, we find that the
+photometry of fitted objects is more inconsistent if the sky is fitted
+for each object than if it is determined in a separate step
+(presumably due to the extra degree of freedom in the model fitting).
+Second, by subtracting a background model, we remove varying
+backgrounds from the image so that the resulting pixels can later be
+combined to make a deep stack.  
+
+The details of the background model are discussed in Paper IV.
+Briefly, the background subtraction is performed on each chip
+independently.  The image is divided into a grid of points with a
+spacing of 400 pixels.  A superpixel of size $800 \times 800$ pixels
+is used to measure the background corresponding to each point.
+Bilinear interpolation is used to estimate the background value at any
+point in the full image.  This approach works well to follow the
+large-scale background structures from the terrestrial and scattered
+sources, and to subtract the background light of large-scale
+astronomical feasures for the analysis of point sources or small-scale
+feasures such as small galaxies.  However, this process acts as a
+high-pass filter, with the result that galaxies larger than a certain
+size will have a significant portion of their light subtracted.  In
+addition, the \ippmisc{PATTERN.ROW} and \ippmisc{PATTERN.CONTINUITY}
+corrections described above (Section~\ref{sec:pattern}) also
+over-subtract large galaxies, and interact badly with the background
+model.  Figures~\ref{fig:ngc157.with.pattern} and
+\ref{fig:ngc157.without.pattern} illustrate the impact of the
+background subtraction on a large galaxy both with and withouth the
+\ippmisc{PATTERN.ROW} correction.
+
+% \note{give examples with simulations and show examples of over-subtraction}
 
 \section{GPC1 Detrend Construction}
@@ -2372,5 +2500,5 @@
 
 Finally, a large number of issues arise due to the row-to-row bias
-issues.  The PATTERN.ROW correction is used on a limited number of
+issues.  The \ippmisc{PATTERN.ROW} correction is used on a limited number of
 cells, to minimize any possible distortion of bright stars or dense
 fields by the fitting process.  As the row-to-row bias changes very
