- Timestamp:
- Mar 9, 2009, 3:41:26 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090215
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psModules/src/objects/pmSourceMatch.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090215
- Property svn:mergeinfo changed
/branches/eam_branches/eam_branch_20090303 (added) merged: 23158,23175-23181,23202-23210,23220-23225 /trunk merged: 23211-23219,23226-23238
- Property svn:mergeinfo changed
-
branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceMatch.c
r23199 r23239 152 152 153 153 154 psArray *pmSourceMatchSources(const psArray *sourceArrays, float radius )154 psArray *pmSourceMatchSources(const psArray *sourceArrays, float radius, bool cullSingles) 155 155 { 156 156 PS_ASSERT_ARRAY_NON_NULL(sourceArrays, NULL); … … 220 220 221 221 // Match with the master list 222 223 psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources224 long numMatch = 0; // Number of matches225 226 long size = numMaster + numSources; // New size227 xMaster = psVectorRealloc(xMaster, size);228 yMaster = psVectorRealloc(yMaster, size);229 matches = psArrayRealloc(matches, size);230 231 psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates for tree lookup232 for (int j = 0; j < numSources; j++) {233 coords->data.F32[0] = xImage->data.F32[j];234 coords->data.F32[1] = yImage->data.F32[j];235 long index = psTreeNearestWithin(tree, coords, radius); // Match index236 if (index >= 0) {237 // Record the match238 pmSourceMatch *match = matches->data[index]; // Match data239 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);240 numMatch++;241 } else {242 // Add to the master list243 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data244 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);245 xMaster->data.F32[numMaster] = xImage->data.F32[j];246 yMaster->data.F32[numMaster] = yImage->data.F32[j];247 matches->data[numMaster] = match;248 numMaster++;249 xMaster->n = yMaster->n = matches->n = numMaster;250 }251 252 }253 psFree(coords);254 psFree(tree);255 222 { 223 psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources 224 long numMatch = 0; // Number of matches 225 226 long size = numMaster + numSources; // New size 227 xMaster = psVectorRealloc(xMaster, size); 228 yMaster = psVectorRealloc(yMaster, size); 229 matches = psArrayRealloc(matches, size); 230 231 psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates for tree lookup 232 for (int j = 0; j < numSources; j++) { 233 coords->data.F32[0] = xImage->data.F32[j]; 234 coords->data.F32[1] = yImage->data.F32[j]; 235 long index = psTreeNearestWithin(tree, coords, radius); // Match index 236 if (index >= 0) { 237 // Record the match 238 pmSourceMatch *match = matches->data[index]; // Match data 239 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j); 240 numMatch++; 241 } else { 242 // Add to the master list 243 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data 244 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j); 245 xMaster->data.F32[numMaster] = xImage->data.F32[j]; 246 yMaster->data.F32[numMaster] = yImage->data.F32[j]; 247 matches->data[numMaster] = match; 248 numMaster++; 249 xMaster->n = yMaster->n = matches->n = numMaster; 250 } 251 252 } 253 psFree(coords); 254 psFree(tree); 255 } 256 256 257 257 match_image_done: … … 263 263 } 264 264 265 // Now cull the matches that contain only a single star 266 int numGood = 0; // Number of good matches 265 if (cullSingles) { 266 // Now cull the matches that contain only a single star 267 int numGood = 0; // Number of good matches 268 for (int i = 0; i < matches->n; i++) { 269 pmSourceMatch *match = matches->data[i]; // Match of interest 270 if (match->num > 1) { 271 if (i != numGood) { 272 psFree(matches->data[numGood]); 273 matches->data[numGood] = psMemIncrRefCounter(match); 274 } 275 numGood++; 276 } 277 } 278 matches->n = numGood; 279 for (int i = numGood; i < numMaster; i++) { 280 psFree(matches->data[i]); 281 matches->data[i] = NULL; 282 } 283 } 284 285 return matches; 286 } 287 288 289 psArray *pmSourceMatchMerge(psArray *sourceArrays, float radius) 290 { 291 PS_ASSERT_ARRAY_NON_NULL(sourceArrays, NULL); 292 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, NULL); 293 294 psArray *matches = pmSourceMatchSources(sourceArrays, radius, false); // Source matches 295 if (!matches) { 296 psError(PS_ERR_UNKNOWN, false, "Unable to match source lists."); 297 return NULL; 298 } 299 300 int index = 0; // Index to current position on list 267 301 for (int i = 0; i < matches->n; i++) { 302 pmSource *source = NULL; // Source to put in merged list 268 303 pmSourceMatch *match = matches->data[i]; // Match of interest 269 if (match->num > 1) { 270 if (i != numGood) { 271 psFree(matches->data[numGood]); 272 matches->data[numGood] = psMemIncrRefCounter(match); 273 // psFree(match); 274 } 275 numGood++; 276 } 277 } 278 matches->n = numGood; 279 for (int i = numGood; i < numMaster; i++) { 280 psFree(matches->data[i]); 281 matches->data[i] = NULL; 282 } 304 for (int j = 0; j < match->num && !source; j++) { 305 if (!isfinite(match->mag->data.F32[j]) || !isfinite(match->magErr->data.F32[j])) { 306 continue; 307 } 308 int image = match->image->data.S32[j]; // Index of image 309 int index = match->index->data.S32[j]; // Index of source for image 310 psArray *list = sourceArrays->data[image]; // List of interest 311 source = list->data[index]; 312 break; 313 } 314 315 if (source) { 316 psFree(matches->data[index]); 317 matches->data[index] = psMemIncrRefCounter(source); 318 index++; 319 } 320 } 321 322 // Clear out the rest of the list 323 int num = index; // Number of good sources 324 for (; index < matches->n; index++) { 325 psFree(matches->data[index]); 326 matches->data[index] = NULL; 327 } 328 matches->n = num; 283 329 284 330 return matches; 285 331 } 286 287 332 288 333 // Iterate on the star magnitudes and image transparencies … … 524 569 psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches 525 570 const psVector *zp, // Zero points for each image (including airmass term) 526 int maxIter, // Maximum number of iterations527 571 float tol, // Relative tolerance for convergence 572 int iter1, // Number of iterations for pass 1 573 float rej1, // Limit on rejection between iterations for pass 1 574 float sys1, // Systematic error in measurements for pass 1 575 int iter2, // Number of iterations for pass 2 576 float rej2, // Limit on rejection between iterations for pass 2 577 float sys2, // Systematic error in measurements for pass 2 528 578 float rejLimit, // Limit on rejection between iterations 529 579 int transIter, // Clipping iterations for transparency 530 580 float transClip, // Clipping level for transparency 531 float photoLevel, // Level at which we declare image is photometric 532 float starClip, // Clipping for stars 533 float sysErr // Systematic error in measurements 581 float photoLevel // Level at which we declare image is photometric 534 582 ) 535 583 { … … 539 587 PS_ASSERT_FLOAT_LARGER_THAN(transClip, 0.0, NULL); 540 588 541 sysErr *= sysErr; 589 sys1 *= sys1; 590 sys2 *= sys2; 542 591 543 592 int numImages = zp->n; // Number of images … … 552 601 553 602 float chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, 554 photo, sys Err); // chi^2 for solution603 photo, sys1); // chi^2 for solution 555 604 psTrace("psModules.objects", 1, "Initial: chi^2 = %f\n", chi2); 556 605 float lastChi2 = INFINITY; // chi^2 on last iteration 557 606 float fracRej = INFINITY; // Fraction of measurements rejected 558 607 559 // in the first passes, the transparencies are not well deteremined: use high systematic error and the rejection thresholds 560 for (int i = 0; i < 5; i++) { 608 // In the first passes, the transparencies are not well deteremined: use high systematic error and 609 // rejection thresholds 610 for (int i = 0; i < iter1; i++) { 561 611 562 612 // Identify photometric nights … … 572 622 psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages); 573 623 574 // XXX use 20 sigma rejection and 0.1 mag systematic error (move these to the recipe) 575 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, 20.0, PS_SQR(0.1)); 624 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, rej1, sys1); 576 625 psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100); 577 626 578 // XXX use 0.05 mag systematic error (move these to the recipe) 579 chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, PS_SQR(0.1)); 627 chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sys1); 580 628 psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej); 581 629 } 582 630 583 for (int i = 0; i < maxIter&& (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) {631 for (int i = 0; i < iter2 && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) { 584 632 lastChi2 = chi2; 585 633 … … 594 642 return NULL; 595 643 } 596 psTrace("psModules.objects", 3, " Determined %d/%d are photometric", numPhoto, numImages);597 598 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, starClip, sysErr);599 psTrace("psModules.objects", 3, " %f%% of measurements rejected", fracRej * 100);600 601 chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sys Err);602 psTrace("psModules.objects", 1, " iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);644 psTrace("psModules.objects", 3, "Pass 2: Determined %d/%d are photometric", numPhoto, numImages); 645 646 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, rej2, sys2); 647 psTrace("psModules.objects", 3, "Pass 2: %f%% of measurements rejected", fracRej * 100); 648 649 chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sys2); 650 psTrace("psModules.objects", 1, "Pass 2: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej); 603 651 } 604 652
Note:
See TracChangeset
for help on using the changeset viewer.
