IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 5:03:33 PM (17 years ago)
Author:
Paul Price
Message:

Merging pap_branch_20090128. Resolved a small number of conflicts. Compiles, but not tested in detail.

File:
1 edited

Legend:

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

    r21183 r21366  
    22# include <gsl/gsl_sf_gamma.h>
    33
    4 static float psphotModelContour(const psImage *image, const psImage *weight, const psImage *mask,
     4static float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask,
    55                                psImageMaskType maskVal, const pmModel *model, float Ro);
    66
     
    6262
    6363        psF32 **resid  = source->pixels->data.F32;
    64         psF32 **weight = source->weight->data.F32;
     64        psF32 **variance = source->variance->data.F32;
    6565        psImageMaskType **mask    = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
    6666
    6767        // check for extendedness: measure the delta flux significance at the 1 sigma contour
    68         source->extNsigma = psphotModelContour(source->pixels, source->weight, source->maskObj, maskVal,
     68        source->extNsigma = psphotModelContour(source->pixels, source->variance, source->maskObj, maskVal,
    6969                                               source->modelPSF, 1.0);
    7070
     
    103103        // Compare the central pixel with those on either side, for the four possible lines through it.
    104104
    105         // Soften weights (add systematic error)
    106         float softening = soft * PS_SQR(source->peak->flux); // Softening for weights
     105        // Soften variances (add systematic error)
     106        float softening = soft * PS_SQR(source->peak->flux); // Softening for variances
    107107
    108108        // Across the middle: y = 0
    109109        float cX = 2*resid[yPeak][xPeak]   - resid[yPeak+0][xPeak-1]  - resid[yPeak+0][xPeak+1];
    110         float dcX = 4*weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1];
     110        float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1];
    111111        float nX = cX / sqrtf(dcX + softening);
    112112
    113113        // Up the centre: x = 0
    114114        float cY = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak+0]  - resid[yPeak+1][xPeak+0];
    115         float dcY = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak+0] + weight[yPeak+1][xPeak+0];
     115        float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0];
    116116        float nY = cY / sqrtf(dcY + softening);
    117117
    118118        // Diagonal: x = y
    119119        float cL = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak-1]  - resid[yPeak+1][xPeak+1];
    120         float dcL = 4*weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1];
     120        float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1];
    121121        float nL = cL / sqrtf(dcL + softening);
    122122
    123123        // Diagonal: x = - y
    124124        float cR = 2*resid[yPeak][xPeak]   - resid[yPeak+1][xPeak-1]  - resid[yPeak-1][xPeak+1];
    125         float dcR = 4*weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1];
     125        float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1];
    126126        float nR = cR / sqrtf(dcR + softening);
    127127
     
    160160        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
    161161        if (source->crNsigma > CR_NSIGMA_LIMIT) {
    162             // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask);
    163             psphotMaskCosmicRay_Old (source, maskVal, crMask);
     162            // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask);
     163            psphotMaskCosmicRay_Old (source, maskVal, crMask);
    164164        }
    165165    }
     
    190190// deviation in sigmas.  This is measured on the residual image - should we ignore negative
    191191// deviations?
    192 static float psphotModelContour(const psImage *image, const psImage *weight, const psImage *mask,
     192static float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask,
    193193                                psImageMaskType maskVal, const pmModel *model, float Ro)
    194194{
     
    240240        if (yPixM >= 0 && yPixM < image->numRows &&
    241241            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {
    242             float dSigma = image->data.F32[yPixM][xPix] / sqrtf(weight->data.F32[yPixM][xPix]);
     242            float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]);
    243243            nSigma += dSigma;
    244244            nPts++;
     
    251251        if (yPixP >= 0 && yPixP < image->numRows &&
    252252            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {
    253             float dSigma = image->data.F32[yPixP][xPix] / sqrtf(weight->data.F32[yPixP][xPix]);
     253            float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]);
    254254            nSigma += dSigma;
    255255            nPts++;
     
    274274    pmFootprint *footprint = peak->footprint;
    275275    if (!footprint) {
    276         // if we have not footprint, use the old code to mask by isophot
    277         psphotMaskCosmicRay_Old (source, maskVal, crMask);
    278         return true;
     276        // if we have not footprint, use the old code to mask by isophot
     277        psphotMaskCosmicRay_Old (source, maskVal, crMask);
     278        return true;
    279279    }
    280280
    281281    if (!footprint->spans) {
    282         // if we have not footprint, use the old code to mask by isophot
    283         psphotMaskCosmicRay_Old (source, maskVal, crMask);
    284         return true;
     282        // if we have not footprint, use the old code to mask by isophot
     283        psphotMaskCosmicRay_Old (source, maskVal, crMask);
     284        return true;
    285285    }
    286286
    287287    // mask all of the pixels covered by the spans of the footprint
    288288    for (int j = 1; j < footprint->spans->n; j++) {
    289         pmSpan *span1 = footprint->spans->data[j];
    290 
    291         int iy = span1->y;
    292         int xs = span1->x0;
    293         int xe = span1->x1;
    294        
    295         for (int ix = xs; ix < xe; ix++) {
    296             mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
    297         }
     289        pmSpan *span1 = footprint->spans->data[j];
     290
     291        int iy = span1->y;
     292        int xs = span1->x0;
     293        int xe = span1->x1;
     294
     295        for (int ix = xs; ix < xe; ix++) {
     296            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
     297        }
    298298    }
    299299    return true;
     
    308308    psImage *mask   = source->maskView;
    309309    psImage *pixels = source->pixels;
    310     psImage *weight = source->weight;
     310    psImage *variance = source->variance;
    311311
    312312    // XXX This should be a recipe variable
     
    318318    // mark the pixels in this row to the left, then the right
    319319    for (int ix = xo; ix >= 0; ix--) {
    320         float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);
    321         if (SN > SN_LIMIT) {
    322             mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
    323         }
     320        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
     321        if (SN > SN_LIMIT) {
     322            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
     323        }
    324324    }
    325325    for (int ix = xo + 1; ix < pixels->numCols; ix++) {
    326         float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);
    327         if (SN > SN_LIMIT) {
    328             mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
    329         }
     326        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
     327        if (SN > SN_LIMIT) {
     328            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
     329        }
    330330    }
    331331
     
    333333    // first go up:
    334334    for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) {
    335         // mark the pixels in this row to the left, then the right
    336         for (int ix = 0; ix < pixels->numCols; ix++) {
    337             float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);
    338             if (SN < SN_LIMIT) continue;
    339 
    340             bool valid = false;
    341             valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
    342             valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
    343             valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
    344 
    345             if (!valid) continue;
    346             mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
    347         }
     335        // mark the pixels in this row to the left, then the right
     336        for (int ix = 0; ix < pixels->numCols; ix++) {
     337            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
     338            if (SN < SN_LIMIT) continue;
     339
     340            bool valid = false;
     341            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
     342            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
     343            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
     344
     345            if (!valid) continue;
     346            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
     347        }
    348348    }
    349349    // next go down:
    350350    for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) {
    351         // mark the pixels in this row to the left, then the right
    352         for (int ix = 0; ix < pixels->numCols; ix++) {
    353             float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);
    354             if (SN < SN_LIMIT) continue;
    355 
    356             bool valid = false;
    357             valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
    358             valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
    359             valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
    360 
    361             if (!valid) continue;
    362             mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
    363         }
     351        // mark the pixels in this row to the left, then the right
     352        for (int ix = 0; ix < pixels->numCols; ix++) {
     353            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
     354            if (SN < SN_LIMIT) continue;
     355
     356            bool valid = false;
     357            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
     358            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
     359            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
     360
     361            if (!valid) continue;
     362            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
     363        }
    364364    }
    365365    return true;
Note: See TracChangeset for help on using the changeset viewer.