IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2011, 1:12:39 PM (15 years ago)
Author:
eugene
Message:

use the smoothed image for footprint culling; use a more stringent culling for saturated stars; more tweaks to get sat stars to be fitted; various updates to psphotStack; unify psphotImageLoop varients; be a bit careful about number of stars in a PSF clump

Location:
trunk/psphot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src/psphotRadialApertures.c

    r30624 r31154  
    3737    int Nradial = 0;
    3838
     39    // perform full non-linear fits / extended source analysis?
     40    if (!psMetadataLookupBool (&status, recipe, "RADIAL_APERTURES")) {
     41        psLogMsg ("psphot", PS_LOG_INFO, "skipping radial apertures\n");
     42        return true;
     43    }
     44
    3945    psTimerStart ("psphot.radial");
    4046
     
    6268    psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe");
    6369    psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define");
     70    float outerRadius = radMax->data.F32[radMax->n - 1];
    6471
    6572    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     
    6774    assert (maskVal);
    6875
    69     // XXX temporary user-supplied systematic sky noise measurement (derive from background model)
    70     float skynoise = psMetadataLookupF32 (&status, recipe, "SKY.NOISE");
    71 
    7276    // S/N limit to perform full non-linear fits
    7377    float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM");
     
    7579    // source analysis is done in S/N order (brightest first)
    7680    // XXX are we getting the objects out of order? does it matter?
    77     sources = psArraySort (sources, pmSourceSortBySN);
     81    sources = psArraySort (sources, pmSourceSortByFlux);
    7882
    7983    // option to limit analysis to a specific region
     
    9599        // limit selection to some SN limit
    96100        assert (source->peak); // how can a source not have a peak?
    97         if (source->peak->SN < SN_LIM) continue;
     101        if (sqrt(source->peak->detValue) < SN_LIM) continue;
    98102
    99103        // limit selection by analysis region
     
    112116            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    113117        }
     118
     119        // we need to change the view for the radial aperture analysis, but we want to recover exactly
     120        // the original view; the following elements get destroyed by pmSourceRedefinePixels so save them:
     121        psImage *oldMaskObj   = psMemIncrRefCounter(source->maskObj);
     122        psImage *oldModelFlux = psMemIncrRefCounter(source->modelFlux);
     123        psImage *oldPSFimage  = psMemIncrRefCounter(source->psfImage);
     124        psRegion oldRegion    = source->region;
     125
    114126        Nradial ++;
    115127
    116128        // force source image to be a bit larger...
    117         float radius = source->peak->xf - source->pixels->col0;
    118         radius = PS_MAX (radius, source->peak->yf - source->pixels->row0);
    119         radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0);
    120         radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0);
    121         pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius);
    122 
    123         if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, 0)) {
     129        pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, outerRadius + 2);
     130
     131        if (!psphotRadialApertureSource (source, recipe, maskVal, radMax, 0)) {
    124132            psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    125133        } else {
     
    127135        }
    128136
     137        pmSourceRedefinePixelsByRegion (source, readout, oldRegion);
     138        psFree(source->maskObj);   source->maskObj   = oldMaskObj;
     139        psFree(source->modelFlux); source->modelFlux = oldModelFlux;
     140        psFree(source->psfImage);  source->psfImage  = oldPSFimage;
     141       
    129142        // re-subtract the object, leave local sky
    130143        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     
    135148}
    136149
    137 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *aperRadii, int entry) {
     150bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *aperRadii, int entry) {
    138151
    139152    // if we are a child source, save the results to the parent source radial aperture array
     
    163176    }
    164177
    165     // center of the apertures
    166     float xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage
    167     float yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage
     178    float xCM = NAN, yCM = NAN;
     179    if (pmSourcePositionUseMoments(source)) {
     180        xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage
     181        yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage
     182    } else {
     183        xCM = source->peak->xf - 0.5 - source->pixels->col0; // coord of peak in subimage
     184        yCM = source->peak->yf - 0.5 - source->pixels->row0; // coord of peak in subimage
     185    }
    168186
    169187    // one pass through the pixels to select the valid pixels and calculate R^2
     
    203221    psVector *flux    = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
    204222    psVector *fluxErr = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
     223    psVector *fluxStd = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
    205224    psVector *fill    = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
    206225
    207226    psVectorInit (flux,    0.0);
     227    psVectorInit (fluxStd, 0.0);
    208228    psVectorInit (fluxErr, 0.0);
    209229    psVectorInit (fill,    0.0);
     
    212232    for (int i = 0; i < pixRadius2->n; i++, rPix2++) {
    213233
     234        int j = 0;
    214235        float *aRad2 = aperRadii2->data.F32;
    215         for (int j = 0; (*rPix2 < *aRad2) && (j < aperRadii2->n); j++, aRad2++) {
     236        for (; (*aRad2 < *rPix2) && (j < aperRadii2->n); j++, aRad2++);
     237        for (; j < aperRadii2->n; j++, aRad2++) {
    216238            flux->data.F32[j]    += pixFlux->data.F32[i];
     239            fluxStd->data.F32[j] += PS_SQR(pixFlux->data.F32[i]);
    217240            fluxErr->data.F32[j] += pixVar->data.F32[i];
    218241            fill->data.F32[j]    += 1.0;
    219242        }
    220243    }
     244
     245    /* for each radial bin, R(i), we measure:
     246       1) the flux within that aperture: F(i) = \sum_{r_j<R_i}(F_j)
     247       2) the fractional fill factor (count of valid pixels / effective area of the aperture
     248       3) the error on the flux within that aperture
     249     */
    221250
    222251    for (int i = 0; i < flux->n; i++) {
    223252        // calculate the total flux for bin 'nOut'
    224253        float Area = M_PI*aperRadii2->data.F32[i];
    225         fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]);
    226         fill->data.F32[i] /= Area;
    227         psTrace ("psphot", 5, "radial bins: %3d  %5.1f : %8.1f +/- %7.2f : %4.2f %6.1f\n",
    228                  i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], fill->data.F32[i], Area);
     254
     255        int nPix = fill->data.F32[i];
     256        float SBmean = flux->data.F32[i] / nPix;
     257        float SBstdv = sqrt((fluxStd->data.F32[i] / nPix) - PS_SQR(SBmean));
     258
     259        // flux->data.F32[i]    = SBmean * Area;
     260        fluxStd->data.F32[i] = SBstdv * Area;
     261        fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix;
     262
     263        // fill->data.F32[i] /= Area;
     264        psTrace ("psphot", 5, "radial bins: %3d  %5.1f : %8.1f +/- %7.2f : %8.1f +/- %8.1f : %4.2f %6.1f\n",
     265                 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], SBmean, SBstdv, fill->data.F32[i], Area);
    229266    }
    230267   
    231268    radialAper->flux = flux;
     269    radialAper->fluxStdev = fluxStd;
    232270    radialAper->fluxErr = fluxErr;
    233271    radialAper->fill = fill;
     
    245283static int nPix = 0;
    246284
    247 bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax, int entry) {
     285bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *radMax, int entry) {
    248286
    249287    psAssert(source->radialAper->data[entry] == NULL, "why is this already defined?");
Note: See TracChangeset for help on using the changeset viewer.