Index: /trunk/psModules/src/concepts/pmConceptsAverage.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsAverage.c	(revision 20595)
+++ /trunk/psModules/src/concepts/pmConceptsAverage.c	(revision 20596)
@@ -102,4 +102,29 @@
 }
 
+float averageWithDropouts (psList *sources, char *name) {
+
+    bool status;
+
+    float sum = 0;
+    int nCells = 0;                     // Number of cells;
+    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
+    pmCell *cell = NULL;                // Source cell from iteration
+    while ((cell = psListGetAndIncrement(sourcesIter))) {
+        if (!cell) {
+            continue;
+        }
+
+	float value = psMetadataLookupF32(&status, cell->concepts, name);
+	if (!status) continue;
+	if (!isfinite(value)) continue;
+
+        sum += value;
+        nCells++;
+    }
+    psFree (sourcesIter);
+
+    float average = sum / nCells;
+    return average;
+}
 
 // Set a variety of concepts in a cell by averaging over several
@@ -111,10 +136,6 @@
     PS_ASSERT_INT_POSITIVE(sources->n, false);
 
-    float gain       = 0.0;             // Gain
-    float readnoise  = 0.0;             // Read noise
     float saturation = INFINITY;        // Saturation level
     float bad        = -INFINITY;       // Bad level
-    float exposure   = 0.0;             // Exposure time
-    float darktime   = 0.0;             // Dark time
     double time      = 0.0;             // Time of observation
     psTimeType timeSys = 0;             // Time system
@@ -124,4 +145,10 @@
     int xParity = 0, yParity = 0;       // Parity
 
+    float gain      = averageWithDropouts (sources, "CELL.GAIN");
+    float readnoise = averageWithDropouts (sources, "CELL.READNOISE");
+    float exposure  = averageWithDropouts (sources, "CELL.EXPOSURE");
+    float darktime  = averageWithDropouts (sources, "CELL.DARKTIME");
+
+    // other concepts are a bit more "special"
     int nCells = 0;                     // Number of cells;
     psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
@@ -133,8 +160,4 @@
 
         nCells++;
-        gain       += psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN");
-        readnoise  += psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE");
-        exposure   += psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE");
-        darktime   += psMetadataLookupF32(NULL, cell->concepts, "CELL.DARKTIME");
         psTime *cellTime = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TIME");
         time       += psTimeToMJD(cellTime);
@@ -200,9 +223,5 @@
     psFree(sourcesIter);
 
-    gain      /= (float)nCells;
-    readnoise /= (float)nCells;
-    exposure  /= (float)nCells;
-    darktime  /= (float)nCells;
-    time      /= (double)nCells;
+    time /= nCells;
 
     MD_UPDATE(target->concepts, "CELL.GAIN", F32, gain);
