Changeset 17516
- Timestamp:
- May 4, 2008, 2:10:40 PM (18 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 7 edited
-
pmFootprint.h (modified) (1 diff)
-
pmFootprintArrayGrow.c (modified) (4 diffs)
-
pmFootprintIDs.c (modified) (2 diffs)
-
pmFootprintsAssignPeaks.c (modified) (2 diffs)
-
psphotCullPeaks.c (modified) (3 diffs)
-
psphotFindFootprints.c (modified) (1 diff)
-
psphotFitSourcesLinear.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/pmFootprint.h
r17443 r17516 47 47 48 48 psImage *pmSetFootprintArrayIDs(const psArray *footprints, const bool relativeIDs); 49 psImage *pmSetFootprintID( const pmFootprint *fp, const int id);49 psImage *pmSetFootprintID(psImage *idImage, const pmFootprint *fp, const int id); 50 50 void pmSetFootprintArrayIDsForImage(psImage *idImage, 51 51 const psArray *footprints, // the footprints to insert -
trunk/psphot/src/pmFootprintArrayGrow.c
r17443 r17516 8 8 assert (footprints->n == 0 || pmFootprintTest(footprints->data[0])); 9 9 10 psTimerStart ("grow"); 11 10 12 if (footprints->n == 0) { // we don't know the size of the footprint's region 11 13 return psArrayAlloc(0); … … 16 18 */ 17 19 psImage *idImage = pmSetFootprintArrayIDs(footprints, true); 20 psLogMsg ("psphot", PS_LOG_DETAIL, "set footprint array IDs: %f sec\n", psTimerMark ("grow")); 21 18 22 if (r <= 0) { 19 23 r = 1; // r == 1 => no grow … … 32 36 } 33 37 38 # if (1) 39 psImage *f32ImageIn = psImageCopy (NULL, idImage, PS_TYPE_F32); 40 psImage *f32ImageOut = psImageConvolveFFT(NULL, f32ImageIn, NULL, 0, circle); 41 psImage *grownIdImage = psImageCopy (NULL, f32ImageOut, PS_TYPE_S32); 42 psFree (f32ImageIn); 43 psFree (f32ImageOut); 44 # else 34 45 psImage *grownIdImage = psImageConvolveDirect(NULL, idImage, circle); // Here's the actual grow step 46 # endif 47 48 psLogMsg ("psphot", PS_LOG_DETAIL, "convolved with grow disc: %f sec\n", psTimerMark ("grow")); 35 49 psFree(circle); 36 50 37 51 psArray *grown = pmFootprintsFind(grownIdImage, 0.5, 1); // and here we rebuild the grown footprints 52 psLogMsg ("psphot", PS_LOG_DETAIL, "found grown footprints: %f sec\n", psTimerMark ("grow")); 53 38 54 assert (grown != NULL); 39 55 psFree(idImage); psFree(grownIdImage); … … 46 62 psFree((psArray *)peaks); 47 63 64 psLogMsg ("psphot", PS_LOG_DETAIL, "finished grow: %f sec\n", psTimerMark ("grow")); 65 48 66 return grown; 49 67 -
trunk/psphot/src/pmFootprintIDs.c
r17443 r17516 74 74 * Set an image to the value of footprint's ID whever they may fall 75 75 */ 76 psImage *pmSetFootprintID(const pmFootprint *fp, // the footprint to insert 76 psImage *pmSetFootprintID(psImage *idImage, 77 const pmFootprint *fp, // the footprint to insert 77 78 const int id) { // the desired ID 78 79 assert(fp != NULL && pmFootprintTest((const psPtr)fp)); … … 83 84 assert (numCols >= 0 && numRows >= 0); 84 85 85 psImage *idImage = psImageAlloc(numCols, numRows, PS_TYPE_S32); 86 if (idImage == NULL) { 87 idImage = psImageAlloc(numCols, numRows, PS_TYPE_S32); 88 } else { 89 assert (idImage->numCols == numCols); 90 assert (idImage->numRows == numRows); 91 // XXX assert on type (S32) 92 } 86 93 P_PSIMAGE_SET_ROW0(idImage, row0); 87 94 P_PSIMAGE_SET_COL0(idImage, col0); -
trunk/psphot/src/pmFootprintsAssignPeaks.c
r17443 r17516 8 8 psErrorCode 9 9 pmFootprintsAssignPeaks(psArray *footprints, // the pmFootprints 10 const psArray *peaks) { // the pmPeaks10 const psArray *peaks) { // the pmPeaks 11 11 assert (footprints != NULL); 12 12 assert (footprints->n == 0 || pmFootprintTest(footprints->data[0])); … … 54 54 55 55 psFree(ids); 56 // 56 57 57 // Make sure that peaks within each footprint are sorted and unique 58 //59 58 for (int i = 0; i < footprints->n; i++) { 59 60 60 pmFootprint *fp = footprints->data[i]; 61 62 // XXX are we allowed to have peak-less footprints?? 63 if (!fp->peaks->n) continue; 64 61 65 fp->peaks = psArraySort(fp->peaks, pmPeakSortBySN); 62 66 63 for (int j = 1; j < fp->peaks->n; j++) { // check for duplicates 64 if (fp->peaks->data[j] == fp->peaks->data[j-1]) { 65 (void)psArrayRemoveIndex(fp->peaks, j); 66 j--; // we moved everything down one 67 // XXX EAM : the algorithm below should be much faster than using psArrayRemove if 68 // the number of peaks in the footprint is large, or if there are no duplicates. 69 // if we have a lot of small-number peak arrays with duplicates, this may be 70 // slower. 71 72 // track the number of good peaks in the footprint 73 int nGood = 1; 74 75 // check for duplicates 76 // on first pass, we set the index to NULL if peak is a duplicate 77 // XXX EAM : this can leave behind duplicates of the same S/N 78 // (if sorted list has A, B, A, B ...) 79 for (int j = 1; j < fp->peaks->n; j++) { 80 if (fp->peaks->data[j] == fp->peaks->data[nGood]) { 81 // everything on the array has its own mem reference; free and drop this one 82 psFree (fp->peaks->data[j]); 83 fp->peaks->data[j] = NULL; 84 } else { 85 nGood ++; 67 86 } 68 87 } 88 89 // no deleted peaks, go to next footprint 90 if (nGood == fp->peaks->n) continue; 91 92 int nKeep = 0; 93 94 psArray *goodPeaks = psArrayAlloc (nGood); 95 // on second pass, save the good peaks 96 for (int j = 0; j < fp->peaks->n; j++) { // check for duplicates 97 if (fp->peaks->data[j] == NULL) continue; 98 // transfer the data (NULL to avoid double free) 99 // this is only slightly sleazy 100 goodPeaks->data[nKeep] = fp->peaks->data[j]; 101 fp->peaks->data[j] = NULL; 102 nKeep ++; 103 } 104 psAssert (nGood == nKeep, "mis-counted nKeep or nGood"); 105 106 // free the old (now NULL-filled) array 107 psFree (fp->peaks); 108 fp->peaks = goodPeaks; 69 109 } 110 111 // (void)psArrayRemoveIndex(fp->peaks, j); 112 70 113 71 114 return PS_ERR_NONE; -
trunk/psphot/src/psphotCullPeaks.c
r17443 r17516 52 52 * starting point, discard the peak. 53 53 */ 54 psErrorCode pmFootprintCullPeaks (const psImage *img, // the image wherein lives the footprint54 psErrorCode pmFootprintCullPeaks_OLD(const psImage *img, // the image wherein lives the footprint 55 55 const psImage *weight, // corresponding variance image 56 56 pmFootprint *fp, // Footprint containing mortal peaks … … 125 125 pmFootprint *peakFootprint = pmFootprintsFindAtPoint(subImg, threshold, brightPeaks, peak->y, peak->x); 126 126 brightPeaks->n = 0; // don't double free 127 psImage *idImg = pmSetFootprintID( peakFootprint, peak_id);127 psImage *idImg = pmSetFootprintID(NULL, peakFootprint, peak_id); 128 128 psFree(peakFootprint); 129 129 … … 158 158 } 159 159 160 /* 161 * Examine the peaks in a pmFootprint, and throw away the ones that are not sufficiently 162 * isolated. More precisely, for each peak find the highest coll that you'd have to traverse 163 * to reach a still higher peak --- and if that coll's more than nsigma DN below your 164 * starting point, discard the peak. 165 */ 166 167 # define IN_PEAK 1 168 psErrorCode pmFootprintCullPeaks(const psImage *img, // the image wherein lives the footprint 169 const psImage *weight, // corresponding variance image 170 pmFootprint *fp, // Footprint containing mortal peaks 171 const float nsigma_delta, // how many sigma above local background a peak 172 // needs to be to survive 173 const float min_threshold) { // minimum permitted coll height 174 assert (img != NULL); assert (img->type.type == PS_TYPE_F32); 175 assert (weight != NULL); assert (weight->type.type == PS_TYPE_F32); 176 assert (img->row0 == weight->row0 && img->col0 == weight->col0); 177 assert (fp != NULL); 178 179 if (fp->peaks == NULL || fp->peaks->n == 0) { // nothing to do 180 return PS_ERR_NONE; 181 } 182 183 psRegion subRegion; // desired subregion; 1 larger than bounding box (grr) 184 subRegion.x0 = fp->bbox.x0; subRegion.x1 = fp->bbox.x1 + 1; 185 subRegion.y0 = fp->bbox.y0; subRegion.y1 = fp->bbox.y1 + 1; 186 187 psImage *subImg = psImageSubset((psImage *)img, subRegion); 188 psImage *subWt = psImageSubset((psImage *)weight, subRegion); 189 assert (subImg != NULL && subWt != NULL); 190 191 psImage *idImg = psImageAlloc(subImg->numCols, subImg->numRows, PS_TYPE_S32); 192 193 // We need a psArray of peaks brighter than the current peak. 194 // We reject peaks which either: 195 // 1) are below the local threshold 196 // 2) have a brighter peak within their threshold 197 198 // allocate the full-sized array. if the final array is much smaller, we can realloc 199 // at that point. 200 psArray *brightPeaks = psArrayAllocEmpty(fp->peaks->n); 201 psArrayAdd (brightPeaks, 128, fp->peaks->data[0]); 202 203 // The brightest peak is always safe; go through other peaks trying to cull them 204 for (int i = 1; i < fp->peaks->n; i++) { // n.b. fp->peaks->n can change within the loop 205 const pmPeak *peak = fp->peaks->data[i]; 206 int x = peak->x - subImg->col0; 207 int y = peak->y - subImg->row0; 208 // 209 // Find the level nsigma below the peak that must separate the peak 210 // from any of its friends 211 // 212 assert (x >= 0 && x < subImg->numCols && y >= 0 && y < subImg->numRows); 213 const float stdev = sqrt(subWt->data.F32[y][x]); 214 float threshold = subImg->data.F32[y][x] - nsigma_delta*stdev; 215 if (isnan(threshold) || threshold < min_threshold) { 216 // min_threshold is assumed to be below the detection threshold, 217 // so all the peaks are pmFootprint, and this isn't the brightest 218 continue; 219 } 220 221 // XXX EAM : if stdev >= 0, i'm not sure how this can ever be true? 222 if (threshold > subImg->data.F32[y][x]) { 223 threshold = subImg->data.F32[y][x] - 10*FLT_EPSILON; 224 } 225 226 // XXX this is a bit expensive: psImageAlloc for every peak contained in this footprint 227 // perhaps this should alloc a single ID image above and pass it in to be set. 228 229 // XXX optionally use the faster pmFootprintsFind if the subimage size is large (eg, M31) 230 231 // at this point brightPeaks only has the peaks brighter than the current 232 pmFootprint *peakFootprint = pmFootprintsFindAtPoint(subImg, threshold, brightPeaks, peak->y, peak->x); 233 234 // XXX need to supply the image here 235 // we set the IDs to either 1 (in peak) or 0 (not in peak) 236 pmSetFootprintID (idImg, peakFootprint, IN_PEAK); 237 psFree(peakFootprint); 238 239 // Check if any of the previous (brighter) peaks are within the footprint of this peak 240 // If so, the current peak is bogus; drop it. 241 bool keep = true; 242 for (int j = 0; keep && (j < brightPeaks->n); j++) { 243 const pmPeak *peak2 = fp->peaks->data[j]; 244 int x2 = peak2->x - subImg->col0; 245 int y2 = peak2->y - subImg->row0; 246 if (idImg->data.S32[y2][x2] == IN_PEAK) 247 // There's a brighter peak within the footprint above threshold; so cull our initial peak 248 keep = false; 249 } 250 if (!keep) continue; 251 252 psArrayAdd (brightPeaks, 128, fp->peaks->data[i]); 253 } 254 255 psFree (fp->peaks); 256 fp->peaks = brightPeaks; 257 258 psFree(idImg); 259 psFree(subImg); 260 psFree(subWt); 261 262 return PS_ERR_NONE; 263 } 264 -
trunk/psphot/src/psphotFindFootprints.c
r17443 r17516 1 1 # include "psphotInternal.h" 2 3 // N.b. We're not culling this list; call pmFootprintCullPeaks if you4 // want to do that5 2 6 3 bool psphotFindFootprints (pmDetections *detections, psImage *significance, pmReadout *readout, psMetadata *recipe, const int pass, psMaskType maskVal) { -
trunk/psphot/src/psphotFitSourcesLinear.c
r16820 r17516 158 158 // set the sky, sky_x, sky_y components of border matrix 159 159 SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER); 160 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "set border: %f (%d elements)\n", psTimerMark ("psphot"), sparse->Nelem); 160 161 161 162 psSparseConstraint constraint; … … 174 175 skyfit = NULL; 175 176 } 177 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "solve matrix: %f (%d elements)\n", psTimerMark ("psphot"), sparse->Nelem); 176 178 177 179 // adjust I0 for fitSources and subtract … … 192 194 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 193 195 } 196 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "sub models: %f (%d elements)\n", psTimerMark ("psphot"), sparse->Nelem); 194 197 195 198 // measure chisq for each source … … 199 202 pmSourceChisq (model, source->pixels, source->maskObj, source->weight, maskVal); 200 203 } 204 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "get chisqs: %f (%d elements)\n", psTimerMark ("psphot"), sparse->Nelem); 201 205 202 206 // psFree (index); … … 212 216 } 213 217 218 // XXX do we need this? 219 214 220 // Calculate the weight terms for the sky fit component of the matrix. This function operates 215 221 // on the pixels which correspond to all of the sources of interest. These elements fill in … … 222 228 fullArray = psRegionForImage (readout->mask, fullArray); 223 229 psImageMaskRegion (readout->mask, fullArray, "OR", PM_MASK_MARK); 230 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "step 1: %f sec\n", psTimerMark ("psphot")); 224 231 225 232 // turn off MARK for all object pixels … … 232 239 psImageMaskCircle (source->maskView, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK)); 233 240 } 241 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "step 2: %f sec\n", psTimerMark ("psphot")); 234 242 235 243 // accumulate the image statistics from the masked regions … … 268 276 } 269 277 } 278 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "step 3: %f sec\n", psTimerMark ("psphot")); 270 279 271 280 // turn off MARK for all image pixels 272 281 psImageMaskRegion (readout->mask, fullArray, "AND", PS_NOT_U8(PM_MASK_MARK)); 282 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "step 4: %f sec\n", psTimerMark ("psphot")); 273 283 274 284 // set the Border T elements … … 287 297 psSparseBorderElementT (border, 2, 2, y2); 288 298 } 299 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "step 5: %f sec\n", psTimerMark ("psphot")); 300 289 301 return true; 290 302 }
Note:
See TracChangeset
for help on using the changeset viewer.
