IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41556


Ignore:
Timestamp:
Apr 27, 2021, 8:39:17 AM (5 years ago)
Author:
eugene
Message:

updates to the good/bad night logic; save image stats

Location:
trunk/Ohana/src/relphot
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/Makefile

    r41462 r41556  
    5454$(SRC)/load_catalogs.$(ARCH).o   \
    5555$(SRC)/load_images.$(ARCH).o     \
     56$(SRC)/save_images.$(ARCH).o     \
     57$(SRC)/MagResidSave.$(ARCH).o    \
    5658$(SRC)/synthetic_mags.$(ARCH).o  \
    5759$(SRC)/plot_scatter.$(ARCH).o    \
     
    117119$(SRC)/select_images.$(ARCH).o   \
    118120$(SRC)/load_images.$(ARCH).o     \
     121$(SRC)/save_images.$(ARCH).o     \
     122$(SRC)/MagResidSave.$(ARCH).o    \
    119123$(SRC)/load_catalogs.$(ARCH).o   \
    120124$(SRC)/reload_catalogs.$(ARCH).o \
  • trunk/Ohana/src/relphot/include/relphot.h

    r41555 r41556  
    643643int           setMcalOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
    644644
    645 void          setMcal             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
    646 int           setMmos             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
    647 int           setMgrp             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
     645void          setMcal             PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
     646int           setMmos             PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
     647int           setMgrp             PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
    648648
    649649int           setMrel             PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
     
    841841void RepairWarpMeasuresCloseLogfile ();
    842842
    843 int save_images_backup (FITS_DB *db);
    844 
    845843void dump_tgroups (Catalog *catalog, int Npass);
    846844void dump_catalog (Catalog *catalog, off_t c, int Npass);
     
    853851int UseStandardOLS (ZptFitModeType mode);
    854852int GetActivePhotcodeIndex (int photcode);
     853
     854int save_images_backup (FITS_DB *db);
     855int save_images_updates (FITS_DB *db);
     856
     857int MagResidSave(char *filename, Catalog *catalog);
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r41555 r41556  
    7575Image *getimage (off_t N) {
    7676  return (&image[N]);
     77}
     78
     79off_t *get_N_onImage() {
     80  return N_onImage;
     81}
     82
     83IDX_T **get_ImageToCatalog() {
     84  return ImageToCatalog;
     85}
     86
     87IDX_T **get_ImageToMeasure() {
     88  return ImageToMeasure;
    7789}
    7890
     
    570582
    571583/* determine Mcal values for all images */
    572 void setMcal (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     584void setMcal (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    573585
    574586  off_t i, j, m, c, n;
    575   int mark, bad, Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys;
     587  int mark, Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys;
    576588
    577589  if (IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_NONE) return;
     
    580592
    581593  int Nsecfilt = GetPhotcodeNsecfilt ();
    582 
    583   if (PoorImages) {
    584     // XXX use bad stars and measurements for PoorImages? or not?
    585     // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;
    586     IMAGE_BAD = 0;
    587   }
    588594
    589595  off_t Nmax = 0;
     
    618624    }
    619625
    620     /* on PoorImages run, skip good images */
    621     if (PoorImages) {
    622       bad = image[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);
    623       if (!bad) continue;
    624     }     
    625 
    626626    if (image[i].photcode == 0) continue; // skip the PHU images
    627627
     
    629629    int badMosaic = (image[i].flags & ID_IMAGE_MOSAIC_POOR);
    630630    int isMosaic  = isMosaicChip(image[i].photcode);
     631    int useMcal   = TRUE;
    631632
    632633    // unset at start by default (set if actually used below)
     
    638639    // in BAD_NIGHT mode, we fit ONLY images in bad nights
    639640    if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT)) {
    640       if (!badNight) continue;
     641      if (!badNight) useMcal = FALSE; // do not fit images from good nights
    641642    }
    642643
    643644    // in BAD_NIGHT_BAD_MOSAIC mode, we fit ONLY bad mosaics in bad nights
    644645    if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC)) {
    645       if (!badNight) continue;
    646       if (!badMosaic && isMosaic) continue; // skip good mosaics (but not good images)
     646      if (!badNight) useMcal = FALSE; // do not fit images from good nights
     647      if (!badMosaic && isMosaic) useMcal = FALSE; // skip good mosaics (but not good images)
    647648    }
    648649
    649650    // in BAD_MOSAIC mode, we fit bad mosaics ignoring night state
    650651    if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_MOSAIC)) {
    651       if (!badMosaic && isMosaic) continue; // skip good mosaics (but not bad images)
     652      if (!badMosaic && isMosaic) useMcal = FALSE; // skip good mosaics (but not bad images)
    652653    }
    653654
     
    759760
    760761    /* too few good measurements or too many bad measurements */
    761     mark = FALSE;
    762     if (!PoorImages) {
    763       mark = (Nref < IMAGE_TOOFEW) || (Nref < IMAGE_GOOD_FRACTION*N_onImage[i]);
    764       if (mark) {
    765         image[i].flags |= ID_IMAGE_PHOTOM_FEW;
    766         Nfew ++;
    767       } else {
    768         image[i].flags &= ~ID_IMAGE_PHOTOM_FEW;
    769       }     
    770     }
     762    mark = (Nref < IMAGE_TOOFEW) || (Nref < IMAGE_GOOD_FRACTION*N_onImage[i]);
     763    if (mark) {
     764      image[i].flags |= ID_IMAGE_PHOTOM_FEW;
     765      image[i].dMcal      = NAN;
     766      image[i].McalChiSq  = NAN;
     767      image[i].nFitPhotom = 0;
     768      Nfew ++;
     769    } else {
     770      image[i].flags &= ~ID_IMAGE_PHOTOM_FEW;
     771    }     
    771772    if (mark) continue;
    772773
     774    // use liststats to find the 20-pct, median, 80-pct points
     775    StatType stats;
     776    liststats_setmode (&stats, "MEDIAN");
     777    liststats (psfStars.alldata->yVector, NULL, NULL, Nref, &stats);
     778    double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;  // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma)
     779
     780    // soften the individual errors with 10% of the scatter above
     781    for (j = 0; j < Nref; j++) {
     782      double newSigma = hypot(psfStars.alldata->dyVector[j], 0.1*altSigma);
     783      psfStars.alldata->dyVector[j] = newSigma;
     784    }
     785
    773786    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
     787    // XXX: apply airmass from above and fit only zp?
     788
     789    // XXX soften the stats?
     790
    774791    fit1d_irls (&psfStars, Nref);
    775     image[i].McalPSF    = psfStars.bSaveArray[0][0];
     792    fit1d_irls (&kronStars, Nkron);
     793    fit1d_irls (&brightStars, Nbright);
     794
     795    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
     796    if (useMcal) {
     797      image[i].McalPSF    = psfStars.bSaveArray[0][0];
     798      image[i].McalAPER   = kronStars.bSaveArray[0][0];
     799      image[i].flags |= ID_IMAGE_IMAGE_PHOTCAL;  // set this flag (unset by default)
     800    } else {
     801      image[i].McalPSF    = 0.0;
     802      image[i].McalAPER   = 0.0;
     803    }
     804
     805    // record statistics on the fit regardless if it is used or not
    776806    image[i].dMcal      = psfStars.bSigma[0];
    777807    image[i].nFitPhotom = psfStars.Nmeas;
     
    779809    Ncalibrated ++;
    780810
    781     // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
    782     // XXX: apply airmass from above and fit only zp?
    783     // XXX EAM : temporarily use this to track calibration quality
    784     if (0) {
    785       fit1d_irls (&kronStars, Nkron);
    786       image[i].McalAPER   = kronStars.bSaveArray[0][0];
    787     }
     811    // bright end scatter
     812    image[i].dMagSys = brightStars.sigma;
    788813
    789814    if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) {
     
    796821    }
    797822
    798     // bright end scatter
    799     fit1d_irls (&brightStars, Nbright);
    800     image[i].dMagSys = brightStars.sigma;
    801 
    802     if (image[i].McalPSF < -CLOUD_TOLERANCE) {
    803       image[i].McalPSF = 0.0;
    804     }
    805 
    806     image[i].flags |= ID_IMAGE_IMAGE_PHOTCAL;  // set this flag
    807 
    808823    // minUbercalDist calculated here is the min value for any star owned by this image
    809824    // since this particular image is tied to that star, bump its distance by 1
     
    813828  fprintf (stderr, "%d images calibrated\n", Ncalibrated);
    814829  fprintf (stderr, "%d images marked having too few measurements (Nbad: %d, Nmos: %d, Ngrid: %d, Nrel: %d, Nsys: %d)\n", Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys);
    815 
    816   if (PoorImages) {
    817     IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
    818     STAR_BAD  = ID_OBJ_POOR | ID_OBJ_FEW;
    819     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
    820   }
    821830
    822831  FitDataSetFree (&brightStars);
     
    12911300  image = NULL;
    12921301}
    1293 
    1294 void checkImages (char *name) {
    1295 
    1296   off_t i;
    1297   fprintf (stderr, "--- %s ---\n", name);
    1298  
    1299   OhanaMemblock *ref = (OhanaMemblock *) image - 1;
    1300   fprintf (stderr, "file: %s\n", ref->file);
    1301 
    1302   fprintf (stderr, "0x%08llx \n", (unsigned long long) image);
    1303 
    1304   for (i = 0; i < Nimage; i++) {
    1305     fprintf (stderr, "%s : 0x%08x : %6.3f  %6.3f\n", image[i].name, image[i].flags, image[i].McalPSF, image[i].McalAPER);
    1306   }
    1307 }
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r41555 r41556  
    11# include "relphot.h"
    22off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start);
     3int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog, FlatCorrectionTable *flatcorr);
    34
    45// see discussion in ImagesOps.c re: IDX_T
     
    983984  int Nskip;
    984985  off_t Nmax;
    985   int PoorImages;
    986986  FitDataSet psfStars;
    987987  FitDataSet kronStars;
     
    10021002int setMmos_mosaic (Mosaic *mosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info, FlatCorrectionTable *flatcorr);
    10031003void *setMmos_worker (void *data);
    1004 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr);
    1005 
    1006 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists, int PoorImages) {
     1004int setMmos_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr);
     1005
     1006void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists) {
    10071007  info->Nfew = 0;
    10081008  info->Nbad = 0;
     
    10141014
    10151015  info->Nmax = Nmax;
    1016   info->PoorImages = PoorImages;
    10171016
    10181017  if (allocLists) {
     
    10691068}
    10701069
    1071 int setMmos (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     1070int setMmos (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    10721071
    10731072  off_t i, N, Nmax;
     
    10821081  // so do not run setMmos in threaded mode if PLOTSTUFF is set
    10831082  if (NTHREADS && !PLOTSTUFF) {
    1084     int status = setMmos_threaded (catalog, PoorImages, flatcorr);
     1083    int status = setMmos_threaded (catalog, flatcorr);
    10851084    return status;
    10861085  }
     
    10891088
    10901089  fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
    1091 
    1092   if (PoorImages) {
    1093     // XXX use bad stars and measurements for PoorImages? or not?
    1094     // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;
    1095     IMAGE_BAD = 0;
    1096   }
    10971090
    10981091  Nmax = 0;
     
    11021095
    11031096  SetMmosInfo info;
    1104   SetMmosInfoInit (&info, Nmax, TRUE, PoorImages);
     1097  SetMmosInfoInit (&info, Nmax, TRUE);
    11051098
    11061099  // int savePlotDelay = PLOTDELAY;
     
    11211114  fprintf (stderr, "%d mosaics marked having too few measurements (Nbad: %d, Ncal: %d, Ngrid: %d, Nrel: %d, Nsys: %d)\n", info.Nfew, info.Nbad, info.Ncal, info.Ngrid, info.Nrel, info.Nsys);
    11221115
    1123   if (PoorImages) {
    1124     IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
    1125     STAR_BAD  = ID_OBJ_POOR | ID_OBJ_FEW;
    1126     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
    1127   }
    11281116  return (TRUE);
    11291117}
     
    11341122  off_t j, NimageReal;
    11351123
    1136   /* on PoorImages run, skip good images */
    1137   if (info->PoorImages) {
    1138     int bad = myMosaic[0].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);
    1139     if (!bad) return TRUE;
    1140   }     
    1141 
    11421124  FitDataSet *psfStars = &info->psfStars;
    11431125  FitDataSet *kronStars = &info->kronStars;
     
    11471129  assert (Nmos < Nmosaic);
    11481130
     1131  int Nsecfilt = GetPhotcodeNsecfilt ();
     1132
     1133  int minUbercalDist = 1000;
     1134
     1135  // unset this flag at start (set below if zeropoint is calculated)
     1136  myMosaic->flags &= ~ID_IMAGE_MOSAIC_PHOTCAL;  // unset this flag
     1137
     1138  // calculate the statistics for both good and bad exposures, but only set Mmos if the rules allow
     1139  // we only skip the statistics for nights with too few measurements or exposures
     1140
     1141  // if we are fitting TGroup zero points, when we identify the bad TGroups, we proceed
     1142  // to fit the mosaics which are from the bad TGroups
     1143
     1144  // if we are fitting Mosaic zero points, when we identify the bad nights, we proceed
     1145  // to fit the images which are from the bad Mosaics
     1146
    11491147  int badNight  = (myMosaic[0].flags & ID_IMAGE_NIGHT_POOR);
    11501148  int badMosaic = (myMosaic[0].flags & ID_IMAGE_MOSAIC_POOR);
    1151 
    1152   myMosaic->flags &= ~ID_IMAGE_MOSAIC_PHOTCAL;  // unset this flag
    1153 
    1154   // if we are fitting TGroup zero points, when we identify the bad TGroups, we proceed
    1155   // to fit the mosaics which are from the bad TGroups
    1156 
    1157   // if we are fitting Mosaic zero points, when we identify the bad nights, we proceed
    1158   // to fit the images which are from the bad Mosaics
    1159 
    1160   // in BAD_NIGHT mode, we fit ONLY mosaics in bad nights
     1149  int useMmos   = TRUE;
     1150
     1151  // in BAD_NIGHT mode, we fit ONLY mosaics in bad nights (do not fit mosaics from good nights)
    11611152  if (MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT) {
    1162     if (!badNight) return TRUE;
     1153    if (!badNight) useMmos = FALSE;
    11631154  }
    11641155
    11651156  // in BAD_NIGHT_GOOD_MOSAIC mode, we fit ONLY good mosaics in bad nights
    11661157  if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC)) {
    1167     if (!badNight) return TRUE;
    1168     if (badMosaic) return TRUE;
     1158    if (!badNight) useMmos = FALSE; // do not fit good nights
     1159    if (badMosaic) useMmos = FALSE; // do not fit bad mosaics
    11691160  }
    11701161
    11711162  // in GOOD_MOSAIC mode, we fit good mosaics ignoring night state
    11721163  if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_GOOD_MOSAIC)) {
    1173     if (badMosaic) return TRUE;
     1164    if (badMosaic) useMmos = FALSE; // do not fit bad mosaics
    11741165  }
    11751166
     
    11891180      // fprintf (stderr, "%d %d %d\n", (int) i, (int) im, image[im].ubercalDist);
    11901181    }
     1182    // XXX if KEEP_UBERCAL, calculate stats but do not change Mmos
    11911183    if (KEEP_UBERCAL) return TRUE;
    11921184  }
    1193 
    1194   int Nsecfilt = GetPhotcodeNsecfilt ();
    1195 
    1196   int minUbercalDist = 1000;
    11971185
    11981186  // do not modify the calibration for mosaics with partial images loaded (skipCal TRUE)
     
    12041192  int testImage = FALSE;
    12051193  // testImage |= (abs(myMosaic[0].start - 1324104046) < 10);
    1206   // testImage |= (abs(myMosaic[0].start - 1324103823) < 10);
    1207   // testImage |= (abs(myMosaic[0].start - 1323003245) < 10);
    1208   // testImage |= (abs(myMosaic[0].start - 1323003069) < 10);
    1209   // testImage |= (abs(myMosaic[0].start - 1323003125) < 10);
    1210   // testImage |= (abs(myMosaic[0].start - 1323003300) < 10);
    1211   // testImage |= (abs(myMosaic[0].start - 1323003365) < 10);
    1212   // testImage |= (abs(myMosaic[0].start - 1323003191) < 10);
    1213   // testImage |= (abs(myMosaic[0].start - 1323003014) < 10);
    1214   // testImage |= (abs(myMosaic[0].start - 1323003484) < 10);
    1215   // testImage |= (abs(myMosaic[0].start - 1323003419) < 10);
    1216   // testImage |= (abs(myMosaic[0].start - 1323002949) < 10);
    12171194
    12181195  FILE *fout = NULL;
     
    12211198    snprintf (filename, 64, "test.%05d.%02d.dat", (int) Nmos, npass_output);
    12221199    fout = fopen (filename, "w");
     1200    save_test_mosaic_measures (fout, Nmos, catalog, flatcorr);
     1201    fclose (fout);
    12231202  }
    12241203
     
    12321211    off_t c = MosaicToCatalog[Nmos][j];
    12331212     
    1234     // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF
    1235     if (fout) {
    1236       float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);
    1237       // float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    1238       float Mgrid    = getMgrid (m, c);
    1239       float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    1240       float Mflat    = getMflat (m, c, flatcorr, catalog);
    1241 
    1242       off_t n = catalog[c].measureT[m].averef;
    1243       float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    1244 
    1245       float delta = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
    1246 
    1247       int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
    1248 
    1249       fprintf (fout, "%f %f : %f %f %f %f %f  : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, delta, isBad);
    1250     }
    1251 
    12521213    if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    12531214      info->Nbad ++;
     
    13291290  /* N_onMosaic[Nmos] is all measurements, N is good measurements */
    13301291
    1331   if (fout) { fclose (fout); }
    1332 
    1333   /* too few good measurements or too many bad measurements (skip in PoorImages run) */
    1334   if (!info->PoorImages) {
    1335     int mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*N_onMosaic[Nmos]);
    1336     if (mark) {
    1337       if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), (%d < %d) || (%d < %f*"OFF_T_FMT")\n", image[MosaicToImage[Nmos][0]].name,  Nmos,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  N_onMosaic[Nmos]); }
    1338       myMosaic[0].flags |= ID_IMAGE_PHOTOM_FEW;
    1339       info->Nfew ++;
    1340       if (testImage) {
    1341         fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) IMAGE_TOOFEW, (int) (IMAGE_GOOD_FRACTION*N_onMosaic[Nmos]));
    1342       }
    1343       return TRUE; // skip mosaics with too few good measurements
    1344     } else {
    1345       myMosaic[0].flags &= ~ID_IMAGE_PHOTOM_FEW;
    1346     }
     1292  /* skip mosaics with too few good measurements or too many bad measurements */
     1293  int mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*N_onMosaic[Nmos]);
     1294  if (mark) {
     1295    myMosaic->flags |= ID_IMAGE_PHOTOM_FEW;
     1296    myMosaic->McalPSF    = 0.0;
     1297    myMosaic->McalAPER   = 0.0;
     1298    myMosaic->dMcal      = NAN;
     1299    myMosaic->stdev      = NAN;
     1300    myMosaic->dMmin      = NAN;
     1301    myMosaic->dMmax      = NAN;
     1302    myMosaic->McalChiSq  = NAN;
     1303    myMosaic->nFitPhotom = 0;
     1304    myMosaic->nValPhotom = N;
     1305    info->Nfew ++;
     1306    if (testImage) {
     1307      fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) IMAGE_TOOFEW, (int) (IMAGE_GOOD_FRACTION*N_onMosaic[Nmos]));
     1308    }
     1309    return TRUE; // skip mosaics with too few good measurements
     1310  } else {
     1311    myMosaic[0].flags &= ~ID_IMAGE_PHOTOM_FEW;
     1312  }
     1313
     1314  StatType stats;
     1315  liststats_setmode (&stats, "MEDIAN");
     1316  liststats (psfStars->alldata->yVector, NULL, NULL, N, &stats);
     1317  double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;  // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma)
     1318
     1319  // soften the individual errors with 10% of the scatter above
     1320  for (j = 0; j < N; j++) {
     1321    double newSigma = hypot(psfStars->alldata->dyVector[j], 0.1*altSigma);
     1322    psfStars->alldata->dyVector[j] = newSigma;
    13471323  }
    13481324
    13491325  fit1d_irls (psfStars, N);
    13501326  fit1d_irls (brightStars, Nbright);
     1327  fit1d_irls (kronStars, N);
     1328
     1329  if (useMmos) {
     1330    myMosaic->McalPSF    = psfStars->bSaveArray[0][0];
     1331    myMosaic->McalAPER   = kronStars->bSaveArray[0][0];
     1332    myMosaic->flags |= ID_IMAGE_MOSAIC_PHOTCAL;  // set this flag
     1333  } else {
     1334    myMosaic->McalPSF    = 0.0;
     1335    myMosaic->McalAPER   = 0.0;
     1336  }
    13511337
    13521338  // for now, I have no reason to measure these separately for camera-level images
    1353   myMosaic[0].McalPSF    = psfStars->bSaveArray[0][0];
    1354   myMosaic[0].dMcal      = psfStars->bSigma[0];     
    1355   myMosaic[0].stdev      = psfStars->sigma;
    1356   myMosaic[0].McalChiSq  = psfStars->chisq;         
    1357   myMosaic[0].nFitPhotom = psfStars->Nmeas;         
    1358   myMosaic[0].nValPhotom = N;       
    1359 
    1360   fit1d_irls (kronStars, N);
    1361   myMosaic->McalAPER   = kronStars->bSaveArray[0][0];
     1339  myMosaic->dMcal      = psfStars->bSigma[0];       
     1340  myMosaic->stdev      = psfStars->sigma;
     1341  myMosaic->McalChiSq  = psfStars->chisq;           
     1342  myMosaic->nFitPhotom = psfStars->Nmeas;           
     1343  myMosaic->nValPhotom = N;         
     1344
     1345  // bright end scatter
     1346  myMosaic->dMsys = brightStars->sigma; // stdev of bright star mags
    13621347
    13631348  if (testImage) {
    13641349    fprintf (stderr, "test image %d (%d) %f %f %d ... ", (int) Nmos, myMosaic->start, myMosaic->McalPSF, myMosaic->dMcal, myMosaic->nFitPhotom);
     1350    fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].McalPSF, myMosaic[0].dMsys, myMosaic[0].McalChiSq);
    13651351  }
    13661352
     
    13681354    fprintf (stderr, "Mmos: %6.3f +/- %6.3f %5d %5d | %s\n", myMosaic->McalPSF, myMosaic->dMcal, myMosaic->nFitPhotom, N, image[MosaicToImage[Nmos][0]].name);
    13691355    plot_setMcal (psfStars->alldata->yVector, N);
    1370   }
    1371 
    1372   // bright end scatter
    1373   fit1d_irls (brightStars, Nbright);
    1374   myMosaic->dMsys = brightStars->sigma; // stdev of bright star mags
    1375 
    1376   if (myMosaic[0].McalPSF < -CLOUD_TOLERANCE) {
    1377     myMosaic[0].McalPSF = 0.0;
    1378   }
    1379 
    1380   myMosaic->flags |= ID_IMAGE_MOSAIC_PHOTCAL;  // set this flag
    1381 
    1382   if (testImage) {
    1383     fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].McalPSF, myMosaic[0].dMsys, myMosaic[0].McalChiSq);
    13841356  }
    13851357
     
    14001372}
    14011373 
    1402 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     1374int save_test_mosaic_measures (FILE *fout, int Nmos, Catalog *catalog, FlatCorrectionTable *flatcorr) {
     1375
     1376  int Nsecfilt = GetPhotcodeNsecfilt ();
     1377
     1378  for (int j = 0; j < N_onMosaic[Nmos]; j++) {
     1379     
     1380    off_t m = MosaicToMeasure[Nmos][j];
     1381    off_t c = MosaicToCatalog[Nmos][j];
     1382     
     1383    // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF
     1384    float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);
     1385    // float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
     1386    float Mgrid    = getMgrid (m, c);
     1387    float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     1388    float Mflat    = getMflat (m, c, flatcorr, catalog);
     1389
     1390    off_t n = catalog[c].measureT[m].averef;
     1391    float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     1392   
     1393    float delta = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
     1394
     1395    int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
     1396   
     1397    fprintf (fout, "%f %f : %f %f %f %f %f  : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, delta, isBad);
     1398  }
     1399  return TRUE;
     1400}
     1401
     1402int setMmos_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    14031403
    14041404  int i;
     
    14081408
    14091409  fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
    1410 
    1411   if (PoorImages) {
    1412     // XXX use bad stars and measurements for PoorImages? or not?
    1413     // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;
    1414     IMAGE_BAD = 0;
    1415   }
    14161410
    14171411  off_t Nmax = 0;
     
    14211415
    14221416  SetMmosInfo summary;
    1423   SetMmosInfoInit (&summary, Nmax, FALSE, PoorImages);
     1417  SetMmosInfoInit (&summary, Nmax, FALSE);
    14241418
    14251419  pthread_attr_t attr;
     
    14451439    threadinfo[i].flatcorr = flatcorr;
    14461440
    1447     // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop,
    1448     // PoorImages) used in the threads to allocate the arrays and set the MaxIterations
    1449     SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages);
     1441    // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop) used in
     1442    // the threads to allocate the arrays and set the MaxIterations
     1443    SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE);
    14501444    pthread_create (&threads[i], NULL, setMmos_worker, &threadinfo[i]);
    14511445  }
     
    14921486  npass_output ++;
    14931487
    1494   if (PoorImages) {
    1495     IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
    1496     STAR_BAD  = ID_OBJ_POOR | ID_OBJ_FEW;
    1497     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
    1498   }
    14991488  return TRUE;
    15001489}
     
    15051494
    15061495  SetMmosInfo results;
    1507   SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages);
     1496  SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE);
    15081497
    15091498  while (1) {
     
    18921881  int N = 0;
    18931882  for (int i = 0; i < Nmosaic; i++) {
    1894     // if (mosaic[i].flags & IMAGE_BAD) continue;
    18951883    if (!(mosaic[i].flags & ID_IMAGE_MOSAIC_PHOTCAL)) continue;
    18961884    if (mosaic[i].skipCal) continue;
     
    19061894  float MaxChiSq = stats.Upper90;
    19071895
    1908   // old version based on Mcal value
    1909   // MaxOffset = MAX (IMAGE_OFFSET, 2*stats.sigma);
    1910   /// MedOffset = stats.median;
    1911 
    19121896  liststats (slist, NULL, NULL, N, &stats);
    19131897  float MaxScatter = stats.Upper90;
    1914   // old: MaxScatter = MAX (IMAGE_SCATTER, 2*stats.median);
    19151898
    19161899  fprintf (stderr, "MOSAIC: Max ChiSq: %f, Max Scatter: %f\n", MaxChiSq, MaxScatter);
     
    19271910    int mark = FALSE;
    19281911
    1929     if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW)) {
     1912    if (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW) {
    19301913      mark = TRUE;
    19311914      Nfew ++;
  • trunk/Ohana/src/relphot/src/StarOps.c

    r41473 r41556  
    662662
    663663// this function only operations on the PSF magnitudes
     664
     665// XXX EAM clean_measures is no longer used -- we rely on IRLS to down-weight outliers
    664666
    665667# define NSIGMA_CLIP 3.0
  • trunk/Ohana/src/relphot/src/TGroupOps.c

    r41555 r41556  
    194194  for (off_t i = 0; i < Nsubset; i++) {
    195195    ImageToTGroup[i] = NULL;
    196 
    197     // ignore non-GPC1 images
    198     // if (!isGPC1chip(subset[i].photcode)) {
    199     //   Nsimple ++;
    200     //   continue;
    201     // }
    202196
    203197    // ignore mosaic images (photcode == 0)
     
    459453  // this tgroup has been identified as poor.
    460454  tgroup->flags |= ID_IMAGE_NIGHT_POOR;
     455  tgroup->McalPSF  = 0.0;
     456  tgroup->McalAPER = 0.0;
     457  tgroup->dKlam    = 0.0;
    461458
    462459  // all associated mosaics should be marked as coming from a bad night
     
    473470    image[im].flags |= ID_IMAGE_NIGHT_POOR;
    474471  }
    475 
    476   tgroup->McalPSF  = 0.0;
    477   tgroup->McalAPER = 0.0;
    478   tgroup->dKlam    = 0.0;
    479472}
    480473
     
    552545  fprintf (stderr, "Matched %d detections to tgroups\n", Nmatch);
    553546
    554   // XXX print results for testing
    555   for (int i = 0; FALSE && (i < NtgroupTimes); i++) {
    556     TGroup *tgroup = tgroupTimes[i][0].byCode;
    557     for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
    558       if (0) fprintf (stderr, "  TGROUP time %.0f photcode %d, Nmeasure: %d, Nimage: %d\n", ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, (int) tgroup[j].Nmeasure, (int) tgroup[j].Nimage);
    559     }
    560   }
    561547  return (TRUE);
    562548}
     
    574560
    575561  TGroup *myGroup = ImageToTGroup[idx];
    576   TGTimes *parent = (TGTimes *) myGroup->parent;
    577   if (!myGroup) {
    578     // Image *image = getimage(idx);
    579     // fprintf (stderr, "unmatched image %s\n", image[0].name);
    580     // skip measurements from simple chips (not matched to a tgroup by definition)
    581     return;
    582   }
    583 
    584   // test to check we got the right match:
    585   {
    586     Image *image = getimage(idx);
    587     // XXX we are now matching with just tzero.  be careful for cameras with drift
    588     // unsigned int imageStart = image[0].tzero - MAX(0.01*image[0].trate*image[0].NY, 1);
    589     unsigned int imageStart = image[0].tzero;
    590     // XXX to do this check I need a pointer to the group master
    591     if ((imageStart < parent->start) || (imageStart > parent->stop)) {
    592       fprintf (stderr, "error in image to tgroup match\n");
    593       abort();
    594     }
    595   }
     562  if (!myGroup) return;
    596563
    597564  // this measurement is on one of my tgroups, mark it as mine.
     
    611578}
    612579
    613 // XXX return the error as well as the value
     580// dZpt (if supplied) returns the error on Mgrp
    614581float getMgrp (off_t meas, int cat, float airmass, float *dZpt) {
    615582
     
    638605}
    639606
    640 // XXX remove the lists and replace with StatDataSet structs?
    641 // XXX move the StatDataSetAlloc up?
    642607typedef struct {
    643608  int Nfew;
     
    650615  int Nskip;
    651616  off_t Nmax;
    652   int PoorImages;
    653617  FitDataSet psfStars;
    654618  FitDataSet kronStars;
     
    669633int   setMgrp_tgroup (TGroup *tgroup, off_t Nmos, Image *image, Catalog *catalog, SetMgrpInfo *info, FlatCorrectionTable *flatcorr);
    670634void *setMgrp_worker (void *data);
    671 int   setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr);
    672 
    673 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists, int PoorImages) {
     635int   setMgrp_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr);
     636
     637void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists) {
    674638  info->Nfew = 0;
    675639  info->Nbad = 0;
     
    682646
    683647  info->Nmax = Nmax;
    684   info->PoorImages = PoorImages;
    685648
    686649  if (allocLists) {
     
    744707}
    745708
    746 int setMgrp (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     709int setMgrp (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    747710
    748711  off_t N;
     
    755718  // so do not run setMgrp in threaded mode if PLOTSTUFF is set
    756719  if (NTHREADS && !PLOTSTUFF) {
    757     int status = setMgrp_threaded (catalog, PoorImages, flatcorr);
     720    int status = setMgrp_threaded (catalog, flatcorr);
    758721    return status;
    759722  }
     
    770733
    771734  SetMgrpInfo info;
    772   SetMgrpInfoInit (&info, Nmax, TRUE, PoorImages);
     735  SetMgrpInfoInit (&info, Nmax, TRUE);
    773736
    774737  for (off_t i = 0; i < NtgroupTimes; i++) {
     
    776739    for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
    777740      setMgrp_tgroup (&tgroup[j], i, image, catalog, &info, flatcorr);
    778       // fprintf (stderr, "TGROUP time %.0f photcode %d Mcal: %f, dK: %f, dMcal: %f, sigma: %f, chisq: %f, %d of %d, limiting negative clouds to %f\n", ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, tgroup[j].McalPSF, tgroup[j].dKlam, tgroup[j].dMcal, tgroup[j].stdev, tgroup[j].McalChiSq, tgroup[j].nFitPhotom, tgroup[j].nValPhotom, CLOUD_TOLERANCE);
     741      // fprintf (stderr, "TGROUP time %.0f photcode %d Mcal: %f, dK: %f, dMcal: %f, sigma: %f, chisq: %f, %d of %d, limiting negative clouds to %f\n",
     742      // ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode, tgroup[j].McalPSF, tgroup[j].dKlam, tgroup[j].dMcal, tgroup[j].stdev, tgroup[j].McalChiSq, tgroup[j].nFitPhotom, tgroup[j].nValPhotom, CLOUD_TOLERANCE);
    779743    }
    780744  }
     
    799763int setMgrp_tgroup (TGroup *myTGroup, off_t Ngrp, Image *image, Catalog *catalog, SetMgrpInfo *info, FlatCorrectionTable *flatcorr) {
    800764
    801   off_t j, NimageReal;
    802 
    803   // At some point, we identify good and bad tgroups.  We mark bad tgroups and do not fit
    804   // a zero point for them. Instead we will fit those exposures or images separately
    805   if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_GOOD_NIGHT) {
    806     int bad = myTGroup->flags & ID_IMAGE_NIGHT_POOR;
    807     if (bad) return TRUE;
    808   }
     765  off_t j;
     766
     767  // calculate the statistics for both good and bad nights, but only set Mcal for the good nights
     768  // we only skip the statistics for nights with too few measurements or exposures
    809769
    810770  FitDataSet *psfStars = &info->psfStars;
     
    815775  assert (Ngrp < NtgroupTimes);
    816776
    817   // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used
    818   getimages (&NimageReal, NULL);
    819 
    820777  int Nsecfilt = GetPhotcodeNsecfilt ();
    821778
    822   int testImage = FALSE;
    823779  TGTimes *tgroup = (TGTimes *) myTGroup->parent;
    824780  double mjdStart = ohana_sec_to_mjd (tgroup->start);
     
    827783  myTGroup->flags &= ~ID_IMAGE_TGROUP_PHOTCAL;
    828784 
    829   // testImage = TRUE;
    830   testImage |= (abs(mjdStart - 57353) < 0.1);
    831   testImage |= (abs(mjdStart - 57952) < 0.1);
    832   testImage |= (abs(mjdStart - 55843) < 0.1);
    833   testImage |= (abs(mjdStart - 56586) < 0.1);
    834   testImage |= (abs(mjdStart - 57323) < 0.1);
    835   //testImage |= (abs(mjdStart - 57971) < 0.1);
    836   //testImage |= (abs(mjdStart - 57974) < 0.1);
    837   //testImage |= (abs(mjdStart - 57978) < 0.1);
    838   //testImage |= (abs(mjdStart - 57981) < 0.1);
     785  // in clean_tgroups (run on each iteration), we identify good and bad tgroups.  We mark
     786  // bad tgroups and do not save a zero point for them. Instead we will fit those
     787  // exposures or images separately
     788  int useMgrp = TRUE; 
     789  if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_GOOD_NIGHT) {
     790    if (myTGroup->flags & ID_IMAGE_NIGHT_POOR) useMgrp = FALSE;
     791  }
     792
     793  // for testing, supply the MJD of a night or nights here to dump the full list of measurements
     794  int testImage = FALSE;
     795  // testImage |= (abs(mjdStart - 57353) < 0.1);
    839796
    840797  FILE *fout = NULL;
     
    905862    float MsysKron = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_KRON);
    906863
    907     // XXX byCode : here we are only checking for equiv photcodes (not active photcodes)
     864    // here we are only checking for equiv photcodes (not active photcodes)
    908865    PhotCode *code = GetPhotcodebyCode (catalog[c].measureT[m].photcode);
    909866    if (!code) goto skip;
     
    942899  }
    943900
    944   /* too few good measurements or too many bad measurements (skip in PoorImages run) */
     901  /* skip nights with too few good measurements or too many bad measurements */
    945902  int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure);
    946903  if (mark) {
    947     if (TRUE) {
    948       TGTimes *mygroup = (TGTimes *) myTGroup->parent;
    949       if (0) { // XXX EAM
    950         fprintf (stderr, "marked tgroup %f,%d, (%d < %d) || (%d < %f*"OFF_T_FMT")\n", ohana_sec_to_mjd(mygroup->start), myTGroup->photcode, N, NIGHT_TOOFEW, N, NIGHT_GOOD_FRACTION, myTGroup->Nmeasure);
    951       }
    952     }
    953904    myTGroup->flags |= ID_IMAGE_PHOTOM_FEW;
     905    myTGroup->McalPSF    = 0.0;
     906    myTGroup->McalAPER   = 0.0;
     907    myTGroup->dMcal      = NAN;
     908    myTGroup->stdev      = NAN;
     909    myTGroup->dMmin      = NAN;
     910    myTGroup->dMmax      = NAN;
     911    myTGroup->McalChiSq  = NAN;
     912    myTGroup->nFitPhotom = 0;
    954913    myTGroup->nValPhotom = N;
     914    myTGroup->dKlam      = (TGROUP_FIT_AIRMASS) ? psfStars->bSaveArray[1][0] : 0;
    955915    info->Nfew ++;
    956916    if (testImage) {
     
    986946
    987947  fit1d_irls (psfStars, N);
    988 
    989   // if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mgrp: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
    990 
    991   // for now, I have no reason to measure these separately for camera-level images
    992   myTGroup->McalPSF    = psfStars->bSaveArray[0][0];
     948  fit1d_irls (kronStars, N);
     949  fit1d_irls (brightStars, Nbright);
     950
     951  if (useMgrp) {
     952    myTGroup->McalPSF    = psfStars->bSaveArray[0][0];
     953    myTGroup->McalAPER   = kronStars->bSaveArray[0][0];   // XXX this does not make sense: I need to apply the airmass slope calculated above first
     954    myTGroup->flags |= ID_IMAGE_TGROUP_PHOTCAL;  // set this flag (unset by default)
     955  } else {
     956    myTGroup->McalPSF    = 0.0;
     957    myTGroup->McalAPER   = 0.0;
     958  }
     959
     960  // record statistics on the fit regardless if it is used or not
    993961  myTGroup->dMcal      = psfStars->bSigma[0];
    994962  myTGroup->stdev      = psfStars->sigma;
     
    1000968  myTGroup->dKlam      = (TGROUP_FIT_AIRMASS) ? psfStars->bSaveArray[1][0] : 0;
    1001969
    1002   // XXX this does not make sense: I need to apply the airmass slope calculated above first
    1003   fit1d_irls (kronStars, N);
    1004   myTGroup->McalAPER   = kronStars->bSaveArray[0][0];
     970  // bright end scatter (systematic error)
     971  myTGroup->dMsys = brightStars->sigma;
    1005972
    1006973  if (testImage) {
    1007974    TGTimes *parent = (TGTimes *) myTGroup->parent;
    1008975    fprintf (stderr, "test night %.0f aper: %f %f %d ... ", ohana_sec_to_mjd(parent->start), myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom);
     976    fprintf (stderr, "%f %f  :  %f\n", myTGroup->McalPSF, myTGroup->dMsys, myTGroup->McalChiSq);
    1009977  }
    1010978  if (PLOTSTUFF) {
    1011979    fprintf (stderr, "Mgrp: %6.3f +/- %6.3f %5d of %5d | %.0f\n", myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom, N, ohana_sec_to_mjd(tgroup->start));
    1012980    plot_setMcal (psfStars->alldata->yVector, N);
    1013   }
    1014 
    1015   // bright end scatter
    1016   // XXX this does not make sense: I need to apply the airmass slope calculated above first
    1017   // redo this by calculating the corrected bright stars mags
    1018   fit1d_irls (brightStars, Nbright);
    1019   myTGroup->dMsys = brightStars->sigma;
    1020 
    1021   // keep this??
    1022   if (myTGroup->McalPSF < -CLOUD_TOLERANCE) {
    1023     myTGroup->McalPSF = 0.0;
    1024   }
    1025 
    1026   myTGroup->flags |= ID_IMAGE_TGROUP_PHOTCAL;  // set this flag
    1027 
    1028   if (testImage) {
    1029     fprintf (stderr, "%f %f  :  %f\n", myTGroup->McalPSF, myTGroup->dMsys, myTGroup->McalChiSq);
    1030981  }
    1031982
     
    10701021}
    10711022
    1072 int setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     1023int setMgrp_threaded (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    10731024
    10741025  int i;
     
    10771028  Image *image = getimages (&N, NULL);
    10781029
    1079   fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
    1080 
    10811030  off_t Nmax = 0;
    10821031  for (off_t i = 0; i < NtgroupTimes; i++) {
     
    10881037
    10891038  SetMgrpInfo summary;
    1090   SetMgrpInfoInit (&summary, Nmax, FALSE, PoorImages);
     1039  SetMgrpInfoInit (&summary, Nmax, FALSE);
    10911040
    10921041  pthread_attr_t attr;
     
    11121061    threadinfo[i].flatcorr = flatcorr;
    11131062
    1114     // we do NOT allocate the arrays here, we only supply basic info (Nmax,
    1115     // PoorImages) used in the threads to allocate the arrays and set the MaxIterations
    1116     SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages);
     1063    // we do NOT allocate the arrays here, we only supply basic info used in the threads
     1064    // to allocate the arrays and set the MaxIterations
     1065    SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE);
    11171066    pthread_create (&threads[i], NULL, setMgrp_worker, &threadinfo[i]);
    11181067  }
     
    11691118
    11701119  SetMgrpInfo results;
    1171   SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages); // allocate list, dlist arrays here
     1120  SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE); // allocate list, dlist arrays here
    11721121
    11731122  while (1) {
     
    11941143}
    11951144
    1196 // XXX should I split these stats out by photcode?
    1197 // XXX double check the IMAGE_BAD filter:
    11981145StatType statsTGroupM (Catalog *catalog) {
    11991146  OHANA_UNUSED_PARAM(catalog);
     
    12091156  ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes);
    12101157
    1211   // is ID_IMAGE_PHOTOM_POOR used for tgroups?
    1212   int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR;
     1158  int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW;
    12131159
    12141160  int n = 0;
     
    13161262  ALLOCATE (slist, double, NtgroupTimes*Nphotcodes);
    13171263
     1264  // measure the good/bad statistics using nights which are actually calibrated
     1265  // but they will be applied to all nights below (allowing bad nights to become good)
    13181266  int N = 0;
    13191267  for (int i = 0; i < NtgroupTimes; i++) {
    13201268    TGroup *tgroup = tgroupTimes[i][0].byCode;
    13211269    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
    1322       if (tgroup[j].flags & IMAGE_BAD) continue;
     1270      if (!(tgroup[j].flags & ID_IMAGE_TGROUP_PHOTCAL)) continue;
    13231271      mlist[N] = tgroup[j].McalChiSq;
    13241272      slist[N] = tgroup[j].stdev; // stdev of all measurements
    1325    // slist[N] = tgroup[j].dMsys; // stdev of bright measurements
    13261273      N++;
    13271274    }
     
    14911438}
    14921439
     1440// temporary test output
    14931441void dump_tgroups (Catalog *catalog, int Npass) {
    14941442
     
    16061554  fclose (fout);
    16071555}
     1556
     1557/*
     1558  for testing, put lines like these in relphot_images.c within the iteration loop
     1559      dump_tgroups (catalog, i + 40);
     1560      dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog
     1561      dump_tgroup_imstats (i + 40);
     1562*/
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r41555 r41556  
    4141  load_images (&db, skylist, &UserPatch, FALSE, USE_ALL_IMAGES);
    4242  MARKTIME("-- load images: %f sec\n", dtime);
    43 
    44   // checkImages("load images");
    4543
    4644  /* unlock, if we can (else, unlocked below) */
     
    6361    /* add in a loop over the catalogs calling dvo_catalog_chipcoords */
    6462
    65     // checkImages("load catalog");
    66 
    6763    /* match measurements with images, mosaics */
    6864    initImageBins  (catalog, Ncatalog, TRUE);
     
    8783
    8884    setExclusions (catalog, Ncatalog, TRUE);
    89     // checkImages("set Exclu");
    9085
    9186    global_stats (catalog, Ncatalog, flatcorr, 0);
     
    118113      SetZptIteration (i);
    119114
    120       dump_tgroups (catalog, i);
    121       dump_catalog (catalog, 0, i); // for a test, just dump a specific catalog
    122       dump_tgroup_imstats (i);
    123 
    124115      setMrel  (catalog, Ncatalog, flatcorr); // threaded
    125       setMcalTest (catalog, flatcorr);
    126 
    127       dump_tgroups (catalog, i + 20);
    128       dump_catalog (catalog, 0, i + 20); // for a test, just dump a specific catalog
    129       dump_tgroup_imstats (i + 20);
    130 
    131       setMcal  (catalog, FALSE, flatcorr);
    132       setMmos  (catalog, FALSE, flatcorr);
    133       setMgrp  (catalog, FALSE, flatcorr);
    134       dump_tgroups (catalog, i + 40);
    135       dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog
    136       dump_tgroup_imstats (i + 40);
     116
     117      setMcal  (catalog, flatcorr);
     118      setMmos  (catalog, flatcorr);
     119      setMgrp  (catalog, flatcorr);
    137120
    138121      setMgrid (catalog, flatcorr);
     
    166149    if (USE_GRID) dump_grid ();
    167150
    168     /* set Mcal & Mmos for bad images */
    169     int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;
    170     onlyPoorImages = FALSE; // XXX deactivate for now
    171     setMcal  (catalog, onlyPoorImages, flatcorr); // max loop since this is a final pass
    172     setMmos  (catalog, onlyPoorImages, flatcorr); // max loop since this is a final pass
    173     setMgrp  (catalog, onlyPoorImages, flatcorr); // max loop since this is a final pass
    174151    MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
    175152
     
    177154    setMcalFromTGroups (); // copy per-tgroup calibrations to the images
    178155
    179     if (SAVE_IMAGE_UPDATES) {
    180 
    181       FITS_DB dbX;
    182       off_t *LineNumber;
    183       Image *image, *subset;
    184       off_t Nimage, Nsubset, i, Nx;
    185       char filename[1024];
    186 
    187       gfits_db_init (&dbX);
    188       dbX.lockstate = LCK_XCLD;
    189       dbX.timeout   = 60.0;
    190       dbX.mode      = db.mode;
    191       dbX.format    = db.format;
    192 
    193       snprintf (filename, 1024, "%s.bck", ImageCat);
    194       if (!gfits_db_lock (&dbX, filename)) {
    195         fprintf (stderr, "can't lock backup image image catalog\n");
    196         return (FALSE);
    197       }
    198    
    199       // apply the changes from the image subset to the full table:
    200 
    201       // convert database table to internal structure (binary to Image)
    202       // 'image' points to the same memory as db->ftable->buffer
    203       image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    204       if (!image) {
    205         fprintf (stderr, "ERROR: failed to read images\n");
    206         exit (2);
    207       }
    208       gfits_scan (db.ftable.header, "NAXIS1", OFF_T_FMT, 1,  &Nx);
    209 
    210       subset = getimages (&Nsubset, &LineNumber);
    211       for (i = 0; i < Nsubset; i++) {
    212         if (LineNumber[i] == -1) continue;
    213         memcpy (&image[LineNumber[i]], &subset[i], Nx);
    214       }
    215 
    216       // copy Images.dat data (all or only the subset / vtable elements?)  I think I need to dump
    217       // the entire Image table, but with the updates in place I think this says: re-work the
    218       // ftable/vtable usage in this program to be more sensible...
    219       gfits_copy_header (&db.header,  &dbX.header);
    220       gfits_copy_matrix (&db.matrix,  &dbX.matrix);
    221       gfits_copy_header (&db.theader, &dbX.theader);
    222       gfits_copy_ftable (&db.ftable,  &dbX.ftable);
    223 
    224       dbX.ftable.header = &dbX.theader;
    225       dbX.virtual = FALSE;
    226 
    227       // save Images.dat using the copied structure
    228       if (UPDATE_CATFORMAT) {
    229         // ensure the db format is updated
    230         dbX.format = dvo_catalog_catformat (UPDATE_CATFORMAT);
    231         gfits_modify (&dbX.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT);
    232 
    233         char photcodeFile[1024];
    234         sprintf (photcodeFile, "%s/Photcodes.dat", CATDIR);
    235         SavePhotcodesFITS (photcodeFile);
    236       }
    237       dvo_image_save (&dbX, VERBOSE);
    238       dvo_image_unlock (&dbX);
    239       gfits_db_free (&dbX);
    240       MARKTIME("-- save Image.dat.bck: %f sec\n", dtime);
    241     }
     156    // calculate and save per-chip residuals here:
     157    MagResidSave ("mag.resid.fits", catalog);
     158
     159    save_images_updates (&db);
    242160
    243161    /* at this point, we have correct cal coeffs in the image/mosaic structures */
  • trunk/Ohana/src/relphot/src/relphot_parallel_images.c

    r41473 r41556  
    112112
    113113    // set the image (Mcal) and mosaic (Mmos) zero point offsets given the mean mags and measurements
    114     setMcal  (catalog, FALSE, flatcorr);
    115     setMmos  (catalog, FALSE, flatcorr);
     114    setMcal  (catalog, flatcorr);
     115    setMmos  (catalog, flatcorr);
    116116    // setMgrp  (catalog, FALSE, flatcorr); XXX think this through: this may not make sense for tgroups
    117117    MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime);
     
    144144  client_logger_message ("all hosts are done the loops\n");
    145145
    146   /* set Mcal & Mmos for bad images (for stack_and_warps, force images to be measured) */
    147   int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;
    148   setMcal  (catalog, onlyPoorImages, flatcorr);
    149   setMmos  (catalog, onlyPoorImages, flatcorr);
    150   // setMgrp  (catalog, onlyPoorImages, flatcorr); XXX see above
    151146  MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
    152147
  • trunk/Ohana/src/relphot/src/relphot_parallel_regions.c

    r40291 r41556  
    11# include "relphot.h"
    2 int save_images_backup (FITS_DB *db);
    32
    43int relphot_parallel_regions (SkyTable *sky) {
     
    101100  return TRUE;
    102101}
    103 
    104 int save_images_backup (FITS_DB *db) {
    105 
    106   FITS_DB dbX;
    107   char filename[1024];
    108 
    109   INITTIME;
    110 
    111   gfits_db_init (&dbX);
    112   dbX.lockstate = LCK_XCLD;
    113   dbX.timeout   = 60.0;
    114   dbX.mode      = db->mode;
    115   dbX.format    = db->format;
    116 
    117   snprintf (filename, 1024, "%s.bck", ImageCat);
    118   if (!gfits_db_lock (&dbX, filename)) {
    119     fprintf (stderr, "can't lock backup image image catalog\n");
    120     return (FALSE);
    121   }
    122    
    123   // copy Images.dat data (all or only the subset / vtable elements?)  I think I need to dump
    124   // the entire Image table, but with the updates in place I think this says: re-work the
    125   // ftable/vtable usage in this program to be more sensible...
    126   gfits_copy_header (&db->header,  &dbX.header);
    127   gfits_copy_matrix (&db->matrix,  &dbX.matrix);
    128   gfits_copy_header (&db->theader, &dbX.theader);
    129   gfits_copy_ftable (&db->ftable,  &dbX.ftable);
    130 
    131   dbX.ftable.header = &dbX.theader;
    132 
    133   dvo_image_save (&dbX, VERBOSE);
    134   dvo_image_unlock (&dbX);
    135   MARKTIME("-- save Image.dat.bck: %f sec\n", dtime);
    136 
    137   gfits_db_free (&dbX);
    138   return TRUE;
    139 }
Note: See TracChangeset for help on using the changeset viewer.