- Timestamp:
- Apr 9, 2010, 4:41:16 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c
r27628 r27649 14 14 if (!psphotMatchSourcesReadout (objects, config, view, "PSPHOT.INPUT", i)) { 15 15 psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i); 16 return false; 16 psFree (objects); 17 return NULL; 17 18 } 18 19 } 20 21 // psphotMatchSourcesGenerate (objects, config, view, "PSPHOT.INPUT", i); 22 23 return objects; 24 } 25 26 bool 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 19 54 return true; 20 55 } 21 56 22 // we need a couple of functions to distinguish coincident sources:23 // XXX these are similar (identical?) to the goals of pmSourceMatch.c24 25 57 # define NEXT1 { i++; continue; } 26 58 # define NEXT2 { j++; continue; } 27 28 bool psphotSourceMerge (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) { 59 bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS) { 29 60 30 61 float dx, dy; 31 62 63 float RADIUS2 = RADIUS*RADIUS; 64 32 65 // sort the source list by X 33 pmSourceSortByX (sources1);34 pmSourceSortByX (sources2);66 sources = psArraySort (sources, pmSourceSortByX); 67 objects = psArraySort (objects, pmPhotObjSortByX); 35 68 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 36 76 int i, j; 37 for (i = j = 0; (i < sources 1->n) && (j < sources2->n); ) {77 for (i = j = 0; (i < sources->n) && (j < objects->n); ) { 38 78 39 pmSource *src1 = sources1->data[i];40 pm Source *src2 = sources2->data[j];79 pmSource *src = sources->data[i]; 80 pmPhotObj *obj = objects->data[j]; 41 81 42 if (!src 1) NEXT1;43 if (!src 1->peak) NEXT1;44 if (!finite(src 1->peak->xf)) NEXT1;45 if (!finite(src 1->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; 46 86 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; 51 90 52 dx = src 1->peak->xf - src2->peak->xf;91 dx = src->peak->xf - obj->x; 53 92 if (dx < -1.02*RADIUS) NEXT1; 54 93 if (dx > +1.02*RADIUS) NEXT2; 55 94 56 95 // 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++) { 58 99 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; 61 104 62 dr = dx*dx + dy*dy;105 float dr = dx*dx + dy*dy; 63 106 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; 67 123 i++; 68 124 } 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; 69 141 }
Note:
See TracChangeset
for help on using the changeset viewer.
