IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34542


Ignore:
Timestamp:
Oct 24, 2012, 8:52:34 AM (14 years ago)
Author:
bills
Message:

In psphotStack add third pass for psphotKronIterate. Here measure kron flux
but not radius for matched sources. The radial momement for these is set to the
minimum of the values for the detected sources for the object

Location:
trunk/psphot/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphot.h

    r34528 r34542  
    372372bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, const char *filerule, int index);
    373373bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS);
    374 bool psphotDropBadMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
     374bool psphotFilterMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
    375375
    376376bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final);
  • trunk/psphot/src/psphotKronIterate.c

    r34418 r34542  
    22
    33bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool oldWindow);
    4 bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, bool applyWeight, psImage *smoothedPixels);
     4bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal, bool applyWeight, psImage *smoothedPixels, bool measureRadius);
    55
    66
     
    185185    }
    186186
     187    if (pass == 3) {
     188        KRON_SMOOTH = false;
     189        KRON_ITERATIONS = 1;
     190    }
     191
    187192    // We measure the Kron Radius on a smoothed copy of the readout image
    188193    psImage *smoothedImage = NULL;
     
    311316    float KRON_SB_MIN_DIVISOR       = PS_SCALAR_VALUE(job->args->data[12],F32);
    312317    int pass                        = PS_SCALAR_VALUE(job->args->data[13],S32);
    313 #ifndef REVERT_ON_BAD_MEASUREMENT
    314     (void) pass;
    315 #endif
     318
     319    bool measureRadius = true;
     320    if (pass == 3) {
     321        measureRadius = false;
     322    }
    316323
    317324    for (int j = 0; j < KRON_ITERATIONS; j++) {
     
    320327            pmSource *source = sources->data[i];
    321328            if (!source->peak) continue; // XXX how can we have a peak-less source?
     329
     330            if (pass == 3) {
     331                // in pass 3 we only measure the flux for matched sources
     332                if (!(source->mode2 & PM_SOURCE_MODE2_MATCHED)) {
     333                    continue;
     334                }
     335            }
    322336
    323337# if (0)
     
    331345# endif
    332346
    333             // check status of this source's moments
    334             if (!source->moments) continue;
    335             if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
    336             if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     347            if (measureRadius) {
     348                // check status of this source's moments
     349                if (!source->moments) continue;
     350                if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
     351                if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     352            }
     353
    337354            if (!isfinite(source->moments->Mrf)) {
    338355                // Once we save a bad Mrf measurement we give up on this source
     
    358375            // On first iteration set window radius to sky radius (if valid). We also use this on subsequent
    359376            // iterations if we cannot find a better limit
    360             float maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS;
     377            float maxWindow;
     378            if (measureRadius) {
     379                maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS;
     380            } else {
     381                maxWindow = source->moments->Mrf;
     382            }
    361383            if (j > 0) {
    362384                // on subsequent iterations we use a factor times the previous radial moment value
     
    402424            // does not meet the requirements for measuring the Kron Radius or Magnitude.
    403425            // Note: that it performs the cuts even if KRON_APPLY_WINDOW is false
    404             if (psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) {
     426            if (!measureRadius || psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) {
    405427
    406428                // this function populates moments->Mrf,KronFlux,KronFluxErr
    407                 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, KRON_APPLY_WEIGHT, smoothedPixels);
     429                psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal,
     430                    KRON_APPLY_WEIGHT, smoothedPixels, measureRadius);
     431
    408432                psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    409433
     
    444468
    445469bool psphotKronWindowMag (pmSource *source, psImage *kronWindow, float radius, float minKronRadius, psImageMaskType maskVal,
    446     bool applyWeight, psImage *smoothedPixels) {
     470    bool applyWeight, psImage *smoothedPixels, bool measureRadius) {
    447471
    448472    PS_ASSERT_PTR_NON_NULL(source, false);
     
    495519    psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
    496520
    497     for (psS32 row = 0; row < source->pixels->numRows ; row++) {
    498 
    499         psF32 yDiff = row - yCM;
    500         if (fabs(yDiff) > radius) continue;
    501 
    502         // coordinate of mirror pixel
    503         int yFlip = yCM - yDiff;
    504         if (yFlip < 0) continue;
    505         if (yFlip >= source->pixels->numRows) continue;
    506 
    507         for (psS32 col = 0; col < source->pixels->numCols ; col++) {
    508             // check mask and value for this pixel
    509             if (vMsk && (vMsk[row][col] & maskVal)) continue;
    510             if (isnan(vPix[row][col])) continue;
    511 
    512             psF32 xDiff = col - xCM;
    513             if (fabs(xDiff) > radius) continue;
    514 
    515             // coordinate of mirror pixel
    516             int xFlip = xCM - xDiff;
    517             if (xFlip < 0) continue;
    518             if (xFlip >= source->pixels->numCols) continue;
    519 
    520             // check mask and value for mirror pixel
    521             if (vMsk && (vMsk[yFlip][xFlip] & maskVal)) continue;
    522             if (isnan(vPix[yFlip][xFlip])) continue;
    523 
    524             // radius is just a function of (xDiff, yDiff)
    525             psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
    526             if (r2 > R2) continue;
    527 
    528             // flux * window
    529             float z = r2 * rsigma2;
    530             assert (z >= 0.0);
    531 
    532             // weight by window image and wide Gaussian
    533             float weight1  = vWin[row+Ywo][col+Xwo]*exp(-z);
    534             float weight2  = vWin[yFlip+Ywo][xFlip+Xwo]*exp(-z);
    535 
    536             float fDiff1 = vPix[row][col]*weight1;
    537             float fDiff2 = vPix[yFlip][xFlip]*weight2;
    538 
    539             float pDiff = (fDiff1 > 0.0) ? sqrt(fabs(fDiff1*fDiff2)) : -sqrt(fabs(fDiff1*fDiff2));
    540 
    541             // Kron Flux uses the 1st radial moment (maybe Gaussian windowed?)
    542             psF32 rf = pDiff * sqrt(r2);
    543             psF32 rs = 0.5 * (fDiff1 + fDiff2);
    544 
    545             RF  += rf;
    546             RS  += rs;
    547         }
    548     }
    549 
    550     float MrfTry = RF/RS;
    551     if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) {
    552         // We did not get a good measurement
    553         source->moments->Mrf = NAN;
    554         source->moments->KronFlux  = NAN;
    555         source->moments->KronFluxErr  = NAN;
    556         return false;
    557     }
    558 
    559     float Mrf = MAX(minKronRadius, MrfTry);
    560     // Saturate the 1st radial moment
    561     if (sqrt(source->peak->detValue) < 10.0) {
    562         Mrf = MIN (radius, Mrf);
     521    if (measureRadius) {
     522        for (psS32 row = 0; row < source->pixels->numRows ; row++) {
     523
     524            psF32 yDiff = row - yCM;
     525            if (fabs(yDiff) > radius) continue;
     526
     527            // coordinate of mirror pixel
     528            int yFlip = yCM - yDiff;
     529            if (yFlip < 0) continue;
     530            if (yFlip >= source->pixels->numRows) continue;
     531
     532            for (psS32 col = 0; col < source->pixels->numCols ; col++) {
     533                // check mask and value for this pixel
     534                if (vMsk && (vMsk[row][col] & maskVal)) continue;
     535                if (isnan(vPix[row][col])) continue;
     536
     537                psF32 xDiff = col - xCM;
     538                if (fabs(xDiff) > radius) continue;
     539
     540                // coordinate of mirror pixel
     541                int xFlip = xCM - xDiff;
     542                if (xFlip < 0) continue;
     543                if (xFlip >= source->pixels->numCols) continue;
     544
     545                // check mask and value for mirror pixel
     546                if (vMsk && (vMsk[yFlip][xFlip] & maskVal)) continue;
     547                if (isnan(vPix[yFlip][xFlip])) continue;
     548
     549                // radius is just a function of (xDiff, yDiff)
     550                psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     551                if (r2 > R2) continue;
     552
     553                // flux * window
     554                float z = r2 * rsigma2;
     555                assert (z >= 0.0);
     556
     557                // weight by window image and wide Gaussian
     558                float weight1  = vWin[row+Ywo][col+Xwo]*exp(-z);
     559                float weight2  = vWin[yFlip+Ywo][xFlip+Xwo]*exp(-z);
     560
     561                float fDiff1 = vPix[row][col]*weight1;
     562                float fDiff2 = vPix[yFlip][xFlip]*weight2;
     563
     564                float pDiff = (fDiff1 > 0.0) ? sqrt(fabs(fDiff1*fDiff2)) : -sqrt(fabs(fDiff1*fDiff2));
     565
     566                // Kron Flux uses the 1st radial moment (maybe Gaussian windowed?)
     567                psF32 rf = pDiff * sqrt(r2);
     568                psF32 rs = 0.5 * (fDiff1 + fDiff2);
     569
     570                RF  += rf;
     571                RS  += rs;
     572            }
     573        }
     574
     575        float MrfTry = RF/RS;
     576        if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) {
     577            // We did not get a good measurement
     578            source->moments->Mrf = NAN;
     579            source->moments->KronFlux  = NAN;
     580            source->moments->KronFluxErr  = NAN;
     581            return false;
     582        }
     583
     584        float Mrf = MAX(minKronRadius, MrfTry);
     585        // Saturate the 1st radial moment
     586        if (sqrt(source->peak->detValue) < 10.0) {
     587            Mrf = MIN (radius, Mrf);
     588        }
     589        source->moments->Mrf = Mrf;
    563590    }
    564591
    565592    // Calculate the Kron magnitude (make this block optional?)
    566     float radKron  = 2.5*Mrf;
     593    float radKron  = 2.5 * source->moments->Mrf;
    567594    float radKron2 = radKron*radKron;
    568595
     
    575602    // smoothed image above)
    576603    vPix = source->pixels->data.F32;
    577 
    578604
    579605    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
     
    607633    }
    608634
    609     source->moments->Mrf         = Mrf;
    610635    source->moments->KronFlux    = Sum;
    611636    source->moments->KronFluxErr = sqrt(Var);
     
    621646    if (source->type == PM_SOURCE_TYPE_DEFECT) return false;
    622647    if (source->type == PM_SOURCE_TYPE_SATURATED) return false;
     648    if (source->mode2 & PM_SOURCE_MODE2_MATCHED) return true;
     649
    623650    if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) return false;
    624651    if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) return false;
  • trunk/psphot/src/psphotSourceMatch.c

    r34354 r34542  
    559559}
    560560
    561 bool psphotDropBadMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects) {
     561bool psphotFilterMatchedSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects) {
    562562
    563563    bool status = false;
    564564
    565     psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Drop Bad Matched Sources ---");
     565    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Filter Matched Sources ---");
    566566
    567567    psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     
    615615    psFree(dropped);
    616616
     617    // find the "best" Mrf from the detected sources.
     618    // Currently we use the smallest positive value
     619    for (int i=0; i< objects->n; i++) {
     620        pmPhotObj *obj = objects->data[i];
     621
     622        float minMrf = 1000.;
     623        bool hasMatched = false;
     624        for (int j = 0; j < obj->sources->n; j++) {
     625            pmSource *source = obj->sources->data[j];
     626            if (source->mode2 & PM_SOURCE_MODE2_MATCHED) {
     627                hasMatched = true;
     628                continue;
     629            }
     630            float Mrf = source->moments->Mrf;
     631            if (isfinite(Mrf) && Mrf < minMrf && Mrf > 0) {
     632                minMrf = Mrf;
     633            }
     634        }
     635
     636        if (!hasMatched || minMrf > 120.) {
     637            continue;
     638        }
     639
     640        // set Mrf for matched sources to the value found above
     641        for (int j = 0; j < obj->sources->n; j++) {
     642            pmSource *source = obj->sources->data[j];
     643            if (source->mode2 & PM_SOURCE_MODE2_MATCHED) {
     644                source->moments->Mrf = minMrf;
     645            }
     646        }
     647    }
     648
    617649    return true;
    618650}
  • trunk/psphot/src/psphotStackReadout.c

    r34418 r34542  
    369369    psMemDump("psfstats");
    370370
    371     // drop matched sources without any useful measurements
    372     psphotDropBadMatchedSources (config, view, STACK_SRC, objects);
     371    // drop matched sources without any useful measurements and set kron radii for the ones
     372    // we decide to keep
     373    psphotFilterMatchedSources (config, view, STACK_SRC, objects);
     374
     375    // measure kron fluxes for the matched sources only
     376    psphotKronIterate(config, view, STACK_SRC, 3);
    373377
    374378    // measure elliptical apertures, petrosians (objects sorted by S/N)
Note: See TracChangeset for help on using the changeset viewer.