Index: /branches/eam_branches/ohana.20190329/src/opihi/cmd.data/medimage_commands.c
===================================================================
--- /branches/eam_branches/ohana.20190329/src/opihi/cmd.data/medimage_commands.c	(revision 40754)
+++ /branches/eam_branches/ohana.20190329/src/opihi/cmd.data/medimage_commands.c	(revision 40755)
@@ -22,14 +22,14 @@
   int N;
   Buffer *image;
-  Buffer *sig = NULL;
-
-  if ((N = get_argument (argc, argv, "-sigma"))) {
-    remove_argument (N, &argc, argv);
-    if ((sig = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  Buffer *var = NULL;
+
+  if ((N = get_argument (argc, argv, "-variance"))) {
+    remove_argument (N, &argc, argv);
+    if ((var = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE);
     remove_argument (N, &argc, argv);
   }
 
   if (argc != 3) {
-    gprint (GP_ERR, "USAGE: medimage add (name) (image) [-sigma sigma]\n");
+    gprint (GP_ERR, "USAGE: medimage add (name) (image) [-variance variance]\n");
     gprint (GP_ERR, "       add the given image to the set of images to be medianed\n");
     gprint (GP_ERR, "       optionally supply variance image (for weighted calculations)\n");
@@ -39,8 +39,8 @@
   if ((image = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE);
 
-  if (sig) {
-    if ((sig->matrix.Naxis[0] != image->matrix.Naxis[0]) ||
-	(sig->matrix.Naxis[1] != image->matrix.Naxis[1])) {
-      gprint (GP_ERR, "sigma buffer does not match image buffer dimensions\n");
+  if (var) {
+    if ((var->matrix.Naxis[0] != image->matrix.Naxis[0]) ||
+	(var->matrix.Naxis[1] != image->matrix.Naxis[1])) {
+      gprint (GP_ERR, "variance buffer does not match image buffer dimensions\n");
       return FALSE;
     }
@@ -68,17 +68,17 @@
   // new image should match existing medimage dimensions
 
-  // AddMedImage (median, image, sig);
+  // AddMedImage (median, image, var);
   int Ninput = median->Ninput;
   median->Ninput ++;
   REALLOCATE (median->flx, float *, median->Ninput);
-  REALLOCATE (median->sig, float *, median->Ninput);
+  REALLOCATE (median->var, float *, median->Ninput);
 
   ALLOCATE (median->flx[Ninput], float, median->Nx*median->Ny);
   memcpy (median->flx[Ninput], image->matrix.buffer, sizeof(float)*median->Nx*median->Ny);
 
-  median->sig[Ninput] = NULL;
-  if (sig) {
-    ALLOCATE (median->sig[Ninput], float, median->Nx*median->Ny);
-    memcpy (median->sig[Ninput], sig->matrix.buffer, sizeof(float)*median->Nx*median->Ny);
+  median->var[Ninput] = NULL;
+  if (var) {
+    ALLOCATE (median->var[Ninput], float, median->Nx*median->Ny);
+    memcpy (median->var[Ninput], var->matrix.buffer, sizeof(float)*median->Nx*median->Ny);
   }
 
@@ -105,4 +105,11 @@
     if (mode != CALC_MEDIAN) { gprint (GP_ERR, "supply only one of -mean, -irls, -wtmean\n"); return FALSE; }
     mode = CALC_WTMEAN;
+    remove_argument (N, &argc, argv);
+  }
+
+  Buffer *variance = NULL;
+  if ((N = get_argument (argc, argv, "-variance"))) {
+    remove_argument (N, &argc, argv);
+    if ((variance = SelectBuffer (argv[N], ANYBUFFER, TRUE)) == NULL) return (FALSE);
     remove_argument (N, &argc, argv);
   }
@@ -145,9 +152,9 @@
 	val[N] = v;
 	wgt[N] = 1.0;
-	if (median->sig[n]) {
-	  float s = median->sig[n][Npix];
+	if (median->var[n]) {
+	  float s = median->var[n][Npix];
 	  if (!isfinite(s)) continue;
 	  if (fabs(s) < 2*FLT_MIN) s = 2*FLT_MIN;
-	  wgt[N] = 1.0 / SQ(s);
+	  wgt[N] = 1.0 / s;
 	}
 	N++;
Index: /branches/eam_branches/ohana.20190329/src/opihi/include/data.h
===================================================================
--- /branches/eam_branches/ohana.20190329/src/opihi/include/data.h	(revision 40754)
+++ /branches/eam_branches/ohana.20190329/src/opihi/include/data.h	(revision 40755)
@@ -49,5 +49,5 @@
   int Ny;
   float **flx;
-  float **sig;
+  float **var;
 } MedImageType;
 
Index: /branches/eam_branches/ohana.20190329/src/opihi/lib.data/MedImageOps.c
===================================================================
--- /branches/eam_branches/ohana.20190329/src/opihi/lib.data/MedImageOps.c	(revision 40754)
+++ /branches/eam_branches/ohana.20190329/src/opihi/lib.data/MedImageOps.c	(revision 40755)
@@ -33,8 +33,8 @@
   for (i = 0; i < medimage[0].Ninput; i++) {
     free (medimage[0].flx[i]);
-    FREE (medimage[0].sig[i]);
+    FREE (medimage[0].var[i]);
   }
   free (medimage[0].flx);
-  free (medimage[0].sig);
+  free (medimage[0].var);
   free (medimage);
 }
@@ -78,5 +78,5 @@
   medimage->Ny = Ny;
   ALLOCATE (medimage->flx, float *, 1);
-  ALLOCATE (medimage->sig, float *, 1);
+  ALLOCATE (medimage->var, float *, 1);
 
   medimages[N] = medimage;
Index: /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitprofile.c
===================================================================
--- /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitprofile.c	(revision 40754)
+++ /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitprofile.c	(revision 40755)
@@ -78,18 +78,21 @@
   
   float Sky_V = 0.0, BckL_V = 0.0, BckR_V = 0.0;
-  int Sky_N = 0, BckL_N = 0, BckR_N = 0;
+  float Sky_N = 0.0, BckL_N = 0.0, BckR_N = 0.0;
   for (int i = 0; i < xprofile->Nelements; i++) {
+    if (!isfinite(wprofile->elements.Flt[i])) continue;
+    if (!isfinite(fprofile->elements.Flt[i])) continue;
+    float wt = 1 / SQ(wprofile->elements.Flt[i]);
     if (xprofile->elements.Flt[i] < Xs) {
-      BckL_V += fprofile->elements.Flt[i];
-      BckL_N ++;
+      BckL_V += fprofile->elements.Flt[i]*wt;
+      BckL_N += wt;
       continue;
     }
     if (xprofile->elements.Flt[i] > Xe) {
-      BckR_V += fprofile->elements.Flt[i];
-      BckR_N ++;
+      BckR_V += fprofile->elements.Flt[i]*wt;
+      BckR_N += wt;
       continue;
     }
-    Sky_V += fprofile->elements.Flt[i];
-    Sky_N ++;
+    Sky_V += fprofile->elements.Flt[i]*wt;
+    Sky_N += wt;
   }
   float Sky = Sky_V / Sky_N;
@@ -211,4 +214,6 @@
   int Npts = 0;
   for (int i = 0; i < NptsAll; i++) {
+    if (!isfinite(wprofile[i])) continue;
+    if (!isfinite(fprofile[i])) continue;
     int keep = (mode == MODE_UPPER) ^ (xprofile[i] < limit);
     if (keep) {
Index: /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_mkslit.c
===================================================================
--- /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_mkslit.c	(revision 40754)
+++ /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_mkslit.c	(revision 40755)
@@ -7,14 +7,21 @@
   // input parameters:
   //   slit profile response : vector of fractional flux vs x-coord
-  //   trace                 : spline fit of slit central x pos vs y-coord
-  //   flux                  : vector of input signal vs y-coord
+  //   trace_ref,trace_blu   : spline fit of slit central x pos vs y-coord
+  //   flux (optional)       : vector of input signal vs y-coord
+  //   sky  (optional)       : vector of input signal vs y-coord
+  //   fluxbins (optional)   : size of output image in y-direction
+  //   NOTE: one of flux, sky, or fluxbins must be defined
+
+  // output : buff (an image with Nx defined by profile and Ny defined
+  //                by flux, sky, or fluxbins)
 
   int N;
 
-  Vector *profile = NULL;
-  Vector *flux    = NULL;
-  Vector *sky     = NULL;
-  Spline *trace   = NULL;
-  Buffer *buff    = NULL;
+  Vector *profile   = NULL;
+  Vector *flux      = NULL;
+  Vector *sky       = NULL;
+  Spline *trace_red = NULL;
+  Spline *trace_blu = NULL;
+  Buffer *buff      = NULL;
 
   // user-specified flux value (otherwise assumed to be 1)
@@ -40,6 +47,16 @@
   }
 
-  if (argc != 4) {
-    gprint (GP_ERR, "USAGE: deimos mkslit (profile) (trace) (buffer) [-flux vector] [-fluxbins N] [-sky vector]\n");
+  // for a red vs blu spline, we need to specify the split point
+  // XXX this is REALLY ad-hoc for Deimos.  not sure how to make
+  // this more generic (need to define the ranges somewhere)
+  int redlimit = 4096;
+  if ((N = get_argument (argc, argv, "-redlimit"))) {
+    remove_argument (N, &argc, argv);
+    redlimit = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 5) {
+    gprint (GP_ERR, "USAGE: deimos mkslit (profile) (trace_red) (trace_blu) (buffer) [-flux vector] [-fluxbins N] [-sky vector]\n");
     return FALSE;
   }
@@ -51,7 +68,8 @@
 
   // XXX I probably should rename FindSpline as SelectSpline and give it the same behavior
-  if ((profile = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
-  if ((trace   = FindSpline (argv[2])) == NULL) return (FALSE);
-  if ((buff    = SelectBuffer (argv[3], ANYBUFFER, TRUE)) == NULL) return (FALSE);
+  if ((profile   = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((trace_red = FindSpline (argv[2])) == NULL) return (FALSE);
+  if ((trace_blu = FindSpline (argv[3])) == NULL) return (FALSE);
+  if ((buff      = SelectBuffer (argv[4], ANYBUFFER, TRUE)) == NULL) return (FALSE);
 
   // define the output window
@@ -73,4 +91,5 @@
 
     // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center
+    Spline *trace = (iy < redlimit) ? trace_red : trace_blu;
     float dx = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy);
     
