Changeset 30172
- Timestamp:
- Dec 24, 2010, 3:25:49 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/psphot/src/psphotMergeSources.c
r30142 r30172 520 520 } 521 521 522 // c opy the detections from one pmFPAfile to another522 // create source children from ruleSrc for ruleOut 523 523 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 524 524 { … … 542 542 } 543 543 544 // add newly selected sources to the existing list of sources 544 // create source children from ruleSrc for ruleOut for this entry. XXX currently, this is only 545 // used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called 546 // repeatedly) 545 547 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 546 548 … … 567 569 psAssert (readoutOut, "missing readout?"); 568 570 569 // loop over the sources, redefine their pixels to point at the new filerule image, 570 // copy the source data, and add a reference back to the original source 571 572 // XXX currently, this is only used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called repeatedly) 571 // generate a new detection structure for the output filerule 573 572 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 574 573 if (!detectionsOut) { … … 583 582 } 584 583 584 // loop over the sources, redefine their pixels to point at the new filerule image, 585 // copy the source data, and add a reference back to the original source 586 585 587 // copy the sources from sourceSrcs to the new detection structure 586 588 for (int i = 0; i < sourcesSrc->n; i++) { … … 590 592 sourceOut->parent = sourceSrc; 591 593 592 // does this copy all model data? 594 // keep the original source flags 595 sourceOut->type = sourceSrc->type; 596 sourceOut->mode = sourceSrc->mode; 597 sourceOut->mode2 = sourceSrc->mode2; 598 sourceOut->tmpFlags = sourceSrc->tmpFlags; 599 600 // does this copy all model data? (NO) 601 sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF); 602 sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT); 603 604 if (sourceSrc->modelFits) { 605 sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n); 606 for (int j = 0; j < sourceSrc->modelFits->n; j++) { 607 sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]); 608 } 609 } 593 610 594 611 // drop the references to the original image pixels: 595 // pmSourceFreePixels (sourceOut); 596 597 // allocate image, weight, mask for the new image for each peak (square of radius OUTER) 598 pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y, sourceSrc->fitRadius, true); 599 600 // XXX source ID, imageID : how are they really used? 601 sourceOut->imageID = sourceSrc->imageID; 602 // P_PM_SOURCE_SET_ID(source, i); 603 604 psArrayAdd (detections->allSources, 100, sourceOut); 605 } 606 psLogMsg ("psphot", 3, "%ld known sources supplied", detections->allSources->n); 607 608 609 return true; 610 } 611 612 pmSourceFreePixels (sourceOut); 613 614 // allocate image, weight, mask for the new image for each peak 615 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 616 617 // child sources have not been subtracted in this image, but this flag may be raised if 618 // they were subtracted in the parent's image 619 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 620 621 psArrayAdd (detectionsOut->allSources, 100, sourceOut); 622 psFree (sourceOut); 623 } 624 psLogMsg ("psphot", 3, "%ld known sources supplied", detectionsOut->allSources->n); 625 626 627 return true; 628 } 629 630 // create source children associated with 'filerule' from the objectsSrc. XXX currently, this 631 // is only used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be 632 // called repeatedly) 633 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc) { 634 635 bool status; 636 637 int nImages = psphotFileruleCount(config, filerule); 638 639 // generate look-up arrays for detections and readouts 640 psArray *detArrays = psArrayAlloc(nImages); 641 psArray *readouts = psArrayAlloc(nImages); 642 643 for (int i = 0; i < nImages; i++) { 644 645 // find the currently selected readout 646 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 647 psAssert (file, "missing file?"); 648 649 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 650 psAssert (readout, "missing readout?"); 651 652 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 653 if (!detections) { 654 detections = pmDetectionsAlloc(); 655 detections->allSources = psArrayAllocEmpty (100); 656 detections->peaks = psArrayAllocEmpty (100); 657 // save detections on the readout->analysis 658 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detections)) { 659 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 660 return NULL; 661 } 662 psFree(detections); // a copy remains on the analysis metadata 663 psAssert (detections, "missing detections?"); 664 } 665 detArrays->data[i] = psMemIncrRefCounter(detections); 666 readouts->data[i] = psMemIncrRefCounter(readout); 667 } 668 669 psArray *objectsOut = psArrayAlloc(objectsSrc->n); 670 671 // copy all sources for each object 672 for (int k = 0; k < objectsSrc->n; k++) { 673 674 pmPhotObj *objectSrc = objectsSrc->data[k]; 675 if (!objectSrc) continue; 676 if (!objectSrc->sources) continue; 677 678 pmPhotObj *objectOut = pmPhotObjAlloc(); 679 objectsOut->data[k] = objectOut; 680 681 objectOut->SN = objectSrc->SN; 682 objectOut->x = objectSrc->x; 683 objectOut->y = objectSrc->y; 684 685 objectOut->sources = psArrayAlloc(objectSrc->sources->n); 686 687 // copy the sources from sourceSrcs to the new detection structure 688 // loop over the sources, redefine their pixels to point at the new filerule image, 689 // copy the source data, and add a reference back to the original source 690 for (int i = 0; i < objectSrc->sources->n; i++) { 691 692 pmSource *sourceSrc = objectSrc->sources->data[i]; 693 694 pmSource *sourceOut = pmSourceCopy(sourceSrc); 695 objectOut->sources->data[i] = sourceOut; 696 697 sourceOut->parent = sourceSrc; 698 699 // keep the original source flags 700 sourceOut->type = sourceSrc->type; 701 sourceOut->mode = sourceSrc->mode; 702 sourceOut->mode2 = sourceSrc->mode2; 703 sourceOut->tmpFlags = sourceSrc->tmpFlags; 704 705 // does this copy all model data? (NO) 706 sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF); 707 sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT); 708 709 if (sourceSrc->modelFits) { 710 sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n); 711 for (int j = 0; j < sourceSrc->modelFits->n; j++) { 712 sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]); 713 } 714 } 715 716 // drop the references to the original image pixels: 717 pmSourceFreePixels (sourceOut); 718 719 // set the output readotu 720 int index = sourceOut->imageID; 721 if (index >= readouts->n) continue; // skip the sources generated by the chisq image 722 pmReadout *readout = readouts->data[index]; 723 724 // allocate image, weight, mask for the new image for each peak 725 pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 726 727 // child sources have not been subtracted in this image, but this flag may be raised if 728 // they were subtracted in the parent's image 729 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 730 731 // set the output detections: 732 pmDetections *detectionsOut = detArrays->data[index]; 733 psArrayAdd (detectionsOut->allSources, 100, sourceOut); 734 psArrayAdd (detectionsOut->peaks, 100, sourceOut->peak); 735 } 736 } 737 738 for (int i = 0; i < nImages; i++) { 739 pmDetections *detections = detArrays->data[i]; 740 psLogMsg ("psphot", 3, "%ld source children for image %d", detections->allSources->n, i); 741 } 742 743 psFree (detArrays); 744 psFree (readouts); 745 746 return objectsOut; 747 } 748
Note:
See TracChangeset
for help on using the changeset viewer.
