Changeset 34317 for trunk/psphot/src/psphotKronIterate.c
- Timestamp:
- Aug 16, 2012, 2:38:37 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotKronIterate.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotKronIterate.c
r34311 r34317 5 5 6 6 7 bool psphotKronIterate (pmConfig *config, const pmFPAview *view, const char *filerule )7 bool psphotKronIterate (pmConfig *config, const pmFPAview *view, const char *filerule, int pass) 8 8 { 9 9 bool status = true; … … 42 42 // psAssert (psf, "missing psf?"); 43 43 44 if (!psphotKronIterateReadout (config, recipe, view, filerule, readout, sources, psf, i )) {44 if (!psphotKronIterateReadout (config, recipe, view, filerule, readout, sources, psf, i, pass)) { 45 45 psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i); 46 46 return false; … … 54 54 bool psphotVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max); 55 55 56 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index) { 56 #ifdef DUMP_KRS 57 FILE *dumpFile = NULL; 58 #endif 59 60 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index, int pass) { 57 61 58 62 bool status = false; 63 64 #ifdef DUMP_KRS 65 if (!dumpFile) { 66 dumpFile = fopen("kr.txt", "w"); 67 psAssert (dumpFile, "failed to open kr.txt"); 68 } 69 fprintf(dumpFile, "\n\n Input %d\n", index); 70 #endif 59 71 60 72 if (!sources->n) { … … 64 76 65 77 psTimerStart ("psphot.kron"); 66 67 78 68 79 // determine the number of allowed threads … … 236 247 PS_ARRAY_ADD_SCALAR(job->args, KRON_SMOOTH_SIGMA, PS_TYPE_F32); 237 248 PS_ARRAY_ADD_SCALAR(job->args, KRON_SB_MIN_DIVISOR,PS_TYPE_F32); 249 PS_ARRAY_ADD_SCALAR(job->args, pass, PS_TYPE_S32); 238 250 239 251 // set this to 0 to run without threading … … 298 310 float KRON_SMOOTH_SIGMA = PS_SCALAR_VALUE(job->args->data[11],F32); 299 311 float KRON_SB_MIN_DIVISOR = PS_SCALAR_VALUE(job->args->data[12],F32); 312 int pass = PS_SCALAR_VALUE(job->args->data[13],S32); 313 #ifndef REVERT_ON_BAD_MEASUREMENT 314 (void) pass; 315 #endif 300 316 301 317 for (int j = 0; j < KRON_ITERATIONS; j++) { … … 309 325 if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue; 310 326 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 327 if (!isfinite(source->moments->Mrf)) { 328 // Once we save a bad Mrf measurement we give up on this source 329 // checking here allows us to avoid adding and subtracting the model 330 continue; 331 } 311 332 312 333 // replace object in image … … 322 343 } 323 344 324 // On first iteration set window radius to sky radius (if valid) on second iteration 325 // use a factor times the previous radial moment value up to a maximum value that 326 // depends on the surface brightness of the source 327 float maxWindow; 328 if (j == 0) { 329 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 330 } else { 345 // On first iteration set window radius to sky radius (if valid). We also use this on subsequent 346 // iterations if we cannot find a better limit 347 float maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 348 if (j > 0) { 349 // on subsequent iterations we use a factor times the previous radial moment value 350 // limited to a maximum value that depends on the surface brightness of the source 331 351 if (KRON_SB_MIN_DIVISOR) { 332 352 // Limit window radius based on surface brightness if we have a good measurement of kron flux 333 if (isfinite(source->moments->Mrf) && source->moments->Mrf > 0 && 334 isfinite(source->moments->KronFlux) && (source->moments->KronFlux > 0)) { 353 if (isfinite(source->moments->KronFlux) && (source->moments->KronFlux > 0)) { 335 354 float Rmax = sqrt(source->moments->KronFlux) / KRON_SB_MIN_DIVISOR; 336 355 337 maxWindow = PS_MIN(6.0*source->moments->Mrf, Rmax); 338 } else { 339 maxWindow = RADIUS; 356 if (isfinite(source->moments->Mrf) && source->moments->Mrf > 0) { 357 maxWindow = PS_MIN(6.0*source->moments->Mrf, Rmax); 358 } else { 359 maxWindow = PS_MIN(Rmax, maxWindow); 360 } 340 361 } 341 362 } else { … … 345 366 } 346 367 float windowRadius = PS_MAX(RADIUS, maxWindow); 368 369 #ifdef REVERT_ON_BAD_MEASURMENT 370 // save previous measurements. We might revert back to them if this round fails 371 float MrfPrior = source->moments->Mrf; 372 float KronFluxPrior = source->moments->KronFlux; 373 float KronFluxErrPrior = source->moments->KronFluxErr; 374 #endif 347 375 348 376 // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS … … 371 399 } 372 400 401 #ifdef REVERT_ON_BAD_MEASUREMENT 402 // on pass 2 if we get an invalid measurement on a pass 1 source where we had a good one previously 403 // in pass 1 keep that measurement 404 bool reverted = false; 405 if (pass > 1 && !isfinite(source->moments->Mrf) && (source->mode2 & PM_SOURCE_MODE2_PASS1_SRC)) { 406 source->moments->Mrf = MrfPrior; // This is finite otherwise we wouldn't have gotten here 407 source->moments->KronFlux = KronFluxPrior; 408 source->moments->KronFluxErr = KronFluxErrPrior; 409 reverted = true; 410 } 411 #endif 412 #ifdef DUMP_KRS 413 #ifndef REVERT_ON_BAD_MEASUREMENT 414 bool reverted = false; 415 #endif 416 fprintf(dumpFile, "%7d %1d %6.1f %6.1f %6.1f %6.1f %6.1f %6.1f %2d\n", source->id, reverted, source->moments->Mrf, MrfPrior, maxWindow, windowRadius, source->peak->xf, source->peak->yf, source->imageID); 417 #endif 418 373 419 // if we subtracted it above, re-subtract the object, leave local sky 374 420 if (reSubtract) { … … 490 536 491 537 float MrfTry = RF/RS; 492 if (!isfinite(MrfTry)) { 493 // We did not get a successul measurement of the kron radius. 494 // Leave the current values unchanged. 538 if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) { 539 // We did not get a good measurement 540 source->moments->Mrf = NAN; 541 source->moments->KronFlux = NAN; 542 source->moments->KronFluxErr = NAN; 495 543 return false; 496 544 } … … 546 594 } 547 595 548 source->moments->Mrf = Mrf;596 source->moments->Mrf = Mrf; 549 597 source->moments->KronFlux = Sum; 550 598 source->moments->KronFluxErr = sqrt(Var); … … 564 612 psAssert(kronWindow, "need a window"); 565 613 566 // If we are not applying the window then we don't need to check for valid Mrf here.614 // XXX: If we are not applying the window then we don't need to check for valid Mrf here. 567 615 // We should give the this module a chance to measure a good value. 568 // Not yet though. We need to test the effect of this616 // However experiments show that it hardly ever succeeds in getting a better value 569 617 if (!isfinite(source->moments->Mrf) || source->moments->Mrf < 0 ) return false; 570 618
Note:
See TracChangeset
for help on using the changeset viewer.
