Index: /trunk/doc/release.2015/ps1.analysis/analysis.tex
===================================================================
--- /trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 39813)
+++ /trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 39814)
@@ -1,3 +1,3 @@
-\documentclass[iop,floatfix]{emulateapj}
+\documentclass[iop,floatfix,onecolumn]{emulateapj}
 % \pdfoutput=1
 
@@ -93,14 +93,4 @@
 \keywords{Surveys:\PSONE }
 
-\section{OUTLINE}
-\begin{verbatim}
-Intro
- Pan-STARRS background
- Scope: Source Detection \& Characterization, Galaxy modeling
- Requirements / Goals
- Comparable programs
- PSPhot
-\end{verbatim}
-
 \section{INTRODUCTION}\label{sec:intro}
 
@@ -441,7 +431,4 @@
 \subsubsection{Determination of the Peak Coordinates and Errors}
 
-\note{this section is wrong: it is a poor estimator of the source
-  position errors.  we gave up a reverted to using the FWHM / (S/N)}
-
 We use the 9 pixels which include the source peak to fit for the
 position and position errors.  We model the peak of the sources as a
@@ -478,15 +465,4 @@
 \end{verbatim}
 
-which can be used to determine the errors on the coefficients: 
-
-\begin{eqnarray}
-\sigma^2_{00} & = & \sigma^2 (5/9) \\
-\sigma^2_{10} & = & \sigma^2 (1/6) \\
-\sigma^2_{01} & = & \sigma^2 (1/6) \\
-\sigma^2_{11} & = & \sigma^2 (1/6) \\
-\sigma^2_{20} & = & \sigma^2 (1/2) \\
-\sigma^2_{02} & = & \sigma^2 (1/2) \\
-\end{eqnarray}
-
 The location of the peak is determined from the minimum of the
 bi-quadratic function above, and is given by:
@@ -498,13 +474,5 @@
 \end{eqnarray}
 
-Applying error propagation to the above, we find:
-
-\begin{eqnarray}
-\sigma_{Det}^2  & = & \sigma_{11}^2 (4 C_{11}^2) + \sigma_{20}^2 (16 C_{02}^2) + \sigma_{02}^2 (16 C_{20}^2) \\
-\sigma_{xn}^2   & = & \sigma_{11}^2 C_{01}^2 + \sigma_{01}^2 C_{11}^2 + \sigma_{02}^2 (4 C_{10}^2) + \sigma_{10}^2 (4 C_{02}^2) \\
-\sigma_{yn}^2   & = & \sigma_{11}^2 C_{10}^2 + \sigma_{10}^2 C_{11}^2 + \sigma_{20}^2 (4 C_{01}^2) + \sigma_{01}^2 (4 C_{20}^2) \\
-\sigma_{x}^2    & = & x^2 (\sigma_{xn}^2 / xn^2 + \sigma_{Det}^2 / Det^2) \\
-\sigma_{y}^2    & = & y^2 (\sigma_{yn}^2 / yn^2 + \sigma_{Det}^2 / Det^2) \\
-\end{eqnarray}
+\note{error on the peak position}
 
 \subsection{PSF Determination}
@@ -652,14 +620,14 @@
 All candidate PSF objects are then fitted with the selected object
 model, allowing all of the parameters (PSF and independent) to vary in
-the fit.  PSPhot uses the Levenberg-Marqardt process for the
-non-linear fitting.  Non-linear fitting can be very computationally
-intensive, particularly for if the starting parameters are far from
-the minimization values.  PSPhot uses the first and second moments to
-make a good guess for the centroid and shape parameters for the PSF
-models.  \note{still true? In order to minimize the impact of close
-  neighbors, the variance values used in the fit are enhanced by a
-  fraction of the deviation of the particular pixel value from the
-  model guess.}  Any objects which fail to converge in the fit are
-flagged as invalid.
+the fit.  PSPhot uses the Levenberg-Marqardt method \note{REF, link to
+  psLibADD} for the non-linear fitting.  Non-linear fitting can be
+very computationally intensive, particularly for if the starting
+parameters are far from the minimization values.  PSPhot uses the
+first and second moments to make a good guess for the centroid and
+shape parameters for the PSF models.  \note{still true? In order to
+  minimize the impact of close neighbors, the variance values used in
+  the fit are enhanced by a fraction of the deviation of the
+  particular pixel value from the model guess.}  Any objects which
+fail to converge in the fit are flagged as invalid.
 
 \note{does the variance enhancement introduce too much bias?}
@@ -698,21 +666,13 @@
 correction is judged to be the best model.
 
