Index: /branches/eam_01_branch/psphot/configure.ac
===================================================================
--- /branches/eam_01_branch/psphot/configure.ac	(revision 10280)
+++ /branches/eam_01_branch/psphot/configure.ac	(revision 10281)
@@ -41,4 +41,44 @@
 fi
 
+dnl ------------------ kapa,libkapa options -------------------------
+dnl -- libkapa implies the requirement for libpng, libjpeg as well --
+
+dnl save LIBS/CFLAGS/LDFLAGS
+TMP_LIBS=${LIBS}
+TMP_CFLAGS=${CFLAGS}
+TMP_LDFLAGS=${LDFLAGS}
+TMP_CPPFLAGS=${CPPFLAGS}
+
+AC_ARG_WITH(kapa,
+[AS_HELP_STRING(--with-kapa=DIR,Specify location of libkapa)],
+[KAPA_CFLAGS="-I$withval/include"
+ KAPA_LDFLAGS="-L$withval/lib"])
+AC_ARG_WITH(kapa-include,
+[AS_HELP_STRING(--with-kapa-include=DIR,Specify libkapa include directory.)],
+[KAPA_CFLAGS="-I$withval"])
+AC_ARG_WITH(kapa-lib,
+[AS_HELP_STRING(--with-kapa-lib=DIR,Specify libkapa library directory.)],
+[KAPA_LDFLAGS="-L$withval"])
+
+CFLAGS="${CFLAGS} ${KAPA_CFLAGS}"
+CPPFLAGS=${CFLAGS}
+LDFLAGS="${LDFLAGS} ${KAPA_LIBS}"
+
+AC_CHECK_HEADERS([kapa.h],[],
+  [AC_MSG_ERROR([libkapa headers not found.  Obtain it at http://kiawe.ifa.hawaii.edu/Elixir/Ohana or use --with-kapa to specify location.])]
+)
+AC_CHECK_LIB(kapa,KapaInitGraph,[],
+  [AC_MSG_ERROR([libkapa headers not found.  Obtain it at http://kiawe.ifa.hawaii.edu/Elixir/Ohana or use --with-kapa to specify location.])],[-lm]
+)
+
+AC_SUBST([KAPA_CFLAGS])
+
+dnl restore the CFLAGS/LDFLAGS
+LIBS=${TMP_LIBS}
+CFLAGS=${TMP_CFLAGS}
+LDFLAGS=${TMP_LDFLAGS}
+CPPFLAGS=${TMP_CPPFLAGS}
+
+dnl ------------- psLib, psModules ---------------
 PKG_CHECK_MODULES(PSLIB, pslib >= 0.12.99)
 PKG_CHECK_MODULES(PSMODULE, psmodules >= 0.12.99)
Index: /branches/eam_01_branch/psphot/src/psphotImageMedian.c
===================================================================
--- /branches/eam_01_branch/psphot/src/psphotImageMedian.c	(revision 10280)
+++ /branches/eam_01_branch/psphot/src/psphotImageMedian.c	(revision 10281)
@@ -149,9 +149,10 @@
     stats = psImageStats (stats, model->image, NULL, 0);
     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MEAN", PS_DATA_F32 | PS_META_REPLACE, "sky model mean",          stats->sampleMean);
-    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_STDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev",         stats->sampleStdev);
+    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_STDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev",        stats->sampleStdev);
     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MAX",  PS_DATA_F32 | PS_META_REPLACE, "sky model maximum value", stats->max);
     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MIN",  PS_DATA_F32 | PS_META_REPLACE, "sky model minimum value", stats->min);
     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NX",   PS_DATA_S32 | PS_META_REPLACE, "sky model size (x)",      nx);
     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NY",   PS_DATA_S32 | PS_META_REPLACE, "sky model size (y)",      ny);
+    psLogMsg ("psphot", 3, "background sky : min %f mean %f max %f stdev %f", stats->min, stats->sampleMean, stats->max, stats->sampleStdev);
     psFree (stats);
 
Index: /branches/eam_01_branch/psphot/src/psphotReadout.c
===================================================================
--- /branches/eam_01_branch/psphot/src/psphotReadout.c	(revision 10280)
+++ /branches/eam_01_branch/psphot/src/psphotReadout.c	(revision 10281)
@@ -74,4 +74,7 @@
         return true;
     }
+
+    // XXX test the plotting function
+    psphotPlotMoments (sources);
 
     // psphotTestPSF (readout, sources, recipe);
Index: /branches/eam_01_branch/psphot/src/psphotSummaryPlots.c
===================================================================
--- /branches/eam_01_branch/psphot/src/psphotSummaryPlots.c	(revision 10281)
+++ /branches/eam_01_branch/psphot/src/psphotSummaryPlots.c	(revision 10281)
@@ -0,0 +1,74 @@
+# include "psphot.h"
+
+// plot the sx, sy moments plane (faint and bright sources)
+bool psphotPlotMoments (psArray *sources) {
+
+
+
+  Graphdata graphdata;
+
+  // XXX make -noX an option
+  int kapa = KiiOpen ("kapa", "psphot");
+
+  KapaResize (kapa, 500, 500);
+  KapaInitGraph (&graphdata);
+
+  // examine sources to set data range
+  graphdata.xmin = -0.05;
+  graphdata.ymin = -0.05;
+  graphdata.xmax = +2.05;
+  graphdata.xmin = +2.05;
+  
+  KapaSetFont (kapa, "helvetica", 14);
+  KapaBox (kapa, &graphdata);
+  KapaSendLabel (kapa, "sigma_x|", KAPA_LABEL_XM);
+  KapaSendLabel (kapa, "sigma_y|", KAPA_LABEL_YM);
+	       
+  psVector *xBright = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
+  psVector *yBright = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
+  psVector *xFaint  = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
+  psVector *yFaint  = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
+
+  // construct the vectors
+  int nB = 0;
+  int nF = 0;
+  for (int i = 0; i < sources->n; i++) {
+    pmSource *source = sources->data[i];
+    if (source->moments == NULL) continue;
+    
+    xFaint->data.F32[nF] = source->moments->Sx;
+    yFaint->data.F32[nF] = source->moments->Sy;
+    nF++;
+    
+    // XXX make this a user-defined cutoff
+    if (source->moments->SN < 25) continue;
+
+    xBright->data.F32[nB] = source->moments->Sx;
+    yBright->data.F32[nB] = source->moments->Sy;
+    nB++;
+  }
+  xFaint->n = nF;
+  yFaint->n = nF;
+
+  xBright->n = nB;
+  yBright->n = nB;
+  
+  graphdata.color = KapaColorByName ("black");
+  graphdata.ptype = 0;
+  graphdata.size = 0.3;
+  graphdata.style = 2;
+  KapaPrepPlot (kapa, nF, &graphdata);
+  KapaPlotVector (kapa, nF, xFaint->data.F32);
+  KapaPlotVector (kapa, nF, yFaint->data.F32);
+  
+  graphdata.color = KapaColorByName ("red");
+  graphdata.ptype = 2;
+  graphdata.size = 0.5;
+  graphdata.style = 2;
+  KapaPrepPlot (kapa, nB, &graphdata);
+  KapaPlotVector (kapa, nB, xBright->data.F32);
+  KapaPlotVector (kapa, nB, yBright->data.F32);
+
+  KapaPNG (kapa, "test.png");
+  return true;
+}
