IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 13, 2011, 12:33:05 PM (15 years ago)
Author:
eugene
Message:

adding some of the metadata needed by PSPS to output headers; skip models with few valid pixels (eg, only the edge is showing); only do the linear fit on pixels within the fit radius; modify psf-match auto-scaling process; enable multiple target psfs for matched-psf aperture photometry; speed up analysis of the radial apertures

Location:
trunk/psphot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src/psphotRadialApertures.c

    r29936 r30624  
    102102        if (source->peak->x > AnalysisRegion.x1) continue;
    103103        if (source->peak->y > AnalysisRegion.y1) continue;
     104
     105        // allocate pmSourceExtendedParameters, if not already defined
     106        if (!source->radialAper) {
     107            source->radialAper = psArrayAlloc(1);
     108        }
    104109
    105110        // replace object in image
     
    116121        pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius);
    117122
    118         if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax)) {
     123        if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, 0)) {
    119124            psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    120125        } else {
     
    130135}
    131136
    132 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax) {
    133 
    134     // allocate pmSourceExtendedParameters, if not already defined
    135     if (!source->radial) {
    136         source->radial = pmSourceRadialAperturesAlloc ();
     137bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *aperRadii, int entry) {
     138
     139    // if we are a child source, save the results to the parent source radial aperture array
     140    psArray *radialAperSet = source->radialAper;
     141    if (source->parent) {
     142        radialAperSet = source->parent->radialAper;
     143    }
     144    psAssert(radialAperSet, "this should be defined before calling");
     145    psAssert(radialAperSet->data[entry] == NULL, "why is this already defined?");
     146
     147    pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc ();
     148    radialAperSet->data[entry] = radialAper;
     149
     150    // storage for the derived pixel values
     151    psVector *pixRadius2 = psVectorAllocEmpty(100, PS_TYPE_F32);
     152    psVector *pixFlux    = psVectorAllocEmpty(100, PS_TYPE_F32);
     153    psVector *pixVar     = psVectorAllocEmpty(100, PS_TYPE_F32);
     154
     155    // outer-most radius for initial truncation
     156    float Rmax  = aperRadii->data.F32[aperRadii->n - 1];
     157    float Rmax2 = PS_SQR(Rmax);
     158
     159    // store the R^2 values for the apertures
     160    psVector *aperRadii2 = psVectorAlloc(aperRadii->n, PS_TYPE_F32);
     161    for (int i = 0; i < aperRadii->n; i++) {
     162        aperRadii2->data.F32[i] = PS_SQR(aperRadii->data.F32[i]);
     163    }
     164
     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
     168
     169    // one pass through the pixels to select the valid pixels and calculate R^2
     170    for (int iy = 0; iy < source->pixels->numRows; iy++) {
     171
     172        float yDiff = iy - yCM;
     173        if (fabs(yDiff) > Rmax) continue;
     174
     175        float *vPix = source->pixels->data.F32[iy];
     176        float *vWgt = source->variance->data.F32[iy];
     177        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy];
     178
     179        for (int ix = 0; ix < source->pixels->numCols; ix++, vPix++, vWgt++) {
     180
     181            if (vMsk) {
     182                if (*vMsk & maskVal) {
     183                    vMsk++;
     184                    continue;
     185                }
     186                vMsk++;
     187            }
     188            if (isnan(*vPix)) continue;
     189
     190            float xDiff = ix - xCM;
     191            if (fabs(xDiff) > Rmax) continue;
     192
     193            // radius is just a function of (xDiff, yDiff)
     194            float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     195            if (r2 > Rmax2) continue;
     196
     197            psVectorAppend(pixRadius2, r2);
     198            psVectorAppend(pixFlux, *vPix);
     199            psVectorAppend(pixVar, *vWgt);
     200        }
     201    }
     202
     203    psVector *flux    = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
     204    psVector *fluxErr = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
     205    psVector *fill    = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin
     206
     207    psVectorInit (flux,    0.0);
     208    psVectorInit (fluxErr, 0.0);
     209    psVectorInit (fill,    0.0);
     210
     211    float *rPix2 = pixRadius2->data.F32;
     212    for (int i = 0; i < pixRadius2->n; i++, rPix2++) {
     213
     214        float *aRad2 = aperRadii2->data.F32;
     215        for (int j = 0; (*rPix2 < *aRad2) && (j < aperRadii2->n); j++, aRad2++) {
     216            flux->data.F32[j]    += pixFlux->data.F32[i];
     217            fluxErr->data.F32[j] += pixVar->data.F32[i];
     218            fill->data.F32[j]    += 1.0;
     219        }
     220    }
     221
     222    for (int i = 0; i < flux->n; i++) {
     223        // calculate the total flux for bin 'nOut'
     224        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);
    137229    }
    138230   
    139     psVector *radius  = psVectorAllocEmpty(100, PS_TYPE_F32);
     231    radialAper->flux = flux;
     232    radialAper->fluxErr = fluxErr;
     233    radialAper->fill = fill;
     234
     235    psFree (aperRadii2);
     236    psFree (pixRadius2);
     237    psFree (pixFlux);
     238    psFree (pixVar);
     239
     240    return true;
     241}
     242
     243static int nCalls = 0;
     244static int nPass = 0;
     245static int nPix = 0;
     246
     247bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax, int entry) {
     248
     249    psAssert(source->radialAper->data[entry] == NULL, "why is this already defined?");
     250
     251    pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc ();
     252    source->radialAper->data[entry] = radialAper;
     253
     254    psVector *pixRadius  = psVectorAllocEmpty(100, PS_TYPE_F32);
    140255    psVector *pixFlux = psVectorAllocEmpty(100, PS_TYPE_F32);
    141256    psVector *pixVar  = psVectorAllocEmpty(100, PS_TYPE_F32);
     
    144259        for (int ix = 0; ix < source->pixels->numCols; ix++) {
    145260
    146             // 0.5 PIX: get radius as a function of pixel coord
     261            // 0.5 PIX: get pixRadius as a function of pixel coord
    147262            float x = ix + 0.5 - source->peak->xf + source->pixels->col0;
    148263            float y = iy + 0.5 - source->peak->yf + source->pixels->row0;
     
    150265            float r = hypot(x, y);
    151266
    152             psVectorAppend(radius, r);
     267            psVectorAppend(pixRadius, r);
    153268            psVectorAppend(pixFlux, source->pixels->data.F32[iy][ix]);
    154269            psVectorAppend(pixVar, source->variance->data.F32[iy][ix]);
    155         }
    156     }
    157     psphotRadialAperturesSortFlux(radius, pixFlux, pixVar);
     270            nPix ++;
     271            // if (nPix % 10000 == 0) {fprintf (stderr, "?");}
     272        }
     273    }
     274    psphotRadialAperturesSortFlux(pixRadius, pixFlux, pixVar);
    158275
    159276    psVector *flux    = psVectorAllocEmpty(radMax->n, PS_TYPE_F32); // surface brightness of radial bin
     
    174291
    175292    // XXX assume (or enforce) that the bins are contiguous and non-overlapping (Rmax[i] = Rmin[i+1])
    176     for (int i = 0; !done && (i < radius->n); i++) {
    177         if (radius->data.F32[i] > Rmax) {
     293    for (int i = 0; !done && (i < pixRadius->n); i++) {
     294        if (pixRadius->data.F32[i] > Rmax) {
    178295            // calculate the total flux for bin 'nOut'
    179296            float Area = M_PI*PS_SQR(Rmax);
     
    185302                     nOut, radMax->data.F32[nOut], flux->data.F32[nOut], fluxErr->data.F32[nOut], fill->data.F32[nOut], Area);
    186303
     304            nPass ++;
     305            // if (nPass % 1000 == 0) {fprintf (stderr, "!");}
     306
    187307            nOut ++;
    188308            if (nOut >= radMax->n) break;
     
    195315    flux->n = fluxErr->n = fill->n = nOut;
    196316   
    197     psFree(source->radial->flux);
    198     psFree(source->radial->fluxErr);
    199     psFree(source->radial->fill);
    200 
    201     source->radial->flux = flux;
    202     source->radial->fluxErr = fluxErr;
    203     source->radial->fill = fill;
    204 
    205     psFree (radius);
     317    radialAper->flux = flux;
     318    radialAper->fluxErr = fluxErr;
     319    radialAper->fill = fill;
     320
     321    psFree (pixRadius);
    206322    psFree (pixFlux);
    207323    psFree (pixVar);
    208324
     325    nCalls ++;
     326    // if (nCalls % 100 == 0) {fprintf (stderr, "*");}
    209327    return true;
    210328}
Note: See TracChangeset for help on using the changeset viewer.