IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18382 for trunk/ppStack


Ignore:
Timestamp:
Jun 30, 2008, 12:09:14 PM (18 years ago)
Author:
Paul Price
Message:

Figured that we don't want a set of unique sources, since that includes all the cosmic rays from all the inputs. Rather, we want for each image the list of sources in that image, but corrected to be on a common magnitude system (matching zero points across the images) and use that for our target PSF image.

Location:
trunk/ppStack/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStack.h

    r18346 r18382  
    7070/// Add sources to source lists, removing duplicates and solving for magnitude differences
    7171///
    72 /// Returns the source lists.
     72/// Corrects the sources to have consistent magnitudes.  Returns the source lists.
    7373psArray *ppStackSourceListAdd(psArray *lists, ///< List to which to add, or NULL
    74                               const pmReadout *inRO, ///< Readout containing the sources
     74                              psArray *sources, ///< Sources to add
    7575                              const pmConfig *config ///< Configuration
    7676    );
    7777
    78 /// Combine source lists to yield a unique set of sources
     78/// Combine source lists to yield a set of unique sources.
    7979///
    80 /// Returns the sources
     80/// Corrects the sources to have consistent magnitudes where possible.  Returns the sources
    8181psArray *ppStackSourceListCombine(psArray *lists, ///< Source lists
    8282                                  const pmConfig *config ///< Configuration
  • trunk/ppStack/src/ppStackLoop.c

    r18346 r18382  
    213213    // Preparation iteration: Load the sources, and get a target PSF model
    214214    psTrace("ppStack", 1, "Determining target PSF....\n");
    215     psArray *sources = NULL;            // Sources to use for PSF matching
     215    psArray *globalSources = NULL;      // Global list of sources for matching (haveSources = TRUE)
     216    psArray *indSources = psArrayAlloc(num); // Individual lists of sources for matching (haveSources = FALSE)
    216217    pmPSF *targetPSF = NULL;            // Target PSF
    217218    bool haveSources = psMetadataLookupBool(NULL, config->arguments, "HAVE.SOURCES"); // Global sources?
     
    240241                psError(PS_ERR_UNKNOWN, false, "Unable to find PSF.");
    241242                psFree(view);
    242                 psFree(sources);
     243                psFree(globalSources);
     244                psFree(indSources);
    243245                psFree(sourceLists);
    244246                psFree(fileIter);
     
    257259                psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF.");
    258260                psFree(view);
    259                 psFree(sources);
     261                psFree(globalSources);
     262                psFree(indSources);
    260263                psFree(sourceLists);
    261264                psFree(fileIter);
     
    270273            if (!haveSources) {
    271274                pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources
    272                 sourceLists = ppStackSourceListAdd(sourceLists, ro, config);
     275                psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources
     276                if (!sources) {
     277                    psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout.");
     278                    return NULL;
     279                }
     280                sources->data[index] = psMemIncrRefCounter(sources);
     281                sourceLists = ppStackSourceListAdd(sourceLists, sources, config);
    273282                if (!sourceLists) {
    274283                    psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list.");
    275284                    psFree(view);
    276                     psFree(sources);
     285                    psFree(globalSources);
     286                    psFree(indSources);
    277287                    psFree(fileIter);
    278288                    psFree(psfs);
     
    288298        if (!targetPSF) {
    289299            psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF.");
    290             psFree(sources);
     300            psFree(globalSources);
     301            psFree(indSources);
    291302            return false;
    292303        }
     
    294305        if (haveSources) {
    295306            // We want to hang on to the 'sources' even when its host FPA is blown away
    296             sources = psMemIncrRefCounter(pmFPAfileThisReadout(config->files, view, "PPSTACK.INPUT.SOURCES"));
    297             if (!sources) {
     307            globalSources = psMemIncrRefCounter(pmFPAfileThisReadout(config->files, view,
     308                                                                     "PPSTACK.INPUT.SOURCES"));
     309            if (!globalSources) {
    298310                psError(PS_ERR_UNKNOWN, true, "Unable to find sources.");
    299311                psFree(view);
     
    301313            }
    302314        } else {
    303             sources = ppStackSourceListCombine(sourceLists, config);
     315            globalSources = ppStackSourceListCombine(sourceLists, config);
    304316            psFree(sourceLists);
    305             if (!sources) {
     317            if (!globalSources) {
    306318                psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list.");
    307319                psFree(view);
     
    343355        pmFPAview *view = filesIterateDown(config);
    344356        if (!view) {
    345             psFree(sources);
     357            psFree(globalSources);
     358            psFree(indSources);
    346359            psFree(targetPSF);
    347360            psFree(rng);
     
    354367        // Background subtraction, scaling and normalisation is performed automatically by the image matching
    355368        psArray *regions = NULL, *kernels = NULL; // Regions and kernels used in subtraction
     369        psArray *sources = haveSources ? globalSources : indSources->data[i]; // Sources for matching
    356370        if (!ppStackMatch(readout, &regions, &kernels, sources, targetPSF, rng, config)) {
    357371            psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i);
     
    374388        numGood++;
    375389    }
    376     psFree(sources);
     390    psFree(globalSources);
     391    psFree(indSources);
    377392    psFree(targetPSF);
    378393    psFree(rng);
  • trunk/ppStack/src/ppStackSources.c

    r18356 r18382  
    1717    psArray *sources;                   // Sources within region
    1818    psVector *indices;                  // Indices from tree to sources
     19    psArray *duplicates;                // Duplicate sources (from overlaps)
    1920    psTree *tree;                       // kd tree with sources
    2021} ppStackSourceList;
     
    4546    psFree(list->sources);
    4647    psFree(list->indices);
     48    psFree(list->duplicates);
    4749    psFree(list->tree);
    4850}
     
    130132// Extend a list of sources
    131133bool ppStackSourceListExtend(ppStackSourceList *list, // List to extend
    132                              const psArray *newSources // Sources to add
     134                             const psArray *newSources, // Sources to add
     135                             const psArray *newDups // Duplicate sources to add
    133136    )
    134137{
     
    136139    psAssert(newSources, "Must be given sources");
    137140
    138     psArray *oldSources = list->sources;// Old list of sources
    139     long numOld = oldSources->n;        // Number of old sources
    140     long numNew = newSources->n;        // Number of new sources
    141 
    142     list->sources = oldSources = psArrayRealloc(oldSources, numOld + numNew);
    143     for (long i = 0; i < numNew; i++) {
    144         psArrayAdd(oldSources, 1, newSources->data[i]);
    145     }
    146     psFree(list->tree);
    147 
    148     psVector *x = NULL, *y = NULL;      // Source coordinates
    149     stackSourcesParse(&list->bounds, &x, &y, &list->indices, list->sources);
    150     list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources
    151     psFree(x);
    152     psFree(y);
     141    {
     142        psArray *oldSources = list->sources;// Old list of sources
     143        long numOld = oldSources->n;        // Number of old sources
     144        long numNew = newSources->n;        // Number of new sources
     145
     146        list->sources = oldSources = psArrayRealloc(oldSources, numOld + numNew);
     147        for (long i = 0; i < numNew; i++) {
     148            psArrayAdd(oldSources, 1, newSources->data[i]);
     149        }
     150        psFree(list->tree);
     151
     152        psVector *x = NULL, *y = NULL;      // Source coordinates
     153        stackSourcesParse(&list->bounds, &x, &y, &list->indices, list->sources);
     154        list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources
     155        psFree(x);
     156        psFree(y);
     157    }
     158
     159    if (newDups) {
     160        psArray *oldDups = list->duplicates; // Old list of duplicates
     161        long numOld = oldDups ? oldDups->n : 0; // Number of old duplicates
     162        long numNew = newDups->n;       // Number of new duplicates
     163
     164        list->duplicates = oldDups = psArrayRealloc(oldDups, numOld + numNew);
     165        for (long i = 0; i < numNew; i++) {
     166            psArrayAdd(oldDups, 1, newDups->data[i]);
     167        }
     168    }
    153169
    154170    return list;
     
    201217    psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates of source
    202218    psArray *outside = psArrayAllocEmpty(numSources); // Sources that don't correlate
     219    psArray *inside = psArrayAllocEmpty(numSources); // Sources that do correlate
    203220    for (long i = 0; i < numSources; i++) {
    204221        coords->data.F32[0] = x->data.F32[i];
     
    207224        if (match < 0) {
    208225            numOut++;
    209             if (outside) {
    210                 psArrayAdd(outside, 1, sources->data[indices->data.U32[i]]);
    211             }
     226            psArrayAdd(outside, 1, sources->data[indices->data.U32[i]]);
    212227            continue;
    213228        }
     
    220235            numIn++;
    221236            magDiff->data.F32[numIn] = listSource->psfMag - source->psfMag;
     237            psArrayAdd(inside, 1, source);
    222238        }
    223239    }
     
    256272                source->psfMag -= meanDiff;
    257273            }
     274            for (long j = 0; j < list->duplicates->n; j++) {
     275                pmSource *source = list->duplicates->data[j];
     276                source->psfMag -= meanDiff;
     277            }
    258278
    259279            // Suck sources from this list into the first one we found.
    260             psTrace("ppStack.sources", 4, "Bridge found: Merging lists.");
    261 
    262             ppStackSourceListExtend(*merge, list->sources);
     280            psTrace("ppStack.sources", 4, "Bridge: Merging lists.");
     281
     282            ppStackSourceListExtend(*merge, list->sources, NULL);
    263283            psFree(list);
    264284            lists->data[listIndex] = NULL;
     
    269289                source->psfMag += meanDiff;
    270290            }
     291            for (long j = 0; j < numIn; j++) {
     292                pmSource *source = inside->data[j]; // New source
     293                source->psfMag += meanDiff;
     294            }
    271295            // Put the sources that didn't correlate into the list
    272             psTrace("ppStack.sources", 4, "Extending list");
    273             ppStackSourceListExtend(list, outside);
     296            psTrace("ppStack.sources", 4, "Overlap: Extending list");
     297            ppStackSourceListExtend(list, outside, inside);
    274298            *merge = list;
    275299        }
     
    281305        psFree(outside);
    282306    }
     307    psFree(inside);
    283308
    284309    return numIn;
     
    286311
    287312
    288 psArray *ppStackSourceListAdd(psArray *lists, const pmReadout *inRO, const pmConfig *config)
    289 {
    290     PS_ASSERT_PTR_NON_NULL(inRO, NULL);
     313psArray *ppStackSourceListAdd(psArray *lists, psArray *sources, const pmConfig *config)
     314{
     315    PS_ASSERT_PTR_NON_NULL(sources, NULL);
    291316    PS_ASSERT_PTR_NON_NULL(config, NULL);
    292 
    293     psArray *sources = psMetadataLookupPtr(NULL, inRO->analysis, "PSPHOT.SOURCES");
    294     if (!sources) {
    295         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout.");
    296         return NULL;
    297     }
    298317
    299318    if (!lists) {
     
    399418                // It doesn't match anything at all.  Merge it in to the first list.
    400419                psTrace("ppStack.sources", 4, "Disjoint list: Merging into first");
    401                 ppStackSourceListExtend(firstList, list->sources);
     420                ppStackSourceListExtend(firstList, list->sources, NULL);
    402421            }
    403422        }
Note: See TracChangeset for help on using the changeset viewer.