IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1104


Ignore:
Timestamp:
Jun 25, 2004, 2:34:15 PM (22 years ago)
Author:
Paul Price
Message:

Reworked the bias subtraction and convolution sections.

File:
1 edited

Legend:

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

    r973 r1104  
    1 %%% $Id: ModulesSDRS.tex,v 1.2 2004-06-10 01:57:54 price Exp $
     1%%% $Id: ModulesSDRS.tex,v 1.3 2004-06-26 00:34:15 price Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    5252
    5353This document describes the Pan-STARRS Image Processing Pipeline (IPP)
    54 Phase 2 processing modules.  Phase 2 is the processing stage wherein
     54Phase 2 image processing modules.  Phase 2 is the processing stage wherein
    5555the instrumental signatures are removed from the detector images, in
    5656preparation for the combination of multiple images in Phase 4.
     
    7777\item Mask bad pixels;
    7878\item Mask cosmic rays;
    79 \item Mask optical defects;
    80 \item Measure the PSF;
    81 \item Find and measure objects;
    82 \item Correct astrometry; and
    83 \item Get postage stamps.
     79\item \tbd{Mask optical defects;}
     80\item \tbd{Measure the PSF;}
     81\item \tbd{Find and measure objects;}
     82\item \tbd{Correct astrometry; and}
     83\item \tbd{Get postage stamps.}
    8484\end{itemize}
    8585
    86 Each of these shall be discussed in turn, below.
     86Each of these shall be discussed in turn, below.  Those modules which
     87are \tbd{TBD} will be deferred until they may be properly defined.
    8788
    8889These modules are built on top of, and are dependent upon, the \PS{}
    89 Library, PSLib.
     90Library, PSLib.  Some functions are specified below which should be
     91added to PSLib, since we anticipate that these will also find use in
     92other modules.
    9093
    9194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    97100a kernel derived from the list of OT shifts made during the exposure.
    98101
     102\subsection{Kernel definition}
     103
     104In order to perform a convolution, we need to define the convolution
     105kernel.  We need a more general object than a \code{psImage} so that
     106we can incorporate the offset from the $(0,0)$ pixel to the $(0,0)$
     107value of the kernel\footnote{The kernel has both positive and negative
     108indices to convey the positive and negative shifts.  One might
     109consider setting the \code{x0} and \code{y0} members of a
     110\code{psImage} to the appropriate offsets, but this is not the purpose
     111of these members, and doing so may affect the behavior of other
     112\code{psImage} operations.}.  Hence we define a \code{psKernel}:
     113
     114\begin{verbatim}
     115/** A convolution kernel */
     116typedef struct {
     117    int xMin, yMin;                     ///< Most negative indices
     118    int xMax, yMax;                     ///< Most positive indices
     119    float **kernel;                     ///< The kernel data
     120} psKernel;
     121\end{verbatim}
     122
     123The \code{kernel} member shall point to an image that contains the
     124kernel values.  The kernel has both positive and negative indices to
     125convey the positive and negative shifts.  The maximum extent of these
     126shifts shall be defined by the \code{xMin}, \code{xMax}, \code{yMin}
     127and \code{yMax} members.  Note that \code{xMin} and \code{yMin}, under
     128normal circumstances, should be negative numbers.  That is,
     129\code{myKernel->kernel[-3][-2]} may be defined if \code{yMin} and
     130\code{xMin} are equal to or more negative than -3 and -2,
     131respectively.
     132
     133Of course, we require the appropriate constructor and destructor:
     134\begin{verbatim}
     135psKernel *psKernelAlloc(int xMin, int xMax, int yMin, int yMax);
     136void psKernelFree(psKernel *myKernel);
     137\end{verbatim}
     138
     139
    99140\subsection{Calculate the convolution kernel}
    100141
    101142Given a list of pixel shifts made in the course of OT guiding,
    102 \code{psPhase2GetKernel} shall return an image that represents the
    103 kernel.  The API shall be the following:
    104 \begin{verbatim}
    105 /** Returns the kernel of OT shifts made during the course of the exposure. */
    106 psImage *psPhase2GetKernel(psVector *xShifts, ///< List of OT shifts in x; integers
    107                            psVector *yShifts ///< List of OT shifts in y; integers; xshifts->n == yShifts->n
    108                            );
    109 \end{verbatim}
     143\code{psPhase2GetKernel} shall return the kernel.  The API shall be
     144the following:
     145\begin{verbatim}
     146psKernel *psPhase2GetKernel(const psVector *xShifts, const psVector *yShifts);
     147\end{verbatim}
     148
     149The shift vectors, \code{xShifts} and \code{yShifts}, will be supplied
     150by the user, most probably from the FITS file containing the image.
    110151
    111152The elements of the shift vectors should be of an integer type,
     
    114155
    115156The format of the shifts vectors will be a list of the net shift
    116 position relative to the starting point for each timestep (there will
    117 likely be about 10~Hz $\times$ 30~sec = 300 timesteps).
    118 
    119 If the vectors are not of the same size, then the function shall
    120 generate an error.
     157position relative to the starting point for each timestep.  In the
     158normal course of \PS{} observations using orthogonal transfer, there
     159will likely be about 10~Hz $\times$ 30~sec $=$ 300 timesteps.
     160
     161If the vectors are not of the same number of elements, then the
     162function shall generate a warning shall be generated, following which,
     163the longer vector trimmed to the length of the shorter, and the
     164function shall continue.
    121165
    122166\subsection{Convolve an image with the kernel}
    123167
    124168Given an input image and the convolution kernel,
    125 \code{psPhase2ConvolveWithKernel} shall convolve the input image with
    126 the kernel and return the convolved image.  The API shall be the
    127 following:
    128 \begin{verbatim}
    129 /** Returns an image that is the result of convolving the input image with the specified kernel. */
    130 psImage *psPhase2ConvolveWithKernel(psImage *out, ///< Output image, or NULL
    131                                     const psImage *in, ///< Input image to be convolved
    132                                     const psImage *kernel ///< Kernel by which to convolve
    133                                     );
    134 \end{verbatim}
    135 
    136 Two methods shall be used to do the convolution: for small kernels
    137 (smaller than 200 total pixels), the convolution shall be performed in
    138 real space; for large kernels (larger than 200 total pixels), the
    139 convolution shall be performed using Fast Fourier Transforms (FFTs).
    140 
    141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    142 
     169\code{psPhase2ConvolveWithKernel} shall convolve the input image,
     170\code{in}, with the kernel, \code{kernel} and return the convolved
     171image, \code{out}.  The API shall be the following:
     172\begin{verbatim}
     173psImage *psImageConvolve(psImage *out, const psImage *in, const psKernel *kernel, bool direct);
     174\end{verbatim}
     175
     176Two methods shall be available for the convolution: if \code{direct}
     177is \code{true}, then the convolution shall be performed in real space
     178(appropriate for small kernels); otherwise, the convolution shall be
     179performed using Fast Fourier Transforms (FFTs; appropriate for larger
     180kernels).
     181
     182In the event that \code{out} is \code{NULL}, a new \code{psImage}
     183shall be allocated and returned.
     184
     185\subsection{PSLib Routines}
     186
     187\code{psKernel} and \code{psImageConvolve} shall be part of the \PS{}
     188Library, \code{PSLib}, so that they may be re-used for other modules.
     189
     190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    143191
    144192\section{Bias subtraction and trim}
     
    162210A \code{psImageRegion} specifies the offset from $(0,0)$ on the
    163211detector\footnote{Note that an image may be smaller than the entire
    164 area of the detector if the detector is windowed.} and the size of the
    165 region.
     212area of the detector if the detector is windowed, or if a subimage has
     213been generated.} and the size of the region.
    166214
    167215We also require a corresponding constructor and destructor:
     
    181229(\code{psList}) of \code{psImageRegion}s.
    182230
     231\subsection{Splines}
     232
     233A spline is a popular choice for fitting 1D data, such as overscans,
     234but we neglected to define them for PSLib.  We now define
     235one-dimensional cubic splines, \code{psSpline1D}, which shall be
     236included into PSLib:
     237
     238\begin{verbatim}
     239/** A 1D cubic-spline */
     240typedef struct {
     241    int n;                              ///< Number of spline pieces
     242    float *coeff[4];                    ///< Coefficients.  There are 4 coefficients for each spline piece.
     243    float *coeffErr[4];                 ///< Errors in the coefficients.
     244    bool *mask[4];                      ///< Mask for the coefficients.
     245    float *domains;                     ///< The boundaries between each spline piece.  Size is n+1.
     246} psSpline1D;
     247\end{verbatim}
     248
     249The \code{psSpline1D} structure is very similar to that of the
     250one-dimensional Chebyshev polynomial, \code{psPolynomial1D},
     251except for the following:
     252\begin{itemize}
     253\item Each spline piece has 4 coefficients (with corresponding error
     254and mask), corresponding to each of the zeroth through third order
     255coefficients of a cubic; and
     256\item It includes an additional member, \code{domains}, which
     257specifies the boundaries between each spline piece (including the two
     258ends).
     259\end{itemize}
     260
     261Of course, we require the appropriate constructors and destructor:
     262\begin{verbatim}
     263/** Constructors */
     264psSpline1D *psSpline1DAlloc(int n, float min, float max);
     265psSpline1D *psSpline1DAllocGeneric(const psVector *bounds);
     266void psSpline1DFree(psSpline1D *mySpline);
     267\end{verbatim}
     268
     269\code{psSpline1DAlloc} shall allocate and return a \code{psSpline1D},
     270setting the \code{domains} on the basis of the input number of spline
     271pieces, \code{n}, and the minimum (\code{min}) and maximum
     272(\code{max}) data values.
     273
     274\code{psSpline1DAllocGeneric} shall allocate and return a
     275\code{psSpline1D}, using the \code{bounds} to define the number of
     276spline pieces and the \code{domains}.
     277
     278\code{psSpline1DFree} shall free the given spline, and its members.
     279
     280Also, as for the polynomials, we require an evaluator.  Given a
     281\code{spline} and ordinate at which to evaluate, \code{x},
     282\code{psSpline1DEval} shall evaluate and return the value of the
     283spline at the ordinate.  If the ordinate is outside the bounds, then
     284the function shall generate a warning, and extrapolate the spline to
     285the ordinate and return the value.
     286
     287\begin{verbatim}
     288/** Evaluator */
     289float psSpline1DEval(const psSpline1D *spline, ///< Spline to evaluate
     290                     float x    ///< Normalised (-1,1) coordinates at which to evaluate
     291                     );
     292\end{verbatim}
     293
     294
    183295\subsection{Bias subtraction}
    184296
     
    187299The API shall be the following:
    188300\begin{verbatim}
    189 /** Subtracts an overscan and bias from the input image. */
    190 psReadout *psPhase2SubtractBias(psReadout *in, ///< Input image to be de-biased, and output
    191                                 psPolynomial1D *polySpec, ///< Polynomial specification to use for fit,
    192                                                           ///< outputed
    193                                 const psList *regions, ///< Linked list of psImageRegion types.
    194                                 psOverscanAxis overscanAxis, ///< Overscan axis
    195                                 const psStatsOptions *stat, ///< Statistic to use
    196                                 const psImage *bias ///< Bias (or dark) image to subtract
    197                                 );
    198 \end{verbatim}
    199 
    200 The input image shall have the bias subtracted in-place.
    201 
    202 The polynomial specification, \code{polySpec}, specifies the order of
    203 a polynomial fit which may be made to the overscan if the
    204 \code{overscanAxis} is \code{PS_OVERSCAN_ROWS_FIT} or
    205 \code{PS_OVERSCAN_COLUMNS_FIT}.  \code{polySpec} shall, upon return,
    206 contain the coefficients of the overscan fit, if performed.
    207 
    208 The prescan and/or overscan regions to be used are specified in
    209 \code{regions}.
     301psReadout *psPhase2SubtractBias(psReadout *in, void *fitSpec, psOverscanAxis overscanAxis, psBiasFit fit,
     302                                int nBin, const psList *regions, const psStats *stat, const psImage *bias);
     303\end{verbatim}
     304
     305The input image, \code{in}, shall have the bias subtracted in-place.
     306
     307The type of the overscan fit specification, \code{fitSpec}, shall be
     308dependent upon the value of \code{fit}, which specifies the type of
     309fit to be employed.  \code{fit} is an enumerated type:
     310
     311\begin{verbatim}
     312/** Fit type for bias */
     313typedef enum {
     314    PS_OVERSCAN_FIT_NONE,               ///< No fit to bias
     315    PS_OVERSCAN_FIT_LINEAR,             ///< Do linear interpolation on bias
     316    PS_OVERSCAN_FIT_POLYNOMIAL,         ///< Fit polynomial to bias
     317    PS_OVERSCAN_FIT_CHEBYSHEV,          ///< Fit chebyshev to bias
     318    PS_OVERSCAN_FIT_SPLINE              ///< Fit cubic splines to bias
     319} psBiasFit;
     320\end{verbatim}
     321
     322If \code{fitSpec} is \code{NULL}, or \code{fit} is
     323\code{PS_OVERSCAN_FIT_NONE}, then no fit shall be performed to the
     324overscan.  If \code{fit} is \code{PS_OVERSCAN_FIT_LINEAR}, then the
     325function shall perform simple linear interpolation between points in
     326the overscan.  Otherwise, \code{fitSpec} shall be interpreted to be a
     327structure of the appropriate type (\code{psPolynomial1D} for
     328\code{PS_OVERSCAN_FIT_POLYNOMIAL} and
     329\code{PS_OVERSCAN_FIT_CHEBYSHEV}, and \code{psSpline1D} for
     330\code{PS_OVERSCAN_FIT_SPLINE}), and the overscan shall be fit using
     331the specified functional form.  Upon return, the \code{fitSpec} shall
     332contain the coefficients of the overscan fit.
    210333
    211334The \code{overscanAxis} specifies how the prescan/overscan subtraction
     
    214337/** Overscan axis */
    215338typedef enum {
    216     PS_OVERSCAN_NONE = 0,               ///< No overscan subtraction
    217     PS_OVERSCAN_ROWS = 1,               ///< Subtract rows
    218     PS_OVERSCAN_COLUMNS = 2,            ///< Subtract columns
    219     PS_OVERSCAN_ROWS_FIT = -1,          ///< Subtract a fit to rows
    220     PS_OVERSCAN_COLUMNS_FIT = -2,       ///< Subtract a fit to columns
    221     PS_OVERSCAN_ALL = 3                 ///< Subtract the statistic of all pixels in overscan region
     339    PS_OVERSCAN_NONE,                   ///< No overscan subtraction
     340    PS_OVERSCAN_ROWS,                   ///< Subtract rows
     341    PS_OVERSCAN_COLUMNS,                ///< Subtract columns
     342    PS_OVERSCAN_ALL                     ///< Subtract the statistic of all pixels in overscan region
    222343} psOverscanAxis;
    223344\end{verbatim}
    224345
    225 No prescan/overscan subtraction shall be performed if the
    226 \code{overscanAxis} is \code{PS_OVERSCAN_NONE} or if \code{regions} is
    227 \code{NULL}.  The subtraction shall be on the basis of rows or columns
    228 if the \code{overscanAxis} is \code{PS_OVERSCAN_ROWS} or
    229 \code{PS_OVERSCAN_COLUMNS}, respectively.  If the \code{overscanAxis}
    230 is \code{PS_OVERSCAN_ROWS_FIT} or \code{PS_OVERSCAN_COLUMNS_FIT}, a
    231 fit to the prescan/overscan region shall be subtracted from the rows
    232 or columns, respectively.  Finally, if the \code{overscanAxis} is
    233 \code{PS_OVERSCAN_ALL}, then the appropriate statistic (specified by
    234 \code{stat}) of all of the pixels in the prescan/overscan region(s)
    235 shall be subtracted from the image.
     346If the \code{overscanAxis} is \code{PS_OVERSCAN_NONE}, then the
     347function shall not perform any overscan subtraction.  If the
     348\code{overscanAxis} is \code{PS_OVERSCAN_ALL}, then all the overscan
     349regions shall be used to generate a single statistic (specified by
     350\code{stat}) which shall be subtracted from the entire image.  A
     351warning shall be generated if the \code{overscanAxis} is
     352\code{PS_OVERSCAN_NONE} or \code{PS_OVERSCAN_ALL} and the \code{fit}
     353is not \code{PS_OVERSCAN_FIT_NONE}.
     354
     355If the \code{overscanAxis} is \code{PS_OVERSCAN_ROWS} or
     356\code{PS_OVERSCAN_COLUMNS}, then the overscan shall be reduced to a
     357single vector in the dimension specified using the specified statistic
     358(\code{stat}).  If \code{nBin} is positive and less than the dimension
     359of the vector, then the vector shall subsequently be binned down into
     360\code{nBin} bins, again using the specified statistic (\code{stat}).
     361If the overscan is not defined for each row/column, then the function
     362shall generate a warning and then interpolate using the provided
     363functional form if \code{fit} is not \code{PS_OVERSCAN_FIT_NONE};
     364otherwise, the function shall generate an error.
     365
     366The prescan and/or overscan regions to be used are specified in
     367\code{regions}, which is a linked list of \code{psImageRegion}s.  If
     368\code{regions} is non-\code{NULL} and \code{overscanAxis} is not
     369\code{PS_OVERSCAN_NONE}, then the function shall generate a warning.
    236370
    237371The statistic to use in combining multiple pixels in the
    238 prescan/overscan regions is specified by \code{stat}.  Legal values
    239 shall be \code{PS_STAT_SAMPLE_MEAN}, \code{PS_STAT_SAMPLE_MEDIAN},
    240 \code{PS_STAT_ROBUST_MEAN}, \code{PS_STAT_ROBUST_MEDIAN},
    241 \code{PS_STAT_ROBUST_MODE}.  \tbd{Note in particular that
    242 %\code{PS_STAT_CLIPPED_MEAN}
    243 a clipped mean is not supported, because that means we have to supply
    244 clipping parameters which isn't very neat.}
    245 
    246 A full-frame bias (or dark) image shall be subtracted if \code{bias}
    247 is non-NULL.  Note that the input image, \code{in}, and the
    248 \code{bias} image need not be the same size, but the function shall
    249 use the offsets in the image (\code{in->x0} and \code{in->y0}) to
    250 determine the appropriate offsets to obtain the correct pixel on the
    251 \code{bias}.  In the event that the \code{bias} image is too small
    252 (i.e., pixels on the input image refer to pixels outside the range of
    253 the \code{bias} image), the function shall generate an error.
     372prescan/overscan regions is specified by \code{stat}.  \code{stat} is
     373of type \code{psStats} instead of simply \code{psStatsOptions} so that
     374clipping levels may be specified, if desired.  In the event that
     375multiple options are specified by \code{stats}, a warning shall be
     376generated, and the option with the highest priority shall be used,
     377according to the following priority order: \code{PS_STAT_SAMPLE_MEAN},
     378\code{PS_STAT_SAMPLE_MEDIAN}, \code{PS_STAT_CLIPPED_MEAN},
     379\code{PS_STAT_ROBUST_MEAN},\ \code{PS_STAT_ROBUST_MEDIAN},
     380\code{PS_STAT_ROBUST_MODE}.
     381
     382A bias (or dark) image shall be subtracted pixel-by-pixel from the
     383input image if \code{bias} is non-NULL.  Note that the input image,
     384\code{in}, and the \code{bias} image need not be the same size, but
     385the function shall use the offsets in the image (\code{in->x0} and
     386\code{in->y0}) to determine the appropriate offsets to obtain the
     387correct pixel on the \code{bias}.  In the event that the \code{bias}
     388image is too small (i.e., pixels on the input image refer to pixels
     389outside the range of the \code{bias} image), the function shall
     390generate an error.
    254391
    255392
Note: See TracChangeset for help on using the changeset viewer.