IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 9, 2010, 4:41:16 PM (16 years ago)
Author:
eugene
Message:

working on psphotStack (nearly done)

File:
1 edited

Legend:

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

    r27628 r27649  
    1414        if (!psphotMatchSourcesReadout (objects, config, view, "PSPHOT.INPUT", i)) {
    1515            psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i);
    16             return false;
     16            psFree (objects);
     17            return NULL;
    1718        }
    1819    }
     20
     21    // psphotMatchSourcesGenerate (objects, config, view, "PSPHOT.INPUT", i);
     22
     23    return objects;
     24}
     25
     26bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) {
     27 
     28    bool status = false;
     29
     30    // select the appropriate recipe information
     31    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     32    psAssert (recipe, "missing recipe?");
     33
     34    int RADIUS = psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.MATCH.RADIUS");
     35    psAssert (status, "programming error: must define PSPHOT.STACK.MATCH.RADIUS");
     36
     37    // find the currently selected readout
     38    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     39    psAssert (file, "missing file?");
     40
     41    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     42    psAssert (readout, "missing readout?");
     43
     44    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     45    psAssert (detections, "missing detections?");
     46    psAssert (detections->newSources, "new sources not defined?");
     47    psAssert (!detections->allSources, "all sources already defined?");
     48
     49    // XXX TEST:
     50    if (detections->newSources) {
     51        psphotMatchSourcesToObjects(objects, detections->newSources, RADIUS);
     52    }
     53
    1954    return true;
    2055}
    2156
    22 // we need a couple of functions to distinguish coincident sources:
    23 // XXX these are similar (identical?) to the goals of pmSourceMatch.c
    24  
    2557# define NEXT1 { i++; continue; }
    2658# define NEXT2 { j++; continue; }
    27  
    28 bool psphotSourceMerge (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) {
     59bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS) {
    2960 
    3061    float dx, dy;
    3162 
     63    float RADIUS2 = RADIUS*RADIUS;
     64
    3265    // sort the source list by X
    33     pmSourceSortByX (sources1);
    34     pmSourceSortByX (sources2);
     66    sources = psArraySort (sources, pmSourceSortByX);
     67    objects = psArraySort (objects, pmPhotObjSortByX);
    3568 
     69    psVector *found = psVectorAlloc(sources->n, PS_TYPE_U8);
     70    psVectorInit (found, 0);
     71
     72    // match sources to existing objects
     73
     74    psLogMsg ("psphot", PS_LOG_DETAIL, "attempt to match sources (%ld vs %ld)", sources->n, objects->n);
     75
    3676    int i, j;
    37     for (i = j = 0; (i < sources1->n) && (j < sources2->n); ) {
     77    for (i = j = 0; (i < sources->n) && (j < objects->n); ) {
    3878 
    39         pmSource *src1 = sources1->data[i];
    40         pmSource *src2 = sources2->data[j];
     79        pmSource  *src = sources->data[i];
     80        pmPhotObj *obj = objects->data[j];
    4181 
    42         if (!src1) NEXT1;
    43         if (!src1->peak) NEXT1;
    44         if (!finite(src1->peak->xf)) NEXT1;
    45         if (!finite(src1->peak->yf)) NEXT1;
     82        if (!src) NEXT1;
     83        if (!src->peak) NEXT1;
     84        if (!finite(src->peak->xf)) NEXT1;
     85        if (!finite(src->peak->yf)) NEXT1;
    4686 
    47         if (!src2) NEXT2;
    48         if (!src2->peak) NEXT2;
    49         if (!finite(src2->peak->xf)) NEXT2;
    50         if (!finite(src2->peak->yf)) NEXT2;
     87        if (!obj) NEXT2;
     88        if (!finite(obj->x)) NEXT2;
     89        if (!finite(obj->y)) NEXT2;
    5190 
    52         dx = src1->peak->xf - src2->peak->xf;
     91        dx = src->peak->xf - obj->x;
    5392        if (dx < -1.02*RADIUS) NEXT1;
    5493        if (dx > +1.02*RADIUS) NEXT2;
    5594 
    5695        // we are within match range, look for matches:
    57         for (int J = j; (dx > -1.02*radius) && (J < sources2->n); J++) {
     96        int Jmin = -1;
     97        float Rmin = RADIUS2;
     98        for (int J = j; (dx > -1.02*RADIUS) && (J < objects->n); J++) {
    5899 
    59             dx = src1->peak->xf - src2->peak->xf;
    60             dy = src1->peak->yf - src2->peak->yf;
     100            obj = objects->data[J];
     101           
     102            dx = src->peak->xf - obj->x;
     103            dy = src->peak->yf - obj->y;
    61104 
    62             dr = dx*dx + dy*dy;
     105            float dr = dx*dx + dy*dy;
    63106            if (dr > RADIUS2) continue;
    64  
    65             // add to group?
    66         }
     107            if (dr < Rmin) {
     108                Rmin = dr;
     109                Jmin  = J;
     110            }
     111        }
     112
     113        // no match, try next source
     114        if (Jmin == -1) {
     115            i++;
     116            continue;
     117        }
     118        obj = objects->data[Jmin];
     119
     120        // add to object
     121        pmPhotObjAddSource (obj, src);
     122        found->data.U8[i] = 1;
    67123        i++;
    68124    }
     125
     126    // add missed sources to new objects
     127
     128    for (i = 0; i < sources->n; i++) {
     129
     130        if (found->data.U8[i]) continue;
     131
     132        pmSource *src = sources->data[i];
     133
     134        pmPhotObj *obj = pmPhotObjAlloc();
     135        pmPhotObjAddSource(obj, src);
     136        psArrayAdd (objects, 100, obj);
     137    }
     138    psLogMsg ("psphot", PS_LOG_DETAIL, "matched sources (%ld vs %ld)", sources->n, objects->n);
     139
     140    return true;
    69141}
Note: See TracChangeset for help on using the changeset viewer.