-\subsubsection{Basic Deblending}
-
-The collection of identified peaks is examined to find peaks which are
-'blended', that is, they are close enough together to make the
-analysis of one of the sources difficult if performed in isolation.
-Saturated stars also result in additional peaks which are likely to be
-invalid; it is useful to restrict a saturated star to a single primary
-position with associated neighboring peaks.
-
-The deblending process first searches for any peaks which are within
-the image cell of another peak.  All such groups are examined,
-starting with the brightest source.  An isophot is found about the
-primary peak which is at least \code{DEBLEND\_SKY\_NSIGMA} times the sky
-sigma above the local background and which is otherwise
-\code{DEBLEND\_PEAK\_FRACTION} of the primary peak central pixel flux.
-Any secondary sources which are contained within this isophot are
-considered to be blended peaks associated with the primary peak.  
+\subsection{Very Bright Stars}
+\note{flesh out}
+
+The PSF modeling code fails to fit the wings of highly saturated stars
+if the core of the star is too contaminated by saturated pixels. For
+stars with estimated instrumental magnitudes brighter than XXX, we fit
+and subtract a radial profile modeled with a spline (?).
+
+\subsection{PSF vs CR vs Extended}
 
 \subsection{Bright Source Analysis}
@@ -1071,5 +1031,164 @@
 tested.
 
