Changeset 38396
- Timestamp:
- Jun 5, 2015, 2:31:52 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotStackUpdateReadout.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotStackUpdateReadout.c
r38383 r38396 10 10 bool psphotStackUpdateReadout (pmConfig *config, const pmFPAview *view) { 11 11 12 psArray *objects = NULL; // used below after 'pass1finish' label12 psArray *objects = NULL; 13 13 14 14 // measure the total elapsed time in psphotReadout. dtime is the elapsed time used jointly … … 79 79 return psphotReadoutCleanup (config, view, STACK_RAW); 80 80 } 81 82 #ifdef MEASURE_PSF83 if (!psphotChoosePSF (config, view, STACK_RAW, true)) {84 psLogMsg ("psphot", 3, "failure to construct a psf model");85 return psphotReadoutCleanup (config, view, STACK_RAW);86 }87 if (!strcasecmp (breakPt, "PSFMODEL")) {88 return psphotReadoutCleanup (config, view, STACK_RAW);89 }90 #endif91 81 92 82 if (!psphotDeblendSatstars (config, view, STACK_RAW)) { … … 327 317 for (int i = 0; i < sources->n; i++) { 328 318 pmSource *source = sources->data[i]; 329 source->imageID = index; // XXX is this necessary?319 source->imageID = index; // XXX: This is usually set in psphotSourceStatsReadout 330 320 pmModel *modelPSF = source->modelPSF; 331 321 // free any previous radial aperture measurements … … 339 329 if (!(source->mode & PM_SOURCE_MODE_PSFMODEL)) { 340 330 // The cmf loaders unconditionallly create psf models even if the source did not have one. 341 fprintf(stderr, "source %d %5d should not have a psf model 0x%08X%08X\n", index, source->seq, source->mode2, source->mode);331 // fprintf(stderr, "source %d %5d should not have a psf model 0x%08X%08X\n", index, source->seq, source->mode2, source->mode); 342 332 psFree(source->modelPSF) ; 343 333 } … … 361 351 // for anything except psphotStack -updatemode. 362 352 if (modelPSF && isfinite(source->psfFlux)) { 363 // The cmf reader is incorrectly setting the sky parameter for psf models364 modelPSF->params->data.F32[PM_PAR_SKY] = 0.0;353 // The cmf reader was incorrectly setting the sky parameter for psf models 354 modelPSF->params->data.F32[PM_PAR_SKY] = 0.0; 365 355 modelPSF->dparams->data.F32[PM_PAR_SKY] = 0.0; 356 366 357 // Calculate flux for normalized model 367 float saveI0 = modelPSF->params->data.F32[PM_PAR_I0];368 358 modelPSF->params->data.F32[PM_PAR_I0] = 1.0; 369 359 float normFlux = modelPSF->class->modelFlux(modelPSF->params); 370 360 float psfFlux = source->psfFlux; 371 #define APPLY_APCORR 372 #ifdef APPLY_APCORR 361 // back out the ApTrend 373 362 double apTrend = pmTrend2DEval (psf->ApTrend, (float)source->peak->x, (float)source->peak->y); 374 363 double adjustment = pow(10.0, -0.4*apTrend); 375 if (isfinite(adjustment) && adjustment != 0.0) { 376 psfFlux = psfFlux / adjustment; 377 } else { 378 fprintf(stderr, "apTrend adjustment for source %5d invalid: %f\n", source->seq, adjustment); 379 } 380 #endif 364 psAssert ( (isfinite(adjustment) && adjustment != 0.0), "Invalid adjustment value: %f", adjustment); 365 366 psfFlux = psfFlux / adjustment; 381 367 float newI0 = psfFlux / normFlux; 382 if (isfinite (newI0) ) { 383 // psf model looks to be good. 384 modelPSF->params->data.F32[PM_PAR_I0] = newI0; 385 #ifdef USE_SAVED_I0 386 // I am testing with a modified cmf that saves PM_PAR_I0 387 modelPSF->params->data.F32[PM_PAR_I0] = saveI0; 388 #endif 389 // fprintf (stderr, "%5d %12f %12f %12f\n", source->seq, saveI0, newI0, saveI0 - newI0); 390 goodModel = true; 391 } else { 392 psAssert(isfinite (modelPSF->params->data.F32[PM_PAR_I0]), "got infinite I0 for psf model"); 393 } 394 } 395 396 // It is rather expensive initializing all of the extended models. Lets only initialize 397 // the extended model that will be used if any. 368 369 psAssert(isfinite (newI0) , "got infinite I0 for psf model"); 370 371 // new I0 for psf model looks good. 372 modelPSF->params->data.F32[PM_PAR_I0] = newI0; 373 goodModel = true; 374 } 375 376 // It is rather expensive setting the I0 all of the extended models. Lets only initialize 377 // the extended model if it will be used for subtraction. 398 378 399 379 bool isPSF = false; … … 403 383 goodModel = false; 404 384 // calculate flux from the previously measured model magnitude. It will be nan if the 405 // flux was negative unfortunately .385 // flux was negative unfortunately so we lose those. 406 386 if (isfinite(model->mag)) { 407 387 float modelFlux = pow(10., -0.4 * model->mag); 408 388 409 // XXX: We are assuming here that we only use PCM models. Get fromrecipe.389 // XXX: We are assuming here that we only use PCM models. Should get that information from the recipe. 410 390 pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize); 411 391 if (!pcm) { … … 421 401 goodModel = true; 422 402 // Usually this it is set when doing the fit. Since we are instantiating the model we 423 // set it explicitly .403 // set it explicitly here. 424 404 model->isPCM = true; 425 405 } … … 430 410 // The original flux was probably negative. 431 411 // This is somewhat rare. I saw it in about .2% of extended sources in my first test. 432 // Set source type to star to prevent source subtraction from crashing. 433 // this may cause model psf to be used in places. 434 // XXX However we aren't going to cache it below. 412 // Set source type to star to prevent source subtraction from crashing by trying to use 413 // an incomplete extended model. 414 // XXX: this may cause model psf to be used in places. 415 // XXX However we aren't going to cache it below so... 435 416 source->type = PM_SOURCE_TYPE_STAR; 436 417 model = NULL; … … 443 424 // Is this a reasonable guess? 444 425 source->moments->nPixels = source->modelPSF->nPix; 426 source->tmpFlags |= PM_SOURCE_TMPF_CANDIDATE_PSFSTAR; 445 427 } 446 428 … … 449 431 source->moments->SN = 0; 450 432 if (isfinite(kronFlux) && isfinite(source->moments->KronFluxErr) && isfinite(source->psfMag)) { 451 // This is how we set the SN column in the CFF files 433 // This is how we set the SN column in the CFF files... 452 434 source->moments->SN = kronFlux/source->moments->KronFluxErr; 453 435 } else if (isfinite(source->psfFlux) && isfinite(source->psfFluxErr)) { 436 // kron no good try this. It's just used for sorting 454 437 source->moments->SN = source->psfFlux/source->psfFluxErr; 455 438 } 456 439 457 440 if (goodModel && model) { 441 // Yipee! cache the model 458 442 if (model->isPCM) { 459 443 pmPCMCacheModel (source, maskVal, psfSize, fitNsigmaConv); … … 465 449 466 450 psFree(fitOptions); 467 468 #ifdef MEASURE_PSF469 // need to drop the psf model in order for it to be re-measured470 // Hmm, will this invalidate the results from above where we used the loaded one?471 psMetadataRemoveKey(readout->analysis, "PSPHOT.PSF");472 #endif473 451 474 452 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
