IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19915


Ignore:
Timestamp:
Oct 6, 2008, 3:16:44 AM (18 years ago)
Author:
eugene
Message:

apply the maskVal to mask tests; handle masked pixels in the outer 8 of top 9 pixels for CR; drop old EXT measurements (superceded by model contour); add visualizations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotSourceSize.c

    r19286 r19915  
    22# include <gsl/gsl_sf_gamma.h>
    33
    4 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro);
     4float psphotModelContour (psImage *image, psImage *weight, psImage *mask, psMaskType maskVal, pmModel *model, float Ro);
    55
    66// we need to call this function after sources have been fitted to the PSF model and
     
    5151
    5252        // check for extendedness: measure the delta flux significance at the 1 sigma contour
    53         source->extNsigma = psphotModelContour (source->pixels, source->weight, source->maskObj, source->modelPSF, 1.0);
     53        source->extNsigma = psphotModelContour (source->pixels, source->weight, source->maskObj, maskVal, source->modelPSF, 1.0);
    5454
    5555        // XXX prevent a source from being both CR and EXT?
     
    7878        if (!keep) continue;
    7979
     80        if (mask[yPeak][xPeak] & maskVal) continue;
     81
    8082        // XXX need to deal with edge peaks... and mask
    81         float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1];
    82         float cY = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak+0] - resid[yPeak+1][xPeak+0];
    83         float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1];
    84         float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1];
    85 
    86         float dcX = 4*weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1];
    87         float dcY = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak+0] + weight[yPeak+1][xPeak+0];
    88         float dcL = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1];
    89         float dcR = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1];
    90 
    91         float nX = cX / sqrt(dcX);
    92         float nY = cY / sqrt(dcY);
    93         float nL = cL / sqrt(dcL);
    94         float nR = cR / sqrt(dcR);
     83        float nX = 0;
     84        float nY = 0;
     85        float nL = 0;
     86        float nR = 0;
     87
     88        if (!(mask[yPeak+0][xPeak-1] & maskVal) && !(mask[yPeak+0][xPeak+1] & maskVal)) {
     89            float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1];
     90            float dcX = 4*weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1];
     91            nX = cX / sqrt(dcX);
     92        }
     93
     94        if (!(mask[yPeak-1][xPeak+0] & maskVal) && !(mask[yPeak+1][xPeak+0] & maskVal)) {
     95            float cY = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak+0] - resid[yPeak+1][xPeak+0];
     96            float dcY = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak+0] + weight[yPeak+1][xPeak+0];
     97            nY = cY / sqrt(dcY);
     98        }
     99
     100        if (!(mask[yPeak-1][xPeak-1] & maskVal) && !(mask[yPeak+1][xPeak+1] & maskVal)) {
     101            float dcL = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1];
     102            float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1];
     103            nL = cL / sqrt(dcL);
     104        }
     105
     106        if (!(mask[yPeak+1][xPeak-1] & maskVal) && !(mask[yPeak-1][xPeak+1] & maskVal)) {
     107            float dcR = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1];
     108            float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1];
     109            nR = cR / sqrt(dcR);
     110        }
    95111
    96112        // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)
     
    100116        // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
    101117
    102         // not strictly accurate: overcounts the chisq contribution from the center pixel (by factor of 4)
     118        // not strictly accurate: overcounts the chisq contribution from the center pixel (by
     119        // factor of 4); also biases a bit low if any pixels are masked
     120        // XXX I am not sure I want to keep this value...
    103121        source->psfChisq = PS_SQR (nX) + PS_SQR (nY) + PS_SQR (nX) + PS_SQR (nR);
    104122
    105123        float fCR = 0.0;
    106         float fEXT = 0.0;
    107124        int nCR = 0;
    108         int nEXT = 0;
    109125        if (nX > 0.0) {
    110126            fCR += nX;
    111127            nCR ++;
    112         } else {
    113             fEXT += nX;
    114             nEXT ++;
    115128        }
    116129        if (nY > 0.0) {
    117130            fCR += nY;
    118131            nCR ++;
    119         } else {
    120             fEXT += nY;
    121             nEXT ++;
    122132        }
    123133        if (nL > 0.0) {
    124134            fCR += nL;
    125135            nCR ++;
    126         } else {
    127             fEXT += nL;
    128             nEXT ++;
    129136        }
    130137        if (nR > 0.0) {
    131138            fCR += nR;
    132139            nCR ++;
    133         } else {
    134             fEXT += nR;
    135             nEXT ++;
    136140        }
    137141        source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
    138         // NOTE: abs needed to make the Nsigma value positive
    139 
    140         if (!isfinite(source->crNsigma)) {
    141           fprintf (stderr, ".");
    142           source->crNsigma = -6.0;
    143         }
     142        assert (isfinite(source->crNsigma));
    144143
    145144        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
     
    212211    }
    213212
     213    // now that we have masked pixels associated with CRs, we can grow the mask
    214214    if (grow > 0) {
    215215        psImage *newMask = psImageConvolveMask(NULL, readout->mask, crMask, crMask, -grow, grow, -grow, grow);
     
    225225              sources->n - first, psTimerMark ("psphot"));
    226226
     227    psphotVisualPlotSourceSize (sources);
     228    psphotVisualShowSourceSize (sources);
     229
    227230    return true;
    228231}
    229 
    230 
    231 // some possible classes:
    232 // all 4 curvatures are highly negative : CR
    233 // all 4 curvatures are highly positive : EXT
    234 
    235 // at least 2 are significantly negative, none are significantly positive : CR
    236 // at least 2 are significantly positive, none are significantly negative : EXT
    237 
    238 // any are significantly negative, some may be significantly positive : CR
    239 // any are significantly positive, none may be significantly positive : EXT
    240 
    241 /* Nn  Np  No
    242    4   0   0   CR_1
    243    3   1   0   CR_1
    244    3   0   1   CR_1
    245    2   2   0   CR_2
    246    2   1   1   CR_2
    247    2   0   2   CR_2
    248    1   3   0   CR_3
    249    1   2   1   CR_3
    250    1   1   2   CR_3
    251    1   0   3   CR_3
    252    0   4   0   EXT
    253    0   3   1   EXT
    254    0   2   2   EXT
    255    0   1   3   PSF
    256    0   0   4   PSF
    257 */
    258 
    259 /* Alternatively, write a f(CR) = Sum(nX,etc if >0) */
    260 
    261 
    262 /* I can write the formal probability that the 4 measurements are consistent with a PSF
    263  * based on how large the error values are (Nsigma -> erf -> P(Nsigma)).
    264  * I should examine this value as a function of flux and also examine the distribution of
    265  * the probabilities for the PSF sources.
    266  */
    267 
    268232
    269233// given the PSF ellipse parameters, navigate around the 1sigma contour, return the total
    270234// deviation in sigmas.  This is measure on the residual image - should we ignore negative
    271235// deviations?
    272 float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro) {
     236    float psphotModelContour (psImage *image, psImage *weight, psImage *mask, psMaskType maskVal, pmModel *model, float Ro) {
    273237
    274238    psF32 *PAR = model->params->data.F32;
     
    309273
    310274        if ((yPixM >= 0) && (yPixM < image->numRows)) {
    311             if (!mask || !mask->data.U8[yPixM][xPix]) {
     275            if (!mask || !(mask->data.U8[yPixM][xPix] & maskVal)) {
    312276                float dSigma = image->data.F32[yPixM][xPix] / sqrt (weight->data.F32[yPixM][xPix]);
    313277                nSigma += dSigma;
     
    319283
    320284        if ((yPixP >= 0) && (yPixP < image->numRows)) {
    321             if (!mask || !mask->data.U8[yPixP][xPix]) {
     285            if (!mask || !(mask->data.U8[yPixP][xPix] & maskVal)) {
    322286                float dSigma = image->data.F32[yPixP][xPix] / sqrt (weight->data.F32[yPixP][xPix]);
    323287                nSigma += dSigma;
Note: See TracChangeset for help on using the changeset viewer.