Changeset 41894 for trunk/ppImage/src/ppImageDetrendPattern.c
- Timestamp:
- Nov 4, 2021, 6:07:14 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageDetrendPattern.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImageDetrendPattern.c
r41265 r41894 14 14 15 15 bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView, 16 constppImageOptions *options)16 ppImageOptions *options) 17 17 { 18 18 pmCell *cell = NULL; … … 31 31 // CELLS in the format:CHIPS metadata table) 32 32 33 // New 2021 October : During ppImageParseCamera, we have loaded a file identified by 34 // PPIMAGE.PATTERN.ROW.AMP on config->files. This file contains a collection of FITS 35 // tables, one per chip. Each table lists the typical bias-drift amplitude for cell, 36 // measured from a collection of dark images. These values are passed (via 37 // cell->analysis) to pmPatternRow which choosed to apply the correction based on the 38 // ratio of the poisson noise due to the median background (+ read noise) and the 39 // typical amplitude. Tests show that if the amplitude / noise < 1/6, then the 40 // row-by-row variations are insignificant. 41 33 42 // We also check the chip header for the boolean 'PTRN_ROW' : if this is true, we have 34 43 // already applied this correct to this data, so we simply skip the correction for this … … 52 61 53 62 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT"); 63 64 // grab the PATTERN.ROW.AMP file 65 pmFPAfile *PRAfile = psMetadataLookupPtr (NULL, config->files, "PPIMAGE.PATTERN.ROW.AMP"); 66 if (!PRAfile) { 67 psLogMsg("ppImage", PS_LOG_INFO, "Pattern Row Amplitude file not found, applying to all (with limits from ROW.SUBSET) "); 68 } 69 54 70 pmFPAview *view = pmFPAviewAlloc(0); // View for local processing 55 71 *view = *inputView; … … 75 91 } 76 92 93 // grab the corresponding cell 94 if (PRAfile) { 95 pmCell *PRAcell = pmFPAviewThisCell (view, PRAfile->fpa); 96 psAssert (PRAcell, "found Pattern Row Amplitude file, but not cell?"); 97 98 // find the nominal signal amplitude (check the ghost and/or crosstalk recipe file) 99 float amplitude = psMetadataLookupF32 (&status, PRAcell->analysis, "PTN.ROW.AMP"); 100 if (!status) amplitude = NAN; 101 102 // put the value on the science cell 103 psMetadataAddF32 (cell->analysis, PS_LIST_TAIL, "PTN.ROW.AMP", PS_META_REPLACE, "", amplitude); 104 } 105 77 106 bool doPattern = false; 78 107 if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.ROW.SUBSET")) { 79 108 ESCAPE(false, "Unable to determine whether row pattern matching should be applied."); 80 109 } 81 //psWarning ("Row: %d\n", doPattern);82 110 if (!doPattern) continue; 83 111 84 // A very detailed log message. 85 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 86 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); 87 psLogMsg("ppImage", PS_LOG_INFO, "Performing row pattern correction for %s, %s\n", chipName, cellName); 88 89 // process each of the readouts 90 pmReadout *readout; // Readout from cell 91 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 92 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 93 ESCAPE(false, "load failure for Readout"); 94 } 95 if (!readout->data_exists) { 96 continue; 97 } 98 99 // Perform pattern correction 100 if (!pmPatternRow(readout, options->patternRowOrder, options->patternRowIter, 101 options->patternRowRej, options->patternRowThresh, options->patternRowMean, 102 options->patternRowStdev, options->maskValue, options->darkMask)) { 103 psFree(view); 104 return(false); 105 } 106 } 107 108 } 112 // switch to test threaded version 113 if (true) { 114 // I need to allocate a view here to be freed by the 115 // called function below. 116 pmFPAview *myView = pmFPAviewAlloc(0); // View for local processing 117 *myView = *view; 118 119 // allocate a job, construct the arguments for this job 120 psThreadJob *job = psThreadJobAlloc("PPIMAGE_PATTERN_ROW_CELL"); 121 psArrayAdd(job->args, 1, config); 122 psArrayAdd(job->args, 1, input->fpa); 123 psArrayAdd(job->args, 1, chip); 124 psArrayAdd(job->args, 1, cell); 125 psArrayAdd(job->args, 1, myView); 126 psArrayAdd(job->args, 1, options); 127 if (!psThreadJobAddPending(job)) { 128 return false; 129 } 130 } else { 131 // bump the counter since it must be freed by the function below. 132 psMemIncrRefCounter (view); // View for local processing 133 if (!ppImageDetrendPatternApplyCell (config, input->fpa, chip, cell, view, options)) { 134 return false; 135 } 136 } 137 138 } 139 140 // wait here for the threaded jobs to finish 141 // if no threads are allocated, this 142 if (!psThreadPoolWait(true, true)) { 143 psError(PS_ERR_UNKNOWN, false, "Unable to apply bias correction."); 144 return false; 145 } 146 109 147 psMetadataAddBool(hdu->header, PS_LIST_TAIL, "PTRN_ROW",PS_META_REPLACE,"PATTERN.ROW correction applied",true); 110 148 psFree(view); … … 266 304 return false; 267 305 } 306 307 // thread safety : 308 bool ppImageDetrendPatternApplyCell (pmConfig *config, pmFPA *fpa, pmChip *chip, pmCell *cell, pmFPAview *view, ppImageOptions *options) { 309 310 // process each of the readouts 311 pmReadout *readout; // Readout from cell 312 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 313 if (!readout->data_exists) { 314 continue; 315 } 316 317 // Perform pattern correction 318 if (!pmPatternRow(readout, options->patternRowOrder, options->patternRowIter, 319 options->patternRowRej, options->patternRowThresh, options->patternRowMean, 320 options->patternRowStdev, options->maskValue, options->darkMask)) { 321 psFree (view); 322 return false; 323 } 324 } 325 psFree (view); // supplied view must be freeable 326 return true; 327 } 328
Note:
See TracChangeset
for help on using the changeset viewer.
