IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17153


Ignore:
Timestamp:
Mar 26, 2008, 11:00:19 AM (18 years ago)
Author:
eugene
Message:

adding function to measure 1 sigma contour

File:
1 edited

Legend:

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

    r17118 r17153  
    5555        if (!keep) continue;
    5656
    57         // need a reasonably fast way to follow the psf R = 1 annulus
    58 
    59         // save the PSF model from the Ensemble fit
    60         pmModel *PSF = source->modelPSF;
    61 
    62         // convert model to polar terms
    63         psEllipseShape shape;
    64         psF32 *PAR = PSF->params->data.F32;
    65         shape.sx   = PAR[PM_PAR_SXX] / M_SQRT2;
    66         shape.sy   = PAR[PM_PAR_SYY] / M_SQRT2;
    67         shape.sxy  = PAR[PM_PAR_SXY];
    68 
    69         psEllipseShapeToAxes (shape, 20.0);
    70        
    71 
    72         for (theta = 0.0; theta < 360.0; theta += 10.0) {
    73          
    74 
     57        // measure the flux at the 1 sigma contour
     58        psVector *contour = psphotModelContour (source->pixels, source->maskObj, source->modelPSF, 1.0);
    7559
    7660        // XXX for now, just skip any masked pixels
     
    198182 */
    199183
     184
     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?
     189psVector *psphotModelContour (psImage *image, psImage *mask, pmModel *model, float Ro) {
     190
     191    psF32 *PAR = model->params->data.F32;
     192    psVector *contour = psVectorAllocEmpty (50, PS_TYPE_F32);
     193    int nPts = 0;
     194
     195    // Ro = (x / SXX)^2 + (y / SYY)^2 + x y SXY;
     196    // y^2 (1/SYY^2) + y (x SXY) + (x / SXX)^2 - Ro = 0;
     197    // y = [-(x SXY) +/- sqrt ((x SXY)^2 - 4 (1/SYY^2) ((x/SXX)^2 - Ro))] * [SYY^2 / 2];
     198    // y = [-B +/- sqrt (B^2 - 4 A C)] / [2 A];
     199
     200    // min/max value of x is where T -> 0
     201    // solve this for x2:
     202    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
     204
     205    int xMax = sqrt(Q);
     206    int xMin = -1.0*xMax;
     207
     208    for (int x = MIN; x <= MAX; x++) {
     209        float A = PS_SQR (1.0 / PAR[PM_PAR_SYY]);
     210        float B = x * PAR[PM_PAR_SXY];
     211        float C = PS_SQR (x / PAR[PM_PAR_SXX]) - Ro;
     212
     213        float T = PS_SQR(B) - 4*A*C;
     214        if (T < 0.0) continue;
     215   
     216        float yP = (-B + sqrt (T)) / (2.0 * A);
     217        float yM = (-B - sqrt (T)) / (2.0 * A);
     218
     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;
     222
     223        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++;
     231            }
     232        }
     233       
     234        if (yPixM == yPixP) continue;
     235
     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++;
     241            }
     242        }
     243    }   
     244
     245    return contour;
     246}
Note: See TracChangeset for help on using the changeset viewer.