IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 7, 2008, 10:12:27 AM (18 years ago)
Author:
Paul Price
Message:

Cleaning up pmSourcePSFClump, adding trace statements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSource.c

    r19906 r19954  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2008-10-06 13:05:13 $
     8 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2008-10-07 20:12:27 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    279279    psTrace("psModules.objects", 5, "---- begin ----\n");
    280280
    281     # define NPIX 10
    282     # define SCALE 0.1
     281// XXX This should be in the recipe
     282#define SCALE 0.1                       // Scale of splane
    283283
    284284    psArray *peaks  = NULL;
     
    290290    PS_ASSERT_PTR_NON_NULL(recipe, errorClump);
    291291
    292     bool status = true;
    293     float PSF_CLUMP_SN_LIM = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_SN_LIM");
     292    bool status = true;                 // Status of MD lookup
     293    float PSF_CLUMP_SN_LIM = psMetadataLookupF32(&status, recipe, "PSF_CLUMP_SN_LIM");
    294294    if (!status) {
    295295        PSF_CLUMP_SN_LIM = 0;
     
    298298    // find the sigmaX, sigmaY clump
    299299    {
    300         psStats *stats  = NULL;
    301         psImage *splane = NULL;
    302         int binX, binY;
    303         bool status;
    304 
    305         psF32 SX_MAX = psMetadataLookupF32 (&status, recipe, "MOMENTS_SX_MAX");
    306         if (!status)
     300        psF32 SX_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SX_MAX");
     301        if (!status) {
     302            psWarning("MOMENTS_SX_MAX not set in recipe");
    307303            SX_MAX = 10.0;
    308         psF32 SY_MAX = psMetadataLookupF32 (&status, recipe, "MOMENTS_SY_MAX");
    309         if (!status)
     304        }
     305        psF32 SY_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_SY_MAX");
     306        if (!status) {
     307            psWarning("MOMENTS_SY_MAX not set in recipe");
    310308            SY_MAX = 10.0;
    311         psF32 AR_MAX = psMetadataLookupF32 (&status, recipe, "MOMENTS_AR_MAX");
    312         if (!status)
     309        }
     310        psF32 AR_MAX = psMetadataLookupF32(&status, recipe, "MOMENTS_AR_MAX");
     311        if (!status) {
     312            psWarning("MOMENTS_AR_MAX not set in recipe");
    313313            AR_MAX =  3.0;
     314        }
    314315        psF32 AR_MIN = 1.0 / AR_MAX;
    315316
    316317        // construct a sigma-plane image
    317         splane = psImageAlloc (SX_MAX/SCALE, SY_MAX/SCALE, PS_TYPE_F32);
    318         psImageInit(splane, 0);  // psImageAlloc doesn't zero the data
     318        int numCols = SX_MAX / SCALE, numRows = SY_MAX / SCALE; // Size of sigma-plane image
     319        psTrace("psModules.objects", 10, "sigma-plane dimensions: %dx%d\n", numCols, numRows);
     320        psImage *splane = psImageAlloc(numCols, numRows, PS_TYPE_F32); // sigma-plane image
     321        psImageInit(splane, 0);
    319322
    320323        // place the sources in the sigma-plane image (ignore 0,0 values?)
    321         int nValid = 0;
    322         for (psS32 i = 0 ; i < sources->n ; i++)
    323         {
    324             pmSource *tmpSrc = (pmSource *) sources->data[i];
    325             if (tmpSrc == NULL)
    326                 continue;
    327             if (tmpSrc->moments == NULL)
    328                 continue;
    329             if (tmpSrc->moments->SN < PSF_CLUMP_SN_LIM)
    330                 continue;
    331 
    332             if (tmpSrc->peak->x < region->x0) continue;
    333             if (tmpSrc->peak->x > region->x1) continue;
    334             if (tmpSrc->peak->y < region->y0) continue;
    335             if (tmpSrc->peak->y > region->y1) continue;
     324        int nValid = 0;                 // Number of valid sources
     325        for (int i = 0; i < sources->n; i++) {
     326            pmSource *src = sources->data[i]; // Source of interest
     327            if (!src || !src->moments) {
     328                continue;
     329            }
     330
     331            int x = src->peak->x, y = src->peak->y; // Coordinates of peak
     332            if (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) {
     333                continue;
     334            }
     335
     336            if (src->mode & PM_SOURCE_MODE_BLEND) {
     337                continue;
     338            }
     339
     340            if (src->moments->SN < PSF_CLUMP_SN_LIM) {
     341                psTrace("psModules.objects", 10, "Rejecting source from clump because of low S/N (%f)\n",
     342                        src->moments->SN);
     343                continue;
     344            }
     345
     346            float Mxx = src->moments->Mxx, Myy = src->moments->Myy; // Second moments
     347            float ar = Mxx / Myy;       // Radius
    336348
    337349            // Sx,Sy are limited at 0.  a peak at 0,0 is artificial
    338             if (fabs(tmpSrc->moments->Mxx) < 0.05)
    339                 continue;
    340             if (fabs(tmpSrc->moments->Myy) < 0.05)
    341                 continue;
    342             if ((tmpSrc->moments->Mxx / tmpSrc->moments->Myy) > AR_MAX)
    343                 continue;
    344             if ((tmpSrc->moments->Mxx / tmpSrc->moments->Myy) < AR_MIN)
    345                 continue;
    346             if (tmpSrc->mode & PM_SOURCE_MODE_BLEND)
    347                 continue;
     350            if (fabs(Mxx) < 0.05 || fabs(Myy < 0.05)) {
     351                psTrace("psModules.objects", 10,
     352                        "Rejecting source from clump because of low moments (%f,%f)\n",
     353                        Mxx, Myy);
     354                continue;
     355            }
     356            if (Mxx > SX_MAX || Myy > SY_MAX) {
     357                psTrace("psModules.objects", 10,
     358                        "Rejecting source from clump because of high moments (%f,%f)\n",
     359                        Mxx, Myy);
     360                continue;
     361            }
     362            if (ar > AR_MAX || ar < AR_MIN) {
     363                psTrace("psModules.objects", 10, "Rejecting source from clump because of Ar (%f)\n", ar);
     364                continue;
     365            }
    348366
    349367            // for the moment, force splane dimensions to be 10x10 image pix
    350             binX = tmpSrc->moments->Mxx/SCALE;
    351             if (binX < 0)
    352                 continue;
    353             if (binX >= splane->numCols)
    354                 continue;
    355 
    356             binY = tmpSrc->moments->Myy/SCALE;
    357             if (binY < 0)
    358                 continue;
    359             if (binY >= splane->numRows)
    360                 continue;
     368            int binX = Mxx / SCALE, binY = Myy /  SCALE; // Position on splane
     369            psAssert(binX >= 0 && binX < numCols && binY >= 0 && binY < numRows, "We checked it already");
    361370
    362371            splane->data.F32[binY][binX] += 1.0;
    363             nValid ++;
     372            nValid++;
    364373        }
    365374
    366375        // find the peak in this image
    367         stats = psStatsAlloc (PS_STAT_MAX);
     376        psStats *stats = psStatsAlloc (PS_STAT_MAX);
    368377        if (!psImageStats (stats, splane, NULL, 0)) {
    369378            psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
     
    433442                continue;
    434443
    435             if (tmpSrc->peak->x < region->x0) continue;
    436             if (tmpSrc->peak->x > region->x1) continue;
    437             if (tmpSrc->peak->y < region->y0) continue;
    438             if (tmpSrc->peak->y > region->y1) continue;
     444            if (tmpSrc->peak->x < region->x0) continue;
     445            if (tmpSrc->peak->x > region->x1) continue;
     446            if (tmpSrc->peak->y < region->y0) continue;
     447            if (tmpSrc->peak->y > region->y1) continue;
    439448
    440449            if (tmpSrc->moments->Mxx < minSx)
     
    521530        pmSource *source = (pmSource *) sources->data[i];
    522531
    523         if (source->peak->x < region->x0) continue;
    524         if (source->peak->x > region->x1) continue;
    525         if (source->peak->y < region->y0) continue;
    526         if (source->peak->y > region->y1) continue;
     532        if (source->peak->x < region->x0) continue;
     533        if (source->peak->x > region->x1) continue;
     534        if (source->peak->y < region->y0) continue;
     535        if (source->peak->y > region->y1) continue;
    527536
    528537        source->peak->type = 0;
     
    721730                vMsk++;
    722731            }
    723             if (isnan(*vPix)) continue;
     732            if (isnan(*vPix)) continue;
    724733
    725734            psF32 xDiff = col + xOff;
     
    893902        psF32 **target = source->pixels->data.F32;
    894903        if (mode & PM_MODEL_OP_NOISE) {
    895             // XXX need to scale by the gain...
     904            // XXX need to scale by the gain...
    896905            target = source->weight->data.F32;
    897906        }
     
    967976        return model;
    968977
    969         // the 'best' extended model is saved in source->modelEXT (may be a pointer to one of
    970         // the elements of source->modelFits)
     978        // the 'best' extended model is saved in source->modelEXT (may be a pointer to one of
     979        // the elements of source->modelFits)
    971980      case PM_SOURCE_TYPE_EXTENDED:
    972         model = source->modelEXT;
     981        model = source->modelEXT;
    973982        if (!model && source->modelPSF) {
    974             // XXX raise an error or warning here?
     983            // XXX raise an error or warning here?
    975984            if (isPSF) {
    976985                *isPSF = true;
Note: See TracChangeset for help on using the changeset viewer.