Changeset 21183 for trunk/psphot/src/psphotMakeResiduals.c
- Timestamp:
- Jan 26, 2009, 8:40:07 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotMakeResiduals.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotMakeResiduals.c
r20453 r21183 1 1 # include "psphotInternal.h" 2 2 3 bool psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, ps MaskType maskVal) {3 bool psphotMakeResiduals (psArray *sources, psMetadata *recipe, pmPSF *psf, psImageMaskType maskVal) { 4 4 5 5 bool status, isPSF; 6 6 double flux, dflux; 7 ps U8mflux;7 psImageMaskType mflux; 8 8 9 9 psTimerStart ("psphot.residuals"); … … 69 69 // - set output pixel, weight, and mask 70 70 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; 75 82 76 83 // determine the maximum image size from the input sources … … 95 102 psImage *image = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 96 103 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); 98 105 pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal); 99 106 … … 103 110 psBinaryOp (weight, weight, "/", psScalarAlloc(Io*Io, PS_TYPE_F32)); 104 111 105 // we willinterpolate 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); 110 117 111 118 // save the X,Y position for future reference … … 131 138 psVector *fluxes = psVectorAlloc (input->n, PS_TYPE_F32); 132 139 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); 134 141 135 142 // statistic to use to determine baseline for clipping … … 164 171 bool offImage = false; 165 172 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); 166 174 // This pixel is off the image 167 175 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; 174 182 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) { 178 186 nGoodPixel ++; 179 187 } 180 188 } 181 189 182 // skip pixels w hich are off the image...190 // skip pixels with insufficient data 183 191 bool validPixel = (SPATIAL_ORDER == 0) ? (nGoodPixel > 1) : (nGoodPixel > 3); 184 192 if (!validPixel) { … … 186 194 resid->Rx->data.F32[oy][ox] = 0.0; 187 195 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; 189 197 continue; 190 198 } … … 192 200 // measure the robust median to determine a baseline reference value 193 201 *fluxClip = *fluxClipDef; 194 psVectorStats (fluxClip, fluxes, NULL, fmasks, 0xff);202 psVectorStats (fluxClip, fluxes, NULL, fmasks, fmaskVal); 195 203 psErrorClear(); // clear (ignore) any outstanding errors 196 204 … … 202 210 float swing = fabs(delta) / sigma; 203 211 204 // make this a user option 212 // mask pixels which are out of range 205 213 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++; 209 217 } 210 218 … … 212 220 // measure the desired statistic on the unclipped pixels 213 221 *fluxStats = *fluxStatsDef; 214 psVectorStats (fluxStats, fluxes, NULL, fmasks, 0xff);222 psVectorStats (fluxStats, fluxes, NULL, fmasks, fmaskVal); 215 223 psErrorClear(); // clear (ignore) any outstanding errors 216 224 … … 220 228 221 229 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]); 226 234 227 235 } else { … … 230 238 psVectorInit(B, 0.0); 231 239 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; 233 241 B->data.F64[0] += fluxes->data.F32[i]/dfluxes->data.F32[i]; 234 242 B->data.F64[1] += fluxes->data.F32[i]*xC->data.F32[i]/dfluxes->data.F32[i]; … … 260 268 261 269 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]); 263 272 264 273 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; 266 275 } 267 276 //resid->weight->data.F32[oy][ox] = XXX;
Note:
See TracChangeset
for help on using the changeset viewer.