-\subsubsection{Types of Object / PSF models currently available}
+\subsection{Radial Profiles}
+
+Galaxies with regular profiles, such as elliptical galaxies and
+regular spiral galaxies, may be described as primarily a radial
+surface brightness profile, with additional structure acting as a
+perturbation on that profile.  For many galaxies, the azimuthal shape
+at a given isophotal level may be described as an elliptical contour.
+To first order, a galaxy may be well decribed with a single elliptical
+contour and radial profile.  
+
+In order to facilitate the Petrosian photometry analysis below, PSPhot
+generates a radial profile for each suspected galaxy.  This analysis
+starts by generating a radial profile in 24 azimuthal segments.  Near
+the center of the galaxy, the profile is defined for radial
+coordinates in steps of 1 pixel, with the closest pixel values
+interpolated to that radial position.  Further from the center,
+profile is defined using the median of the pixels landing in an
+annular segment of size $\delta R = r \sin \theta$, rounded up to the
+nearest integer pixel value.  The median of all pixels within a
+rectangular approximation to the radial wedge is used.
+
+The resulting 24 radial profiles are subject to contamination from
+neighboring sources or to NAN values from masked pixels.  To clean the
+profiles, pairs of radial profiles from opposite sides of the source
+are compared.  Any masked values are replaced by the corresponding
+value in the other profile.  The minimum of both profiles is the kept
+for both profiles.  The result of this analysis is a set of profiles
+of the form $f_i(r_i)$.  In this case, $f_i$ is effectively the
+surface brightness for each radius in instrumental counts per pixel.
+
+The surface brightness profiles are then used to define the radial
+contour at a specific isophotal level.  This contour will be used to
+rescale the radial profiles into a single set of profiles normalized
+by the elliptical contour.  This contour is defined by determining the
+median radius for profile bins with surface brightness in the range
+$F_{\rm min} + 0.1 F_{\rm range}$ to $F_{\rm min} + 0.5 F_{\rm
+  range}$.  The result of this analysis is a value for the radius as a
+function of the angle for a well-defined surface brightness regime.
+We then determine the elliptical shape parameters for this elliptical
+contour: $R_{\rm major}, R_{\rm minor}, \theta$.  This ellipse is then
+used to redefine a single radial profile normalized by the elliptical
+contour: 
+\[
+\rho = \sqrt{\frac{x^2}{S^2_{xx}} + \frac{y^2}{S^2_{yy}} + x y S_{xy} \\
+\]
+
+The surface brightness values are sampled at a number of radial
+annuli, with the radii defined in the configuration ({\tt
+  RADIAL.ANNULAR.BINS.LOWER \& RADIAL.ANNULAR.BINS.UPPER}).  For each
+source, the resulting surface brightness profile is saved in the
+output cmf-file as an N-element value in the FITS table ({\tt
+  PROF\_SB}).  The flux at each radial position and the fill-factor
+(fraction of pixels used to the total possible) as also saved as
+equal-length vectors in the FITS table ({\tt PROF\_FLUX and
+  PROF\_FILL}).  The values of the radial bins are saved in the cmf
+header ({\tt RMIN\_NN, RMAX\_NN}).
+
+\note{these profiles are not saved in PSPS}
+
+\subsection{Petrosian Radii and Magnitudes}
+
+Petrosian (REF) defined an adaptive aperture based on a ratio of
+surface brightnesses.  The motivation is to define an aperture which
+can be determined for galaxies without significant biases as a
+function of distance.  Since surface brightness in a resolved object
+is conserved, using a ratio of surface brightness to define a spatial
+scale results in a spatial scale which is constant regardless of
+galaxy distance.  
+
+In the classic definition, a reference radius, R90
+is specified as the radius at which the flux
+
+To measure the Petrosian radius and flux, we start by defining a
+series of radial apertures with power-law spacing: $r_{i + 1} = 1.25
+r_i$.  We calculate the surface brightness for the annulus from $r_i -
+r_{i+1}$ by calculating the median of the values in the range $r_i /
+\sqrt{1.25}$ to $r_{i+1} \sqrt{1.25}$ and dividing the the effective
+area of the annulus corresponding to $r_i - r_{i+1}$.  
+
+For any annulus $i$ spanning the radii $r_{\rm min}$ to $r_{\rm max} =
+\Beta r_{\rm min}$, the
+Petrosian Ratio for that annulus is defined as the ratio of the
+surface brightness in the annulus to the average surface brigthness
+within $r_{\rm max}$.  The Petrosian Radius is defined to be $r_{\rm
+  max}$ for the annulus for which the Petrosian Ratio = 0.2, i.e., the
+point on the galaxy radial profile at which the surface brightness is
+20\% of the average surface brightness at that point.  
+
+We determine the Petrosian Radius for the galaxy by quadratic
+interpolation between the last two of the fixed annuli with Petrosian
+Ratio $> 0.2$ and the first annulus with Petrosian Ratio $< 0.2$.  In
+general, the Petrosian Ratio for a galaxy with a regular morphology
+(spiral or elliptical) is falling monotonically, so this interpolation
+is unambiguous.  However, irregular galaxy morphologies, noise, and/or
+significant masking can cause the Petrosian Ratio to have rises as
+well as drops.  We track the Petrosian Ratio until the value is no
+longer significant ($\sigma_{\rm Ratio} < 2 {\rm Ratio}$).  If the
+Petrosian Ratio drops below 0.2 for more than one radius, we choose
+the largest such radius.  
+
+Once the Petrosian Radius has been determined, we can now measure the
+Petrosian Flux : this is defined to be the total flux within an
+aperture corresponding to 2 $\times$ the Petrosian Radius.  Using the
+Petrosian Flux, we can calculate two other interesting radii: $R_{50}$
+and $R_{90}$, the radii inside which 50\% and 90\% of the total
+Petrosian flux is contained.  
+
+\subsection{Kron Magnitudes}
+
+
+
+\subsection{Convolved Galaxy Model Fits}
+
+In the galaxy model fittting stage, sources which meet certain
+criteria are fitted with analytical models for galaxies.  The
+available models for the PV3 analysis were:
+\begin{itemize}
+\item Exponential profile : $f = I_0 e^{\frac{-r}{r_0}}$
+\item DeVaucouleur profile : $f = I_0 e^{\frac{-r^{1/4}}{r_0}}$
+\item Sersic : $f = I_0 e^{\frac{-r^{1/n}}{r_0}}$
+\end{itemize}
+
+In this stage, the galaxy model is convolved with our best guess for
+the PSF model at the location of the galaxy.  For the PV3 analysis,
+all sources detected in the 'bright source' analysis step (S/N > 20 ?)
+were fitted with all three galaxy models, unless (a) the morphological
+test identified the source as a likely cosmic ray (\ref{CR})
+or (b) the peak of the PSF profile was above the saturation limit
+\note{for the chip? cell?}.  Sources in the denser portions of the
+Galactic plane and bulge were not included in the analysis.  This
+restriction limited the total time spent on the galaxy modeling
+analysis at the expense of galaxy photometry in the plane (though Kron
+photometry is available for those objects).
+
+The Galactic Plane region was defined by $|b| > b_{\rm min}$ where
+$b_{\rm min} = b_0 + r_b e^{\frac{-l^2}{2 \sigma_b^2}}$.  For the PV3
+analysis, $b_0 = XX$, $r_b = XX$, $\sigma_b = XX$.
+
+The galaxy models are fitted using the same Levenberg-Marquart
+minimization code use for the other non-linear fitting stages.  In the
+convolved galaxy fit, the galaxy model image and the model derivative
+images are convolved with the psf at each iteration. WRITE out the
+chi-square and show how this is separated out as a set of images.  For
+the Exponential and DeVaucouleur fits, all parameters are fitted in
+the non-linear minimization stage.  For the Sersic model fits, there
+is too much degeneracy (yes?) between ???.  We determine the Sersic
+index using a grid search, using the non-linear minimization for the
+remaining parameters on each grid search step.  The index is fitted in
+the following values (XXXXX).
+
+With XXXM galaxies to It is important to make an initial guess for the model parameters
+which is reasonably close to the best fit value, 
+
+\subsection{Convolved Radial Aperture Photometry}
+
+\subsection{Forced Photometry : PSFs}
+
+\subsection{Forced Photometry : galaxies}
+
+\subsection{Types of Object / PSF models currently available}
 
 \note{the discussion of the model types needs to be extended}
