IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 14, 2021, 11:02:20 AM (5 years ago)
Author:
eugene
Message:

add code to rationalize the zero points on each pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r41647 r41662  
    951951}
    952952
     953// find the median zero point and subtract it (for each active average photcode)
     954void rationalize_zeropoints (int Niter) {
     955
     956  if (VERBOSE) fprintf (stderr, "rationalize zero points\n");
     957
     958  // if we are calculating zero points for tgroups,
     959  // rationalize based on the tgroups
     960  if (TGROUP_ZEROPT) {
     961    for (int ic = 0; ic < Nphotcodes; ic++) {
     962      double zpt = get_median_zpt_tgroups (photcodes[ic][0].code);
     963      fprintf (stderr, "rationalize zero points by tgroup for %s (%d) : %f\n", photcodes[ic][0].name, photcodes[ic][0].code, zpt);
     964      if (isnan(zpt)) continue;
     965      set_median_zpt_tgroups (photcodes[ic][0].code, zpt);
     966      set_median_zpt_mosaics (photcodes[ic][0].code, zpt);
     967      set_median_zpt_images  (photcodes[ic][0].code, zpt);
     968    }
     969    return;
     970  }
     971
     972  // if we are calculating zero points for mosaics, but not tgroups,
     973  // rationalize based on the mosaics
     974  if (MOSAIC_ZEROPT) {
     975    for (int ic = 0; ic < Nphotcodes; ic++) {
     976      double zpt = get_median_zpt_mosaics (photcodes[ic][0].code);
     977      fprintf (stderr, "rationalize zero points by mosaic for %s (%d) : %f\n", photcodes[ic][0].name, photcodes[ic][0].code, zpt);
     978      if (isnan(zpt)) continue;
     979      set_median_zpt_tgroups (photcodes[ic][0].code, zpt);
     980      set_median_zpt_mosaics (photcodes[ic][0].code, zpt);
     981      set_median_zpt_images  (photcodes[ic][0].code, zpt);
     982    }
     983    return;
     984  }   
     985
     986  // otherwise, rationalize based on the images
     987  for (int ic = 0; ic < Nphotcodes; ic++) {
     988    double zpt = get_median_zpt_images (photcodes[ic][0].code);
     989    fprintf (stderr, "rationalize zero points by image for %s (%d) : %f\n", photcodes[ic][0].name, photcodes[ic][0].code, zpt);
     990    if (isnan(zpt)) continue;
     991    set_median_zpt_tgroups (photcodes[ic][0].code, zpt);
     992    set_median_zpt_mosaics (photcodes[ic][0].code, zpt);
     993    set_median_zpt_images  (photcodes[ic][0].code, zpt);
     994  }
     995}
     996
     997double get_median_zpt_images (short photcode) {
     998
     999  double *mlist;
     1000
     1001  ALLOCATE (mlist, double, Nimage);
     1002
     1003  int N = 0;
     1004  for (int i = 0; i < Nimage; i++) {
     1005    int mycode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     1006    if (mycode != photcode) continue;
     1007    if (!(image[i].flags & ID_IMAGE_IMAGE_PHOTCAL)) continue;
     1008    mlist[N] = image[i].McalPSF;
     1009    N++;
     1010  }
     1011
     1012  if (N == 0) {
     1013    free (mlist);
     1014    return NAN;
     1015  }
     1016
     1017  StatType stats;
     1018  liststats_setmode (&stats, "MEAN");
     1019
     1020  liststats (mlist, NULL, NULL, N, &stats);
     1021  free (mlist);
     1022
     1023  return stats.median;
     1024}
     1025
     1026void set_median_zpt_images (short photcode, double zpt) {
     1027
     1028  if (!isfinite(zpt)) return; // do not break the zero points
     1029
     1030  for (int i = 0; i < Nimage; i++) {
     1031    int mycode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     1032    if (mycode != photcode) continue;
     1033    image[i].McalPSF -= zpt;
     1034    image[i].McalAPER -= zpt;
     1035  }
     1036
     1037  return;
     1038}
     1039
    9531040static int setMcal_init_done = FALSE;
    9541041void plot_setMcal (double *list, int Npts) {
Note: See TracChangeset for help on using the changeset viewer.