IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36208


Ignore:
Timestamp:
Oct 13, 2013, 1:31:44 PM (13 years ago)
Author:
eugene
Message:

strip out old pmSourceMoments code (long ago moved to pmSourceMoments.c)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.c

    r36157 r36208  
    692692            // why do we recalculate moments here?
    693693            // we already attempt to do this in psphotSourceStats
    694             // pmSourceMoments (source, INNER_RADIUS);
    695694            Nsatstar ++;
    696695            continue;
     
    806805    return true;
    807806}
    808 
    809 /******************************************************************************
    810 pmSourceMoments(source, radius): this function takes a subImage defined in the
    811 pmSource data structure, along with the peak location, and determines the
    812 various moments associated with that peak.
    813 
    814 Requires the following to have been created:
    815     pmSource
    816     pmSource->peak
    817     pmSource->pixels
    818     pmSource->variance
    819     pmSource->mask
    820 
    821 XXX: The peak calculations are done in image coords, not subImage coords.
    822 
    823 XXX EAM : this version clips input pixels on S/N
    824 XXX EAM : this version returns false for several reasons
    825 *****************************************************************************/
    826 # define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0)
    827 
    828 /*** this been moved to pmSourceMoments.c ***/
    829 # if (0)
    830 bool pmSourceMoments(pmSource *source,
    831                      psF32 radius)
    832 {
    833     psTrace("psModules.objects", 10, "---- begin ----\n");
    834     PS_ASSERT_PTR_NON_NULL(source, false);
    835     PS_ASSERT_PTR_NON_NULL(source->peak, false);
    836     PS_ASSERT_PTR_NON_NULL(source->pixels, false);
    837     PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false);
    838 
    839     //
    840     // XXX: Verify the setting for sky if source->moments == NULL.
    841     //
    842     psF32 sky = 0.0;
    843     if (source->moments == NULL) {
    844         source->moments = pmMomentsAlloc();
    845     } else {
    846         sky = source->moments->Sky;
    847     }
    848 
    849     //
    850     // Sum = SUM (z - sky)
    851     // X1  = SUM (x - xc)*(z - sky)
    852     // X2  = SUM (x - xc)^2 * (z - sky)
    853     // XY  = SUM (x - xc)*(y - yc)*(z - sky)
    854     //
    855     psF32 peakPixel = -PS_MAX_F32;
    856     psS32 numPixels = 0;
    857     psF32 Sum = 0.0;
    858     psF32 Var = 0.0;
    859     psF32 X1 = 0.0;
    860     psF32 Y1 = 0.0;
    861     psF32 X2 = 0.0;
    862     psF32 Y2 = 0.0;
    863     psF32 XY = 0.0;
    864     psF32 x  = 0;
    865     psF32 y  = 0;
    866     psF32 R2 = PS_SQR(radius);
    867 
    868     psF32 xPeak = source->peak->x;
    869     psF32 yPeak = source->peak->y;
    870     psF32 xOff = source->pixels->col0 - source->peak->x;
    871     psF32 yOff = source->pixels->row0 - source->peak->y;
    872 
    873     // XXX why do I get different results for these two methods of finding Sx?
    874     // XXX Sx, Sy would be better measured if we clip pixels close to sky
    875     // XXX Sx, Sy can still be imaginary, so we probably need to keep Sx^2?
    876     // We loop through all pixels in this subimage (source->pixels), and for each
    877     // pixel that is not masked, AND within the radius of the peak pixel, we
    878     // proceed with the moments calculation.  need to do two loops for a
    879     // numerically stable result.  first loop: get the sums.
    880     // XXX EAM : mask == 0 is valid
    881 
    882     for (psS32 row = 0; row < source->pixels->numRows ; row++) {
    883 
    884         psF32 *vPix = source->pixels->data.F32[row];
    885         psF32 *vWgt = source->variance->data.F32[row];
    886         psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
    887 
    888         for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
    889             if (vMsk) {
    890                 if (*vMsk) {
    891                     vMsk++;
    892                     psTrace("psModules.objects", 10, "Ignoring pixel %d,%d due to mask: %d\n",
    893                             col, row, (int)*vMsk);
    894                     continue;
    895                 }
    896                 vMsk++;
    897             }
    898             if (isnan(*vPix)) continue;
    899 
    900             psF32 xDiff = col + xOff;
    901             psF32 yDiff = row + yOff;
    902 
    903             // radius is just a function of (xDiff, yDiff)
    904             if (!VALID_RADIUS(xDiff, yDiff, R2)) {
    905 #if 1
    906                 psTrace("psModules.objects", 10, "Ignoring pixel %d,%d due to position: %f %f\n",
    907                         col, row, xDiff, yDiff);
    908 #endif
    909                 continue;
    910             }
    911 
    912             psF32 pDiff = *vPix - sky;
    913             psF32 wDiff = *vWgt;
    914 
    915             // XXX EAM : check for valid S/N in pixel
    916             // XXX EAM : should this limit be user-defined?
    917 #if 1
    918             if (PS_SQR(pDiff) < wDiff) {
    919                 psTrace("psModules.objects", 10, "Ignoring pixel %d,%d due to insignificance: %f, %f\n",
    920                         col, row, pDiff, wDiff);
    921                 continue;
    922             }
    923 #endif
    924 
    925             Var += wDiff;
    926             Sum += pDiff;
    927 
    928             psF32 xWght = xDiff * pDiff;
    929             psF32 yWght = yDiff * pDiff;
    930 
    931             X1  += xWght;
    932             Y1  += yWght;
    933 
    934             XY  += xDiff * yWght;
    935             X2  += xDiff * xWght;
    936             Y2  += yDiff * yWght;
    937 
    938             peakPixel = PS_MAX (*vPix, peakPixel);
    939             numPixels++;
    940         }
    941     }
    942 
    943     // if we have less than (1/4) of the possible pixels, force a retry
    944     // XXX EAM - the limit is a bit arbitrary.  make it user defined?
    945     if ((numPixels < 0.75*R2) || (Sum <= 0)) {
    946         psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n",
    947                  numPixels, (int)(0.75*R2), Sum);
    948         psTrace("psModules.objects", 10, "---- end (false) ----\n");
    949         return (false);
    950     }
    951 
    952     psTrace ("psModules.objects", 4, "sky: %f  Sum: %f  X1: %f  Y1: %f  X2: %f  Y2: %f  XY: %f  Npix: %d\n",
    953              sky, Sum, X1, Y1, X2, Y2, XY, numPixels);
    954 
    955     //
    956     // first moment X  = X1/Sum + xc
    957     // second moment X = sqrt (X2/Sum - (X1/Sum)^2)
    958     // Sxy             = XY / Sum
    959     //
    960     x = X1/Sum;
    961     y = Y1/Sum;
    962     if ((fabs(x) > radius) || (fabs(y) > radius)) {
    963         psTrace ("psModules.objects", 3, "large centroid swing; invalid peak %d, %d\n",
    964                  source->peak->x, source->peak->y);
    965         psTrace("psModules.objects", 10, "---- end(false)  ----\n");
    966         return (false);
    967     }
    968 
    969     source->moments->Mx = x + xPeak;
    970     source->moments->My = y + yPeak;
    971 
    972     // XXX EAM : Sxy needs to have x*y subtracted
    973     source->moments->Mxy = XY/Sum - x*y;
    974     source->moments->Sum = Sum;
    975     source->moments->SN  = Sum / sqrt(Var);
    976     source->moments->Peak = peakPixel;
    977     source->moments->nPixels = numPixels;
    978 
    979     // XXX EAM : these values can be negative, so we need to limit the range
    980     // XXX EAM : make the use of this consistent: should this be the second moment or sqrt?
    981     // source->moments->Mxx = sqrt(PS_MAX(X2/Sum - PS_SQR(x), 0));
    982     // source->moments->Myy = sqrt(PS_MAX(Y2/Sum - PS_SQR(y), 0));
    983     source->moments->Mxx = PS_MAX(X2/Sum - PS_SQR(x), 0);
    984     source->moments->Myy = PS_MAX(Y2/Sum - PS_SQR(y), 0);
    985 
    986     psTrace ("psModules.objects", 4,
    987              "sky: %f  Sum: %f  Mx: %f  My: %f  Mxx: %f  Myy: %f  Mxy: %f\n",
    988              sky, Sum, source->moments->Mx, source->moments->My,
    989              source->moments->Mxx, source->moments->Myy, source->moments->Mxy);
    990 
    991     psTrace("psModules.objects", 10, "---- end ----\n");
    992     return(true);
    993 }
    994 # endif
    995807
    996808// construct a realization of the source model
Note: See TracChangeset for help on using the changeset viewer.