Changeset 36375 for trunk/psphot/src/psphotExtendedSourceFits.c
- Timestamp:
- Dec 10, 2013, 2:55:11 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (2 props)
-
psphot/src/psphotExtendedSourceFits.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
trunk/psphot
- Property svn:mergeinfo changed
-
trunk/psphot/src
- Property svn:ignore
-
old new 24 24 psphotModelTest 25 25 psphotMinimal 26 psphotFullForce 27 psmakecff
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
trunk/psphot/src/psphotExtendedSourceFits.c
r36108 r36375 65 65 psphotVisualShowImage(readout); 66 66 67 // psphotSaveImage (NULL, readout->image, "test.01.fits");68 69 67 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 70 68 psAssert (detections, "missing detections?"); … … 111 109 if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) { 112 110 fitMaxTol = 1.0; 111 } 112 113 float fitNsigmaConv = psMetadataLookupF32 (&status, recipe, "EXT_FIT_NSIGMA_CONV"); // number of sigma for the convolution 114 if (!status || !isfinite(fitNsigmaConv) || fitNsigmaConv <= 0) { 115 fitNsigmaConv = 5.0; 113 116 } 114 117 … … 137 140 fitOptions->minTol = fitMinTol; 138 141 fitOptions->maxTol = fitMaxTol; 142 fitOptions->nsigma = fitNsigmaConv; 139 143 140 144 fitOptions->gainFactorMode = gainFactorMode; 141 145 fitOptions->chisqConvergence = chisqConvergence; 142 146 fitOptions->isInteractive = isInteractive; 147 148 // use poissonian errors or local-sky errors 149 fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON"); 150 if (!status) fitOptions->poissonErrors = true; 143 151 144 152 // maskVal is used to test for rejected pixels, and must include markVal … … 285 293 psArrayAdd(job->args, 1, cells->data[j]); // sources 286 294 psArrayAdd(job->args, 1, models); 295 287 296 // Allocate a metadata iterator here because psMetadataIteratorAlloc/Free are not thread safe 288 297 psMetadataIterator *iter = psMetadataIteratorAlloc (models, PS_LIST_HEAD, NULL); … … 386 395 psphotSersicModelClassCleanup(); 387 396 388 // psphotSaveImage (NULL, readout->image, "test.02.fits");389 390 397 psphotVisualShowResidualImage (readout, false); 391 398 … … 428 435 // psTraceSetLevel ("psLib.math.psMinimizeLMChi2_Alt", 5); 429 436 437 pmModelStatus badModel = PM_MODEL_STATUS_NONE; 438 badModel |= PM_MODEL_STATUS_BADARGS; 439 badModel |= PM_MODEL_STATUS_OFFIMAGE; 440 badModel |= PM_MODEL_STATUS_NAN_CHISQ; 441 badModel |= PM_MODEL_SERSIC_PCM_FAIL_GUESS; 442 badModel |= PM_MODEL_SERSIC_PCM_FAIL_GRID; 443 badModel |= PM_MODEL_PCM_FAIL_GUESS; 444 430 445 // choose the sources of interest 431 446 for (int i = 0; i < sources->n; i++) { … … 433 448 pmSource *source = sources->data[i]; 434 449 435 // skip PSF-like and non-astronomical objects 436 if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue; 437 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 438 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 439 440 // skip saturated stars modeled with a radial profile 441 if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue; 442 443 // XXX this should use peak? 450 // rules for measuring petrosian parameters for specific objects are set in 451 // psphotChooseAnalysisOptions.c 452 if (!(source->tmpFlags & PM_SOURCE_TMPF_EXT_FIT)) continue; 453 454 // limit selection by analysis region (XXX move this into psphotChooseAnalysisOption?) 444 455 if (source->peak->x < region->x0) continue; 445 456 if (source->peak->y < region->y0) continue; 446 457 if (source->peak->x > region->x1) continue; 447 458 if (source->peak->y > region->y1) continue; 448 449 450 // XXX for a test, just do the obvious trail451 // XXX if (source->peak->xf < 1100) continue;452 // XXX if (source->peak->xf > 1400) continue;453 // XXX if (source->peak->yf > 245) continue;454 459 455 460 // replace object in image … … 462 467 psphotSetRadiusMomentsExact(&fitRadius, &windowRadius, readout, source, markVal); // NOTE : 6 allocs 463 468 464 // XXX WATCH OUT HERE!!465 // fitRadius = 30;466 467 469 // UPDATE : we have changed the moments calculation. There is now an iteration within 468 470 // psphotKronMasked to determine moments appropriate for a larger object. The values … … 475 477 } 476 478 479 # ifdef TEST_OBJECT 477 480 bool testObject = false; 478 // testObject |= ((fabs(source->peak->xf - 179) < 5) && (fabs(source->peak->yf - 1138) < 5)); 479 // testObject |= ((fabs(source->peak->xf - 5047) < 5) && (fabs(source->peak->yf - 151) < 5)); 480 // testObject |= ((fabs(source->peak->xf - 3929) < 5) && (fabs(source->peak->yf - 4109) < 5)); 481 // testObject |= ((fabs(source->peak->xf - 915) < 5) && (fabs(source->peak->yf - 5998) < 5)); 482 // testObject |= ((fabs(source->peak->xf - 5406) < 5) && (fabs(source->peak->yf - 326) < 5)); 481 testObject |= ((fabs(source->peak->xf - 179) < 5) && (fabs(source->peak->yf - 1138) < 5)); 483 482 if (testObject) { 484 483 fprintf (stderr, "test object @ %f, %f\n", source->peak->xf, source->peak->yf); … … 486 485 psTraceSetLevel ("psphot.psphotExtendedSourceFits_Threaded", 5); 487 486 } 487 # endif 488 488 489 489 // loop here over the models chosen for each source (exclude by S/N) … … 501 501 assert (status); 502 502 503 // limit selection to some SN limit 504 bool skipSource = false; 505 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 506 skipSource = (source->moments->KronFlux < FIT_SN_LIM * source->moments->KronFluxErr); 507 } else { 508 skipSource = (sqrt(source->peak->detValue) < FIT_SN_LIM); 509 } 510 if (skipSource) { 503 // limit selection to some SN limit for specific models (this value only applies if > EXTENDED_SOURCE_SN_LIM) 504 if (isfinite(FIT_SN_LIM)) { 505 if (source->moments->KronFlux < FIT_SN_LIM * source->moments->KronFluxErr) { 511 506 Nfaint ++; 512 507 continue; 508 } 513 509 } 510 511 source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_RUN; 514 512 515 513 // check on the model type … … 529 527 psTrace ("psphot", 5, "failed to fit psf-conv model for object at %f, %f", source->moments->Mx, source->moments->My); 530 528 Nfail ++; 529 source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_FAIL; 531 530 continue; 532 531 } … … 534 533 source->moments->Mx, source->moments->My, pmModelClassGetName (modelFit->type), modelFit->chisq, modelFit->nPix, modelFit->nIter); 535 534 Nconvolve ++; 536 if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) {535 if (!(modelFit->flags & badModel)) { 537 536 NconvolvePass ++; 538 537 source->mode |= PM_SOURCE_MODE_EXTENDED_FIT; … … 548 547 Nfail ++; 549 548 doneFits = true; 549 source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_FAIL; 550 550 continue; 551 551 } 552 552 psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f (npix: %d, niter: %d)\n", source->moments->Mx, source->moments->My, pmModelClassGetName (modelFit->type), modelFit->chisq, modelFit->nPix, modelFit->nIter); 553 553 Nplain ++; 554 if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) {554 if (!(modelFit->flags & badModel)) { 555 555 NplainPass ++; 556 556 source->mode |= PM_SOURCE_MODE_EXTENDED_FIT; … … 576 576 fprintf (stderr, "update window : %f %f : %f -> %f\n", source->peak->xf, source->peak->yf, fitRadius, 2*fitRadius); 577 577 psphotSetWindowTrail (&fitRadius, &windowRadius, readout, source, markVal, fitRadius*2.0); 578 source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_RETRY; 578 579 } 579 580 } 580 581 } 581 582 } 582 // XXX really need to do this in a cleaner way: 583 if (!modelFit) continue; 583 psAssert (modelFit, "modelFit not set?"); 584 584 585 585 // test for fit quality / result … … 590 590 } 591 591 592 // we are allowed to fit both stars and non-stars here -- if we have fitted 593 // something which we think is a star, we should use that model to subtract the 594 // object from the image. 595 if (source->type == PM_SOURCE_TYPE_STAR) { 596 // ensure the modelPSF is cached 597 pmSourceCacheModel (source, maskVal); 598 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 599 continue; 600 } 601 592 602 // evaluate the relative quality of the models, choose one 603 // the PSF model might be the best fit : allow it to succeed 593 604 float minChisq = NAN; 594 605 int minModel = -1; … … 596 607 pmModel *model = source->modelFits->data[i]; 597 608 609 // skip the really bad fits 598 610 if (!(model->flags & PM_MODEL_STATUS_FITTED)) continue; 599 600 if (model->flags & (PM_MODEL_STATUS_BADARGS)) continue; 611 if (model->flags & badModel) continue; 612 601 613 // if (model->flags & (PM_MODEL_STATUS_NONCONVERGE)) continue; 602 if (model->flags & (PM_MODEL_STATUS_OFFIMAGE)) continue;603 614 604 615 if ((minModel < 0) || (model->chisq < minChisq)) { … … 618 629 pmSourceCacheModel (source, maskVal); 619 630 631 # if (PS_TRACE_ON) 620 632 pmModel *model = source->modelFits->data[0]; 621 633 int flags = 0xffffffff; … … 623 635 flags = model->flags; 624 636 } 625 626 637 fprintf (stderr, "failed to fit extended source model to object %d @ %f, %f (%x)\n", source->id, source->moments->Mx, source->moments->My, flags); 638 #endif 627 639 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 628 640 641 source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_NONE; 629 642 continue; 630 643 } … … 643 656 if (source->modelEXT->isPCM) { 644 657 // fprintf (stderr, "subtract PCM extended source model for object %d @ %f, %f\n", source->id, source->moments->Mx, source->moments->My); 645 pmPCMCacheModel (source, maskVal, psfSize );658 pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma); 646 659 } else { 647 660 // fprintf (stderr, "subtract non-PCM extended source model for object %d @ %f, %f\n", source->id, source->moments->Mx, source->moments->My); 648 661 pmSourceCacheModel (source, maskVal); 649 662 } 663 source->modelEXT->flags |= PM_MODEL_BEST_FIT; 650 664 651 665 // subtract the best fit from the object, leave local sky … … 655 669 psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 656 670 671 # ifdef TEST_OBJECT 657 672 if (testObject) { 658 673 psTraceSetLevel ("psModules.objects.pmPCM_MinimizeChisq", 0); 659 674 psTraceSetLevel ("psphot.psphotExtendedSourceFits_Threaded", 0); 660 675 } 676 # endif 661 677 } 662 678
Note:
See TracChangeset
for help on using the changeset viewer.
