pmFringeStats.h

Go to the documentation of this file.
00001 /* @file pmFringeStats.h
00002  * @brief Measure fringe statistics, and apply correction
00003  *
00004  * @author Eugene Magnier, IfA
00005  * @author Paul Price, IfA
00006  *
00007  * @version $Revision: 1.12 $ $Name:  $
00008  * @date $Date: 2007/01/24 02:54:15 $
00009  * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
00010  */
00011 
00012 #ifndef PM_FRINGE_STATS
00013 #define PM_FRINGE_STATS
00014 
00015 /// @addtogroup detrend Detrend Creation and Application
00016 /// @{
00017 
00018 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00019 // pmFringeRegions
00020 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00021 
00022 /// Fringe measurement regions.
00023 ///
00024 /// Fringes are measured within a box of size dX,dY.  A large scale smoothing is performed by subtracting the
00025 /// background within large divisions of the image.  The coordinates of the fringe points and the mask may be
00026 /// NULL, which means that they will be generated when required.
00027 typedef struct
00028 {
00029     int nRequested;                     // Number of fringe points selected
00030     int nAccepted;                      // Number of fringe points not masked
00031     int dX;                             // Median box half-width
00032     int dY;                             // Median box half-height
00033     int nX;                             // Number of large-scale smoothing divisions in x (col)
00034     int nY;                             // Number of large-scale smoothing divisions in y (row)
00035     psVector *x;                        // Fringe point coordinates (col), or NULL
00036     psVector *y;                        // Fringe point coordinates (row), or NULL
00037     psVector *mask;                     // Fringe point on/off mask, or NULL
00038 }
00039 pmFringeRegions;
00040 
00041 /// Allocate fringe regions
00042 pmFringeRegions *pmFringeRegionsAlloc (int nPts, ///< Number of fringe points to create
00043                                        int dX, ///< Half-width of fringe boxes
00044                                        int dY, ///< Half-height of fringe boxes
00045                                        int nX, ///< Smoothing scale in x
00046                                        int nY ///< Smoothing scale in y
00047                                       );
00048 
00049 /// Generate the fringe points
00050 ///
00051 /// Fringe points are generated randomly over the image.  No effort is made to avoid masked regions (indeed,
00052 /// the function knows nothing about masks).  If the random number generator is NULL, then a new one will be
00053 /// used.
00054 bool pmFringeRegionsCreatePoints(pmFringeRegions *fringe, ///< Fringe regions to generate
00055                                  const psImage *image, ///< Image for the regions (defines the size)
00056                                  psRandom *random ///< Random number generator, or NULL
00057                                 );
00058 
00059 /// Write the regions to a FITS file
00060 ///
00061 /// The fringe regions are written to the FITS file, with the given extension name.  The header is
00062 /// supplemented with scalar values dX, dY, nX and nY (as PSFRNGDX, PSFRNGDY, PSFRNGNX, PSFRNGNY) from the
00063 /// fringe regions, while the fringe coordinates and mask are written as a FITS table (as x, y, mask).
00064 bool pmFringeRegionsWriteFits(psFits *fits, ///< Output FITS file
00065                               psMetadata *header, ///< Additional headers to write, or NULL
00066                               const pmFringeRegions *regions, ///< Regions to write
00067                               const char *extname ///< Extension name, or NULL
00068                              );
00069 
00070 /// Read the regions from a FITS file
00071 ///
00072 /// The fringe regions are read from the FITS file, at the given extension name.  The scalars are retrieved
00073 /// from the header, while the table provides the fringe coordinates and mask.
00074 pmFringeRegions *pmFringeRegionsReadFits(psMetadata *header, ///< Header to read, or NULL
00075         const psFits *fits, ///< Input FITS file
00076         const char *extname ///< Extension name, or NULL
00077                                         );
00078 
00079 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00080 // pmFringeStats
00081 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00082 
00083 /// Fringe measurements for a particular image
00084 ///
00085 /// Measurements of the median and stdev are made at each of the fringe regions.
00086 typedef struct
00087 {
00088     pmFringeRegions *regions;           ///< Fringe regions
00089     psVector *f;                        ///< Fringe point median
00090     psVector *df;                       ///< Fringe point stdev
00091 }
00092 pmFringeStats;
00093 
00094 /// Allocate fringe statistics
00095 pmFringeStats *pmFringeStatsAlloc(pmFringeRegions *regions // The fringe regions which will be measured
00096                                  );
00097 
00098 /// Measure the fringe statistics for an image
00099 ///
00100 /// Given an input image and fringe regions at which to measure, measures the median and stdev at each of the
00101 /// fringe points.  If the fringe points are undefined, they are generated.
00102 pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, ///< Fringe regions at which to measure
00103                                     const pmReadout *readout, ///< Readout for which to measure
00104                                     psMaskType maskVal ///< Mask value for image
00105                                    );
00106 
00107 /// Write the fringe stats for an image to a FITS table
00108 ///
00109 /// The fringe measurements are written to the FITS file with the given extension name.  The median and stdev
00110 /// measurements are written as a FITS table (as f and df).
00111 bool pmFringeStatsWriteFits(psFits *fits, ///< FITS file to which to write
00112                             psMetadata *header, ///< Additional headers to write, or NULL
00113                             const pmFringeStats *fringe, ///< Fringe statistics to be written
00114                             const char *extname ///< Extension name for table
00115                            );
00116 
00117 /// Read the fringe stats for an image from a FITS table
00118 ///
00119 /// The fringe measurements are read from the FITS file, at the given extension name.  The table provides the
00120 /// median and stdev measurements.  It is assumed that the fringe measurements correspond to the regions
00121 /// provided.
00122 pmFringeStats *pmFringeStatsReadFits(psMetadata *header, ///< Header to read, or NULL
00123                                      const psFits *fits, ///< FITS file from which to read
00124                                      const char *extname, ///< Extension name to read
00125                                      pmFringeRegions *regions ///< Corresponding regions
00126                                     );
00127 
00128 /// Concatenate the fringe stats for several readouts into a single fringe stats.
00129 ///
00130 /// Each readout of each chip must be measured separately (so as to avoid any gaps between the cells, as in
00131 /// the case for GPC).  But the fit must be performed with all the readouts belonging to a chip (in order to
00132 /// get a secure measurement of the fringe amplitudes).  To do so, we need to concatenate the fringe
00133 /// measurements for each of the chip components.  This function generates a new pmFringeStats from
00134 /// concatenating those in the array.  The corresponding pmFringeRegions is also generated.
00135 pmFringeStats *pmFringeStatsConcatenate(const psArray *fringes, ///< Array of pmFringeStats for the readouts
00136                                         const psVector *x0, ///< Offset in x for the readout
00137                                         const psVector *y0 ///< Offset in y for the readout
00138                                        );
00139 
00140 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00141 // Input/output for multiple pmFringeStats
00142 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00143 
00144 /// Write an array of fringes measurements to a FITS table.
00145 ///
00146 /// Writes an array of fringe measurements for a cell as a FITS table in the analysis metadata.  The array of
00147 /// fringe statistics must all use the same fringe regions (or there is no point in storing them all
00148 /// together).  The header is supplemented with scalar values dX, dY, nX and nY (as PSFRNGDX, PSFRNGDY,
00149 /// PSFRNGNX, PSFRNGNY) from the fringe regions, while the fringe coordinates and mask are written as a FITS
00150 /// table (as x, y, mask, f, df; f and df are vectors).
00151 bool pmFringesFormat(pmCell *cell,   ///< Cell for which to write
00152                      psMetadata *header, ///< Header, or NULL
00153                      const psArray *fringes ///< Array of pmFringeStats, all for the same pmFringeRegion
00154                     );
00155 
00156 /// Parses an array of fringes measurements from a FITS table.
00157 ///
00158 /// The fringes for the cell are read from the FITS table in the analysis metadata.  The table provides the
00159 /// region and the (possibly multiple) fringe statistics for that region.  The current extension is used if
00160 /// the extension name is not provided.
00161 psArray *pmFringesParse(pmCell *cell ///< Cell for which to read fringes
00162                        );
00163 
00164 
00165 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00166 // pmFringeScale
00167 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00168 
00169 /// The fringe correction solution
00170 typedef struct
00171 {
00172     int nFringeFrames;                  ///< Number of fringe frames
00173     psVector *coeff;                    ///< Fringe coefficients; size = nFringeFrames
00174     psVector *coeffErr;                 ///< Error in fringe coefficients; size = nFringeFrames
00175 }
00176 pmFringeScale;
00177 
00178 /// Measure the scales for the fringe correction
00179 ///
00180 /// Given a fringe measurement for a science image, and an array of template fringe measurements, this
00181 /// function measures the contribution of each of the templates to the input.  Rejection is performed on the
00182 /// fringe regions, to weed out stars etc.
00183 pmFringeScale *pmFringeScaleMeasure(pmFringeStats *science, ///< Fringe measurements from science image
00184                                     psArray *fringes, ///< Array of fringe measurements from templates
00185                                     float rej, ///< Rejection threshold (in standard deviations)
00186                                     unsigned int nIter, ///< Maximum number of iterations
00187                                     float keepFrac ///< Minimum fraction of regions to keep
00188                                    );
00189 
00190 /// Allocate fringe scales
00191 pmFringeScale *pmFringeScaleAlloc(int nFringeFrames ///< Number of fringe frames
00192                                  );
00193 
00194 
00195 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00196 // Fringe correction
00197 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00198 
00199 /// Solve for and apply the fringe correction
00200 ///
00201 /// This is a wrapper around each of the fringe correction components to measure the fringe points, solve for
00202 /// the fringe correction, and apply the fringe correction.  The input fringe images are modified (scaled by
00203 /// the solution coefficients in order to correct the science image).  Returns the summed fringe image.
00204 psImage *pmFringeCorrect(pmReadout *in, ///< Input science image
00205                          pmFringeRegions *fringes, ///< The fringe regions used
00206                          psArray *fringeImages, ///< Fringe template images to use in correction
00207                          psArray *fringeStats, ///< Fringe stats (for templates) to use in correction
00208                          psMaskType maskVal, ///< Value to mask for science image
00209                          float rej,     ///< Rejection threshold, for pmFringeScaleMeasure
00210                          unsigned int nIter, ///< Maximum number of iterations, for pmFringeScaleMeasure
00211                          float keepFrac ///< Minimum fraction of regions to keep, for pmFringeScaleMeasure
00212                         );
00213 /// @}
00214 #endif

Generated on Fri Feb 2 22:35:28 2007 for Pan-STARRS Module Library by  doxygen 1.5.1