- Timestamp:
- Nov 17, 2011, 1:09:10 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111110/psphot/src/psphotMergeSources.c
r32686 r32689 520 520 } 521 521 522 // c reate source parents children from ruleSrc for ruleOut for orphans523 bool psphot SourceParent(pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc)522 // copy the newPeaks from the detections of one pmFPAfile to another 523 bool psphotCopyPeaks (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 524 524 { 525 525 bool status = true; … … 534 534 for (int i = 0; i < num; i++) { 535 535 if (i == chisqNum) continue; // skip chisq image 536 if (!psphotSourceParentReadout (config, view, ruleOut, ruleSrc, i)) { 536 if (!psphotCopyPeaksReadout (config, view, ruleOut, ruleSrc, i)) { 537 psError (PSPHOT_ERR_CONFIG, false, "failed to copy peaks from %s to %s entry %d", ruleSrc, ruleOut, i); 538 return false; 539 } 540 } 541 return true; 542 } 543 544 // add newly detected peaks to the existing list of sources 545 bool psphotCopyPeaksReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 546 547 bool status; 548 549 // find the currently selected readout 550 pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, ruleSrc, index); // File of interest 551 psAssert (fileSrc, "missing file?"); 552 553 pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa); 554 psAssert (readoutSrc, "missing readout?"); 555 556 pmDetections *detections = psMetadataLookupPtr (&status, readoutSrc->analysis, "PSPHOT.DETECTIONS"); 557 psAssert (detections, "missing detections?"); 558 559 // find the currently selected readout 560 pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, ruleOut, index); // File of interest 561 psAssert (fileOut, "missing file?"); 562 563 pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa); 564 psAssert (readoutOut, "missing readout?"); 565 566 // generate a new detection structure for the output filerule 567 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 568 psAssert (detectionsOut, "missing PSPHOT.DETECTIONS?"); 569 570 psAssert (detectionsOut->peaks, "programming error"); 571 psAssert (!detectionsOut->oldPeaks, "programming error"); 572 psAssert (detections->peaks, "programming error"); 573 574 // save the OUT existing peaks on oldPeaks 575 detectionsOut->oldPeaks = detectionsOut->peaks; 576 detectionsOut->peaks = psArrayAllocEmpty(detections->peaks->n); 577 578 for (int i = 0; i < detections->peaks->n; i++) { 579 psAssert (detections->peaks->data[i], "programming error"); 580 pmPeak *peak = pmPeakAlloc (0, 0, 0.0, PM_PEAK_LONE); 581 pmPeakCopy(peak, detections->peaks->data[i]); 582 psArrayAdd (detectionsOut->peaks, 100, peak); 583 psFree (peak); 584 } 585 return true; 586 } 587 588 // create source parents children from ruleSrc for ruleOut for orphans 589 bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 590 { 591 bool status = true; 592 593 int num = psphotFileruleCount(config, ruleSrc); 594 595 // skip the chisq image because it is a duplicate of the detection version 596 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 597 if (!status) chisqNum = -1; 598 599 // loop over the available readouts 600 for (int i = 0; i < num; i++) { 601 if (i == chisqNum) continue; // skip chisq image 602 if (!psphotSourceParentsReadout (config, view, ruleOut, ruleSrc, i)) { 537 603 psError (PSPHOT_ERR_CONFIG, false, "failed to copy sources from %s to %s entry %d", ruleSrc, ruleOut, i); 538 604 return false; … … 542 608 } 543 609 544 // create source parents from ruleSrc for ruleOut for orphaned children for this readout. XXX currently, this is only 545 // used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called 546 // repeatedly) 547 548 // XXX this function will do bad things if called repeatedly. It needs to either (1) delete 549 // the existing DETECTION container on the output images, or (2) intelligently supplement the 550 // existing DETECTION container with only the new detections. 551 bool psphotSourceParentReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 610 // create source parents from ruleSrc for ruleOut for orphaned children for this readout. 611 bool psphotSourceParentsReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 552 612 553 613 bool status; 614 int nParents = 0; 615 int nNonOrphans = 0; 554 616 555 617 // find the currently selected readout … … 583 645 for (int i = 0; i < sourcesSrc->n; i++) { 584 646 pmSource *sourceSrc = sourcesSrc->data[i]; 585 if (sourceSrc->parent) continue; // I am not an orphan 647 if (sourceSrc->parent) { 648 nNonOrphans ++; 649 continue; // Not an orphan 650 } 586 651 587 652 pmSource *sourceOut = pmSourceCopy(sourceSrc); … … 609 674 pmSourceFreePixels (sourceOut); 610 675 611 // XXX do we need to skip the Chisq image sources?612 613 676 // allocate image, weight, mask for the new image for each peak 614 677 if (sourceOut->modelPSF) { … … 620 683 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 621 684 685 nParents ++; 622 686 psArrayAdd (detectionsOut->allSources, 100, sourceOut); 623 687 psFree (sourceOut); 624 688 } 625 psLogMsg ("psphot", 3, "%ld known sources supplied", detectionsOut->allSources->n); 626 689 psLogMsg ("psphot", 3, "%d parents created, %d unorphaned children, %ld input vs %ld output", nParents, nNonOrphans, sourcesSrc->n, detectionsOut->allSources->n); 627 690 628 691 return true; … … 651 714 } 652 715 653 // create source children from ruleSrc for ruleOut for this entry. XXX currently, this is only716 // Create source children from ruleSrc for ruleOut for this entry. Currently, this is only 654 717 // used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called 655 // repeatedly) 656 657 // XXX this function will do bad things if called repeatedly. It needs to either (1) delete 658 // the existing DETECTION container on the output images, or (2) intelligently supplement the 659 // existing DETECTION container with only the new detections. 718 // repeatedly). 660 719 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 661 720 … … 682 741 psAssert (readoutOut, "missing readout?"); 683 742 684 // generate a new detection structure for the output filerule 685 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 686 if (!detectionsOut) { 687 detectionsOut = pmDetectionsAlloc(); 688 detectionsOut->allSources = psArrayAllocEmpty (100); 689 // save detections on the readout->analysis 690 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { 691 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 692 return false; 693 } 694 psFree(detectionsOut); // a copy remains on the analysis metadata 743 // replace any existing DETECTION container on readoutOut->analysis with the new one 744 pmDetections *detectionsOut = pmDetectionsAlloc(); 745 detectionsOut->allSources = psArrayAllocEmpty (100); 746 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { 747 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 748 return false; 695 749 } 696 750 … … 729 783 730 784 // allocate image, weight, mask for the new image for each peak 731 if (sourceOut->modelPSF) { 732 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 733 } 785 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->windowRadius); 734 786 735 787 // child sources have not been subtracted in this image, but this flag may be raised if … … 740 792 psFree (sourceOut); 741 793 } 742 psLogMsg ("psphot", 3, "%ld known sources supplied", detectionsOut->allSources->n); 743 794 psLogMsg ("psphot", 3, "created %ld children", detectionsOut->allSources->n); 795 796 psFree(detectionsOut); // a copy remains on the analysis metadata 744 797 745 798 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
