IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 17, 2011, 1:09:10 PM (15 years ago)
Author:
eugene
Message:

correctly handle the second pass in the detection image: the code was creating duplicate detections in 2 ways: 1) the source subtraction before the second pass was only being applied to the SRC, not the DET image, thus all 1st pass detections were also found as 2nd pass detections; 2) the DBL star fitting function was causing trouble, with the two positions merging to a single object -- this was considered a success, but left behind flux in the subtracted image (and garbage detections in general); Ive turned off the DBL fitting for now as I am not convinced that code is ready

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111110/psphot/src/psphotMergeSources.c

    r32686 r32689  
    520520}
    521521
    522 // create source parents children from ruleSrc for ruleOut for orphans
    523 bool psphotSourceParent (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc)
     522// copy the newPeaks from the detections of one pmFPAfile to another
     523bool psphotCopyPeaks (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc)
    524524{
    525525    bool status = true;
     
    534534    for (int i = 0; i < num; i++) {
    535535        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
     545bool 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
     589bool 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)) {
    537603            psError (PSPHOT_ERR_CONFIG, false, "failed to copy sources from %s to %s entry %d", ruleSrc, ruleOut, i);
    538604            return false;
     
    542608}
    543609
    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. 
     611bool psphotSourceParentsReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) {
    552612
    553613    bool status;
     614    int nParents = 0;
     615    int nNonOrphans = 0;
    554616
    555617    // find the currently selected readout
     
    583645    for (int i = 0; i < sourcesSrc->n; i++) {
    584646      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      }
    586651
    587652      pmSource *sourceOut = pmSourceCopy(sourceSrc);
     
    609674      pmSourceFreePixels (sourceOut);
    610675
    611       // XXX do we need to skip the Chisq image sources?
    612 
    613676      // allocate image, weight, mask for the new image for each peak
    614677      if (sourceOut->modelPSF) {
     
    620683      sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    621684
     685      nParents ++;
    622686      psArrayAdd (detectionsOut->allSources, 100, sourceOut);
    623687      psFree (sourceOut);
    624688    }
    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);
    627690
    628691    return true;
     
    651714}
    652715
    653 // create source children from ruleSrc for ruleOut for this entry.  XXX currently, this is only
     716// Create source children from ruleSrc for ruleOut for this entry.  Currently, this is only
    654717// 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).
    660719bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) {
    661720
     
    682741    psAssert (readoutOut, "missing readout?");
    683742
    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;
    695749    }
    696750
     
    729783
    730784      // 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);
    734786
    735787      // child sources have not been subtracted in this image, but this flag may be raised if
     
    740792      psFree (sourceOut);
    741793    }
    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
    744797
    745798    return true;
Note: See TracChangeset for help on using the changeset viewer.