IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 17, 2023, 3:27:26 PM (3 years ago)
Author:
eugene
Message:

use peak position instead of centroids only for faint (S/N < 25) sources; only skip negative-sum sources if they are not externally supplied

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/psModules/src/objects/pmSourceMoments.c

    r38873 r42511  
    231231    }
    232232
     233    // For faint externally-supplied sources, the centroids are unreliable.
     234    // In those cases, we should keep the peak position instead of the centroid position.
     235    bool skipCentroid = false;
     236    skipCentroid |= (source->mode  & PM_SOURCE_MODE_EXTERNAL); // skip externally supplied positions
     237    skipCentroid |= (source->mode2 & PM_SOURCE_MODE2_MATCHED); // skip sources defined by other image positions
     238
    233239    // if we have less than (1/4) of the possible pixels (in circle or box), force a retry
    234240    int minPixels = PS_MIN(0.75*R2, source->pixels->numCols*source->pixels->numRows/4.0);
    235241
    236242    // XXX EAM - the limit is a bit arbitrary.  make it user defined?
    237     if ((numPixels < minPixels) || (Sum <= 0)) {
     243    if (numPixels < minPixels) {
    238244        psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n", numPixels, minPixels, Sum);
     245        return (false);
     246    }
     247
     248    // Skip negative-sum sources, but only if the sources are not forced (externally supplied)
     249    if (!skipCentroid && (Sum <= 0)) {
     250        psTrace ("psModules.objects", 3, "insufficient significant pixels (%d vs %d; %f) for source\n", numPixels, minPixels, Sum);
    239251        return (false);
    240252    }
     
    243255    float Mx = X1/Sum;
    244256    float My = Y1/Sum;
    245     if ((fabs(Mx) > radius) || (fabs(My) > radius)) {
    246         psTrace ("psModules.objects", 3, "extreme centroid swing; invalid peak %d, %d\n", source->peak->x, source->peak->y);
    247         return (false);
    248     }
    249257    if ((fabs(Mx) > 2.0) || (fabs(My) > 2.0)) {
    250258        psTrace ("psModules.objects", 3, " big centroid swing; ok peak? %d, %d\n", source->peak->x, source->peak->y);
    251259    }
    252 
    253260    psTrace ("psModules.objects", 5, "id: %d, sky: %f  Mx: %f  My: %f  Sum: %f  X1: %f  Y1: %f  Npix: %d\n", source->id, sky, Mx, My, Sum, X1, Y1, numPixels);
     261
     262    // XXX EAM : I need to move this block so I can use SN to choose if we keep the centroids or not
     263    source->moments->Sum = Sum;
     264    source->moments->SN  = Sum / sqrt(Var);
     265    source->moments->Peak = peakPixel;
     266    source->moments->nPixels = numPixels;
    254267
    255268    // add back offset of peak in primary image
     
    258271    // 0.5 PIX: moments are calculated using the pixel index and converted here to pixel coords
    259272
    260     // we only update the centroid if the position is not supplied from elsewhere
    261     bool skipCentroid = false;
    262     skipCentroid |= (source->mode  & PM_SOURCE_MODE_EXTERNAL); // skip externally supplied positions
    263     skipCentroid |= (source->mode2 & PM_SOURCE_MODE2_MATCHED); // skip sources defined by other image positions
    264 
    265     if (skipCentroid) {
     273    // XXX for a test, do NOT skip the centroid for relatively strong sources, even if forced
     274    // XXX this is a somewhat arbitrary limit.  use PSF_SN_LIM (see below) instead?
     275    if (skipCentroid && (source->moments->SN < 25)) {
    266276        source->moments->Mx = source->peak->xf;
    267277        source->moments->My = source->peak->yf;
    268278    } else {
     279        if ((fabs(Mx) > radius) || (fabs(My) > radius)) {
     280            psTrace ("psModules.objects", 3, "extreme centroid swing; invalid peak %d, %d\n", source->peak->x, source->peak->y);
     281
     282            // XXX should we really be rejecting these sources, or just keeping the peak position?
     283            return (false);
     284
     285            source->moments->Mx = source->peak->xf;
     286            source->moments->My = source->peak->yf;
     287            return (true);
     288        }
    269289        source->moments->Mx = Mx + xGuess;
    270290        source->moments->My = My + yGuess;
    271291    }
    272 
    273     source->moments->Sum = Sum;
    274     source->moments->SN  = Sum / sqrt(Var);
    275     source->moments->Peak = peakPixel;
    276     source->moments->nPixels = numPixels;
    277292
    278293    return true;
Note: See TracChangeset for help on using the changeset viewer.