IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 13, 2005, 11:05:23 AM (21 years ago)
Author:
eugene
Message:

updates for cycle 8 release

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/modules/ModulesSDRS.tex

    r5023 r5030  
    1 %%% $Id: ModulesSDRS.tex,v 1.57 2005-09-13 03:36:09 price Exp $
    2 \documentclass[panstarrs]{panstarrs}
     1%%% $Id: ModulesSDRS.tex,v 1.58 2005-09-13 21:05:23 eugene Exp $
     2\documentclass[panstarrs,spec]{panstarrs}
    33
    44% basic document variables
     
    1111\project{Pan-STARRS Image Processing Pipeline}
    1212\organization{Institute for Astronomy}
    13 \version{07}
     13\version{08}
    1414\docnumber{PSDC-430-012}
    1515
    16 \setlength{\topsep}{-2pt}
    17  
    1816\begin{document}
    1917\maketitle
     
    353306 & 2005 Apr 27 & final for cycle 6 \\ \hline
    363407 & 2005 Jul 15 & final for cycle 7 \\ \hline
     3508 & 2005 Sep 13 & final for cycle 8 \\ \hline
    3736\RevisionsEnd
    3837
     
    7473
    7574PSLib defines a \code{psMetadata} structure which can carry labeled
    76 data of arbirtary types.  The associated functions implemented by
     75data of arbitrary types.  The associated functions implemented by
    7776PSLib consist of tools to manipulate and extract data from
    78 \code{psMetadata} collections.  Within PSLib, the \code{psMetadata}
    79 stucture is used to carry the data from a FITS header.  In addition,
    80 functions are available to fill a \code{psMetadata} collection from a
    81 text-based configuration file using a particular syntax, and to fill a
    82 \code{psMetadata} collection from a properly formatted XML document.
     77\code{psMetadata} collections.  A particular application of the
     78\code{psMetadata} structure within PSLib is to carry the data from a
     79FITS header.  Other general-purpose information is also carried with
     80the structure.  Functions are available to fill a \code{psMetadata}
     81collection from a text-based configuration file using a human-readable
     82syntax, and to fill a \code{psMetadata} collection from a properly
     83formatted XML document.
    8384
    8485In the IPP Modules, we use \code{psMetadata} collections to carry
     
    108109configuration being the most general, and the recipe configuration the
    109110most specific.  For example, not all sites will have to deal with all
    110 cameras, and different cameras will have different recipes according
    111 to their particular quirks.
     111cameras, and different cameras may require different recipes at
     112different times according to their particular quirks, analysis
     113experimentations, or their evolution.
    112114
    113115Each of the levels will have a metadata configuration file.  In the
     
    116118environment variable \code{PS_SITE}, if defined, or \code{~/.ipprc}
    117119otherwise.  The camera configuration shall be specified by the
    118 \code{camera} option on the command line if provided, or shall be
     120\code{-camera} option on the command line if provided, or shall be
    119121inferred from a FITS header (more detail below).  The recipe
    120122configuration shall be specified by the \code{-recipe} option on the
     
    138140  \end{itemize}
    139141\item \code{CAMERAS} of type \code{METADATA}: A list of instruments
    140   that the system can handle.  Cameras are specified as separate
     142  that the system understands.  Cameras are specified as separate
    141143  metadata entries, with the name of the camera as the key, and the
    142144  filename of the camera configuration file (of type \code{STR}) as
     
    197199\subsubsection{Camera Configuration}
    198200
    199 The camera configuration is the most complicated and involved, since
     201The camera configuration is somewhat complicated and involved, since
    200202it must not only specify how to translate the pixels from a FITS file
    201203into a focal plane hierarchy (\S\ref{sec:focalplane}), but it must
     
    216218correspond to individual reads of the detector.
    217219
     220The FITS data storage formation is a standard in the astronomical
     221community for storing astronomical images.  A FITS file consists of an
     222arbitrary number of coupled human readable \code{ASCII} header
     223segments and binary data segments.  The headers describe the format
     224and layout of the data segments.  The first of these groups is
     225traditionally called the 'primary header unit' (PHU) and the rest are
     226referred to as 'extensions'.  The header segments may contain
     227extensive documentary information related to the interpretation of the
     228data.  Although the FITS format defines a standard representation of
     229the data, the header metadata is not so consistently defined within
     230the astronomical community.  Also, the flexibility of the data format
     231means that different representations are possible for the same
     232fundamental collection of data.  The tools presented in this section
     233provide a method to define and constrain the wide range of possible
     234FITS representations of astronomical images.
     235
    218236Within the FITS data representation, there are various choices which
    219237can and have been made for the placement of the pixels in the file.
     
    222240image data could be written as part of the primary data unit.  In a
    223241more complex case with multiple chips and multiple cells, the data may
    224 be organized in various ways.  The data may be distributed into
     242be organized in several ways.  The data may be distributed into
    225243multiple files or in multiple FITS data extensions.  A single camera
    226244image may be written as a collection of files for individual chips
     
    231249
    232250In all of these representations, there are only two basic distinctions
    233 in how the pixel data is stored: what level the entire FITS file
    234 corresponds to (FPA or chip), and what level the extensions correspond
    235 to (chip, cell or no extensions at all).  Knowing these, and having
    236 a list of the components, we can construct the focal plane hierarchy.
    237 
    238 We therefore specify the following keywords:
     251in how the pixel data is stored: what level in the hierarchy the
     252entire FITS file corresponds to (FPA, chip, or cell), and what level
     253the extensions correspond to (chip, cell or no extensions at all).
     254Knowing these, and having a list of the components, we can construct
     255the focal plane hierarchy.
     256
     257Note that a single data extension, consisting of a uniform grid of
     258pixels, can only naturally represent a cell or a chip.  In order to
     259represent the entire focal plane array as a single grid, some
     260artificial choices would be made to fill-in or ignore the gaps between
     261chips and their relative rotations.  Within our framework, a complete
     262focal plane mosaic of multiple chips could be represented as a single
     263extension by treating the collection of pixels as if they were from a
     264single chip. 
     265
     266To define the hierarchy, we specify the following keywords:
    239267\begin{itemize}
    240 \item \code{PHU} of type \code{STR}: May be one of \code{CHIP} or
    241   \code{CELL}.  This specifies what the scale of the Primary Header
    242   Unit (and hence the entire FITS file) is.
     268
     269\item \code{PHU} of type \code{STR}: May be one of \code{FPA},
     270  \code{CHIP}, or \code{CHIP}.  This specifies the focal plane level
     271  of the Primary Header Unit, and hence the entire FITS file (the
     272  'class' of the file) .
     273
    243274\item \code{EXTENSIONS} of type \code{STR}: May be one of \code{CHIP},
    244275  \code{CELL} or \code{NONE}, though not of a level higher than that
    245276  specified by the \code{PHU}.  This specifies what each extension
    246277  represents.
     278
    247279\item \code{CONTENTS} which may be of type \code{METADATA} or
    248280  \code{STR}, depending upon the \code{PHU} and \code{EXTENSIONS},
     
    431463Each image has associated with it what we will call {\it concepts}
    432464(for want of a better word).  These are values corresponding to
    433 general quantities and qualities relevant to the IPP such as airmass,
    434 date, read noise and filter.  The values of each of the below concepts
    435 shall be determined when the FPA is read into memory (via
    436 \code{pmFPARead}), and stored at the appropriate level in the focal
    437 plane hierarchy.
     465general quantities and qualities necessary to understand and interpret
     466the data such as airmass, date, read noise and filter.  The values of
     467each of the below concepts shall be determined when the FPA is read
     468into memory (via \code{pmFPARead}), and stored at the appropriate
     469level in the focal plane hierarchy.
    438470
    439471Below is a list of concepts that the IPP requires, with the
     
    466498\end{itemize}
    467499
    468 \tbd{Note that \code{CELL.EXPOSURE}, \code{CELL.DARKTIME} and
    469 \code{CELL.TIME} should actually be specified at the readout level.
    470 However, at this present time, we're not sure how these should be
    471 specified, and so we move them up to the cell level and assume that
    472 all readouts are of the same exposure and dark time.}
     500\tbd{Note that CELL.EXPOSURE, CELL.DARKTIME and CELL.TIME should
     501actually be specified at the readout level.  However, at this present
     502time, we're not sure how these should be specified, and so we move
     503them up to the cell level and assume that all readouts are of the same
     504exposure and dark time.}
    473505
    474506For different camera systems, these concepts are not always known by
     
    498530\code{METADATA}, with the component keywords being the value of the
    499531second concept (on which the first depends).  To avoid infinite
    500 recursion, no further dependency is permitted.  An example of the
     532recursion, no further dependency is permitted.  We also allow an entry
     533\code{CONCEPT.DEFAULT} specifiying the default value of the concept if
     534a match is not made with the dependcency list.  An example of the
    501535dependency:
    502536
     
    505539DEFAULTS        METADATA
    506540        CELL.GAIN.DEPEND     STR     CHIP.NAME
     541        CELL.GAIN.DEFAULT    STR     1.0
    507542        CELL.GAIN    METADATA
    508543                ccd00   F32     1.2
     
    552587
    553588Note that the FITS standard is that the time in the header refers to
    554 the {\it start} of the observation.  \tbd{In the future, we might add
    555 additional qualifiers that calculate the start time of the observation
    556 based on someone foolishly putting the end- or mid-time in the header.}
    557 
    558 \tbd{Should we move \code{CELL.TIMESYS} into the format as well?}
     589the {\it start} of the observation. 
     590
     591\tbd{the PRE2000 and BACKWARDS qualifiers should be replace with
     592explicit format definitions in the form YYYY/MM/DD}
     593
     594\tbd{In the future, we might add additional qualifiers that calculate
     595the start time of the observation based on someone foolishly putting
     596the end- or mid-time in the header.}
     597
     598\tbd{Should we move CELL.TIMESYS into the format as well?}
    559599
    560600\paragraph{FPA.RA and FPA.DEC}
     
    607647commas or semi-colons) that contains the appropriate values.
    608648\end{itemize}
     649
     650\tbd{the use of implicit interpretation of formats should be
     651  discouraged: format interpretation guides should be provided}
    609652
    610653\subsection{Configuration APIs}
     
    641684  trace levels specified by the \code{TRACE}.
    642685\end{itemize}
     686Note that additional log/trace command-line options may be specified
     687and interpretted using the \code{psArgumentVerbosity} function from
     688psLib.  These options should (in the case of logging) override the
     689configuration-supplied information or (in the case of tracing)
     690supplement it.
    643691
    644692\code{pmConfigCameraFromHeader} shall load the \code{camera}
     
    784832M_{\rm pM} - pA, M_{\rm sP} - M_{\rm sM} - sA)$.
    785833
    786 \section{Phase 2}
    787 
    788 Phase 2 is the processing stage wherein the instrumental signatures
    789 are removed from the detector images, in preparation for the
    790 combination of multiple images in Phase 4.
    791 
    792 The Phase 2 processing modules are:
     834\section{Image Detrending}
     835
     836Image Detrending is the image analysis process wherein the
     837instrumental signatures are removed from the individual images.  This
     838section discusses the modules used for image detrending.  The basic
     839image detrending steps are:
    793840\begin{itemize}
    794841\item Subtract bias;
     
    797844\item Mask bad pixels;
    798845\item Subtract the background;
    799 \item \tbd{Mask cosmic rays;}
    800 \item \tbd{Mask optical defects;}
    801 \item \tbd{Measure the PSF;}
    802 \item \tbd{Find and measure objects;}
    803 \item \tbd{Correct astrometry; and}
    804 \item \tbd{Get postage stamps.}
     846\item Mask cosmic rays;
     847\item Mask optical defects;
    805848\end{itemize}
    806 
    807 Each of these shall be discussed in turn, below.  Those modules which
    808 are \tbd{} will be deferred until they may be properly defined,
    809 some of which requires further research to define the best algorithm.
    810849
    811850\subsection{Bias subtraction}
     
    9951034\label{sec:maskValues}
    9961035
    997 We define several mask values for use in the phase 2 processing:
     1036We define several mask values for use in the detrend processing:
    9981037\begin{datatype}
    9991038/** Mask values */
     
    10331072the \code{growVal}).
    10341073
    1035 \tbd{In the future, may change \code{grow} to a convolution kernel}.
     1074\tbd{In the future, may change {\tt grow} to a convolution kernel}.
    10361075
    10371076Note that the input image, \code{in}, and the \code{mask} need not be
     
    11041143
    11051144The elements of the focal plane hierarchy each contain an
    1106 \code{analysis} member, intended to log the results of the Phase 2
    1107 tasks.  The Phase 2 tasks shall add to the \code{analysis} members as
     1145\code{analysis} member, intended to log the results of the detrend
     1146tasks.  The detrend tasks shall add to the \code{analysis} members as
    11081147follows:
    11091148
     
    12941333of the same type.
    12951334
    1296 \section{Object Detection, Measurement, and Classification Routines}
     1335\section{Objects on Images}
    12971336
    12981337\subsection{Overview}
     
    13041343The elements defined in this section are generally low-level
    13051344components which can be connected together to construct a complete
    1306 object measurement suite.  An example pseudo-C program using these
    1307 functions is provided in Appendix~\ref{psphot}.
     1345object measurement suite. 
    13081346
    13091347We first define the collection of structures needed to carry
     
    13291367referenced without attempting to supply an analytical model.  Finally,
    13301368it is often useful to allow a single complex model to be represented
    1331 as a collection of simpler contained structures which may be modelled.
     1369as a collection of simpler contained structures which may be modeled.
    13321370Thus, the representation of an object must be capable of identifying
    13331371children, or substructures, of that object.
     
    13941432edge.  The \code{PM_PEAK_FLAT} represents a peak pixel which has more
    13951433than a specific number of neighbors at the same value, within some
    1396 tolarence:
     1434tolerance:
    13971435\begin{datatype}
    13981436typedef enum {
     
    14771515\subsubsection{pmModel Source Model and Abstraction}
    14781516
    1479 An object's flux distribution may be modelled with some analytical
     1517An object's flux distribution may be modeled with some analytical
    14801518function.  The description of the model includes the model parameters
    14811519and their errors, along with the fit $\chi^2$.  The model type is
     
    15661604
    15671605\code{pmModelFunc} is the function used to determine the value of the
    1568 mdoel at a specific coordinate, and is the one used by
     1606model at a specific coordinate, and is the one used by
    15691607\code{psMinimizeLMChi2}. 
    15701608
     
    16811719set by the model fitting and psf fitting steps.  For each model, the
    16821720value of the quality metric is stored in the vector \code{metric} and
    1683 the fitted instrumental magntiude is stored in \code{fitMag}.  The
     1721the fitted instrumental magnitude is stored in \code{fitMag}.  The
    16841722quality metric for the PSF model is the aperture magnitude minus the
    16851723fitted magnitude for each source.  This collection of aperture
    16861724residuals is examined in the analysis process, and a linear trend of
    1687 the residual with the inverse object flux (ie, $10^{0.4*mag)$) is
     1725the residual with the inverse object flux (ie, $10^{0.4*mag}$) is
    16881726fitted.  The result of this fit is a measured sky bias (systematic
    16891727error in the sky measured by the fits), an effective
     
    17091747
    17101748The following datatype defines the masks used by the \code{pmPSFtry}
    1711 anslysis to identify sources which should or should not be included in
     1749analysis to identify sources which should or should not be included in
    17121750the analysis.
    17131751\begin{datatype}
     
    17361774\end{prototype}
    17371775
    1738 \subsection{Object Model Abstraction}
    1739 
    1740 \tbd{this section is duplicating the section above}
    1741 
    1742 The object model functions are defined to allow for the flexible
    1743 addition of new object models.  Every object model, with parameters
    1744 represented by \code{pmModel}, has an associated set of functions
    1745 which provide necessary support operations.  A set of abstract
    1746 functions allow the programmer to select the approriate function or
    1747 property for a specific named object model.
    1748 
    1749 The following function concepts are provided by each model.
    1750 
    1751 \begin{prototype}
    1752 typedef psMinimizeLMChi2Func psModelFunc;
    1753 \end{prototype}
    1754 This function is the model chi-square minimization function for this
    1755 model.
    1756 
    1757 \begin{prototype}
    1758 typedef psF64 (*psModelFlux)(const psVector *params);
    1759 \end{prototype}
    1760 This function returns the integrated flux for the given model
    1761 parameters.
    1762 
    1763 \begin{prototype}
    1764 typedef bool (*psModelGuessFunc)(psModel *model, psSource *source);
    1765 \end{prototype}
    1766 This function provides the model guess parameters based on the details
    1767 of the given source.
    1768 
    1769 \begin{prototype}
    1770 typedef bool (*psModelFromPSFFunc)(psModel *modelPSF, psModel *modelFLT, pmPSF *psf);
    1771 \end{prototype}
    1772 This function constructs the PSF model for the given source based on
    1773 the supplied \code{psf} and the FLT model for the object. 
    1774 
    1775 \begin{prototype}
    1776 typedef psF64 (*psModelRadius)(const psVector *params, double flux);
    1777 \end{prototype}
    1778 This function returns the radius at which the given model and
    1779 parameters achieves the given flux.
    1780 
    1781 Each of the function types above has a corresponding function which
    1782 returns the function given the model type:
    1783 \begin{prototype}
    1784 psModelFunc psModelFunc_GetFunction (psModelType type);
    1785 psModelFlux psModelFlux_GetFunction (psModelType type);
    1786 psModelGuessFunc psModelGuessFunc_GetFunction (psModelType type);
    1787 psModelFromPSFFunc psModelFromPSFFunc_GetFunction (psModelType type);
    1788 psModelRadius psModelRadius_GetFunction (psModelType type);
    1789 \end{prototype}
    1790 
    1791 In addition, the following utility functions return information about
    1792 the specified model:
    1793 
    1794 \begin{prototype}
    1795 psS32 psModelParameterCount (psModelType type);
    1796 psS32 psModelSetType (char *name);
    1797 char *psModelGetType (psModelType type);
    1798 \end{prototype}
    1799 \code{psModelParameterCount} returns the number of parameters for the
    1800 given model.  The remaining functions lookup the name or identifying
    1801 code for the model from the other concept.  Model names are character
    1802 strings in all caps of the form \code{GAUSS}.  Names are invarient
    1803 between multiple compliations of the library, but the model numbers
    1804 are not and should only be used within programs.
    1805 
    18061776\subsection{Basic Object Detection APIs}
    18071777
     
    18191789cases must be addressed.  Equal value elements: If an element has the
    18201790same value as the following element, it is not considered a peak.  If
    1821 an element has the same value as the preceeding element (but not the
     1791an element has the same value as the preceding element (but not the
    18221792following), then it is considered a peak.  Note that this rule
    18231793(arbitrarily) identifies flat regions by their trailing edge.  Edge
     
    18581828
    18591829\begin{prototype}
    1860 pmSource *pmSourceLocalSky(const psImage *image, const pmPeak *peak, psStatsOptions statsOptions, float innerRadius, float outerRadius);
    1861 \end{prototype}
    1862 
    1863 Measure the local sky in the vicinity of the given \code{peak}.  The
    1864 image pixels in the square annulus with inner and outer half-width
    1865 ('square-radii') as specified are used to measure the local background
    1866 in the vicinity of the the specified peak coordinates.  The local
    1867 background measurement uses the specified statistic passed in via the
    1868 \code{stats} entry.  This function allocates a \code{pmSource}
    1869 structure and uses the resulting sky to set the value of the
    1870 \code{pmMoments.sky} element of that \code{pmSource} structure.  The
    1871 input \code{peak} is also placed on the \code{pmSource} structure,
    1872 which is then returned.
     1830bool pmSourceDefinePixels(pmSource *mySource,
     1831                          pmReadout *readout,
     1832                          psF32 x,
     1833                          psF32 y,
     1834                          psF32 Radius)
     1835\end{prototype}
     1836
     1837Define \code{psImage} subarrays for the source located at coordinates
     1838\code{x,y} on the image set defined by \code{readout}.  The pixels
     1839defined by this operation consist of a square window (of full width $2
     1840Radius + 1$) centered on the pixel which contains the given
     1841coordinate, in the frame of the readout.  The window is defined to
     1842have limits which are valid within the boundary of the \code{readout}
     1843image, thus if the radius would fall outside the image pixels, the
     1844subimage is truncated to only consist of valid pixels.  If
     1845\code{readout->mask} or \code{readout->weight} are not \code{NULL},
     1846matching subimages are defined for those images as well.  This
     1847function fails if no valid pixels can be defined (x or y less than
     1848Radius, for example).  This function should be used to define a region
     1849of interest around a source, including both source and sky pixels.
     1850
     1851\begin{prototype}
     1852pmSource *pmSourceLocalSky(pmSource *source,
     1853                           psStatsOptions statsOptions,
     1854                           psF32 Radius)
     1855\end{prototype}
     1856
     1857Measure the local sky in the vicinity of the given \code{source}.  The
     1858\code{Radius} defines the square aperture in which the moments will be
     1859measured.  This function assumes the source pixels have been defined,
     1860and that the value of \code{Radius} here is smaller than the value of
     1861\code{Radius} used to define the pixels.  The annular region not
     1862contained within the radius defined here is used to measure the local
     1863background in the vicinity of the source.  The local background
     1864measurement uses the specified statistic passed in via the
     1865\code{statsOptions} entry.  This function allocates the
     1866\code{pmMoments} structure.  The resulting sky is used to set the
     1867value of the \code{pmMoments.sky} element of the provided
     1868\code{pmSource} structure. 
    18731869
    18741870\begin{prototype}
     
    18841880value indicates the success (TRUE) of the operation.
    18851881
    1886 \tbd{add pmSourcePSFClump}
    1887 
    1888 \tbd{fix pmSourceRoughClass}
    1889 
    1890 \tbd{add pmSourcePhotometry}
    1891 
    1892 \tbd{pmSourceDophotType}
    1893 
    1894 \tbd{pmSourceSextractType}
    1895 
    1896 \tbd{pmModelFitStatus}
    1897 
    1898 \begin{prototype}
    1899 bool pmSourceRoughClass(pmArray *source, psMetadata *metadata);
     1882\begin{prototype}
     1883pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *metadata);
     1884\end{prototype}
     1885
     1886We use the source moments to make an initial, approximate source
     1887classification, and as part of the information needed to build a PSF
     1888model for the image.  As long as the PSF shape does not vary
     1889excessively across the image, the sources which are represented by a
     1890PSF (the start) will have very similar second moments.  The function
     1891\code{pmSourcePSFClump} searches a collection of \code{sources} with
     1892measured moments for a group with moments which are all very similar.
     1893The function returns a \code{pmPSFClump} structure, representing the
     1894centroid and size of the clump in the $\sigma_x$, $\sigma_y$
     1895second-moment plane. 
     1896
     1897The goal is to identify and characterize the stellar clump within the
     1898$\sigma_x, \sigma_y$ plane.  To do this, an image is constructed to
     1899represent this plane.  The units of $\sigma_x$ and $\sigma_y$ are in
     1900image pixels.  A pixel in this analysis image represents 0.1 pixels in
     1901the input image.  The dimensions of the image need only be 10 pixels.
     1902The peak pixel in this image (above a threshold of half of the image
     1903maximum) is found.  The coordinates of this peak pixel represent the
     19042D mode of the $\sigma_x, \sigma_y$ distribution.  The sources with
     1905$\sigma_x, \sigma_y$ within 0.2 pixels of this value are then used to
     1906calculate the median and standard deviation of the $\sigma_x,
     1907\sigma_y$ values.  These resulting values are returned via the
     1908\code{pmPSFClump} structure.
     1909
     1910The return value indicates the success (TRUE) of the operation.
     1911
     1912\tbd{limit the S/N of the candidate sources (part of Metadata)?}
     1913
     1914\tbd{save the clump parameters on the Metadata}
     1915
     1916\begin{prototype}
     1917bool pmSourceRoughClass(psArray *sources, psMetadata *metadata, pmPSFClump clump)
    19001918\end{prototype}
    19011919
    19021920Based on the specified data values, make a guess at the source
    19031921classification.  The sources are provides as a \code{psArray} of
    1904 \code{psSource} entries.  Definable parameters needed to make the
     1922\code{pmSource} entries.  Definable parameters needed to make the
    19051923classification are provided to the routine with the \code{psMetadata}
    19061924structure.  The rules below refer to values which can be extracted
     
    19251943electrons, stored with the metadata keyword \code{READ_NOISE}.
    19261944
    1927 Sources with $SN$ less than \code{FAINT_SN_LIM} are identified as type
    1928 \code{PM_SOURCE_FAINTSTAR}.  Sources with $SN$ greater than
    1929 \code{PSF_SN_LIM} are then selected as possible PSF stars.  These
    1930 sources are used to determine a guess at the shape of the PSF, based
    1931 on the collection of $\sigma_x$ and $\sigma_y$ values.
    1932 
    1933 The goal is to identify and characterize the stellar clump within the
    1934 $\sigma_x, \sigma_y$ plane.  To do this, an image is constructed to
    1935 represent this plane.  The units of $\sigma_x$ and $\sigma_y$ are in
    1936 image pixel.  A pixel in this analysis image represents 0.1 pixels in
    1937 the input image.  The dimensions of the image need only be 10 pixels.
    1938 The peak pixel in this image (above a threshold of half of the image
    1939 maximum) is found.  The coordinates of this peak pixel represent the
    1940 2D mode of the $\sigma_x, \sigma_y$ distribution.  The sources with
    1941 $\sigma_x, \sigma_y$ within 0.2 pixels of this value are then used to
    1942 calculate the median and standard deviation of the $\sigma_x,
    1943 \sigma_y$ values.  These resulting values are placed back on the
    1944 metadata structure with the metadata names \code{PSF_CLUMP_X},
    1945 \code{PSF_CLUMP_dX} and \code{PSF_CLUMP_Y}, \code{PSF_CLUMP_dY}.
    1946 
    19471945All sources with:
    19481946\[ |\sigma_x - \mbox{CLUMP}_x| < \mbox{CLUMP}_{dx}\]
     
    19611959\tbd{need to exclude stars outside valid data region}.
    19621960
    1963 The return value indicates the success (TRUE) of the operation.
     1961Sources with $SN$ less than \code{FAINT_SN_LIM} are identified as type
     1962\code{PM_SOURCE_FAINTSTAR}.  Sources with $SN$ greater than
     1963\code{PSF_SN_LIM} are then selected as possible PSF stars.  These
     1964sources are used to determine a guess at the shape of the PSF, based
     1965on the collection of $\sigma_x$ and $\sigma_y$ values.
     1966
     1967\tbd{this discussion needs to be adjusted to match the implementation}
    19641968
    19651969\subsection{Object Fitting}
     
    19871991\item Subtract model from image.
    19881992\end{enumerate}
    1989 
    1990 \begin{prototype}
    1991 bool pmSourceSetPixelsCircle(pmSource *source, const psImage *image, float radius, int maskVal);
    1992 \end{prototype}
    1993 
    1994 Define pixels associated with a source based on a circular aperture.
    1995 This operation creates the \code{source.pixels} and \code{source.mask}
    1996 entries for the source based on a circular aperture centered on the
    1997 source centroid, if the \code{pmSource.pmMoments} entry exists, or
    1998 \code{pmSource.pmPeak} if it does not.  The \code{source.pixels} is a
    1999 subimage of the input image.  The function returns \code{TRUE} on
    2000 success or \code{FALSE} on failure.
    20011993
    20021994\begin{prototype}
     
    20392031
    20402032\begin{prototype}
     2033bool pmModelFitStatus (pmModel *model);
     2034\end{prototype}
     2035
     2036This function wraps the call to the model-specific function returned
     2037by \code{pmModelFitStatusFunc_GetFunction}.  The model-specific
     2038function examines the model parameters, parameter errors, Chisq, S/N,
     2039and other parameters available from \code{model} to decide if the
     2040particular fit was successful or not.
     2041
     2042\begin{prototype}
    20412043bool pmSourceAddModel(psImage *image, pmSource *source, bool center, bool sky);
    20422044bool pmSourceSubModel(psImage *image, pmSource *source, bool center, bool sky);
     
    20452047Add or subtract the given source model flux to/from the provided
    20462048image.  The boolean option \code{center} selects if the source is
    2047 recentered to the image center or if it is placed at its centroid
     2049re-centered to the image center or if it is placed at its centroid
    20482050location.  The boolean option \code{sky} selects if the background sky
    20492051is applied (\code{TRUE}) or not.  The pixel range in the target image
     
    20512053image.  The success status is returned.
    20522054
    2053 \subsection{Basic Object Models}
    2054 \label{ObjectModels}
    2055 
    2056 We specify a variety of basic object models which are required.
    2057 Details of the model functional forms, parameters, and the derivatives
    2058 are specified in the ADD.
    2059 
    2060 \subsubsection{Real 2D Gaussian}
    2061 
    2062 \begin{prototype}
    2063 float pmMinLM_Gauss2D(psVector *deriv, psVector *params, psVector *x);
    2064 \end{prototype}
    2065 
    2066 This function is a two-dimensional Gaussian with an elliptical
    2067 cross-section and a constant local background. 
    2068 
    2069 The intial guess for the Gaussian parameters may be taken from the
    2070 moments, peak value, and local sky.
    2071 
    2072 \subsubsection{Pseudo-Gaussian}
    2073 
    2074 \begin{prototype}
    2075 float pmMinLM_PseudoGauss2D(psVector *deriv, psVector *params, psVector *x);
    2076 \end{prototype}
    2077 
    2078 This function is a polynomial approximation of a 2D Gaussian otherwise
    2079 very similar to the real Gaussian.  It is used in place of a real
    2080 Gaussian for speed.
    2081 
    2082 The intial guess for the Gaussian parameters may be taken from the
    2083 moments, peak value, and local sky.
    2084 
    2085 \subsubsection{Waussian}
    2086 
    2087 \begin{prototype}
    2088 float pmMinLM_Wauss2D(psVector *deriv, psVector *params, psVector *x);
    2089 \end{prototype}
    2090 
    2091 The Waussian is a modified polynomial approximation of a 2D Gaussian,
    2092 with non-linear polynomial terms having variable coefficients, rather
    2093 than the Taylor series values of 1/2 and 1/6. 
    2094 
    2095 \subsubsection{Twisted Gaussian}
    2096 
    2097 \begin{prototype}
    2098 float pmMinLM_TwistGauss2D(psVector *deriv, psVector *params, psVector *x);
    2099 \end{prototype}
    2100 
    2101 This function describes an object with power-law wings and a flattened
    2102 core, where the core has a different contour from the wings. 
    2103 
    2104 The intial guess for the Gaussian parameters may be taken from the
    2105 moments, peak value, and local sky.
    2106 
    2107 \tbd{future galaxy models to be implemented}
    2108 
    2109 \subsubsection{Sersic Galaxy Model}
    2110 
    2111 \begin{prototype}
    2112 float pmMinLM_Sersic(psVector *deriv, psVector *params, psVector *x);
    2113 \end{prototype}
    2114 
    2115 \subsubsection{Sersic with Core Galaxy Model}
    2116 
    2117 \begin{prototype}
    2118 float pmMinLM_SersicCore(psVector *deriv, psVector *params, psVector *x);
    2119 \end{prototype}
    2120 
    2121 \subsubsection{Pseudo Sersic Galaxy Model}
    2122 
    2123 \begin{prototype}
    2124 float pmMinLM_PseudoSersic(psVector *deriv, psVector *params, psVector *x);
    2125 \end{prototype}
    2126 
     2055\begin{prototype}
     2056bool pmSourcePhotometry (float *fitMag,  // integrated fit magnitude
     2057                         float *obsMag,  // aperture flux magnitude
     2058                         pmModel *model, // model used for photometry
     2059                         psImage *image, // image pixels to be used
     2060                         psImage *mask   // mask of pixels to ignore
     2061);
     2062\end{prototype}
     2063
     2064The function returns both the magnitude of the fit, defined as $-2.5
     2065\log{\rm flux}$, where the flux is integrated under the model,
     2066theoretically from a radius of 0 to infinity.  In practice, we
     2067integrate the model beyond $50 \sigma$.  The aperture magnitude is
     2068defined as $-2.5 \log{\rm flux}$, where the flux is summed for all
     2069pixels which are not excluded by the aperture mask.  The model flux is
     2070calculated by calling the model-specific function provided by
     2071\code{pmModelFlux_GetFunction}.
     2072
     2073\begin{prototype}
     2074int pmSourceDophotType (pmSource *source);
     2075\end{prototype}
     2076This function converts the source classification into the closest
     2077available approximation to the Dophot classification scheme.  The
     2078following list gives the correspondence:
     2079\begin{verbatim}
     2080PM_SOURCE_DEFECT:       8
     2081PM_SOURCE_SATURATED:    8
     2082PM_SOURCE_SATSTAR:      10
     2083PM_SOURCE_PSFSTAR:      1
     2084PM_SOURCE_GOODSTAR:     1
     2085PM_SOURCE_POOR_FIT_PSF: 7
     2086PM_SOURCE_FAIL_FIT_PSF: 4
     2087PM_SOURCE_FAINTSTAR:    4
     2088PM_SOURCE_GALAXY:       2
     2089PM_SOURCE_FAINT_GALAXY: 2
     2090PM_SOURCE_DROP_GALAXY:  2
     2091PM_SOURCE_FAIL_FIT_GAL: 2
     2092PM_SOURCE_POOR_FIT_GAL: 2
     2093PM_SOURCE_OTHER:        ?
     2094\end{verbatim}
     2095
     2096\begin{prototype}
     2097int pmSourceSextractType (pmSource *source);
     2098\end{prototype}
     2099This function converts the source classification into the closest
     2100available approximation to the Sextractor classification scheme.
     2101\tbd{the correspondence is not yet defined}.
    21272102
    21282103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    22182193  questionable pixels neighbor each other in the transformed image.
    22192194\item The cores of point sources may mimic a cosmic ray, especially in
    2220   under-sampled images.  To minimise flagging stars as cosmic rays, we
     2195  under-sampled images.  To minimize flagging stars as cosmic rays, we
    22212196  determine the gradient around the pixel of interest; if the gradient
    22222197  is large, then the pixel is likely the core of a point source.  In
     
    23322307Image subtraction is arguably the best method of identifying faint
    23332308variable sources in images with different point-spread functions.  It
    2334 relies on fitting for a convolution kernel that minimises the
     2309relies on fitting for a convolution kernel that minimizes the
    23352310residuals in subtracting small regions of the image.  The use of a
    23362311convolution kernel consisting of a linear combination of basis
     
    24342409\code{spatialOrder}).  The \code{subIndex} is set to the kernel which
    24352410has \code{u = 0}, \code{v = 0}, \code{xOrder = 0} and \code{yOrder =
    2436 0}, for the first of the gaussian widths in the \code{sigmas} vector.
     24110}, for the first of the Gaussian widths in the \code{sigmas} vector.
    24372412
    24382413\subsection{Stamps}
     
    24722447
    24732448\begin{prototype}
    2474 psArary *pmSubtractionFindStamps(psArray *stamps, // Output stamps, or NULL
     2449psArray *pmSubtractionFindStamps(psArray *stamps, // Output stamps, or NULL
    24752450                                 const psImage *image, // Image for which to find stamps
    24762451                                 const psImage *mask, // Mask
     
    24912466stamp \code{status} is \code{PM_STAMP_REJECTED}.
    24922467
    2493 A stamp shall be recognised as the pixel with the greatest value that
     2468A stamp shall be recognized as the pixel with the greatest value that
    24942469does not have the corresponding pixel in the \code{mask} matching
    24952470\code{maskVal}.  If the value of the this pixel does not exceed
     
    25532528
    25542529Since this step is one of the major rate-limiting factors in image
    2555 subtraction, care should be taken with optimisation.
     2530subtraction, care should be taken with optimization.
    25562531
    25572532\begin{prototype}
     
    26032578input image, and then squaring to obtain the mean square residual.
    26042579
    2605 \subsection{Visualisation of kernel}
    2606 
    2607 Having solved for the best-fit kernel, it is often useful to visualise
     2580\subsection{Visualization of kernel}
     2581
     2582Having solved for the best-fit kernel, it is often useful to visualize
    26082583it.
    26092584
     
    27092684\appendix
    27102685
    2711 \section{Pseudo-C PSPhot}
    2712 \label{psphot}
    2713 
    2714 \begin{verbatim}
    2715 # include <pslib.h>
    2716 # include <psmodule.h>
    2717 
    2718 main () {
    2719 
    2720   psMetadata *header;
    2721   psImage *image;
    2722 
    2723   fd = psFitsOpen (argv[1]);
    2724   md = psFitsReadHeader (fd);
    2725   image = psFitsReadImage (fd, md);
    2726 
    2727   stats = psImageStats (NULL, image);
    2728 
    2729   RDNOISE  = psMetadataLookup (md, "RDNOISE");
    2730   GAIN     = psMetadataLookup (md, "GAIN");
    2731   INNER    = psMetadataLookup (config, "INNER_RADIUS");
    2732   OUTER    = psMetadataLookup (config, "OUTER_RADIUS");
    2733   SATURATE = psMetadataLookup (config, "SATURATE");
    2734   NSIGMA   = psMetadataLookup (config, "PSF_PEAK_THRESHOLD");
    2735   RADIUS   = psMetadataLookup (config, "PSF_MOMENTS_RADIUS");
    2736   XBORDER  = psMetadataLookup (config, "XBORDER");
    2737   YBORDER  = psMetadataLookup (config, "YBORDER");
    2738 
    2739   keep = psRegionAlloc (XBORDER, image->nCol - YBORDER,
    2740                         YBORDER, image->nRow - YBORDER);
    2741  
    2742   Sky = stats->median;
    2743   Sig = sqrt(Sky/GAIN + SQ(RDNOISE));
    2744 
    2745   kernel = psKernelParts ();
    2746   smooth = psImageConvolve (NULL, image, kernel, PS_PARTS);
    2747 
    2748   peaks = pmFindImagePeaks (smooth, NSIGMA*Sig + Sky);
    2749 
    2750   peaks = pmCullImagePeaks (peaks, SATURATE, *keep);
    2751  
    2752   sources = pmSourceLocalSky (image, peaks, INNER, OUTER);
    2753 
    2754   sources = pmSourceMoments (image, sources, RADIUS);
    2755  
    2756   sources = pmSourceRoughClassify (sources, SATURATE, MIN_SN_LIM, *keep);
    2757 
    2758   stars = pmSourceSelectBrightStars (sources);
    2759 
    2760   stars = pmSourceFitModel (
    2761 }
    2762 
    2763 
    2764 
    2765 psArray *pmFindImagePeaks (psImage *image, float threshold) {
    2766 
    2767   psVector *row;
    2768 
    2769   row = psVectorAlloc (image[0].Ncol);
    2770 
    2771   /* find peaks in each row */
    2772   for (i = 0; i < image[0].Nrow; i++) {
    2773     rowpeaks = pmFindVectorPeaks (row, threshold);
    2774     peaks.x = rowpeaks;
    2775     peaks.y = i;
    2776     peaks.z = image (i, x);
    2777   }
    2778 
    2779   /* drop non-local peaks (peaks with neighbors) */
    2780   for (n = 0; n < peaks.n; n++) {
    2781     if (!local_peak) {
    2782       drop_peak;
    2783     }
    2784   }
    2785   return (peaks);
    2786 }
    2787 \end{verbatim}
     2686\section{Basic Object Models}
     2687\label{ObjectModels}
     2688
     2689We specify a variety of basic object models which are required.
     2690Details of the model functional forms, parameters, and the derivatives
     2691are specified in the ADD.
     2692
     2693\subsubsection{Real 2D Gaussian}
     2694
     2695\begin{prototype}
     2696float pmMinLM_Gauss2D(psVector *deriv, psVector *params, psVector *x);
     2697\end{prototype}
     2698
     2699This function is a two-dimensional Gaussian with an elliptical
     2700cross-section and a constant local background. 
     2701
     2702The initial guess for the Gaussian parameters may be taken from the
     2703moments, peak value, and local sky.
     2704
     2705\subsubsection{Pseudo-Gaussian}
     2706
     2707\begin{prototype}
     2708float pmMinLM_PseudoGauss2D(psVector *deriv, psVector *params, psVector *x);
     2709\end{prototype}
     2710
     2711This function is a polynomial approximation of a 2D Gaussian otherwise
     2712very similar to the real Gaussian.  It is used in place of a real
     2713Gaussian for speed.
     2714
     2715The initial guess for the Gaussian parameters may be taken from the
     2716moments, peak value, and local sky.
     2717
     2718\subsubsection{Waussian}
     2719
     2720\begin{prototype}
     2721float pmMinLM_Wauss2D(psVector *deriv, psVector *params, psVector *x);
     2722\end{prototype}
     2723
     2724The Waussian is a modified polynomial approximation of a 2D Gaussian,
     2725with non-linear polynomial terms having variable coefficients, rather
     2726than the Taylor series values of 1/2 and 1/6. 
     2727
     2728\subsubsection{Twisted Gaussian}
     2729
     2730\begin{prototype}
     2731float pmMinLM_TwistGauss2D(psVector *deriv, psVector *params, psVector *x);
     2732\end{prototype}
     2733
     2734This function describes an object with power-law wings and a flattened
     2735core, where the core has a different contour from the wings. 
     2736
     2737The initial guess for the Gaussian parameters may be taken from the
     2738moments, peak value, and local sky.
     2739
     2740\tbd{future galaxy models to be implemented}
     2741
     2742\subsubsection{Sersic Galaxy Model}
     2743
     2744\begin{prototype}
     2745float pmMinLM_Sersic(psVector *deriv, psVector *params, psVector *x);
     2746\end{prototype}
     2747
     2748\subsubsection{Sersic with Core Galaxy Model}
     2749
     2750\begin{prototype}
     2751float pmMinLM_SersicCore(psVector *deriv, psVector *params, psVector *x);
     2752\end{prototype}
     2753
     2754\subsubsection{Pseudo Sersic Galaxy Model}
     2755
     2756\begin{prototype}
     2757float pmMinLM_PseudoSersic(psVector *deriv, psVector *params, psVector *x);
     2758\end{prototype}
    27882759
    27892760%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracChangeset for help on using the changeset viewer.