IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32686


Ignore:
Timestamp:
Nov 17, 2011, 6:47:47 AM (15 years ago)
Author:
eugene
Message:

fixing source subtraction for DET image

Location:
branches/eam_branches/ipp-20111110/psphot/src
Files:
2 edited

Legend:

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

    r31452 r32686  
    520520}
    521521
     522// create source parents children from ruleSrc for ruleOut for orphans
     523bool psphotSourceParent (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 (!psphotSourceParentReadout (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 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.
     551bool psphotSourceParentReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) {
     552
     553    bool status;
     554
     555    // find the currently selected readout
     556    pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, ruleSrc, index); // File of interest
     557    psAssert (fileSrc, "missing file?");
     558
     559    pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa);
     560    psAssert (readoutSrc, "missing readout?");
     561
     562    pmDetections *detectionsSrc = psMetadataLookupPtr (&status, readoutSrc->analysis, "PSPHOT.DETECTIONS");
     563    psAssert (detectionsSrc, "missing detections?");
     564
     565    psArray *sourcesSrc = detectionsSrc->allSources;
     566    psAssert (sourcesSrc, "missing sources?");
     567
     568    // find the currently selected readout
     569    pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, ruleOut, index); // File of interest
     570    psAssert (fileOut, "missing file?");
     571
     572    pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa);
     573    psAssert (readoutOut, "missing readout?");
     574
     575    // generate a new detection structure for the output filerule
     576    pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS");
     577    psAssert (detectionsOut, "missing PSPHOT.DETECTIONS?");
     578
     579    // loop over the sources, redefine their pixels to point at the new filerule image,
     580    // copy the source data, and add a reference back to the original source
     581   
     582    // copy the sources from sourceSrcs to the new detection structure
     583    for (int i = 0; i < sourcesSrc->n; i++) {
     584      pmSource *sourceSrc = sourcesSrc->data[i];
     585      if (sourceSrc->parent) continue; // I am not an orphan
     586
     587      pmSource *sourceOut = pmSourceCopy(sourceSrc);
     588      sourceOut->parent = sourceSrc;
     589     
     590      // keep the original source flags
     591      sourceOut->seq      = sourceSrc->seq;
     592      sourceOut->type     = sourceSrc->type;
     593      sourceOut->mode     = sourceSrc->mode;
     594      sourceOut->mode2    = sourceSrc->mode2;
     595      sourceOut->tmpFlags = sourceSrc->tmpFlags;
     596
     597      // does this copy all model data? (NO)
     598      sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF);
     599      sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
     600
     601      if (sourceSrc->modelFits) {
     602          sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n);
     603          for (int j = 0; j < sourceSrc->modelFits->n; j++) {
     604              sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]);
     605          }
     606      }
     607
     608      // drop the references to the original image pixels:
     609      pmSourceFreePixels (sourceOut);
     610
     611      // XXX do we need to skip the Chisq image sources?
     612
     613      // allocate image, weight, mask for the new image for each peak
     614      if (sourceOut->modelPSF) {
     615        pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
     616      }
     617
     618      // child sources have not been subtracted in this image, but this flag may be raised if
     619      // they were subtracted in the parent's image
     620      sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     621
     622      psArrayAdd (detectionsOut->allSources, 100, sourceOut);
     623      psFree (sourceOut);
     624    }
     625    psLogMsg ("psphot", 3, "%ld known sources supplied", detectionsOut->allSources->n);
     626
     627
     628    return true;
     629}
     630
    522631// create source children from ruleSrc for ruleOut
    523632bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc)
     
    545654// used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called
    546655// 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.
    547660bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) {
    548661
     
    593706     
    594707      // keep the original source flags
     708      sourceOut->seq      = sourceSrc->seq;
    595709      sourceOut->type     = sourceSrc->type;
    596710      sourceOut->mode     = sourceSrc->mode;
     
    612726      pmSourceFreePixels (sourceOut);
    613727
     728      // XXX do we need to skip the Chisq image sources?
     729
    614730      // allocate image, weight, mask for the new image for each peak
    615731      if (sourceOut->modelPSF) {
     
    630746}
    631747
    632 // create source children associated with 'filerule' from the objectsSrc.  XXX currently, this
    633 // is only used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be
    634 // called repeatedly)
     748// create source children associated with 'filerule' from the objectsSrc.  returns a new object
     749// array containing the child sources.  XXX currently, this is only used by psphotStackReadout
     750// (sources go on allSources so that psphotChoosePSF can be called repeatedly)
    635751psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc) {
    636752
     
    652768        psAssert (readout, "missing readout?");
    653769
     770        // create DETECTIONS containers for each image, in case one lacks it
    654771        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    655772        if (!detections) {
     
    665782            psAssert (detections, "missing detections?");
    666783        }
     784
     785        // we need to save the new sources on the detection arrays of the appropriate image
    667786        detArrays->data[i] = psMemIncrRefCounter(detections);
    668787        readouts->data[i] = psMemIncrRefCounter(readout);
     
    695814
    696815            pmSource *sourceOut = pmSourceCopy(sourceSrc);
     816            sourceOut->parent = sourceSrc;
     817
     818            // save on the output object array at the same location
    697819            objectOut->sources->data[i] = sourceOut;
    698 
    699             sourceOut->parent = sourceSrc;
    700820
    701821            // keep the original source flags and sequence ID (if set)
     
    720840            pmSourceFreePixels (sourceOut);
    721841
    722             // set the output readotu
     842            // set the output readout
    723843            int index = sourceOut->imageID;
    724844            if (index >= readouts->n) continue; // skip the sources generated by the chisq image
  • branches/eam_branches/ipp-20111110/psphot/src/psphotStackReadout.c

    r32685 r32686  
    115115    }
    116116
    117     // if DET and SRC are different images, copy the detections from DET to SRC
     117    // If DET and SRC are different images, copy the detections from DET to SRC.  This 'copy'
     118    // is just a copy of the container pointer; the sources on both DET and SRC are the same
     119    // memory objects
    118120    if (strcmp(STACK_SRC, STACK_DET)) {
    119121        if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) {
     
    197199    // linear fit to include all sources (subtract again)
    198200    // NOTE : apply to ALL sources (extended + psf)
    199     // NOTE 2 : this function subtracts the models from the given filerule (SRC)
     201    // NOTE 2 : this function subtracts the models from the given filerule (SRC), not DET
    200202    psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 2 (detections->allSources)
    201203
     
    204206    // NOTE: this block performs the 2nd pass low-significance PSF detection stage
    205207    {
     208        // XXX the steps below to subtract the sources from DET should be skipped if SRC == DET!
     209
     210        // generate children sources for all sources in the SRC image
     211        // XXX (DROP existing detections list)
     212        psphotSourceChildren (config, view, STACK_DET, STACK_SRC);
     213
    206214        //  subtract all sources from DET (this will subtract using the psf model for SRC, which
    207215        //  will somewhat oversubtract the sources -- this is OK
     216        // *** this fails because the source->pixels are still pointing at SRC, not DET
    208217        psphotRemoveAllSources (config, view, STACK_DET, true); // ignore subtraction state for sources
    209218
     
    222231        // (this operation just ensures the metadata container has a view on SRC as well
    223232        if (strcmp(STACK_SRC, STACK_DET)) {
    224             if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) {
     233            // XXX this operation now needs to create source parents for the new detections
     234            // XXX if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) {
     235            // XXX      psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
     236            // XXX      return psphotReadoutCleanup (config, view, STACK_SRC);
     237            // XXX }
     238           
     239            // the old detection here are children of SRC; generate parents for the new detections
     240            if (!psphotSourceParents (config, view, STACK_SRC, STACK_DET)) {
    225241                psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
    226242                return psphotReadoutCleanup (config, view, STACK_SRC);
Note: See TracChangeset for help on using the changeset viewer.