IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41557


Ignore:
Timestamp:
Apr 27, 2021, 4:25:16 PM (5 years ago)
Author:
eugene
Message:

common function to soften fit errors; use IRLS for MagResidSave; add Median and altSigma to MagResidSave

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

Legend:

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

    r41556 r41557  
    598598void          FitDataSetAlloc     PROTO((FitDataSet *dataset, int Nmax, int order, int Nbootstrap));
    599599void          FitDataSetAddPriors PROTO((FitDataSet *dataset));
     600StatType      FitDataSetSoften    PROTO((FitDataSet *dataset, int Nvalues));
    600601
    601602unsigned int *ReadTGroupFile      PROTO((FILE *f, int *nelem));
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r41556 r41557  
    784784    }
    785785
    786     // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
    787     // XXX: apply airmass from above and fit only zp?
    788 
    789     // XXX soften the stats?
     786    // soften the errors based on the scatter
     787    FitDataSetSoften (&psfStars, Nref);
    790788
    791789    fit1d_irls (&psfStars, Nref);
  • trunk/Ohana/src/relphot/src/MagResidSave.c

    r41556 r41557  
    1212  float dMresid;
    1313  float  Mchisq;
     14  float  Mmedian;
     15  float  Maltsig;
    1416  int    Nfit;
    1517} MagResidResult;
     
    3941  }
    4042
    41   // we are making a 0-order fit and not doing bootstrap analysis, using OLS
     43  // we are making a 0-order fit and not doing bootstrap analysis
    4244  FitDataSet psfStars;
    4345  FitDataSetAlloc (&psfStars, Nmax, 0, 0);
    44   psfStars.MaxIterations = 0;
     46  // By default, we use IRLS; if MaxIterations = 0, then we use OLS
     47  // psfStars.MaxIterations = 0;
    4548
    4649  gfits_init_header (&header);
     
    5659  gfits_define_bintable_column (&theader, "E", "MAG_ERROR", "magnitude error", "magnitudes", 1.0, 0.0);
    5760  gfits_define_bintable_column (&theader, "E", "MAG_CHISQ", "magnitude resid chisq", "unitless", 1.0, 0.0);
     61  gfits_define_bintable_column (&theader, "E", "MAG_MEDIAN", "median magnitude residual", "magnitudes", 1.0, 0.0);
     62  gfits_define_bintable_column (&theader, "E", "MAG_ALTSIG", "68 percentile range as sigma", "magnitudes", 1.0, 0.0);
    5863  gfits_define_bintable_column (&theader, "E", "AIRMASS",   "", "unitless", 1.0, 0.0);
    5964  gfits_define_bintable_column (&theader, "D", "MJD",       "", "unitless", 1.0, 0.0);
     
    6267  gfits_define_bintable_column (&theader, "J", "FLAGS",     "image flags", "unitless",   1.0, 0.0);
    6368  gfits_define_bintable_column (&theader, "J", "NFIT",      "number of stars fitted", NULL, 1.0, FT_BZERO_INT32);
     69  gfits_define_bintable_column (&theader, "J", "NMEAS",     "number of stars on image", NULL, 1.0, FT_BZERO_INT32);
    6470
    6571  // generate the output array that carries the data
     
    7379  ALLOCATE_PTR (dMresid,  float,  Nimage);
    7480  ALLOCATE_PTR (Mchisq,   float,  Nimage);
     81  ALLOCATE_PTR (Mmedian,  float,  Nimage);
     82  ALLOCATE_PTR (Maltsig,  float,  Nimage);
    7583  ALLOCATE_PTR (airmass,  float,  Nimage);
    7684  ALLOCATE_PTR (mjd,      double, Nimage);
     
    7987  ALLOCATE_PTR (flags,    int,    Nimage);
    8088  ALLOCATE_PTR (Nfit,     int,    Nimage);
     89  ALLOCATE_PTR (Nmeas,    int,    Nimage);
    8190
    8291  // XXXX fill in the vectors here
     
    94103    Mchisq[i]   = NAN;
    95104    dMresid[i]  = NAN;
     105    Mmedian[i]  = NAN;
     106    Maltsig[i]  = NAN;
    96107    Nfit[i]     = 0;
    97108    Nmeas[i]    = N_onImage[i];
     
    110121    Mchisq[i]   = result.Mchisq;
    111122    dMresid[i]  = result.dMresid;
     123    Mmedian[i]  = result.Mmedian;
     124    Maltsig[i]  = result.Maltsig;
    112125    Nfit[i]     = result.Nfit;
    113126  }
    114127
    115128  // add the columns to the output array
    116   gfits_set_bintable_column (&theader, &ftable, "RA",        Rs,   Nimage);
    117   gfits_set_bintable_column (&theader, &ftable, "DEC",       Ds,   Nimage);
     129  gfits_set_bintable_column (&theader, &ftable, "RA",        Rs,       Nimage);
     130  gfits_set_bintable_column (&theader, &ftable, "DEC",       Ds,       Nimage);
    118131  gfits_set_bintable_column (&theader, &ftable, "MAG_RESID", Mresid,   Nimage);
    119132  gfits_set_bintable_column (&theader, &ftable, "MAG_ERROR", dMresid,  Nimage);
    120133  gfits_set_bintable_column (&theader, &ftable, "MAG_CHISQ", Mchisq,   Nimage);
     134  gfits_set_bintable_column (&theader, &ftable, "MAG_MEDIAN", Mmedian, Nimage);
     135  gfits_set_bintable_column (&theader, &ftable, "MAG_ALTSIG", Maltsig, Nimage);
    121136  gfits_set_bintable_column (&theader, &ftable, "AIRMASS",   airmass,  Nimage);
    122137  gfits_set_bintable_column (&theader, &ftable, "MJD",       mjd,      Nimage);
     
    125140  gfits_set_bintable_column (&theader, &ftable, "FLAGS",     flags,    Nimage);
    126141  gfits_set_bintable_column (&theader, &ftable, "NFIT",      Nfit,     Nimage);
     142  gfits_set_bintable_column (&theader, &ftable, "NMEAS",     Nmeas,    Nimage);
    127143
    128144  free (Rs);
     
    131147  free (dMresid );
    132148  free (Mchisq  );
     149  free (Mmedian );
     150  free (Maltsig );
    133151  free (airmass );
    134152  free (mjd     );
     
    137155  free (flags   );
    138156  free (Nfit    );
     157  free (Nmeas   );
    139158
    140159  FILE *f = fopen (filename, "w");
     
    185204  result.dMresid = NAN;
    186205  result.Mchisq  = NAN;
     206  result.Mmedian = NAN;
     207  result.Maltsig = NAN;
    187208  result.Nfit    = 0;
    188209
     
    239260    result.dMresid = NAN;
    240261    result.Mchisq  = NAN;
     262    result.Mmedian = NAN;
     263    result.Maltsig = NAN;
    241264    result.Nfit    = Nref;
    242265    return result;
    243266  }
     267
     268  StatType stats = FitDataSetSoften (psfStars, Nref);
     269  double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;
    244270
    245271  // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
     
    249275  result.Nfit    = psfStars->Nmeas;
    250276  result.Mchisq  = psfStars->chisq;
     277  result.Mmedian = stats.median;
     278  result.Maltsig = altSigma;
    251279
    252280  return result;
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r41556 r41557  
    11611161
    11621162  // in GOOD_MOSAIC mode, we fit good mosaics ignoring night state
     1163  // This case should only be used when not fitting nights / tgroups
    11631164  if ((MOSAIC_ZPT_MODE == MOSAIC_ZPT_MODE_GOOD_MOSAIC)) {
    11641165    if (badMosaic) useMmos = FALSE; // do not fit bad mosaics
     
    13121313  }
    13131314
    1314   StatType stats;
    1315   liststats_setmode (&stats, "MEDIAN");
    1316   liststats (psfStars->alldata->yVector, NULL, NULL, N, &stats);
    1317   double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;  // 20% to 80% encompasses 60% of the values, corresponds to the range (-0.85 sigma : +0.85 sigma)
    1318 
    1319   // soften the individual errors with 10% of the scatter above
    1320   for (j = 0; j < N; j++) {
    1321     double newSigma = hypot(psfStars->alldata->dyVector[j], 0.1*altSigma);
    1322     psfStars->alldata->dyVector[j] = newSigma;
    1323   }
    1324 
     1315  // soften the errors based on the scatter
     1316  FitDataSetSoften (psfStars, N);
     1317 
    13251318  fit1d_irls (psfStars, N);
    13261319  fit1d_irls (brightStars, Nbright);
  • trunk/Ohana/src/relphot/src/TGroupOps.c

    r41556 r41557  
    927927  */
    928928
    929   // use liststats to find the 20-pct, median, 80-pct points
    930   StatType stats;
    931   liststats_setmode (&stats, "MEDIAN");
    932   liststats (psfStars->alldata->yVector, NULL, NULL, N, &stats);
    933   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)
     929  StatType stats = FitDataSetSoften (psfStars, N);
     930  double altSigma = (stats.Upper80 - stats.Lower20) / 1.6;
    934931
    935932  TGTimes *mygroup = (TGTimes *) myTGroup->parent;
    936933  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);
    937 
    938   // soften the individual errors with 10% of the scatter above
    939   for (j = 0; j < N; j++) {
    940     double newSigma = hypot(psfStars->alldata->dyVector[j], 0.1*altSigma);
    941     psfStars->alldata->dyVector[j] = newSigma;
    942   }
    943934
    944935  // do anything special with identified good nights?
  • trunk/Ohana/src/relphot/src/bcatalog.c

    r40291 r41557  
    106106
    107107      // skip garbage measurements
    108       if (isnan(catalog[0].measure[offset].psfQF)     || (catalog[0].measure[offset].psfQF < 0.85))     { Npsfqf ++; continue; }
    109       if (isnan(catalog[0].measure[offset].psfQFperf) || (catalog[0].measure[offset].psfQFperf < 0.85)) { Npsfqf ++; continue; }
     108      if (isnan(catalog[0].measure[offset].psfQF)     || (catalog[0].measure[offset].psfQF < 0.95))     { Npsfqf ++; continue; }
     109      if (isnan(catalog[0].measure[offset].psfQFperf) || (catalog[0].measure[offset].psfQFperf < 0.95)) { Npsfqf ++; continue; }
    110110      if (isnan(catalog[0].measure[offset].M)) { Nnan ++; continue; }
    111111
  • trunk/Ohana/src/relphot/src/fit1d_irls.c

    r41462 r41557  
    368368  }
    369369}
     370
     371StatType FitDataSetSoften (FitDataSet *dataset, int Nvalues) {
     372
     373  // use liststats to find the 20-pct, median, 80-pct points
     374  StatType stats;
     375  liststats_setmode (&stats, "MEDIAN");
     376  liststats (dataset->alldata->yVector, NULL, NULL, Nvalues, &stats);
     377
     378  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)
     379
     380  // soften the individual errors with 10% of the scatter above
     381  for (int j = 0; j < Nvalues; j++) {
     382    double newSigma = hypot(dataset->alldata->dyVector[j], 0.1*altSigma);
     383    dataset->alldata->dyVector[j] = newSigma;
     384  }
     385 
     386  return stats;
     387}
  • trunk/Ohana/src/relphot/src/setMrelCatalog.c

    r41555 r41557  
    267267    if (USE_REFERENCE_WEIGHT && (code->type == PHOT_REF)) modifiedWeight = code->photomErrSys; // we are overloading this field for now
    268268
     269    // XXX I should probably do something more clever with the measured scatter in the nights, mosaics, images
     270
    269271    // combine the various errors in quadrature here:
    270272    float dMsys = hypot (code->photomErrSys, dMgrp);
Note: See TracChangeset for help on using the changeset viewer.