IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27650


Ignore:
Timestamp:
Apr 11, 2010, 2:48:58 PM (16 years ago)
Author:
eugene
Message:

create sources for matched detections found on other images (psphotStack)

Location:
branches/eam_branches/stackphot.20100406/psphot/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/stackphot.20100406/psphot/src

    • Property svn:ignore
      •  

        old new  
        2121psphotForced
        2222psphotMakePSF
         23psphotStack
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotMergeSources.c

    r27314 r27650  
    7676    pmDetections *extCMF = NULL;
    7777    psArray *extSourcesTXT = NULL;
    78 
    79     // find the currently selected readout
    80     pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest
     78    int index = 0;
     79
     80    // find the currently selected readout
     81    pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", index); // File of interest
    8182    psAssert (file, "missing file?");
    8283
     
    118119                psFree (source->modelPSF);
    119120                source->modelPSF = NULL;
     121                source->imageID = index;
    120122
    121123                psArrayAdd (detections->newSources, 100, source);
     
    140142                psFree (source->modelPSF);
    141143                source->modelPSF = NULL;
     144                source->imageID = index;
    142145
    143146                psArrayAdd (detections->newSources, 100, source);
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c

    r27649 r27650  
    11# include "psphotInternal.h"
     2
     3bool psphotMatchSourcesGenerate (pmConfig *config, const pmFPAview *view, psArray *objects);
    24 
    35psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view)
     
    1921    }
    2022
    21     // psphotMatchSourcesGenerate (objects, config, view, "PSPHOT.INPUT", i);
     23    psphotMatchSourcesGenerate (config, view, objects);
    2224
    2325    return objects;
     
    135137        pmPhotObjAddSource(obj, src);
    136138        psArrayAdd (objects, 100, obj);
     139        psFree (obj);
    137140    }
    138141    psLogMsg ("psphot", PS_LOG_DETAIL, "matched sources (%ld vs %ld)", sources->n, objects->n);
    139142
     143    psFree (found);
    140144    return true;
    141145}
     146
     147bool psphotMatchSourcesGenerate (pmConfig *config, const pmFPAview *view, psArray *objects) {
     148
     149    bool status = false;
     150
     151    // select the appropriate recipe information
     152    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     153    psAssert (recipe, "missing recipe?");
     154
     155    // determine properties (sky, moments) of initial sources
     156    float OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS");
     157    psAssert (status, "missing SKY_OUTER_RADIUS in recipe?");
     158
     159    int nImages = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     160    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     161
     162    // generate look-up arrays for detections and readouts
     163    psArray *detArrays = psArrayAlloc(nImages);
     164    psArray *readouts = psArrayAlloc(nImages);
     165
     166    for (int i = 0; i < nImages; i++) {
     167
     168        // find the currently selected readout
     169        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", i); // File of interest
     170        psAssert (file, "missing file?");
     171
     172        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     173        psAssert (readout, "missing readout?");
     174
     175        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     176        psAssert (detections, "missing detections?");
     177
     178        detArrays->data[i] = psMemIncrRefCounter(detections);
     179        readouts->data[i] = psMemIncrRefCounter(readout);
     180    }
     181
     182    // vector to track if source for an image is found
     183    psVector *found = psVectorAlloc(nImages, PS_TYPE_U8);
     184
     185    for (int i = 0; i < objects->n; i++) {
     186        pmPhotObj *obj = objects->data[i];
     187
     188        // mark the images for which sources have been found
     189        psVectorInit (found, 0);
     190        for (int j = 0; j < obj->sources->n; j++) {
     191
     192            pmSource *src = obj->sources->data[j];
     193            int index = src->imageID;
     194            psAssert (index >= 0, "invalid index");
     195            psAssert (index < found->n, "invalid index");
     196
     197            found->data.U8[index] = 1;
     198        }
     199
     200        // generate new sources for the image that are missing
     201        for (int index = 0; index < found->n; index++) {
     202            if (found->data.U8[index]) continue;
     203
     204            pmDetections *detections = detArrays->data[index];
     205            pmReadout *readout = readouts->data[index];
     206            int row0 = readout->image->row0;
     207            int col0 = readout->image->col0;
     208
     209            // XXX the peak type is not really used in psphot
     210            // PM_PEAK_LONE is certainly not true, but irrelevant
     211            float peakFlux = readout->image->data.F32[(int)(obj->y-row0-0.5)][(int)(obj->x-col0-0.5)];
     212            pmPeak *peak = pmPeakAlloc(obj->x, obj->y, peakFlux, PM_PEAK_LONE);
     213            peak->flux = peakFlux;
     214            peak->SN = 1.0;
     215            peak->xf = obj->x;
     216            peak->yf = obj->y;
     217            peak->dx = NAN;
     218            peak->dy = NAN;
     219           
     220            // XXX assign to a footprint?
     221
     222            // create a new source
     223            pmSource *source = pmSourceAlloc();
     224            source->imageID = index;
     225
     226            // add the peak
     227            source->peak = psMemIncrRefCounter(peak);
     228
     229            // allocate space for moments
     230            source->moments = pmMomentsAlloc();
     231
     232            // allocate image, weight, mask arrays for each peak (square of radius OUTER)
     233            pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
     234
     235            peak->assigned = true;
     236            pmPhotObjAddSource(obj, source);
     237            psArrayAdd (detections->newSources, 100, source);
     238            psFree (source);
     239            psFree (peak);
     240        }
     241    }
     242
     243    // how many sources do we have now?
     244    int nSources = 0;
     245    for (int i = 0; i < objects->n; i++) {
     246        pmPhotObj *obj = objects->data[i];
     247        nSources += obj->sources->n;
     248    }
     249    psLogMsg ("psphot", PS_LOG_DETAIL, "total of %d sources for %d images", nSources, nImages);
     250
     251
     252    psFree (found);
     253    psFree (detArrays);
     254    psFree (readouts);
     255    return true;
     256}
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceStats.c

    r27571 r27650  
    22
    33// convert detections to sources and measure their basic properties (moments, local sky, sky
    4 // variance) Note: this function only generates sources for the new peaks (peak->assigned)
     4// variance) Note: this function only generates sources for the new peaks (peak->assigned).
     5// The new sources are added to any existing sources on detections->newSources.  The sources
     6// on detections->allSources are ignored.
    57bool psphotSourceStats (pmConfig *config, const pmFPAview *view, bool setWindow)
    68{
     
    4042    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    4143    psAssert (detections, "missing detections?");
    42     psAssert (!detections->newSources, "new sources already defined?");
    4344
    4445    // XXX TEST:
     
    8485
    8586    // generate the array of sources, define the associated pixel
    86     sources = psArrayAllocEmpty (peaks->n);
     87    if (!detections->newSources) {
     88        detections->newSources = psArrayAllocEmpty (peaks->n);
     89    }
     90    sources = detections->newSources;
    8791
    8892    // if there are no peaks, we save the empty source array and return
    8993    if (!peaks->n) {
    90         // save the new sources on the detection structure:
    91         detections->newSources = sources;
    9294        return true;
    9395    }
     
    100102        // create a new source
    101103        pmSource *source = pmSourceAlloc();
     104        source->imageID = index;
    102105
    103106        // add the peak
     
    119122        psLogMsg ("psphot", PS_LOG_INFO, "break point PEAKS, skipping MOMENTS\n");
    120123        psphotVisualShowMoments (sources);
    121         detections->newSources = sources;
    122124        return true;
    123125    }
     
    126128        if (!psphotSetMomentsWindow(recipe, readout->analysis, sources)) {
    127129            psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
    128             psFree(sources);
     130            psFree(detections->newSources);
    129131            return false;
    130132        }
     
    178180                psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
    179181                psFree (job);
    180                 psFree(sources);
     182                psFree(detections->newSources);
    181183                return false;
    182184            }
     
    187189        if (!psThreadPoolWait (false)) {
    188190            psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
    189             psFree(sources);
     191            psFree(detections->newSources);
    190192            return false;
    191193        }
     
    215217    psphotVisualShowMoments (sources);
    216218
    217     // save the new sources on the detection structure:
    218     detections->newSources = sources;
    219 
    220 
    221219    if (detections->allSources) {
    222220        psphotMaskCosmicRayFootprintCheck(detections->allSources);
     
    377375        pmSource *source = sources->data[i];
    378376
     377        if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue;
     378        source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
     379
    379380        // skip faint sources for moments measurement
    380381        if (source->peak->SN < MIN_SN) {
Note: See TracChangeset for help on using the changeset viewer.