Index: /branches/eam_branches/ipp-20150625/Ohana/src/libdvo/include/libdvo_astro.h
===================================================================
--- /branches/eam_branches/ipp-20150625/Ohana/src/libdvo/include/libdvo_astro.h	(revision 38697)
+++ /branches/eam_branches/ipp-20150625/Ohana/src/libdvo/include/libdvo_astro.h	(revision 38698)
@@ -170,5 +170,5 @@
 /* in AstromOffsetMapOps.c */
 float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir);
-int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
+int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir);
 
 /* in AstromOffsetMapUtils.c */
Index: /branches/eam_branches/ipp-20150625/Ohana/src/libdvo/src/AstromOffsetMapOps.c
===================================================================
--- /branches/eam_branches/ipp-20150625/Ohana/src/libdvo/src/AstromOffsetMapOps.c	(revision 38697)
+++ /branches/eam_branches/ipp-20150625/Ohana/src/libdvo/src/AstromOffsetMapOps.c	(revision 38698)
@@ -6,5 +6,5 @@
 int dump_map_data (float *x, float *y, float *f, int Npts, char *filename);
 int AstromOffsetMapFit_Chisq (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
-int AstromOffsetMapFit_Median (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
+int AstromOffsetMapFit_Mean (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir);
 
 float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir) {
@@ -68,7 +68,7 @@
 }
 
-int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
-
-  int status = AstromOffsetMapFit_Median (map, x, y, f, Npts, xdir);
+int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir) {
+
+  int status = AstromOffsetMapFit_Mean (map, x, y, f, df, Npts, xdir);
   return status;
 }
@@ -374,5 +374,5 @@
 // given (x,y),value vector sets, choose the map that minimizes the difference between 
 // the values and bilinear interpolation of the map
-int AstromOffsetMapFit_Median (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
+int AstromOffsetMapFit_Mean (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir) {
 
   int i, ix, iy;
@@ -389,10 +389,12 @@
   int Npix = Nx*Ny;
 
-  double **values;
+  double **values, **dvalues;
   int    *Nvalue;
   ALLOCATE (Nvalue, int, Npix);
   ALLOCATE (values, double *, Npix);
+  ALLOCATE (dvalues, double *, Npix);
   for (i = 0; i < Npix; i++) {
     ALLOCATE (values[i], double, Npts);
+    ALLOCATE (dvalues[i], double, Npts);
     Nvalue[i] = 0;
   }
@@ -403,4 +405,6 @@
     // data value & weight for this point
     if (!isfinite(f[i])) continue;
+    if (!isfinite(df[i])) continue;
+    if (df[i] == 0.0) continue;
 
     // if (mask && (mask[i] & maskValue)) continue;
@@ -417,4 +421,5 @@
     int N = Nvalue[I];
     values[I][N] = f[i];
+    dvalues[I][N] = df[i];
     Nvalue[I] ++;
   }    
@@ -424,5 +429,5 @@
       int I = ix + Nx * iy;
       if (Nvalue[I] > 5) {
-	vstats_getstats (values[I], NULL, NULL, Nvalue[I], &stats);
+	vstats_getstats (values[I], dvalues[I], NULL, Nvalue[I], &stats);
 	Vptr[I] = stats.mean;
       } else {
@@ -435,6 +440,8 @@
   for (i = 0; i < Npix; i++) {
     free (values[i]);
+    free (dvalues[i]);
   }    
   free (values);
+  free (dvalues);
   free (Nvalue);
 
