Index: /branches/rel10_ifa/psModules/src/astrom/Makefile.am
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/Makefile.am	(revision 6585)
+++ /branches/rel10_ifa/psModules/src/astrom/Makefile.am	(revision 6586)
@@ -6,4 +6,5 @@
 	pmFPA.c \
 	pmFPAConstruct.c \
+	pmFPAMaskWeight.c \
 	pmFPARead.c \
 	pmHDU.c \
@@ -26,4 +27,5 @@
 	pmFPA.h \
 	pmFPAConstruct.h \
+	pmFPAMaskWeight.h \
 	pmFPARead.h \
 	pmHDU.h \
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPA.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPA.c	(revision 6585)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPA.c	(revision 6586)
@@ -12,6 +12,6 @@
 * XXX: Should we implement non-linear cell->chip transforms?
 *
-*  @version $Revision: 1.1.4.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-03-09 03:08:08 $
+*  @version $Revision: 1.1.4.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-15 02:37:16 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -601,86 +601,3 @@
 }
 
-#if 0
-bool pmCellSetWeights(pmCell *cell // Cell for which to set weights
-                     )
-{
-    float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); // Cell gain
-    float readnoise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); // Cell read noise
-    psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); // Trim section
-    float saturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION"); // Saturation level
-    float bad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD"); // Bad level
-
-    pmHDU *hdu = cell->hdu;             // The data unit, containing the weight and mask originals
-    if (!hdu) {
-        pmChip *chip = cell->parent;    // The parent chip
-        if (chip->hdu) {
-            hdu = chip->hdu;
-        } else {
-            pmFPA *fpa = chip->parent;  // The parent FPA
-            hdu = fpa->hdu;
-            if (!hdu) {
-                psError(PS_ERR_UNKNOWN, true, "Unable to find the HDU in the hierarchy!\n");
-                return false;
-            }
-        }
-    }
-
-    psArray *pixels = hdu->images;      // Array of images
-    psArray *weights = hdu->weights;    // Array of weight images
-    psArray *masks = hdu->masks;        // Array of mask images
-    // Generate the weights and masks if required
-    if (! weights) {
-        weights = psArrayAlloc(pixels->n);
-        for (int i = 0; i < pixels->n; i++) {
-            psImage *image = pixels->data[i];
-            weights->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32);
-            psImageInit(weights->data[i], 0.0);
-        }
-        hdu->weights = weights;
-    }
-    if (! masks) {
-        masks = psArrayAlloc(pixels->n);
-        for (int i = 0; i < pixels->n; i++) {
-            psImage *image = pixels->data[i];
-            masks->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8);
-            psImageInit(masks->data[i], 0);
-        }
-        hdu->masks = masks;
-    }
-
-    // Set the pixels
-    psArray *readouts = cell->readouts; // Array of readouts
-    for (int i = 0; i < readouts->n; i++) {
-        pmReadout *readout = readouts->data[i]; // The readout of interest
-
-        if (! readout->weight) {
-            readout->weight = psMemIncrRefCounter(psImageSubset(weights->data[i], *trimsec));
-        }
-        if (! readout->mask) {
-            readout->mask = psMemIncrRefCounter(psImageSubset(masks->data[i], *trimsec));
-        }
-
-        // Set up the mask
-        psImage *image = readout->image;// Pixels
-        psImage *mask = readout->mask;  // Mask image
-        for (int i = 0; i < image->numRows; i++) {
-            for (int j = 0; j < image->numCols; j++) {
-                if (image->data.F32[i][j] > saturation) {
-                    mask->data.U8[i][j] = PM_MASK_SAT;
-                }
-                if (image->data.F32[i][j] < bad) {
-                    mask->data.U8[i][j] = PM_MASK_BAD;
-                }
-            }
-        }
-
-        // Set weight image to the variance = g*f + rn^2
-        psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32));
-        psBinaryOp(readout->weight, readout->weight, "+",
-                   psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
-    }
-
-    return true;
-}
-
-#endif
+
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAMaskWeight.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAMaskWeight.c	(revision 6586)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAMaskWeight.c	(revision 6586)
@@ -0,0 +1,101 @@
+#include <stdio.h>
+#include "pslib.h"
+#include "pmFPA.h"
+#include "pmFPAMaskWeight.h"
+
+bool pmReadoutSetMask(pmReadout *readout // Readout for which to set mask
+                     )
+{
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+
+    pmCell *cell = readout->parent;     // The parent cell
+    bool mdok = true;                   // Status of MD lookup
+
+    // Get the "concepts" of interest
+    float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level
+    if (!mdok || isnan(saturation)) {
+        psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n");
+        return false;
+    }
+    float bad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD"); // Bad level
+    if (!mdok || isnan(bad)) {
+        psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n");
+        return false;
+    }
+
+    psImage *image = readout->image;    // The image pixels
+    psImage *mask = readout->mask;      // The mask pixels
+    if (!mask) {
+        mask = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8);
+        readout->mask = mask;
+        psImageInit(mask, 0);
+    }
+
+    // Set up the mask
+    for (int i = 0; i < image->numRows; i++) {
+        for (int j = 0; j < image->numCols; j++) {
+            if (image->data.F32[i][j] > saturation) {
+                mask->data.U8[i][j] |= PM_MASK_SAT;
+            }
+            if (image->data.F32[i][j] < bad) {
+                mask->data.U8[i][j] |= PM_MASK_BAD;
+            }
+        }
+    }
+
+    return true;
+}
+
+bool pmReadoutSetWeight(pmReadout *readout // Readout for which to set weight
+                       )
+{
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+
+    pmCell *cell = readout->parent;     // The parent cell
+    bool mdok = true;                   // Status of MD lookup
+
+    // Get the "concepts" of interest
+    float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain
+    if (!mdok || isnan(gain)) {
+        psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set weight.\n");
+        return false;
+    }
+    float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise
+    if (!mdok || isnan(readnoise)) {
+        psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set weight.\n");
+        return false;
+    }
+
+    psImage *image = readout->image;    // The image pixels
+    psImage *weight = readout->weight;  // The weight pixels
+    if (!weight) {
+        weight = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32);
+        readout->weight = weight;
+        psImageInit(weight, 0.0);
+    }
+
+    // Set weight image to the variance in ADU = f/g + rn^2
+    psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32));
+    psBinaryOp(readout->weight, readout->weight, "+",
+               psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
+
+    return true;
+}
+
+
+
+bool pmCellSetMaskWeight(pmCell *cell // Cell for which to set weights
+                        )
+{
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+
+    bool success = true;                // Was everything successful?
+    psArray *readouts = cell->readouts; // Array of readouts
+    for (int i = 0; i < readouts->n; i++) {
+        pmReadout *readout = readouts->data[i]; // The readout
+        success |= pmReadoutSetMask(readout);
+        success |= pmReadoutSetWeight(readout);
+    }
+
+    return success;
+}
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAMaskWeight.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAMaskWeight.h	(revision 6586)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAMaskWeight.h	(revision 6586)
@@ -0,0 +1,23 @@
+#ifndef PM_READOUT_MASK_WEIGHT_H
+#define PM_READOUT_MASK_WEIGHT_H
+
+#include "pmFPA.h"
+
+/** Mask values */
+typedef enum {
+    PM_MASK_TRAP    = 0x0001,   ///< The pixel is a charge trap.
+    PM_MASK_BADCOL  = 0x0002,   ///< The pixel is a bad column.
+    PM_MASK_SAT     = 0x0004,   ///< The pixel is saturated.
+    PM_MASK_BAD     = 0x0008,   ///< The pixel is low
+    PM_MASK_FLAT    = 0x0010    ///< The pixel is non-positive in the flat-field.
+} pmMaskValue;
+
+bool pmReadoutSetMask(pmReadout *readout // Readout for which to set mask
+                     );
+bool pmReadoutSetWeight(pmReadout *readout // Readout for which to set weight
+                       );
+bool pmCellSetMaskWeight(pmCell *cell // Cell for which to set weights
+                        );
+
+
+#endif
