IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 5, 2011, 11:02:53 AM (15 years ago)
Author:
eugene
Message:

merge updates from eam branch 20110404

File:
1 edited

Legend:

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

    r29546 r31451  
    5050
    5151#include "pmSourcePhotometry.h"
    52 
    53 pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType markVal, float xc, float yc);
     52#include "pmGrowthCurveGenerate.h"
    5453
    5554/*****************************************************************************/
     
    197196        // mask the given aperture and measure the apMag
    198197        psImageKeepCircle (mask, xc, yc, radius, "OR", markVal);
    199         if (!pmSourcePhotometryAper (&apMag, NULL, NULL, model, pixels, NULL, mask, maskVal)) {
     198        if (!pmSourcePhotometryAper (NULL, &apMag, NULL, NULL, model, pixels, NULL, mask, maskVal)) {
    200199            psFree (growth);
    201200            psFree (view);
     
    226225    return growth;
    227226}
     227
     228# define DEBUG 0
     229# if (DEBUG)
     230static FILE *fgr = NULL;
     231# endif
     232
     233// we generate the growth curve for the center of the image with the specified psf model
     234bool pmGrowthCurveGenerateFromSources (pmReadout *readout, pmPSF *psf, psArray *sources, bool INTERPOLATE_AP, psImageMaskType maskVal, psImageMaskType markVal)
     235{
     236    PS_ASSERT_PTR_NON_NULL(readout, false);
     237    PS_ASSERT_PTR_NON_NULL(readout->image, false);
     238
     239    // maskVal is used to test for rejected pixels, and must include markVal
     240    maskVal |= markVal;
     241
     242    pmSourcePhotometryMode photMode = INTERPOLATE_AP ? PM_SOURCE_PHOT_INTERP : 0;
     243   
     244    // measure the growth curve for each PSF source and average them together
     245    psArray *growths = psArrayAllocEmpty (100);
     246
     247# if (DEBUG)
     248    fgr = fopen ("growth.mags.dat", "w");
     249# endif
     250
     251    for (int i = 0; i < sources->n; i++) {
     252
     253        pmSource *source = sources->data[i];
     254
     255        if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
     256
     257        pmGrowthCurve *growth = pmGrowthCurveForSource (source, psf, photMode, maskVal, markVal);
     258        if (!growth) continue;
     259       
     260        psArrayAdd (growths, 100, growth);
     261        psFree (growth);
     262    }
     263    psAssert (growths->n, "cannot build growth curve (no valid PSF stars?)");
     264
     265# if (DEBUG)
     266    fclose (fgr);
     267# endif
     268
     269    // just use a simple sample median to get the 'best' value from each growth curve...
     270    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     271
     272    psVector *values = psVectorAlloc (growths->n, PS_DATA_F32);
     273
     274    // loop over a range of source fluxes
     275    // no need to interpolate since we have forced the object center
     276    // to 0.5, 0.5 above
     277    for (int i = 0; i < psf->growth->radius->n; i++) {
     278
     279        // median the values for each radial bin
     280        values->n = 0;
     281        for (int j = 0; j < growths->n; j++) {
     282            pmGrowthCurve *growth = growths->data[j];
     283            if (!isfinite(growth->apMag->data.F32[i])) continue;
     284            psVectorAppend (values, growth->apMag->data.F32[i] - growth->refMag);
     285        }
     286        if (values->n == 0) {
     287            psf->growth->apMag->data.F32[i] = NAN;
     288        } else {
     289            if (!psVectorStats (stats, values, NULL, NULL, 0)) {
     290                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     291                return false;
     292            }
     293            psf->growth->apMag->data.F32[i] = stats->sampleMedian;
     294        }
     295    }
     296
     297    psf->growth->fitMag = psf->growth->apMag->data.F32[psf->growth->radius->n-1];
     298    psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
     299    psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
     300
     301    psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f (fitMag - apMag @ ref : %f - %f)\n", psf->growth->apLoss, psf->growth->fitMag, psf->growth->apRef);
     302
     303    psFree (growths);
     304    psFree (stats);
     305    psFree (values);
     306
     307    return true;
     308}
     309
     310pmGrowthCurve *pmGrowthCurveForSource (pmSource *source, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal, psImageMaskType markVal) {
     311
     312    float radius;
     313
     314    assert (psf->growth);
     315
     316    float minRadius = psf->growth->radius->data.F32[0];
     317    pmGrowthCurve *growth = pmGrowthCurveAlloc (minRadius, psf->growth->maxRadius, psf->growth->refRadius);
     318
     319    // measure the fitMag for this source (for normalization)
     320    // pmSourcePhotometryModel (&fitMag, NULL, source->psfModel);
     321    growth->fitMag = source->psfMag;
     322
     323    float xc = source->peak->xf;
     324    float yc = source->peak->yf;
     325
     326    // Loop over the range of radii
     327    for (int i = 0; i < growth->radius->n; i++) {
     328
     329        radius = growth->radius->data.F32[i];
     330
     331        // mask the given aperture and measure the apMag
     332        psImageKeepCircle (source->maskObj, xc, yc, radius, "OR", markVal);
     333
     334        if (!pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, radius)) {
     335            psFree (growth);
     336            return NULL;
     337        }
     338
     339        // if (!pmSourcePhotometryAper (NULL, &apMag, NULL, NULL, NULL, source->pixels, NULL, source->maskObj, maskVal)) {
     340        //     psFree (growth);
     341        //     return NULL;
     342        // }
     343
     344        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); // clear the circular mask
     345
     346        growth->apMag->data.F32[i] = source->apMag;
     347    }
     348    psAssert(growth->refBin >= 0, "invalid growth reference bin");
     349    psAssert(growth->refBin < growth->apMag->n, "invalid growth reference bin");
     350    growth->refMag = growth->apMag->data.F32[growth->refBin];
     351
     352    // Loop over the range of radii
     353# if (DEBUG)
     354    for (int i = 0; i < growth->radius->n; i++) {
     355        fprintf (fgr, "%f %f  %f %f %f %f\n", xc, yc, growth->radius->data.F32[i], growth->apMag->data.F32[i], growth->fitMag, growth->refMag);
     356    }
     357# endif
     358
     359    return growth;
     360}
Note: See TracChangeset for help on using the changeset viewer.