IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 13, 2009, 4:55:31 PM (17 years ago)
Author:
eugene
Message:

iteratively determine optimal Gaussian window sigma value; adjust clump parameters based on window sigma

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/psphot/src/psphotSourceStats.c

    r24589 r25358  
    2121    float OUTER    = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS");
    2222    if (!status) return NULL;
     23
     24    OUTER = PS_MAX(OUTER, 20.0); // XXX Guarantee that we can encompass the max moments radius
     25
    2326    char *breakPt  = psMetadataLookupStr (&status, recipe, "BREAK_POINT");
    2427    if (!status) return NULL;
     
    6063        psphotVisualShowMoments (sources);
    6164        return sources;
     65    }
     66
     67    // XXX *** this section is an attempt to iteratively determine the best value for sigma of the moments weighting Gaussian
     68    {
     69        float MIN_SN       = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN");
     70        if (!status) return false;
     71
     72        float sigma[4] = {1.0, 2.0, 3.0, 4.5};
     73        float Sout[4];
     74
     75        // XXX check that this sorts by peak->SN
     76        sources = psArraySort (sources, pmSourceSortBySN);
     77
     78        // loop over radii:
     79        for (int i = 0; i < 4; i++) {
     80
     81            for (int j = 0; (j < sources->n) && (j < 400); j++) {
     82 
     83                pmSource *source = sources->data[j];
     84                psAssert (source->moments, "force moments to exist");
     85                source->moments->nPixels = 0;
     86
     87                // skip faint sources for moments measurement
     88                if (source->peak->SN < MIN_SN) {
     89                    continue;
     90                }
     91
     92                // measure basic source moments
     93                status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0);
     94            }
     95
     96            // choose a grid scale that is a fixed fraction of the psf sigma^2
     97            psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(sigma[i]));
     98            psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SX_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));
     99            psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SY_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));
     100
     101            // determine the PSF parameters from the source moment values
     102            pmPSFClump psfClump = pmSourcePSFClump (NULL, sources, recipe);
     103            psLogMsg ("psphot", 3, "radius %.1f, nStars: %d, nSigma: %5.2f, X,  Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]);
     104
     105            psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
     106            psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, "PSF.CLUMP.REGION.000");
     107            if (!regionMD) {
     108                regionMD = psMetadataAlloc();
     109                psMetadataAddMetadata (recipe, PS_LIST_TAIL, "PSF.CLUMP.REGION.000", PS_META_REPLACE, "psf clump region", regionMD);
     110                psFree (regionMD);
     111            }
     112            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     113            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     114            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     115            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     116           
     117            psphotVisualPlotMoments (recipe, sources);
     118
     119            Sout[i] = sqrt(0.5*(psfClump.X + psfClump.Y)) / sigma[i];
     120        }
     121
     122        // we are looking for sigma for which Sout = 0.65 (or some other value)
     123
     124        float Sigma = NAN;
     125        float minS = Sout[0];
     126        float maxS = Sout[0];
     127        for (int i = 0; i < 4; i++) {
     128            minS = PS_MIN(Sout[i], minS);
     129            maxS = PS_MAX(Sout[i], maxS);
     130        }
     131        if (minS > 0.65) Sigma = sigma[3];
     132        if (maxS < 0.65) Sigma = sigma[0];
     133
     134        for (int i = 0; i < 3; i++) {
     135            if ((Sout[i] > 0.65) && (Sout[i+1] > 0.65)) continue;
     136            if ((Sout[i] < 0.65) && (Sout[i+1] < 0.65)) continue;
     137            Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]);
     138        }
     139        psAssert (isfinite(Sigma), "did we miss a case?");
     140       
     141        // choose a grid scale that is a fixed fraction of the psf sigma^2
     142        psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(Sigma));
     143        psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SX_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(Sigma));
     144        psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SY_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(Sigma));
     145        psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_GAUSS_SIGMA", PS_META_REPLACE, "moments limit", Sigma);
     146        psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_MOMENTS_RADIUS", PS_META_REPLACE, "moments limit", 4.0*Sigma);
     147
     148        psLogMsg ("psphot", 3, "using window function with sigma = %f\n", Sigma);
    62149    }
    63150
Note: See TracChangeset for help on using the changeset viewer.