IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41662


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

Location:
trunk/Ohana/src/relphot
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/include/relphot.h

    r41647 r41662  
    874874void ResetAverageActivePhotcodes (SecFilt *secfilt);
    875875
    876 
     876void   rationalize_zeropoints (int Niter);
     877double get_median_zpt_images (short photcode);
     878void   set_median_zpt_images (short photcode, double zpt);
     879double get_median_zpt_mosaics (short photcode);
     880void   set_median_zpt_mosaics (short photcode, double zpt);
     881double get_median_zpt_tgroups (short photcode);
     882void   set_median_zpt_tgroups (short photcode, double zpt);
  • 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) {
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r41647 r41662  
    15741574}
    15751575
     1576double get_median_zpt_mosaics (short photcode) {
     1577
     1578  double *mlist;
     1579
     1580  if (!MOSAIC_ZEROPT) return NAN;
     1581
     1582  ALLOCATE (mlist, double, Nmosaic);
     1583
     1584  int N = 0;
     1585  for (int i = 0; i < Nmosaic; i++) {
     1586    if (mosaic[i].photcode != photcode) continue;
     1587    if (!(mosaic[i].flags & ID_IMAGE_MOSAIC_PHOTCAL)) continue;
     1588    mlist[N] = mosaic[i].McalPSF;
     1589    N++;
     1590  }
     1591
     1592  if (N == 0) {
     1593    free (mlist);
     1594    return NAN;
     1595  }
     1596
     1597  StatType stats;
     1598  liststats_setmode (&stats, "MEAN");
     1599
     1600  liststats (mlist, NULL, NULL, N, &stats);
     1601  free (mlist);
     1602
     1603  return stats.median;
     1604}
     1605
     1606void set_median_zpt_mosaics (short photcode, double zpt) {
     1607
     1608  if (!MOSAIC_ZEROPT) return;
     1609  if (!isfinite(zpt)) return; // do not break the zero points
     1610
     1611  for (int i = 0; i < Nmosaic; i++) {
     1612    if (mosaic[i].photcode != photcode) continue;
     1613    mosaic[i].McalPSF -= zpt;
     1614    mosaic[i].McalAPER -= zpt;
     1615  }
     1616
     1617  return;
     1618}
     1619
    15761620void plot_mosaic_fields (Catalog *catalog) {
    15771621
  • trunk/Ohana/src/relphot/src/TGroupOps.c

    r41647 r41662  
    13651365}
    13661366
     1367double get_median_zpt_tgroups (short photcode) {
     1368
     1369  double *mlist;
     1370
     1371  if (!TGROUP_ZEROPT) return NAN;
     1372
     1373  ALLOCATE (mlist, double, NtgroupTimes);
     1374
     1375  int N = 0;
     1376  for (int i = 0; i < NtgroupTimes; i++) {
     1377    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1378    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1379      if (tgroup[j].photcode != photcode) continue;
     1380      if (!(tgroup[j].flags & ID_IMAGE_TGROUP_PHOTCAL)) continue;
     1381      mlist[N] = tgroup[j].McalPSF;
     1382      N++;
     1383    }
     1384  }
     1385
     1386  if (N == 0) {
     1387    free (mlist);
     1388    return NAN;
     1389  }
     1390
     1391  StatType stats;
     1392  liststats_setmode (&stats, "MEAN");
     1393
     1394  liststats (mlist, NULL, NULL, N, &stats);
     1395  free (mlist);
     1396
     1397  return stats.median;
     1398}
     1399
     1400void set_median_zpt_tgroups (short photcode, double zpt) {
     1401
     1402  if (!TGROUP_ZEROPT) return;
     1403  if (!isfinite(zpt)) return; // do not break the zero points
     1404
     1405  for (int i = 0; i < NtgroupTimes; i++) {
     1406    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1407    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1408      if (tgroup[j].photcode != photcode) continue;
     1409      tgroup[j].McalPSF -= zpt;
     1410      tgroup[j].McalAPER -= zpt;
     1411    }
     1412  }
     1413  return;
     1414}
     1415
    13671416void plot_tgroup_fields (Catalog *catalog) {
    13681417
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r41647 r41662  
    102102      setMmos  (catalog);
    103103      setMgrp  (catalog);
     104
     105      rationalize_zeropoints (i);
    104106
    105107      setMgrid (catalog, Ncatalog);
Note: See TracChangeset for help on using the changeset viewer.