IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32612


Ignore:
Timestamp:
Nov 3, 2011, 7:41:16 PM (15 years ago)
Author:
eugene
Message:

fix up profile wings to use flux and slope as criteria for finish; save on source

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110906/psphot/src/psphotRadialProfileWings.c

    r32606 r32612  
    44// reach sky + X sigma
    55
    6 bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, float minRadius, float maxRadius, psImageMaskType maskVal);
     6bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, psImageMaskType maskVal);
    77bool psphotRadialProfileFluxAtRadius (psVector *flux, psVector *fluxVar, pmSource *source, pmReadout *readout, float Radius, float dRadius, psImageMaskType maskVal);
    88
     
    5151}
    5252
     53// these are set before we fork off to threads and used by all threads as constant values
     54static float MAX_RADIUS = NAN;
     55static float MIN_RADIUS = NAN;
     56static float SKY_STDEV  = NAN;
     57// static FILE *file = NULL;
     58
    5359bool psphotRadialProfileWingsReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources) {
    5460
     
    6975
    7076    // XXX is this a good recipe value to use for MAX RADIUS??
    71     float MAX_RADIUS = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_RADIUS");
     77    MAX_RADIUS = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_RADIUS");
    7278    if (!status) {
    7379        MAX_RADIUS = 50.0;
    7480    }
    7581
    76     float MIN_RADIUS = 0.25*psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS");
     82    MIN_RADIUS = 0.25*psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS");
    7783    if (!status) {
    7884        MIN_RADIUS = 0.25*psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
     85    }
     86
     87    // SKY_STDEV is the sigma of the sky model (ie, smoothed on large scales)
     88    SKY_STDEV = psMetadataLookupF32 (&status, readout->analysis, "MSKY_SIG");
     89    if (!status) {
     90        SKY_STDEV = 1.0; // a crude default value (why would this not exist?)
    7991    }
    8092
     
    97109    }
    98110
     111    // file = fopen ("radii.dat", "w");
     112
    99113    // threaded measurement of the source magnitudes
    100114    // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
     
    116130            psArrayAdd(job->args, 1, cells->data[j]); // sources
    117131            PS_ARRAY_ADD_SCALAR(job->args, maskVal,       PS_TYPE_IMAGE_MASK);
    118             PS_ARRAY_ADD_SCALAR(job->args, MIN_RADIUS,    PS_TYPE_F32);
    119             PS_ARRAY_ADD_SCALAR(job->args, MAX_RADIUS,    PS_TYPE_F32);
    120132
    121133// set this to 0 to run without threading
     
    151163    psFree (cellGroups);
    152164
     165    // fclose (file);
     166
    153167    psLogMsg ("psphot.wings", PS_LOG_WARN, "measure radial profile wings : %f sec for %ld objects\n", psTimerMark ("psphot.wings"), sources->n);
    154168    return true;
     
    160174    psArray *sources                = job->args->data[1];
    161175    psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA);
    162     float MIN_RADIUS                = PS_SCALAR_VALUE(job->args->data[3],F32);
    163     float MAX_RADIUS                = PS_SCALAR_VALUE(job->args->data[4],F32);
    164176
    165177    for (int i = 0; i < sources->n; i++) {
     
    184196
    185197        // this function populates moments->Mrf,KronFlux,KronFluxErr
    186         psphotRadialProfileWingsSource (source, readout, MIN_RADIUS, MAX_RADIUS, maskVal);
     198        psphotRadialProfileWingsSource (source, readout, maskVal);
    187199
    188200        // if we subtracted it above, re-subtract the object, leave local sky
     
    194206}
    195207
     208# define TEST_X 3158
     209# define TEST_Y 3096
     210
    196211// XXX use integer radius values?  the rings assume integer values, right? or do they?
    197 bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, float minRadius, float maxRadius, psImageMaskType maskVal) {
     212bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, psImageMaskType maskVal) {
    198213
    199214    PS_ASSERT_PTR_NON_NULL(source, false);
    200215    PS_ASSERT_PTR_NON_NULL(source->peak, false);
    201216    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
    202     PS_ASSERT_FLOAT_LARGER_THAN(minRadius, 0.0, false);
    203     PS_ASSERT_FLOAT_LARGER_THAN(maxRadius, 0.0, false);
    204217
    205218    // psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
    206219
    207     // radii will be minRadius to maxRadius in NN log steps:
     220    // radii will be MIN_RADIUS to MAX_RADIUS in NN log steps:
    208221    float NSTEP = 10.0;
    209222    float MIN_DR = 2;
    210223    float NSIGMA = 1.0;
    211     float SKY = 0.0;
    212     float alpha = pow ((maxRadius / minRadius), 1.0/NSTEP) - 1.0;
    213     float dRmax = maxRadius * alpha / (1.0 + alpha); // approximate size of last annulus, to get a rough size for vector allocation
     224    float THRESHOLD = 2.0*SKY_STDEV;
     225    float alpha = pow ((MAX_RADIUS / MIN_RADIUS), 1.0/NSTEP) - 1.0;
     226    float dRmax = MAX_RADIUS * alpha / (1.0 + alpha); // approximate size of last annulus, to get a rough size for vector allocation
    214227
    215228    int iter = 0;
    216229
    217     psVector *flux = psVectorAllocEmpty(7*maxRadius*dRmax, PS_TYPE_F32);
    218     psVector *fluxVar = psVectorAllocEmpty(7*maxRadius*dRmax, PS_TYPE_F32);
     230    psVector *flux = psVectorAllocEmpty(7*MAX_RADIUS*dRmax, PS_TYPE_F32);
     231    psVector *fluxVar = psVectorAllocEmpty(7*MAX_RADIUS*dRmax, PS_TYPE_F32);
    219232
    220233    // should I just use sample median here?
     
    222235    psStats *varStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    223236
    224     for (float radius = minRadius; radius < maxRadius; iter ++) {
     237    float lastFlux = NAN;
     238    float lastRadius = NAN;
     239    float lastSlope = NAN;
     240    bool limit = false;
     241    float limitRadius = NAN;
     242    float limitFlux = NAN;
     243    float limitSlope = NAN;
     244
     245    // note: radius is the inner radius of the annulus; outer radius = inner radius + dR
     246    for (float radius = MIN_RADIUS; !limit && (radius < MAX_RADIUS); iter ++) {
    225247
    226248        float dR = (int)(radius * alpha);
    227249        if (dR < MIN_DR) dR = MIN_DR;
     250        float outerRadius = radius + dR;
     251        float meanRadius = (2.0/3.0) * (outerRadius*outerRadius*outerRadius - radius*radius*radius) / (PS_SQR(outerRadius) - PS_SQR(radius));
    228252
    229253        // extract a vector of the pixel values (signal, variance) at this radius + dR
     
    243267        // \mean(variance) * Npts and cancelling the Npts term inside and out of the sqrt()
    244268       
    245         fprintf (stderr, "%f %f : %f : %f %f\n", source->peak->xf, source->peak->yf, radius, meanFlux, meanFluxError);
    246 
    247         if (meanFlux - NSIGMA * meanFluxError < SKY) {
    248             fprintf (stderr, "hit the sky at %f\n", radius);
    249         }
    250        
     269        float slope = NAN;
     270        if (isfinite(lastFlux)) {
     271            slope = (meanFlux - lastFlux) / (meanRadius - lastRadius);
     272        }
     273
     274        // fprintf (stderr, "%f %f : %f : %f %f  :  %f\n", source->peak->xf, source->peak->yf, radius, meanFlux, meanFluxError, slope);
     275
     276        if (!limit) {
     277            limit |= (meanFlux - NSIGMA * meanFluxError < THRESHOLD); // dropped to sky level
     278            limit |= isfinite(slope) && (fabs(slope) < 3.0); // SB no longer changing.
     279            limitRadius = meanRadius;
     280            limitFlux = meanFlux;
     281            limitSlope = slope;
     282        }
     283
    251284        // completion criteria:
    252285        // 1) flux - NSIGMA * dflux <= sky
     
    254287        // 3) flux flat?
    255288
     289        lastFlux = meanFlux;
     290        lastRadius = meanRadius;
     291        lastSlope = slope;
     292
    256293        // reset the flux & fluxVar vector length to zero for re-use above:
    257294        flux->n = 0;
     
    260297    }
    261298
     299    if (!limit) {
     300        limitRadius = lastRadius;
     301        limitFlux = lastFlux;
     302        limitSlope = lastSlope;
     303    }
     304    // fprintf (file, "%f %f : %f %f : %f\n", source->peak->xf, source->peak->yf, limitRadius, limitFlux, limitSlope);
     305
    262306    psFree (flux);
    263307    psFree (fluxVar);
    264308    psFree (fluxStats);
    265309    psFree (varStats);
     310
     311    source->skyRadius = limitRadius;
     312    source->skyFlux   = limitFlux;
     313    source->skySlope  = limitSlope;
    266314
    267315    // save the max radius (and anything else?)
Note: See TracChangeset for help on using the changeset viewer.