Changeset 6205 for trunk/psModules/src/imcombine/pmReadoutCombine.c
- Timestamp:
- Jan 26, 2006, 11:10:51 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmReadoutCombine.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmReadoutCombine.c
r5516 r6205 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-11-15 20:09:03$7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-01-26 21:10:50 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 461 461 } 462 462 463 464 465 /** 466 * 467 * The input array fluxLevels consists of Ni vectors, one per mosaic image. 468 * Each vector consists of Nj elements, each a measurement of the input 469 * flat-field image flux levels. All of these vectors must be constructed with 470 * the same number of elements, or the function will return an error. If a chip 471 * is missing from a particular image, that element should be set to NaN. The 472 * vector chipGains supplies initial guesses for the chip gains. If the vector 473 * contains the values 0.0 or NaN for any of the elements, the gain is set to the 474 * mean of the valid values. If the vector length does not match the number of 475 * chips, an warning is raised, all chip gain guesses will be set to 1.0, and the 476 * vector length modified to match the number of chips defined by the supplied 477 * fluxLevels. The sourceFlux input vector must be allocated (not NULL), but the 478 * routine will set the vector length to the number of source images regardless 479 * of the initial state of the vector. All vectors used by this function must be 480 * of type PS_DATA_F64. 481 * 482 483 fluxLevels(i, j): for each flat field image i, this psArray contains a vector 484 with an elemenmt for each chip j. So, fluxLevels(i, j) corresponds to the 485 measured flux M_(i, j) for flat image i, chip j. 486 487 chipGains[]: has j elements, one for each chip. 488 489 490 They have the observed flux levels for each chip of each image. They want to 491 solve for the actual flux levels and the gain of each chip. 492 493 Okay, they want to solve for source fluxes and chip gains. 494 495 496 497 498 499 500 * 501 */ 502 bool pmFlatNormalization( 503 psVector *sourceFlux, 504 psVector *chipGains, 505 psArray *fluxLevels) 506 { 507 PS_ASSERT_PTR_NON_NULL(fluxLevels, false); 508 psS32 numImages = fluxLevels->n; 509 psS32 numChips = ((psVector *) fluxLevels->data[0])->n; 510 for (psS32 i = 0 ; i < numImages ; i++) { 511 psVector *tmpVec = (psVector *) fluxLevels->data[i]; 512 PS_ASSERT_VECTOR_NON_NULL(tmpVec, false); 513 PS_ASSERT_VECTOR_TYPE(tmpVec, PS_TYPE_F64, false); 514 PS_ASSERT_VECTOR_SIZE(tmpVec, numChips, false); 515 } 516 517 // 518 // Ensure that *localChipGains points to a vector of the same length as numImages. 519 // 520 PS_ASSERT_PTR_NON_NULL(chipGains, false); 521 PS_ASSERT_VECTOR_TYPE(chipGains, PS_TYPE_F64, false); 522 psVector *localChipGains = chipGains; 523 if (numChips != chipGains->n) { 524 psLogMsg(__func__, PS_LOG_WARN, "WARNING: the chipGains vector length does not match the number of chips.\n"); 525 localChipGains = psVectorAlloc(numChips, PS_TYPE_F64); 526 psBool rc = psVectorInit(localChipGains, 1.0); 527 if (rc == false) { 528 printf("XXX: gen error\n"); 529 } 530 } 531 532 // 533 // If the chipGains vector contains the values 0.0 or NaN for any of the elements, 534 // the gain is set to the mean of the valid values. 535 // 536 psBool meanFlag = false; 537 psVector *chipGainsMask = psVectorAlloc(chipGains->n, PS_TYPE_U8); 538 for (psS32 i = 0 ; i < chipGains->n ; i++) { 539 if ((fabs(chipGains->data.F64[i]) < FLT_EPSILON) || 540 (isnan(chipGains->data.F64[i]))) { 541 chipGainsMask->data.U8[i] = 1; 542 meanFlag = true; 543 } 544 } 545 // Must calculate the mean. 546 if (meanFlag == true) { 547 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 548 stats = psVectorStats(stats, chipGains, NULL, chipGainsMask, 1); 549 if (stats == NULL) { 550 printf("XXX: gen error\n"); 551 } 552 psF64 mean; 553 psBool rc = p_psGetStatValue(stats, &mean); 554 if (rc == false) { 555 printf("XXX: gen error\n"); 556 } 557 // Set the gain to this mean for chips with a gain of 0.0 or NAN 558 559 for (psS32 i = 0 ; i < chipGains->n ; i++) { 560 if ((fabs(chipGains->data.F64[i]) < FLT_EPSILON) || 561 (isnan(chipGains->data.F64[i]))) { 562 chipGains->data.F64[i] = mean; 563 } 564 } 565 } 566 567 // 568 // Assert that sourceFlux is non-NULL, correct type, correct size. 569 // 570 PS_ASSERT_PTR_NON_NULL(sourceFlux, false); 571 PS_ASSERT_VECTOR_TYPE(sourceFlux, PS_TYPE_F64, false); 572 psVectorRealloc(sourceFlux, numImages); 573 574 575 576 577 578 579 psFree(psVector); 580 if (numImages != chipGains->n) { 581 psFree(localChipGains); 582 } 583 }
Note:
See TracChangeset
for help on using the changeset viewer.
