- Timestamp:
- Oct 23, 2021, 1:48:02 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmPattern.c
r41851 r41856 160 160 161 161 162 // XXX allow user choice of binned vs unbinned analysis? 162 163 bool pmPatternRow(pmReadout *ro, int order, int iter, float rej, float thresh, 163 164 psStatsOptions clipMean, psStatsOptions clipStdev, 164 165 psImageMaskType maskVal, psImageMaskType maskBad) { 165 166 166 bool status = pmPatternRowBinned(ro, order, iter, rej, thresh, clipMean, clipStdev, maskVal, maskBad); 167 // bool status = pmPatternRowUnbinned(ro, order, iter, rej, thresh, clipMean, clipStdev, maskVal, maskBad); 168 return status; 167 bool status = false; 168 if (true) { 169 status = pmPatternRowBinned(ro, order, iter, rej, thresh, clipMean, clipStdev, maskVal, maskBad); 170 } else { 171 status = pmPatternRowUnbinned(ro, order, iter, rej, thresh, clipMean, clipStdev, maskVal, maskBad); 172 } 173 return status; 169 174 } 170 175 171 // USE_BACKGROUND_STDEV: if true, the analysis will use the measured robust stdev to clip the out-of-range pixles172 // if false, the stdev will be estimated based on the Poisson statistics of the median (sky level).176 // USE_BACKGROUND_STDEV: if TRUE, the analysis will use the measured robust stdev to clip the out-of-range pixles 177 // if FALSE, the stdev will be estimated based on the Poisson statistics of the median (sky level). 173 178 # define USE_BACKGROUND_STDEV 0 174 179 … … 184 189 PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, false); 185 190 191 bool mdok; // Status of MD lookup 192 193 pmCell *cell = ro->parent; 194 pmChip *chip = cell->parent; 195 const char *chipName = psMetadataLookupStr(&mdok, chip->concepts, "CHIP.NAME"); // Name of chip 196 const char *cellName = psMetadataLookupStr(&mdok, cell->concepts, "CELL.NAME"); // Name of cell 197 186 198 psImage *image = ro->image; // Image to correct 187 199 psImage *mask = ro->mask; // Mask for image … … 191 203 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 192 204 if (!psImageBackground(stats, NULL, ro->image, ro->mask, maskVal, rng)) { 193 psWarning("Unable to calculate statistics on readout; masking entire readout.");205 psWarning("Unable to calculate statistics on readout; skipping pattern correction for %s, %s.", chipName, cellName); 194 206 psErrorClear(); 195 207 psFree(stats); 196 208 psFree(rng); 197 psImageInit(image, NAN);198 if (mask) {199 psBinaryOp(mask, mask, "|", psScalarAlloc(maskBad, PS_TYPE_IMAGE_MASK));200 }201 if (ro->variance) {202 psImageInit(image, NAN);203 }204 209 return true; 205 210 } … … 226 231 // so smaller by a factor of 1.4 than what we predict, which is not very large 227 232 228 # define READNOISE 10 233 // find the nominal signal amplitude (check the ghost and/or crosstalk recipe file) 234 float nominalAmplitude = psMetadataLookupF32 (&mdok, cell->analysis, "PTN.ROW.AMP"); 235 if (!mdok) nominalAmplitude = 20; // XXX EAM : somewhat arbitrary number 236 // If we cannot determine the nominal amplitude, we fall-back on the worst case 237 238 // XXX retrieve noise and gain from 'concepts' if possible 239 # define READNOISE 10 /* arbitrary number */ 229 240 float sigma = sqrt(stats->robustMedian + PS_SQR(READNOISE)); 230 float lower = stats->robustMedian - thresh * sigma; // Lower bound for data 231 float upper = stats->robustMedian + thresh * sigma; // Upper bound for data 241 float delta = PS_MIN (thresh * sigma, 2*nominalAmplitude); 242 float lower = stats->robustMedian - delta; // Lower bound for data 243 float upper = stats->robustMedian + delta; // Upper bound for data 232 244 float background = stats->robustMedian; 245 246 // if the noise from the background is too large 247 float significance = nominalAmplitude / sigma; 248 249 // XXX EAM : arbitrary number 250 if (isfinite(nominalAmplitude) && (significance < 1.0/6.0)) { 251 psLogMsg("ppImage", PS_LOG_INFO, "Skipping row pattern correction for %s, %s, stats: %f - %f - %f : %f %f %f\n", chipName, cellName, lower, background, upper, sigma, nominalAmplitude, significance); 252 return true; 253 } 254 fprintf (stderr, "correcting pattern row background %s: %f - %f - %f : %f %f %f\n", cellName, lower, background, upper, sigma, nominalAmplitude, significance); 255 psLogMsg("ppImage", PS_LOG_INFO, "Performing row pattern correction for %s, %s, stats: %f - %f - %f : %f %f %f\n", chipName, cellName, lower, background, upper, sigma, nominalAmplitude, significance); 233 256 # endif 234 257 235 pmCell *cell = ro->parent;236 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell237 fprintf (stderr, "pattern row background %s: %f - %f - %f\n", cellName,lower, background, upper);238 239 240 // XXX add code to skip fit if background stdev is large compared to expected signal241 // XXX add a constraint to the fit so the |amplitude| < x (x ~ 20 - 25)242 243 258 psFree(stats); 244 259 psFree(rng); … … 458 473 } 459 474 460 # define NPIX 31475 # define NPIX 15 461 476 462 477 // bin by NPIX in the x-direction to reduce the number of calculations needed to measure … … 473 488 PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, false); 474 489 490 bool mdok; // Status of MD lookup 491 492 pmCell *cell = ro->parent; 493 pmChip *chip = cell->parent; 494 const char *chipName = psMetadataLookupStr(&mdok, chip->concepts, "CHIP.NAME"); // Name of chip 495 const char *cellName = psMetadataLookupStr(&mdok, cell->concepts, "CELL.NAME"); // Name of cell 496 475 497 psImage *image = ro->image; // Image to correct 476 498 psImage *mask = ro->mask; // Mask for image 477 499 int numCols = image->numCols, numRows = image->numRows; // Size of image 478 500 479 // use the background and typical amplitude value to choose to correct or not480 // pmCell *cell = ro->parent;481 482 501 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 483 502 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 484 503 if (!psImageBackground(stats, NULL, ro->image, ro->mask, maskVal, rng)) { 485 psWarning("Unable to calculate statistics on readout; skipping pattern correction.");504 psWarning("Unable to calculate statistics on readout; skipping pattern correction for %s, %s.", chipName, cellName); 486 505 psErrorClear(); 487 506 psFree(stats); … … 525 544 // so smaller by a factor of 1.4 than what we predict, which is not very large 526 545 546 // find the nominal signal amplitude (check the ghost and/or crosstalk recipe file) 547 float nominalAmplitude = psMetadataLookupF32 (&mdok, cell->analysis, "PTN.ROW.AMP"); 548 if (!mdok) nominalAmplitude = 20; // XXX EAM : somewhat arbitrary number 549 if (!isfinite(nominalAmplitude)) nominalAmplitude = 20; // XXX EAM : somewhat arbitrary number 550 // If we cannot determine the nominal amplitude, we fall-back on the worst case 551 527 552 // retrieve noise and gain from 'concepts' if possible 528 553 # define READNOISE 10 /* arbitrary number */ 529 554 float sigma = sqrt(stats->robustMedian + PS_SQR(READNOISE)); 530 float delta = PS_MIN (thresh * sigma, 40); // XXX EAM : arbitrary number555 float delta = PS_MIN (thresh * sigma, 5*nominalAmplitude); 531 556 float lower = stats->robustMedian - delta; // Lower bound for data 532 557 float upper = stats->robustMedian + delta; // Upper bound for data 533 558 float background = stats->robustMedian; 534 559 535 // find the nominal signal amplitude (check the ghost and/or crosstalk recipe file)536 float nominalAmplitude = 20; // XXX EAM : arbitrary number537 538 560 // if the noise from the background is too large 539 561 float significance = nominalAmplitude / sigma; 540 if (significance < 0.5) return true; // XXX EAM : arbitrary number 541 542 pmCell *cell = ro->parent; 543 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell 544 fprintf (stderr, "pattern row background %s: %f - %f - %f\n", cellName, lower, background, upper); 562 563 // XXX EAM : arbitrary number 564 if (isfinite(nominalAmplitude) && (significance < 1.0/6.0)) { 565 psLogMsg("ppImage", PS_LOG_INFO, "Skipping row pattern correction for %s, %s, stats: %f - %f - %f : %f %f %f\n", chipName, cellName, lower, background, upper, sigma, nominalAmplitude, significance); 566 psFree(stats); 567 psFree(rng); 568 return true; 569 } 570 psLogMsg("ppImage", PS_LOG_INFO, "Performing row pattern correction for %s, %s, stats: %f - %f - %f : %f %f %f\n", chipName, cellName, lower, background, upper, sigma, nominalAmplitude, significance); 545 571 # endif 546 572 … … 643 669 } 644 670 645 // XXX how much time is spent in the fitting? to test: make this always true671 // If not enough points are valid, skip 646 672 if (num < validNmin) { 647 // Not enough points to fit648 // EAM 20211011 : we used to mask rows which could not be fit, but this is excessive. just skip.649 // patternMaskRow(ro, y, maskBad);650 673 // Ignore this row in our subsequent fits, because the fit failed. 651 674 yaxisMask->data.PS_TYPE_VECTOR_MASK_DATA[y] = 0xFF; … … 656 679 psWarning("Unable to fit polynomial to row %d", y); 657 680 psErrorClear(); 658 // EAM 20211011 : we used to mask rows which could not be fit, but this is excessive. just skip.659 // patternMaskRow(ro, y, maskBad);660 681 // Ignore this row in our subsequent fits, because the fit failed. 661 682 yaxisMask->data.PS_TYPE_VECTOR_MASK_DATA[y] = 0xFF; … … 672 693 psWarning("Unable to evaluate polynomial for row %d", y); 673 694 psErrorClear(); 674 // EAM 20211011 : we used to mask rows which could not be fit, but this is excessive. just skip.675 // patternMaskRow(ro, y, maskBad);676 695 yaxisMask->data.PS_TYPE_VECTOR_MASK_DATA[y] = 0xFF; 677 696 continue;
Note:
See TracChangeset
for help on using the changeset viewer.
