- Timestamp:
- Aug 3, 2011, 10:30:02 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110710/psphot/src/psphotExtendedSourceFits.c
r31867 r31990 45 45 int Nfail = 0; 46 46 47 psphotSersicModelClassInit(); 48 47 49 psTimerStart ("psphot.extended"); 48 50 … … 103 105 104 106 if (item->type != PS_DATA_METADATA) { 107 // XXX we could cull the bad entries or build a validated model folder 105 108 psAbort ("Invalid type for EXTENDED_SOURCE_MODEL entry %s, not a metadata folder", item->name); 106 // XXX we could cull the bad entries or build a validated model folder107 109 } 108 110 … … 247 249 psFree(AnalysisRegion); 248 250 251 psphotSersicModelClassCleanup(); 252 249 253 psLogMsg ("psphot", PS_LOG_INFO, "extended source model fits: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next); 250 254 psLogMsg ("psphot", PS_LOG_INFO, " %d convolved models (%d passed)\n", Nconvolve, NconvolvePass); … … 265 269 int Nplain = 0; 266 270 int NplainPass = 0; 267 bool savePics = false; 268 float radius; 271 float fitRadius, windowRadius; 269 272 psScalar *scalar = NULL; 270 273 pmMoments psfMoments; … … 279 282 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); 280 283 281 // pthread_t tid = pthread_self(); // Thread identifier282 283 284 // Define source fitting parameters for extended source fits 284 285 pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc(); … … 309 310 if (source->peak->y > region->y1) continue; 310 311 311 // if model is NULL, we don't have a starting guess312 // XXX use the parameters guessed from moments313 // if (source->modelEXT == NULL) continue;314 315 // fprintf (stderr, "fit %d,%d in thread %d\n", source->peak->x, source->peak->y, (int) tid);316 317 312 // replace object in image 318 313 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { … … 321 316 Next ++; 322 317 323 // set the radius based on the f ootprint (also sets the mask pixels)324 if (!psphotSetRadius Footprint(&radius, readout, source, markVal, 1.0)) {318 // set the radius based on the first radial moment (also sets the mask pixels) 319 if (!psphotSetRadiusMoments(&fitRadius, &windowRadius, readout, source, markVal)) { 325 320 fprintf (stderr, "skipping (1) %f, %f\n", source->peak->xf, source->peak->yf); 326 321 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 327 // XXX raise an error of some kind 322 // XXX raise an error of some kind or set a flag bit 328 323 continue; 329 324 } 330 325 331 // XXX note that this changes the source moments that are published... 332 // recalculate the source moments using the larger extended-source moments radius 333 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 334 // this uses the footprint to judge both radius and aperture? 335 // XXX save the psf-based moments for output 326 // Recalculate the source moments using the larger extended-source moments radius. At 327 // this stage, skip Gaussian windowing, and do not clip pixels by S/N. Save the 328 // psf-based moments for output 336 329 psfMoments = *source->moments; 337 if (!pmSourceMoments (source, radius, 0.0, 0.0, 0.0, maskVal)) {330 if (!pmSourceMoments (source, windowRadius, 0.0, 0.0, 0.0, maskVal & PS_NOT_IMAGE_MASK(markVal))) { 338 331 // subtract the best fit from the object, leave local sky 339 332 fprintf (stderr, "skipping (2) %f, %f\n", source->peak->xf, source->peak->yf); … … 344 337 } 345 338 346 // save the modelFlux here in case we need to subtract it (for failure) 339 // save the PSF-based modelFlux here in case we need to subtract it (for failure). If 340 // it does not exist, attempt to generate it. Give up if we cannot even do that. 347 341 psImage *modelFluxStart = psMemIncrRefCounter (source->modelFlux); 348 342 if (!modelFluxStart) { … … 358 352 } 359 353 360 if (savePics) {361 psphotSaveImage (NULL, readout->image, "image.xp.fits");362 }363 364 354 // array to store the pointers to the model flux images while the models are being fitted 365 355 psArray *modelFluxes = psArrayAllocEmpty (models->list->n); … … 368 358 if (source->modelFits == NULL) { 369 359 source->modelFits = psArrayAllocEmpty (models->list->n); 360 } 361 // extFitPars are the non-parametric data measured for this model fit (moments, kron, etc) 362 if (source->extFitPars == NULL) { 363 source->extFitPars = psArrayAllocEmpty (models->list->n); 370 364 } 371 365 … … 397 391 bool convolved = psMetadataLookupBool (&status, model, "PSF_CONVOLVED_VALUE"); 398 392 assert (status); 399 400 // XXX psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6);401 // XXX psTraceSetLevel ("psphot.psphotModelWithPSF_LMM", 6);402 403 // XXX this does not make sense in a threaded context404 psTimerStart ("psphot.extended.fit");405 393 406 394 // fit the model as convolved or not … … 439 427 } 440 428 441 psLogMsg ("psphot", PS_LOG_INFO, "model fit: %7.5f sec, %5d npix, %2d iter, %s type\n", psTimerMark ("psphot.extended.fit"), modelFit->nPix, modelFit->nIter, pmModelClassGetName (modelFit->type)); 442 443 // save each of the model flux images and store the best 429 // save each of the model flux images for now, and (below) store the best 444 430 psArrayAdd (modelFluxes, 4, source->modelFlux); 445 431 432 pmSourceExtFitPars *extFitPars = pmSourceExtFitParsAlloc(); 433 extFitPars->Mxx = source->moments->Mxx; 434 extFitPars->Mxy = source->moments->Mxy; 435 extFitPars->Myy = source->moments->Myy; 436 extFitPars->Mrf = source->moments->Mrf; 437 extFitPars->Mrh = source->moments->Mrh; 438 extFitPars->peakMag = (source->peak->rawFlux > 0) ? -2.5*log10(source->peak->rawFlux) : NAN; 439 440 // save kron mag, but assign apMag & psfMag on output (not yet calculated) 441 extFitPars->krMag = -2.5*log10(source->moments->KronFlux); 442 443 psArrayAdd (source->extFitPars, 4, extFitPars); 444 psFree (extFitPars); 445 446 446 // test for fit quality / result 447 modelFit->fitRadius = radius;447 modelFit->fitRadius = fitRadius; 448 448 psArrayAdd (source->modelFits, 4, modelFit); 449 449 … … 470 470 } 471 471 472 // clear the circular mask 473 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 474 472 475 if (minModel == -1) { 473 // re-subtract the object, leave local sky476 // no valid extended fit; re-subtract the object, leave local sky 474 477 psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->Mx, source->moments->My); 475 478 … … 483 486 psFree (modelFluxes); 484 487 485 if (savePics) {486 psphotSaveImage (NULL, readout->image, "image.xp.fits");487 char key[10];488 fprintf (stdout, "continue? ");489 if (!fgets (key, 8, stdin)) {490 psWarning("Couldn't read anything.");491 } else if (key[0] == 'n') {492 savePics = false;493 }494 }495 488 continue; 496 489 } … … 516 509 psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->Mx, source->moments->My, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq); 517 510 psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 518 519 if (savePics) {520 psphotSaveImage (NULL, readout->image, "image.xm.fits");521 char key[10];522 fprintf (stdout, "continue? ");523 if (!fgets (key, 8, stdin)) {524 psWarning("Couldn't read anything.");525 } else if (key[0] == 'n') {526 savePics = false;527 }528 }529 511 } 530 512 psFree (fitOptions); 531 532 // fprintf (stderr, "xfit : tried %ld objects\n", sources->n);533 513 534 514 // change the value of a scalar on the array (wrap this and put it in psArray.h)
Note:
See TracChangeset
for help on using the changeset viewer.
