IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41555


Ignore:
Timestamp:
Apr 24, 2021, 2:28:09 PM (5 years ago)
Author:
eugene
Message:

add function to measure the residual stats for each chip, fix resets and flags on resets; fix update of image mcal from tgroup and mosaic; improved determination of bad nights and bad mosaics; allow tgroups to fit only zero points without airmass terms; clean up the test detection dumps; soften the errors to avoid overweighting extreme outliers with high S/N; more careful sequencing of fitting modes; add manual iteration option

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

Legend:

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

    r41485 r41555  
    8888  float dMcal;
    8989  float dMsys;
     90  float stdev;
     91  float dMmin;
     92  float dMmax;
    9093  float McalChiSq;
    9194  float secz;
     
    107110  float dMsys;
    108111  float stdev;
     112  float dMmin;
     113  float dMmax;
    109114  float McalChiSq;
    110115  unsigned int nFitPhotom;
     
    155160  double min;
    156161  double max;
     162  double Upper90;
    157163  double Upper80;
    158164  double Lower20;
     165  double Lower10;
    159166  double total;
    160167  int    Nmeas;
     
    415422int    TEST_IMAGE2;
    416423
     424int    MANUAL_ITERATION;
    417425int    NLOOP;
    418426int    NGRID;
     
    643651int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
    644652
     653void          setMcalTest         PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr));
     654
    645655int           setMave             PROTO((Catalog *catalog, int Ncatalog));
    646656void          set_ZP              PROTO((double ZERO));
     
    835845void dump_tgroups (Catalog *catalog, int Npass);
    836846void dump_catalog (Catalog *catalog, off_t c, int Npass);
     847void dump_tgroup_imstats (int Npass);
    837848
    838849void SetZptIteration (int current);
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r41550 r41555  
    11# include "relphot.h"
    2 # define BASIC_STATS 0
    32
    43// the MeasureToImage, ImageToCatalog, and ImageToMeasure arrays are a substantial part of the memory footprint.
     
    631630    int isMosaic  = isMosaicChip(image[i].photcode);
    632631
     632    // unset at start by default (set if actually used below)
     633    image[i].flags &= ~ID_IMAGE_IMAGE_PHOTCAL;
     634
    633635    // if requested, freeze mosaic chips:
    634636    if (FREEZE_IMAGES && isMosaic) continue;
     
    719721      }
    720722
     723      float Moff = Mmos + Mgrp + Mgrid - Mflat;
     724
    721725      PhotCode *code = GetPhotcodebyCode (catalog[c].measureT[m].photcode);
    722726      if (!code) goto skip;
     
    727731
    728732    skip:
    729       psfStars.alldata-> yVector[Nref] = MsysPSF - MrelPSF - Mmos - Mgrp - Mgrid + Mflat;
     733      psfStars.alldata-> yVector[Nref] = MsysPSF - MrelPSF - Moff;
    730734      psfStars.alldata->dyVector[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    731735
     
    734738
    735739      if (isfinite(MrelKron) && isfinite(MsysKron)) {
    736         kronStars.alldata-> yVector[Nkron] = MsysKron - MrelKron - Mmos - Mgrp - Mgrid + Mflat;
     740        kronStars.alldata-> yVector[Nkron] = MsysKron - MrelKron - Moff;
    737741        kronStars.alldata->dyVector[Nkron] = psfStars.alldata->dyVector[Nref];
    738742        Nkron ++;
     
    765769      }     
    766770    }
     771    if (mark) continue;
    767772
    768773    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
     
    776781    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
    777782    // XXX: apply airmass from above and fit only zp?
    778     fit1d_irls (&kronStars, Nkron);
    779     image[i].McalAPER   = kronStars.bSaveArray[0][0];
     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    }
    780788
    781789    if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) {
     
    795803      image[i].McalPSF = 0.0;
    796804    }
     805
     806    image[i].flags |= ID_IMAGE_IMAGE_PHOTCAL;  // set this flag
    797807
    798808    // minUbercalDist calculated here is the min value for any star owned by this image
     
    814824  FitDataSetFree (&psfStars);
    815825
     826  return;
     827}
     828
     829/* determine McalTEST values for all images -- this is not used to set measure.Mcal, but only to test */
     830void setMcalTest (Catalog *catalog, FlatCorrectionTable *flatcorr) {
     831
     832  off_t i, j, m, c, n;
     833  int Nfew, Nbad, Nmos, Ngrp, Nrel, Ngrid, Nsys;
     834
     835  int Nsecfilt = GetPhotcodeNsecfilt ();
     836
     837  off_t Nmax = 0;
     838  for (i = 0; i < Nimage; i++) {
     839    Nmax = MAX (Nmax, N_onImage[i]);
     840  }
     841
     842  // we are making a 0-order fit and not doing bootstrap analysis:
     843  FitDataSet psfStars;
     844  FitDataSetAlloc (&psfStars, Nmax, 0, 0);
     845
     846  // for testing, need to allow this to be optional
     847  if (FALSE && UseStandardOLS(ZPT_IMAGES)) {
     848    psfStars.MaxIterations = 0;
     849  }
     850  psfStars.MaxIterations = 0;
     851
     852  Nfew = Nbad = Nmos = Ngrp = Ngrid = Nrel = Nsys = 0;
     853
     854  int Ncalibrated = 0;
     855  for (i = 0; i < Nimage; i++) {
     856    if (image[i].photcode == 0) continue; // skip the PHU images
     857
     858    off_t Nref = 0;    // number of stars used to measure McalPSF
     859
     860    if (N_onImage[i] == 0) {
     861      // fprintf (stderr, "image missing detections? %s %d "OFF_T_FMT"\n", image[i].name, image[i].nstar, N_onImage[i]);
     862      continue;
     863    }
     864
     865    for (j = 0; j < N_onImage[i]; j++) {
     866     
     867      m = ImageToMeasure[i][j];
     868      c = ImageToCatalog[i][j];
     869     
     870      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
     871          Nbad++;
     872          continue;
     873      }
     874      float Mmos  = getMmos  (m, c);
     875      if (isnan(Mmos)) {
     876          Nmos ++;
     877          continue;
     878      }
     879      float Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass, NULL); // ignore error for now?
     880      if (isnan(Mgrp)) {
     881          Ngrp ++;
     882          continue;
     883      }
     884      float Mgrid = getMgrid (m, c);
     885      if (isnan(Mgrid)) {
     886          Ngrid++;
     887          continue;
     888      }
     889
     890      // MrelPSF is the average magnitude for this star. 
     891      float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     892      if (isnan(MrelPSF)) {
     893          Nrel ++;
     894          continue;
     895      }
     896     
     897      // image.Mcal is not supposed to include the flat-field correction, so we need to
     898      // apply that offset as well here for this image (in other words, each detection is
     899      // being compared to the model, excluding the zero point, Mcal.  The model includes
     900      // the flat-correction.  NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat)
     901
     902      float Mflat = getMflat (m, c, flatcorr, catalog);
     903
     904      // get the PSF magnitude for thie measurement, with airmass slope applied
     905      n = catalog[c].measureT[m].averef;
     906      float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     907      if (isnan(MsysPSF)) {
     908        Nsys++;
     909        continue;
     910      }
     911
     912      float Moff = Mmos + Mgrp + Mgrid - Mflat;
     913
     914      psfStars.alldata-> yVector[Nref] = MsysPSF - MrelPSF - Moff;
     915      psfStars.alldata->dyVector[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     916      Nref++;
     917    }
     918
     919    if (Nref < 5) {
     920      // fprintf (stderr, "very few detections? %s %d "OFF_T_FMT"\n", image[i].name, image[i].nstar, Nref);
     921      // continue;
     922      image[i].McalAPER   = NAN;
     923      image[i].dMcal      = NAN;
     924      image[i].nFitPhotom = Nref;
     925      image[i].McalChiSq  = NAN;
     926      continue;
     927    }
     928
     929    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
     930    fit1d_irls (&psfStars, Nref);
     931    image[i].McalAPER   = psfStars.bSaveArray[0][0];
     932    image[i].dMcal      = psfStars.bSigma[0];
     933    image[i].nFitPhotom = psfStars.Nmeas;
     934    image[i].McalChiSq  = psfStars.chisq;
     935    Ncalibrated ++;
     936  }
     937
     938  fprintf (stderr, "%d images calibrated\n", Ncalibrated);
     939  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);
     940
     941  FitDataSetFree (&psfStars);
    816942  return;
    817943}
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r41487 r41555  
    685685      // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
    686686
     687      if (!isfinite(image[m].McalPSF)) {
     688        image[m].McalPSF = 0.0;
     689        image[m].McalAPER = 0.0;
     690        image[m].dMcal = 0.0;
     691        image[m].McalChiSq = 0.0;
     692        fprintf (stderr, "warning: resetting NAN value for Mcal %s\n", image[m].name);
     693      }
     694
    687695      McalPSF   += image[m].McalPSF;
    688696      McalAPER  += image[m].McalAPER;
     
    694702      image[m].dMcal     = NAN;
    695703      image[m].McalChiSq = NAN;
     704
    696705    }
    697706    dS /= MosaicN_Image[i];
     
    734743    for (j = 0; j < MosaicN_Image[i]; j++) {
    735744      im = MosaicToImage[i][j];
    736       image[im].McalPSF    += mosaic[i].McalPSF;
    737       image[im].McalAPER   += mosaic[i].McalAPER;
    738       image[im].dMcal       = mosaic[i].dMcal;
    739       image[im].McalChiSq   = mosaic[i].McalChiSq;
    740       image[im].ubercalDist = mosaic[i].ubercalDist;
    741       image[im].dMagSys     = mosaic[i].dMsys;
    742       image[im].nFitPhotom  = mosaic[i].nFitPhotom;
     745      if (mosaic[i].flags & ID_IMAGE_MOSAIC_PHOTCAL) {
     746        image[im].McalPSF     = mosaic[i].McalPSF;
     747        image[im].McalAPER    = mosaic[i].McalAPER;
     748        image[im].dMcal       = mosaic[i].dMcal;
     749        image[im].McalChiSq   = mosaic[i].McalChiSq;
     750        image[im].ubercalDist = mosaic[i].ubercalDist;
     751        image[im].dMagSys     = mosaic[i].dMsys;
     752        image[im].nFitPhotom  = mosaic[i].nFitPhotom;
     753      }
    743754      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW);
    744755      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR);
    745756      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_MOSAIC_POOR);
     757      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_TGROUP_PHOTCAL);
     758      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_MOSAIC_PHOTCAL);
     759      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_IMAGE_PHOTCAL);
    746760    }
    747761    mosaic[i].McalPSF  = 0.0;
     
    756770
    757771  // this mosaic has been identified as poor.
    758   mosaic[myMosaic].flags |= ID_IMAGE_PHOTOM_POOR;
     772  mosaic[myMosaic].flags |= ID_IMAGE_MOSAIC_POOR;
    759773  mosaic[myMosaic].McalPSF  = 0.0;
    760774  mosaic[myMosaic].McalAPER = 0.0;
     
    776790
    777791  // this mosaic has been identified as good.
    778   mosaic[myMosaic].flags &= ~ID_IMAGE_PHOTOM_POOR;
     792  mosaic[myMosaic].flags &= ~ID_IMAGE_MOSAIC_POOR;
    779793
    780794  image = getimages (&Nimage, NULL);
     
    12971311    assert (Nbright >= 0);
    12981312
    1299     psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
     1313    float Moff =  Mcal + Mgrp + Mgrid - Mflat;
     1314
     1315    psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Moff;
    13001316    psfStars->alldata->dyVector[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    13011317
    1302     kronStars->alldata-> yVector[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
     1318    kronStars->alldata-> yVector[N] = MsysKron - MrelKron - Moff;
    13031319    kronStars->alldata->dyVector[N] = psfStars->alldata->dyVector[N];
    13041320
     
    13371353  myMosaic[0].McalPSF    = psfStars->bSaveArray[0][0];
    13381354  myMosaic[0].dMcal      = psfStars->bSigma[0];     
     1355  myMosaic[0].stdev      = psfStars->sigma;
    13391356  myMosaic[0].McalChiSq  = psfStars->chisq;         
    13401357  myMosaic[0].nFitPhotom = psfStars->Nmeas;         
     
    18631880void clean_mosaics () {
    18641881
    1865   off_t i, N, mark, Ntotal, Nmark, Nscatter, Noffset, Nrejects, Nchisq;
    1866   double *mlist, *slist, *dlist;
    1867   double MaxOffset, MedOffset, MaxScatter;
     1882  double *mlist, *slist;
    18681883
    18691884  if (!MOSAIC_ZEROPT) return;
     
    18741889  ALLOCATE (mlist, double, Nmosaic);
    18751890  ALLOCATE (slist, double, Nmosaic);
    1876   ALLOCATE (dlist, double, Nmosaic);
    1877 
    1878   for (i = N = 0; i < Nmosaic; i++) {
     1891
     1892  int N = 0;
     1893  for (int i = 0; i < Nmosaic; i++) {
    18791894    // if (mosaic[i].flags & IMAGE_BAD) continue;
    18801895    if (!(mosaic[i].flags & ID_IMAGE_MOSAIC_PHOTCAL)) continue;
    18811896    if (mosaic[i].skipCal) continue;
    1882     mlist[N] = mosaic[i].McalPSF;
    1883     slist[N] = mosaic[i].dMcal;
    1884     dlist[N] = 1;
     1897    mlist[N] = mosaic[i].McalChiSq;
     1898    slist[N] = mosaic[i].stdev;
    18851899    N++;
    18861900  }
     
    18891903  liststats_setmode (&stats, "MEAN");
    18901904
    1891   liststats (mlist, dlist, NULL, N, &stats);
    1892   MaxOffset = MAX (IMAGE_OFFSET, 2*stats.sigma);
    1893   MedOffset = stats.median;
    1894 
    1895   liststats (slist, dlist, NULL, N, &stats);
    1896   MaxScatter = MAX (IMAGE_SCATTER, 2*stats.median);
    1897   fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);
     1905  liststats (mlist, NULL, NULL, N, &stats);
     1906  float MaxChiSq = stats.Upper90;
     1907
     1908  // old version based on Mcal value
     1909  // MaxOffset = MAX (IMAGE_OFFSET, 2*stats.sigma);
     1910  /// MedOffset = stats.median;
     1911
     1912  liststats (slist, NULL, NULL, N, &stats);
     1913  float MaxScatter = stats.Upper90;
     1914  // old: MaxScatter = MAX (IMAGE_SCATTER, 2*stats.median);
     1915
     1916  fprintf (stderr, "MOSAIC: Max ChiSq: %f, Max Scatter: %f\n", MaxChiSq, MaxScatter);
    18981917 
    1899   // XXX this needs to be configurable
    1900   float MaxChiSq = 10.0;
    1901 
    1902   Ntotal = Nmark = Nscatter = Noffset = Nrejects = Nchisq = 0;
    1903   for (i = 0; i < Nmosaic; i++) {
     1918  int Ntotal = 0, Nmark = 0, Nscatter = 0, Nfew = 0, Nchisq = 0;
     1919  for (int i = 0; i < Nmosaic; i++) {
    19041920    // if we are keeping ubercal sacrosanct, then we should not be allowed to break them...
    19051921    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
     
    19071923    Ntotal ++;
    19081924
     1925    if (mosaic[i].skipCal) continue;
     1926
     1927    int mark = FALSE;
     1928
    19091929    if (mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW)) {
    1910       continue;
    1911     }
    1912     if (mosaic[i].skipCal) continue;
    1913 
    1914     mark = FALSE;
    1915     if (mosaic[i].dMcal > MaxScatter) {
     1930      mark = TRUE;
     1931      Nfew ++;
     1932    }
     1933    if (mosaic[i].stdev > MaxScatter) {
    19161934      mark = TRUE;
    19171935      Nscatter ++;
    1918     }
    1919     if (fabs(mosaic[i].McalPSF - MedOffset) > MaxOffset) {
    1920       mark = TRUE;
    1921       Noffset ++;
    1922     }
    1923     if (mosaic[i].nFitPhotom < 0.7*mosaic[i].nValPhotom) {
    1924       mark = TRUE;
    1925       Nrejects ++;
    19261936    }
    19271937    if (mosaic[i].McalChiSq > MaxChiSq) {
     
    19371947  }
    19381948
    1939   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);
     1949  fprintf (stderr, "%d of %d mosaics marked poor (%d scatter, %d chisq, %d few)\n",  Nmark, Ntotal, Nscatter, Nchisq, Nfew);
    19401950
    19411951  free (mlist);
    19421952  free (slist);
    1943   free (dlist);
    19441953}
    19451954
  • trunk/Ohana/src/relphot/src/TGroupOps.c

    r41487 r41555  
    22
    33void assignMosaicsToTGroups (void);
     4int save_test_night_measures (FILE *fout, TGroup *myTGroup, Catalog *catalog, FlatCorrectionTable *flatcorr);
    45
    56// tgroupTimes carries the times of the tgroups (initially, just the photometric nights)
     
    8283      tgroup[j].dMcal     = 0.0; // note : at the end, tgroup.Mcal is added back to the input images
    8384      tgroup[j].dMsys     = 0.0;
     85      tgroup[j].dMmin     = NAN;
     86      tgroup[j].dMmax     = NAN;
    8487      tgroup[j].McalChiSq = 0.0; // NAN or 0.0?
    8588
     
    142145    tgroup[j].dMcal     = 0.0; // note : at the end, tgroup.Mcal is added back to the input images
    143146    tgroup[j].dMsys     = 0.0;
     147    tgroup[j].dMmin     = NAN;
     148    tgroup[j].dMmax     = NAN;
    144149    tgroup[j].McalChiSq = 0.0; // NAN or 0.0?
    145150
     
    421426        off_t im = tgroup[i].image[j];
    422427        double Mgrp = (TGROUP_FIT_AIRMASS) ? tgroup[i].McalPSF + tgroup[i].dKlam*(image[im].secz - 1.0) : tgroup[i].McalPSF;
    423         image[im].McalPSF    += Mgrp;
    424         image[im].McalAPER   += Mgrp;
    425         image[im].dMcal       = tgroup[i].dMcal;
    426         image[im].McalChiSq   = tgroup[i].McalChiSq;
    427         image[im].dMagSys     = tgroup[i].dMsys;
    428         image[im].nFitPhotom  = tgroup[i].nFitPhotom;
     428        if (tgroup[i].flags & ID_IMAGE_TGROUP_PHOTCAL) {
     429          image[im].McalPSF     = Mgrp;
     430          image[im].McalAPER    = Mgrp;
     431          image[im].dMcal       = tgroup[i].dMcal;
     432          image[im].McalChiSq   = tgroup[i].McalChiSq;
     433          image[im].dMagSys     = tgroup[i].dMsys;
     434          image[im].nFitPhotom  = tgroup[i].nFitPhotom;
     435        }
    429436        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_NIGHT_POOR); // probably not necessary : it is set in markBadTGroup
    430437        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_MOSAIC_POOR); // probably not necessary : it is set in markBadTGroup
     
    432439        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_PHOTOM_POOR);
    433440        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_PHOTOM_UBERCAL);
     441        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_TGROUP_PHOTCAL);
     442        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_MOSAIC_PHOTCAL);
     443        image[im].flags            |= (tgroup[i].flags & ID_IMAGE_IMAGE_PHOTCAL);
    434444       
    435445        // fprintf (stderr, "TG to IMAGE: %f +/- %f -> %f (%d)\n", tgroup[i].McalPSF, tgroup[i].dMcal, image[im].McalPSF, tgroup[i].nFitPhotom);
     
    687697      info->psfStars.MaxIterations = 0;
    688698    }
    689     if (1) {
    690       FitDataSetAddPriors (&info->psfStars);
     699    FitDataSetAddPriors (&info->psfStars); // why only psfStars?
     700    if (TGROUP_FIT_AIRMASS) {
    691701      info->psfStars.bPriorValue[1] = 0.0;  // note that we are fitting relative to the nominal slope
    692702      info->psfStars.bPriorSigma[1] = 0.04; // XXX this prior sigma needs to be user-configured
     
    812822  int testImage = FALSE;
    813823  TGTimes *tgroup = (TGTimes *) myTGroup->parent;
    814   // testImage |= (abs(tgroup->start - 1245283200) < 10);
     824  double mjdStart = ohana_sec_to_mjd (tgroup->start);
     825
     826  // unset this flag at start (set below if zeropoint is calculated)
     827  myTGroup->flags &= ~ID_IMAGE_TGROUP_PHOTCAL;
     828 
    815829  // 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);
    816839
    817840  FILE *fout = NULL;
     
    820843    snprintf (filename, 64, "test.%05d.%02d.dat", (int) Ngrp, npass_output);
    821844    fout = fopen (filename, "w");
     845    fprintf (fout, "# tgroup %s (%.0f)\n", ohana_sec_to_date(tgroup->start), mjdStart);
     846    save_test_night_measures (fout, myTGroup, catalog, flatcorr);
     847    fclose (fout);
    822848  }
    823849
     
    831857    off_t c = myTGroup->catalog[j];
    832858     
    833     // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF
    834     if (fout) {
    835 
    836       float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);     // image zero point
    837       float Mmos     = getMmos  (m, c);                    // mosaic zero point
    838       // XXX these two should both be 0.0 if we are fitting tgroups : skip those calls above?
    839 
    840       float Mgrid    = getMgrid (m, c);                    // camera offset (deprecated?)
    841       float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude
    842       float Mflat    = getMflat (m, c, flatcorr, catalog); // flat-field correction
    843 
    844       off_t n = catalog[c].measureT[m].averef;
    845 
    846       // magnitude for this measurement
    847       float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    848 
    849       // for historical reasons, Mflat is defined with the wrong sign
    850       float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrid + Mflat;
    851 
    852       int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
    853 
    854       fprintf (fout, "%f %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, catalog[c].measureT[m].airmass, delta, isBad);
    855     }
    856 
    857859    if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    858860      info->Nbad ++;
     
    916918    assert (Nbright >= 0);
    917919
    918     psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
    919     psfStars->alldata-> xVector[N] = (catalog[c].measureT[m].airmass - 1.0);
     920    float Moff =  Mcal + Mmos + Mgrid - Mflat;
     921
     922    psfStars->alldata-> yVector[N] = MsysPSF - MrelPSF - Moff;
    920923    psfStars->alldata->dyVector[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    921924
    922     kronStars->alldata-> yVector[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
    923     kronStars->alldata-> xVector[N] = psfStars->alldata-> xVector[N];
     925    kronStars->alldata-> yVector[N] = MsysKron - MrelKron - Moff;
    924926    kronStars->alldata->dyVector[N] = psfStars->alldata->dyVector[N];
     927
     928    if (TGROUP_FIT_AIRMASS) {
     929      psfStars->alldata-> xVector[N] = (catalog[c].measureT[m].airmass - 1.0);
     930      kronStars->alldata-> xVector[N] = psfStars->alldata-> xVector[N];
     931    }
    925932
    926933    if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
    927934      brightStars->alldata-> yVector[Nbright] = psfStars->alldata-> yVector[N];
    928       brightStars->alldata-> xVector[Nbright] = psfStars->alldata-> xVector[N];
    929935      brightStars->alldata->dyVector[Nbright] = psfStars->alldata->dyVector[N];
     936      if (TGROUP_FIT_AIRMASS) {
     937        brightStars->alldata-> xVector[Nbright] = psfStars->alldata-> xVector[N];
     938      }
    930939      Nbright ++;
    931940    }
    932941    N++;
    933942  }
    934   if (fout) { fclose (fout); }
    935943
    936944  /* too few good measurements or too many bad measurements (skip in PoorImages run) */
    937945  int mark = (N < NIGHT_TOOFEW) || (N < NIGHT_GOOD_FRACTION*myTGroup->Nmeasure);
    938946  if (mark) {
    939     if (VERBOSE2) {
     947    if (TRUE) {
    940948      TGTimes *mygroup = (TGTimes *) myTGroup->parent;
    941       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);
     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      }
    942952    }
    943953    myTGroup->flags |= ID_IMAGE_PHOTOM_FEW;
     954    myTGroup->nValPhotom = N;
    944955    info->Nfew ++;
    945956    if (testImage) {
     
    949960  } else {
    950961    myTGroup->flags &= ~ID_IMAGE_PHOTOM_FEW;
     962  }
     963
     964  /* we have a non-trivial fraction of measurements which are extreme outliers, and
     965     measurements with very small errors.  To avoid over-weighting measurements with very
     966     small errors, let's add something in quadarature. 
     967  */
     968
     969  // use liststats to find the 20-pct, median, 80-pct points
     970  StatType stats;
     971  liststats_setmode (&stats, "MEDIAN");
     972  liststats (psfStars->alldata->yVector, NULL, NULL, N, &stats);
     973  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)
     974
     975  TGTimes *mygroup = (TGTimes *) myTGroup->parent;
     976  fprintf (stderr, "TGroup Stats %f,%d : %d %d %6.3f %6.3f\n", ohana_sec_to_mjd(mygroup->start), myTGroup->photcode, (int) N, (int) myTGroup->Nmeasure, stats.median, altSigma);
     977
     978  // soften the individual errors with 10% of the scatter above
     979  for (j = 0; j < N; j++) {
     980    double newSigma = hypot(psfStars->alldata->dyVector[j], 0.1*altSigma);
     981    psfStars->alldata->dyVector[j] = newSigma;
    951982  }
    952983
     
    962993  myTGroup->dMcal      = psfStars->bSigma[0];
    963994  myTGroup->stdev      = psfStars->sigma;
     995  myTGroup->dMmin      = psfStars->min;
     996  myTGroup->dMmax      = psfStars->max;
    964997  myTGroup->McalChiSq  = psfStars->chisq;
    965998  myTGroup->nFitPhotom = psfStars->Nmeas;
    966999  myTGroup->nValPhotom = N;
    967   myTGroup->dKlam      = psfStars->bSaveArray[1][0];
     1000  myTGroup->dKlam      = (TGROUP_FIT_AIRMASS) ? psfStars->bSaveArray[1][0] : 0;
    9681001
    9691002  // XXX this does not make sense: I need to apply the airmass slope calculated above first
     
    9911024  }
    9921025
     1026  myTGroup->flags |= ID_IMAGE_TGROUP_PHOTCAL;  // set this flag
     1027
    9931028  if (testImage) {
    9941029    fprintf (stderr, "%f %f  :  %f\n", myTGroup->McalPSF, myTGroup->dMsys, myTGroup->McalChiSq);
     
    9981033}
    9991034 
     1035int save_test_night_measures (FILE *fout, TGroup *myTGroup, Catalog *catalog, FlatCorrectionTable *flatcorr) {
     1036
     1037  int Nsecfilt = GetPhotcodeNsecfilt ();
     1038
     1039  for (int j = 0; j < myTGroup->Nmeasure; j++) {
     1040     
     1041    off_t m = myTGroup->measure[j];
     1042    off_t c = myTGroup->catalog[j];
     1043     
     1044    // XXX these two should both be 0.0 if we are fitting tgroups
     1045    float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);     // image zero point
     1046    float Mmos     = getMmos  (m, c);                    // mosaic zero point
     1047
     1048    float Mgrid    = getMgrid (m, c);                    // camera offset (deprecated?)
     1049    float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP); // average magnitude
     1050    float Mflat    = getMflat (m, c, flatcorr, catalog); // flat-field correction
     1051
     1052    off_t n = catalog[c].measureT[m].averef;
     1053
     1054    // magnitude for this measurement
     1055    float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     1056
     1057    // for historical reasons, Mflat is defined with the wrong sign
     1058    float delta = MsysPSF - MrelPSF - Mcal - Mmos - Mgrid + Mflat - myTGroup->McalPSF;
     1059
     1060    int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
     1061
     1062    double mjdMeas = ohana_sec_to_mjd (catalog[c].measureT[m].t);
     1063
     1064    fprintf (fout, "%f %f : %f %f %f %f %f  : %f %f %d : %f\n",
     1065             catalog[c].averageT[n].R, catalog[c].averageT[n].D,
     1066             MsysPSF, MrelPSF, Mcal, Mgrid, Mflat, catalog[c].measureT[m].airmass, delta, isBad, mjdMeas);
     1067
     1068  }
     1069  return TRUE;
     1070}
     1071
    10001072int setMgrp_threaded (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
    10011073
     
    12211293}
    12221294
    1223 /* mark tgroup if: abs(Mcal - <Mcal>) too large, dMcal too large */
     1295/* new rules for bad tgroups (bad nights)
     1296 * too few exposures (Nmosaic < X)
     1297 * dMsys or stdev > X
     1298 * X%-ile of dMsys or stdev
     1299 * McalChiSq > X
     1300 * X%-ile of McalChiSq
     1301
     1302 * I can define rules for these but they would be arbitrary
     1303 * I think I should do an analysis of the observed distribution
     1304
     1305 */
     1306
    12241307void clean_tgroups () {
    12251308
    1226   off_t mark, Ntotal, Nmark, Nscatter, Noffset, Nrejects, Nchisq;
    1227   double *mlist, *slist, *dlist;
    1228   double MaxOffset, MedOffset, MaxScatter;
     1309  double *mlist, *slist;
    12291310
    12301311  if (!TGROUP_ZEROPT) return;
     
    12341315  ALLOCATE (mlist, double, NtgroupTimes*Nphotcodes);
    12351316  ALLOCATE (slist, double, NtgroupTimes*Nphotcodes);
    1236   ALLOCATE (dlist, double, NtgroupTimes*Nphotcodes);
    12371317
    12381318  int N = 0;
     
    12411321    for (int j = 0; j < tgroupTimes[i][0].nCode; j++) {
    12421322      if (tgroup[j].flags & IMAGE_BAD) continue;
    1243       mlist[N] = tgroup[j].McalPSF;
    1244       slist[N] = tgroup[j].dMcal;
    1245       dlist[N] = 1;
     1323      mlist[N] = tgroup[j].McalChiSq;
     1324      slist[N] = tgroup[j].stdev; // stdev of all measurements
     1325   // slist[N] = tgroup[j].dMsys; // stdev of bright measurements
    12461326      N++;
    12471327    }
     
    12511331  liststats_setmode (&stats, "MEAN");
    12521332
    1253   liststats (mlist, dlist, NULL, N, &stats);
    1254   MaxOffset = MAX (NIGHT_OFFSET, 3*stats.sigma);
    1255   MedOffset = stats.median;
    1256 
    1257   liststats (slist, dlist, NULL, N, &stats);
    1258   MaxScatter = MAX (NIGHT_SCATTER, 2*stats.median);
    1259   fprintf (stderr, "TGROUPS: median Mrel: %f, median dMrel: %f, Max Offset: %f, Max Scatter: %f\n", MedOffset, stats.median, MaxOffset, MaxScatter);
     1333  liststats (mlist, NULL, NULL, N, &stats);
     1334  float MaxChiSq = stats.Upper90;
     1335
     1336  liststats (slist, NULL, NULL, N, &stats);
     1337  float MaxScatter = stats.Upper90;
     1338
     1339  fprintf (stderr, "TGROUPS: Max ChiSq: %f, Max Scatter: %f\n", MaxChiSq, MaxScatter);
    12601340 
    1261   // XXX this needs to be configurable
    1262   float MaxChiSq = 10.0;
    1263 
    1264   Ntotal = Nmark = Nscatter = Noffset = Nrejects = Nchisq = 0;
     1341  int Ntotal = 0, Nmark = 0, Nscatter = 0, Nchisq = 0, NfewNights = 0, NfewExp = 0;
    12651342  for (int i = 0; i < NtgroupTimes; i++) {
    12661343    TGroup *tgroup = tgroupTimes[i][0].byCode;
     
    12691346      Ntotal ++;
    12701347
    1271       // ignore the nights with too few measurements
    1272       // XXX what to do with nights with too few measurements?
    1273       // XXX probably free the images to be fitted
     1348      int mark = FALSE;
     1349
     1350      // too few measurements (set in setMgrp_tgroup)
    12741351      if (tgroup[j].flags & ID_IMAGE_PHOTOM_FEW) {
    1275         markBadTGroup(&tgroup[j]); // mark the image associated with a bad night
    1276         continue;
     1352        mark = TRUE;
     1353        NfewNights ++;
    12771354      }
    1278      
    1279       mark = FALSE;
    1280       if (tgroup[j].dMcal > MaxScatter) {
     1355      // too few exposures (configure)
     1356      if (tgroup[j].Nmosaic < 4) {
     1357        mark = TRUE;
     1358        NfewExp ++;
     1359      }
     1360      // scatter too large
     1361      if (tgroup[j].stdev > MaxScatter) {
    12811362        mark = TRUE;
    12821363        Nscatter ++;
    12831364      }
    1284       if (fabs(tgroup[j].McalPSF - MedOffset) > MaxOffset) {
    1285         mark = TRUE;
    1286         Noffset ++;
    1287       }
    1288       if (tgroup[j].nFitPhotom < 0.7*tgroup[j].nValPhotom) {
    1289         mark = TRUE;
    1290         Nrejects ++;
    1291       }
     1365      // chisq too large
    12921366      if (tgroup[j].McalChiSq > MaxChiSq) {
    12931367        mark = TRUE;
     
    13031377  }
    13041378
    1305   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);
     1379  fprintf (stderr, "%d of %d tgroups marked poor (%d scatter, %d few nights, %d few exposures, %d chisq)\n",  Nmark, Ntotal, Nscatter, NfewNights, NfewExp, Nchisq);
    13061380
    13071381  free (mlist);
    13081382  free (slist);
    1309   free (dlist);
    13101383}
    13111384
     
    14651538  }
    14661539}
     1540
     1541void dump_tgroup_imstats (int Npass) {
     1542
     1543  FILE *fout = NULL;
     1544  char filename[64];
     1545
     1546  snprintf (filename, 64, "imstats.grp.%02d.dat", Npass);
     1547  fout = fopen (filename, "w");
     1548
     1549  for (off_t i = 0; i < NtgroupTimes; i++) {
     1550
     1551    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1552    for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1553      fprintf (fout, "%.0f %5d | %6ld %6d %6d %4ld %4ld | 0x%08x %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
     1554               ohana_sec_to_mjd(tgroupTimes[i][0].start), tgroup[j].photcode,
     1555               tgroup[j].Nmeasure, tgroup[j].nFitPhotom, tgroup[j].nValPhotom, tgroup[j].Nimage, tgroup[j].Nmosaic,
     1556               tgroup[j].flags, tgroup[j].McalPSF, tgroup[j].dKlam, tgroup[j].dMcal, tgroup[j].dMsys, tgroup[j].stdev, tgroup[j].dMmin, tgroup[j].dMmax, tgroup[j].McalChiSq);
     1557    }
     1558  }
     1559  fclose (fout);
     1560
     1561  // ************ mosaic stats
     1562
     1563  snprintf (filename, 64, "imstats.mos.%02d.dat", Npass);
     1564  fout = fopen (filename, "w");
     1565
     1566  for (off_t i = 0; i < NtgroupTimes; i++) {
     1567
     1568    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1569    for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1570
     1571      for (off_t k = 0; k < tgroup->Nmosaic; k++) {
     1572        Mosaic *mosaic = tgroup[j].mosaic[k];
     1573
     1574        fprintf (fout, "%4ld %3ld %3ld %.0f %5d %5d %5d | %12.5f %5.3f 0x%08x | %6.3f %6.3f %6.3f %6.3f\n",
     1575                 i, j, k, ohana_sec_to_mjd(tgroupTimes[i][0].start), mosaic->photcode, mosaic->nFitPhotom, mosaic->nValPhotom,
     1576                 ohana_sec_to_mjd(mosaic->start), mosaic->secz, mosaic->flags,
     1577                 mosaic->McalPSF, mosaic->dMcal, mosaic->dMsys, mosaic->McalChiSq);
     1578      }
     1579    }
     1580  }
     1581  fclose (fout);
     1582
     1583  // ************ image stats
     1584
     1585  snprintf (filename, 64, "imstats.chp.%02d.dat", Npass);
     1586  fout = fopen (filename, "w");
     1587
     1588  off_t Nimage = 0;
     1589  Image *image = getimages (&Nimage, NULL);
     1590  for (off_t i = 0; i < NtgroupTimes; i++) {
     1591
     1592    TGroup *tgroup = tgroupTimes[i][0].byCode;
     1593    for (off_t j = 0; j < tgroupTimes[i][0].nCode; j++) {
     1594
     1595      for (off_t k = 0; k < tgroup->Nimage; k++) {
     1596        off_t im = tgroup[j].image[k];
     1597
     1598        fprintf (fout, "%4ld %3ld %3ld %.0f %5d | %12.5f %5.3f 0x%08x | %6.3f %6.3f %6.3f %6.3f %6.3f\n",
     1599                 i, j, k, ohana_sec_to_mjd(tgroupTimes[i][0].start), image[im].photcode,
     1600                 ohana_sec_to_mjd(image[im].tzero), image[im].secz, image[im].flags,
     1601                 image[im].McalPSF, image[im].McalAPER, image[im].dMcal, image[im].dMagSys, image[im].McalChiSq);
     1602      }
     1603    }
     1604  }
     1605
     1606  fclose (fout);
     1607}
  • trunk/Ohana/src/relphot/src/ZeroPointModes.c

    r41473 r41555  
    44
    55void SetZptIteration (int current) {
     6  // XXX add 'manual' option here: ask for desired zpt iteration
     7  if (MANUAL_ITERATION) {
     8    int newValue;
     9    fprintf (stdout, "Set Iteration (current = %d): ", CurrentLoop);
     10    fscanf (stdin, "%d", &newValue);
     11    fprintf (stdout, "Using iteration %d\n", newValue);
     12    CurrentLoop = newValue;
     13    return;
     14  }
     15
     16  // automatic iteration:
    617  CurrentLoop = current;
    718}
     
    1425
    1526  if (TGROUP_ZEROPT && MOSAIC_ZEROPT) {
    16     if ((CurrentLoop > 4) && (CurrentLoop <= 8)) {
     27    if (CurrentLoop < 6) {
     28      TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_ALL;
     29      IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_NONE;
     30      MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE;
     31    }
     32    if ((CurrentLoop >= 6) && (CurrentLoop < 12)) {
    1733      // after iterating a few times on the TGroup zero points:
    1834      // * identify the photometric nights
     
    2339      clean_tgroups(); // do this on every pass to update the status of nights
    2440    }
    25     if ((CurrentLoop > 8) && (CurrentLoop <= 999)) {
     41    if ((CurrentLoop >= 12) && (CurrentLoop < 18)) {
    2642      // after iterating a few times on the TGroup & Mosaic zero points:
    2743      // * identify the good / bad Mosaics
     
    3349      clean_mosaics(); // do this on every pass
    3450    }
     51    if ((CurrentLoop >= 18) && (CurrentLoop <= 999)) {
     52      // after iterating a few times on the TGroup & Mosaic zero points:
     53      // * identify the good / bad Mosaics
     54      // * fit the chips from the bad Mosaics
     55      TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_GOOD_NIGHT; // stop fitting the bad nights
     56      MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_BAD_NIGHT_GOOD_MOSAIC; // only fit good mosaics on bad nights
     57      IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_BAD_NIGHT_BAD_MOSAIC; // only fit bad mosaics on bad nights
     58      clean_tgroups(); // do this on every pass
     59      clean_mosaics(); // do this on every pass
     60      clean_images(); // do this on every pass
     61    }
    3562  }
    3663
    3764  if (TGROUP_ZEROPT && !MOSAIC_ZEROPT) {
     65    if (CurrentLoop <= 4) {
     66      TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_ALL;
     67      IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_NONE;
     68      MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE;
     69    }
    3870    if ((CurrentLoop > 4) && (CurrentLoop <= 999)) {
    3971      // after iterating a few times on the TGroup zero points:
     
    4880
    4981  if (!TGROUP_ZEROPT && MOSAIC_ZEROPT) {
     82    if (CurrentLoop <= 4) {
     83      TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE;
     84      MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_ALL;
     85      IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_NONE;
     86    }
    5087    if ((CurrentLoop > 4) && (CurrentLoop <= 999)) {
    5188      // after iterating a few times on the Mosaic zero points:
     
    6097
    6198  if (!TGROUP_ZEROPT && !MOSAIC_ZEROPT) {
    62     if ((CurrentLoop > 4) && (CurrentLoop <= 999)) {
    63       // after iterating a few times on the Image zero points:
    64       // * ???
    65       TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE;
    66       MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE;
    67       IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_ALL;
    68     }
     99    // if we are not fitting TGROUP or MOSAIC, just fit all images
     100    TGROUP_ZPT_MODE = TGROUP_ZPT_MODE_NONE;
     101    MOSAIC_ZPT_MODE = MOSAIC_ZPT_MODE_NONE;
     102    IMAGE_ZPT_MODE  = IMAGE_ZPT_MODE_ALL;
    69103  }
    70104}
     
    83117        return FALSE;
    84118      case ZPT_MOSAIC:
     119        if (CurrentLoop < 9) return TRUE;
     120        return FALSE;
     121      case ZPT_IMAGES:
     122      default:
     123        if (CurrentLoop < 15) return TRUE;
     124        return FALSE;
     125    }
     126  }
     127
     128  if (TGROUP_ZEROPT && !MOSAIC_ZEROPT) {
     129    switch (mode) {
     130      case ZPT_STARS:
     131        if (CurrentLoop < 3) return TRUE;
     132        return FALSE;
     133      case ZPT_TGROUP:
     134      case ZPT_MOSAIC:
     135        if (CurrentLoop < 3) return TRUE;
     136        return FALSE;
     137      case ZPT_IMAGES:
     138      default:
    85139        if (CurrentLoop < 7) return TRUE;
    86140        return FALSE;
    87       case ZPT_IMAGES:
    88       default:
    89         if (CurrentLoop < 11) return TRUE;
    90         return FALSE;
    91     }
    92   }
    93 
    94   if (TGROUP_ZEROPT && !MOSAIC_ZEROPT) {
     141    }
     142  }
     143
     144  if (!TGROUP_ZEROPT && MOSAIC_ZEROPT) {
    95145    switch (mode) {
    96146      case ZPT_STARS:
     
    108158  }
    109159
    110   if (!TGROUP_ZEROPT && MOSAIC_ZEROPT) {
    111     switch (mode) {
    112       case ZPT_STARS:
    113         if (CurrentLoop < 3) return TRUE;
    114         return FALSE;
    115       case ZPT_TGROUP:
    116       case ZPT_MOSAIC:
    117         if (CurrentLoop < 3) return TRUE;
    118         return FALSE;
    119       case ZPT_IMAGES:
    120       default:
    121         if (CurrentLoop < 7) return TRUE;
    122         return FALSE;
    123     }
    124   }
    125 
    126160  if (!TGROUP_ZEROPT && !MOSAIC_ZEROPT) {
    127161    switch (mode) {
     
    139173  return FALSE;
    140174}
     175
     176/*  TGROUP & MOSAIC:
     177    0 - TGROUP ONLY & OLS
     178    1 - TGROUP ONLY & OLS
     179    2 - TGROUP ONLY & OLS
     180
     181    3 - TGROUP ONLY & IRLS
     182    4 - TGROUP ONLY & IRLS
     183    5 - TGROUP ONLY & IRLS
     184
     185    6 - TGROUP + MOSAIC & OLS MOSAIC
     186    7 - TGROUP + MOSAIC & OLS MOSAIC
     187    8 - TGROUP + MOSAIC & OLS MOSAIC
     188
     189    9 - TGROUP + MOSAIC & IRLS MOSAIC
     190   10 - TGROUP + MOSAIC & IRLS MOSAIC
     191   11 - TGROUP + MOSAIC & IRLS MOSAIC
     192
     193   12 - TGROUP + MOSAIC + IMAGE & OLS IMAGE
     194   13 - TGROUP + MOSAIC + IMAGE & OLS IMAGE
     195   14 - TGROUP + MOSAIC + IMAGE & OLS IMAGE
     196
     197   15 - TGROUP + MOSAIC + IMAGE & IRLS IMAGE
     198   16 - TGROUP + MOSAIC + IMAGE & IRLS IMAGE
     199   17 - TGROUP + MOSAIC + IMAGE & IRLS IMAGE
     200
     201*/
     202
  • trunk/Ohana/src/relphot/src/args.c

    r41485 r41555  
    192192  }
    193193
     194  MANUAL_ITERATION = FALSE;
     195  if ((N = get_argument (argc, argv, "-manual-iteration"))) {
     196    remove_argument (N, &argc, argv);
     197    MANUAL_ITERATION = TRUE;
     198  }
     199
    194200  NGRID = 8;
    195201  if ((N = get_argument (argc, argv, "-ngrid"))) {
     
    325331    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
    326332  }
    327 
    328333
    329334  // default behavior is to fit all chips independently
  • trunk/Ohana/src/relphot/src/liststats.c

    r41462 r41555  
    2626  stats->Upper80 = NAN;
    2727  stats->Lower20 = NAN;
     28  stats->Upper90 = NAN;
     29  stats->Lower10 = NAN;
    2830  stats->total   = NAN;
    2931  stats->Nmeas = 0;
     
    4951  if (N < 1) return (FALSE);
    5052
     53  int N90 = MIN (N-1, 0.9*N);
    5154  int N80 = MIN (N-1, 0.8*N);
    5255  int N20 = MAX (0, 0.2*N);
     56  int N10 = MAX (0, 0.1*N);
    5357
    5458  if (weight) {
     
    6872  stats[0].Upper80 = value[N80];
    6973  stats[0].Lower20 = value[N20];
     74  stats[0].Upper90 = value[N90];
     75  stats[0].Lower10 = value[N10];
    7076
    7177  switch (stats->statmode) {
     
    116122  WeightedMean |= (stats->statmode == STATS_INNER_WTMEAN);
    117123  WeightedMean |= (stats->statmode == STATS_CHI_INNER_WTMEAN);
     124  if (!dvalue) WeightedMean = FALSE;  // warn the user?
    118125
    119126  /* calculating the per-star offset based on the desired weighting scheme */
     
    137144        M  += value[i] * weight[i];
    138145        W  +=            weight[i];
    139         dM += SQ (weight[i] * dvalue[i]);
     146        dM += dvalue ? SQ (weight[i] * dvalue[i]) : 0.0;
    140147        R  += weight[i];
    141148        Nm += 1.0; 
    142149      }
    143150      Mo  = M / W;
    144       dMo = sqrt (dM) / R;
     151      dMo = dvalue ? sqrt (dM) / R : NAN;
    145152    }
    146153  } else {
     
    159166      for (i = ks; i < ke; i++) {
    160167        M   += value[i];
    161         dM  += SQ (dvalue[i]);
     168        dM  += dvalue ? SQ (dvalue[i]) : 0.0;
    162169        Nm  += 1.0; 
    163170      }
    164171      Mo = M / Nm;
    165       dMo = sqrt (dM) / Nm;
     172      dMo = dvalue ? sqrt (dM) / Nm : NAN;
    166173    }
    167174  }
  • trunk/Ohana/src/relphot/src/load_images.c

    r41404 r41555  
    5858  // images / detections may have been added
    5959  for (off_t i = 0; i < Nsubset; i++) {
    60     if (subset[i].flags & ID_IMAGE_PHOTOM_FEW) {
    61       subset[i].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);
    62     }
     60    // reset these two regardless (we will re-determine)
     61    subset[i].flags &= ~(ID_IMAGE_PHOTOM_NOCAL | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP | ID_IMAGE_PHOTOM_FEW);
    6362    if (RESET) {
    6463      if (RESET_ZEROPTS) {
     
    7069        }
    7170      }
    72       subset[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
     71      subset[i].flags &= ~(ID_IMAGE_MOSAIC_POOR | ID_IMAGE_NIGHT_POOR);
     72      subset[i].flags &= ~(ID_IMAGE_IMAGE_PHOTCAL | ID_IMAGE_MOSAIC_PHOTCAL | ID_IMAGE_TGROUP_PHOTCAL);
    7373      subset[i].ubercalDist = 1000;
    7474    }
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r41473 r41555  
    117117    for (i = 0; i < NLOOP; i++) {
    118118      SetZptIteration (i);
     119
    119120      dump_tgroups (catalog, i);
    120121      dump_catalog (catalog, 0, i); // for a test, just dump a specific catalog
     122      dump_tgroup_imstats (i);
    121123
    122124      setMrel  (catalog, Ncatalog, flatcorr); // threaded
     125      setMcalTest (catalog, flatcorr);
     126
    123127      dump_tgroups (catalog, i + 20);
    124128      dump_catalog (catalog, 0, i + 20); // for a test, just dump a specific catalog
     129      dump_tgroup_imstats (i + 20);
    125130
    126131      setMcal  (catalog, FALSE, flatcorr);
     
    129134      dump_tgroups (catalog, i + 40);
    130135      dump_catalog (catalog, 0, i + 40); // for a test, just dump a specific catalog
     136      dump_tgroup_imstats (i + 40);
    131137
    132138      setMgrid (catalog, flatcorr);
     
    143149
    144150      global_stats (catalog, Ncatalog, flatcorr, i);
    145 
    146151      SetZeroPointModes ();
     152
    147153      MARKTIME("-- finished loop %d: %f sec\n", i, dtime);
    148154      fprintf (stderr, "----- continue loop %d -----\n", i);
  • trunk/Ohana/src/relphot/src/setMrelCatalog.c

    r41473 r41555  
    272272    float Map  = NAN;
    273273    float dMap = NAN;
     274
     275    // XXX I am not convinced the sign on Mflat here is correct
     276    float Moff =  Mflat + Mcal + Mmos + Mgrp + Mgrid;
     277
    274278    if (isSetMrelFinal) {
    275279      Map = PhotCat (&measure[k], MAG_CLASS_APER);
     
    282286      if (CHECK_VALID_MAG(Map, dMap)) {
    283287        int Nap = results->aperData[Nsec].Nlist;
    284         results->aperData[Nsec].flxlist[Nap] = Map - Mflat - Mcal - Mmos - Mgrp - Mgrid; // this is consistent with PhotRel
     288        results->aperData[Nsec].flxlist[Nap] = Map - Moff; // this is consistent with PhotRel
    285289        results->aperData[Nsec].errlist[Nap] = dMap;
    286290        results->aperData[Nsec].wgtlist[Nap] = modifiedWeight;
     
    302306    if (CHECK_VALID_MAG(Mkron, dMkron)) {
    303307      int Nkron = results->kronData[Nsec].Nlist;
    304       results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrp - Mgrid; // this is consistent with PhotRel
     308      results->kronData[Nsec].flxlist[Nkron] = Mkron - Moff; // this is consistent with PhotRel
    305309      results->kronData[Nsec].errlist[Nkron] = dMkron;
    306310      results->kronData[Nsec].wgtlist[Nkron] = modifiedWeight;
     
    315319    if (CHECK_VALID_MAG(Mpsf, dMpsf)) {
    316320      int Npsf = results->psfData[Nsec].Nlist;
    317       results->psfData[Nsec].flxlist[Npsf] = Mpsf - Mflat - Mcal - Mmos - Mgrp - Mgrid; // this is consistent with PhotRel
     321      results->psfData[Nsec].flxlist[Npsf] = Mpsf - Moff; // this is consistent with PhotRel
    318322      results->psfData[Nsec].errlist[Npsf] = dMpsf;
    319323      results->psfData[Nsec].wgtlist[Npsf] = modifiedWeight;
Note: See TracChangeset for help on using the changeset viewer.