IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 11, 2013, 3:21:06 PM (13 years ago)
Author:
watersc1
Message:

Update to FWHM rejection. I've not fully tested this yet, although it does seem to work as intended in the initial tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackPrepare.c

    r34800 r35394  
    253253    float maxFWHM = psMetadataLookupF32(&mdok, recipe, "PSF.INPUT.MAX"); // max allowed input fwhm
    254254    float clipFWHMnSig = psMetadataLookupF32(&mdok, recipe, "PSF.INPUT.CLIP.NSIGMA"); // sigma clipping of inputs
    255 
     255    float threshFWHM = psMetadataLookupF32(&mdok, recipe, "PSF.INPUT.THRESH"); // FWHM size that we refuse to clip below
     256    float asymmetryFWHM = psMetadataLookupF32(&mdok, recipe, "PSF.INPUT.ASYMMETRY"); // max bimodal asymmetry
    256257    psString log = psStringCopy("Input seeing FWHMs:\n"); // Log message
    257258    bool havePSFs = false;                                // Do we have any PSFs?
     
    286287            options->inputSeeing->data.F32[i] = sumFWHM / (float)numFWHM;
    287288        }
    288 
     289#ifdef OLD_REJECTION
    289290        // reject any input images which exceed the specified max FWHM
    290291        if (isfinite(maxFWHM) && (options->inputSeeing->data.F32[i] > maxFWHM)) {
     
    292293            psLogMsg("ppStack", PS_LOG_INFO, "PSF FWHM for image %d is too large (%f vs %f maxFWHM) --- rejected.", i, options->inputSeeing->data.F32[i], maxFWHM);
    293294        }
    294 
     295#endif
    295296        psStringAppend(&log, "Input %d: %f\n", i, options->inputSeeing->data.F32[i]);
    296297    }
     
    300301    psFree(log);
    301302
     303    // Do GMM test with two modes to decide where to put the break.
     304    double Punimodal;
     305    int m = 2;
     306    psVector *modes = psVectorAlloc(num,PS_TYPE_F32);
     307    psVector *means = psVectorAlloc(m,PS_TYPE_F32);
     308    psVector *S     = psVectorAlloc(m,PS_TYPE_F32);
     309    psVector *pi    = psVectorAlloc(m,PS_TYPE_F32);
     310    psImage *P      = psImageAlloc(m,num,PS_TYPE_F32);
     311    float limit;
     312    if (!psMM1DClass(options->inputSeeing,
     313                     options->inputSeeing->n,
     314                     modes,means,
     315                     S,pi,P,
     316                     2,
     317                     &Punimodal)) {
     318      // Handle error here
     319      psFree(modes);
     320      psFree(means);
     321      psFree(S);
     322      psFree(pi);
     323      psFree(P);
     324      return(false);
     325    }
     326    fprintf(stderr,"means: %g %g\n",means->data.F32[0],means->data.F32[1]);
     327    fprintf(stderr,"sigma: %g %g \n",S->data.F32[0],S->data.F32[1]);
     328
     329    fprintf(stderr,"pi:    %g %g\n",pi->data.F32[0],pi->data.F32[1]);
     330   
     331    //    unwrittenGMMfunction(options->inputSeeing, options->inputMask, 0xff,
     332    //           &Punimodal,
     333    //           &m1,&s1,&pi1,
     334    //           &m2,&s2,&pi2);
     335
     336    // Use Gaussian mixture model analysis of the FWHM distribution to decide an optional FWHM limit
     337    if ((Punimodal > 0.5)|| // This distribution is best represented by a single mode
     338        (num <= 4)) {       // Or we have a small number of inputs, making this statistic poor.
     339      limit = maxFWHM;
     340    }
     341    else {                  // This is a bimodal distribution
     342      if ((fabs(pi->data.F32[0] - pi->data.F32[1]) < asymmetryFWHM)||  // However, both modes are equally populated
     343          (pi->data.F32[1] > pi->data.F32[0])) {                       // Or the larger FWHM mode is more populated
     344        limit = means->data.F32[1] + clipFWHMnSig * S->data.F32[1];
     345      }
     346      else {                                   // The smaller FWHM mode is more populated
     347        limit = means->data.F32[0] + clipFWHMnSig * S->data.F32[0];
     348      }
     349    }
     350    if (limit > maxFWHM)    { limit = maxFWHM; }    // We should not be larger than our max
     351    if (limit < threshFWHM) { limit = threshFWHM; } // Nor smaller than our min
     352
     353    for (int i = 0; i < num; i++) {
     354      if (options->inputSeeing->data.F32[i] > limit) {
     355        options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_PSF;
     356        psLogMsg("ppStack", PS_LOG_INFO,
     357                 "PSF FWHM for image %d is too large (%f vs %f fwhmlimit) --- rejected",
     358                 i, options->inputSeeing->data.F32[i],limit);
     359      }
     360    }
     361    psFree(means);
     362    psFree(modes);
     363    psFree(S);
     364    psFree(pi);
     365    psFree(P);
     366   
     367#ifdef OLD_REJECTION
    302368    // We should have the ability to filter the input list based on the seeing:
    303369    // * reject above some max value and/or min value
     
    323389        }
    324390    }
    325 
     391#endif
    326392    // Generate target PSF
    327393    if (options->convolve) {
Note: See TracChangeset for help on using the changeset viewer.