Index: /trunk/doc/release.2015/ps1.analysis/analysis.tex
===================================================================
--- /trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 41332)
+++ /trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 41333)
@@ -100,6 +100,6 @@
 images from other telescopes.  We describe the analysis of the
 astronomical sources by \ippprog{psphot} in general as well as for the
-specific case of the 3rd processing version used for the first \textmod{two public
-releases} of the Pan-STARRS $3\pi$ survey data.
+specific case of the 3rd processing version used for the first
+\textmod{two public releases} of the Pan-STARRS $3\pi$ survey data.
 \end{abstract}
 
@@ -156,6 +156,6 @@
 partners collaborate with the Pan-STARRS team to harvest the transient
 sources such supernovae and graviational wave counterparts.  A second
-Pan-STARRS telescope \citep[PS2][]{chambers2017,chambers2020},
-generally matching the PS1 design \citep{Morgan2012} has since been
+Pan-STARRS telescope \citep[PS2][Chambers et al 2020 in prep]{chambers2017},
+generally matching the PS1 design \citep{2012SPIE.8444E..0HM} has since been
 constructed and has been producing science results since early 2018.
 
@@ -281,10 +281,10 @@
 
 The photometric and astrometric precision goals for the Pan-STARRS\,1
-surveys were quite stringent.  The astrometric goals were relative astrometric accuracy of 10 milliarcseconds
-and absolute astrometric accuracy of 100 milliarcseconds with respect
-to the ICRS reference stars.  For photometry, the goal was 10
-millimagnitudes accuracy within the internal photometric system across
-the sky, though the tie to an absolute standard was not required to
-meet this standard.
+surveys were quite stringent.  The astrometric goals were relative
+astrometric accuracy of 10 milliarcseconds and absolute astrometric
+accuracy of 100 milliarcseconds with respect to the ICRS reference
+stars.  For photometry, the goal was 10 millimagnitudes accuracy
+within the internal photometric system across the sky, though the tie
+to an absolute standard was not required to meet this standard.
 
 An additional constraint on the Pan-STARRS analysis system comes from
@@ -303,8 +303,8 @@
 efficient.  Not only is it necessary to make a careful measurement of
 the flux of individual sources, it is also critical to characterize
-the image point spread function (PSF), and its variations across the field
-and from image to image.  Since comparisons between images must be
-reliable, the measurements must be stable for both photometry and
-astrometry.
+the image point spread function (PSF), and its variations across the
+field and from image to image.  Since comparisons between images must
+be reliable, the measurements must be stable for both photometry and
+astrometry.  
 
 A variety of astronomical software packages perform the basic source
@@ -518,11 +518,26 @@
 \end{itemize}
 
-\note{Discuss the psphot photometry accuracy and the ubercal solution,
-  etc.  mention Paper V}
-
-\textadd{The success of the \ippprog{psphot} implementation is meeting
+\textadd{The success of the \ippprog{psphot} implementation in meeting
   the photometry and astrometry design requirements is demonstrated by
-  the achieved accuracy for the Pan-STARRS $3\pi$ Survey data.  
-}
+  the achieved accuracy for the Pan-STARRS $3\pi$ Survey data.  For a
+  survey like the Pan-STARRS\,1 $3\pi$ survey to achieve photometry
+  and astrometry accuracy at the level of our goals, not only must the
+  measurement of the astronomical detections be precise, but it is
+  necessary for the detrending (instrumental signature remove) and
+  calibration processes to correct for a wide variety of systematic
+  effects and it is also necessary for the observations to be
+  performed in such a way that the data can be calibrated well.  These
+  others aspects of the process are discussed in detail elsewhere
+  (Papers I, III, V).  In the end, the goals were largely achieved for
+  the Pan-STARRS\,1 $3\pi$ survey. As reported in Paper V, the
+  resulting photometric system is consistent across the sky to between
+  7 and 12.4 millimagnitudes depending on the filter.  The systematic
+  error floor for individual photometry measurements is $(\sigma_g,
+  \sigma_r, \sigma_i, \sigma_z, \sigma_y) = (14, 14, 15, 15, 18)$
+  millimagnitudes.  The bright-star systematic error floor for
+  individual astrometric measurements is 16 milliarcseconds and the
+  Pan-STARRS Data Release 2 (DR2) astrometric system is tied to the
+  Gaia DR1 coordinate frame with a systematic uncertainty of $\sim 5$
+  milliarcseconds. }
 
 \section{Basic Analysis}
@@ -554,5 +569,5 @@
 
 \item {\bf Output} Write out sources in selected format, write out
-  difference image, variance image, etc, as selected.
+  difference image, variance image, etc, as selected.  
 \end{enumerate}
 
@@ -578,4 +593,13 @@
 PSF model may already be available from external information, in which
 case the PSF modeling stage can be skipped.
