
- select different calibration options
- plot various terms

- rationalize Mmos & Mcal (sum(Mcal) -> Mmos)

- options:

  -update:  update phot database 
  -mosaic:  apply per-mosaic corrections
  -grid:    apply X,Y-based offset
  -chips:   apply per-chip corrections
  -trange:  select images in time range
  

find_images: selects images in region, filtered by photcode, time range

bcatalog:    selects stars & measurments, filtered by mag limit, photcode, time range

image:  a single ccd
mosaic: a collection of associate ccds (mosaiclink[image])
grid:   x,y magnitude correction grid across mosaic 
fit:    2-d fit of mag offsets across field



m = Mrel + Mcal + Mmos + Mxy + Mgrid

Mrel  (average)
Mcal  (image)
Mmos  (mosaic)
Mxy   (Xi, Yi) (Xi,Yi per image ??)
Mgrid (Xm, Ym)


 measure -> average           catalog[i].measure[j].averef 
 average -> measure           catalog[i].average[j].offset, catalog[i].average[j].Nm

 measure -> image             image:  image[cat, meas]
 image   -> measure           image:  catlist[image], measlist[image]

 measure -> mosaic            mosaic: mosaic[cat, meas]
 mosaic  -> measure	      mosaic: catlist[mosaic], measlist[mosaic]

 measure -> gridbin           grid:   bin[cat, meas]
 gridbin -> measure           grid:   catlist[bin], measlist[bin]

 measure -> Xi, Yi -> Mxy     


getMmos:

 for (i = 0; i < Nmosaic; i++) {

   for (j = 0; j < Nmeasure[i]; j++) {
      cat  = catlist[i][j]
      meas = measlist[i][j]

      M = catalog[cat].measure[meas].M
      Mcal  = applyMcal  (cat, meas)
      Mrel  = applyMrel  (cat, meas)
      Mxy   = applyMxy   (cat, meas)
      Mgrid = applyMgrid (cat, meas)

      list[n] = M - Mcal - Mrel - Mxy - Mgrid
    }
  }



excluding data points:

star:   N < 2
image:  


--

MAG_LIM      : keep stars brighter than MAG_LIM (Mcat)
SIGMA_LIM    : keep stars with error < SIGMA_LIM
STAR_SCATTER : exclude stars with dM > STAR_SCATTER
IMAGE_SCATTER, NIMAGE_SCATTER : define image scatter limits



load_images - exclude images 


