IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17239


Ignore:
Timestamp:
Mar 30, 2008, 8:44:57 AM (18 years ago)
Author:
eugene
Message:

measure 1sigma contour in psf-sub images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080324/psphot/src/psphotSourceSize.c

    r17153 r17239  
    11# include "psphotInternal.h"
    22# include <gsl/gsl_sf_gamma.h>
     3
     4float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro);
    35
    46// we need to call this function after sources have been fitted to the PSF model and
     
    1416    psTimerStart ("psphot");
    1517
    16     float CR_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.CRNSIGMA.LIMIT");
     18    float CR_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.CR.NSIGMA.LIMIT");
     19    assert (status);
     20
     21    float EXT_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.EXT.NSIGMA.LIMIT");
    1722    assert (status);
    1823
     
    2530
    2631        source->crNsigma  = -1.0;
    27         source->extNsigma = -1.0;
     32        source->extNsigma = 0.0;
    2833
    2934        // source must have been subtracted
     
    3136        if (!(source->mode & PM_SOURCE_MODE_SUBTRACTED)) continue;
    3237
    33         psF32 **resid = source->pixels->data.F32;
     38        psF32 **resid  = source->pixels->data.F32;
    3439        psF32 **weight = source->weight->data.F32;
    35         psU8 **mask = source->maskObj->data.U8;
     40        psU8 **mask    = source->maskObj->data.U8;
    3641
    3742        int xPeak = source->peak->xf - source->pixels->col0 + 0.5;
     
    5661
    5762        // measure the flux at the 1 sigma contour
    58         psVector *contour = psphotModelContour (source->pixels, source->maskObj, source->modelPSF, 1.0);
    59 
    60         // XXX for now, just skip any masked pixels
    61         extSum = 0.0;
    62         bool keep = true;
    63         for (int iy = -1; (iy <= +1) && keep; iy++) {
    64             for (int ix = -1; (ix <= +1) && keep; ix++) {
    65                 if (mask[yPeak+iy][xPeak+ix]) { keep &= false; }
    66             }
    67         }
    68         if (!keep) continue;
     63        // XXX prevent a source from being both CR and EXT?
     64        source->extNsigma = psphotModelContour (source->pixels, source->weight, source->maskObj, source->modelPSF, 1.0);
     65
     66        if (source->extNsigma > EXT_NSIGMA_LIMIT) {
     67          source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
     68        }
    6969
    7070        // XXX need to deal with edge peaks... and mask
     
    126126        }
    127127        source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
    128         source->extNsigma = (nEXT > 0) ? fabs(fEXT) / nEXT : 0.0;
    129128        // NOTE: abs needed to make the Nsigma value positive
    130129
     
    135134
    136135        if (source->crNsigma > CR_NSIGMA_LIMIT) {
    137           source->mode |= PM_SOURCE_MODE_CRLIMIT;
     136          source->mode |= PM_SOURCE_MODE_CR_LIMIT;
    138137        }
    139138    }
     
    183182
    184183
    185 // given the PSF ellipse parameters, navigate around the 1sigma contour
    186 // XXX return the Nsigma total deviation? 
    187 // XXX return just the sum around the contour? 
    188 // this is measure on the residual image - should we ignore negative deviations?
    189 psVector *psphotModelContour (psImage *image, psImage *mask, pmModel *model, float Ro) {
     184// given the PSF ellipse parameters, navigate around the 1sigma contour, return the total
     185// deviation in sigmas.  This is measure on the residual image - should we ignore negative
     186// deviations?
     187float psphotModelContour (psImage *image, psImage *weight, psImage *mask, pmModel *model, float Ro) {
    190188
    191189    psF32 *PAR = model->params->data.F32;
    192     psVector *contour = psVectorAllocEmpty (50, PS_TYPE_F32);
    193     int nPts = 0;
    194190
    195191    // Ro = (x / SXX)^2 + (y / SYY)^2 + x y SXY;
     
    201197    // solve this for x2:
    202198    float Q = Ro * PS_SQR(PAR[PM_PAR_SXX]) / (1.0 - PS_SQR(PAR[PM_PAR_SXX]*PAR[PM_PAR_SYY]*PAR[PM_PAR_SXY]) / 4.0);
    203     if (Q < 0.0) return contour; // ellipse is imaginary
     199    if (Q < 0.0) return NAN; // ellipse is imaginary
    204200
    205201    int xMax = sqrt(Q);
    206202    int xMin = -1.0*xMax;
    207203
    208     for (int x = MIN; x <= MAX; x++) {
     204    int nPts = 0;
     205    float nSigma = 0.0;
     206
     207    for (int x = xMin; x <= xMax; x++) {
    209208        float A = PS_SQR (1.0 / PAR[PM_PAR_SYY]);
    210209        float B = x * PAR[PM_PAR_SXY];
     
    217216        float yM = (-B - sqrt (T)) / (2.0 * A);
    218217
    219         int xPix  = x  + PAR[PM_PAR_X0] - source->pixels->col0 + 0.5;
    220         int yPixM = yM + PAR[PM_PAR_Y0] - source->pixels->row0 + 0.5;
    221         int yPixP = yP + PAR[PM_PAR_Y0] - source->pixels->row0 + 0.5;
     218        int xPix  = x  + PAR[PM_PAR_XPOS] - image->col0 + 0.5;
     219        int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
     220        int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
    222221
    223222        if (xPix < 0) continue;
    224         if (xPix >= source->pixels->numCols) continue;
    225 
    226         if ((yPixM >= 0) && (yPixM < source->pixels->numRows)) {
    227             if (!mask || !mask->data.U8[xPix][yPixM]) {
    228                 contour->data.F32[nPts] = image->data.F32[xPix][yPixM];
    229                 psVectorExtend (contour, 100, 1);
    230                 nPts++;
     223        if (xPix >= image->numCols) continue;
     224
     225        if ((yPixM >= 0) && (yPixM < image->numRows)) {
     226            if (!mask || !mask->data.U8[yPixM][xPix]) {
     227                float dSigma = image->data.F32[yPixM][xPix] / sqrt (weight->data.F32[yPixM][xPix]);
     228                nSigma += dSigma;
     229                nPts ++;
    231230            }
    232231        }
     
    234233        if (yPixM == yPixP) continue;
    235234
    236         if ((yPixP >= 0) && (yPixP < source->pixels->numRows)) {
    237             if (!mask || !mask->data.U8[xPix][yPixP]) {
    238                 contour->data.F32[nPts] = image->data.F32[xPix][yPixP];
    239                 psVectorExtend (contour, 100, 1);
    240                 nPts++;
     235        if ((yPixP >= 0) && (yPixP < image->numRows)) {
     236            if (!mask || !mask->data.U8[yPixP][xPix]) {
     237                float dSigma = image->data.F32[yPixP][xPix] / sqrt (weight->data.F32[yPixP][xPix]);
     238                nSigma += dSigma;
     239                nPts ++;
    241240            }
    242241        }
    243242    }   
    244 
    245     return contour;
     243    nSigma /= nPts;
     244    return nSigma;
    246245}
Note: See TracChangeset for help on using the changeset viewer.