IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2009, 3:11:32 PM (17 years ago)
Author:
eugene
Message:

check in changes from genes development branch : extensive changes to moments calculation, psf model generation, aperture residuals

File:
1 edited

Legend:

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

    r24874 r25754  
    282282
    283283    psArray *peaks  = NULL;
    284     pmPSFClump errorClump = {-1.0, -1.0, 0.0, 0.0};
    285     pmPSFClump emptyClump = {+0.0, +0.0, 0.0, 0.0};
     284    pmPSFClump errorClump = {-1.0, -1.0, 0.0, 0.0, 0, 0.0};
     285    pmPSFClump emptyClump = {+0.0, +0.0, 0.0, 0.0, 0, 0.0};
    286286    pmPSFClump psfClump;
    287287
     
    319319
    320320        // construct a sigma-plane image
    321         int numCols = SX_MAX / PSF_CLUMP_GRID_SCALE, numRows = SY_MAX / PSF_CLUMP_GRID_SCALE; // Size of sigma-plane image
     321        int numCols = 1 + SX_MAX / PSF_CLUMP_GRID_SCALE; // Size of sigma-plane image
     322        int numRows = 1 + SY_MAX / PSF_CLUMP_GRID_SCALE; // Size of sigma-plane image
    322323        psTrace("psModules.objects", 10, "sigma-plane dimensions: %dx%d\n", numCols, numRows);
    323324        psImage *splane = psImageAlloc(numCols, numRows, PS_TYPE_F32); // sigma-plane image
     
    332333            }
    333334
    334             int x = src->peak->x, y = src->peak->y; // Coordinates of peak
    335             if (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) {
    336                 continue;
    337             }
     335            if (region) {
     336                int x = src->peak->x, y = src->peak->y; // Coordinates of peak
     337                if (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) {
     338                    continue;
     339                }
     340            }
    338341
    339342            if (src->mode & PM_SOURCE_MODE_BLEND) {
    340343                continue;
    341344            }
     345
     346            if (!src->moments->nPixels) continue;
    342347
    343348            if (src->moments->SN < PSF_SN_LIM) {
     
    384389
    385390        // find the peak in this image
    386         psStats *stats = psStatsAlloc (PS_STAT_MAX);
     391        psStats *stats = psStatsAlloc (PS_STAT_MAX | PS_STAT_SAMPLE_STDEV);
    387392        if (!psImageStats (stats, splane, NULL, 0)) {
    388393            psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
     
    393398        peaks = pmPeaksInImage (splane, stats[0].max / 2);
    394399        psTrace ("psModules.objects", 2, "clump threshold is %f\n", stats[0].max/2);
     400
     401        psfClump.nSigma = stats->sampleStdev;
    395402
    396403        const bool keep_psf_clump = psMetadataLookupBool(NULL, recipe, "KEEP_PSF_CLUMP");
     
    430437        psTrace ("psModules.objects", 2, "clump is at %d, %d (%f)\n", clump->x, clump->y, clump->value);
    431438
     439        // XXX store the mean sigma?
     440        float meanSigma = psfClump.nSigma;
     441        psfClump.nStars = clump->value;
     442        psfClump.nSigma = clump->value / meanSigma;
     443
    432444        // define section window for clump
    433445        minSx = clump->x * PSF_CLUMP_GRID_SCALE - 2.0*PSF_CLUMP_GRID_SCALE;
     
    452464                continue;
    453465
    454             if (tmpSrc->peak->x < region->x0) continue;
    455             if (tmpSrc->peak->x > region->x1) continue;
    456             if (tmpSrc->peak->y < region->y0) continue;
    457             if (tmpSrc->peak->y > region->y1) continue;
     466            if (region) {
     467                if (tmpSrc->peak->x < region->x0) continue;
     468                if (tmpSrc->peak->x > region->x1) continue;
     469                if (tmpSrc->peak->y < region->y0) continue;
     470                if (tmpSrc->peak->y > region->y1) continue;
     471            }
    458472
    459473            if (tmpSrc->moments->Mxx < minSx)
     
    919933    if (model == NULL) return false;  // model must be defined
    920934
     935    bool addNoise = mode & PM_MODEL_OP_NOISE;
     936
    921937    if (source->modelFlux) {
    922938        // add in the pixels from the modelFlux image
     
    940956
    941957        psF32 **target = source->pixels->data.F32;
    942         if (mode & PM_MODEL_OP_NOISE) {
    943             // XXX need to scale by the gain...
     958        if (addNoise) {
     959            // when adding noise, we assume the shape and Io have been modified
    944960            target = source->variance->data.F32;
    945961        }
    946962
    947         // XXX need to respect the source and model masks?
    948963        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
    949964            int oy = iy + dY;
     
    959974            }
    960975        }
     976        if (!addNoise) {
     977            if (add) {
     978                source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     979            } else {
     980                source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     981            }
     982        }
    961983        return true;
    962984    }
    963985
    964986    psImage *target = source->pixels;
    965     if (mode & PM_MODEL_OP_NOISE) {
     987    if (addNoise) {
    966988        target = source->variance;
    967989    }
    968990
    969     if (add) {
    970         status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
    971     } else {
    972         status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     991    if (!addNoise) {
     992        if (add) {
     993            status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     994            source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     995        } else {
     996            status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     997            source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     998        }
    973999    }
    9741000
Note: See TracChangeset for help on using the changeset viewer.