IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 30, 2013, 6:10:41 PM (13 years ago)
Author:
watersc1
Message:

Changes to stacking code:

  • New input FWHM clipping algorithm using mixture models
  • New recipes/reductions that further reduce FWHM clipping
  • pmSubtractionRejectStamps now fits flux/chi2 values in log-log space to prevent outliers biasing the fit (and causing images to be rejected due to a small number of bad stamps)
  • pmPSF now correctly chooses between useReff forms as appropriate
  • pmPSF change fixes circularization issues in pmReadoutFakeFromSources
  • pmPSFEnvelope somewhat more clear about circularization
  • Changed debugging in pmSubtractionEquation to add information.

I do not see any conflicts with the ppSub code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r33425 r35455  
    3737#define USE_KERNEL_ERR                  // Use kernel error image?
    3838#define NUM_COVAR_POS 5                 // Number of positions for covariance calculation
     39#define USE_LOGFIT_REJECT
    3940
    4041// XXX we need to pass these fwhm values elsewhere.  These should go on one of the structure, but
     
    966967    psPolynomial1D *model = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 2);
    967968
     969#ifdef USE_LOGFIT_REJECT
     970    // CZW: Since flux and chisq can range over many orders of magnitude, use a log-log fit to calculate the
     971    // RMS scatter.  This should be more robust against outliers that can impact the fit quality.
     972    psVector *logchisq = psVectorAlloc(match->chisq->n,PS_TYPE_F32);
     973    psVector *logflux  = psVectorAlloc(match->fluxes->n,PS_TYPE_F32);
     974    for (int qq = 0; qq < match->chisq->n; qq++) {
     975      if ((match->chisq->data.F32[qq] > 0)&&
     976          (match->fluxes->data.F32[qq] > 0)) {
     977        logchisq->data.F32[qq] = log10(match->chisq->data.F32[qq]);
     978        logflux->data.F32[qq]  = log10(match->fluxes->data.F32[qq]);
     979      }
     980      else {
     981        // Ignore negative values.  Maybe we could do an offset or something, but not today.
     982        match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[qq] |= PM_SUBTRACTION_STAMP_REJECTED;
     983      }
     984      //      if (!(match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[qq] & 0xff)) {
     985      //        psLogMsg("psModules.imcombine", PS_LOG_INFO, "RRRRRR: %d %g %g %g %g\n",
     986      //                 qq,match->chisq->data.F32[qq],match->fluxes->data.F32[qq],
     987      //                 0.0,0.0);
     988      // }
     989
     990    }
     991    bool result = psVectorClipFitPolynomial1D(model, stats, match->stampMask, 0xff, logchisq, NULL, logflux);
     992    if (!result) {
     993        psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations.");
     994        psFree(model);
     995        psFree(stats);
     996        return -1;
     997    }
     998
     999    // However, since we've done a log-log fit, we can't rely on the statistics in the stats object
     1000    // To accurately represent the distribution.  I've tried to massage them (as dlog10(X) = abs(1/(X log(10))) dX),
     1001    // but ended up deciding to just manually calculate the residual, and then pass that to a robust stats object.
     1002    psStats *residStats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     1003    psVector *residData = psVectorAlloc(match->chisq->n,PS_TYPE_F32);
     1004    int counter = 0;
     1005    for (int qq = 0; qq < match->chisq->n; qq++) {
     1006      if (!(match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[qq] & 0xff)) {
     1007        double vv = pow(10,
     1008                        model->coeff[0] +
     1009                        model->coeff[1] * log10(match->fluxes->data.F32[qq]) +
     1010                        model->coeff[2] * pow(log10(match->fluxes->data.F32[qq]),2));
     1011        residData->data.F32[qq] = match->chisq->data.F32[qq] - vv;
     1012        counter++;
     1013        //                      psLogMsg("psModules.imcombine", PS_LOG_INFO, "SSSSS: %d %g %g %g %g\n",
     1014        //                       qq,match->chisq->data.F32[qq],match->fluxes->data.F32[qq],
     1015        //                       vv,residData->data.F32[qq]);
     1016      }
     1017    }
     1018    psVectorStats(residStats,residData,NULL,match->stampMask,0xff);
     1019    if (isnan(residStats->robustMedian)) {
     1020        psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations.");
     1021        psFree(model);
     1022        psFree(stats);
     1023        psFree(logchisq);
     1024        psFree(logflux);
     1025        psFree(residStats);
     1026        psFree(residData);
     1027
     1028        return -1;
     1029    }
     1030
     1031    kernels->mean = residStats->robustMedian;
     1032    kernels->rms =  residStats->robustStdev;
     1033    kernels->numStamps = counter;
     1034
     1035    psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", residStats->robustMedian,residStats->robustStdev);
     1036    psFree(logchisq);
     1037    psFree(logflux);
     1038    psFree(residStats);
     1039    psFree(residData);
     1040
     1041#else
     1042    // CZW: Otherwise, use the original linear fit code.
    9681043    bool result = psVectorClipFitPolynomial1D(model, stats, match->stampMask, 0xff, match->chisq, NULL, match->fluxes);
    9691044    if (!result) {
     
    9791054        return -1;
    9801055    }
    981 
    9821056    kernels->mean = stats->sampleMean;
    983     kernels->rms = stats->sampleStdev;
     1057    kernels->rms =  stats->sampleStdev;
    9841058    kernels->numStamps = stats->clippedNvalues;
     1059    psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", stats->sampleMean, stats->sampleStdev);
     1060#endif
    9851061
    9861062    psLogMsg ("pmPSFtry", 4, "chisq vs flux model: %e + %e flux + %e flux^2\n", model->coeff[0], model->coeff[1], model->coeff[2]);
    987     psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", stats->sampleMean, stats->sampleStdev);
    9881063    psLogMsg("psModules.imcombine", PS_LOG_INFO, "Mean deviation from %d stamps: %lf +/- %lf",  kernels->numStamps, kernels->mean, kernels->rms);
    9891064
Note: See TracChangeset for help on using the changeset viewer.