Changeset 35383 for trunk/ppStack/src/ppStackSources.c
- Timestamp:
- Apr 9, 2013, 1:33:36 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/ppStack/src/ppStackSources.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackSources.c
r34174 r35383 11 11 #endif 12 12 13 #ifdef TESTING 13 // #define TESTING_CZW 14 15 #ifdef TESTING_CZW 14 16 // Dump matches to a file 15 17 static void dumpMatches(const char *filename, // File to which to dump … … 28 30 psVectorInit(magErr, NAN); 29 31 for (int j = 0; j < match->num; j++) { 32 if (match->mask) { 30 33 if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) { 31 continue; 32 } 34 continue; 35 } 36 } 33 37 int index = match->image->data.U32[j]; // Image index 34 38 mag->data.F32[index] = match->mag->data.F32[j] - zp->data.F32[index]; … … 39 43 } 40 44 for (int j = 0; j < num; j++) { 41 fprintf(outMatches, "%f (%f) ", mag->data.F32[j], magErr->data.F32[j]); 45 fprintf(outMatches, "%f %f %f %f %f %f\t", 46 match->mag->data.F32[j], 47 zp->data.F32[j], 48 trans ? trans->data.F32[j] : NAN, 49 magErr->data.F32[j], 50 match->x->data.F32[j], 51 match->y->data.F32[j]); 42 52 } 43 53 fprintf(outMatches, "\n"); … … 271 281 return false; 272 282 } 273 274 #ifdef TESTING 283 options->sources = psMemIncrRefCounter(matches); 284 psArray *matchedSources = psArrayAlloc(0); 285 286 #ifdef TESTING_CZW 275 287 dumpMatches("source_match.dat", num, matches, zp, NULL); 276 288 #endif 277 289 278 290 if (options->matchZPs) { 279 psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1, 291 292 psVector *trans = pmSourceMatchRelphot(matches, matchedSources, zp, tol, iter1, starRej1, starSys1, 280 293 iter2, starRej2, starSys2, starLimit, 281 294 transIter, transRej, transThresh); // Transparencies per image … … 324 337 325 338 // m_inst_o - m_inst_i = zp[i] - zpTarget - c1 * airmassTarget - 2.5log(sumExpTime) - trans_i 326 339 #ifdef TESTING_CZW 340 dumpMatches("source_match2.dat", num, matches, zp, trans); 341 #endif 327 342 if (options->matchZPs) { 328 343 options->norm = psVectorAlloc(num, PS_TYPE_F32); 329 344 for (int i = 0; i < num; i++) { 330 if (inputMask->data.U8[i] ||!isfinite(trans->data.F32[i])) {331 continue;332 }345 if (!isfinite(trans->data.F32[i])) { 346 continue; 347 } 333 348 psArray *sources = sourceLists->data[i]; // Sources of interest 334 349 float magCorr = zp->data.F32[i] - trans->data.F32[i] - 2.5*log10(options->sumExposure) - airmassTerm * airmassTarget; … … 341 356 options->norm->data.F32[i] = magCorr; 342 357 psLogMsg("ppStack", PS_LOG_INFO, 343 "Applying scale correction to image %d: %f mag (%f) \n",344 i, magCorr, trans->data.F32[i] );358 "Applying scale correction to image %d: %f mag (%f) (with inputMask value %d)\n", 359 i, magCorr, trans->data.F32[i],inputMask->data.U8[i]); 345 360 346 361 for (int j = 0; j < sources->n; j++) { 347 362 pmSource *source = sources->data[j]; // Source of interest 363 source->psfMag += magCorr; 364 source->apMag += magCorr; 365 348 366 if (!source) { 349 367 continue; 350 368 } 351 369 // XXX need to apply to apMag as well 352 source->psfMag += magCorr; 353 source->apMag += magCorr; 370 psTrace("ppStack",5,"Source corrections: %d %d %f %f %f %f %f %f %f %f\n",i,j, 371 source->peak->xf,source->peak->yf, 372 source->psfMag,source->psfMagErr, 373 airmassTerm,airmassTarget,2.5 * log10(options->sumExposure), 374 source->psfMag + magCorr); 354 375 } 355 376 } 356 377 } 378 matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches 357 379 358 380 if (zpExpNum == numGoodImages) { … … 366 388 367 389 368 #ifdef TESTING369 dumpMatches("source_mags.dat", num, matches, zp, trans);370 #endif371 390 psFree(trans); 372 391 373 #ifdef TESTING 392 #ifdef TESTING_CZW 374 393 // Double check: all transparencies should be zero 375 394 { 376 395 psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches 396 psArray *matchedSources = psArrayAlloc(matches->n); 377 397 if (!matches) { 378 398 psError(PPSTACK_ERR_DATA, false, "Unable to match sources"); … … 380 400 return false; 381 401 } 382 psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1,402 psVector *trans = pmSourceMatchRelphot(matches, matchedSources, zp, tol, iter1, starRej1, starSys1, 383 403 iter2, starRej2, starSys2, starLimit, 384 404 transIter, transRej, transThresh); // Transparencies … … 386 406 fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]); 387 407 } 408 388 409 psFree(trans); 389 410 psFree(matches); 390 } 391 #endif 392 } 393 394 psFree(zp); 411 psFree(matchedSources); 412 } 413 #endif 414 } 415 416 395 417 psFree(zpExp); 396 418 397 419 #ifdef ASTROMETRY 420 // CZW: This is off by default. 398 421 // Position offsets 399 422 { … … 436 459 437 460 #if (defined TESTING && defined ASTROMETRY) 461 // CZW: This is off by default. 438 462 // Double check: all offsets should be zero 439 463 { … … 458 482 if (options->photometry) { 459 483 // Save best matches for future photometry 460 psArray *sourcesBest = options->sources = psArrayAllocEmpty(matches->n); 461 484 psArray *sourcesBest = options->sources = psArrayAllocEmpty(matches->n); 462 485 // XXX something of a hack: require at least 2 detections or the nominated fraction of the max possible 463 486 //int minMatches = PS_MAX(2, fracMatch * num);// Minimum number of matches required 464 487 //MEH - if many poor images, will hit oddity with num fraction. use numGoodImages instead 465 int minMatches = PS_MAX(2, fracMatch * numGoodImages);// Minimum number of matches required 466 467 int good0 = 0; 468 for (int i = 0; i < num; i++) { 469 if (inputMask->data.U8[i]) { 470 continue; 471 } 472 good0 = i; 473 break; 488 int minMatches = PS_MAX(2, fracMatch * numGoodImages);// Minimum number of matches required 489 490 int good0 = 0; 491 for (int i = 0; i < num; i++) { 492 if (inputMask->data.U8[i]) { 493 continue; 474 494 } 475 476 for (int i = 0; i < matches->n; i++) { 477 pmSourceMatch *match = matches->data[i]; // Match of interest 478 if (match->num < minMatches) { 479 continue; 480 } 481 482 // We need to grab a single instance of this source: just take the first available 483 // MEH - if first available is a rejected image, then problem. so take first non-rejected instance above 484 //int image = match->image->data.S32[0]; // Index of image 485 //int index = match->index->data.S32[0]; // Index of source within image 486 int image = match->image->data.S32[good0]; // Index of image 487 int index = match->index->data.S32[good0]; // Index of source within image 488 psArray *sources = sourceLists->data[image]; // Sources for image 489 pmSource *source = sources->data[index]; // Source of interest 490 491 psArrayAdd(sourcesBest, sourcesBest->n, source); 492 } 493 psLogMsg("ppStack", PS_LOG_INFO, "Selected %ld sources for photometry analysis", sourcesBest->n); 494 } 495 495 good0 = i; 496 break; 497 } 498 499 for (int i = 0; i < matches->n; i++) { 500 pmSourceMatch *match = matches->data[i]; // Match of interest 501 if (match->num < minMatches) { 502 continue; 503 } 504 505 // We need to grab a single instance of this source: just take the first available 506 // MEH - if first available is a rejected image, then problem. so take first non-rejected instance above 507 // int image = match->image->data.S32[0]; // Index of image 508 // int index = match->index->data.S32[0]; // Index of source within image 509 int image = match->image->data.S32[good0]; // Index of image 510 int index = match->index->data.S32[good0]; // Index of source within image 511 psArray *sources = sourceLists->data[image]; // Sources for image 512 pmSource *source = sources->data[index]; // Source of interest 513 514 // CZW: Accept the first source for all properties, except for the magnitudes. 515 // We have average magnitudes from relphot, so we should use those 516 pmSource *photsource = matchedSources->data[i]; 517 if ((photsource)&&(isfinite(photsource->psfMag))) { 518 // CZW: photsource is the average relphot mag, which is equal to <m_i + zpIN_j> 519 // (primed are averaged values for this discussion) 520 // Therefore, the correct magnitude for psfMag' is: 521 // psfMag' = (photsource - zpIN_j + magCorr) 522 // apMag - psfMag should be retained, so: 523 // apMag - psfMag = apMag' - psfMag' 524 // apMag' = apMag + psfMag' - psfMag 525 source->apMag = source->apMag + (photsource->psfMag + options->norm->data.F32[image] - zp->data.F32[image] - source->psfMag); 526 source->psfMag = photsource->psfMag + options->norm->data.F32[image] - zp->data.F32[image]; 527 528 psTrace("ppStack", 5, "Best Source %d/%ld @ %f %f %f %f %f %d",i,sourcesBest->n,source->peak->xf,source->peak->yf, 529 source->psfMag, 530 photsource->psfMag + options->norm->data.F32[image] - zp->data.F32[image] , 531 source->psfMagErr,-1); 532 psArrayAdd(sourcesBest, sourcesBest->n, source); 533 } 534 } 535 psLogMsg("ppStack", PS_LOG_INFO, "Selected %ld sources for photometry analysis", sourcesBest->n); 536 537 } 538 psFree(zp); 496 539 psFree(matches); 497 540
Note:
See TracChangeset
for help on using the changeset viewer.
