- Timestamp:
- Sep 5, 2012, 4:04:34 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20120805/psphot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120805/psphot
- Property svn:mergeinfo changed
/trunk/psphot (added) merged: 34293,34307,34311,34317,34319,34321,34336,34338,34352-34354,34363
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20120805/psphot/src
- Property svn:mergeinfo changed
/trunk/psphot/src (added) merged: 34293,34307,34311,34317,34319,34321,34336,34338,34352-34354,34363
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20120805/psphot/src/psphotKronIterate.c
r34378 r34399 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 … … 160 171 161 172 // generate the window image: multiply the flux by this to downweight neighbors 173 // XXX: we don't need this image if we aren't going to apply the window 162 174 psImage *kronWindow = psImageAlloc (readout->image->numCols, readout->image->numRows, PS_TYPE_F32); 163 175 psImageInit (kronWindow, 1.0); … … 235 247 PS_ARRAY_ADD_SCALAR(job->args, KRON_SMOOTH_SIGMA, PS_TYPE_F32); 236 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); 237 250 238 251 // set this to 0 to run without threading … … 297 310 float KRON_SMOOTH_SIGMA = PS_SCALAR_VALUE(job->args->data[11],F32); 298 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 299 316 300 317 for (int j = 0; j < KRON_ITERATIONS; j++) { … … 308 325 if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue; 309 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 } 310 332 311 333 // skip saturated stars modeled with a radial profile … … 324 346 } 325 347 326 // On first iteration set window radius to sky radius (if valid) on second iteration 327 // use a factor times the previous radial moment value up to a maximum value that 328 // depends on the surface brightness of the source 329 float maxWindow; 330 if (j == 0) { 331 maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 332 } else { 348 // On first iteration set window radius to sky radius (if valid). We also use this on subsequent 349 // iterations if we cannot find a better limit 350 float maxWindow = isfinite(source->skyRadius) ? source->skyRadius : RADIUS; 351 if (j > 0) { 352 // on subsequent iterations we use a factor times the previous radial moment value 353 // limited to a maximum value that depends on the surface brightness of the source 333 354 if (KRON_SB_MIN_DIVISOR) { 334 if (isfinite(source->moments->KronFlux) && (source->moments->KronFlux > 0)) {335 // Limit window radius based on surface brightness355 // Limit window radius based on surface brightness if we have a good measurement of kron flux 356 if (isfinite(source->moments->KronFlux) && (source->moments->KronFlux > 0)) { 336 357 float Rmax = sqrt(source->moments->KronFlux) / KRON_SB_MIN_DIVISOR; 337 358 338 if ( source->moments->Mrf > 0) {359 if (isfinite(source->moments->Mrf) && source->moments->Mrf > 0) { 339 360 maxWindow = PS_MIN(6.0*source->moments->Mrf, Rmax); 340 361 } else { 341 maxWindow = Rmax;362 maxWindow = PS_MIN(Rmax, maxWindow); 342 363 } 343 } else {344 maxWindow = RADIUS;345 364 } 346 365 } else { 347 // old code366 // old recipe, no surface brightness cut 348 367 maxWindow = isfinite(source->moments->Mrf) ? 6.0*source->moments->Mrf : RADIUS; 349 368 } 350 369 } 351 370 float windowRadius = PS_MAX(RADIUS, maxWindow); 371 372 #ifdef REVERT_ON_BAD_MEASURMENT 373 // save previous measurements. We might revert back to them if this round fails 374 float MrfPrior = source->moments->Mrf; 375 float KronFluxPrior = source->moments->KronFlux; 376 float KronFluxErrPrior = source->moments->KronFluxErr; 377 #endif 352 378 353 379 // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS … … 376 402 } 377 403 404 #ifdef REVERT_ON_BAD_MEASUREMENT 405 // on pass 2 if we get an invalid measurement on a pass 1 source where we had a good one previously 406 // in pass 1 keep that measurement 407 bool reverted = false; 408 if (pass > 1 && !isfinite(source->moments->Mrf) && (source->mode2 & PM_SOURCE_MODE2_PASS1_SRC)) { 409 source->moments->Mrf = MrfPrior; // This is finite otherwise we wouldn't have gotten here 410 source->moments->KronFlux = KronFluxPrior; 411 source->moments->KronFluxErr = KronFluxErrPrior; 412 reverted = true; 413 } 414 #endif 415 #ifdef DUMP_KRS 416 #ifndef REVERT_ON_BAD_MEASUREMENT 417 bool reverted = false; 418 #endif 419 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); 420 #endif 421 378 422 // if we subtracted it above, re-subtract the object, leave local sky 379 423 if (reSubtract) { … … 494 538 } 495 539 540 float MrfTry = RF/RS; 541 if (RF <= 0. || RS <= 0 || !isfinite(MrfTry)) { 542 // We did not get a good measurement 543 source->moments->Mrf = NAN; 544 source->moments->KronFlux = NAN; 545 source->moments->KronFluxErr = NAN; 546 return false; 547 } 548 549 float Mrf = MAX(minKronRadius, MrfTry); 496 550 // Saturate the 1st radial moment 497 float Mrf = MAX(minKronRadius, RF/RS);498 551 if (sqrt(source->peak->detValue) < 10.0) { 499 552 Mrf = MIN (radius, Mrf); … … 544 597 } 545 598 546 source->moments->Mrf = Mrf;599 source->moments->Mrf = Mrf; 547 600 source->moments->KronFlux = Sum; 548 601 source->moments->KronFluxErr = sqrt(Var); … … 562 615 psAssert(kronWindow, "need a window"); 563 616 617 // XXX: If we are not applying the window then we don't need to check for valid Mrf here. 618 // We should give the this module a chance to measure a good value. 619 // However experiments show that it hardly ever succeeds in getting a better value 564 620 if (!isfinite(source->moments->Mrf) || source->moments->Mrf < 0 ) return false; 565 621
Note:
See TracChangeset
for help on using the changeset viewer.
