IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33157


Ignore:
Timestamp:
Jan 26, 2012, 5:21:00 AM (14 years ago)
Author:
eugene
Message:

relphot runs with ubercal & flatcorr, signs seem right

Location:
branches/eam_branches/ipp-20111122/Ohana/src/relphot
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/include/relphot.h

    r33117 r33157  
    7979int    FREEZE_MOSAICS;
    8080int    USE_GRID;
     81int    KEEP_UBERCAL;
    8182char  *OUTROOT;
    8283int    PLOTDELAY;
     
    157158off_t         getImageEntry       PROTO((off_t meas, int cat));
    158159float         getMcal             PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog));
     160float         getMflat            PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog));
    159161float         getMgrid            PROTO((off_t meas, int cat));
    160162float         getMmos             PROTO((off_t meas, int cat));
     
    196198int           reload_images       PROTO((FITS_DB *db));
    197199int           setExclusions       PROTO((Catalog *catalog, int Ncatalog));
    198 void          setMcal             PROTO((Catalog *catalog, int Poor));
     200void          setMcal             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
    199201void          setMcalFinal        PROTO((void));
    200202int           setMcalOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/ImageOps.c

    r33117 r33157  
    11# include "relphot.h"
     2void plot_setMcal (double *list, int Npts, StatType *stats, float clouds);
    23
    34// we have an array of images: image[ImageIndex] (ImageIndex : 0 < Nimage)
     
    253254}
    254255
     256// returns image.Mcal - ff(x,y)
    255257float getMcal (off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog) {
    256258
     
    268270  int flat_id = image[i].photom_map_id;
    269271  if (flat_id) {
    270     offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[cat].measure[meas].Xccd, catalog[cat].measure[meas].Yccd);
    271   }
    272   value += offset;
     272    offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[cat].measureT[meas].Xccd, catalog[cat].measureT[meas].Yccd);
     273  }
     274  value -= offset;
    273275
    274276  return (value);
     277}
     278
     279float getMflat (off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog) {
     280
     281  off_t i = MeasureToImage[cat][meas];
     282  if (i == -1) return (NAN);
     283
     284  float offset = 0.0;
     285
     286  // to do this, I need to pass in the catalog and flatcorr pointers
     287  int flat_id = image[i].photom_map_id;
     288  if (flat_id) {
     289    offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[cat].measureT[meas].Xccd, catalog[cat].measureT[meas].Yccd);
     290  }
     291
     292  return (offset);
    275293}
    276294
     
    285303
    286304/* determine Mcal values for all images */
    287 void setMcal (Catalog *catalog, int PoorImages) {
     305void setMcal (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
    288306
    289307  off_t i, j, m, c, n, N, Nmax, mark, bad;
    290308  int Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys, Nbright;
    291   float Msys, Mrel, Mmos, Mgrid, McalBright, McalBright2;
     309  float Msys, Mrel, Mmos, Mgrid, Mflat, McalBright, McalBright2;
    292310  double *list, *dlist;
    293311  StatType stats;
     
    321339      if (!bad) continue;
    322340    }     
     341
     342    /* we optionally do not recalibrate images with UBERCAL zero points */
     343    if (KEEP_UBERCAL && (image[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    323344
    324345    N = 0;
     
    348369      }
    349370     
     371      // image.Mcal is not supposed to include the flat-field correction, so we need to
     372      // apply that offset as well here for this image (in other words, each detection is
     373      // being compared to the model, excluding the zero point, Mcal.  The model includes
     374      // the flat-correction.  NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat)
     375
     376      Mflat = getMflat (m, c, flatcorr, catalog);
     377
    350378      n = catalog[c].measureT[m].averef;
    351379      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     
    354382        continue;
    355383      }
    356       list[N] = Msys - Mrel - Mmos - Mgrid;
     384
     385      fprintf (stderr, "%1d, %3d : %3d, %3d : %10.6f %10.6f : %6.3f  %6.3f  %6.3f  %6.3f  %6.3f\n", (int) i, (int) j, (int) c, (int) m, catalog[c].averageT[n].R, catalog[c].averageT[n].D, Msys, Mrel, Mmos, Mgrid, Mflat);
     386
     387      list[N] = Msys - Mrel - Mmos - Mgrid + Mflat;
    357388      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    358389      if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
     
    385416    image[i].Xm    = 100.0*log10(stats.chisq);
    386417
     418    plot_setMcal (list, N, &stats, CLOUD_TOLERANCE);
     419
    387420    if (image[i].Mcal < -CLOUD_TOLERANCE) {
    388421      image[i].Mcal = 0.0;
     
    454487}
    455488
     489void plot_setMcal (double *list, int Npts, StatType *stats, float clouds) {
     490
     491  off_t i;
     492  double *xlist;
     493  Graphdata graphdata;
     494
     495  if (!PLOTSTUFF) return;
     496
     497  ALLOCATE (xlist, double, Npts);
     498
     499  /**** Mcal vs seq ****/
     500  float minMcal    = +100.0;
     501  float maxMcal    = -100.0;
     502  for (i = 0; i < Npts; i++) {
     503    xlist[i] = i;
     504    minMcal = MIN (list[i], minMcal);
     505    maxMcal = MAX (list[i], maxMcal);
     506  }
     507
     508  float McalRange  = MAX(1.2*(maxMcal - minMcal), 0.21);
     509  float McalCenter = 0.5*(maxMcal + minMcal);
     510
     511  plot_defaults (&graphdata);
     512  graphdata.xmin = -1;
     513  graphdata.xmax = Npts + 1;
     514  graphdata.ymin = McalCenter - 0.5*McalRange;
     515  graphdata.ymax = McalCenter + 0.5*McalRange;
     516  plot_list (&graphdata, xlist, list, Npts, "sequence vs Mcal", "%s.seq.png", OUTROOT);
     517
     518  free (xlist);
     519}
     520
    456521void plot_images () {
    457522
     
    467532
    468533  /**** dMcal vs airmass ****/
     534  float minAirmass = 1000.0;
     535  float maxAirmass =    0.0;
     536  float minMcal    = +100.0;
     537  float maxMcal    = -100.0;
     538  float mindMcal    = +100.0;
     539  float maxdMcal    = -100.0;
    469540  for (i = 0; i < Nimage; i++) {
    470541    Mlist[i] = image[i].Mcal;
    471542    dlist[i] = image[i].dMcal;
    472543    xlist[i] = image[i].secz;
    473   }
     544    minAirmass = MIN (image[i].secz, minAirmass);
     545    maxAirmass = MAX (image[i].secz, maxAirmass);
     546    minMcal = MIN (image[i].Mcal, minMcal);
     547    maxMcal = MAX (image[i].Mcal, maxMcal);
     548    mindMcal = MIN (image[i].dMcal, mindMcal);
     549    maxdMcal = MAX (image[i].dMcal, maxdMcal);
     550  }
     551
     552  float AirmassRange  = MAX(1.2*(maxAirmass - minAirmass), 0.25);
     553  float AirmassCenter = 0.5*(maxAirmass + minAirmass);
     554
     555  float McalRange  = MAX(1.2*(maxMcal - minMcal), 0.21);
     556  float McalCenter = 0.5*(maxMcal + minMcal);
     557
     558  float dMcalRange  = MAX(1.2*(maxdMcal - mindMcal), 0.21);
     559  float dMcalCenter = 0.5*(maxdMcal + mindMcal);
    474560
    475561  plot_defaults (&graphdata);
    476   graphdata.ymin = PlotdMmin;
    477   graphdata.ymax = PlotdMmax;
     562  graphdata.xmin = AirmassCenter - 0.5*AirmassRange;
     563  graphdata.xmax = AirmassCenter + 0.5*AirmassRange;
     564  graphdata.ymin = McalCenter - 0.5*McalRange;
     565  graphdata.ymax = McalCenter + 0.5*McalRange;
    478566  plot_list (&graphdata, xlist, Mlist, Nimage, "airmass vs Mcal", "%s.airmass.png", OUTROOT);
     567
    479568  plot_defaults (&graphdata);
     569  graphdata.xmin = McalCenter - 0.5*McalRange;
     570  graphdata.xmax = McalCenter + 0.5*McalRange;
     571  graphdata.ymin = dMcalCenter - 0.5*dMcalRange;
     572  graphdata.ymax = dMcalCenter + 0.5*dMcalRange;
    480573  plot_list (&graphdata, Mlist, dlist, Nimage, "Mcal vs dMcal", "%s.Mcal.dMcal.png", OUTROOT);
    481574
     
    495588  plot_defaults (&graphdata);
    496589  graphdata.style = 1;
     590  graphdata.xmin = dMcalCenter - 0.5*dMcalRange;
     591  graphdata.xmax = dMcalCenter + 0.5*dMcalRange;
    497592  plot_list (&graphdata, xlist, Mlist, NBIN, "dMcal hist", "%s.dMcalhist.png", OUTROOT);
    498593
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/MosaicOps.c

    r33117 r33157  
    102102    mosaic[Nmosaic].secz  = image[i].secz;
    103103    mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     104
     105    // XXX do we need to do something about flag consistency across a mosaic?
    104106
    105107    /* add image to mosaic image list */
     
    175177      dMcal += image[m].dMcal;
    176178      Xm    += image[m].Xm;
     179
     180      // XXX: how does this work with UBERCAL?  We want to keep the Mcal values supplied by ubercal, but
     181      // solve for a single offset for each exposure (Mosaic.Mcal). 
     182
     183      // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not)
     184
     185      // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
     186
    177187      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
    178188      image[m].Mcal  = 0.0;
     
    215225  image = getimages (&Nimage, NULL);
    216226
     227  // XXX I think this is OK in the ubercal context, but probably need to skip UBERCAL
     228  // images? (no need to update them)
     229
    217230  // copy the mosaic results to the images.  set the mosaic Mcal to 0.0 since we have moved its
    218231  // impact to the images
     
    380393  off_t i, j, m, c, N, Nmax;
    381394  int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys, Nsecfilt;
    382   float Msys, Mrel, Mcal, Mgrid;
     395  float Msys, Mrel, Mcal, Mgrid, Mflat;
    383396  double *list, *dlist, *Mlist, *dMlist;
    384397  StatType stats;
     
    414427      if (!bad) continue;
    415428    }     
     429
     430    /* we optionally do not recalibrate images with UBERCAL zero points */
     431    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    416432
    417433    N = 0;
     
    441457      }
    442458     
     459      // image.Mcal is not supposed to include the flat-field correction, so we need to
     460      // apply that offset as well here for this image (in other words, each detection is
     461      // being compared to the model, excluding the zero point, Mcal.  The model includes
     462      // the flat-correction.  NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat)
     463
     464      Mflat = getMflat (m, c, flatcorr, catalog);
     465
    443466      n = catalog[c].measureT[m].averef;
    444467      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
     
    447470        continue;
    448471      }
    449       list[N]  = Msys - Mrel - Mcal - Mgrid;
     472      list[N]  = Msys - Mrel - Mcal - Mgrid + Mflat;
    450473      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    451474      Mlist[N] = Msys;
     
    499522// to 0.0.  At the same time, we make a guess to the effective impact on all other images,
    500523// driven by the coupling of common stars.
     524// XXX this function is no longer used because we force significantly negative clouds to 0.0
    501525int rationalize_mosaics (Catalog *catalog, int Ncatalog) {
    502526
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/StarOps.c

    r33117 r33157  
    6060    for (j = 0; j < catalog[i].Naverage; j++) {
    6161
     62      // XXX accumulate all secfilt values in a single pass?
     63
    6264      int Ns;
    6365      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     
    8284            continue;
    8385          }
     86
     87          // XXX include the ubercal measurements?  yes, of course!  these are the well-determined values, supposedly!
     88
    8489          // XXX allow REF stars (no Image Entry) to be included in the calculation this
    8590          // should be optionally set, and should allow for REF stars to be downweighted by
     
    144149}
    145150
     151// setMrel and setMrelOutput are extremely similar, but have slightly different implications:
     152// * setMrel uses the internal Tiny structures only
     153// * setMrelOutput skips stars for which there are too few good measurements
     154// * setMrelOutput is meant to be called repeatedly, relaxing the criteria for 'good' on each pass
    146155int setMrelOutput (Catalog *catalog, int Ncatalog, int mark, FlatCorrectionTable *flatcorr) {
    147156
     
    167176  for (i = 0; i < Ncatalog; i++) {
    168177    for (j = 0; j < catalog[i].Naverage; j++) {
     178
    169179      /* skip stars already calibrated */
    170180      if (catalog[i].found[j]) continue; 
     
    172182      int Ns;
    173183      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     184
    174185        int thisCode = photcodes[Ns][0].code;
    175186        Nsec = GetPhotcodeNsec(thisCode);
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c

    r31668 r33157  
    189189  }
    190190
     191  KEEP_UBERCAL = FALSE;
     192  if ((N = get_argument (argc, argv, "-keep-ubercal"))) {
     193    remove_argument (N, &argc, argv);
     194    KEEP_UBERCAL = TRUE;
     195  }
     196
    191197  MIN_ERROR = 0.001;
    192198  if ((N = get_argument (argc, argv, "-minerror"))) {
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c

    r30616 r33157  
    3737  fprintf (stderr, "  -imfreeze\n");
    3838  fprintf (stderr, "  -grid\n");
     39  fprintf (stderr, "  -keep-ubercal : do not change zero point for ubercal-ed images\n");
    3940  fprintf (stderr, "  -area Xmin Xmax Ymin Ymax\n");
    4041  fprintf (stderr, "  -instmag min max\n");
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/plot_scatter.c

    r33117 r33157  
    1111  for (i = 0; i < Ncatalog; i++) {
    1212    for (j = 0; j < catalog[i].Naverage; j++) {
    13       Ntot += catalog[i].average[j].Nmeasure;
     13      Ntot += catalog[i].averageT[j].Nmeasure;
    1414    }
    1515  }
     
    3232            /* calculate the average value for a single star */
    3333            if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
    34             m = catalog[i].average[j].measureOffset;
     34            m = catalog[i].averageT[j].measureOffset;
    3535
    36             for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     36            for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
    3737                // skip measurements that do not match the current photcode
    3838                int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/plotstuff.c

    r27611 r33157  
    165165  graphdata[0].color = black;
    166166  graphdata[0].lweight = 0;
    167   graphdata[0].size = 0.5;
     167  graphdata[0].size = 1.0;
    168168
    169169  graphdata[0].xmin = dUNDEF;
  • branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c

    r33117 r33157  
    120120  /* determine fit values */
    121121  for (i = 0; i < NLOOP; i++) {
     122    if (PLOTSTUFF) {
     123      plot_scatter (catalog, Ncatalog, flatcorr);
     124    }
    122125    setMrel  (catalog, Ncatalog, flatcorr);
    123     setMcal  (catalog, FALSE);
     126    if (PLOTSTUFF) {
     127      plot_scatter (catalog, Ncatalog, flatcorr);
     128    }
     129    setMcal  (catalog, FALSE, flatcorr);
    124130    setMmos  (catalog, FALSE, flatcorr);
    125131    setMgrid (catalog, flatcorr);
     
    160166
    161167  /* set Mcal & Mmos for bad images */
    162   setMcal  (catalog, TRUE);
     168  setMcal  (catalog, TRUE, flatcorr);
    163169  setMmos  (catalog, TRUE, flatcorr);
    164170  MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
Note: See TracChangeset for help on using the changeset viewer.