Changeset 30033
- Timestamp:
- Dec 14, 2010, 10:36:51 AM (15 years ago)
- Location:
- tags/ipp-20101206
- Files:
-
- 9 edited
-
psLib/src/imageops/psImageMapFit.c (modified) (13 diffs)
-
psLib/src/imageops/psImageMapFit.h (modified) (4 diffs)
-
psModules/src/objects/pmPSFtry.h (modified) (2 diffs)
-
psModules/src/objects/pmPSFtryMakePSF.c (modified) (9 diffs)
-
psModules/src/objects/pmPSFtryModel.c (modified) (2 diffs)
-
psModules/src/objects/pmTrend2D.c (modified) (4 diffs)
-
psModules/src/objects/pmTrend2D.h (modified) (1 diff)
-
psphot/src/psphotApResid.c (modified) (1 diff)
-
psphot/src/psphotMakeFluxScale.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-20101206/psLib/src/imageops/psImageMapFit.c
r25753 r30033 48 48 49 49 // map defines the output image dimensions and scaling. 50 bool psImageMapFit( psImageMap *map, const psVector *mask, psVectorMaskType maskValue,50 bool psImageMapFit(bool *goodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue, 51 51 const psVector *x, const psVector *y, const psVector *f, const psVector *df) 52 52 { 53 53 // XXX Add Asserts 54 55 *goodFit = false; 54 56 55 57 // dimensions of the output map image … … 81 83 map->map->data.F32[0][0] = psStatsGetValue(map->stats, mean); 82 84 map->error->data.F32[0][0] = psStatsGetValue(map->stats, stdev); 85 *goodFit = true; 83 86 return true; 84 87 } … … 86 89 if (Nx == 1) { 87 90 bool status; 88 status = psImageMapFit1DinY ( map, mask, maskValue, x, y, f, df);91 status = psImageMapFit1DinY (goodFit, map, mask, maskValue, x, y, f, df); 89 92 return status; 90 93 } 91 94 if (Ny == 1) { 92 95 bool status; 93 status = psImageMapFit1DinX ( map, mask, maskValue, x, y, f, df);96 status = psImageMapFit1DinX (goodFit, map, mask, maskValue, x, y, f, df); 94 97 return status; 95 98 } … … 310 313 311 314 if (!psMatrixGJSolve(A, B)) { 312 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n");313 315 psFree (A); 314 316 psFree (B); 315 return false;317 return true; 316 318 } 317 319 … … 337 339 psFree (Empty); 338 340 341 *goodFit = true; 339 342 return true; 340 343 } 341 344 342 345 // measure residuals on each pass and clip outliers based on stats 343 bool psImageMapClipFit( psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,346 bool psImageMapClipFit(bool *goodFit, psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue, 344 347 const psVector *x, const psVector *y, const psVector *f, const psVector *df) 345 348 { … … 351 354 psAssert(f, "impossible"); 352 355 356 *goodFit = false; 357 353 358 // the user supplies one of various stats option pairs, 354 359 // determine the desired mean and stdev STATS options: … … 393 398 psTrace("psLib.imageops", 6, "Loop iteration %d. Calling psImageMapFit()\n", N); 394 399 psS32 Nkeep = 0; 395 if (!psImageMapFit( map, mask, maskValue, x, y, f, df)) {400 if (!psImageMapFit(goodFit, map, mask, maskValue, x, y, f, df)) { 396 401 psError(PS_ERR_UNKNOWN, false, "Could not fit image map.\n"); 397 402 psFree(resid); … … 399 404 return false; 400 405 } 406 if (!goodFit) { 407 psWarning ("bad fit to image map, try something else"); 408 return true; 409 } 401 410 402 411 psVector *fit = psImageMapEvalVector(map, mask, maskValue, x, y); … … 454 463 psFree(resid); 455 464 if (!inMask) psFree (mask); 465 *goodFit = true; // XXX probably don't need to set this (set by psImageMapFit) 456 466 return true; 457 467 } 458 468 459 469 // map defines the output image dimensions and scaling. 460 bool psImageMapFit1DinY( psImageMap *map, const psVector *mask, psVectorMaskType maskValue,470 bool psImageMapFit1DinY(bool *goodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue, 461 471 const psVector *x, const psVector *y, const psVector *f, const psVector *df) 462 472 { 463 473 // XXX Add Asserts 464 474 assert (map->binning->nXruff == 1); 475 476 *goodFit = false; 465 477 466 478 // dimensions of the output map image … … 578 590 579 591 if (!psMatrixGJSolve(A, B)) { 580 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.\n");581 592 psFree (A); 582 593 psFree (B); 583 594 psFree (Empty); 584 return false;595 return true; 585 596 } 586 597 … … 602 613 psFree (Empty); 603 614 615 *goodFit = true; 604 616 return true; 605 617 } 606 618 607 619 // map defines the output image dimensions and scaling. 608 bool psImageMapFit1DinX( psImageMap *map, const psVector *mask, psVectorMaskType maskValue,620 bool psImageMapFit1DinX(bool *goodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue, 609 621 const psVector *x, const psVector *y, const psVector *f, const psVector *df) 610 622 { 611 623 // XXX Add Asserts 612 624 assert (map->binning->nYruff == 1); 625 626 *goodFit = false; 613 627 614 628 // dimensions of the output map image … … 726 740 727 741 if (!psMatrixGJSolve(A, B)) { 728 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations..\n");729 742 psFree (A); 730 743 psFree (B); 731 744 psFree (Empty); 732 return false;745 return true; 733 746 } 734 747 … … 750 763 psFree (Empty); 751 764 765 *goodFit = true; 752 766 return true; 753 767 } -
tags/ipp-20101206/psLib/src/imageops/psImageMapFit.h
r25753 r30033 8 8 9 9 // fit the image map to a set of points 10 bool psImageMapFit(psImageMap *map, 10 bool psImageMapFit(bool *goodFit, 11 psImageMap *map, 11 12 const psVector *mask, 12 13 psVectorMaskType maskValue, // … … 18 19 19 20 // fit the image map to a set of points 20 bool psImageMapClipFit(psImageMap *map, 21 bool psImageMapClipFit(bool *goodFit, 22 psImageMap *map, 21 23 psStats *stats, 22 24 psVector *mask, // WARNING: Mask is modified! … … 28 30 ); 29 31 30 bool psImageMapFit1DinY(psImageMap *map, 32 bool psImageMapFit1DinY(bool *goodFit, 33 psImageMap *map, 31 34 const psVector *mask, 32 35 psVectorMaskType maskValue, … … 37 40 ); 38 41 39 bool psImageMapFit1DinX(psImageMap *map, 42 bool psImageMapFit1DinX(bool *goodFit, 43 psImageMap *map, 40 44 const psVector *mask, 41 45 psVectorMaskType maskValue, -
tags/ipp-20101206/psModules/src/objects/pmPSFtry.h
r25754 r30033 100 100 bool pmPSFtryFitEXT (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal); 101 101 102 bool pmPSFtryMakePSF ( pmPSFtry *psfTry);102 bool pmPSFtryMakePSF (bool *goodFit, pmPSFtry *psfTry); 103 103 104 104 bool pmPSFtryFitPSF (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal); … … 123 123 ); 124 124 125 bool pmPSFFitShapeParams ( pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);125 bool pmPSFFitShapeParams (bool *goodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask); 126 126 127 127 float psVectorSystematicError (psVector *residuals, psVector *errors, float clipFraction); -
tags/ipp-20101206/psModules/src/objects/pmPSFtryMakePSF.c
r29004 r30033 50 50 Note: some of the array entries may be NULL (failed fits); ignore them. 51 51 *****************************************************************************/ 52 bool pmPSFtryMakePSF ( pmPSFtry *psfTry)52 bool pmPSFtryMakePSF (bool *goodFit, pmPSFtry *psfTry) 53 53 { 54 54 PS_ASSERT_PTR_NON_NULL(psfTry, false); … … 74 74 75 75 // fit the shape parameters (SXX, SYY, SXY) as a function of position 76 if (!pmPSFFitShapeParams ( psf, psfTry->sources, x, y, srcMask)) {76 if (!pmPSFFitShapeParams (goodFit, psf, psfTry->sources, x, y, srcMask)) { 77 77 psFree(x); 78 78 psFree(y); 79 79 return false; 80 } 81 if (!goodFit) { 82 psWarning ("poor fit to PSF shape parameters for trend order %d, %d, skipping\n", psf->trendNx, psf->trendNy); 83 psFree(x); 84 psFree(y); 85 return true; 80 86 } 81 87 … … 115 121 // the mask is carried from previous steps and updated with this operation 116 122 // the weight is either the flux error or NULL, depending on 'psf->poissonErrorParams' 117 if (!pmTrend2DFit ( trend, srcMask, 0xff, x, y, z, NULL)) {123 if (!pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, z, NULL)) { 118 124 psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i); 119 125 psFree(x); … … 122 128 return false; 123 129 } 130 if (!goodFit) { 131 // if we do not get a good fit (but do not actually hit an error), 132 // tell the calling program to try something else 133 psWarning ("poor fit to PSF parameter %d for trend order %d, %d, skipping\n", i, psf->trendNx, psf->trendNy); 134 psFree(x); 135 psFree(y); 136 psFree(z); 137 return true; 138 } 124 139 if (trend->mode == PM_TREND_MAP) { 125 140 // p_psImagePrint (2, trend->map->map, "param N Before"); // XXX TEST: … … 163 178 164 179 // fit the shape parameters using the supplied order (pmPSF->trendNx,trendNy) 165 bool pmPSFFitShapeParams ( pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {180 bool pmPSFFitShapeParams (bool *goodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) { 166 181 167 182 // we are doing a robust fit. after each pass, we drop points which are more deviant than … … 219 234 trend = psf->params->data[PM_PAR_E0]; 220 235 trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here 221 status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e0, NULL); 236 status &= pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, e0, NULL); 237 if (!goodFit) { 238 psFree (e0); 239 psFree (e1); 240 psFree (e2); 241 return true; 242 } 222 243 mean = psStatsGetValue (trend->stats, meanOption); 223 244 stdev = psStatsGetValue (trend->stats, stdevOption); … … 228 249 trend = psf->params->data[PM_PAR_E1]; 229 250 trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here 230 status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e1, NULL); 251 status &= pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, e1, NULL); 252 if (!goodFit) { 253 psFree (e0); 254 psFree (e1); 255 psFree (e2); 256 return true; 257 } 231 258 mean = psStatsGetValue (trend->stats, meanOption); 232 259 stdev = psStatsGetValue (trend->stats, stdevOption); … … 237 264 trend = psf->params->data[PM_PAR_E2]; 238 265 trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here 239 status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e2, NULL); 266 status &= pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, e2, NULL); 267 if (!goodFit) { 268 psFree (e0); 269 psFree (e1); 270 psFree (e2); 271 return true; 272 } 240 273 mean = psStatsGetValue (trend->stats, meanOption); 241 274 stdev = psStatsGetValue (trend->stats, stdevOption); … … 246 279 if (!status) { 247 280 psError (PS_ERR_UNKNOWN, true, "failed to fit PSF shape params"); 281 psFree (e0); 282 psFree (e1); 283 psFree (e2); 248 284 return false; 249 285 } -
tags/ipp-20101206/psModules/src/objects/pmPSFtryModel.c
r29004 r30033 136 136 137 137 // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation 138 if (!pmPSFtryMakePSF (psfTry)) { 138 bool goodFit = false; 139 if (!pmPSFtryMakePSF (&goodFit, psfTry)) { 139 140 psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources"); 140 141 psFree(psfTry); 141 142 return NULL; 142 143 } 144 if (!goodFit) { 145 psWarning ("poor psf fit for order %d, skipping\n", i); 146 continue; 147 } 143 148 144 149 // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric … … 169 174 } 170 175 psFree (srcMask); 176 177 if (!minPSF) { 178 psError(PS_ERR_UNKNOWN, false, "failed to construct a valid psf model from the sources"); 179 psFree(psfTry); 180 return NULL; 181 } 171 182 172 183 // keep the ones matching the min systematic error: -
tags/ipp-20101206/psModules/src/objects/pmTrend2D.c
r25754 r30033 179 179 } 180 180 181 bool pmTrend2DFit( pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,181 bool pmTrend2DFit(bool *goodFit, pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x, 182 182 const psVector *y, const psVector *f, const psVector *df) 183 183 { … … 188 188 PS_ASSERT_VECTOR_NON_NULL(f, false); 189 189 190 bool status; 190 bool status = false; 191 *goodFit = false; 192 // for the psImageMap fit, it is possible to have valid data but no valid solution for 193 // example, an isolated cell may not be reached from other cells, making the solution 194 // degenerate. psImageMapFit should probably handle this case, but until it does, we allow 195 // it to fail on the result, but not yield an error (goodFit = false). 196 // psVectorClipFitPolynomial2D can not fail in this way (really?), so goodFit is always 197 // true 198 191 199 switch (trend->mode) { 192 200 case PM_TREND_POLY_ORD: … … 196 204 // of points in the image, and potentially based on the fractional range of the 197 205 // data? 206 *goodFit = true; 198 207 break; 199 208 … … 201 210 // XXX supply fraction from trend elements 202 211 // XXX need to add the API which adjusts the scale 203 status = psImageMapClipFit( trend->map, trend->stats, mask, maskVal, x, y, f, df);212 status = psImageMapClipFit(goodFit, trend->map, trend->stats, mask, maskVal, x, y, f, df); 204 213 break; 205 214 -
tags/ipp-20101206/psModules/src/objects/pmTrend2D.h
r29004 r30033 76 76 ); 77 77 78 bool pmTrend2DFit(pmTrend2D *trend, 78 bool pmTrend2DFit(bool *goodFit, 79 pmTrend2D *trend, 79 80 psVector *mask, // Warning: mask is modified! 80 81 psVectorMaskType maskVal, -
tags/ipp-20101206/psphot/src/psphotApResid.c
r29936 r30033 378 378 379 379 // XXX test for errors here 380 if (!pmTrend2DFit (apTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft)) { 380 bool goodFit = false; 381 if (!pmTrend2DFit (&goodFit, apTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft)) { 382 // XXX this is probably a real error, and I should exit 383 psWarning("Failed to fit trend for %d x %d map", Nx, Ny); 384 psFree (apTrend); 385 return NULL; 386 } 387 if (!goodFit) { 381 388 psWarning("Failed to fit trend for %d x %d map", Nx, Ny); 382 389 psFree (apTrend); -
tags/ipp-20101206/psphot/src/psphotMakeFluxScale.c
r25755 r30033 55 55 fPts->n = Npts; 56 56 57 if (!pmTrend2DFit (trend, NULL, 0xff, xPts, yPts, fPts, NULL)) { 57 // XXX we should allow the spatial sampling to decrease if the fit fails 58 bool goodFit = false; 59 if (!pmTrend2DFit (&goodFit, trend, NULL, 0xff, xPts, yPts, fPts, NULL)) { 58 60 psError(PS_ERR_UNKNOWN, false, "Unable to fit trend"); 61 success = false; 62 goto DONE; 63 } 64 if (!goodFit) { 65 psError(PS_ERR_UNKNOWN, false, "poor fit to flux-scale trend"); 59 66 success = false; 60 67 goto DONE;
Note:
See TracChangeset
for help on using the changeset viewer.
