Changeset 41856 for branches/eam_branches/ipp-dev-20210817/psModules
- Timestamp:
- Oct 23, 2021, 1:48:02 PM (5 years ago)
- Location:
- branches/eam_branches/ipp-dev-20210817/psModules/src
- Files:
-
- 9 edited
-
camera/pmFPAfile.c (modified) (2 diffs)
-
camera/pmFPAfile.h (modified) (1 diff)
-
camera/pmFPAfileFitsIO.c (modified) (1 diff)
-
camera/pmFPAfileIO.c (modified) (8 diffs)
-
detrend/pmDetrendDB.c (modified) (1 diff)
-
detrend/pmDetrendDB.h (modified) (1 diff)
-
detrend/pmPattern.c (modified) (10 diffs)
-
detrend/pmPatternIO.c (modified) (6 diffs)
-
detrend/pmPatternIO.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-dev-20210817/psModules/src/camera/pmFPAfile.c
r41535 r41856 551 551 if (!strcasecmp(type, "KH.CORRECT")) { 552 552 return PM_FPA_FILE_KH_CORRECT; 553 } 554 if (!strcasecmp(type, "PATTERN.ROW.AMP")) { 555 return PM_FPA_FILE_PATTERN_ROW_AMP; 553 556 } 554 557 if (!strcasecmp(type, "SUBKERNEL")) { … … 606 609 case PM_FPA_FILE_KH_CORRECT: 607 610 return ("KH.CORRECT"); 611 case PM_FPA_FILE_PATTERN_ROW_AMP: 612 return ("PATTERN.ROW.AMP"); 608 613 case PM_FPA_FILE_SUBKERNEL: 609 614 return ("SUBKERNEL"); -
branches/eam_branches/ipp-dev-20210817/psModules/src/camera/pmFPAfile.h
r36834 r41856 52 52 PM_FPA_FILE_SRCTEXT, 53 53 PM_FPA_FILE_PATTERN, 54 PM_FPA_FILE_PATTERN_ROW_AMP, 54 55 PM_FPA_FILE_LINEARITY, 55 56 PM_FPA_FILE_EXPNUM, -
branches/eam_branches/ipp-dev-20210817/psModules/src/camera/pmFPAfileFitsIO.c
r36834 r41856 152 152 case PM_FPA_FILE_ASTROM_REFSTARS: 153 153 case PM_FPA_FILE_KH_CORRECT: 154 case PM_FPA_FILE_PATTERN_ROW_AMP: 154 155 { 155 156 pmHDU *hdu = pmFPAviewThisHDU(view, fpa); -
branches/eam_branches/ipp-dev-20210817/psModules/src/camera/pmFPAfileIO.c
r41843 r41856 253 253 status = pmPatternRead(view, file, config); 254 254 break; 255 case PM_FPA_FILE_PATTERN_ROW_AMP: 256 status = pmPatternRowAmpRead(view, file, config); 257 break; 255 258 case PM_FPA_FILE_SX: 256 259 case PM_FPA_FILE_RAW: … … 363 366 case PM_FPA_FILE_ASTROM_REFSTARS: 364 367 case PM_FPA_FILE_KH_CORRECT: 368 case PM_FPA_FILE_PATTERN_ROW_AMP: 365 369 case PM_FPA_FILE_JPEG: 366 370 case PM_FPA_FILE_KAPA: … … 451 455 return true; 452 456 } 457 if (file->type == PM_FPA_FILE_PATTERN_ROW_AMP) { 458 psTrace("psModules.camera", 6, "skip write for %s, no write function defined", file->name); 459 return true; 460 } 453 461 454 462 // open the file if not yet opened … … 547 555 case PM_FPA_FILE_KH_CORRECT: 548 556 psError(PS_ERR_IO, true, "cannot write type KH.CORRECT (%s)", file->name); 557 break; 558 559 case PM_FPA_FILE_PATTERN_ROW_AMP: 560 psError(PS_ERR_IO, true, "cannot write type PATTERN.ROW.AMP (%s)", file->name); 549 561 break; 550 562 … … 624 636 case PM_FPA_FILE_ASTROM_REFSTARS: 625 637 case PM_FPA_FILE_KH_CORRECT: 638 case PM_FPA_FILE_PATTERN_ROW_AMP: 626 639 case PM_FPA_FILE_LINEARITY: 627 640 case PM_FPA_FILE_EXPNUM: … … 702 715 case PM_FPA_FILE_ASTROM_REFSTARS: 703 716 case PM_FPA_FILE_KH_CORRECT: 717 case PM_FPA_FILE_PATTERN_ROW_AMP: 704 718 case PM_FPA_FILE_EXPNUM: 705 719 psTrace ("psModules.camera", 6, "NOT freeing %s (%s) : save for further analysis\n", file->filename, file->name); … … 865 879 case PM_FPA_FILE_ASTROM_REFSTARS: 866 880 case PM_FPA_FILE_KH_CORRECT: 881 case PM_FPA_FILE_PATTERN_ROW_AMP: 867 882 case PM_FPA_FILE_LINEARITY: 868 883 case PM_FPA_FILE_EXPNUM: … … 1069 1084 case PM_FPA_FILE_ASTROM_MODEL: 1070 1085 case PM_FPA_FILE_KH_CORRECT: 1086 case PM_FPA_FILE_PATTERN_ROW_AMP: 1071 1087 case PM_FPA_FILE_SX: 1072 1088 case PM_FPA_FILE_RAW: -
branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmDetrendDB.c
r38038 r41856 112 112 DETREND_STRING_CASE(AUXMASK); 113 113 DETREND_STRING_CASE(KH_CORRECT); 114 DETREND_STRING_CASE(PATTERN_ROW_AMP); 114 115 default: 115 116 return NULL; -
branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmDetrendDB.h
r36834 r41856 41 41 PM_DETREND_TYPE_AUXMASK, 42 42 PM_DETREND_TYPE_KH_CORRECT, 43 PM_DETREND_TYPE_PATTERN_ROW_AMP, 43 44 } pmDetrendType; 44 45 -
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; -
branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmPatternIO.c
r41851 r41856 8 8 #include "pmFPAview.h" 9 9 #include "pmFPAfile.h" 10 #include "pmFPAUtils.h" 10 11 #include "pmFPAfileFitsIO.h" 11 12 #include "pmFPAHeader.h" … … 455 456 /**************** PatternRowAmp(litude) I/O *************************/ 456 457 457 # if (0) 458 /********************* Read Data functions *****************************/ 459 460 bool pmPatternRowAmpReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 458 bool pmPatternRowAmpRead (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 461 459 { 462 460 // read the full model in one pass: require the level to be FPA … … 499 497 } 500 498 499 int nGood = 0; 500 int nTotal = 0; 501 501 while (haveData) { 502 502 … … 511 511 // determine the chip: 512 512 char *extname = psMetadataLookupStr (&status, header, "EXTNAME"); 513 psLogMsg ("psModules.detrend", 4, "read %ld rows from Pattern Row Amplitude file, extname %s\n", model->n, extname); 513 psLogMsg ("psModules.detrend", 8, "read %ld rows from Pattern Row Amplitude file, extname %s\n", model->n, extname); 514 nTotal += model->n; 514 515 515 516 // I expect to find a name of the form: chipName.ptn (eg, XY01.ptn) 516 517 // where chipName like 'XY01' 517 psAssert (strlen(extname) == 10, "invalid extension %s", extname);518 psAssert (strlen(extname) == 8, "invalid extension %s", extname); 518 519 psAssert (extname[5] == 'p', "invalid extension %s", extname); 519 520 psAssert (extname[6] == 't', "invalid extension %s", extname); … … 530 531 for (int i = 0; i < model->n; i++) { 531 532 psMetadata *row = model->data[i]; 532 char *cellName = psMetadataLookupStr(&status, row, "cellname"); 533 float *amplitude = psMetadataLookupF32(&status, row, "medianValue"); 533 534 char *cellName = psMetadataLookupStr(&status, row, "CELL_NAME"); 535 if (!cellName) continue; 536 537 float amplitude = psMetadataLookupF32(&status, row, "VALUE_MEDIAN"); 534 538 535 539 int cellNumber = pmChipFindCell (chip, cellName); 536 pmCell *cell = chip->data[cellNumber]; 540 pmCell *cell = chip->cells->data[cellNumber]; 541 if (!cell) continue; 537 542 538 543 psMetadataAddF32 (cell->analysis, PS_LIST_TAIL, "PTN.ROW.AMP", PS_META_REPLACE, "", amplitude); 544 nGood ++; 539 545 } 546 540 547 psFree (model); 541 548 psFree (header); … … 544 551 haveData = psFitsMoveExtNum (file->fits, 1, true); 545 552 } 546 547 return true; 548 } 549 # endif 553 psLogMsg ("psModules.detrend", 4, "read %d of %d rows from Pattern Row Amplitude file\n", nGood, nTotal); 554 555 return true; 556 } -
branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmPatternIO.h
r26893 r41856 35 35 ); 36 36 37 38 bool pmPatternRowAmpRead (const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 39 bool pmPatternRowAmpReadFPA (pmFPAfile *file); 40 bool pmPatternRowAmpReadChips (pmFPAfile *file); 41 37 42 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
