Changeset 30624 for trunk/psphot/src/psphotMergeSources.c
- Timestamp:
- Feb 13, 2011, 12:33:05 PM (15 years ago)
- Location:
- trunk/psphot
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psphotMergeSources.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:mergeinfo changed
-
trunk/psphot/src/psphotMergeSources.c
r29936 r30624 513 513 } 514 514 515 return true; 516 } 517 515 // loop over the sources, redefine their pixels to point at the new filerule image, 516 // copy the source data, and add a reference back to the original source 517 518 519 return true; 520 } 521 522 // create source children from ruleSrc for ruleOut 523 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 524 { 525 bool status = true; 526 527 int num = psphotFileruleCount(config, ruleSrc); 528 529 // skip the chisq image because it is a duplicate of the detection version 530 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 531 if (!status) chisqNum = -1; 532 533 // loop over the available readouts 534 for (int i = 0; i < num; i++) { 535 if (i == chisqNum) continue; // skip chisq image 536 if (!psphotSourceChildrenReadout (config, view, ruleOut, ruleSrc, i)) { 537 psError (PSPHOT_ERR_CONFIG, false, "failed to copy sources from %s to %s entry %d", ruleSrc, ruleOut, i); 538 return false; 539 } 540 } 541 return true; 542 } 543 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) 547 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 548 549 bool status; 550 551 // find the currently selected readout 552 pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, ruleSrc, index); // File of interest 553 psAssert (fileSrc, "missing file?"); 554 555 pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa); 556 psAssert (readoutSrc, "missing readout?"); 557 558 pmDetections *detectionsSrc = psMetadataLookupPtr (&status, readoutSrc->analysis, "PSPHOT.DETECTIONS"); 559 psAssert (detectionsSrc, "missing detections?"); 560 561 psArray *sourcesSrc = detectionsSrc->allSources; 562 psAssert (sourcesSrc, "missing sources?"); 563 564 // find the currently selected readout 565 pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, ruleOut, index); // File of interest 566 psAssert (fileOut, "missing file?"); 567 568 pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa); 569 psAssert (readoutOut, "missing readout?"); 570 571 // generate a new detection structure for the output filerule 572 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 573 if (!detectionsOut) { 574 detectionsOut = pmDetectionsAlloc(); 575 detectionsOut->allSources = psArrayAllocEmpty (100); 576 // save detections on the readout->analysis 577 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { 578 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 579 return false; 580 } 581 psFree(detectionsOut); // a copy remains on the analysis metadata 582 } 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 587 // copy the sources from sourceSrcs to the new detection structure 588 for (int i = 0; i < sourcesSrc->n; i++) { 589 pmSource *sourceSrc = sourcesSrc->data[i]; 590 591 pmSource *sourceOut = pmSourceCopy(sourceSrc); 592 sourceOut->parent = sourceSrc; 593 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 } 610 611 // drop the references to the original image pixels: 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.
