IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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:
2 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/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}
Note: See TracChangeset for help on using the changeset viewer.