Index: trunk/psModules/src/camera/pmFPAMaskWeight.c
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 26076)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 26893)
@@ -370,8 +370,34 @@
 
     psImage *image = readout->image, *mask = readout->mask, *variance = readout->variance; // Readout parts
-
     int numCols = image->numCols, numRows = image->numRows; // Size of image
-    int numPix = numCols * numRows;                         // Number of pixels
-    int num = PS_MAX(sample, numPix);                       // Number we care about
+
+    int xMin, xMax, yMin, yMax;         // Bounds of image
+    if (mask) {
+        xMin = numCols;
+        xMax = 0;
+        yMin = numRows;
+        yMax = 0;
+        for (int y = 0; y < numRows; y++) {
+            for (int x = 0; x < numCols; x++) {
+                if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
+                    continue;
+                }
+                xMin = PS_MIN(xMin, x);
+                xMax = PS_MAX(xMax, x);
+                yMin = PS_MIN(yMin, y);
+                yMax = PS_MAX(yMax, y);
+            }
+        }
+    } else {
+        xMin = 0;
+        xMax = numCols;
+        yMin = 0;
+        yMax = numRows;
+    }
+
+    int xNum = xMax - xMin, yNum = yMax - yMin; // Number of pixels
+
+    int numPix = xNum * yNum;                                  // Number of pixels
+    int num = PS_MIN(sample, numPix);                          // Number we care about
     psVector *signoise = psVectorAllocEmpty(num, PS_TYPE_F32);   // Signal-to-noise values
 
@@ -379,6 +405,6 @@
         // We have an image smaller than Nsubset, so just loop over the image pixels
         int index = 0;                  // Index for vector
-        for (int y = 0; y < numRows; y++) {
-            for (int x = 0; x < numCols; x++) {
+        for (int y = yMin; y < yMax; y++) {
+            for (int x = xMin; x < xMax; x++) {
                 if ((mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) ||
                     !isfinite(image->data.F32[y][x]) || !isfinite(variance->data.F32[y][x])) {
@@ -397,6 +423,6 @@
             // Pixel coordinates
             int pixel = numPix * psRandomUniform(rng);
-            int x = pixel % numCols;
-            int y = pixel / numCols;
+            int x = xMin + pixel % xNum;
+            int y = yMin + pixel / xNum;
 
             if ((mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) ||
@@ -428,10 +454,12 @@
     // Check valid range of correction factor
     if ((isfinite(minValid) && correction < minValid) || (isfinite(maxValid) && correction > maxValid)) {
-        psWarning("Variance renormalisation is outside valid range: %f vs %f:%f --- no correction made",
-                  correction, minValid, maxValid);
-        return true;
-    }
-
-    psBinaryOp(variance, variance, "*", psScalarAlloc(PS_SQR(correction), PS_TYPE_F32));
+	psError(PS_ERR_UNKNOWN, true, "Variance renormalisation is outside valid range: %f vs %f:%f --- no correction made", correction, minValid, maxValid);
+	psMetadataAddF32(readout->analysis, PS_LIST_TAIL, PM_READOUT_ANALYSIS_RENORM, 0, "Renormalisation of variance", PS_SQR(correction));
+        return false;
+    }
+
+    psImage *subImage = psImageSubset(variance, psRegionSet(xMin, xMax, yMin, yMax)); // Smaller image
+    psBinaryOp(subImage, subImage, "*", psScalarAlloc(PS_SQR(correction), PS_TYPE_F32));
+    psFree(subImage);
 
     pmHDU *hdu = pmHDUFromReadout(readout); // HDU for readout
