IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 15, 2006, 2:26:07 PM (21 years ago)
Author:
eugene
Message:

fleshing out APIs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/psphot/psphot.tex

    r4902 r6005  
    142142  discussion and add in the references.}
    143143
     144\note{Add discussion of the lessons learned from experience with previous
     145  analysis programs}
     146
    144147The Pan-STARRS IPP team decided that none of the existing packages met
    145148all of their needs, particularly given the very challenging goals of
     
    156159Python).
    157160
    158 \note{Add discussion of the lessons learned from experience with previous
    159   analysis programs}
     161\section{PSPhot Design Goals}
     162
     163PSPhot has a number of important requirements that it must meet, and a
     164number of design goals which we believe will help to make usable in a
     165wide range of circumstances.  The critical requirements of the
     166Pan-STARRS IPP which drive the requirements for PSPhot:
    160167
    161168\begin{itemize}
    162 \item Flexible PSF model: functional form should be
    163   easily modified. 
    164 \item PSF variation is fundamental : PSF representation should incorporate 2-D variations. 
    165 \item Speed fitting with accurate parameter guesses.
    166 \item Make good use of moment information to speed analysis. 
    167 \item Careful definition of PSF validity tests. 
    168 \item Careful analysis of aperture corrections. 
    169 \item Flexible non-PSF models. 
    170 \item Good code abstraction to simplify modification.
     169\item {\bf 10 millimagnitude photometric accuracy}.  For PSPhot, this
     170  implies that the measured photometry of stellar objects must be
     171  substantially better than this 10 mmag since the photometry error
     172  per image is combined with an error in the flat-field calibration
     173  and an error in measuring the atmospheric effects.  We have set a
     174  goal for PSPhot of 3mmag photometric consistency for bright stars
     175  between pairs of images obtained in photometric conditions at the
     176  same pointing, ie to remove sensitivity to flat-field errors.  This
     177  goal splits the difference between the three main contributors and
     178  still allows some leeway.  This requirement must be met for
     179  well-sampled images and images with only modest undersampling.
     180
     181\item {\bf 10 milliarcsecond astrometric accuracy}. Relative
     182  astrometric calibration depends on the consistency of the individual
     183  measurements.  The measurements from PSPhot must be sufficiently
     184  representative of the true object position to enable astrometric
     185  calibration at the 10mas level.  The error in the individual
     186  measurements will be folded together with the errors introduced by
     187  the optical system, the effects of seeing, and by the available
     188  reference catalogs.  We have set a goal for PSPhot of 5mas
     189  consistency between the true source postion and the measured
     190  position given reasonable PSF variations under simulations.  This
     191  level must be reached for images with 250 mas pixels, implying
     192  PSPhot must introduce measurement errors less than 1/50th of a
     193  pixel.
     194
     195\item {\bf processing time of 45 seconds} This requirement depends
     196  strongly on the hardware organization, the amount of time spent on
     197  other analysis steps, the density of stars per image, and the depth
     198  for a given type of image.  For the sources at the faint limit (eg,
     199  $5\sigma$), the average density of sources is expected to be roughly
     200  $3\times10^5$ per square degree, while sources at the 20 $\sigma$
     201  level may have densities of $\sim 5\times10^4$ per square degree.
     202  Allowing 30 seconds for the PSPhot portion of the analysis, of which
     203  15 is used for careful analysis of the brighter sources, 10 seconds
     204  is used for PSF modeling and other overheads, and the remaining 5
     205  seconds is used for the PSF fitting of the faintest source implies
     206  that the detailed modelling may take roughly 3msec per source, and
     207  the basic PSF fitting may be allowed 150 usec per source.
    171208\end{itemize}
    172209
     210The design goals for PSPhot are chosen to make the program flexible,
     211general, and able to meet the unknown usages cases future projects may
     212require:
     213
     214\begin{itemize}
     215\item {\bf Flexible PSF model} Different image sources require
     216  different ways of representing the PSF.  Ideally, both analytical
     217  and pixel-based versions should be possible.
     218
     219\item {\bf PSF spatial variation} Most images result in some spatial
     220  PSF variations at a certain level.  The PSF representation should
     221  naturally incorporate 2-D variations.
     222
     223\item {\bf Flexible non-PSF models} PSPhot must be able to represent
     224  PSF-like objects as well as non-PSF sources.  It must be easy to add
     225  new object models as interesting representations of sources are
     226  invented.
     227
     228\item {\bf Clean code base} PSPhot should incorporate a high-degree of
     229  abstraction and encapsulation so that changes to the code structure
     230  can be performed without pulling the code apart and starting from scratch.
     231
     232\item {\bf PSF validity tests} PSPhot should include the ability to
     233  choose different types of PSF models for diffent situations, or to
     234  provide the user with methods for assessing the different PSF models.
     235
     236\item {\bf Careful aperture corrections} PSPhot must carefully measure
     237  and correct for the photometric and astrometric trends introduced by
     238  using analytical PSF models.
     239
     240\item {\bf User Configurable} PSPhot should allow users to change the
     241  options easily and to allow different approaches to the analysis.
     242
     243\end{itemize}
     244
    173245\section{PSPhot Analysis Process}
    174246
     
    178250
    179251\begin{itemize}
    180 \item image preparation - load data, characterize the image
     252\item {\bf Image preparation} Load data, characterize the image
    181253  background, load or construct noise and mask images.
    182254
    183 \item initial object detection - smooth, find peaks, measure basic
    184   properties
    185 
    186 \item PSF determination - select PSF candidates, perform model fits,
    187   build PSF model from fits, select best PSF model class, determine
    188   image aperture corrections. 
    189 
    190 \item Fit PSF objects - fit objects with PSFs, determine PSF validity,
    191   subtract PSF-like objects
    192 
    193 \item Fit non-PSF objects - fit non-PSF model, select best model
    194   class, subtract model
    195 
    196 \item low S/N sources - detect low-level sources, measure properties
    197 
    198 \item output - write out objects in selected format, write out
     255\item {\bf Initial object detection} Smooth, find peaks, measure basic
     256  properties
     257
     258\item {\bf PSF determination} Select PSF candidates, perform model
     259  fits, build PSF model from fits, select best PSF model class.
     260
     261\item {\bf Bright object analysis} Fit objects with PSFs, determine
     262  PSF validity, subtract PSF-like objects, fit non-PSF model(s),
     263  select best model class, subtract model.
     264
     265\item {\bf Low S/N sources} Detect low-level sources, measure
     266  properties (aperture or PSF)
     267
     268\item {\bf Aperture corrections} Measure the curve-of-growth, spatial
     269  aperture variations, and background-error corrections. 
     270
     271\item {\bf Output} Write out objects in selected format, write out
    199272  difference image, noise image, etc, as selected.
    200273\end{itemize}
    201274
    202 \note{the current configuration variables and some of the function
    203   names are not very well chosen.  expect these to be modified as the
    204   code base is cleaned.}
     275Note that a given run of PSPhot \note{should} allow the user to
     276perform any of these stages as an option.  For example, the PSF model
     277may already be available from external information, in which case the
     278PSF modeling stage can be skipped.  Or, when used as a library
     279function, the image may have already been loaded and the mask and
     280weight images constructed.  In some implementations, it may be
     281possible to skip the initial object detection stage because only
     282supplied sources are measured.  These are only some of the possible
     283configurations.  The use of these different configurations depends on
     284the source of the image, the desired detail and speed of the
     285processing, and the level of accuracy desired from the analysis.
    205286
    206287\subsection{Image Preparation}
     
    241322\code{XMIN}, \code{XMAX}, \code{YMIN}, \code{YMAX}.
    242323
    243 \note{minimum valid data value is currently unimplemented}
    244 
    245 \note{mask values are currently hard-wired numbers : they should be
    246 given named enum values}
     324\note{Mask values are currently hard-wired numbers.  We need a method
     325  for user-defined mask values to be supplied.  PSLib needs to have a
     326  mask registration system.}
    247327
    248328The noise image, if not supplied is constructed by default from the
     
    267347dependent on the form of this smoothing function.
    268348
    269 \note{Is this smoothing needed?}
     349\note{Is this smoothing needed?  we could save time here by skipping
     350it.}
    270351
    271352The local peaks in the smoothed image are found by first detecting
     
    412493represent the shape in some way}.
    413494
    414 \subsubsection{PSF Object Candidate Selection}
     495\subsubsection{PSF Candidate Object Selection}
    415496
    416497The first stage of determining the PSF model for an image is to
     
    446527the image. 
    447528
    448 \subsubsection{PSF candidates object model fits}
     529\subsubsection{PSF Candidate Object Model Fits}
    449530
    450531All candidate PSF objects are then fitted with the selected object
     
    453534non-linear fitting.  Non-linear fitting can be very computationally
    454535intensive, particularly for if the starting parameters are far from
    455 the minimization values.  PSPhot uses a the first and second moments
    456 to make a good guess for the centroid and shape parameters for the PSF
     536the minimization values.  PSPhot uses the first and second moments to
     537make a good guess for the centroid and shape parameters for the PSF
    457538models.  In order to minimize the impact of close neighbors, the noise
    458539values used in the fit are enhanced by a fraction of the deviation of
     
    490571ApResid}) is a critical parameter for any PSF modeling software which
    491572uses an analytical model to represent the flux distribution of the
    492 objects in an image.
     573objects in an image.  An approximate correction is measured here, with
     574a more detailed correction measured after all object analysis is
     575performed.  The PSF model with the best consistency of the aperture
     576correction is judged to be the best model.
     577
     578\subsubsection{Basic Deblending}
     579
     580The collection of identified peaks is examined to find peaks which are
     581'blended', that is, they are close enough together to make the
     582analysis of one of the sources difficult if performed in isolation.
     583Saturated stars also result in additional peaks which are likely to be
     584invalid; it is useful to restrict a saturated star to a single primary
     585position with associated neighboring peaks.
     586
     587The deblending process first searches for any peaks which are within
     588the image cell of another peak.  All such groups are examined,
     589starting with the brightest source.  An isophot is found about the
     590primary peak which is at least \code{DEBLEND_SKY_NSIGMA} times the sky
     591sigma above the local background and which is otherwise
     592\code{DEBLEND_PEAK_FRACTION} of the primary peak central pixel flux.
     593Any secondary sources which are contained within this isophot are
     594considered to be blended peaks associated with the primary peak. 
     595
     596\subsection{Bright Source Analysis}
     597
     598After a PSF model has been determined, PSPhot performs the analysis of
     599the bright objects in the image.  In this stage, all of the objects
     600with an estimated signal to noise (based on the moments analysis)
     601greater than a user-set threshold are analysed and subtracted from the
     602image.  An optional successive stage then finds fainter sources and
     603measures them as well (see Faint Source Analysis,
     604Section~\ref{faintsources}).  In the bright source analysis stage, two
     605major varients are available.  In the primary version, all objects are
     606examined (in decending order of brightness) and an appropriate models
     607is determined for each object which is then subtracted; in the
     608alternate version, the objects are examined (in decending order of
     609brightness) and the PSF-like objects subtracted first, then the
     610extended objects are analysed on a second pass.
     611
     612\subsubsection{Fast Ensemble PSF Fitting}
     613
     614Before the detailed analysis of the objects is performed, it is
     615convenient to subtract off all of the sources, at least as well as
     616possible at this stage.  We make the assumption that all sources are
     617PSF-like.  We also assume their position can be taken as the peak of a
     6182D quadratic function fitted to the peak pixel and its surrounding 8
     619pixels.  A single linear fit is used to simultaneously measure all
     620source fluxes.  Since the local sky has been subtracted, this
     621measurement assumes the local sky is zero. 
     622
     623\[
     624\chi^2 = \sum_{\rm pixels} (F_{x,y} - \sum_{\rm sources} A_i PSF[x,y])^2
     625\]
     626
     627Minimizing this equation with respect to each of the $A_i$ values
     628results in a matrix equation:
     629\[ M_{i,j} \bar{A_i} = \bar{F_j}\]
     630where $\bar{A_i}$ is the vector of $A_i$ values, the elements of
     631$M_{i,j}$ consist of the dot product of the unit-flux PSF for source
     632$i$ and source $i$, and $\bar{F_j}$ is the dot product of the
     633unit-flux PSF for source $i$ with the pixels corresponding to source
     634$i$.  The dot products are calculated only using pixels within the
     635source apertures.  Since most sources have no overlap with most other
     636sources, this matrix equation results in a very sparse, mostly
     637diagonal square matrix.  The dimension is the number of sources,
     638likely to be 1000s or 10,000s.  Such a matrix does not lend itself to
     639direct inversion.  However, an interative solution quickly yields a
     640result with sufficient accuracy.  In the iterative solution, a guess
     641at the solution is made; the guess is multiplied by the matrix, and
     642the result compared with the observed vector $\bar{F_j}$.  The
     643difference is used to modify the initial guess. This proces is
     644repeated several times to achieve a good convergence. 
     645
     646Once a solution set for $A_i$ is found, all of the objects are
     647subtracted from the by applying these values to the unit-flux PSF.
     648
     649\subsubsection{PSF Model applied to detected objects}
     650
     651Once a PSF model has been selected for an image, PSPhot attempts to
     652fit all of the detected objects, above a user-defined signal-to-noise
     653ratio (\note{KEYWORD}) with the PSF model.  For these fits, the
     654dependent parameters are fixed by the PSF model and only the 4
     655independent object model parameters are allowed to vary in the fit.
     656PSPhot again uses the Levenberg-Marqardt process for the non-linear
     657fitting.  The objects are fitted in their S/N order, starting with the
     658brightest and working down to the user-specified limit.
     659
     660Once a solution has been achieved, PSPhot attempts to judge the
     661quality of the PSF model as a representation of the object shape.  To
     662do this, it calculates the next step of the minimization {\em allowing
     663the shape parameters to vary}.  This step, essentially the
     664Gauss-Newton minimization distance from the current local minimum,
     665should be very small if the object is well represented by the PSF, but
     666large if the PSF is not a good representation of the object flux.  The
     667model quality is judged by the change in the two shape parameters
     668which represent the 2D size of the object.  For the case of the
     669elliptical Gaussian, these two parameters are $\sigma_x$ and
     670$\sigma_y$.  For a generic model, the shape parameters may be defined
     671differently, but the should always be two parameters which scale the
     672object size in two dimensions (what about a polar-coordinate form?)
     673Currently, PSPhot requires the two relevant shape parameters to be the
     674first two dependent parameters in the list of model parameters (ie,
     675parameters 4 \& 5).
     676
     677The expected distribution of the variation of the two shape parameters
     678will be a function of the signal-to-noise of the object in question
     679and the value of the shape parameter itself.  The expected standard
     680deviation on the shape parameter is, eg, $\sigma_x / {\rm SN}$.  If
     681the object is well-represented by the PSF, then the shape parameter
     682values should be close to their minimization value.  We can thus ask,
     683for each object, given the measured amplitude of the Gauss-Newton
     684step, how many standard deviations from the expected value (of 0.0) is
     685this particular value?  Objects for which the variation in the shape
     686parameters is a large positive number of standard deviations are
     687likely to be better represented by a larger flux distribution than the
     688PSF (eg, a Galaxy or Comet, etc).  Objects for which the variation in
     689the shape parameters is a large negative number of standard deviations
     690are likely to be better represented by a smaller flux distribution
     691than the PSF (ie, a cosmic ray or other defect).  A user-defined
     692number of standard deviations is used to select these two cases, and
     693to flag the object as a likely galaxy (really meaning 'extended') or
     694as a likely defect. 
     695
     696At this stage of the analysis, PSPhot uses two additional indicators
     697to identify good and poor PSF fits.  The first of these is the
     698signal-to-noise ratio.  It is possible for the peak finding algorithm
     699to identify peaks in locations which are not actually a normal peak.
     700Some of these cases are in the edges of saturated, bleeding columns
     701from bright stars, in the nearly flat halos of very bright stars, and
     702so on.  In these cases, a local peak exists, with a lower nearby sky
     703region.  However, the fitted PSF model cannot converge on the peak
     704because it is very poorly defined (perhaps only existing in the
     705smoothed image).  The fit can either fail to converge or it can
     706converge on a fit with very low or negative peak flux / flux
     707normalization.  PSPhot will flag any non-convergent PSF fit and any
     708object with PSF S/N ratio lower than a user-defined cutoff.  It is
     709also useful to identify very poor fits by setting a maximum Chi-Square
     710cutoff for objects. 
     711
     712As the objects are fitted to the PSF model, those which survive the
     713exclusion stage are subtracted from the image.  The subtraction
     714process modifies the image pixels (removing the fitted flux, though
     715not the locally fitted background) but does not modify the mask or the
     716noise images.  The signal-to-noise ratio in the image after
     717subtraction represents the significance of the remaining flux.  If the
     718subtractions are sufficiently accurate models of the PSF flux
     719distribution, the remaining flux should be below 1 $\sigma$
     720significance.  In practice the cores of bright stars are poorly
     721represented and may have larger residual significance. \note{in future
     722work, we may choose to enhance the noise to minimize detection of
     723objects in the residuals of brighter objects}.
     724
     725\subsubsection{Blended Sources}
     726
     727Sources which are blended with other sources are fitted together as a set of
     728PSFs.  A single multi-object fit is performed on all blended peaks.
     729The resulting fits are evaluated independently and any which are
     730determined to be PSFs are subtracted from the image.
     731
     732\subsubsection{Double Sources}
     733
     734Sources which are judged to be non-PSF-like are confronted with two
     735possible alternative choices.  First, the object is fitted with a
     736double-source model.  In this pass, the assumption is made that there
     737are two neighboring sources, but the peaks are blended together, or
     738otherwise not distinguished.  The initial guess for the two peaks is
     739made by splitting the flux of the single source in half and locating
     740the two starting peaks at +/- 2 pixels from the original peak along
     741the direction of the semi-major axis of the sources, as measured from
     742the second moments.  In order for the two-source model to be accepted,
     743both sources must be judged as a valid PSF source.  Otherwise, the
     744double-PSF model is rejected and the source is fitted with the
     745available non-PSF model or models.
     746
     747\note{better description of the acceptance criteria; the FLT model is
     748  tried before the DBL is accepted or rejected}.
     749
     750\subsubsection{Non-PSF Objects}
     751
     752Once every object (above the S/N cutoff) has been confronted with the
     753PSF model, the objects which are thought to be galaxies (extended) can
     754now be fit with appropriate models for the galaxies (or other likely
     755extended shapes).  Again, the fitting stage starts with the brightest
     756sources (as judged by the rough S/N measured from the moments
     757aperture) and working to a user defined S/N limit. 
     758
     759PSPhot will use the user-selected galaxy model to attempt the galaxy
     760model fits.  In the configuration system, the keyword \code{GAL_MODEL}
     761is set to the model of interest.  All suspected extended objects are
     762fitted with the model, allowing all of the parameters to float.  The
     763initial parameter guesses are critical here to achieving convergence
     764on the model fits in a reasonable time.  The moments and the pixel
     765flux distribution are used to make the initial parameter guess.  Many
     766of the object parameters can be accurately guessed from the first and
     767second moments.  The power-law slope can be guessed by measuring the
     768isophotal level at two elliptical radii and comparing the ratio to
     769that expected.
     770
     771For each of the galaxy models (in fact for all object models), a
     772function is defined which examines the fit results and determines if
     773the fit can be consider as a success or a failure.  The exact criteria
     774for this decision will depend on the details of the model, and so this
     775level of abstraction is needed.  For example, in some case, the range
     776of valid values for each of the parameters must be considered in the
     777fit assessment.  In other cases, we may choose to use only the
     778parameter errors and the fit Chi-Square value.
     779
     780All galaxy model fits which are successful are then subtracted from
     781the image as is done for the successful PSF model fits.  Of course,
     782the background flux is retained, with the result that only the object
     783is subtracted from the image.  Again, the noise image is (currently)
     784not modified. 
     785
     786\note{we have no code yet to select the best of several models for a
     787  given objects.  The relative value of the Chi-Square is the obvious
     788  test in this case}.
     789
     790\subsection{Faint Sources}
     791
     792\note{this is not done : should use the ensemble PSF fitting to fit
     793  just the new significant peaks}
     794
     795After a first pass through the image, in which the brighter sources
     796above a high threshold level have been detected, measured, and
     797subtracted, PSPhot optionally begins a second pass at the image.  In
     798this stage, the new peaks are detected on the image with the bright
     799objects subtracted.  In this pass, the peak detection process uses the
     800noise image to test the validity of the individual peaks.  All peaks
     801with a significance greater than a user-defined minimum threshold are
     802accepted as objects of potential interest. 
     803
     804The objects which are measured in this faint-object stage are clearly
     805low significance detections.  A typical threshold for the bright
     806object analysis would S/N of 5 - 10.  The lower limit cutoff for the
     807faint object analysis would typically be S/N of 2 - 4.  In this stage,
     808PSPhot can perform one of three types of analysis.  The difference
     809between these options is one of speed vs detail.
     810
     811In the first option, PSPhot can repeat the analysis described above in
     812sections XXX and XXX, performing a PSF fit followed by a non-PSF fit
     813to the objects which are not PSF-like, and subtracting them.  The
     814advantage of this option is that the faint objects are treated
     815identically to the bright objects, and all potential parameters are
     816measured, even for marginally extended sources.  The disadvantage of
     817this option is that the low signal-to-noise of the objects in this
     818stage limits the amount of information which can be extracted from
     819them.  The marginal gain may not be worth the large expense of
     820processing time.
     821
     822In the second option, PSPhot can perform only the PSF model fit to the
     823remaining peaks, but ignore any further questions of the shape of the
     824objects.  The advantage of this option is that it is substantially
     825faster than performing the more complex (and less stable)
     826multi-parameter non-linear fits on all faint objects.  On the
     827downside, less information is learned about the objects.
     828
     829Finally, PSPhot can simply ignore the fitting process and instead
     830glean information about the fainter sources on the basis of the peak
     831characteristics.  In this option, the image is smoothed with the PSF
     832model, and the peak for each object is measured.  The peak flux and
     833the local peak curvature theoretically give sufficient information to
     834recover the object flux, the centroid coordinates, and the centroid
     835errors.  The advantage of the stage is speed, especially for the very
     836faintest levels: if the lower limit is not sufficiently faint, the
     837time spent in performing the smoothing (3 FFTs) cannot make up for the
     838time which would have been spent applying the PSF model to the peaks.
     839The downside of this method is an increased sensitivity to the local
     840sky model (the local sky must be correctly subtracted) and fewer
     841constraints on the quality of the detection (no Chi-Square is
     842measured, for example).
     843
     844\note{In the ideal case, if we were only interested in detecting PSFs,
     845and we had a good model for the PSF, we could optimally find the
     846sources by smoothing the image and the noise image with the PSF model.
     847\em write out the description of Nick's optimal PSF finding}.
     848
     849PSPhot allows the user to select between these three options for the
     850analysis of the faint sources.  Three separate user-controlled
     851signal-to-noise ratio limits are defined.  One specifies the depth to
     852which the PSF / non-PSF analysis is performed.  A second (which must
     853be smaller) specifies the depth to which only the PSF is fitted.  A
     854third specifies the depth to which the analysis is performed using on
     855the peak statistics.  If two of these are identical, then certain of
     856these options are simply skipped.  For example, if the peak analysis
     857threshold is set to the same value as the PSF-only threshold, no peak
     858analysis is performed.
     859
     860\subsection{Aperture Correction Measurement}
    493861
    494862The important concept here is that an analytical model will always
     
    581949tested.
    582950
    583 \subsubsection{PSF Model applied to detected objects}
    584 
    585 Once a PSF model has been selected for an image, PSPhot attempts to
    586 fit all of the detected objects, above a user-defined signal-to-noise
    587 ratio (\note{KEYWORD}) with the PSF model.  For these fits, the
    588 dependent parameters are fixed by the PSF model and only the 4
    589 independent object model parameters are allowed to vary in the fit.
    590 PSPhot again uses the Levenberg-Marqardt process for the non-linear
    591 fitting.  The objects are fitted in their S/N order, starting with the
    592 brightest and working down to the user-specified limit.
    593 
    594 Once a solution has been achieved, PSPhot attempts to judge the
    595 quality of the PSF model as a representation of the object shape.  To
    596 do this, it calculates the next step of the minimization {\em allowing
    597 the shape parameters to vary}.  This step, essentially the
    598 Gauss-Newton minimization distance from the current local minimum,
    599 should be very small if the object is well represented by the PSF, but
    600 large if the PSF is not a good representation of the object flux.  The
    601 model quality is judged by the change in the two shape parameters
    602 which represent the 2D size of the object.  For the case of the
    603 elliptical Gaussian, these two parameters are $\sigma_x$ and
    604 $\sigma_y$.  For a generic model, the shape parameters may be defined
    605 differently, but the should always be two parameters which scale the
    606 object size in two dimensions (what about a polar-coordinate form?)
    607 Currently, PSPhot requires the two relevant shape parameters to be the
    608 first two dependent parameters in the list of model parameters (ie,
    609 parameters 4 \& 5).
    610 
    611 The expected distribution of the variation of the two shape parameters
    612 will be a function of the signal-to-noise of the object in question
    613 and the value of the shape parameter itself.  The expected standard
    614 deviation on the shape parameter is, eg, $\sigma_x / {\rm SN}$.  If
    615 the object is well-represented by the PSF, then the shape parameter
    616 values should be close to their minimization value.  We can thus ask,
    617 for each object, given the measured amplitude of the Gauss-Newton
    618 step, how many standard deviations from the expected value (of 0.0) is
    619 this particular value?  Objects for which the variation in the shape
    620 parameters is a large positive number of standard deviations are
    621 likely to be better represented by a larger flux distribution than the
    622 PSF (eg, a Galaxy or Comet, etc).  Objects for which the variation in
    623 the shape parameters is a large negative number of standard deviations
    624 are likely to be better represented by a smaller flux distribution
    625 than the PSF (ie, a cosmic ray or other defect).  A user-defined
    626 number of standard deviations is used to select these two cases, and
    627 to flag the object as a likely galaxy (really meaning 'extended') or
    628 as a likely defect. 
    629 
    630 At this stage of the analysis, PSPhot uses two additional indicators
    631 to identify good and poor PSF fits.  The first of these is the
    632 signal-to-noise ratio.  It is possible for the peak finding algorithm
    633 to identify peaks in locations which are not actually a normal peak.
    634 Some of these cases are in the edges of saturated, bleeding columns
    635 from bright stars, in the nearly flat halos of very bright stars, and
    636 so on.  In these cases, a local peak exists, with a lower nearby sky
    637 region.  However, the fitted PSF model cannot converge on the peak
    638 because it is very poorly defined (perhaps only existing in the
    639 smoothed image).  The fit can either fail to converge or it can
    640 converge on a fit with very low or negative peak flux / flux
    641 normalization.  PSPhot will flag any non-convergent PSF fit and any
    642 object with PSF S/N ratio lower than a user-defined cutoff.  It is
    643 also useful to identify very poor fits by setting a maximum Chi-Square
    644 cutoff for objects. 
    645 
    646 As the objects are fitted to the PSF model, those which survive the
    647 exclusion stage are subtracted from the image.  The subtraction
    648 process modifies the image pixels (removing the fitted flux, though
    649 not the locally fitted background) but does not modify the mask or the
    650 noise images.  The signal-to-noise ratio in the image after
    651 subtraction represents the significance of the remaining flux.  If the
    652 subtractions are sufficiently accurate models of the PSF flux
    653 distribution, the remaining flux should be below 1 $\sigma$
    654 significance.  In practice the cores of bright stars are poorly
    655 represented and may have larger residual significance. \note{in future
    656 work, we may choose to enhance the noise to minimize detection of
    657 objects in the residuals of brighter objects}.
    658 
    659951\subsubsection{Types of Object / PSF models currently available}
    660952
     
    662954
    663955\begin{itemize}
    664 \item Pure elliptical Gaussian (GAUSS)
    665 \item polynomial approximation to a Gaussian (PGAUSS)
    666 \item RGAUSS
    667 \item QGAUSS - power law with variable exponential term
     956\item GAUSS  : Pure elliptical Gaussian
     957\item PGAUSS : polynomial approximation to a Gaussian (PGAUSS)
     958\item QGAUSS : power law with variable exponential term
     959\item SGAUSS :
    668960\end{itemize}
    669961
    670 \subsection{Non-PSF Objects}
    671 
    672 Once every object (above the S/N cutoff) has been confronted with the
    673 PSF model, the objects which are thought to be galaxies (extended) can
    674 now be fit with appropriate models for the galaxies (or other likely
    675 extended shapes).  Again, the fitting stage starts with the brightest
    676 sources (as judged by the rough S/N measured from the moments
    677 aperture) and working to a user defined S/N limit. 
    678 
    679 PSPhot will use the user-selected galaxy model to attempt the galaxy
    680 model fits.  In the configuration system, the keyword \code{GAL_MODEL}
    681 is set to the model of interest.  All suspected extended objects are
    682 fitted with the model, allowing all of the parameters to float.  The
    683 initial parameter guesses are critical here to achieving convergence
    684 on the model fits in a reasonable time.  The moments and the pixel
    685 flux distribution are used to make the initial parameter guess.  Many
    686 of the object parameters can be accurately guessed from the first and
    687 second moments.  The power-law slope can be guessed by measuring the
    688 isophotal level at two elliptical radii and comparing the ratio to
    689 that expected.
    690 
    691 For each of the galaxy models (in fact for all object models), a
    692 function is defined which examines the fit results and determines if
    693 the fit can be consider as a success or a failure.  The exact criteria
    694 for this decision will depend on the details of the model, and so this
    695 level of abstraction is needed.  For example, in some case, the range
    696 of valid values for each of the parameters must be considered in the
    697 fit assessment.  In other cases, we may choose to use only the
    698 parameter errors and the fit Chi-Square value.
    699 
    700 All galaxy model fits which are successful are then subtracted from
    701 the image as is done for the successful PSF model fits.  Of course,
    702 the background flux is retained, with the result that only the object
    703 is subtracted from the image.  Again, the noise image is (currently)
    704 not modified. 
    705 
    706 \note{we have no code yet to select the best of several models for a
    707   given objects.  The relative value of the Chi-Square is the obvious
    708   test in this case}.
    709 
    710 \subsection{Faint Sources}
    711 
    712 \note{the following discussion is theoretical : it is not yet coded}
    713 
    714 After a first pass through the image, in which the brighter sources
    715 above a high threshold level have been detected, measured, and
    716 subtracted, PSPhot optionally begins a second pass at the image.  In
    717 this stage, the new peaks are detected on the image with the bright
    718 objects subtracted.  In this pass, the peak detection process uses the
    719 noise image to test the validity of the individual peaks.  All peaks
    720 with a significance greater than a user-defined minimum threshold are
    721 accepted as objects of potential interest. 
    722 
    723 The objects which are measured in this faint-object stage are clearly
    724 low significance detections.  A typical threshold for the bright
    725 object analysis would S/N of 5 - 10.  The lower limit cutoff for the
    726 faint object analysis would typically be S/N of 2 - 4.  In this stage,
    727 PSPhot can perform one of three types of analysis.  The difference
    728 between these options is one of speed vs detail.
    729 
    730 In the first option, PSPhot can repeat the analysis described above in
    731 sections XXX and XXX, performing a PSF fit followed by a non-PSF fit
    732 to the objects which are not PSF-like, and subtracting them.  The
    733 advantage of this option is that the faint objects are treated
    734 identically to the bright objects, and all potential parameters are
    735 measured, even for marginally extended sources.  The disadvantage of
    736 this option is that the low signal-to-noise of the objects in this
    737 stage limits the amount of information which can be extracted from
    738 them.  The marginal gain may not be worth the large expense of
    739 processing time.
    740 
    741 In the second option, PSPhot can perform only the PSF model fit to the
    742 remaining peaks, but ignore any further questions of the shape of the
    743 objects.  The advantage of this option is that it is substantially
    744 faster than performing the more complex (and less stable)
    745 multi-parameter non-linear fits on all faint objects.  On the
    746 downside, less information is learned about the objects.
    747 
    748 Finally, PSPhot can simply ignore the fitting process and instead
    749 glean information about the fainter sources on the basis of the peak
    750 characteristics.  In this option, the image is smoothed with the PSF
    751 model, and the peak for each object is measured.  The peak flux and
    752 the local peak curvature theoretically give sufficient information to
    753 recover the object flux, the centroid coordinates, and the centroid
    754 errors.  The advantage of the stage is speed, especially for the very
    755 faintest levels: if the lower limit is not sufficiently faint, the
    756 time spent in performing the smoothing (3 FFTs) cannot make up for the
    757 time which would have been spent applying the PSF model to the peaks.
    758 The downside of this method is an increased sensitivity to the local
    759 sky model (the local sky must be correctly subtracted) and fewer
    760 constraints on the quality of the detection (no Chi-Square is
    761 measured, for example).
    762 
    763 \note{In the ideal case, if we were only interested in detecting PSFs,
    764 and we had a good model for the PSF, we could optimally find the
    765 sources by smoothing the image and the noise image with the PSF model.
    766 \em write out the description of Nick's optimal PSF finding}.
    767 
    768 PSPhot allows the user to select between these three options for the
    769 analysis of the faint sources.  Three separate user-controlled
    770 signal-to-noise ratio limits are defined.  One specifies the depth to
    771 which the PSF / non-PSF analysis is performed.  A second (which must
    772 be smaller) specifies the depth to which only the PSF is fitted.  A
    773 third specifies the depth to which the analysis is performed using on
    774 the peak statistics.  If two of these are identical, then certain of
    775 these options are simply skipped.  For example, if the peak analysis
    776 threshold is set to the same value as the PSF-only threshold, no peak
    777 analysis is performed.
     962\note{discuss the stability issues with the galaxy model(s)}
     963
     964\subsection{Output Options}
     965
     966\note{need to discuss tests}
     967
     968\note{need to discuss failings and holes}
     969
     970\section{Alternative Scenarios}
     971
     972\subsection{Trailed Sources}
     973
     974\subsection{Fixed / Known-position Sources}
    778975
    779976\subsection{Difference Images}
     
    8331030discussed in the section on Galaxy models.
    8341031
    835 \note{need to discuss tests}
    836 
    837 \note{need to discuss failings and holes}
     1032\section{PSPhot Structures and Data Elements}
     1033
     1034The following structures are described in detail in the document
     1035`Pan-STARRS PS-1 Image Processing Pipeline Modules Supplementary
     1036Design Requirements' (psModules SDRS; PSDC-430-012).
     1037
     1038\begin{datatype}
     1039 pmModel
     1040 pmModelGroup
     1041 pmGrowthCurve
     1042 pmPSF
     1043 pmPSFTry
     1044 pmSource
     1045 pmPeak
     1046 pmMoments
     1047\end{datatype}
     1048
     1049\note{psphot is supposed to operate on individual readouts, and use
     1050  the techniques used by ppImage to extract header-related metadata.
     1051  currently, psphot uses an alternative to the psReadout until the
     1052  ppImage code can be folded together with psphot}.
     1053
     1054\subsection{Top-Level APIs}
     1055
     1056\begin{prototype}
     1057psMetadata     *psphotArguments (int *argc, char **argv);
     1058\end{prototype}
     1059Load the command-line arguments, parse the configuration file, and
     1060place the configuration information on a single metadata structure.
     1061This function searches for the following command line option flags,
     1062and places their corresponding values on the output metadata with the
     1063given name.  These options override any such values in the
     1064configuration file.
     1065\begin{verbatim}
     1066-mask (filename)      : MASK_IMAGE
     1067-weight (filename)    : WEIGHT_IMAGE
     1068-resid (filename)     : RESID_IMAGE
     1069-region [x0:x1,y0:y1] : ANALYSIS_REGIONP
     1070-photcode (code)      : PHOTCODE
     1071-psf (filename)       : PSF_INPUT_FILE
     1072-modeltest x y        : TEST_FIT_X, TEST_FIT_Y
     1073-model (name)         : TEST_FIT_MODEL
     1074-fitmode (name)       : TEST_FIT_MODE
     1075-fitset (name)        : TEST_FIT_SET
     1076\end{verbatim}
     1077
     1078The following option flags can be used to set any option:
     1079\begin{verbatim}
     1080-D  (key) (value)      : any string value
     1081-Df (key) (value)      : any F32 value
     1082-Di (key) (value)      : any S32 value
     1083\end{verbatim}
     1084
     1085The function next examines the remaining command-line arguments and
     1086complains if there are not exactly 3 arguments, reporting the program
     1087usage.  It sets default configuration variables, and then loads the
     1088configuration file specified as the third command-line option.
     1089Finally, it sets the \code{IMAGE} and \code{OUTPUT_FILE} config
     1090options to arguments 1 and 2, respecitively.
     1091
     1092\begin{prototype}
     1093eamReadout     *psphotSetup (psMetadata *config);
     1094\end{prototype}
     1095This function examines the configuration data in \code{config} and
     1096loads the image into memory.  It constructs the weight and mask images
     1097if they have not been specified, or loads the specified images.  The
     1098weight image is built based on the read noise and gain of the image,
     1099as extracted from the header or from the configuration options
     1100directly.  It defines the mask based on the selection image region,
     1101the values for saturation and the \code{min_VALID_PIXEL}. 
     1102
     1103\begin{prototype}
     1104bool            psphotModelTest (eamReadout *imdata, psMetadata *config);
     1105\end{prototype}
     1106This function is an optional test mode for psphot.  If the test mode
     1107has been selected, this function will attempt to fit a single object
     1108with the requested model.  It writes out subimage containing the
     1109source, the difference, the mask, and the weight.  This function may
     1110load a PSF model or fit a floating model.
     1111
     1112\begin{prototype}
     1113psStats        *psphotImageStats (eamReadout *imdata, psMetadata *config);
     1114\end{prototype}
     1115Measure the basic image properties: median sky, expected sky sigma
     1116
     1117\begin{prototype}
     1118psPolynomial2D *psphotImageBackground (eamReadout *imdata, psMetadata *config, psStats *sky);
     1119\end{prototype}
     1120Model the image background as a 2D polynomial and subtract from the
     1121image.   The should use a more sophisticated model and return the
     1122subtracted image.
     1123
     1124\begin{prototype}
     1125psArray        *psphotFindPeaks (eamReadout *imdata, psMetadata *config, psStats *sky);
     1126\end{prototype}
     1127Create a smoothed image and find all local peaks above the threshold
     1128level (uses: \code{PEAKS_SMOOTH_SIGMA, PEAKS_SMOOTH_NSIGMA,
     1129PEAKS_NSIGMA_LIMIT, PEAKS_OUTPUT_FILE})
     1130
     1131\begin{prototype}
     1132psArray        *psphotSourceStats (eamReadout *imdata, psMetadata *config, psArray *allpeaks);
     1133\end{prototype}
     1134Create the basic source structures for all peaks, define the initial
     1135pixels, measure the local sky (sky offset) and the source moments.
     1136
     1137\begin{prototype}
     1138bool            psphotRoughClass (psArray *sources, psMetadata *config);
     1139\end{prototype}
     1140Find the PSF clump and make the first cut source identifications
     1141
     1142\begin{prototype}
     1143bool            psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky);
     1144\end{prototype}
     1145Find all blended peaks and tag, group with single primary source.
     1146
     1147\begin{prototype}
     1148pmPSF          *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *sky);
     1149\end{prototype}
     1150Try each of the selected PSF models on a subset of likely PSF stars.
     1151Measure the metric (aperture residual scatter) for each PSF model and
     1152choose the best model. 
     1153
     1154\begin{prototype}
     1155bool            psphotEnsemblePSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);
     1156\end{prototype}
     1157Perform simultaneous fitting to all sources in the array using a
     1158linear fitting process which assumes all sources are PSFs and their
     1159positions are fixed.  Set the positions based on the bilinear
     1160interpolation of the peak implied by the 3x3 square of pixels
     1161containing the peak.  Local sky is also assumed to be correctly subtracted.
     1162
     1163\begin{prototype}
     1164bool            psphotFullFit (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);
     1165\end{prototype}
     1166Fit all sources in sequence starting from the brightest, and
     1167subtracting the sources as they are fitted.  This function only
     1168attempts single PSF and single EXT models and chooses between them.
     1169The sources are assumed to have been subtracted in advance (ie, using
     1170psphotEnsembleFit).  The models which do not succeed are re-subtracted
     1171using the prior model.
     1172
     1173\begin{prototype}
     1174bool            psphotBlendFit (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);
     1175\end{prototype}
     1176Fit all sources in sequence starting from the brightest, and
     1177subtracting the sources as they are fitted.  This function attempts a
     1178multi-source fit for blended sources, or a single PSF if it is not a
     1179blend, followed by both EXT and DBL models and chooses between them.
     1180The sources are assumed to have been subtracted in advance (ie, using
     1181psphotEnsembleFit).  The models which do not succeed are re-subtracted
     1182using the prior model.
     1183
     1184\begin{prototype}
     1185bool            psphotReplaceUnfit (psArray *sources);
     1186\end{prototype}
     1187After models have been attempted for all sources, this function
     1188replaces the sources which were temporarily subtracted, but which did
     1189not succeed or converge on a good solution.
     1190
     1191\begin{prototype}
     1192bool            psphotApplyPSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);
     1193\end{prototype}
     1194Attempt to fit the PSF model to all sources in brightness order,
     1195subtracting the resulting model if successful.  Only attempts single
     1196PSF models.   
     1197
     1198\begin{prototype}
     1199bool            psphotFitExtended (eamReadout *imdata, psMetadata *config, psArray *sources, psStats *skyStats);
     1200\end{prototype}
     1201Attempt to fit the PSF model to all sources in brightness order,
     1202subtracting the resulting model if successful.  Only attempts single
     1203EXT models.
     1204
     1205\begin{prototype}
     1206bool            psphotApResid (eamReadout *imdata, psArray *sources, psMetadata *config, pmPSF *psf);
     1207 \end{prototype}
     1208Measure the curve-of-growth and the aperture correction trend.
     1209
     1210\begin{prototype}
     1211void            psphotOutput (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);
     1212\end{prototype}
     1213Write out data in various formats as selected.
    8381214
    8391215\section{User's Guide}
     
    8791255\section{Sample Tests}
    8801256
     1257\section{Further Work to be Completed}
     1258
     1259\begin{itemize}
     1260\item convert to pmCell as input data
     1261\item loop over all readouts in a pmCell
     1262\item write out multiple files?
     1263\item better method for defining the recipe?
     1264\item additional options for image background
     1265\item image background should return a background image
     1266
    8811267\end{document}
Note: See TracChangeset for help on using the changeset viewer.