Changeset 18382 for trunk/ppStack
- Timestamp:
- Jun 30, 2008, 12:09:14 PM (18 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 3 edited
-
ppStack.h (modified) (1 diff)
-
ppStackLoop.c (modified) (10 diffs)
-
ppStackSources.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStack.h
r18346 r18382 70 70 /// Add sources to source lists, removing duplicates and solving for magnitude differences 71 71 /// 72 /// Returns the source lists.72 /// Corrects the sources to have consistent magnitudes. Returns the source lists. 73 73 psArray *ppStackSourceListAdd(psArray *lists, ///< List to which to add, or NULL 74 const pmReadout *inRO, ///< Readout containing the sources74 psArray *sources, ///< Sources to add 75 75 const pmConfig *config ///< Configuration 76 76 ); 77 77 78 /// Combine source lists to yield a unique set of sources78 /// Combine source lists to yield a set of unique sources. 79 79 /// 80 /// Returns the sources80 /// Corrects the sources to have consistent magnitudes where possible. Returns the sources 81 81 psArray *ppStackSourceListCombine(psArray *lists, ///< Source lists 82 82 const pmConfig *config ///< Configuration -
trunk/ppStack/src/ppStackLoop.c
r18346 r18382 213 213 // Preparation iteration: Load the sources, and get a target PSF model 214 214 psTrace("ppStack", 1, "Determining target PSF....\n"); 215 psArray *sources = NULL; // Sources to use for PSF matching 215 psArray *globalSources = NULL; // Global list of sources for matching (haveSources = TRUE) 216 psArray *indSources = psArrayAlloc(num); // Individual lists of sources for matching (haveSources = FALSE) 216 217 pmPSF *targetPSF = NULL; // Target PSF 217 218 bool haveSources = psMetadataLookupBool(NULL, config->arguments, "HAVE.SOURCES"); // Global sources? … … 240 241 psError(PS_ERR_UNKNOWN, false, "Unable to find PSF."); 241 242 psFree(view); 242 psFree(sources); 243 psFree(globalSources); 244 psFree(indSources); 243 245 psFree(sourceLists); 244 246 psFree(fileIter); … … 257 259 psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF."); 258 260 psFree(view); 259 psFree(sources); 261 psFree(globalSources); 262 psFree(indSources); 260 263 psFree(sourceLists); 261 264 psFree(fileIter); … … 270 273 if (!haveSources) { 271 274 pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources 272 sourceLists = ppStackSourceListAdd(sourceLists, ro, config); 275 psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources 276 if (!sources) { 277 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout."); 278 return NULL; 279 } 280 sources->data[index] = psMemIncrRefCounter(sources); 281 sourceLists = ppStackSourceListAdd(sourceLists, sources, config); 273 282 if (!sourceLists) { 274 283 psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list."); 275 284 psFree(view); 276 psFree(sources); 285 psFree(globalSources); 286 psFree(indSources); 277 287 psFree(fileIter); 278 288 psFree(psfs); … … 288 298 if (!targetPSF) { 289 299 psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF."); 290 psFree(sources); 300 psFree(globalSources); 301 psFree(indSources); 291 302 return false; 292 303 } … … 294 305 if (haveSources) { 295 306 // We want to hang on to the 'sources' even when its host FPA is blown away 296 sources = psMemIncrRefCounter(pmFPAfileThisReadout(config->files, view, "PPSTACK.INPUT.SOURCES")); 297 if (!sources) { 307 globalSources = psMemIncrRefCounter(pmFPAfileThisReadout(config->files, view, 308 "PPSTACK.INPUT.SOURCES")); 309 if (!globalSources) { 298 310 psError(PS_ERR_UNKNOWN, true, "Unable to find sources."); 299 311 psFree(view); … … 301 313 } 302 314 } else { 303 sources = ppStackSourceListCombine(sourceLists, config);315 globalSources = ppStackSourceListCombine(sourceLists, config); 304 316 psFree(sourceLists); 305 if (! sources) {317 if (!globalSources) { 306 318 psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list."); 307 319 psFree(view); … … 343 355 pmFPAview *view = filesIterateDown(config); 344 356 if (!view) { 345 psFree(sources); 357 psFree(globalSources); 358 psFree(indSources); 346 359 psFree(targetPSF); 347 360 psFree(rng); … … 354 367 // Background subtraction, scaling and normalisation is performed automatically by the image matching 355 368 psArray *regions = NULL, *kernels = NULL; // Regions and kernels used in subtraction 369 psArray *sources = haveSources ? globalSources : indSources->data[i]; // Sources for matching 356 370 if (!ppStackMatch(readout, ®ions, &kernels, sources, targetPSF, rng, config)) { 357 371 psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i); … … 374 388 numGood++; 375 389 } 376 psFree(sources); 390 psFree(globalSources); 391 psFree(indSources); 377 392 psFree(targetPSF); 378 393 psFree(rng); -
trunk/ppStack/src/ppStackSources.c
r18356 r18382 17 17 psArray *sources; // Sources within region 18 18 psVector *indices; // Indices from tree to sources 19 psArray *duplicates; // Duplicate sources (from overlaps) 19 20 psTree *tree; // kd tree with sources 20 21 } ppStackSourceList; … … 45 46 psFree(list->sources); 46 47 psFree(list->indices); 48 psFree(list->duplicates); 47 49 psFree(list->tree); 48 50 } … … 130 132 // Extend a list of sources 131 133 bool ppStackSourceListExtend(ppStackSourceList *list, // List to extend 132 const psArray *newSources // Sources to add 134 const psArray *newSources, // Sources to add 135 const psArray *newDups // Duplicate sources to add 133 136 ) 134 137 { … … 136 139 psAssert(newSources, "Must be given sources"); 137 140 138 psArray *oldSources = list->sources;// Old list of sources 139 long numOld = oldSources->n; // Number of old sources 140 long numNew = newSources->n; // Number of new sources 141 142 list->sources = oldSources = psArrayRealloc(oldSources, numOld + numNew); 143 for (long i = 0; i < numNew; i++) { 144 psArrayAdd(oldSources, 1, newSources->data[i]); 145 } 146 psFree(list->tree); 147 148 psVector *x = NULL, *y = NULL; // Source coordinates 149 stackSourcesParse(&list->bounds, &x, &y, &list->indices, list->sources); 150 list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources 151 psFree(x); 152 psFree(y); 141 { 142 psArray *oldSources = list->sources;// Old list of sources 143 long numOld = oldSources->n; // Number of old sources 144 long numNew = newSources->n; // Number of new sources 145 146 list->sources = oldSources = psArrayRealloc(oldSources, numOld + numNew); 147 for (long i = 0; i < numNew; i++) { 148 psArrayAdd(oldSources, 1, newSources->data[i]); 149 } 150 psFree(list->tree); 151 152 psVector *x = NULL, *y = NULL; // Source coordinates 153 stackSourcesParse(&list->bounds, &x, &y, &list->indices, list->sources); 154 list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources 155 psFree(x); 156 psFree(y); 157 } 158 159 if (newDups) { 160 psArray *oldDups = list->duplicates; // Old list of duplicates 161 long numOld = oldDups ? oldDups->n : 0; // Number of old duplicates 162 long numNew = newDups->n; // Number of new duplicates 163 164 list->duplicates = oldDups = psArrayRealloc(oldDups, numOld + numNew); 165 for (long i = 0; i < numNew; i++) { 166 psArrayAdd(oldDups, 1, newDups->data[i]); 167 } 168 } 153 169 154 170 return list; … … 201 217 psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates of source 202 218 psArray *outside = psArrayAllocEmpty(numSources); // Sources that don't correlate 219 psArray *inside = psArrayAllocEmpty(numSources); // Sources that do correlate 203 220 for (long i = 0; i < numSources; i++) { 204 221 coords->data.F32[0] = x->data.F32[i]; … … 207 224 if (match < 0) { 208 225 numOut++; 209 if (outside) { 210 psArrayAdd(outside, 1, sources->data[indices->data.U32[i]]); 211 } 226 psArrayAdd(outside, 1, sources->data[indices->data.U32[i]]); 212 227 continue; 213 228 } … … 220 235 numIn++; 221 236 magDiff->data.F32[numIn] = listSource->psfMag - source->psfMag; 237 psArrayAdd(inside, 1, source); 222 238 } 223 239 } … … 256 272 source->psfMag -= meanDiff; 257 273 } 274 for (long j = 0; j < list->duplicates->n; j++) { 275 pmSource *source = list->duplicates->data[j]; 276 source->psfMag -= meanDiff; 277 } 258 278 259 279 // Suck sources from this list into the first one we found. 260 psTrace("ppStack.sources", 4, "Bridge found: Merging lists.");261 262 ppStackSourceListExtend(*merge, list->sources );280 psTrace("ppStack.sources", 4, "Bridge: Merging lists."); 281 282 ppStackSourceListExtend(*merge, list->sources, NULL); 263 283 psFree(list); 264 284 lists->data[listIndex] = NULL; … … 269 289 source->psfMag += meanDiff; 270 290 } 291 for (long j = 0; j < numIn; j++) { 292 pmSource *source = inside->data[j]; // New source 293 source->psfMag += meanDiff; 294 } 271 295 // Put the sources that didn't correlate into the list 272 psTrace("ppStack.sources", 4, " Extending list");273 ppStackSourceListExtend(list, outside );296 psTrace("ppStack.sources", 4, "Overlap: Extending list"); 297 ppStackSourceListExtend(list, outside, inside); 274 298 *merge = list; 275 299 } … … 281 305 psFree(outside); 282 306 } 307 psFree(inside); 283 308 284 309 return numIn; … … 286 311 287 312 288 psArray *ppStackSourceListAdd(psArray *lists, const pmReadout *inRO, const pmConfig *config)289 { 290 PS_ASSERT_PTR_NON_NULL( inRO, NULL);313 psArray *ppStackSourceListAdd(psArray *lists, psArray *sources, const pmConfig *config) 314 { 315 PS_ASSERT_PTR_NON_NULL(sources, NULL); 291 316 PS_ASSERT_PTR_NON_NULL(config, NULL); 292 293 psArray *sources = psMetadataLookupPtr(NULL, inRO->analysis, "PSPHOT.SOURCES");294 if (!sources) {295 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout.");296 return NULL;297 }298 317 299 318 if (!lists) { … … 399 418 // It doesn't match anything at all. Merge it in to the first list. 400 419 psTrace("ppStack.sources", 4, "Disjoint list: Merging into first"); 401 ppStackSourceListExtend(firstList, list->sources );420 ppStackSourceListExtend(firstList, list->sources, NULL); 402 421 } 403 422 }
Note:
See TracChangeset
for help on using the changeset viewer.
