IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2011, 1:04:41 PM (15 years ago)
Author:
eugene
Message:

updates to pmPeak to better distinguish peak flux versions; updates to visualization; add bits for substantial suspect masking; consolidate assignment of source position and flux based on peak, moments, etc; improve footprint culling process; fix PSF_QF and PSF_QF_PERFECT calculations; fix source model chisq values

Location:
trunk/psModules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules

    • Property svn:ignore
      •  

        old new  
        2828ChangeLog
        2929psmodules-*.tar.*
         30a.out.dSYM
  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r29935 r31153  
    2323#include "pmFPAMaskWeight.h"
    2424
     25#include "pmConfigMask.h"
    2526#include "pmTrend2D.h"
    2627#include "pmResiduals.h"
     
    4950static float AP_MIN_SN = 0.0;
    5051
    51 bool pmSourceMagnitudesInit (psMetadata *config)
    52 {
    53     PS_ASSERT_PTR_NON_NULL(config, false);
     52// make this a bit more clever and dynamic
     53static psImageMaskType maskSuspect  = 0;
     54static psImageMaskType maskSpike    = 0;
     55static psImageMaskType maskStarCore = 0;
     56static psImageMaskType maskBurntool = 0;
     57static psImageMaskType maskConvPoor = 0;
     58
     59bool pmSourceMagnitudesInit (pmConfig *config, psMetadata *recipe)
     60{
     61    PS_ASSERT_PTR_NON_NULL(recipe, false);
    5462    bool status;
    5563
    56     float limit = psMetadataLookupF32 (&status, config, "AP_MIN_SN");
     64    // we are going to test specially against these poor values
     65    if (config) {
     66        maskSpike    = pmConfigMaskGet("SPIKE", config);
     67        maskStarCore = pmConfigMaskGet("STARCORE", config);
     68        maskBurntool = pmConfigMaskGet("BURNTOOL", config);
     69        maskConvPoor = pmConfigMaskGet("CONV.POOR", config);
     70        maskSuspect  = maskSpike | maskStarCore | maskBurntool | maskConvPoor;
     71    }
     72
     73    float limit = psMetadataLookupF32 (&status, recipe, "AP_MIN_SN");
    5774    if (status) {
    5875        AP_MIN_SN = limit;
     
    7794// XXX masked region should be (optionally) elliptical
    7895// if mode is PM_SOURCE_PHOT_PSFONLY, we skip all other magnitudes
    79 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal)
     96bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal, float radius)
    8097{
    8198    PS_ASSERT_PTR_NON_NULL(source, false);
     
    166183    // measure the contribution of included pixels
    167184    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    168         pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal);
     185        pmSourcePixelWeight (source, model, source->maskObj, maskVal, radius);
    169186    }
    170187
     
    342359
    343360// return source aperture magnitude
    344 bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal)
    345 {
    346     PS_ASSERT_PTR_NON_NULL(pixWeightNotBad, false);
    347     PS_ASSERT_PTR_NON_NULL(pixWeightNotPoor, false);
     361bool pmSourcePixelWeight (pmSource *source, pmModel *model, psImage *mask, psImageMaskType maskVal, float radius)
     362{
     363    PS_ASSERT_PTR_NON_NULL(source, false);
     364    source->pixWeightNotBad = NAN;
     365    source->pixWeightNotPoor = NAN;
     366
    348367    PS_ASSERT_PTR_NON_NULL(mask, false);
    349368    PS_ASSERT_PTR_NON_NULL(model, false);
     
    355374    float value;
    356375
     376    float spikeSum = 0;
     377    float starcoreSum = 0;
     378    float burntoolSum = 0;
     379    float convpoorSum = 0;
     380
    357381    int Xo, Yo, dP;
    358382    int dX, DX, NX;
    359383    int dY, DY, NY;
    360384
    361     *pixWeightNotBad = 0.0;
    362     *pixWeightNotPoor = 0.0;
     385    float radius2 = PS_SQR(radius);
    363386
    364387    // we only care about the value of the object model, not the local sky
     
    387410    NY = mask->numRows;
    388411
     412    psImageMaskType maskBad = maskVal;
     413    maskBad &= ~maskSuspect;
     414
    389415    // measure modelSum and validSum.  this function is applied to a sources' subimage.  the
    390416    // value of DX is chosen (see above) to cover the full possible size of the subimage if it
    391417    // were not by an edge; ie, if the source is cut in half by an image edge, we correctly
    392418    // count the virtual pixels off the edge in normalizing the value of the pixWeight
     419
     420    // we skip any pixels [real or virtual] outside of the specified radius (nominally the aperture radius)
    393421    for (int ix = -DX; ix < DX + 1; ix++) {
     422        if (ix > radius) continue;
    394423        int mx = ix + dX;
    395424        for (int iy = -DY; iy < DY + 1; iy++) {
     425            if (iy > radius) continue;
     426            if (ix*ix + iy*iy > radius2) continue;
    396427            int my = iy + dY;
    397428
     
    409440            if (my >= NY) continue;
    410441
    411             if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) {
     442            // count pixels which are masked only with bad pixels
     443            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskBad)) {
    412444                notBadSum += value;
    413445            }
    414             if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & ~markVal)) {
     446
     447            // count pixels which are masked with an mask bit (bad or poor)
     448            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) {
    415449                notPoorSum += value;
    416450            }
     451
     452            // count pixels which are masked with an mask bit (bad or poor)
     453            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskSpike) {
     454                spikeSum += value;
     455            }
     456            // count pixels which are masked with an mask bit (bad or poor)
     457            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskStarCore) {
     458                starcoreSum += value;
     459            }
     460            // count pixels which are masked with an mask bit (bad or poor)
     461            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskBurntool) {
     462                burntoolSum += value;
     463            }
     464            // count pixels which are masked with an mask bit (bad or poor)
     465            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskConvPoor) {
     466                convpoorSum += value;
     467            }
    417468        }
    418469    }
    419470    psFree (coord);
    420471
    421     *pixWeightNotBad  = notBadSum  / modelSum;
    422     *pixWeightNotPoor = notPoorSum / modelSum;
     472    source->pixWeightNotBad  = notBadSum  / modelSum;
     473    source->pixWeightNotPoor = notPoorSum / modelSum;
     474
     475    if ((spikeSum/modelSum) > 0.25) {
     476        source->mode2 |= PM_SOURCE_MODE2_ON_SPIKE;
     477    }
     478    if ((starcoreSum/modelSum) > 0.25) {
     479        source->mode2 |= PM_SOURCE_MODE2_ON_STARCORE;
     480    }
     481    if ((burntoolSum/modelSum) > 0.25) {
     482        source->mode2 |= PM_SOURCE_MODE2_ON_BURNTOOL;
     483    }
     484    if ((convpoorSum/modelSum) > 0.25) {
     485        source->mode2 |= PM_SOURCE_MODE2_ON_CONVPOOR;
     486    }
     487
     488    if (isfinite(source->pixWeightNotBad) && isfinite(source->pixWeightNotPoor)) {
     489        psAssert (source->pixWeightNotBad <= source->pixWeightNotPoor, "error: all bad pixels should also be poor");
     490    }
    423491
    424492    return (true);
     
    427495# define FLUX_LIMIT 3.0
    428496
    429 // measure stats that may be using in difference images for distinguishing real sources from bad residuals
     497// measure stats that may be used in difference images for distinguishing real sources from bad residuals
    430498bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    431499{
     
    673741# endif
    674742
    675 // determine chisq, etc for linear normalization-only fit
    676 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *variance, psImageMaskType maskVal, const float covarFactor)
     743// determine chisq, nPix, nDOF, chisqNorm : model->nPar must be set
     744bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *variance, psImageMaskType maskVal)
    677745{
    678746    PS_ASSERT_PTR_NON_NULL(model, false);
     
    689757            if (variance->data.F32[j][i] <= 0)
    690758                continue;
    691             dC += PS_SQR (image->data.F32[j][i]) / (covarFactor * variance->data.F32[j][i]);
     759            dC += PS_SQR (image->data.F32[j][i]) / variance->data.F32[j][i];
    692760            Npix ++;
    693761        }
    694762    }
    695763    model->nPix = Npix;
    696     model->nDOF = Npix - 1;
     764    model->nDOF = Npix - model->nPar;
    697765    model->chisq = dC;
     766    model->chisqNorm = dC / model->nDOF;
    698767
    699768    return (true);
    700769}
    701770
     771
     772// return source aperture magnitude
     773bool pmSourceChisqUnsubtracted (pmSource *source, pmModel *model, psImageMaskType maskVal)
     774{
     775    PS_ASSERT_PTR_NON_NULL(source, false);
     776    PS_ASSERT_PTR_NON_NULL(model, false);
     777
     778    float dC = 0.0;
     779    int Npix = 0;
     780
     781    // the model function returns the source flux at a position
     782    psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
     783
     784    psVector *params = model->params;
     785    psImage  *image = source->pixels;
     786    psImage  *mask = source->maskObj;
     787    psImage  *variance = source->variance;
     788
     789    int dX = image->col0;
     790    int dY = image->row0;
     791
     792    for (int iy = 0; iy < image->numRows; iy++) {
     793        for (int ix = 0; ix < image->numCols; ix++) {
     794
     795            // skip pixels which are masked
     796            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue;
     797
     798            if (variance->data.F32[iy][ix] <= 0) continue;
     799
     800            coord->data.F32[0] = (psF32) ix + dX + 0.5;
     801            coord->data.F32[1] = (psF32) iy + dY + 0.5;
     802
     803            // for the full model, add all points
     804            float value = model->modelFunc (NULL, params, coord);
     805
     806            // fprintf (stderr, "%d, %d : %f, %f : %f - %f : %f\n",
     807            // ix, iy, coord->data.F32[0], coord->data.F32[1], image->data.F32[iy][ix], value, dC);
     808
     809            dC += PS_SQR (image->data.F32[iy][ix] - value) / variance->data.F32[iy][ix];
     810            Npix ++;
     811        }
     812    }
     813    model->nPix = Npix;
     814    model->nDOF = Npix - model->nPar;
     815    model->chisq = dC;
     816    model->chisqNorm = dC / model->nDOF;
     817
     818    psFree (coord);
     819    return (true);
     820}
    702821
    703822double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
Note: See TracChangeset for help on using the changeset viewer.