Changeset 23189
- Timestamp:
- Mar 5, 2009, 9:18:09 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmSourceMatch.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceMatch.c
r21266 r23189 63 63 pmSource *source = sources->data[i]; // Source of interest 64 64 if (!source) continue; 65 if (source->mode & SOURCE_MASK) continue;66 if (!isfinite(source->psfMag)) continue;67 if (!isfinite(source->errMag)) continue;68 if (source->psfMag > SOURCE_FAINTEST) continue;65 if (source->mode & SOURCE_MASK) continue; 66 if (!isfinite(source->psfMag)) continue; 67 if (!isfinite(source->errMag)) continue; 68 if (source->psfMag > SOURCE_FAINTEST) continue; 69 69 70 70 float xSrc, ySrc; // Coordinates of source … … 290 290 static float sourceMatchRelphotIterate(psVector *trans, // Transparencies 291 291 psVector *stars, // Star magnitudes 292 psVector *badImage, // Bad image mask 292 293 const psArray *matches, // Array of matches 293 294 const psVector *zp, // Zero points for each image (incl. airmass term) … … 363 364 for (int i = 0; i < numImages; i++) { 364 365 trans->data.F32[i] = accum->data.F64[i] / accumErr->data.F64[i]; 365 366 if (!isfinite(trans->data.F32[i])) { 367 badImage->data.U8[i] = 0xFF; 368 } 366 369 psTrace("psModules.objects", 3, "Transparency for image %d: %f\n", i, trans->data.F32[i]); 367 370 } … … 379 382 } 380 383 int index = match->image->data.U32[j]; // Image index 384 if (badImage->data.U8[index]) { 385 continue; 386 } 381 387 float mag = match->mag->data.F32[j]; // Measured magnitude 382 388 float magErr2 = PS_SQR(match->magErr->data.F32[j]) + sysErr2; // Error in measured magnitude … … 402 408 static int sourceMatchRelphotPhotometric(psVector *photo, // Photometric determination 403 409 const psVector *trans, // Estimated transparencies 410 const psVector *badImage, // Bad image? 404 411 int transIter, // Iterations for transparency 405 412 float transClip, // Clipping level for transparency … … 409 416 psAssert(photo && photo->type.type == PS_TYPE_U8, "Need photometric determination"); 410 417 psAssert(trans && trans->type.type == PS_TYPE_F32, "Need transparencies"); 418 psAssert(badImage && badImage->type.type == PS_TYPE_U8, "Need bad image determination"); 411 419 412 420 int numImages = photo->n; // Number of images 413 421 414 422 psAssert(trans->n == numImages, "Not enough transparencies: %ld", trans->n); 423 psAssert(badImage->n == numImages, "Not enough bad image determinations: %ld", badImage->n); 415 424 psAssert(transIter >= 0, "Iterations for transparency must be non-negative: %d", transIter); 416 425 psAssert(transClip > 0, "Clipping level for transparency must be positive: %f", transClip); … … 421 430 stats->clipSigma = transClip; 422 431 423 if (!psVectorStats(stats, trans, NULL, NULL, 0)) {432 if (!psVectorStats(stats, trans, NULL, badImage, 0xFF)) { 424 433 psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on transparencies."); 425 434 psFree(stats); … … 432 441 int numPhoto = 0; // Number of photometric images 433 442 for (int i = 0; i < numImages; i++) { 443 if (badImage->data.U8[i]) { 444 continue; 445 } 434 446 if (trans->data.F32[i] < thresh) { 435 447 photo->data.U8[i] = 0xFF; … … 451 463 const psVector *zp, // Zero points for each image 452 464 const psVector *photo, // Photometric image? 465 const psVector *badImage, // Bad image? 453 466 float starClip, // Clipping for stars 454 467 float sysErr2 // Systematic error squared … … 468 481 psAssert(!photo || photo->type.type == PS_TYPE_U8, "Photometric determination is wrong type"); 469 482 psAssert(!photo || photo->n == numImages, "Not enough photometric determinations: %ld", photo->n); 483 psAssert(!badImage || badImage->type.type == PS_TYPE_U8, "Photometric determination is wrong type"); 484 psAssert(!badImage || badImage->n == numImages, "Not enough bad determinations: %ld", badImage->n); 470 485 471 486 starClip = PS_SQR(starClip); … … 481 496 numMeasurements++; 482 497 int index = match->image->data.U32[j]; // Image index 498 if (badImage->data.U8[index]) { 499 continue; 500 } 483 501 float mag = match->mag->data.F32[j]; // Measured magnitude 484 502 float magErr = match->magErr->data.F32[j]; // Error in measured magnitude … … 489 507 float dev = mag + cal - stars->data.F32[i]; // Deviation 490 508 491 // only reject detections from photometric images (non-photometric images can492 // have large errors. XXX Or: allow a much higher rejection threshold493 if (photo->data.U8[index]) {494 if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {495 numRejected++;496 match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;497 }498 }509 // only reject detections from photometric images (non-photometric images can 510 // have large errors. XXX Or: allow a much higher rejection threshold 511 if (photo->data.U8[index]) { 512 if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) { 513 numRejected++; 514 match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF; 515 } 516 } 499 517 } 500 518 } … … 529 547 psVector *photo = psVectorAlloc(numImages, PS_TYPE_U8); // Photometric determination for each image 530 548 psVectorInit(photo, 0); 549 psVector *badImage = psVectorAlloc(numImages, PS_TYPE_U8); // Bad image? 550 psVectorInit(badImage, 0); 531 551 psVector *stars = psVectorAlloc(numStars, PS_TYPE_F32); // Magnitudes for each star 532 552 533 float chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, sysErr); // chi^2 for solution 553 float chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, 554 photo, sysErr); // chi^2 for solution 534 555 psTrace("psModules.objects", 1, "Initial: chi^2 = %f\n", chi2); 535 556 float lastChi2 = INFINITY; // chi^2 on last iteration … … 540 561 541 562 // Identify photometric nights 542 int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip, photoLevel); // Number of photometric images 543 if (numPhoto < 0) { 544 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination"); 545 psFree(trans); 546 psFree(photo); 547 psFree(stars); 548 return NULL; 549 } 550 psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages); 551 552 // XXX use 20 sigma rejection and 0.1 mag systematic error (move these to the recipe) 553 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, 20.0, PS_SQR(0.1)); 554 psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100); 555 556 // XXX use 0.05 mag systematic error (move these to the recipe) 557 chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, PS_SQR(0.1)); // chi^2 for solution 558 psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej); 559 } 560 561 for (int i = 0; i < maxIter && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) { 562 lastChi2 = chi2; 563 564 // Identify photometric nights 565 int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip, 563 int numPhoto = sourceMatchRelphotPhotometric(photo, trans, badImage, transIter, transClip, 566 564 photoLevel); // Number of photometric images 567 565 if (numPhoto < 0) { … … 572 570 return NULL; 573 571 } 572 psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages); 573 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)); 576 psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100); 577 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)); 580 psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej); 581 } 582 583 for (int i = 0; i < maxIter && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) { 584 lastChi2 = chi2; 585 586 // Identify photometric nights 587 int numPhoto = sourceMatchRelphotPhotometric(photo, trans, badImage, transIter, transClip, 588 photoLevel); // Number of photometric images 589 if (numPhoto < 0) { 590 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination"); 591 psFree(trans); 592 psFree(photo); 593 psFree(stars); 594 return NULL; 595 } 574 596 psTrace("psModules.objects", 3, "Determined %d/%d are photometric", numPhoto, numImages); 575 597 576 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, starClip, sysErr);598 fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, starClip, sysErr); 577 599 psTrace("psModules.objects", 3, "%f%% of measurements rejected", fracRej * 100); 578 600 579 chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, sysErr); // chi^2 for solution601 chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sysErr); 580 602 psTrace("psModules.objects", 1, "iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej); 581 603 } 582 604 583 605 psFree(photo); 606 psFree(badImage); 584 607 psFree(stars); 585 608
Note:
See TracChangeset
for help on using the changeset viewer.
