IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 26, 2009, 8:40:07 PM (17 years ago)
Author:
eugene
Message:

incorporating changes from 16bit mask upgrades (eam_branch_20081230)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotMakeResiduals.c

    r20453 r21183  
    11# include "psphotInternal.h"
    22
    3 bool psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal) {
     3bool psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psImageMaskType maskVal) {
    44
    55    bool status, isPSF;
    66    double flux, dflux;
    7     psU8 mflux;
     7    psImageMaskType mflux;
    88
    99    psTimerStart ("psphot.residuals");
     
    6969    // - set output pixel, weight, and mask
    7070
    71     // XXX need to set these correctly!!
    72     const int badMask = 1;              // mask bits
    73     const int poorMask = 2;             //       from psImageInterpolate
    74     const int clippedMask = 4;          // mask bit set for clipped values
     71    // these mask values do not correspond to the recipe values: they
     72    // are not propagated to images: they just need to fit in an 8-bit
     73    // value.  they are supplied to psImageInterpolate, which takes a
     74    // psImageMaskType; the mask portion of the result from
     75    // psImageInterpolate is supplied to fmasks, which is then used by
     76    // psVectorStats
     77
     78    const psImageMaskType badMask     = 0x01;   // mask bits
     79    const psImageMaskType poorMask    = 0x02;   // from psImageInterpolate
     80    const psImageMaskType clippedMask = 0x04;   // mask bit set for clipped values
     81    const psVectorMaskType fmaskVal = badMask | poorMask | clippedMask;
    7582
    7683    // determine the maximum image size from the input sources
     
    95102        psImage *image  = psImageCopy (NULL, source->pixels,   PS_TYPE_F32);
    96103        psImage *weight = psImageCopy (NULL, source->weight,   PS_TYPE_F32);
    97         psImage *mask   = psImageCopy (NULL, source->maskView, PS_TYPE_U8);
     104        psImage *mask   = psImageCopy (NULL, source->maskView, PS_TYPE_IMAGE_MASK);
    98105        pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal);
    99106
     
    103110        psBinaryOp (weight, weight, "/", psScalarAlloc(Io*Io, PS_TYPE_F32));
    104111
    105         // we will interpolate the image and weight - include the mask or not?
    106         // XXX consider better values for the mask bits
    107         psImageInterpolation *interp =
    108             psImageInterpolationAlloc(mode, image, weight, NULL, 0xff, 0.0, 0.0, badMask, poorMask, 0.0, 0);
    109         psArrayAdd (input,  100, interp);
     112        // we interpolate the image and weight - include the mask or not?
     113        // XXX why not the mask?
     114        // psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, weight, mask, maskVal, 0.0, 0.0, badMask, poorMask, 0.0, 0);
     115        psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, weight, NULL, 0xff, 0.0, 0.0, badMask, poorMask, 0.0, 0);
     116        psArrayAdd (input, 100, interp);
    110117
    111118        // save the X,Y position for future reference
     
    131138    psVector *fluxes  = psVectorAlloc (input->n, PS_TYPE_F32);
    132139    psVector *dfluxes = psVectorAlloc (input->n, PS_TYPE_F32);
    133     psVector *fmasks  = psVectorAlloc (input->n, PS_TYPE_U8);
     140    psVector *fmasks  = psVectorAlloc (input->n, PS_TYPE_VECTOR_MASK);
    134141
    135142    // statistic to use to determine baseline for clipping
     
    164171                bool offImage = false;
    165172                if (psImageInterpolate (&flux, &dflux, &mflux, ix, iy, interp) == PS_INTERPOLATE_STATUS_OFF) {
     173                    // fprintf (stderr, "off image: %f %f : %f %f\n", ix, iy, flux, dflux);
    166174                    // This pixel is off the image
    167175                    offImage = true;
    168                     fmasks->data.U8[i] = 1;
    169                     // fprintf (stderr, "off image: %f %f : %f %f\n", ix, iy, flux, dflux);
    170                 }
    171                 fluxes->data.F32[i] = flux;
    172                 dfluxes->data.F32[i] = dflux;
    173                 fmasks->data.U8[i] = mflux;
     176                    fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = badMask;
     177                } else {
     178                  fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = mflux; // XXX is mflux IMAGE or VECTOR type?
     179                }
     180                fluxes->data.F32[i] = flux;
     181                dfluxes->data.F32[i] = dflux;
    174182                if (isnan(flux)) {
    175                     fmasks->data.U8[i] = 1;
    176                 }
    177                 if (fmasks->data.U8[i] == 0) {
     183                    fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = badMask;
     184                }
     185                if (fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
    178186                    nGoodPixel ++;
    179187                }
    180188            }
    181189
    182             // skip pixels which are off the image...
     190            // skip pixels with insufficient data
    183191            bool validPixel = (SPATIAL_ORDER == 0) ? (nGoodPixel > 1) : (nGoodPixel > 3);
    184192            if (!validPixel) {
     
    186194                resid->Rx->data.F32[oy][ox] = 0.0;
    187195                resid->Ry->data.F32[oy][ox] = 0.0;
    188                 resid->mask->data.U8[oy][ox] = 1;
     196                resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = badMask;
    189197                continue;
    190198            }
     
    192200            // measure the robust median to determine a baseline reference value
    193201            *fluxClip = *fluxClipDef;
    194             psVectorStats (fluxClip, fluxes, NULL, fmasks, 0xff);
     202            psVectorStats (fluxClip, fluxes, NULL, fmasks, fmaskVal);
    195203            psErrorClear();             // clear (ignore) any outstanding errors
    196204
     
    202210                float swing = fabs(delta) / sigma;
    203211
    204                 // make this a user option
     212                // mask pixels which are out of range
    205213                if (swing > nSigma) {
    206                     fmasks->data.U8[i] = clippedMask;
    207                 }
    208                 if (!fmasks->data.U8[i]) nKeep++;
     214                    fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = clippedMask;
     215                }
     216                if (!fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) nKeep++;
    209217            }
    210218
     
    212220                // measure the desired statistic on the unclipped pixels
    213221                *fluxStats = *fluxStatsDef;
    214                 psVectorStats (fluxStats, fluxes, NULL, fmasks, 0xff);
     222                psVectorStats (fluxStats, fluxes, NULL, fmasks, fmaskVal);
    215223                psErrorClear();         // clear (ignore) any outstanding errors
    216224
     
    220228
    221229                if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*fluxStats->sampleStdev/sqrt(nKeep)) {
    222                   resid->mask->data.U8[oy][ox] = 1;
    223                 }
    224 
    225                 // fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], fluxStats->sampleStdev, fluxStats->sampleStdev/sqrt(nKeep), nKeep, resid->mask->data.U8[oy][ox]);
     230                  resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1;
     231                }
     232
     233                // fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], fluxStats->sampleStdev, fluxStats->sampleStdev/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]);
    226234
    227235            } else {
     
    230238                psVectorInit(B, 0.0);
    231239                for (int i = 0; i < fluxes->n; i++) {
    232                     if (fmasks->data.U8[i]) continue;
     240                    if (fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
    233241                    B->data.F64[0] += fluxes->data.F32[i]/dfluxes->data.F32[i];
    234242                    B->data.F64[1] += fluxes->data.F32[i]*xC->data.F32[i]/dfluxes->data.F32[i];
     
    260268
    261269                float dRo = sqrt(A->data.F32[0][0]);
    262                 // fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], dRo, dRo/sqrt(nKeep), nKeep, resid->mask->data.U8[oy][ox]);
     270                // fprintf (stderr, "res: %2d %2d : %6.4f  %6.4f  %6.4f   %3d  %1d\n",
     271                // ox, oy, resid->Ro->data.F32[oy][ox], dRo, dRo/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]);
    263272
    264273                if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*dRo/sqrt(nKeep)) {
    265                   resid->mask->data.U8[oy][ox] = 1;
     274                  resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1;
    266275                }
    267276                //resid->weight->data.F32[oy][ox] = XXX;
Note: See TracChangeset for help on using the changeset viewer.