Index: trunk/psModules/src/imcombine/pmSubtractionStamps.h
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionStamps.h	(revision 26035)
+++ trunk/psModules/src/imcombine/pmSubtractionStamps.h	(revision 26893)
@@ -24,14 +24,21 @@
     psArray *flux;                      ///< Fluxes for possible stamps (or NULL)
     int footprint;                      ///< Half-size of stamps
+    psKernel *window;                   ///< window function generated from ensemble of stamps
+    float normFrac;                     ///< Fraction of flux in window for normalisation window
+    int normWindow;                     ///< Size of window for measuring normalisation
     float sysErr;                       ///< Systematic error
+    float skyErr;                       ///< increase effective readnoise
 } pmSubtractionStampList;
 
 /// Allocate a list of stamps
-pmSubtractionStampList *pmSubtractionStampListAlloc(int numCols, // Number of columns in image
-                                                    int numRows, // Number of rows in image
-                                                    const psRegion *region, // Region for stamps, or NULL
-                                                    int footprint, // Half-size of stamps
-                                                    float spacing, // Rough average spacing between stamps
-                                                    float sysErr  // Relative systematic error or NAN
+pmSubtractionStampList *pmSubtractionStampListAlloc(
+    int numCols, // Number of columns in image
+    int numRows, // Number of rows in image
+    const psRegion *region, // Region for stamps, or NULL
+    int footprint, // Half-size of stamps
+    float spacing, // Rough average spacing between stamps
+    float normFrac, // Fraction of flux in window for normalisation window
+    float sysErr,  // Relative systematic error or NAN
+    float skyErr  // Relative systematic error or NAN
     );
 
@@ -73,7 +80,7 @@
     psArray *convolutions1;             ///< Convolutions of image 1 for each kernel component, or NULL
     psArray *convolutions2;             ///< Convolutions of image 2 for each kernel component, or NULL
-    psImage *matrix1, *matrix2;         ///< Least-squares matrices for each image, or NULL
-    psImage *matrixX;                   ///< Cross-matrix (for mode DUAL), or NULL
-    psVector *vector1, *vector2;        ///< Least-squares vectors for each image, or NULL
+    psImage *matrix;                    ///< Least-squares matrix, or NULL
+    psVector *vector;                   ///< Least-squares vector, or NULL
+    double norm;                        ///< Normalisation difference
     pmSubtractionStampStatus status;    ///< Status of stamp
 } pmSubtractionStamp;
@@ -83,29 +90,35 @@
 
 /// Find stamps on an image
-pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, ///< Output stamps, or NULL
-                                                const psImage *image1, ///< Image for which to find stamps
-                                                const psImage *image2, ///< Image for which to find stamps
-                                                const psImage *mask, ///< Mask, or NULL
-                                                const psRegion *region, ///< Region to search, or NULL
-                                                float thresh1, ///< Threshold for stamps in image 1
-                                                float thresh2, ///< Threshold for stamps in image 2
-                                                int size, ///< Kernel half-size
-                                                int footprint, ///< Half-size for stamps
-                                                float spacing, ///< Rough spacing for stamps
-                                                float sysErr,  ///< Relative systematic error in images
-                                                pmSubtractionMode mode ///< Mode for subtraction
+pmSubtractionStampList *pmSubtractionStampsFind(
+    pmSubtractionStampList *stamps, ///< Output stamps, or NULL
+    const psImage *image1, ///< Image for which to find stamps
+    const psImage *image2, ///< Image for which to find stamps
+    const psImage *mask, ///< Mask, or NULL
+    const psRegion *region, ///< Region to search, or NULL
+    float thresh1, ///< Threshold for stamps in image 1
+    float thresh2, ///< Threshold for stamps in image 2
+    int size, ///< Kernel half-size
+    int footprint, ///< Half-size for stamps
+    float spacing, ///< Rough spacing for stamps
+    float normFrac, // Fraction of flux in window for normalisation window
+    float sysErr,  ///< Relative systematic error in images
+    float skyErr,  ///< Relative systematic error in images
+    pmSubtractionMode mode ///< Mode for subtraction
     );
 
 /// Set stamps based on a list of x,y
-pmSubtractionStampList *pmSubtractionStampsSet(const psVector *x, ///< x coordinates for each stamp
-                                               const psVector *y, ///< y coordinates for each stamp
-                                               const psImage *image, ///< Image for flux of stamp
-                                               const psImage *mask, ///< Mask, or NULL
-                                               const psRegion *region, ///< Region to search, or NULL
-                                               int size, ///< Kernel half-size
-                                               int footprint, ///< Half-size for stamps
-                                               float spacing, ///< Rough spacing for stamps
-                                               float sysErr,  ///< Systematic error in images
-                                               pmSubtractionMode mode ///< Mode for subtraction
+pmSubtractionStampList *pmSubtractionStampsSet(
+    const psVector *x, ///< x coordinates for each stamp
+    const psVector *y, ///< y coordinates for each stamp
+    const psImage *image, ///< Image for flux of stamp
+    const psImage *mask, ///< Mask, or NULL
+    const psRegion *region, ///< Region to search, or NULL
+    int size, ///< Kernel half-size
+    int footprint, ///< Half-size for stamps
+    float spacing, ///< Rough spacing for stamps
+    float normFrac, // Fraction of flux in window for normalisation window
+    float sysErr,  ///< Systematic error in images
+    float skyErr,  ///< Systematic error in images
+    pmSubtractionMode mode ///< Mode for subtraction
     );
 
@@ -119,5 +132,7 @@
     int footprint,                      ///< Half-size for stamps
     float spacing,                      ///< Rough spacing for stamps
+    float normFrac, // Fraction of flux in window for normalisation window
     float sysErr,                       ///< Systematic error in images
+    float skyErr,                       ///< Systematic error in images
     pmSubtractionMode mode              ///< Mode for subtraction
     );
@@ -132,6 +147,14 @@
     int footprint,                      ///< Half-size for stamps
     float spacing,                      ///< Rough spacing for stamps
+    float normFrac, // Fraction of flux in window for normalisation window
     float sysErr,                       ///< Systematic error in images
+    float skyErr,                       ///< Systematic error in images
     pmSubtractionMode mode              ///< Mode for subtraction
+    );
+
+/// Calculate the window and normalisation window from the stamps
+bool pmSubtractionStampsGetWindow(
+    pmSubtractionStampList *stamps,     ///< List of stamps
+    int kernelSize                      ///< Half-size of kernel
     );
 
@@ -141,5 +164,6 @@
                                 psImage *image2, ///< Input image (or NULL)
                                 psImage *variance, ///< Variance map
-                                int kernelSize ///< Kernel half-size
+                                int kernelSize, ///< Kernel half-size
+                                psRegion bounds ///< Bounds of validity
     );
 
@@ -168,3 +192,6 @@
     );
 
+
+bool pmSubtractionStampsResetStatus (pmSubtractionStampList *stamps);
+
 #endif