+
+\textadd{Ultimately, all measurements of individual astronomical
+  sources from \ippprog{psphot} are reported in one of the tables in
+  the PSPS database.  As discussed in detail in Paper VI, measurements
+  from individual exposures are available from the
+  \ippdbtable{Detection} table.  Measurements of objects in the
+  stacked images are stored in one of several \ippdbtable{Stack...}
+  tables while the `forced' measurements from individual warp images
+  are stored in tables beginning with \ippdbtable{ForcedWarp...}.}
 
 \begin{table*}
@@ -893,6 +917,14 @@
 Since a typical smoothing or warping operation may introduce
 correlation between 25 - 100 neighboring pixels, the size of such a
-covariance image is prohibitive.  
-\note{describe the way we handle covariance}
+covariance image is prohibitive.
+
+%% \note{describe the way we handle covariance}
+
+%% Within the IPP analysis generally, we carry a simplified
+%% representation of the impact of covariance on the variance values
+%% used in pixel analysis operations.  Whenever image operations
+%% introduce covariance by combining information from multiple pixels,
+%% we update a matrix tracking the covariance at the image center for
+%% a small range of pixels.  
 
 Before sources are detected in the image, a model of the background is
@@ -930,8 +962,42 @@
 50\% of the peak bin value.
 
+\begin{table}
+\caption{\label{tab:sky.offset} Comparison of background
+  measurement methods.  Backgrounds were measured for simulated images with the given stellar
+  density (at the low-density detection threshold) and known
+  background level.  The {\tt psphot} technique is less biased at high
+stellar densities.} \vspace{-0.5cm}
+\begin{center}
+% \footnotesize
+\begin{tabular}{cccccc}
+\hline
+\hline
+{\bf Density} & {\bf True} & {\bf Image} & {\bf  Image} & {\bf Gauss} & {\bf \tt psphot} \\
+{\bf \footnotesize $\log_{10}(\mbox{deg}^{-2}$)} & {\bf Sky} & {\bf Mean} & {\bf  Median} & {\bf Fit} & {\bf \tt Value} \\
+\hline
+4.2 & 202.8 & 203.3 & 202.8 & 202.8 & 202.9 \\
+4.7 & 202.8 & 204.9 & 203.1 & 203.0 & 203.0 \\
+5.2 & 202.8 & 210.6 & 204.0 & 203.5 & 203.5 \\
+5.7 & 202.8 & 233.9 & 207.4 & 205.4 & 205.3 \\
+6.2 & 202.8 & 300.9 & 219.7 & 211.2 & 210.6 \\
+6.7 & 202.8 & 534.6 & 286.2 & 242.8 & 233.9 \\
+\hline
+%\multicolumn{5}{l}{$^1$ a footnote} \\
+\end{tabular}
+\end{center}
+\end{table}
+
 If the fit to the asymmetric lower fraction of the curve is less than
 the symmetric fit, but greater than the above lower-bound of the full
 symmetric fit, then the lower fraction value is kept as the true mean
-sky value for this superpixel.
+sky value for this superpixel.  Table~\ref{tab:sky.offset} shows a
+comparison of this technique to several other methods to measure the
+sky background using simulated data with a range of stellar
+densities. The stellar density listed in the table is the number of stars per
+square degree at the $5\sigma$ detection limit {\em in the
+  lowest-density image}. In our simulations, we find that as the
+stellar density rises to values typical in the Galactic plane regions,
+this technique results in a more accurate estimate of the background,
+though it still over-estimates the background compared to the truth.
 
 Bilinear interpolation is used to generate a full-resolution image
@@ -986,5 +1052,5 @@
 \textadd{For an image with a Gaussian PSF of the same size, this method
   would represent the optimal detection algorithm, equivalent to a
-  matched filter \note{add ref}.  At this stage, our goal is simply to
+  matched filter.  At this stage, our goal is simply to
   detect the brighter sources, so the exact size and shape of the PSF
   is not critical. }
@@ -1378,8 +1444,9 @@
 parameters would be the shape terms ($\sigma_x, \sigma_y, \sigma_{\rm
   xy}$) while the independent parameters would be the centroid,
-normalization and local sky values ($x_o, y_o, I_o, S$).  \note{we do
-  not fit sky as a free parametery, right?}  Thus the
-shape parameters are each a function of the source centroid
-coordinates:
+normalization and local sky values ($x_o, y_o, I_o, S$), though as
+noted below (Section~\ref{sec:nonlinear.psf.model}), in practice we do
+not allow the sky to be fitted independently since we subtract the
+background model.  Thus the shape parameters are each a function of
+the source centroid coordinates:
 \begin{eqnarray}
 \sigma_x    & = & f_1(x_{\rm ccd},y_{\rm ccd}) \\
@@ -1423,5 +1490,5 @@
 \textadd{For these PSF models, the functions are evaluated at the pixel center.
 Unlike some galaxy model representations (see
-Section~\label{sec:galaxy.conv.fit} ), the first derivatives of these
+Section~\ref{sec:galaxy.conv.fit} ), the first derivatives of these
 functions approach zero as the radius approaches zero, so sub-pixel
 integration is not necessary.}
@@ -1616,5 +1683,5 @@
 With $\sigma_a$, $\sigma_b$, $\theta$ in hand, we can now transform
 these values to the parameters of our fits, $\sigma_x$, $\sigma_y$,
-$\sigma_{\rm xy}$ (Eqn~\label{eqn:2d.gaussian} above).  This transformation
+$\sigma_{\rm xy}$ (Eqn~\ref{eqn:2d.gaussian} above).  This transformation
 can be determined by rotating the 2D Gaussian equation, yielding:
 \begin{eqnarray}
@@ -1802,5 +1869,5 @@
 not to be in the current thread group).
 
-\note{explain number of superpixels (psphotThreadTools.c)}
+% \note{explain number of superpixels (psphotThreadTools.c)}
 
 As the threads complete their analysis, they are assigned the next
@@ -1897,6 +1964,5 @@
 sky radius.  These values are saved in the \textmod{output FITS catalog files}, but
 not sent to the PSPS.  The sky radius value is used below in the
-calculation of the Kron magnitude. \note{used in both versions?}
-\note{calculated for the second pass?}
+calculation of the Kron magnitude.
 
 \subsubsection{Kron Magnitudes}
@@ -1949,6 +2015,4 @@
 the neighbors.}
 
-% \note{give a test example}
-
 \subsubsection{Source Size Assessment}
 \label{sec:source.size}
@@ -2025,13 +2089,18 @@
 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.
-\ippprog{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.  All
-sources for which a non-linear PSF model has been attempted have the
-flag bit \code{PM_SOURCE_MODE_FITTED} set, regardless of the quality
-of that fit.
+the dependent parameters are fixed by the PSF model and only \textmod{the 3
+independent source model parameters (position in $X$ and $Y$ and flux
+normalization) are allowed to vary in the fit.  Note that we do {\em
+  not} allow the local sky to be fitted as a free parameters.  Since
+we have subtracted a model for the background, allowing the sky to be
+again at this stage is redundant.  In fact, in our testing, we found
+that allowing the sky to float resulted in higher scatter for the flux
+normalizations.}  \ippprog{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.  All sources for which a non-linear PSF model has been
+attempted have the flag bit \code{PM_SOURCE_MODE_FITTED} set,
+regardless of the quality of that fit.
 
 Since the PSF model describes the variation of the PSF across the
@@ -2148,14 +2217,12 @@
 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)\note{is the background actually
-  fitted locally?} 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, \textmod{the remaining flux should be normally distributed about
-zero with a standard deviation of 1 $\sigma$}.  In practice the cores
-of bright stars are poorly represented and may have larger residual
-significance.
+process modifies the image pixels (removing the fitted flux) 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, \textmod{the remaining flux should be
+  normally distributed about zero with a standard deviation of 1
+  $\sigma$}.  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
@@ -2201,6 +2268,4 @@
 comparing the ratio to that expected.
 
-\note{more on the parameter guess}
-
 For each type of extended source model (in fact for all source
 models), a function is defined which examines the fit results and
@@ -2238,4 +2303,39 @@
 \subsection{Faint Source Analysis}
 \label{sec:faint.psf.model}
+
+% pueo:/home/real/eugene/ppsim.20200407
+\begin{figure}[htbp]
+  \begin{center}
+ \includegraphics[width=\hsize,clip]{\picdir/{completion.ppsim}.pdf}
+  \caption{\label{fig:complete.ppsim} Completeness as a function of
+    magnitude (blue curves) for different stellar densities in
+    simulated data.  The curves are labeled with the logarithm of the
+    stellar density at the detection threshold of the low-density
+    image.  The dotted red line shows the detection limit expected for
+    the sky level and seeing.  The solid red curve shows the
+    completeness estimated for the low-density image based on
+    injection and recovery.}
+  \end{center}
+\end{figure}
+
+% pueo:/home/real/eugene/ppsim.20200407
+\begin{figure}[htbp]
+  \begin{center}
+ \includegraphics[width=\hsize,clip]{\picdir/{psphot.complete.pv3}.pdf}
+  \caption{\label{fig:complete.pv3} Completeness and bogus fraction
+    as a function of magnitude for different stellar densities in real
+    PS1 exposures.  Each panel represents an exposure at different
+    Galactic latitudes towards anti-center, labeled by the density of
+    stars at the detection limit of the low-density exposure.  In each
+    panel, the completeness (compared to deep stack data) and fraction
+    of false detections (bogus fraction) is shown for a series of
+    cuts.  The gold curves show all detections in the exposures.  The
+    dotted black curve shows the impact of cutting detections
+    identified by {\tt psphot} as cosmic rays.  The blue curve
+    excludes cosmic rays and detections with {\tt PSF\_QF} $< 0.95$
+    while the red curve excludes cosmic rays and detections with {\tt
+      PSF\_QF\_PERFECT} $< 0.95$.}
+  \end{center}
+\end{figure}
 
 After a first pass through the image, in which the brighter sources
@@ -2274,8 +2374,9 @@
   centroids.}
 
-\textadd{After the flux-normalization is calculated, the moments
-  are used to calculate the preliminary Kron radius and flux (see
-  Section~\ref{sec:kron.mags}).  These are in turn used to assess the
-  source sizes as in Section~\ref{sec:source.size}.  However, the
+\textadd{After the flux-normalization is calculated, the radial
+  profile is measured (Section~\ref{sec:radial.profile}) and the
+  moments are used to calculate the preliminary Kron radius and flux
+  (see Section~\ref{sec:kron.mags}).  These are in turn used to assess
+  the source sizes as in Section~\ref{sec:source.size}.  However, the
   non-linear fitting steps for the PSF model fits
   (Section~\ref{sec:nonlinear.psf.model}) and the extended source
@@ -2288,6 +2389,5 @@
   parameters.  In addition, the positions (for PSF sources) are not
   much improved using the non-linear fitting compared with the
-  non-parametric centroid measurement for these faint sources.
-  \note{show with a model}.}
+  non-parametric centroid measurement for these faint sources. }
 
 The PV3 threshold for the bright source analysis is a signal-to-noise
@@ -2312,6 +2412,4 @@
 on one image based on detections in other images have the flag bit
 \code{PM_SOURCE_MODE2_MATCHED} set.
-
-\note{need to discuss the injection \& recovery analysis of the completeness}
 
 \subsection{Aperture Correction and Total Aperture Fluxes}
@@ -2338,33 +2436,4 @@
 will by determined by how inconsistently the models represent the
 actual source flux.
-
-Aperture photometry attempts to avoid these problems, but introduces
-other difficulties.  In aperture photometry, if a large enough
-aperture is chosen, the amount of flux which is lost will be a small
-fraction of the total source flux.  Even more importantly, as the
-image conditions change, the amount lost will change by an even
-smaller fraction, at least for a large aperture.  
-%
-% This can be seen by
-% the fact that the dominant variations in the image quality are in the
-% focus, tracking and seeing.  All of these errors initially affect the
-% cores of the stellar images, rather than the wide wings.  The wide
-% wings are largely dominated by scattering in the optics and scattering
-% in the atmosphere.  The amplitude and distribution of these two
-% scattering functions do not change significantly or quickly for a
-% single telescope and site.  
-%
-Aperture photometry can then be used to
-correct the PSF photometry.
-
-The difficulty for aperture photometry is the need to make an accurate
-measurement of the local background for each source.  As the aperture
-grows, errors in the measurement of the sky flux start to become
-dominant.  If the aperture is too small, then variations in the image
-quality are dominant.  The brighter is the source, the smaller is the
-error introduced by the large size of the aperture.  However, the
-number of very bright stars is limited in any image, and of course the
-brighter stars are more likely to suffer from non-linearity or
-saturation.  
 
 % /data/kukui.1/eugene/psphot.examples.20190423/compare.sh
@@ -2402,4 +2471,81 @@
 \end{figure*}
 
+% on pueo ~eugene
+% /data/kukui.1/eugene/psphot.examples.20190423/compare.sh
+\begin{figure}[htbp]
+  \begin{center}
+ \includegraphics[width=\hsize,clip]{\picdir/{bright.mag.resid}.\plotext}
+  \caption{\label{fig:mag.resid.stdevs} Demonstration of photometric
+    accuracy using the image sequence from
+    Figure~\ref{fig:mag.resid.psf}. Using only bright stars (7 - 8
+    magnitudes above the detection threshold), we calculate the
+    difference between the magnitudes in the first image and the other
+    17 images.  The plotted dots show for each pair the mean
+    difference vs the standard deviation of the difference.  Red dots
+    show the PSF magnitudes and blue dots show aperture
+    magnitudes. Despite real transparency variations of 0.4 over the
+    50 minutes of this sequence, magnitudes are consistent at the few
+    millimagnitude level.  Aperture magnitudes have scatter in
+    the 2 - 7 millimagnitude range, while the PSF magnitudes have
+    scatter of 7 - 14 millimagntiudes.  
+}
+\end{center}
+\end{figure}
+
+% on pueo ~eugene/zpts.20200406/mana.sh
+\begin{figure*}[htbp]
+  \begin{center}
+ \includegraphics[width=\hsize,clip]{\picdir/{zpt.mjd.v0.i}.\plotext}
+  \caption{\label{fig:zpt.iband} Historical \ips-band zero points.
+    Blue dots are the individual exposure zero points, corrected to
+    airmass at the zenith.  Red dots are the median of zero points
+    from images groups in bins of 10 nights.  The grey line is a
+    spline fit to these median values.  }
+\end{center}
+\end{figure*}
+
+% on pueo ~eugene/zpts.20200406/mana.sh
+\begin{figure}[htbp]
+  \begin{center}
+ \includegraphics[width=\hsize,clip]{\picdir/{zptres.hist.v0.i}.\plotext}
+  \caption{\label{fig:zpt.resid.hist} Historical \ips-band zero-point
+    residual variations.  Log-histogram (black line) of the
+    per-exposure zero points, corrected to the zenith, after
+    subtracting a spline fit to the median of image groups in bins of
+    10 nights.  The inset shows the core of the distribution.  In
+    both, the red line is a Gaussian fit to the distribution.  The
+    large negative tails are due to clouds and haze.  }
+\end{center}
+\end{figure}
+
+Aperture photometry attempts to avoid these problems, but introduces
+other difficulties.  In aperture photometry, if a large enough
+aperture is chosen, the amount of flux which is lost will be a small
+fraction of the total source flux.  Even more importantly, as the
+image conditions change, the amount lost will change by an even
+smaller fraction, at least for a large aperture.  
+%
+% This can be seen by
+% the fact that the dominant variations in the image quality are in the
+% focus, tracking and seeing.  All of these errors initially affect the
+% cores of the stellar images, rather than the wide wings.  The wide
+% wings are largely dominated by scattering in the optics and scattering
+% in the atmosphere.  The amplitude and distribution of these two
+% scattering functions do not change significantly or quickly for a
+% single telescope and site.  
+%
+Aperture photometry can then be used to
+correct the PSF photometry.
+
+The difficulty for aperture photometry is the need to make an accurate
+measurement of the local background for each source.  As the aperture
+grows, errors in the measurement of the sky flux start to become
+dominant.  If the aperture is too small, then variations in the image
+quality are dominant.  The brighter is the source, the smaller is the
+error introduced by the large size of the aperture.  However, the
+number of very bright stars is limited in any image, and of course the
+brighter stars are more likely to suffer from non-linearity or
+saturation.  
+
 In order to thread the needle between these effects, \ippprog{psphot}
 measures the aperture photometry on a modest-sized aperture, and then
@@ -2431,5 +2577,10 @@
 analysis, a grid with a maximum of $6\times 6$ samples per GPC1 chip
 image was used.  The reported PSF magnitudes for all objects have this
-aperture correction applied.
+aperture correction applied.  \textadd{Note that an initial aperture correction was
+measured during the initial steps of the analysis before the PSF model
+was chosen.  However, since the sources in the image were not yet
+measured and subtracted, that aperture could be contaminated by
+neighbors.  The analysis here is performed one fairly bright star at a
+time with all other sources subtracted in order to minimize such contamination.}
 
 % growth curve analysis in psphot:
@@ -2481,4 +2632,104 @@
 %%% term.
 
+\subsection{Completeness \& Contamination}
+
+At the end of the \ippprog{psphot} analysis of the sources in the
+image, an analysis is performed to test the detection efficiency.  A
+number of fake PSF sources are injected into the image and the peak
+detection analysis (Section~\ref{sec:peaks}) is use to determine if
+these sources would have been recovered.  The PSF model fluxes are
+measured for the source which are detected.  For a given image, the
+detection threshold is predicted based on the median image variance
+and the seeing.  A series of brightness bins straddling the threshold
+are defined and a number of sources are injected with magnitudes
+corresponding to each of these bin values.  The \ippprog{psphot}
+recipe value \code{EFF.NUM} specifies the number of sources in each
+brightness bin (500 the PV3), and the value \code{@EFF.MAG} specifies
+the bins as magnitudes above and below the threshold.  For PV3, the 13
+magnitude offsets were (-2.0, -1.0, -0.5, -0.25, -0.1, -0.05, 0.0,
+0.05, 0.1, 0.25, 0.5, 1.0, 2.0), providing fine sampling near the
+limit, but more coarse coverage further away.  Poisson noise
+appropriate to the photon counts of the injected sources are included
+in the image.  Injected sources are uniformly distributed across the
+image in $X$ and $Y$ pixel coordinates {\em without any consideration
+  of the masked regions}.  This last point means the recovered
+fraction in the bright bins can be used to test the masking fraction.
+
+As the stellar density increases, the completeness suffers due to
+crowding and confusion.  Since the injection and recovery analysis of
+the fake sources operates on the source-subtracted image and does not
+attempt to fully discovery the sources, this analysis over-estimates
+the completeness in crowded fields.  To explore the completeness in
+crowded field images, we generate a series of simulated images using a
+Gaussian PSF with FWHM = 1\arcsec for a range of stellar densities.
+We generate fake stars with fluxes as faint as $\frac{1}{5}$ of the
+flux as the low-density detection limit, with densities ranging from
+\approx 14,000 stars per square degree at low-density detection limit
+to \approx 4.8 million stars per square degree at the low-density
+detection limit.  The latter is comparable to observed densities in
+the Galactic plane.  We run the \ippprog{psphot} analysis on these
+simulated images and compare the detected stars to those injected to
+calculate the completeness for each image as a function of the true
+magnitude of the stars.  Figure~\ref{fig:complete.ppsim} shows the measured
+completeness for each of the six simulated images, labeled by the
+logarithm of their faint-end stellar density. The red dashed line
+shows the expected detection limit based on the background and seeing,
+while the red curve shows the completeness curve calculated
+automatically by \ippprog{psphot} using the injection and recovery
+analysis.
+
+For low-density fields, the completeness function determined by
+injection and recovery is similar to that measured by the simulation,
+with the 50\% completeness threshold roughly 0.3 magnitudes too faint.
+As the stellar density increases, the true 50\% completeness magnitude
+rises relative to the value estimated by injection and recovery.
+
+Ideally, all sources detected by \ippprog{psphot} would correspond to
+real astrophysical objects.  In reality, many sources are detected in
+the images which do not correspond to real sources in the sky.  In the
+very simplified simulations discussed above, which do not include
+realistic detector artifacts, we find that the fraction of bogus
+detections is extremely low, even at the very faint end.  In real
+data, bogus detections are due to a variety of typical instrumental
+features including cosmic rays, diffraction spikes, satelite tracks,
+glows, non-Gaussian noise, variance mis-estimation, etc.  See paper III
+for extensive discussion of instrumental artifacts in the Pan-STARRS images.
+
+Figure~\ref{fig:complete.pv3} illustrates the completeness and bogus
+detection fraction for a set of 4 real PS1 exposures from the $3\pi$
+Survey.  This figure uses \ips-band exposures with Galactic longitude
+roughly 200\degrees and latitudes of 0, 10, 30, 90 degrees.  We
+identify the real astrophysical sources in these fields by comparing
+with the deeper stack exposures and counting as real any source
+detected in both \rps\ and \ips.  We correct for the masking fraction
+in the exposures (which is roughly 80\%) in the case of GPC1 and plot
+the completeness fraction for all detections in 0.5 magnitude wide
+bins from the saturation limit to below the detection limit.  We also
+show the bogus fraction, calculated as $1 - f_{\rm pure}$, where
+$f_{\rm pure}$ is the ratio of real detections to all detections for
+the given sample.  We then apply three cuts to remove certain kinds of
+bogus sources.  First, we exclude cosmic rays identified by
+\ippprog{psphot} by rejecting sources with the flag bit
+\code{PM_SOURCE_MODE_CR_LIMIT} (see Section~\ref{sec:source.size}).
+Next, we also remove detections with \ippmisc{PSF_QF} less than 0.95.
+Because this cut removes detections with heavy masking, it exclude a
+number of bogus detections due to glows and edge defects.  Finally, we
+also exclude  detections with \ippmisc{PSF_QF_PERFECT} less than
+0.95.  This cut removes detections on residual persistent glows and
+diffraction spikes.
+
+For the exposures at high-Galactic latitude, with a relatively low
+density of sources, the cosmic rays represent a significant
+contamination, as seen in the excess of bogus sources with \ips-band
+magnitudes in the range 17 - 19.  These are efficiently removed with
+the cosmic ray cut listed above without noticable impact on the
+completeness.  The other two cuts remove significant numbers of bogus
+detections, especially at the faint end, but at a significant cost in
+completeness at even brighter magnitudes.  The completeness impact of
+these cuts is more significant at low-Galactic latitude, likely
+because the chance of having a source lie on the diffraction spikes or
+persistence glows is greatly increased at higher stellar densities.
+The impact of the crowding on the completeness is also clear in this dataset.
+
 \subsection{Stellar Photometry Example}
 \label{sec:phot.example}
@@ -2498,8 +2749,8 @@
 configuration for \ippprog{psphot} as used for the full PV3
 \ippstage{chip} analysis.  The first image of the sequence is compared
-to the remaining 17 images.  A relative zero point correction is
+to the remaining 17 images.  A relative zero-point correction is
 applied, measured as the median of the photometry difference for stars
 with signal-to-noise greater than 50.  The combined error is reported
-and used to generate the histograms shows in the figures.  From these
+and used to generate the histograms shown in the figures.  From these
 two figures, one can observe the trade-off between PSF and aperture
 photometry.  For the brightest instrumental magnitudes, corresponding
@@ -2528,4 +2779,84 @@
 with the aperture photometry degrading rapidly as the flux of the star
 decreases.  
+
+{\TEXTADD The figures above show the relative photometric accuracy for
+  observations at a consistent pointing compared to the photon
+  counting statistics. A related question is to ask how consistent is
+  the photometry of the very brightest stars in terms of magnitudes.
+  Figure~\ref{fig:mag.resid.stdevs} shows the accuracy of the
+  brightest stars in these images for both PSF and aperture
+  magnitudes.  The relative zero point between the 1st image in the
+  sequence and each of the remaining images was calculated and the
+  standard deviations were measured using stars 7 to 8 magnitudes
+  brighter than the detection threshold, for which the photon noise is
+  less than 1 millimagnitude.  Significant zero-point differences
+  between the images are observed, largely due to the atmospheric
+  transparency variations.  Even so, the relative zero points
+  calculated from the aperture magnitudes have standard deviations of
+  2.4 - 7.4 millimags with a median of 3.5 millimags, while for PSF
+  magnitudes, the standard deviations are in the range 6.7 - 14.2
+  millimags, with a median of 9.2. }
+
+{\TEXTADD Our ultimate ability to accurately measure the brightness of
+  individual sources depends on a few factors: the accuracy of the
+  flat-field response, the consistency of the flux measurement across
+  the image (either due to the accuracy of the PSF model or the
+  accuracy of the aperture correction), and the accuracy of our
+  correction for any zero point changes.  Our ability to accurately
+  measure the zero point of each exposure depends in part on the
+  characteristics of the observing site.  In hazy conditions, the
+  transparency of the atmosphere may vary substantially in time but be
+  relatively stable across the field-of-view of the camera, as is
+  shown in Figure~\ref{fig:mag.resid.stdevs}.  Conversely, thin patchy
+  clouds can result in small average transparency changes but
+  substantial localized variations.  If the site experiences more
+  patchy clouds than smooth haze, photometric calibration will be
+  difficult.  A large fraction of time with cloudless conditions will
+  benefit the calibration.}
+
+{\TEXTADD To examine the Pan-STARRS site characteristics, we extracted
+  \ips\ zero points for the lifetime of the observatory (2009 June -
+  2020 April), shown in Figure~\ref{fig:zpt.iband}.  These zero points
+  were measured as part of the PV3 analysis of the $3\pi$ Survey, and
+  from the nightly data analysis after the end of the $3\pi$ Survey,
+  in both cases using the Pan-STARRS-based reference catalog.  The
+  zero points vary from night-to-night and over long periods.  Over
+  the 11 years of PS1 operation, the observed \ips-band zero point
+  (for data in good weather, extrapolated to the zenith), has varied
+  over 0.175 magnitudes (see Figure~\ref{fig:zpt.iband}).  The
+  long-term variations are believed to be due mostly to dust
+  accumulation on the primary mirror and occasional cleaning, though
+  the effect of the atmosphere cannot be ruled out.}
+
+{\TEXTADD Figure~\ref{fig:zpt.resid.hist} shows a log-scale histogram
+  of the \ips-band zero points after subtracting a smoothly varying
+  spline fit to the median of groups of 10 nights.  A Gaussian fit to
+  this distribution has $\sigma = 28.4$ millimags.  If we
+  alternatively subtract a median zero point for each night, the
+  standard deviation is reduced to 18.9 millimags.  These values can be
+  compared to the results of \cite{2012ApJ...756..158S} in which only
+  photometric nights were included, yielding a standard deviation of
+  9.0 millimags.  On short time scales, weather (e.g., clouds \& haze)
+  causes the deviations to lower zero point values.  A small fraction
+  of positive deviations also seen in Figure~\ref{fig:zpt.resid.hist}
+  which are not expected from the normal effects of weather.  We
+  believe these are largely due to aperture correction errors.}
+
+\subsection{Basic Analysis Summary}
+
+\textadd{This section is focused on the basic analysis of the image
+  for point-source detection and measurement.  This analysis is
+  applied as described to the invidual exposures in the
+  \ippstage{chip}-stage analysis and the measurements are exposed in
+  the public release PSPS database in the \ippdbtable{Detection}
+  table.  The same analysis is applied to the individual skycells in
+  the \ippstage{stack}-stage analysis and the resulting values are
+  presented in the PSPS \ippdbtable{StackObjectThin} and
+  \ippdbtable{StackObjectAttribute} tables, with the later presenting
+  values in instrumental units and the former giving calibrated
+  values.  The detection efficiency information determined from the
+  injection and recovery analysis is stored in the
+  \ippdbtable{ImageDetEffMeta} and \ippdbtable{StackDetEffMeta} tables
+  for the \ippstage{chip} and \ippstage{stack} stage analysis.  }
 
 \section{Extended Source Analysis}
@@ -2684,9 +3015,8 @@
 saved as equal-length vectors in the FITS table (\code{PROF_FLUX} and
 \code{PROF_FILL}).  The values of the radial bins are saved in the
-output file FITS header (\code{RMIN_NN}, \code{RMAX_NN}).  
-
-\note{specify PV3 config values?}
-
-% \note{these profiles are not saved in PSPS}
+output file FITS header (\code{RMIN_NN}, \code{RMAX_NN}).  \textadd{These
+measurements are saved in the catalog FITS files generated by
+\ippprog{psphot}, but they are not currently exported to the PSPS
+database for easy access.}
 
 \subsection{Petrosian Radii and Magnitudes}
@@ -2746,5 +3076,6 @@
 parameters were attempted, but for which the radial profile analysis
 failed have the flag bit
-\code{PM_SOURCE_MODE2_PETRO_NO_PROFILE} set.  
+\code{PM_SOURCE_MODE2_PETRO_NO_PROFILE} set.  \textadd{These measurements are
+available from the PSPS \ippdbtable{StackPetrosian} table.}
 
 
@@ -2959,4 +3290,10 @@
 \note{how much error does this approximation introduce?}
 
+The convolved galaxy model fit results are available in one of three
+PSPS database tables: \ippdbtable{StackModelFitExp},
+\ippdbtable{StackModelFitDeV}, \ippdbtable{StackModelFitSer} for the
+Exponential, DeVaucouleur, and S\'ersic models, respectively.
+
+
 \subsection{Fixed Aperture Photometry}
 \label{sec:fixed.aperture.photom}
@@ -3031,5 +3368,14 @@
 SDSS aperture magnitudes.}
 
-\note{test this?}
+\textadd{The measurements described in this subsection are presented
+  in the PSPS database (Paper VI) in the 
+  \ippdbtable{StackApFlxExGalUnc}, \ippdbtable{StackApFlxExGalCon6},
+ \ippdbtable{StackApFlxExGalCon8}, and \ippdbtable{StackApFlx} tables.
+ The first three tables present measurements for all apertures from
+ the unconvolved, 6, and 8-pixel FWHM convolved images (respectively)
+ while the last table presents a subset of the radii from all three
+ sets of measurements joined together for ease of access.}
+
+\note{test SDSS radial apertures?}
 
 % at least out to aperture # RADIAL_AP_MIN (= 4), but no further than
@@ -3190,8 +3536,11 @@
 Traditionally, projects which use multiple exposures to increase the
 depth and sensitivity of the observations have generated something
-equivalent to the stack images produced by the IPP analysis
-(c.f, CFHT Legacy survey, COSMOS, etc).  In theory, the photometry of
-the stack images produces the ``best'' photometry catalog,
-with best sensitivity and the best data quality at all magnitudes.  In
+equivalent to the stack images produced by the IPP analysis,
+\textadd{as done for example by the CFHT Legacy Survey
+  \citep{2006ApJ...647..116H} or the Cosmic Evolution Survey
+  \citep[COSMOS][]{2007ApJS..172...99C}}.  In theory, the photometry
+of the stack images produces the ``best'' photometry catalog, with
+best sensitivity and the best data quality at all magnitudes
+\citep[see e.g., the discussion of]{2017ApJ...836..187Z}.  In
 practice, these images have some significant limitations due to the
 difficulty of modeling the PSF variations.  This difficulty is
@@ -3201,4 +3550,7 @@
 single exposure, and the wide range of image quality conditions under
 which data were obtained and used to generate the $3\pi$ PV3 stacks.
+
+% CFHTLS release doc:
+% http://www.cfht.hawaii.edu/Science/CFHLS/T0007/CFHTLS_T0007-TechnicalDocumentation.pdf
 
 For any specific stack, the point spread function at a particular
@@ -3256,6 +3608,11 @@
 (Section~\ref{sec:ensemble.fitting}).
 
-\textmod{Aperture fluxes, Kron fluxes}, and moments are also measured at
-this stage for each warp.  Note that the flux measurement for a faint,
+\textmod{Aperture fluxes, Kron fluxes}, and moments are also measured
+at this stage for each warp.  \textmod{For the Kron fluxes, the radii
+  are fixed to the value determined in the analysis of the stack.
+  Fluxes are also measured in 3 of the fixed apertures discussed in
+  Section~\ref{sec:fixed.aperture.photom}: those with 3.00, 4.64,
+  and 7.44 arcsecond radii.}
+  Note that the flux measurement for a faint,
 but significant, source from the stack image may be at a low
 significance (less than the $5\sigma$ criterion used when the
@@ -3277,5 +3634,10 @@
 system.  The PSF photometry measurements are combined in the context
 of the DVO database system \citep{magnier2017.datasystem}, including
-recalibration of the zero points for the individual warp.
+recalibration of the zero points for the individual warp.  \textadd{These
+measurements for each warp are available from the PSPS database
+\ippdbtable{ForcedWarpMeasurement} and \ippdbtable{ForcedWarpExtended}
+tables, the latter containing the three fixed-aperture fluxes.  The
+average values calculated over the warps are found in the
+\ippdbtable{ForcedMeanObject} tables.}
 
 \note{discuss the relative quality of average exposure, forced warp
@@ -3339,5 +3701,7 @@
 In this way, the forced galaxy model analysis uses the PSF information
 from each warp image to determine a best set of convolved galaxy
-models for each galaxy model measured for the stack image.
+models for each galaxy model measured for the stack image.  The
+results of these galaxy model fits are available from the PSPS
+database \ippdbtable{ForcedGalaxyShape} table.
 
 \subsection{Galaxy Lensing Parameters}
@@ -3527,4 +3891,9 @@
 \code{PSF_QF_PERFECT} is less than 0.85.
 
+The lensing parameters measured for individual warps are available
+from the PSPS database \ippdbtable{ForcedWarpLensing} table while the
+average values calculated over the warps is found in the
+\ippdbtable{ForcedMeanLensing} tables.
+
 % \note{example of using the lensing elements for binaries?}
 
@@ -3673,4 +4042,19 @@
 \section{Conclusions}
 
+\note{add lessons learned here}
+
+\begin{verbatim}
+Suggestions for improvements / changes
+* use more external knowledge: 
+  ** Gaia or PS1 to select stars as PSF sources
+  ** pre-seed information about the very bright or very crowded
+                regions
+* background model
+  ** allow the superpixel scale to change as a function of environment
+  ** do not use the lower-end model unless region is known to be dense
+* use galactic latitude or local stellar density to smoothly
+  transition from double / multi-PSF to galaxy model fitting
+\end{verbatim}
+
 The Pan-STARRS Image Processing Pipeline has used the \ippprog{psphot}
 software to detect and characterize astronomical sources in images
Index: /trunk/doc/release.2015/ps1.analysis/response.txt
===================================================================
--- /trunk/doc/release.2015/ps1.analysis/response.txt	(revision 41332)
+++ /trunk/doc/release.2015/ps1.analysis/response.txt	(revision 41333)
@@ -16,5 +16,5 @@
 data sets.
 
-**** TBD : all of these items until Abstract
+** added to the end of Section 3 Psphot Design Goals
 
 For many of the sections, the reader would benefit by starting with
@@ -77,5 +77,7 @@
 state the same for galaxy astrometry, fluxes and colors.
 
-**** TBD
+** for each section, we have added a summary of where the values may
+   be found, and added an overall summary of this issue to the end of
+   the Basic Analysis section.
 
 A detail of the code is presented (variable names, etc) that imply
@@ -96,5 +98,5 @@
 that the photometric goals are achieved
 
-**** TBD see note section Forced PSF Phot
+**** TBD : discuss relative quality of chip, forced, stack photometry
 
 - Sec 7, where the image differencing detections and photometry is used
@@ -124,5 +126,5 @@
 in one place would be a useful service.
 
-**** TBD
+**** TBD : summarize the lessons learned
 
 Abstract:
@@ -219,5 +221,9 @@
 applying to bright sources, and another addessing all (==faint) sources.
 
-**** TBD 
+** We have expanded the discussion in 4.7 (Faint Source Analysis) to
+   explain which of the steps in the bright source pass are repeated
+   and which are skipped.  We refer back to the specific sections and
+   explain where there are detailed differences in the bright and
+   faint versions of the same step.
 
 Sec 4.1:
@@ -227,9 +233,14 @@
 of Sec 4.8) that the PSF model for an image is actually selected.
 
-**** TBD 
 ** The aperture correction is measured at the end of the bright-star
-** pass, at which point the PSF model is chosen and fixed.  A final
-** aperture correction is measured at the end of the full analysis,
-** but only for the PSF model class selected earlier.
+   pass, at which point the PSF model is chosen and fixed for the rest
+   of the analysis.  A final aperture correction is measured at the
+   end of the full analysis, but only for the PSF model class selected
+   earlier.  But for PV3, the PDF model was fixed to the PS1_V1
+   version, so this selection was not performed. We have added text to
+   4.5.3 to explain how the aperture correction is used to select a
+   PSF model, and that only the single model form was used for PV3.
+   We also note in section 4.8 that we re-measure the aperture
+   correction at the end with the other sources subtracted.
 
 Sec 4.3:
@@ -264,5 +275,7 @@
 measure is used.
 
-**** TBD: model?
+** added a table showing sky recovery vs stellar density from
+   simulations using the standard psphot analysis vs other methods,
+   added discussion of the results.
 
 Sec 4.4.1:
@@ -319,4 +332,6 @@
 
 **** TBD: SHOW SOME EXAMPLES of PSF variations 
+     choose 3 exposures: 1 with good IQ, one with bad IQ, but round, one with bad IQ but not round,
+     plot some IQ stats (Mxx - Myy) / (Mxx + Myy)
 
 - Please state whether the PSF model is this set of formulae
@@ -344,5 +359,6 @@
 sources by GAIA.
 
-***** TBD
+** This is an interesting suggestion, but out of the scope of this
+   effort.  we have added this to the lessons-learned discussion
 
 Sec 4.5.3:
@@ -419,10 +435,12 @@
 and presented as a future development effort.
 
-**** TBD
+**** TBD : wording of full PSF model section 4.6.6
 
 - Remind the reader that the 4 independent parameters includes a local sky
 value.
 
-**** TBD: double-check if the sky is allowed to float in this step
+** in fact, we do not allow the sky to float; fixed the wording to
+   specify the *3* independent parameters and to explain why we do not
+   allow the sky to float.
 
 - "remaining flux should be below 1\sigma significance" ->
@@ -437,5 +455,5 @@
 range.
 
-**** TBD: was the turned on for PV3?
+**** TBD: double-star mode: was this turned on for PV3? ppSim to show recovery
 
 Sec 4.7:
@@ -444,5 +462,7 @@
 could be included here.
 
-**** TBD: include detection limit description
+** This was a definitely gap.  We have added a subsection (4.9)
+   discussing the completeness and contamination, using both simulated
+   and real data to illustrate these effects
 
 Sec 4.8:
@@ -501,5 +521,9 @@
 atmospheric transparency variations.
 
-**** TBD
+** we have added discussion and some plots showing the repeatability
+   of the brightest stars for PSF and aperture magnitudes.  We also
+   discuss the long-term site characteristics and the impact of the
+   atmosphere on the photometric calibration, relating back to the
+   ubercal work of Schlaley et al 2012.
 
 Sec 5:
@@ -534,5 +558,5 @@
 compare well to those in the PS1 catalog?
 
-**** TBD: compare to SDSS
+**** TBD: compare Petrosian mags to SDSS for some example
 
 Sec 5.3:
@@ -561,5 +585,5 @@
 error of this approximation should be stated.
 
-**** TBD: model
+**** TBD: model central pixel errors for Sersic models
 
 Sec 5.4:
@@ -626,5 +650,5 @@
 discussion would be Zackay & Ofek 2016.
 
-**** TBD
+** added references and updated the text
 
 - The terms "skycell" and "warp image" are first used here without
@@ -664,5 +688,5 @@
 and if not, which code would it be most similar to?
 
-**** TBD
+**** TBD : check on GREAT challenge to compare code 
 
 - Define "KSB" and "HFK" references in-line
@@ -789,5 +813,5 @@
 - Some additional references should be included; some suggestions above.
 
-**** TBD
+** added additional references
 
 ** Also, we have added Danny Farrow (UK Durham & MPIA) to the authors
