Changeset 34404 for trunk/psphot/src/psphotBlendFit.c
- Timestamp:
- Sep 5, 2012, 4:19:30 PM (14 years ago)
- Location:
- trunk/psphot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20120805/psphot (added) merged: 34360,34368-34369,34377-34378,34380,34392,34399
- Property svn:mergeinfo changed
-
trunk/psphot/src
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20120805/psphot/src (added) merged: 34360,34368-34369,34377-34378,34380,34392,34399
- Property svn:mergeinfo changed
-
trunk/psphot/src/psphotBlendFit.c
r34258 r34404 1 1 # include "psphotInternal.h" 2 bool psphotBlendFitSetSource(pmSource *source, psImage *IDimage, float sigSigma); 2 3 3 4 // for now, let's store the detections on the readout->analysis for each readout … … 92 93 float skySig = psMetadataLookupF32(&status, recipe, "SKY_SIG"); 93 94 assert (status && isfinite(skySig) && skySig > 0); 95 96 # if (0) 97 // **** test block : generate an ID image where pixels are set based the source models (flux > 0.1 peak && flux > 2.0 skySig) 98 psImage *IDimage = psImageAlloc (readout->image->numCols, readout->image->numRows, PS_TYPE_S32); 99 psImageInit (IDimage, 0); 100 101 // start with the currently known moments (Mxx, Myy, Mxy) and generate a window image 102 for (int i = 0; i < sources->n; i++) { 103 pmSource *source = sources->data[i]; 104 psphotBlendFitSetSource (source, IDimage, skySig); 105 } 106 psphotSaveImage (NULL, IDimage, "idimage.fits"); 107 # endif 94 108 95 109 // Define source fitting parameters for extended source fits … … 241 255 pmSource *source = sources->data[i]; 242 256 243 # if (0) 244 # define TEST_X 34245 # define TEST_ Y 28246 257 int TEST_ON = false; 258 # if (1) 259 # define TEST_X 653 260 # define TEST_Y 466 247 261 if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) { 248 262 fprintf (stderr, "test object\n"); 249 } 250 263 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 264 TEST_ON = true; 265 } 251 266 # undef TEST_X 252 267 # undef TEST_Y … … 258 273 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 259 274 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 275 276 // skip saturated stars modeled with a radial profile 277 if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue; 260 278 261 279 // skip DBL second sources (ie, added by psphotFitBlob … … 306 324 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 307 325 if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) { 326 if (TEST_ON) { 327 psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 328 } 308 329 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 309 330 Next ++; … … 312 333 } else { 313 334 if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) { 335 if (TEST_ON) { 336 psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 337 } 314 338 source->type = PM_SOURCE_TYPE_STAR; 315 339 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); … … 349 373 } 350 374 375 bool psphotBlendFitSetSource(pmSource *source, psImage *IDimage, float skySigma) { 376 377 if (!source) return false; 378 if (!source->peak) return false; // XXX how can we have a peak-less source? 379 if (!source->moments) return false; 380 if (source->type == PM_SOURCE_TYPE_DEFECT) return false; 381 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 382 if (source->mode2 == PM_SOURCE_MODE2_MATCHED) return false; 383 psAssert(IDimage, "need a window"); 384 385 if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) { 386 // find the radius at which we hit something like 0.1*SATURATION 387 return false; 388 } 389 390 if (!isfinite(source->moments->Mrf) || source->moments->Mrf < 0 ) return false; 391 392 // we have a source with moments Mx, My, Mxx, Mxy, Myy. we just need to define a Gaussian that has 393 // these values (and peak of 1.0) 394 395 int Nx = IDimage->numCols; 396 int Ny = IDimage->numRows; 397 398 float Xo = source->moments->Mx; 399 float Yo = source->moments->My; 400 401 psEllipseMoments moments; 402 moments.x2 = source->moments->Mxx; 403 moments.y2 = source->moments->Myy; 404 moments.xy = source->moments->Mxy; 405 406 psEllipseAxes axes = psEllipseMomentsToAxes(moments, 20.0); 407 if (! (isfinite(axes.major) && isfinite(axes.minor) && isfinite(axes.theta)) ) { 408 fprintf (stderr, "invalid axes found id: %4d major: %f minor: %f theta: %f\n", source->id, axes.major, axes.minor, axes.theta); 409 return false; 410 } 411 412 // Use 1st radial moment as size, not sigma. Why this factor of 0.5 ? 413 float scale = 0.5 * source->moments->Mrf / axes.major; 414 axes.major *= scale; 415 axes.minor *= scale; 416 417 psEllipseShape shape = psEllipseAxesToShape(axes); 418 if (! (isfinite(shape.sx) && isfinite(shape.sy) && isfinite(shape.sxy)) ) { 419 fprintf (stderr, "invalid shape found id: %d sx: %f sy %f sxy: %f\n", source->id, shape.sx, shape.sy, shape.sxy); 420 return false; 421 } 422 423 float Smajor = axes.major; 424 425 // we want to go to 2.15 sigma (0.1 Io) 426 int minX = PS_MIN(PS_MAX(Xo - 2.15*Smajor, 0), Nx - 1); 427 int maxX = PS_MIN(PS_MAX(Xo + 2.15*Smajor, 0), Nx - 1); 428 int minY = PS_MIN(PS_MAX(Yo - 2.15*Smajor, 0), Ny - 1); 429 int maxY = PS_MIN(PS_MAX(Yo + 2.15*Smajor, 0), Ny - 1); 430 431 float rMxx = 0.5 / PS_SQR(shape.sx); 432 float rMyy = 0.5 / PS_SQR(shape.sy); 433 float Sxy = -1. * shape.sxy; // factor of -1 is included to match the previous window function 434 // implementation. XXX: Is this correct? 435 436 int ID = source->id; 437 float Io = source->peak->rawFlux; 438 for (int iy = minY; iy < maxY; iy++) { 439 for (int ix = minX; ix < maxX; ix++) { 440 441 float dX = (ix + 0.5 - Xo); 442 float dY = (iy + 0.5 - Yo); 443 444 float z = rMxx * PS_SQR(dX) + rMyy * PS_SQR(dY) + Sxy*dX*dY; 445 446 float f = Io*exp(-z); 447 448 if (f < 2.0*skySigma) continue; 449 IDimage->data.S32[iy][ix] = ID; 450 } 451 } 452 453 return true; 454 }
Note:
See TracChangeset
for help on using the changeset viewer.
