IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41462 for trunk


Ignore:
Timestamp:
Jan 4, 2021, 4:33:51 PM (6 years ago)
Author:
eugene
Message:

substantial updates to the zero point statistics analysis

Location:
trunk/Ohana/src/relphot
Files:
1 added
17 edited

Legend:

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

    r41453 r41462  
    7777$(SRC)/indexCatalog.$(ARCH).o    \
    7878$(SRC)/client_logger.$(ARCH).o   \
     79$(SRC)/ZeroPointModes.$(ARCH).o  \
    7980$(SRC)/setExclusions.$(ARCH).o   \
    8081$(SRC)/setMrelFinal.$(ARCH).o    \
     
    124125$(SRC)/synthetic_zpts.$(ARCH).o  \
    125126$(SRC)/client_logger.$(ARCH).o   \
     127$(SRC)/ZeroPointModes.$(ARCH).o  \
    126128$(SRC)/setExclusions.$(ARCH).o   \
    127129$(SRC)/setMrelFinal.$(ARCH).o    \
     
    143145TEST_FITIRLS = \
    144146$(SRC)/fit1d_irls.$(ARCH).o      \
     147$(SRC)/extra.$(ARCH).o  \
    145148$(SRC)/test_fitirls.$(ARCH).o
    146149
  • trunk/Ohana/src/relphot/include/relphot.h

    r41453 r41462  
    8484  float secz;
    8585  float ubercalDist;
    86   unsigned short nFitPhotom;
     86  unsigned int nFitPhotom;
     87  unsigned int nValPhotom;
    8788  unsigned int flags;
    8889  char skipCal;               // if TRUE, this mosaic is incomplete and should not be calibrated
     90  char inTGroup;
    8991  Coords coords;
    9092} Mosaic;
     
    9799  float dMcal;
    98100  float dMsys;
     101  float stdev;
    99102  float McalChiSq;
    100   unsigned short nFitPhotom;
     103  unsigned int nFitPhotom;
     104  unsigned int nValPhotom;
    101105  unsigned int flags;
    102106
     
    109113  off_t *measure;
    110114  off_t *catalog;
     115
     116  off_t Nmosaic;
     117  off_t NMOSAIC;
     118  Mosaic **mosaic; // pointer to the mosaic structures
    111119
    112120  void *parent;
     
    185193  int     Nlist;              // total number of measurements in list (may be more than the number to use)
    186194  int     Nbootstrap;         // number of bootstrap iterations
     195  int     MaxIterations;      // number of IRLS iterations
    187196
    188197  // input data & parameters:
     
    387396int    VERBOSE2;
    388397int    VERBOSE_IMAGE;
     398
    389399int    MOSAIC_ZEROPT;
    390400int    TGROUP_ZEROPT;
     401
     402int    FREEZE_IMAGES;
     403int    FREEZE_MOSAICS;
     404
    391405int    TGROUP_FIT_AIRMASS;
    392406
     
    414428double IMAGE_GOOD_FRACTION;
    415429int    IMAGE_BAD;
    416 int    FREEZE_IMAGES;
    417 int    FREEZE_MOSAICS;
    418430int    CALIBRATE_STACKS_AND_WARPS;
    419431int    USE_GRID;
     
    461473SkyRegion UserPatch;
    462474char *UserCatalog;
     475
     476enum {TGROUP_ZPT_MODE_NONE, TGROUP_ZPT_MODE_GOOD_NIGHT, TGROUP_ZPT_MODE_ALL, };
     477int TGROUP_ZPT_MODE;
     478
     479enum {MOSAIC_ZPT_MODE_NONE, MOSAIC_ZPT_MODE_BAD_NIGHT, MOSAIC_ZPT_MODE_GOOD_MOSAIC, MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC, MOSAIC_ZPT_MODE_ALL, };
     480int MOSAIC_ZPT_MODE;
     481
     482enum {IMAGE_ZPT_MODE_NONE, IMAGE_ZPT_MODE_BAD_NIGHT, IMAGE_ZPT_MODE_BAD_MOSAIC, IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC, IMAGE_ZPT_MODE_ALL, };
     483int IMAGE_ZPT_MODE;
    463484
    464485int USE_ALL_IMAGES;
     
    526547float         getMgrid            PROTO((off_t meas, int cat));
    527548float         getMmos             PROTO((off_t meas, int cat));
    528 float         getMgrp             PROTO((off_t meas, int cat, float airmass));
     549float         getMgrp             PROTO((off_t meas, int cat, float airmass, float *dZpt));
    529550float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source));
    530551short         getUbercalDist      PROTO((off_t meas, int cat));
     
    601622int           reload_images       PROTO((FITS_DB *db));
    602623int           setExclusions       PROTO((Catalog *catalog, int Ncatalog, int verbose));
    603 void          setMcal             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
     624void          setMgrid            PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
    604625void          setMcalFromMosaics  PROTO((void));
    605626void          setMcalFromTGroups  PROTO((void));
    606627int           setMcalOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
    607 void          setMgrid            PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
    608 int           setMmos             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
    609 int           setMgrp             PROTO((Catalog *catalog, int Poor, FlatCorrectionTable *flatcorr));
     628
     629void          setMcal             PROTO((Catalog *catalog, int Nloop, int Poor, FlatCorrectionTable *flatcorr));
     630int           setMmos             PROTO((Catalog *catalog, int Nloop, int Poor, FlatCorrectionTable *flatcorr));
     631int           setMgrp             PROTO((Catalog *catalog, int Nloop, int Poor, FlatCorrectionTable *flatcorr));
     632
    610633int           setMrel             PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
    611634void          setMrelFinal        PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr, int simpleAverage));
    612635int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
     636
    613637int           setMave             PROTO((Catalog *catalog, int Ncatalog));
    614638void          set_ZP              PROTO((double ZERO));
     
    627651StatType      statsMosaicX        PROTO((Catalog *catalog));
    628652StatType      statsMosaicdM       PROTO((Catalog *catalog));
     653StatType      statsTGroupM        PROTO((Catalog *catalog));
     654StatType      statsTGroupX        PROTO((Catalog *catalog));
     655StatType      statsTGroupdM       PROTO((Catalog *catalog));
     656
    629657StatType      statsStarN          PROTO((Catalog *catalog, int Ncatalog, int Nsec, int seccode, FlatCorrectionTable *flatcorr));
    630658StatType      statsStarS          PROTO((Catalog *catalog, int Ncatalog, int Nsec));
     
    795823
    796824int save_images_backup (FITS_DB *db);
     825
     826void dump_tgroups (Catalog *catalog, int Npass);
     827void dump_catalog (Catalog *catalog, off_t c, int Npass);
     828
     829void SetZeroPointModes (int nloop);
  • trunk/Ohana/src/relphot/src/GridOps.c

    r41390 r41462  
    415415
    416416        // skip mosaics marked as BAD
    417         Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     417        Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    418418        if (isnan(Mgrp)) {
    419419          Ngrp ++;
     
    575575        continue;
    576576      }
    577       Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     577      Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    578578      if (isnan(Mgrp)) {
    579579        Ngrp ++;
     
    661661      Mmos  = getMmos  (m, c);
    662662      if (isnan(Mmos)) continue;
    663       Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     663      Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    664664      if (isnan(Mgrp)) continue;
    665665      Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r41453 r41462  
    581581
    582582/* determine Mcal values for all images */
    583 void setMcal (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     583void setMcal (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) {
    584584
    585585  off_t i, j, m, c, n;
    586586  int mark, bad, Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys;
    587587
    588   // FREEZE_IMAGES only applies to mosaic data (eg, gpc1)
     588  if (IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_NONE) return;
    589589
    590590  fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
     
    609609  FitDataSetAlloc (&brightStars, Nmax, 0, 0);
    610610
     611  // until the analysis has converged a bit, do not use the IRLS analysis
     612  if (Nloop < 3) {
     613    brightStars.MaxIterations = 0;
     614    kronStars.MaxIterations = 0;
     615    psfStars.MaxIterations = 0;
     616  }
     617
     618
    611619  Nfew = Nbad = Nmos = Ngrp = Ngrid = Nrel = Nsys = 0;
    612620
     
    627635    }     
    628636
    629     // only freeze the gpc1 chips
    630     // XXX : when do we FREEZE_IMAGES in a mix of GPC1, GPC2, etc?
    631     // if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    632     if (FREEZE_IMAGES) continue;
     637    // if requested, freeze mosaic chips:
     638    if (FREEZE_IMAGES && isMosaicChip (image[i].photcode)) continue;
    633639    if (image[i].photcode == 0) continue; // skip the PHU images
     640
     641    int badNight  = (image[i].flags & ID_IMAGE_NIGHT_POOR);
     642    int badMosaic = (image[i].flags & ID_IMAGE_MOSAIC_POOR);
     643
     644    // in BAD_NIGHT mode, we fit ONLY images in bad nights
     645    if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT)) {
     646      if (!badNight) continue;
     647    }
     648
     649    // in BAD_NIGHT_BAD_MOSAIC mode, we fit ONLY bad mosaics in bad nights
     650    if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC)) {
     651      if (!badNight) continue;
     652      if (!badMosaic) continue;
     653    }
     654
     655    // in BAD_MOSAIC mode, we fit bad mosaics ignoring night state
     656    if ((IMAGE_ZPT_MODE == IMAGE_ZPT_MODE_BAD_MOSAIC)) {
     657      if (badMosaic) continue;
     658    }
    634659
    635660    // UBERCAL image: if this is an ubercal image, set minUbercalDist to 0:
     
    665690          continue;
    666691      }
    667       float Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     692      float Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL); // ignore error for now?
    668693      if (isnan(Mgrp)) {
    669694          Ngrp ++;
     
    10271052      Mmos  = getMmos  (m, c);
    10281053      if (isnan(Mmos)) continue;
    1029       Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1054      Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    10301055      if (isnan(Mgrp)) continue;
    10311056      Mgrid = getMgrid (m, c);
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r41454 r41462  
    1010// relationships between the mosaics and their associated images
    1111static off_t   *MosaicN_Image; // number of images associated with the given mosaic
    12 static off_t  **MosaicToImage; // list of imagesa associated with the given mosaic
     12static off_t  **MosaicToImage; // list of images associated with the given mosaic
    1313
    1414// mosaic index for given image : ImageToMosaic[ImageIndex] = MosaicIndex (ImageIndex : 0 < Nimage)
     
    219219    mosaic[i].photcode  = 0;
    220220    mosaic[i].skipCal   = FALSE;
     221    mosaic[i].inTGroup  = FALSE; // not (yet?) assigned to a TGroup
    221222   
    222223    memset (&mosaic[i].coords, 0, sizeof(Coords));
     
    301302    mosaic[j].dMcal     = 0.0;
    302303    mosaic[j].McalChiSq = 0.0;
     304
     305    mosaic[j].nFitPhotom = 0;
     306    mosaic[j].nValPhotom = 0;
    303307
    304308    mosaic[j].dMsys     = subset[i].flags;
     
    750754}
    751755
     756void markBadMosaic (int myMosaic) {
     757
     758  off_t Nimage;
     759  Image *image;
     760
     761  // this mosaic has been identified as poor.
     762  mosaic[myMosaic].flags |= ID_IMAGE_PHOTOM_POOR;
     763  mosaic[myMosaic].McalPSF  = 0.0;
     764  mosaic[myMosaic].McalAPER = 0.0;
     765
     766  image = getimages (&Nimage, NULL);
     767
     768  // all images should be marked as coming from a bad mosaic
     769  // these will be fitted independently
     770  for (off_t i = 0; i < MosaicN_Image[myMosaic]; i++) {
     771    off_t im = MosaicToImage[myMosaic][i];
     772    image[im].flags |= ID_IMAGE_MOSAIC_POOR;
     773  }
     774}
     775
     776void markGoodMosaic (int myMosaic) {
     777
     778  off_t Nimage;
     779  Image *image;
     780
     781  // this mosaic has been identified as good.
     782  mosaic[myMosaic].flags &= ~ID_IMAGE_PHOTOM_POOR;
     783
     784  image = getimages (&Nimage, NULL);
     785
     786  // all images should be marked as NOT coming from a bad mosaic
     787  for (off_t i = 0; i < MosaicN_Image[myMosaic]; i++) {
     788    off_t im = MosaicToImage[myMosaic][i];
     789    image[im].flags &= ~ID_IMAGE_MOSAIC_POOR;
     790  }
     791}
     792
    752793void initMosaicBins (Catalog *catalog, int Ncatalog, int doMosaicList) {
    753794
     
    923964  int Nsys;
    924965  int Nskip;
     966  int Nloop;
    925967  off_t Nmax;
    926968  int PoorImages;
     
    943985int setMmos_mosaic (Mosaic *mosaic, off_t Nmos, Image *image, Catalog *catalog, SetMmosInfo *info, FlatCorrectionTable *flatcorr);
    944986void *setMmos_worker (void *data);
    945 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr);
    946 
    947 void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists, int PoorImages) {
     987int setMmos_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr);
     988
     989void SetMmosInfoInit (SetMmosInfo *info, off_t Nmax, int allocLists, int PoorImages, int Nloop) {
    948990  info->Nfew = 0;
    949991  info->Nbad = 0;
     
    955997
    956998  info->Nmax = Nmax;
     999  info->Nloop = Nloop;
    9571000  info->PoorImages = PoorImages;
    9581001
     
    9621005    FitDataSetAlloc (&info->kronStars,   Nmax, 0, 0);
    9631006    FitDataSetAlloc (&info->brightStars, Nmax, 0, 0);
     1007
     1008    // until the analysis has converged a bit, do not use the IRLS analysis
     1009    if (Nloop < 3) {
     1010      info->brightStars.MaxIterations = 0;
     1011      info->kronStars.MaxIterations = 0;
     1012      info->psfStars.MaxIterations = 0;
     1013    }
    9641014  }
    9651015}
     
    10031053}
    10041054
    1005 int setMmos (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     1055int setMmos (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) {
    10061056
    10071057  off_t i, N, Nmax;
    10081058  Image *image;
    10091059
    1010   if (!MOSAIC_ZEROPT) return (FALSE);
    1011   if (FREEZE_MOSAICS) return (FALSE);
     1060  if (!MOSAIC_ZEROPT) return FALSE;
     1061  if (FREEZE_MOSAICS) return FALSE;
     1062
     1063  if (MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_NONE) return FALSE;
    10121064
    10131065  // plots cannot be done in a threaded context (the plot commands collide)
    10141066  // so do not run setMmos in threaded mode if PLOTSTUFF is set
    10151067  if (NTHREADS && !PLOTSTUFF) {
    1016     int status = setMmos_threaded (catalog, PoorImages, flatcorr);
     1068    int status = setMmos_threaded (catalog, Nloop, PoorImages, flatcorr);
    10171069    return status;
    10181070  }
     
    10341086
    10351087  SetMmosInfo info;
    1036   SetMmosInfoInit (&info, Nmax, TRUE, PoorImages);
     1088  SetMmosInfoInit (&info, Nmax, TRUE, PoorImages, Nloop);
    10371089
    10381090  // int savePlotDelay = PLOTDELAY;
     
    10781130  assert (Nmos >= 0);
    10791131  assert (Nmos < Nmosaic);
     1132
     1133  int badNight  = (myMosaic[0].flags & ID_IMAGE_NIGHT_POOR);
     1134  int badMosaic = (myMosaic[0].flags & ID_IMAGE_MOSAIC_POOR);
     1135
     1136  // if we are fitting TGroup zero points, when we identify the bad TGroups, we proceed
     1137  // to fit the mosaics which are from the bad TGroups
     1138
     1139  // if we are fitting Mosaic zero points, when we identify the bad nights, we proceed
     1140  // to fit the images which are from the bad Mosaics
     1141
     1142  // in BAD_NIGHT mode, we fit ONLY mosaics in bad nights
     1143  if (MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT) {
     1144    if (!badNight) return TRUE;
     1145  }
     1146
     1147  // in BAD_NIGHT_GOOD_MOSAIC mode, we fit ONLY good mosaics in bad nights
     1148  if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC)) {
     1149    if (!badNight) return TRUE;
     1150    if (badMosaic) return TRUE;
     1151  }
     1152
     1153  // in GOOD_MOSAIC mode, we fit good mosaics ignoring night state
     1154  if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_GOOD_MOSAIC)) {
     1155    if (badMosaic) return TRUE;
     1156  }
    10801157
    10811158  // Image *imageReal = getimages (&NimageReal, NULL); returned pointer is not used
     
    11401217    if (fout) {
    11411218      float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);
    1142       // float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1219      // float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    11431220      float Mgrid    = getMgrid (m, c);
    11441221      float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     
    11641241      continue;
    11651242    }
    1166     float Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1243    float Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    11671244    if (isnan(Mgrp)) {
    11681245      info->Ngrp++;
     
    12571334  myMosaic[0].McalChiSq  = psfStars->chisq;         
    12581335  myMosaic[0].nFitPhotom = psfStars->Nmeas;         
     1336  myMosaic[0].nValPhotom = N;       
    12591337
    12601338  // fit1d_irls (kronStars, N);    // does it make sense to calculate a zero point based kron mags?
     
    12961374}
    12971375 
    1298 int setMmos_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     1376int setMmos_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) {
    12991377
    13001378  int i;
     
    13171395
    13181396  SetMmosInfo summary;
    1319   SetMmosInfoInit (&summary, Nmax, FALSE, PoorImages);
     1397  SetMmosInfoInit (&summary, Nmax, FALSE, PoorImages, Nloop);
    13201398
    13211399  pthread_attr_t attr;
     
    13401418    threadinfo[i].image    =    image;
    13411419    threadinfo[i].flatcorr = flatcorr;
    1342     SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages);
     1420
     1421    // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop,
     1422    // PoorImages) used in the threads to allocate the arrays and set the MaxIterations
     1423    SetMmosInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages, Nloop);
    13431424    pthread_create (&threads[i], NULL, setMmos_worker, &threadinfo[i]);
    13441425  }
     
    13981479
    13991480  SetMmosInfo results;
    1400   SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages); // allocate list, dlist arrays here
     1481  SetMmosInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages, threadinfo->info.Nloop);
    14011482
    14021483  while (1) {
     
    17091790      Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    17101791      if (isnan(Mcal)) continue;
    1711       Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
     1792      Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
    17121793      if (isnan(Mgrp)) continue;
    17131794      Mgrid = getMgrid (m, c);
     
    17671848void clean_mosaics () {
    17681849
    1769   off_t i, N, mark, Nmark, Nscatter, Noffset;
     1850  off_t i, N, mark, Ntotal, Nmark, Nscatter, Noffset, Nrejects, Nchisq;
    17701851  double *mlist, *slist, *dlist;
    17711852  double MaxOffset, MedOffset, MaxScatter;
     
    18001881  fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);
    18011882 
    1802   Nmark = Nscatter = Noffset = 0;
     1883  // XXX this needs to be configurable
     1884  float MaxChiSq = 10.0;
     1885
     1886  Ntotal = Nmark = Nscatter = Noffset = Nrejects = Nchisq = 0;
    18031887  for (i = 0; i < Nmosaic; i++) {
    18041888    // if we are keeping ubercal sacrosanct, then we should not be allowed to break them...
    18051889    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    18061890
    1807     if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP)) continue;
     1891    Ntotal ++;
     1892
     1893    if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW)) {
     1894      continue;
     1895    }
    18081896    if (mosaic[i].skipCal) continue;
    18091897
     
    18171905      Noffset ++;
    18181906    }
     1907    if (mosaic[i].nFitPhotom < 0.7*mosaic[i].nValPhotom) {
     1908      mark = TRUE;
     1909      Nrejects ++;
     1910    }
     1911    if (mosaic[i].McalChiSq > MaxChiSq) {
     1912      mark = TRUE;
     1913      Nchisq ++;
     1914    }
    18191915    if (mark) {
    18201916      Nmark ++;
    1821       mosaic[i].flags |= ID_IMAGE_PHOTOM_POOR;
     1917      markBadMosaic(i); // mark the images associated with a bad night
    18221918    } else {
    1823       mosaic[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
    1824     }
    1825   }
    1826 
    1827   fprintf (stderr, OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n",  Nmark, Nscatter, Noffset);
     1919      markGoodMosaic(i); // mark the images associated with a good night
     1920    }
     1921  }
     1922
     1923  fprintf (stderr, OFF_T_FMT" of "OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n",  Nmark, Ntotal, Nscatter, Noffset);
    18281924
    18291925  free (mlist);
  • trunk/Ohana/src/relphot/src/StarOps.c

    r41453 r41462  
    493493        float Mmos  = getMmos  (m, i);
    494494        if (isnan(Mmos)) continue;
    495         float Mgrp  = getMgrp  (m, i, catalog[i].measureT[m].airmass);
     495        float Mgrp  = getMgrp  (m, i, catalog[i].measureT[m].airmass, NULL);
    496496        if (isnan(Mgrp)) continue;
    497497        float Mgrid = getMgrid (m, i);
     
    733733          Mmos  = getMmos  (m, i);
    734734          if (isnan(Mmos)) { Nmos ++; continue; }
    735           Mgrp  = getMgrp  (m, i, catalog[i].measureT[m].airmass);
     735          Mgrp  = getMgrp  (m, i, catalog[i].measureT[m].airmass, NULL);
    736736          if (isnan(Mgrp)) { Ngrp ++; continue; }
    737737          Mgrid = getMgrid (m, i);
     
    10821082}
    10831083
     1084void dump_catalog (Catalog *catalog, off_t c, int Npass) {
     1085
     1086  int Nsecfilt = GetPhotcodeNsecfilt ();
     1087
     1088  FILE *fout = NULL;
     1089  char filename[64];
     1090  snprintf (filename, 64, "tcat.%02d.dat", Npass);
     1091  fout = fopen (filename, "w");
     1092
     1093  for (off_t n = 0; n < catalog[c].Naverage; n++) {
     1094
     1095    off_t m = catalog[c].averageT[n].measureOffset;
     1096    for (off_t k = 0; k < catalog[c].averageT[n].Nmeasure; k++, m++) {
     1097
     1098      float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);     // image zero point
     1099      float Mmos     = getMmos  (m, c);                    // mosaic zero point
     1100      float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
     1101
     1102      float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude
     1103      // float Mgrid    = getMgrid (m, c);                    // camera offset (deprecated?)
     1104      // float Mflat    = getMflat (m, c, flatcorr, catalog); // flat-field correction
     1105
     1106      off_t n = catalog[c].measureT[m].averef;
     1107
     1108      // nominal magnitude for this measurement (instrumental + Ko(airmass - 1) + Co
     1109      float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     1110
     1111      // for historical reasons, Mflat is defined with the wrong sign
     1112      float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrp;
     1113
     1114      fprintf (fout, "%f %f : %f %f : %f %f %f  : %f %f\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mmos, Mgrp, catalog[c].measureT[m].airmass, delta);
     1115    }
     1116  }
     1117  fclose (fout);
     1118}
  • trunk/Ohana/src/relphot/src/TGroupOps.c

    r41454 r41462  
    11# include "relphot.h"
     2
     3void assignMosaicsToTGroups (void);
    24
    35// tgroupTimes carries the times of the tgroups (initially, just the photometric nights)
     
    7880      tgroup[j].dMsys     = 0.0;
    7981      tgroup[j].McalChiSq = 0.0; // NAN or 0.0?
     82
     83      tgroup[j].stdev      = NAN;
     84      tgroup[j].nFitPhotom = 0;
     85      tgroup[j].nValPhotom = 0;
     86
    8087      tgroup[j].flags     = ID_IMAGE_PHOTOM_UBERCAL; // we start by treating the suspected photometric nights as photometric
    8188      tgroup[j].photcode  = photcodes[j][0].code;
     
    8592      ALLOCATE (tgroup[j].image, off_t, tgroup[j].NIMAGE);
    8693      tgroup[j].image[0]  = -1;
     94
     95      tgroup[j].NMOSAIC   = 100;
     96      tgroup[j].Nmosaic   = 0;
     97      ALLOCATE (tgroup[j].mosaic, Mosaic *, tgroup[j].NMOSAIC);
    8798
    8899      tgroup[j].Nmeasure  = 0;
     
    129140    tgroup[j].dMsys     = 0.0;
    130141    tgroup[j].McalChiSq = 0.0; // NAN or 0.0?
     142
     143    tgroup[j].stdev      = NAN;
     144    tgroup[j].nFitPhotom = 0;
     145    tgroup[j].nValPhotom = 0;
     146
    131147    tgroup[j].flags     = 0;   // tgroups NOT in the original file are not suspected as photometric
    132148    tgroup[j].photcode  = photcodes[j][0].code;
     149
    133150    tgroup[j].NIMAGE    = 1000;
    134151    tgroup[j].Nimage    = 0;   // the new TGroup is not suspected to be photometric
    135152    ALLOCATE (tgroup[j].image, off_t, tgroup[j].NIMAGE);
    136153    tgroup[j].image[0]  = -1;
     154
     155    tgroup[j].NMOSAIC   = 100;
     156    tgroup[j].Nmosaic   = 0;
     157    ALLOCATE (tgroup[j].mosaic, Mosaic *, tgroup[j].NMOSAIC);
     158
    137159    tgroup[j].Nmeasure  = 0;
    138160    tgroup[j].NMEASURE  = 1000;
     
    199221  }
    200222
     223  // assign the mosaics to each tgroup -- we do this by image
     224  assignMosaicsToTGroups ();
     225
    201226  initTGroupsMcal ();
    202227
     
    215240    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
    216241      free (tgroup[j].image);
     242      free (tgroup[j].mosaic);
    217243      free (tgroup[j].measure);
    218244      free (tgroup[j].catalog);
     
    249275      tgroup[j].dMsys     = 0.0;
    250276      tgroup[j].McalChiSq = 0.0;// NAN or 0.0?
     277
     278      tgroup[j].stdev      = NAN;
     279      tgroup[j].nFitPhotom = 0;
     280      tgroup[j].nValPhotom = 0;
    251281
    252282      if (tgroup[j].Nimage == 0) continue; // no images, ignore the tgroup
     
    278308}
    279309
     310void assignMosaicsToTGroups (void) {
     311
     312  if (!TGROUP_ZEROPT) return;
     313
     314  // init the tgroup array values
     315  for (int i = 0; i < NtgroupTimes; i++) {
     316    TGroup *tgroup = tgroupTimes[i][0].byCode;
     317    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
     318
     319      if (tgroup[j].Nimage == 0) continue; // no images, ignore the tgroup
     320
     321      // find the mosaics by image (if MOSAIC_ZEROPT is active)
     322      for (int im = 0; MOSAIC_ZEROPT && (im < tgroup[j].Nimage); im++) {
     323        int imageIdx = tgroup[j].image[im];
     324        Mosaic *mosaic = getMosaicForImage (imageIdx);
     325
     326        if (mosaic->inTGroup) continue;
     327
     328        // mosaic to tgroup and extend as needed
     329        tgroup[j].mosaic[tgroup[j].Nmosaic] = mosaic;
     330        mosaic->inTGroup = TRUE;
     331
     332        // advance array and extend if needed
     333        tgroup[j].Nmosaic ++;
     334        if (tgroup[j].Nmosaic >= tgroup[j].NMOSAIC) {
     335          tgroup[j].NMOSAIC += 100;
     336          REALLOCATE (tgroup[j].mosaic, Mosaic *, tgroup[j].NMOSAIC);
     337        }
     338      }
     339    }
     340  }
     341  return;
     342}
     343
    280344TGroup *getTGroupForImage (off_t im) {
    281345
     
    345409
    346410  fprintf (stderr, "*** return Mcal from tgroup.Mcal to image.Mcal ***\n");
     411
     412  // NOTE: nights which are poor should have had Mcal set to 0, making this a NOP for those nights
    347413
    348414  // copy the tgroup results to the images.  set the tgroup Mcal to 0.0 since we have moved its
     
    360426        image[im].dMagSys     = tgroup[i].dMsys;
    361427        image[im].nFitPhotom  = tgroup[i].nFitPhotom;
     428        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_NIGHT_POOR); // XXX copy this down?
     429        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_MOSAIC_POOR); // XXX copy this down?
    362430        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_PHOTOM_FEW);
    363431        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_PHOTOM_POOR);
     
    371439    }
    372440  }     
     441}
     442
     443void markBadTGroup (TGroup *tgroup) {
     444
     445  off_t Nimage;
     446  Image *image;
     447
     448  // this tgroup has been identified as poor.
     449  tgroup->flags |= ID_IMAGE_NIGHT_POOR;
     450
     451  // all associated mosaics should be marked as coming from a bad night
     452  // these will be fitted independently
     453  for (off_t j = 0; j < tgroup->Nmosaic; j++) {
     454    tgroup->mosaic[j]->flags |= ID_IMAGE_NIGHT_POOR;
     455  }
     456
     457  // all associated images should be marked as coming from a bad night
     458  // these will be fitted independently
     459  image = getimages (&Nimage, NULL);
     460  for (off_t j = 0; j < tgroup->Nimage; j++) {
     461    off_t im = tgroup->image[j];
     462    image[im].flags |= ID_IMAGE_NIGHT_POOR;
     463  }
     464
     465  tgroup->McalPSF  = 0.0;
     466  tgroup->McalAPER = 0.0;
     467  tgroup->dKlam    = 0.0;
     468}
     469
     470void markGoodTGroup (TGroup *tgroup) {
     471
     472  off_t Nimage;
     473  Image *image;
     474
     475  // this tgroup has been identified as good.
     476  tgroup->flags &= ~ID_IMAGE_NIGHT_POOR;
     477
     478  // all associated mosaics should be marked as NOT coming from a bad night
     479  for (off_t j = 0; j < tgroup->Nmosaic; j++) {
     480    tgroup->mosaic[j]->flags &= ~ID_IMAGE_NIGHT_POOR;
     481  }
     482
     483  // all associated images should be marked as NOT coming from a bad night
     484  image = getimages (&Nimage, NULL);
     485  for (off_t j = 0; j < tgroup->Nimage; j++) {
     486    off_t im = tgroup->image[j];
     487    image[im].flags &= ~ID_IMAGE_NIGHT_POOR;
     488  }
    373489}
    374490
     
    488604}
    489605
    490 float getMgrp (off_t meas, int cat, float airmass) {
    491 
    492   float value;
    493 
    494   if (!TGROUP_ZEROPT) return (0);
     606// XXX return the error as well as the value
     607float getMgrp (off_t meas, int cat, float airmass, float *dZpt) {
     608
     609  if (dZpt) { *dZpt = 0; }
     610
     611  if (!TGROUP_ZEROPT) return 0.0;
    495612
    496613  // unassigned measurements belong to simple chips
    497614  TGroup *myGroup = MeasureToTGroup[cat][meas];
    498   if (!myGroup) return (0.0);
    499 
    500   // if (myGroup->flags & IMAGE_BAD) return (NAN); 
    501   value = myGroup->McalPSF + myGroup->dKlam*(airmass - 1.0);
    502   return (value);
     615  if (!myGroup) return 0.0;
     616
     617  float value = myGroup->McalPSF + myGroup->dKlam*(airmass - 1.0);
     618  if (dZpt) { *dZpt = myGroup->dMcal; }
     619  return value;
    503620}
    504621
     
    525642  int Nsys;
    526643  int Nskip;
     644  int Nloop;
    527645  off_t Nmax;
    528646  int PoorImages;
     
    545663int   setMgrp_tgroup (TGroup *tgroup, off_t Nmos, Image *image, Catalog *catalog, SetMgrpInfo *info, FlatCorrectionTable *flatcorr);
    546664void *setMgrp_worker (void *data);
    547 int   setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr);
    548 
    549 void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists, int PoorImages) {
     665int   setMgrp_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr);
     666
     667void SetMgrpInfoInit (SetMgrpInfo *info, off_t Nmax, int allocLists, int PoorImages, int Nloop) {
    550668  info->Nfew = 0;
    551669  info->Nbad = 0;
     
    558676
    559677  info->Nmax = Nmax;
     678  info->Nloop = Nloop;
    560679  info->PoorImages = PoorImages;
    561680
     
    567686    FitDataSetAlloc (&info->brightStars, Nmax, fitOrder, 0);
    568687
     688    // until the analysis has converged a bit, do not use the IRLS analysis
     689    if (Nloop < 100) {
     690      info->brightStars.MaxIterations = 0;
     691      info->kronStars.MaxIterations = 0;
     692      info->psfStars.MaxIterations = 0;
     693    }
    569694    if (1) {
    570695      FitDataSetAddPriors (&info->psfStars);
     
    614739}
    615740
    616 int setMgrp (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     741int setMgrp (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) {
    617742
    618743  off_t N;
     
    620745
    621746  if (!TGROUP_ZEROPT) return (FALSE);
     747  if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_NONE) return (FALSE);
    622748
    623749  // plots cannot be done in a threaded context (the plot commands collide)
    624750  // so do not run setMgrp in threaded mode if PLOTSTUFF is set
    625751  if (NTHREADS && !PLOTSTUFF) {
    626     int status = setMgrp_threaded (catalog, PoorImages, flatcorr);
     752    int status = setMgrp_threaded (catalog, Nloop, PoorImages, flatcorr);
    627753    return status;
    628754  }
    629755
    630756  image = getimages (&N, NULL);
    631 
    632   if (PoorImages) {
    633     // XXX use bad stars and measurements for PoorImages? or not?
    634     // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;
    635     IMAGE_BAD = 0;
    636   }
    637757
    638758  off_t Nmax = 0;
     
    645765
    646766  SetMgrpInfo info;
    647   SetMgrpInfoInit (&info, Nmax, TRUE, PoorImages);
    648 
    649   // int savePlotDelay = PLOTDELAY;
    650   // if (PLOTSTUFF) PLOTDELAY = 0.0;
     767  SetMgrpInfoInit (&info, Nmax, TRUE, PoorImages, Nloop);
    651768
    652769  for (off_t i = 0; i < NtgroupTimes; i++) {
     
    654771    for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
    655772      setMgrp_tgroup (&tgroup[j], i, image, catalog, &info, flatcorr);
    656       fprintf (stderr, "TGROUP time %.0f photcode %d Mcal: %f, dK: %f, dMcal: %f, 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, CLOUD_TOLERANCE);
     773      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);
    657774    }
    658775  }
     
    668785  fprintf (stderr, "%d tgroups 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);
    669786
    670   if (PoorImages) {
    671     IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
    672     STAR_BAD  = ID_OBJ_POOR | ID_OBJ_FEW;
    673     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
    674   }
    675787  return (TRUE);
    676788}
     
    684796  off_t j, NimageReal;
    685797
    686   /* on PoorImages run, skip good images */
    687   if (info->PoorImages) {
    688     int bad = myTGroup->flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);
    689     if (!bad) return TRUE;
    690   }     
     798  // At some point, we identify good and bad tgroups.  We mark bad tgroups and do not fit
     799  // a zero point for them. Instead we will fit those exposures or images separately
     800  if (TGROUP_ZPT_MODE == TGROUP_ZPT_MODE_GOOD_NIGHT) {
     801    int bad = myTGroup->flags & ID_IMAGE_NIGHT_POOR;
     802    if (bad) return TRUE;
     803  }
    691804
    692805  FitDataSet *psfStars = &info->psfStars;
     
    704817  int testImage = FALSE;
    705818  TGTimes *tgroup = (TGTimes *) myTGroup->parent;
    706   testImage |= (abs(tgroup->start - 1245283200) < 10);
     819  // testImage |= (abs(tgroup->start - 1245283200) < 10);
     820  // testImage = TRUE;
    707821
    708822  FILE *fout = NULL;
     
    825939
    826940  /* too few good measurements or too many bad measurements (skip in PoorImages run) */
    827   if (!info->PoorImages) {
    828     int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure);
    829     if (mark) {
    830       if (VERBOSE2) {
    831         TGTimes *mygroup = (TGTimes *) myTGroup->parent;
    832         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);
    833       }
    834       myTGroup->flags |= ID_IMAGE_PHOTOM_FEW;
    835       info->Nfew ++;
    836       if (testImage) {
    837         fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) NIGHT_TOOFEW, (int) (NIGHT_GOOD_FRACTION*myTGroup->Nmeasure));
    838       }
    839     } else {
    840       myTGroup->flags &= ~ID_IMAGE_PHOTOM_FEW;
    841     }
     941  int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure);
     942  if (mark) {
     943    if (VERBOSE2) {
     944      TGTimes *mygroup = (TGTimes *) myTGroup->parent;
     945      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);
     946    }
     947    myTGroup->flags |= ID_IMAGE_PHOTOM_FEW;
     948    info->Nfew ++;
     949    if (testImage) {
     950      fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) NIGHT_TOOFEW, (int) (NIGHT_GOOD_FRACTION*myTGroup->Nmeasure));
     951    }
     952  } else {
     953    myTGroup->flags &= ~ID_IMAGE_PHOTOM_FEW;
    842954  }
    843955
     
    852964  myTGroup->McalPSF    = psfStars->bSaveArray[0][0];
    853965  myTGroup->dMcal      = psfStars->bSigma[0];
     966  myTGroup->stdev      = psfStars->sigma;
    854967  myTGroup->McalChiSq  = psfStars->chisq;
    855968  myTGroup->nFitPhotom = psfStars->Nmeas;
     969  myTGroup->nValPhotom = N;
    856970  myTGroup->dKlam      = psfStars->bSaveArray[1][0];
    857971
     
    864978    fprintf (stderr, "test night %.0f aper: %f %f %d ... ", ohana_sec_to_mjd(parent->start), myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom);
    865979  }
     980
     981  // fprintf (stderr, "Mgrp: %6.3f +/- %6.3f %5d of %5d | %.2f %.0f\n", myTGroup->McalPSF, myTGroup->dMcal, myTGroup->nFitPhotom, myTGroup->nValPhotom, myTGroup->McalChiSq, ohana_sec_to_mjd(tgroup->start));
    866982
    867983  if (PLOTSTUFF) {
     
    8851001  }
    8861002
    887   // FitDataSetFree (&brightStars);
    888   // FitDataSetFree (&kronStars);
    889   // FitDataSetFree (&psfStars);
    890 
    8911003  return TRUE;
    8921004}
    8931005 
    894 int setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
     1006int setMgrp_threaded (Catalog *catalog, int Nloop, int PoorImages, FlatCorrectionTable *flatcorr) {
    8951007
    8961008  int i;
     
    9011013  fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
    9021014
    903   if (PoorImages) {
    904     // XXX use bad stars and measurements for PoorImages? or not?
    905     // IMAGE_BAD = STAR_BAD = MEAS_BAD = 0;
    906     IMAGE_BAD = 0;
    907   }
    908 
    9091015  off_t Nmax = 0;
    9101016  for (off_t i = 0; i < NtgroupTimes; i++) {
     
    9161022
    9171023  SetMgrpInfo summary;
    918   SetMgrpInfoInit (&summary, Nmax, FALSE, PoorImages);
     1024  SetMgrpInfoInit (&summary, Nmax, FALSE, PoorImages, Nloop);
    9191025
    9201026  pthread_attr_t attr;
     
    9391045    threadinfo[i].image    =    image;
    9401046    threadinfo[i].flatcorr = flatcorr;
    941     SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages);
     1047
     1048    // we do NOT allocate the arrays here, we only supply basic info (Nmax, Nloop,
     1049    // PoorImages) used in the threads to allocate the arrays and set the MaxIterations
     1050    SetMgrpInfoInit (&threadinfo[i].info, Nmax, FALSE, PoorImages, Nloop);
    9421051    pthread_create (&threads[i], NULL, setMgrp_worker, &threadinfo[i]);
    9431052  }
     
    9861095  npass_output ++;
    9871096
    988   if (PoorImages) {
    989     IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
    990     STAR_BAD  = ID_OBJ_POOR | ID_OBJ_FEW;
    991     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
    992   }
    9931097  return TRUE;
    9941098}
     
    9991103
    10001104  SetMgrpInfo results;
    1001   SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages); // allocate list, dlist arrays here
     1105  SetMgrpInfoInit (&results, threadinfo->info.Nmax, TRUE, threadinfo->info.PoorImages, threadinfo->info.Nloop); // allocate list, dlist arrays here
    10021106
    10031107  while (1) {
     
    10241128}
    10251129
    1026 # if (0)
     1130// XXX should I split these stats out by photcode?
     1131// XXX double check the IMAGE_BAD filter:
    10271132StatType statsTGroupM (Catalog *catalog) {
    10281133  OHANA_UNUSED_PARAM(catalog);
    10291134
    1030   off_t i;
    1031   int n;
    10321135  double *list, *dlist;
    10331136  StatType stats;
     
    10371140
    10381141  // XXX do this by time & photcode?
    1039   ALLOCATE (list, double, Ntgroup);
    1040   ALLOCATE (dlist, double, Ntgroup);
    1041 
    1042   n = 0;
     1142  ALLOCATE (list, double, NtgroupTimes*Nphotcodes);
     1143  ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes);
     1144
     1145  // is ID_IMAGE_PHOTOM_POOR used for tgroups?
     1146  int NIGHT_BAD = ID_IMAGE_NIGHT_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR;
     1147
     1148  int n = 0;
    10431149  for (int i = 0; i < NtgroupTimes; i++) {
    10441150    TGroup *tgroup = tgroupTimes[i][0].byCode;
    10451151    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
    1046       if (tgroup[j].flags & IMAGE_BAD) continue;
     1152      if (tgroup[j].flags & NIGHT_BAD) continue;
    10471153      list[n] = tgroup[j].McalPSF;
    10481154      dlist[n] = 1;
     
    10621168  OHANA_UNUSED_PARAM(catalog);
    10631169
    1064   off_t i, n;
    10651170  double *list, *dlist;
    10661171  StatType stats;
     
    10691174  if (!TGROUP_ZEROPT) return (stats);
    10701175
    1071   ALLOCATE (list, double, Ntgroup);
    1072   ALLOCATE (dlist, double, Ntgroup);
    1073 
    1074   n = 0;
    1075   for (i = 0; i < Ntgroup; i++) {
    1076     if (tgroup[i].flags & IMAGE_BAD) continue;
    1077     list[n] = tgroup[i].dMcal;
    1078     dlist[n] = 1;
    1079     n++;
     1176  ALLOCATE (list, double, NtgroupTimes*Nphotcodes);
     1177  ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes);
     1178
     1179  int n = 0;
     1180  for (int i = 0; i < NtgroupTimes; i++) {
     1181    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1182    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1183      if (tgroup[j].flags & IMAGE_BAD) continue;
     1184      list[n] = tgroup[j].dMcal;
     1185      dlist[n] = 1;
     1186      n++;
     1187    }
    10801188  }
    10811189
     
    10881196}
    10891197
    1090 StatType statsTGroupN (Catalog *catalog, FlatCorrectionTable *flatcorr) {
    1091 
    1092   off_t i, j, m, c, n, N;
     1198StatType statsTGroupX (Catalog *catalog) {
     1199  OHANA_UNUSED_PARAM(catalog);
     1200
    10931201  double *list, *dlist;
    1094   float Mcal, Mgrid, Mrel, Mmos;
    10951202  StatType stats;
    10961203
     
    10981205  if (!TGROUP_ZEROPT) return (stats);
    10991206
    1100   ALLOCATE (list, double, Ntgroup);
    1101   ALLOCATE (dlist, double, Ntgroup);
    1102 
    1103   n = 0;
    1104   for (i = 0; i < Ntgroup; i++) {
    1105     if (tgroup[i].flags & IMAGE_BAD)  continue;
    1106 
    1107     N = 0;
    1108     for (j = 0; j < tgroup[i].Nmeasure; j++) {
    1109 
    1110       m = tgroup[i].measure[j];
    1111       c = tgroup[i].catalog[j];
    1112 
    1113       Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    1114       if (isnan(Mcal)) continue;
    1115       Mmos = getMmos  (m, c);
    1116       if (isnan(Mmos)) continue;
    1117       Mgrid = getMgrid (m, c);
    1118       if (isnan(Mgrid)) continue;
    1119       Mrel = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    1120       if (isnan(Mrel)) continue;
    1121       N++;
    1122     }
    1123     list[n] = N;
    1124     dlist[n] = 1;
    1125     n++;
    1126   }
    1127   // fprintf (stderr, "Ntgroup: "OFF_T_FMT", n: "OFF_T_FMT"\n",  Ntgroup,  n);
     1207  ALLOCATE (list, double, NtgroupTimes*Nphotcodes);
     1208  ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes);
     1209
     1210  int n = 0;
     1211  for (int i = 0; i < NtgroupTimes; i++) {
     1212    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1213    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1214      if (tgroup[j].flags & IMAGE_BAD) continue;
     1215      list[n] = tgroup[j].McalChiSq;
     1216      dlist[n] = 1;
     1217      n++;
     1218    }
     1219  }
    11281220
    11291221  liststats_setmode (&stats, "MEAN");
     
    11351227}
    11361228
    1137 StatType statsTGroupX (Catalog *catalog) {
    1138   OHANA_UNUSED_PARAM(catalog);
    1139 
    1140   off_t i, n;
    1141   double *list, *dlist;
    1142   StatType stats;
    1143 
    1144   bzero (&stats, sizeof (StatType));
    1145   if (!TGROUP_ZEROPT) return (stats);
    1146 
    1147   ALLOCATE (list, double, Ntgroup);
    1148   ALLOCATE (dlist, double, Ntgroup);
    1149 
    1150   n = 0;
    1151   for (i = 0; i < Ntgroup; i++) {
    1152     if (tgroup[i].flags & IMAGE_BAD) continue;
    1153     if (KEEP_UBERCAL && (tgroup[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    1154 
    1155     list[n]  = tgroup[i].McalChiSq;
    1156     dlist[n] = 1;
    1157     n++;
    1158   }
    1159 
    1160   liststats_setmode (&stats, "MEAN");
    1161 
    1162   liststats (list, dlist, NULL, n, &stats);
    1163   free (list);
    1164   free (dlist);
    1165   return (stats);
    1166 }
    1167 # endif
    1168 
    11691229/* mark tgroup if: abs(Mcal - <Mcal>) too large, dMcal too large */
    11701230void clean_tgroups () {
    11711231
    1172   off_t i, N, mark, Nmark, Nscatter, Noffset;
     1232  off_t mark, Ntotal, Nmark, Nscatter, Noffset, Nrejects, Nchisq;
    11731233  double *mlist, *slist, *dlist;
    11741234  double MaxOffset, MedOffset, MaxScatter;
     
    11821242  ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes);
    11831243
    1184   for (i = N = 0; i < NtgroupTimes; i++) {
     1244  int N = 0;
     1245  for (int i = 0; i < NtgroupTimes; i++) {
    11851246    TGroup *tgroup = tgroupTimes[i][0].byCode;
    11861247    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
     
    11971258
    11981259  liststats (mlist, dlist, NULL, N, &stats);
    1199   MaxOffset = MAX (NIGHT_OFFSET, 2*stats.sigma);
     1260  MaxOffset = MAX (NIGHT_OFFSET, 3*stats.sigma);
    12001261  MedOffset = stats.median;
    12011262
    12021263  liststats (slist, dlist, NULL, N, &stats);
    12031264  MaxScatter = MAX (NIGHT_SCATTER, 2*stats.median);
    1204   fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);
     1265  fprintf (stderr, "TGROUPS: median Mrel: %f, median dMrel: %f, Max Offset: %f, Max Scatter: %f\n", MedOffset, stats.median, MaxOffset, MaxScatter);
    12051266 
    1206   Nmark = Nscatter = Noffset = 0;
    1207   for (i = 0; i < NtgroupTimes; i++) {
     1267  // XXX this needs to be configurable
     1268  float MaxChiSq = 10.0;
     1269
     1270  Ntotal = Nmark = Nscatter = Noffset = Nrejects = Nchisq = 0;
     1271  for (int i = 0; i < NtgroupTimes; i++) {
    12081272    TGroup *tgroup = tgroupTimes[i][0].byCode;
    12091273    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
    1210       // if we are keeping ubercal sacrosanct, then we should not be allowed to break them...
    1211       if (KEEP_UBERCAL && (tgroup[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    12121274     
    1213       if (tgroup[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP)) continue;
     1275      Ntotal ++;
     1276
     1277      // ignore the nights with too few measurements
     1278      // XXX what to do with nights with too few measurements?
     1279      // XXX probably free the images to be fitted
     1280      if (tgroup[j].flags & ID_IMAGE_PHOTOM_FEW) {
     1281        markBadTGroup(&tgroup[j]); // mark the image associated with a bad night
     1282        continue;
     1283      }
    12141284     
    12151285      mark = FALSE;
    1216       if (tgroup[i].dMcal > MaxScatter) {
     1286      if (tgroup[j].dMcal > MaxScatter) {
    12171287        mark = TRUE;
    12181288        Nscatter ++;
    12191289      }
    1220       if (fabs(tgroup[i].McalPSF - MedOffset) > MaxOffset) {
     1290      if (fabs(tgroup[j].McalPSF - MedOffset) > MaxOffset) {
    12211291        mark = TRUE;
    12221292        Noffset ++;
    12231293      }
     1294      if (tgroup[j].nFitPhotom < 0.7*tgroup[j].nValPhotom) {
     1295        mark = TRUE;
     1296        Nrejects ++;
     1297      }
     1298      if (tgroup[j].McalChiSq > MaxChiSq) {
     1299        mark = TRUE;
     1300        Nchisq ++;
     1301      }
    12241302      if (mark) {
    12251303        Nmark ++;
    1226         tgroup[i].flags |= ID_IMAGE_PHOTOM_POOR;
     1304        markBadTGroup(&tgroup[j]); // mark the tgroup & associated images & mosaics with a bad night
    12271305      } else {
    1228         tgroup[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
     1306        markGoodTGroup(&tgroup[j]); // mark the tgroup & associated images & mosaics with a good night
    12291307      }
    1230       // XXX : unset the ubercal flag if we mark the night as bad?
    1231     }
    1232   }
    1233 
    1234   fprintf (stderr, OFF_T_FMT" tgroups marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n",  Nmark, Nscatter, Noffset);
     1308    }
     1309  }
     1310
     1311  fprintf (stderr, OFF_T_FMT" of "OFF_T_FMT" tgroups marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset, "OFF_T_FMT" rejects, "OFF_T_FMT" chisq)\n",  Nmark, Ntotal, Nscatter, Noffset, Nrejects, Nchisq);
    12351312
    12361313  free (mlist);
     
    13471424}
    13481425
     1426void dump_tgroups (Catalog *catalog, int Npass) {
     1427
     1428  int Nsecfilt = GetPhotcodeNsecfilt ();
     1429
     1430  int Ngrp = 0;
     1431  for (off_t i = 0; i < NtgroupTimes; i++) {
     1432
     1433    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1434    for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1435
     1436      FILE *fout = NULL;
     1437      char filename[64];
     1438      snprintf (filename, 64, "tgrp.%05d.%02d.dat", Ngrp, Npass);
     1439      fout = fopen (filename, "w");
     1440      Ngrp ++;
     1441
     1442      TGroup *myTGroup = &tgroup[j];
     1443
     1444      for (int k = 0; k < myTGroup->Nmeasure; k++) {
     1445     
     1446        off_t m = myTGroup->measure[k];
     1447        off_t c = myTGroup->catalog[k];
     1448     
     1449        float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);     // image zero point
     1450        float Mmos     = getMmos  (m, c);                    // mosaic zero point
     1451        float Mgrp     = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL);
     1452
     1453        float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude
     1454        // float Mgrid    = getMgrid (m, c);                    // camera offset (deprecated?)
     1455        // float Mflat    = getMflat (m, c, flatcorr, catalog); // flat-field correction
     1456
     1457        off_t n = catalog[c].measureT[m].averef;
     1458
     1459        // nominal magnitude for this measurement (instrumental + Ko(airmass - 1) + Co
     1460        float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     1461
     1462        // for historical reasons, Mflat is defined with the wrong sign
     1463        float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrp;
     1464
     1465        fprintf (fout, "%f %f : %f %f : %f %f %f  : %f %f\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysPSF, MrelPSF, Mcal, Mmos, Mgrp, catalog[c].measureT[m].airmass, delta);
     1466      }
     1467      fclose (fout);
     1468    }
     1469  }
     1470}
  • trunk/Ohana/src/relphot/src/args.c

    r41453 r41462  
    303303  }
    304304
     305  // global restriction on fitting image zero points for mosaic cameras
     306  FREEZE_IMAGES = FALSE;
     307  if ((N = get_argument (argc, argv, "-imfreeze"))) {
     308    remove_argument (N, &argc, argv);
     309    FREEZE_IMAGES = TRUE;
     310  }
     311  // global restriction on fitting mosaic zero points
     312  FREEZE_MOSAICS = FALSE;
     313  if ((N = get_argument (argc, argv, "-mosfreeze"))) {
     314    remove_argument (N, &argc, argv);
     315    FREEZE_MOSAICS = TRUE;
     316  }
     317  CALIBRATE_STACKS_AND_WARPS = FALSE;
     318  if ((N = get_argument (argc, argv, "-only-stacks-and-warps"))) {
     319    remove_argument (N, &argc, argv);
     320    CALIBRATE_STACKS_AND_WARPS = TRUE;
     321  }
     322  USE_MCAL_PSF_FOR_STACK_APER = FALSE;
     323  if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
     324    remove_argument (N, &argc, argv);
     325    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
     326  }
     327
     328
     329  // default behavior is to fit all chips independently
     330  TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE;
     331  MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE;
     332  IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_ALL;
     333
    305334  /* XXX this argument used to do two things: specify the camera name and tell the analysis to
    306335     calculate a common zero point for a single mosaic.  I've moved the MOSAICNAME concept into the
     
    315344      exit (2);
    316345    }
    317   }
    318 
    319   FREEZE_IMAGES = FALSE;
    320   if ((N = get_argument (argc, argv, "-imfreeze"))) {
    321     remove_argument (N, &argc, argv);
    322     FREEZE_IMAGES = TRUE;
    323   }
    324   FREEZE_MOSAICS = FALSE;
    325   if ((N = get_argument (argc, argv, "-mosfreeze"))) {
    326     remove_argument (N, &argc, argv);
    327     FREEZE_MOSAICS = TRUE;
    328   }
    329   CALIBRATE_STACKS_AND_WARPS = FALSE;
    330   if ((N = get_argument (argc, argv, "-only-stacks-and-warps"))) {
    331     remove_argument (N, &argc, argv);
    332     CALIBRATE_STACKS_AND_WARPS = TRUE;
    333   }
    334   USE_MCAL_PSF_FOR_STACK_APER = FALSE;
    335   if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
    336     remove_argument (N, &argc, argv);
    337     USE_MCAL_PSF_FOR_STACK_APER = TRUE;
     346    IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_NONE;
     347    MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_ALL;
    338348  }
    339349
     
    341351  TGROUP_ZEROPT = FALSE;
    342352  char *TGROUP_FILENAME = NULL;
    343   if ((N = get_argument (argc, argv, "-tgroup"))) {
     353  if ((N = get_argument (argc, argv, "-tgroup")) || (N = get_argument (argc, argv, "-tgroups"))) {
    344354    TGROUP_ZEROPT = TRUE;
    345355    remove_argument (N, &argc, argv);
    346356    TGROUP_FILENAME = strcreate(argv[N]);
    347357    remove_argument (N, &argc, argv);
    348     FREEZE_IMAGES = TRUE;
    349   }
    350   if ((N = get_argument (argc, argv, "-tgroups"))) {
    351     if (TGROUP_ZEROPT) {
    352       fprintf (stderr, "use only one of -tgroups and -tgroup (same meaning)\n");
    353       exit (2);
    354     }
    355     TGROUP_ZEROPT = TRUE;
    356     remove_argument (N, &argc, argv);
    357     TGROUP_FILENAME = strcreate(argv[N]);
    358     remove_argument (N, &argc, argv);
    359     FREEZE_IMAGES = TRUE;
     358    // if we fit for TGROUPS, start with the images and mosaics frozen
     359    TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_ALL;
     360    IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_NONE;
     361    MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE;
     362  }
     363  if ((N = get_argument (argc, argv, "-tgroup")) || (N = get_argument (argc, argv, "-tgroups"))) {
     364    fprintf (stderr, "use only one of -tgroups and -tgroup (same meaning)\n");
     365    exit (2);
    360366  }
    361367  TGROUP_FIT_AIRMASS = FALSE;
  • trunk/Ohana/src/relphot/src/extra.c

    r41428 r41462  
    130130}
    131131
     132double weight_cauchy (double x) {
     133  double r = x / 2.385;
     134  return (1.0 / (1.0 + SQ(r)));
     135}
     136
     137double VectorFractionInterpolate (double *values, float fraction, int Npts) {
     138
     139  float F = fraction * Npts;
     140  int   N = fraction * Npts;
     141
     142  if (N < 0        ) return NAN;
     143  if (N >= Npts - 2) return NAN;
     144
     145  // interpolate between N,N+1
     146   
     147  double S = (F - N) * (values[N+1] - values[N]) + values[N];
     148  return S;
     149}
  • trunk/Ohana/src/relphot/src/fit1d_irls.c

    r41453 r41462  
    22
    33// These should probably be tunable:
    4 # define MAX_ITERATIONS 10
    54# define FIT_TOLERANCE 1e-4
    65# define FLT_TOLERANCE 1e-6
     
    3534
    3635  int converged = FALSE;
    37   for (int iterations = 0; !converged && (iterations < MAX_ITERATIONS); iterations++) {
     36  for (int iterations = 0; !converged && (iterations < dataset->MaxIterations); iterations++) {
    3837   
    3938    for (int i = 0; i < Npoints; i++) {
     
    293292  dataset->mterm = 2*order + 1;
    294293  dataset->Nbootstrap = Nbootstrap;
     294  dataset->MaxIterations = 10;
    295295
    296296  // arrays for actual data values
  • trunk/Ohana/src/relphot/src/global_stats.c

    r39357 r41462  
    33void global_stats (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr, int nloop) {
    44
    5   StatType stN, stX, stS, imN, imX, imM, imD, msM, msX, msN, msD;
     5  StatType stN, stX, stS, imN, imX, imM, imD, msM, msX, msN, msD, tgM, tgX, tgD;
    66
    77  liststats_init (&stN);
    88  liststats_init (&stX);
    99  liststats_init (&stS);
     10
    1011  liststats_init (&imN);
    1112  liststats_init (&imX);
    1213  liststats_init (&imM);
    1314  liststats_init (&imD);
     15
    1416  liststats_init (&msN);
    1517  liststats_init (&msX);
     
    1719  liststats_init (&msD);
    1820
    19   // INITTIME;
     21  liststats_init (&tgX);
     22  liststats_init (&tgM);
     23  liststats_init (&tgD);
    2024
    2125  fprintf (stderr, "\n");
     
    2933    int seccode = photcodes[Ns][0].code;
    3034
    31     // MARKTIME("start star stats: %f sec\n", dtime);
    3235    stN = statsStarN (catalog, Ncatalog, Nsec, seccode, flatcorr);
    33     // MARKTIME("done star N: %f sec\n", dtime);
    3436    stX = statsStarX (catalog, Ncatalog, Nsec);
    35     // MARKTIME("done star X: %f sec\n", dtime);
    3637    stS = statsStarS (catalog, Ncatalog, Nsec);
    37     // MARKTIME("done star S: %f sec\n", dtime);
    3838 
    3939    fprintf (stderr, "   --- stats for %s ---\n", photcodes[Ns][0].name);
     
    5353  msX = statsMosaicX (catalog);
    5454 
     55  tgM = statsMosaicM (catalog);
     56  tgD = statsMosaicdM (catalog);
     57  tgX = statsMosaicX (catalog);
     58 
    5559  fprintf (stderr, "meas / image:   %7.0f  %7.0f  %7.0f  %7.0f  %7.0f  %6d\n",   imN.median, imN.mean, imN.sigma, imN.min, imN.max, imN.Nmeas);
    5660  fprintf (stderr, "Mcal image:     %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   imM.median, imM.mean, imM.sigma, imM.min, imM.max, imM.Nmeas);
     
    6266  fprintf (stderr, "dMcal mosaic:   %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   msD.median, msD.mean, msD.sigma, msD.min, msD.max, msD.Nmeas);
    6367  fprintf (stderr, "chisq mosaic:   %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas);
     68
     69  fprintf (stderr, "Mcal  tgroup:   %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   tgM.median, tgM.mean, tgM.sigma, tgM.min, tgM.max, tgM.Nmeas);
     70  fprintf (stderr, "dMcal tgroup:   %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   tgD.median, tgD.mean, tgD.sigma, tgD.min, tgD.max, tgD.Nmeas);
     71  fprintf (stderr, "chisq tgroup:   %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   tgX.median, tgX.mean, tgX.sigma, tgX.min, tgX.max, tgX.Nmeas);
    6472}
    6573
  • trunk/Ohana/src/relphot/src/liststats.c

    r41453 r41462  
    417417}
    418418
    419 double weight_cauchy (double x) {
    420   double r = x / 2.385;
    421   return (1.0 / (1.0 + SQ(r)));
    422 }
    423 
    424 double VectorFractionInterpolate (double *values, float fraction, int Npts) {
    425 
    426   float F = fraction * Npts;
    427   int   N = fraction * Npts;
    428 
    429   if (N < 0        ) return NAN;
    430   if (N >= Npts - 2) return NAN;
    431 
    432   // interpolate between N,N+1
    433    
    434   double S = (F - N) * (values[N+1] - values[N]) + values[N];
    435   return S;
    436 }
    437 
    438419// we could define the weight to be the only scale factor:
    439420// \mu      = \sum (value_i * weight_i) / \sum (weight_i)
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r41390 r41462  
    116116    /* determine fit values */
    117117    for (i = 0; i < NLOOP; i++) {
    118       if (PLOTSTUFF) {
    119         plot_scatter (catalog, Ncatalog, flatcorr);
    120       }
    121       if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog);
    122       // checkImages("start loop");
     118      dump_tgroups (catalog, i);
     119      dump_catalog (catalog, 0, i); // for a test, just dump a specific catalog
    123120
    124121      setMrel  (catalog, Ncatalog, flatcorr); // threaded
    125       if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog);
    126       // checkImages("set Mrel");
    127 
    128       if (PLOTSTUFF) {
    129         plot_scatter (catalog, Ncatalog, flatcorr);
    130       }
    131       setMcal  (catalog, FALSE, flatcorr);
    132       // checkImages("set Mcal");
    133       if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog);
    134 
    135       setMmos  (catalog, FALSE, flatcorr);
    136       setMgrp  (catalog, FALSE, flatcorr);
     122      dump_tgroups (catalog, i + 20);
     123      dump_catalog (catalog, 0, i + 20); // for a test, just dump a specific catalog
     124
     125      setMcal  (catalog, i, FALSE, flatcorr);
     126      setMmos  (catalog, i, FALSE, flatcorr);
     127      setMgrp  (catalog, i, FALSE, flatcorr);
     128      dump_tgroups (catalog, i + 40);
     129      dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog
    137130
    138131      setMgrid (catalog, flatcorr);
     
    147140        plot_chisq (catalog, Ncatalog);
    148141      }
    149       // if (i < NLOOP - 1) rationalize_mosaics (catalog, Ncatalog);
    150       // if (i % 6 == 1) rationalize_images ();
    151 
    152       // NOTE : in the past, I was not iterating enough before cleaning.  make sure we do
    153       // at least 8 loops first -- that should get the systematic errors down to the ~1%
    154       // level, even in cases where we have an even split between photometric data and
    155       // data with 1 mag of extinction.
    156 
    157       if ((i > 8) && (i % 8 == 2)) clean_measures (catalog, Ncatalog, FALSE, flatcorr);
    158       if ((i > 8) && (i % 8 == 3)) clean_stars (catalog, Ncatalog);
    159       if ((i > 8) && (i % 8 == 5)) clean_mosaics ();
    160       if ((i > 8) && (i % 8 == 5)) clean_tgroups ();
    161       if ((i > 8) && (i % 8 == 5)) clean_images ();
    162142
    163143      global_stats (catalog, Ncatalog, flatcorr, i);
     144
     145      SetZeroPointModes (i);
    164146      MARKTIME("-- finished loop %d: %f sec\n", i, dtime);
     147      fprintf (stderr, "----- continue loop %d -----\n", i);
    165148    }
    166149
     
    178161    /* set Mcal & Mmos for bad images */
    179162    int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;
    180     setMcal  (catalog, onlyPoorImages, flatcorr);
    181     setMmos  (catalog, onlyPoorImages, flatcorr);
    182     setMgrp  (catalog, onlyPoorImages, flatcorr);
     163    onlyPoorImages = FALSE; // XXX deactivate for now
     164    setMcal  (catalog, 999, onlyPoorImages, flatcorr); // max loop since this is a final pass
     165    setMmos  (catalog, 999, onlyPoorImages, flatcorr); // max loop since this is a final pass
     166    setMgrp  (catalog, 999, onlyPoorImages, flatcorr); // max loop since this is a final pass
    183167    MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
    184168
  • trunk/Ohana/src/relphot/src/relphot_parallel_images.c

    r41390 r41462  
    114114
    115115    // set the image (Mcal) and mosaic (Mmos) zero point offsets given the mean mags and measurements
    116     setMcal  (catalog, FALSE, flatcorr);
    117     setMmos  (catalog, FALSE, flatcorr);
     116    setMcal  (catalog, i, FALSE, flatcorr);
     117    setMmos  (catalog, i, FALSE, flatcorr);
    118118    // setMgrp  (catalog, FALSE, flatcorr); XXX think this through: this may not make sense for tgroups
    119119    MARKTIME("-- set Mrel, Mcal, Mmos, Mgrid : %f sec\n", dtime);
     
    151151  /* set Mcal & Mmos for bad images (for stack_and_warps, force images to be measured) */
    152152  int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;
    153   setMcal  (catalog, onlyPoorImages, flatcorr);
    154   setMmos  (catalog, onlyPoorImages, flatcorr);
     153  setMcal  (catalog, 999, onlyPoorImages, flatcorr);
     154  setMmos  (catalog, 999, onlyPoorImages, flatcorr);
    155155  // setMgrp  (catalog, onlyPoorImages, flatcorr); XXX see above
    156156  MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
  • trunk/Ohana/src/relphot/src/setMrelCatalog.c

    r41453 r41462  
    99# endif
    1010
     11int magStatsByRanking (StatDataSet *dataset, StatType *stats);
    1112int magStatsByRankingClipped (StatDataSet *dataset, StatType *stats);
    1213int magStatsByRankingIRLS (StatDataSet *dataset, StatType *stats);
     
    1718int liststats_irls (StatDataSet *dataset, int Npoints, StatType *stats);
    1819
    19 # define MAG_STATS_BY_RANKING magStatsByRankingIRLS
     20// # define MAG_STATS_BY_RANKING magStatsByRankingIRLS
     21# define MAG_STATS_BY_RANKING magStatsByRanking
    2022
    2123# define UBERCAL_WEIGHT 100.0
     
    5658}
    5759
     60FILE *TESTFILE = NULL;
     61
    5862int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    5963
     
    6771  SetMrelInfoReset (results); // reset the counters
    6872
     73  TESTFILE = fopen ("mytest.dat", "w");
     74 
    6975  for (j = 0; j < catalog[Nc].Naverage; j++) {
    7076
     
    8389    }
    8490  }
     91
     92  fclose (TESTFILE);
    8593  return (TRUE);
    8694}
     
    222230    // ** Choose the calibration (depends on the mode : do I have an image reference or not?)
    223231    float Mcal = 0.0, Mmos = 0.0, Mgrid = 0.0, Mflat = 0.0, Mgrp = 0.0;
     232    float dMgrp = 0.0;
    224233    off_t meas = measureOffset + k;
    225234    if (getImageEntry (meas, cat) < 0) {
     
    235244      Mmos  = getMmos  (meas, cat);
    236245      if (isnan(Mmos))  SKIP_THIS_MEAS(Nmos);
    237       Mgrp  = getMgrp  (meas, cat, measureT[k].airmass);
     246      Mgrp  = getMgrp  (meas, cat, measureT[k].airmass, &dMgrp);
    238247      if (isnan(Mgrp))  SKIP_THIS_MEAS(Ngrp);
    239248      Mgrid = getMgrid (meas, cat);
     
    251260    int useUbercalWeight = isUbercal || (refPhotcode && (code->code == refPhotcode->code));
    252261
     262    // combine the various errors in quadrature here:
     263    float dMsys = hypot (code->photomErrSys, dMgrp);
     264
    253265    float Map  = NAN;
    254266    float dMap = NAN;
     
    258270      // NOTE: for PV3, apFluxErr is broken (see pmSourcePhotometry.c:245).  we are going to
    259271      // use PSF flux error instead here:
    260       // dMap = MAX (hypot(measure[k].dMap,   code->photomErrSys), MIN_ERROR);
    261       dMap = MAX (hypot(measure[k].dM,   code->photomErrSys), MIN_ERROR);
     272      // dMap = MAX (hypot(measure[k].dMap,   dMsys), MIN_ERROR);
     273      dMap = MAX (hypot(measure[k].dM,   dMsys), MIN_ERROR);
    262274
    263275      if (CHECK_VALID_MAG(Map, dMap)) {
     
    277289    float dMkron;
    278290    if (isSetMrelFinal) {
    279       dMkron = MAX (hypot(measure[k].dMkron, code->photomErrSys), MIN_ERROR);
     291      dMkron = MAX (hypot(measure[k].dMkron, dMsys), MIN_ERROR);
    280292    } else {
    281       dMkron = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
     293      dMkron = MAX (hypot(measureT[k].dM, dMsys), MIN_ERROR);
    282294    }
    283295    if (CHECK_VALID_MAG(Mkron, dMkron)) {
     
    293305
    294306    float Mpsf = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF);
    295     float dMpsf  = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
     307    float dMpsf  = MAX (hypot(measureT[k].dM, dMsys), MIN_ERROR);
    296308    if (CHECK_VALID_MAG(Mpsf, dMpsf)) {
    297309      int Npsf = results->psfData[Nsec].Nlist;
     
    401413      secfilt[Nsec].dMpsfChp = psfstats->error;
    402414      secfilt[Nsec].Mchisq   = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
     415      fprintf (TESTFILE, "%d %d : %d : %f %f : %f\n", cat, (int) ave, NrankingPSF, psfstats->mean, psfstats->median, psfstats->mean - psfstats->median);
    403416    }
    404417
  • trunk/Ohana/src/relphot/src/test_fitirls.c

    r41453 r41462  
    55int main (int argc, char **argv) {
    66 
    7   int Ntests     =  100;
    8   int Npoints    =  100;
    9   int Noutliers  =   10;
    10   int Nbootstrap =  100;
     7  int Ntests      =  100;
     8  int Npoints     =  100;
     9  int Noutliers   =   10;
     10  int Nbootstrap  =  100;
     11  int Niterations =   10;
    1112
    1213  int N;
     
    2930    remove_argument (N, &argc, argv);
    3031    Nbootstrap = atoi (argv[N]);
     32    remove_argument (N, &argc, argv);
     33  }
     34  if ((N = get_argument (argc, argv, "-Niterations"))) {
     35    remove_argument (N, &argc, argv);
     36    Niterations = atoi (argv[N]);
    3137    remove_argument (N, &argc, argv);
    3238  }
     
    8894  FitDataSet dataset;
    8995  FitDataSetAlloc (&dataset, Npoints + Noutliers, FitSlope, Nbootstrap);
     96  dataset.MaxIterations = Niterations;
    9097
    9198  if (isfinite(ValuePrior) || isfinite(SlopePrior)) {
  • trunk/Ohana/src/relphot/test/relphot.tgroups.dvo

    r41453 r41462  
    451451  set stars_dmag = 0.02 + 0.1 * rnd(tmp)
    452452end
     453
     454macro plot.test.files
     455  if ($0 != 2)
     456    echo "USAGE: plot.test.files (N)"
     457    break
     458  end
     459
     460  clear -s
     461  resize 2000 1200
     462
     463  section a0 0.00 0.50 0.25 0.50
     464  section a1 0.25 0.50 0.25 0.50
     465  section a2 0.50 0.50 0.25 0.50
     466  section a3 0.75 0.50 0.25 0.50
     467
     468  section a4 0.00 0.00 0.25 0.50
     469  section a5 0.25 0.00 0.25 0.50
     470  section a6 0.50 0.00 0.25 0.50
     471  section a7 0.75 0.00 0.25 0.50
     472
     473  label -fn helvetica 12
     474  $BSTYLE = -tickpad 0.2 +xpad 0.2 +ypad 0.2 -ypad 5
     475
     476  for i 0 8
     477    sprintf name tgrp.%05d.%02d.dat $i $1
     478    data $name
     479    exec ls -l --full-time $name
     480    read Msys 4 Mrel 5 Mcal 7 Mmos 8 Mgrp 9 airmass 11 dMag 12
     481 
     482    section a$i
     483    lim Msys dMag; box $BSTYLE; plot Msys dMag -pt cir -op 0.2 -c blue
     484  end
     485end
Note: See TracChangeset for help on using the changeset viewer.