/* @file  pmStack.h
 *
 * This file will perform image combination of several images of the
 * same field, produce a list of questionable pixels, then tag some
 * of those pixels as defects.
 *
 * @author Paul Price, IfA
 * @author GLG, MHPCC
 *
 * @version $Revision: 1.9.8.1 $ $Name: not supported by cvs2svn $
 * @date $Date: 2009-01-02 05:13:00 $
 *
 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii
 */

#ifndef PM_STACK_H
#define PM_STACK_H

#include <pslib.h>
#include <pmHDU.h>
#include <pmFPA.h>

/// @addtogroup imcombine Image Combinations
/// @{


/// Container for input image
typedef struct {
    pmReadout *readout;                 ///< Warped readout (sky cell)
    psPixels *reject;                   ///< Pixels to reject
    psPixels *inspect;                  ///< Pixels to inspect
    float weight;                       ///< Relative weighting for image
    float addVariance;                  ///< Additional variance when rejecting
} pmStackData;

/// Constructor
pmStackData *pmStackDataAlloc(pmReadout *readout, ///< Warped readout (sky cell)
                              float weight, ///< Weight to apply
                              float addVariance ///< Additional variance when rejecting
    );

/// Stack input images
bool pmStackCombine(pmReadout *combined,///< Combined readout (output)
                    psArray *input,     ///< Input array of pmStackData
                    psImageMaskType maskVal, ///< Mask value of bad pixels
                    psImageMaskType bad,     ///< Mask value to give rejected pixels
                    int kernelSize,     ///< Half-size of the convolution kernel
                    int numIter,        ///< Number of iterations
                    float rej,          ///< Rejection limit (standard deviations)
                    float sys,          ///< Relative systematic error
                    bool entire,        ///< Combine entire image even if rejection lists provided?
                    bool useVariance,   ///< Use variance values for rejection?
                    bool safe           ///< Play safe with small numbers of input pixels (mask if N <= 2)?
    );

/// @}
#endif
