Changeset 26895
- Timestamp:
- Feb 10, 2010, 7:38:09 PM (16 years ago)
- Location:
- trunk/ppImage/src
- Files:
-
- 8 edited
-
ppImage.h (modified) (2 diffs)
-
ppImageBurntoolMask.c (modified) (5 diffs)
-
ppImageDetrendFringe.c (modified) (15 diffs)
-
ppImageDetrendPattern.c (modified) (2 diffs)
-
ppImageLoop.c (modified) (1 diff)
-
ppImageOptions.c (modified) (5 diffs)
-
ppImageParseCamera.c (modified) (2 diffs)
-
ppImageReplaceBackground.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImage.h
r25930 r26895 38 38 bool doShutter; // Shutter correction 39 39 bool doFlat; // Flat-field normalisation 40 bool doPattern; // Pattern noise subtraction 40 bool doPatternRow; // Row pattern correction 41 bool doPatternCell; // Cell pattern correction 41 42 bool doFringe; // Fringe subtraction 42 43 bool doPhotom; // Source identification and photometry … … 95 96 float fringeKeep; // Fringe keep fraction 96 97 97 // Pattern noise subtraction 98 int patternOrder; // Polynomial order 99 int patternIter; // Clipping iterations 100 float patternRej; // Clipping threshold 101 float patternThresh; // Ignore threshold 102 psStatsOptions patternMean; // Statistic for mean 103 psStatsOptions patternStdev; // Statistic for stdev 98 // Pattern correction 99 int patternRowOrder; // Polynomial order 100 int patternRowIter; // Clipping iterations 101 float patternRowRej; // Clipping threshold 102 float patternRowThresh; // Ignore threshold 103 psStatsOptions patternRowMean; // Statistic for mean 104 psStatsOptions patternRowStdev; // Statistic for stdev 105 psStatsOptions patternCellBG; // statistic for background 106 psStatsOptions patternCellMean; // Statistic for mean 104 107 105 108 int remnanceSize; // Size for remnance detection -
trunk/ppImage/src/ppImageBurntoolMask.c
r25299 r26895 3 3 #endif 4 4 5 /* #define PPIMAGE_BURNTOOL_DEBUG 1 */ 5 #define PPIMAGE_BURNTOOL_DEBUG 0 6 6 7 7 #include "ppImage.h" … … 23 23 return(false); 24 24 } 25 long Nrows = psFitsTableSize(fits); 25 long Nrows = psFitsTableSize(fits); 26 26 27 27 long row = 0; … … 33 33 psImage *image = mask->mask; 34 34 35 35 36 36 /* Set the maskValue from the recipes. */ 37 37 psImageMaskType maskValue = options->burntoolMask; 38 #if defPPIMAGE_BURNTOOL_DEBUG38 #if PPIMAGE_BURNTOOL_DEBUG 39 39 psLogMsg("ppImageBurntoolMask", 4, "Status: %ld %d\n",Nrows,maskValue); 40 40 #endif … … 47 47 48 48 if (psMetadataLookupS32(&status,rowMD,"cell") == burntool_cell) { 49 if (((options->burntoolTrails & 0x01)&&(psMetadataLookupS32(&status,rowMD," nfit") == 0))||50 ((options->burntoolTrails & 0x02)&&(psMetadataLookupS32(&status,rowMD,"up") == 1))||51 ((options->burntoolTrails & 0x04)&&(psMetadataLookupS32(&status,rowMD,"up") == 0))) {52 /* If the fit fails, burntool reports zero here. This53 signifies that it expected to see a trail (else why54 fit) but did not find it when it attempted to55 correct. */56 #if defPPIMAGE_BURNTOOL_DEBUG57 psLogMsg ("ppImageBurntoolMask", 4, "Masking! %d (%d %d %d) %d %d",58 psMetadataLookupS32(&status,rowMD,"cell"),59 ((options->burntoolTrails & 0x0001)&&(psMetadataLookupS32(&status,rowMD,"nfit") == 0)),60 ((options->burntoolTrails & 0x02)&&(psMetadataLookupS32(&status,rowMD,"up") == 1)),61 ((options->burntoolTrails & 0x04)&&(psMetadataLookupS32(&status,rowMD,"up") == 0)),62 options->burntoolTrails,63 maskValue64 );49 if (((options->burntoolTrails & 0x01)&&(psMetadataLookupS32(&status,rowMD,"func") == 4))|| 50 (((options->burntoolTrails & 0x02)&&(psMetadataLookupS32(&status,rowMD,"up") == 1))|| 51 ((options->burntoolTrails & 0x04)&&(psMetadataLookupS32(&status,rowMD,"up") == 0)))) { 52 /* If the fit fails, burntool reports zero here. This 53 signifies that it expected to see a trail (else why 54 fit) but did not find it when it attempted to 55 correct. */ 56 #if PPIMAGE_BURNTOOL_DEBUG 57 psLogMsg ("ppImageBurntoolMask", 4, "Masking! %d (%d %d %d) %d %d", 58 psMetadataLookupS32(&status,rowMD,"cell"), 59 ((options->burntoolTrails & 0x0001)&&(psMetadataLookupS32(&status,rowMD,"nfit") == 0)), 60 ((options->burntoolTrails & 0x02)&&(psMetadataLookupS32(&status,rowMD,"up") == 1)), 61 ((options->burntoolTrails & 0x04)&&(psMetadataLookupS32(&status,rowMD,"up") == 0)), 62 options->burntoolTrails, 63 maskValue 64 ); 65 65 #endif 66 for (int i = psMetadataLookupS32(&status,rowMD,"sxfit");67 i <= psMetadataLookupS32(&status,rowMD,"exfit");68 i++) {66 for (int i = psMetadataLookupS32(&status,rowMD,"sxfit"); 67 i <= psMetadataLookupS32(&status,rowMD,"exfit"); 68 i++) { 69 69 70 if (psMetadataLookupS32(&status,rowMD,"up") == 0) {71 for (int j = 0; j <= psMetadataLookupS32(&status,rowMD,"y1p"); j++) {72 /* #ifdef PPIMAGE_BURNTOOL_DEBUG */ 73 /* psLogMsg("ppImageBurntoolMask", 4, "Noisy!: %d %d %d %d\n", */ 74 /* i,j,image->data.PS_TYPE_IMAGE_MASK_DATA[j][i],maskValue); */ 75 /* #endif */ 76 image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue;77 }78 }79 else {80 for (int j = psMetadataLookupS32(&status,rowMD,"y1m"); j < image->numRows ; j++) {81 /* #ifdef PPIMAGE_BURNTOOL_DEBUG */ 82 /* psLogMsg("ppImageBurntoolMask", 4, "Noisy!: %d %d %d %d\n", */ 83 /* i,j,image->data.PS_TYPE_IMAGE_MASK_DATA[j][i],maskValue); */ 84 /* #endif */ 85 image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue;86 }87 }88 }70 if (psMetadataLookupS32(&status,rowMD,"up") == 0) { 71 for (int j = 0; j <= psMetadataLookupS32(&status,rowMD,"y1p"); j++) { 72 #if PPIMAGE_BURNTOOL_DEBUG 73 psLogMsg("ppImageBurntoolMask", 4, "Noisy!: %d %d %d %d\n", 74 i,j,image->data.PS_TYPE_IMAGE_MASK_DATA[j][i],maskValue); 75 #endif 76 image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue; 77 } 78 } 79 else { 80 for (int j = psMetadataLookupS32(&status,rowMD,"y1m"); j < image->numRows ; j++) { 81 #if PPIMAGE_BURNTOOL_DEBUG 82 psLogMsg("ppImageBurntoolMask", 4, "Noisy!: %d %d %d %d\n", 83 i,j,image->data.PS_TYPE_IMAGE_MASK_DATA[j][i],maskValue); 84 #endif 85 image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskValue; 86 } 87 } 88 } 89 89 90 90 } … … 95 95 return(status); 96 96 } 97 98 99 100 -
trunk/ppImage/src/ppImageDetrendFringe.c
r25930 r26895 14 14 psArray *references = psMemIncrRefCounter(psMetadataLookupPtr(NULL, fringe->analysis, "FRINGE.MEASUREMENTS")); 15 15 if (!references) { 16 psError(PS_ERR_IO, false, "Unable to find fringe references.\n");17 return false;16 psError(PS_ERR_IO, false, "Unable to find fringe references.\n"); 17 return false; 18 18 } 19 19 … … 40 40 char *scienceFringes = NULL; 41 41 if (isResidual) { 42 scienceFringes = psStringCopy ("FRINGE.RESIDUALS");42 scienceFringes = psStringCopy ("FRINGE.RESIDUALS"); 43 43 } else { 44 scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");44 scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS"); 45 45 } 46 46 … … 85 85 psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return 86 86 int video_cell_zero = 0; 87 87 88 88 for (int i = 0; i < cells->n; i++) { 89 89 fringes->data[i] = NULL; … … 91 91 pmCell *cell = cells->data[i]; // Cell of interest 92 92 93 psTrace("psModules.detrend",7,"Readouts: Cell %d chip: %ld\n",i,cell->readouts->n);94 // XXX for now, skip the video cells (cell->readouts->n > 1)95 // CZW: This mess creates a fake set of fringe stats by stealing the previous one.96 // We let the fitting code know that this is all lies by scaling the weights by a crazy amount.97 98 if ( (cell->readouts->n > 1) ) {99 psTrace("psModules.detrend",7,"Should be skipping scichip: %d\n",i);100 psWarning ("Skipping Video Cell (%d) for ppImageDetrendFringe.c:getFringes", i);101 102 if (i == 0) {103 video_cell_zero = 1;104 }105 else {106 pmFringeStats *prevFringe = fringes->data[i-1];107 pmFringeStats *fringe = pmFringeStatsAlloc(prevFringe->regions);108 for (int j = 0; j < fringe->regions->nRequested; j++) {109 fringe->f->data.F32[j] = prevFringe->f->data.F32[j];110 fringe->df->data.F32[j] = prevFringe->df->data.F32[j] / 1e6;111 }112 fringes->data[i] = fringe;113 }114 115 continue;116 }117 93 psTrace("psModules.detrend",7,"Readouts: Cell %d chip: %ld\n",i,cell->readouts->n); 94 // XXX for now, skip the video cells (cell->readouts->n > 1) 95 // CZW: This mess creates a fake set of fringe stats by stealing the previous one. 96 // We let the fitting code know that this is all lies by scaling the weights by a crazy amount. 97 98 if ( (cell->readouts->n > 1) ) { 99 psTrace("psModules.detrend",7,"Should be skipping scichip: %d\n",i); 100 psWarning ("Skipping Video Cell (%d) for ppImageDetrendFringe.c:getFringes", i); 101 102 if (i == 0) { 103 video_cell_zero = 1; 104 } 105 else { 106 pmFringeStats *prevFringe = fringes->data[i-1]; 107 pmFringeStats *fringe = pmFringeStatsAlloc(prevFringe->regions); 108 for (int j = 0; j < fringe->regions->nRequested; j++) { 109 fringe->f->data.F32[j] = prevFringe->f->data.F32[j]; 110 fringe->df->data.F32[j] = prevFringe->df->data.F32[j] / 1e6; 111 } 112 fringes->data[i] = fringe; 113 } 114 115 continue; 116 } 117 118 118 fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source)); 119 119 } … … 123 123 pmFringeStats *fringe = pmFringeStatsAlloc(prevFringe->regions); 124 124 for (int j = 0; j < fringe->regions->nRequested; j++) { 125 fringe->f->data.F32[j] = NAN;126 fringe->df->data.F32[j] = 1.0;125 fringe->f->data.F32[j] = NAN; 126 fringe->df->data.F32[j] = 1.0; 127 127 } 128 128 fringes->data[0] = fringe; 129 129 } 130 130 131 131 return fringes; 132 132 } … … 143 143 psArray *science = NULL; 144 144 if (isResidual) { 145 science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip145 science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip 146 146 } else { 147 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip147 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip 148 148 } 149 149 … … 160 160 for (int j = 0; j < references->n; j++) { // Iterate over cells 161 161 psArray *ref = references->data[j]; // Array of references for this cell 162 162 163 163 refs->data[j] = psMemIncrRefCounter(ref->data[i]); 164 164 } 165 referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);165 referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL); 166 166 psFree(refs); 167 167 } … … 174 174 175 175 if (isResidual) { 176 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.RESIDUAL.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution);176 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.RESIDUAL.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution); 177 177 } else { 178 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution);178 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution); 179 179 } 180 180 … … 184 184 pmHDU *hdu = pmHDUFromCell(science);// HDU of interest 185 185 for (int i = 0; i < solution->nFringeFrames; i++) { 186 // write metadata header value187 psString keyword = NULL;188 if (isResidual) {189 psStringAppend (&keyword, "FRES_%02dV", i);190 } else {191 psStringAppend (&keyword, "FRNG_%02dV", i);192 }193 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);194 psFree (keyword);195 196 keyword = NULL;197 if (isResidual) {198 psStringAppend (&keyword, "FRES_%02dE", i);199 } else {200 psStringAppend (&keyword, "FRNG_%02dE", i);201 }202 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);203 psFree (keyword);186 // write metadata header value 187 psString keyword = NULL; 188 if (isResidual) { 189 psStringAppend (&keyword, "FRES_%02dV", i); 190 } else { 191 psStringAppend (&keyword, "FRNG_%02dV", i); 192 } 193 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]); 194 psFree (keyword); 195 196 keyword = NULL; 197 if (isResidual) { 198 psStringAppend (&keyword, "FRES_%02dE", i); 199 } else { 200 psStringAppend (&keyword, "FRNG_%02dE", i); 201 } 202 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]); 203 psFree (keyword); 204 204 } 205 205 # endif … … 265 265 266 266 # if (0) 267 // write metadata header value268 // XXX this is measured per cell, but we only have headers per chip269 psString keyword = NULL;270 psStringAppend (&keyword, "FRNG_%02dV", i);271 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);272 psFree (keyword);273 274 keyword = NULL;275 psStringAppend (&keyword, "FRNG_%02dE", i);276 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);277 psFree (keyword);267 // write metadata header value 268 // XXX this is measured per cell, but we only have headers per chip 269 psString keyword = NULL; 270 psStringAppend (&keyword, "FRNG_%02dV", i); 271 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]); 272 psFree (keyword); 273 274 keyword = NULL; 275 psStringAppend (&keyword, "FRNG_%02dE", i); 276 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]); 277 psFree (keyword); 278 278 # endif 279 279 … … 291 291 } 292 292 293 // subtract fringe and update mask if fringe value is NAN294 for (int iy = 0; iy < readout->image->numRows; iy++) {295 for (int ix = 0; ix < readout->image->numCols; ix++) {296 readout->image->data.F32[iy][ix] -= sumFringe->data.F32[iy][ix];297 if (!isfinite(sumFringe->data.F32[iy][ix]) && readout->mask) {298 readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= maskVal;299 } 300 }301 }293 // subtract fringe and update mask if fringe value is NAN 294 for (int iy = 0; iy < readout->image->numRows; iy++) { 295 for (int ix = 0; ix < readout->image->numCols; ix++) { 296 readout->image->data.F32[iy][ix] -= sumFringe->data.F32[iy][ix]; 297 if (!isfinite(sumFringe->data.F32[iy][ix]) && readout->mask) { 298 readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= maskVal; 299 } 300 } 301 } 302 302 303 303 // XXX: Make generic, so subregions may be subtracted as well … … 307 307 // } 308 308 309 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS310 ppImageDetrendFringeMeasure (readout, fringes, true, options);309 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS 310 ppImageDetrendFringeMeasure (readout, fringes, true, options); 311 311 } 312 312 psFree(sumFringe); … … 320 320 psFree(timeString); 321 321 322 return sumFringe;322 return true; 323 323 } 324 324 … … 338 338 pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE"); 339 339 if (!fringe) { 340 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");341 psFree (view);342 return false;340 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 341 psFree (view); 342 return false; 343 343 } 344 344 345 345 // Solve the fringe system 346 346 if (!ppImageDetrendFringeSolve(chip, fringe, false, options)) { 347 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n");348 psFree (view);349 return false;347 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n"); 348 psFree (view); 349 return false; 350 350 } 351 351 … … 353 353 view->cell = view->readout = -1; 354 354 while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) { 355 if (!cell->process || !cell->file_exists) {356 continue;357 }358 359 // Apply the fringe correction360 psTrace("ppImage", 3, "Applying fringe correction...\n");361 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE");362 if (!fringeCell) {363 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");364 psFree (view);365 return false;366 }367 368 // XXX for now, skip the video cells (cell->readouts->n > 1)369 if (cell->readouts->n > 1) {370 psWarning ("Skipping Video Cell for ppImageDetrendFringeApply");371 continue;372 }373 374 if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) {375 psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n");376 psFree (view);377 return false;378 }355 if (!cell->process || !cell->file_exists) { 356 continue; 357 } 358 359 // Apply the fringe correction 360 psTrace("ppImage", 3, "Applying fringe correction...\n"); 361 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE"); 362 if (!fringeCell) { 363 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 364 psFree (view); 365 return false; 366 } 367 368 // XXX for now, skip the video cells (cell->readouts->n > 1) 369 if (cell->readouts->n > 1) { 370 psWarning ("Skipping Video Cell for ppImageDetrendFringeApply"); 371 continue; 372 } 373 374 if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) { 375 psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n"); 376 psFree (view); 377 return false; 378 } 379 379 } 380 380 381 381 // Solve the residual fringe system 382 382 if (!ppImageDetrendFringeSolve(chip, fringe, true, options)) { 383 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n");384 psFree (view);385 return false;383 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n"); 384 psFree (view); 385 return false; 386 386 } 387 387 -
trunk/ppImage/src/ppImageDetrendPattern.c
r26694 r26895 5 5 #include "ppImage.h" 6 6 7 #define ESCAPE( MESSAGE) {\8 psError(PS_ERR_UNKNOWN, false, MESSAGE);\7 #define ESCAPE(STATUS,...) { \ 8 psError(PS_ERR_UNKNOWN, STATUS, __VA_ARGS__); \ 9 9 psFree(view); \ 10 10 return false; \ 11 11 } 12 13 static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipename, const char *recipevalue); 12 14 13 15 bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView, … … 16 18 pmCell *cell = NULL; 17 19 18 assert (options->doPattern); // do not call if not needed 19 assert (inputView->chip != -1); 20 assert (inputView->cell == -1); 21 assert (inputView->readout == -1); 22 bool status; 23 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT"); 20 assert(options->doPatternRow || options->doPatternCell); // do not call if not needed 21 assert(inputView->chip != -1); 22 assert(inputView->cell == -1); 23 assert(inputView->readout == -1); 24 24 25 pmFPAview *view = pmFPAviewAlloc(0); // View for local processing 26 *view = *inputView; 25 if (options->doPatternRow) { 26 bool status; 27 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT"); 28 pmFPAview *view = pmFPAviewAlloc(0); // View for local processing 29 *view = *inputView; 30 while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { 31 if (!cell->process || !cell->file_exists) { 32 continue; 33 } 34 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 35 ESCAPE(false, "load failure for Cell"); 36 } 27 37 28 while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { 29 if (!cell->process || !cell->file_exists) { 30 continue; 31 } 32 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 33 ESCAPE("load failure for Cell"); 34 } 35 36 if (!cell->data_exists) { 37 continue; 38 } 39 40 if (cell->readouts->n > 1) { 41 psWarning ("Skipping Video Cell for ppImageDetrendPatternApply"); 42 continue; 43 } 44 45 psMetadataItem *doPattern = pmConfigRecipeValueByView(config, RECIPE_NAME, "PATTERN.SUBSET", 46 chip->parent, view); // Do we do pattern sub? 47 if (!doPattern || doPattern->type != PS_DATA_BOOL) { 48 ESCAPE("Unable to determine whether pattern matching should be applied."); 49 } 50 if (!doPattern->data.B) { 51 continue; 52 } 53 54 psLogMsg("ppImage", PS_LOG_INFO, "Performing pattern subtraction for %d,%d\n", view->chip, view->cell); 55 56 // process each of the readouts 57 pmReadout *readout; // Readout from cell 58 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 59 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 60 ESCAPE("load failure for Readout"); 61 } 62 if (!readout->data_exists) { 38 if (!cell->data_exists) { 63 39 continue; 64 40 } 65 41 66 // perfore pattern correction 67 if (!pmPatternRow(readout, options->patternOrder, options->patternIter, options->patternRej, 68 options->patternThresh, options->patternMean, options->patternStdev, 69 options->maskValue, options->darkMask)) { 70 psFree(view); 71 return(false); 42 if (cell->readouts->n > 1) { 43 psWarning ("Skipping Video Cell for ppImageDetrendPatternApply"); 44 continue; 45 } 46 47 bool doPattern = false; 48 if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.ROW.SUBSET")) { 49 ESCAPE(false, "Unable to determine whether row pattern matching should be applied."); 50 } 51 if (!doPattern) continue; 52 53 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 54 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); 55 psLogMsg("ppImage", PS_LOG_INFO, "Performing row pattern correction for %s, %s\n", 56 chipName, cellName); 57 58 // process each of the readouts 59 pmReadout *readout; // Readout from cell 60 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 61 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 62 ESCAPE(false, "load failure for Readout"); 63 } 64 if (!readout->data_exists) { 65 continue; 66 } 67 68 // Perform pattern correction 69 if (!pmPatternRow(readout, options->patternRowOrder, options->patternRowIter, 70 options->patternRowRej, options->patternRowThresh, options->patternRowMean, 71 options->patternRowStdev, options->maskValue, options->darkMask)) { 72 psFree(view); 73 return(false); 74 } 72 75 } 73 76 } 77 psFree(view); 74 78 } 75 79 76 psFree(view); 80 if (options->doPatternCell) { 81 int numCells = chip->cells->n; // Number of cells 82 psVector *tweak = psVectorAlloc(numCells, PS_TYPE_U8); // Tweak cell? 83 pmFPAview *view = pmFPAviewAlloc(0); // View for local processing 84 *view = *inputView; 85 for (int i = 0; i < chip->cells->n; i++) { 86 view->cell = i; 87 88 bool doPattern = false; 89 if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.CELL.SUBSET")) { 90 ESCAPE(false, "Unable to determine whether row pattern matching should be applied."); 91 } 92 if (doPattern) { 93 tweak->data.U8[i] = 0xFF; 94 } 95 } 96 97 // Tweak the cells 98 if (!pmPatternCell(chip, tweak, options->patternCellBG, options->patternCellMean, 99 options->maskValue, options->darkMask)) { 100 psFree(tweak); 101 psFree(view); 102 return false; 103 } 104 psFree(tweak); 105 psFree(view); 106 } 107 77 108 return(true); 78 109 } 79 110 111 static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipeName, const char *recipeValue) { 80 112 113 *doit = false; 114 115 psMetadataItem *doPattern = pmConfigRecipeValueByView(config, recipeName, recipeValue, chip->parent, view); 116 if (!doPattern) { 117 psError(PS_ERR_UNKNOWN, false, "Unable to determine whether row pattern matching should be applied."); 118 return false; 119 } 120 if (doPattern->type == PS_DATA_BOOL) { 121 *doit = doPattern->data.B; 122 return true; 123 } 124 if (doPattern->type == PS_DATA_STRING) { 125 // expect a string of the form "000110001001" with at least view->cell entries 126 char *string = doPattern->data.str; 127 if (strlen(string) < view->cell) { 128 psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET chip string (too few elements %d)", (int) strlen(string)); 129 return false; 130 } 131 switch (string[view->cell]) { 132 case '0': 133 case 'f': 134 case 'F': 135 case 'n': 136 case 'N': 137 *doit = false; 138 return true; 139 case '1': 140 case 't': 141 case 'T': 142 case 'y': 143 case 'Y': 144 *doit = true; 145 return true; 146 default: 147 psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET chip string %s (unknown value %c))", string, string[view->cell]); 148 return false; 149 } 150 psAbort("imposible to reach here"); 151 } 152 psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET : invalid data type"); 153 return false; 154 } -
trunk/ppImage/src/ppImageLoop.c
r26682 r26895 163 163 } 164 164 165 // Apply the pattern noisecorrection166 if (options->doPattern ) {165 // Apply the pattern correction 166 if (options->doPatternRow || options->doPatternCell) { 167 167 if (!ppImageDetrendPatternApply(config,chip,view,options)) { 168 168 ESCAPE("Unable to apply pattern corrections"); -
trunk/ppImage/src/ppImageOptions.c
r25930 r26895 32 32 options->doShutter = false; // Shutter correction 33 33 options->doFlat = false; // Flat-field normalisation 34 options->doPattern = false; // Pattern noise subtraction 34 options->doPatternRow = false; // Row pattern correction 35 options->doPatternCell = false; // Cell pattern correction 35 36 options->doFringe = false; // Fringe subtraction 36 37 options->doPhotom = false; // Source identification and photometry … … 90 91 options->fringeKeep = 1.0; // Fringe keep fraction 91 92 92 // Pattern noise values 93 94 options->patternOrder = 0; // Polynomial order 95 options->patternIter = 0; // Clipping iterations 96 options->patternRej = NAN; // Clipping rejection threshold 97 options->patternThresh = NAN; // Threshold for ignoring pixels 98 options->patternMean = PS_STAT_NONE; // Statistic for mean 99 options->patternStdev = PS_STAT_NONE; // Statistic for standard deviation 93 // Pattern correction values 94 95 options->patternRowOrder = 0; // Polynomial order 96 options->patternRowIter = 0; // Clipping iterations 97 options->patternRowRej = NAN; // Clipping rejection threshold 98 options->patternRowThresh = NAN; // Threshold for ignoring pixels 99 options->patternRowMean = PS_STAT_NONE; // Statistic for mean 100 options->patternRowStdev = PS_STAT_NONE; // Statistic for standard deviation 101 options->patternCellBG = PS_STAT_NONE; // Statistic for background 102 options->patternCellMean = PS_STAT_NONE; // Statistic for mean 100 103 101 104 // Remnance values … … 238 241 options->doFringe = psMetadataLookupBool(NULL, recipe, "FRINGE"); 239 242 options->doShutter = psMetadataLookupBool(NULL, recipe, "SHUTTER"); 240 options->doPattern = psMetadataLookupBool(NULL, recipe, "PATTERN"); 243 options->doPatternRow = psMetadataLookupBool(NULL, recipe, "PATTERN.ROW"); 244 options->doPatternCell = psMetadataLookupBool(NULL, recipe, "PATTERN.CELL"); 241 245 242 246 options->doStats = false; … … 250 254 options->burntoolTrails = psMetadataLookupS32(&status, recipe, "BURNTOOL.TRAILS"); 251 255 psTrace("psModules.detrend", 7, "burntoolTrails: %d BURNTOOL.TRAILS: %d Status: %d\n", 252 options->burntoolTrails,psMetadataLookupS32(&status,recipe,"BURNTOOL.TRAILS"),status);256 options->burntoolTrails,psMetadataLookupS32(&status,recipe,"BURNTOOL.TRAILS"),status); 253 257 if (!status) { 254 258 psWarning("BURNTOOL.TRAILS not found in recipe: setting to default value.\n"); 255 259 } 256 260 257 261 // binned image options 258 262 options->xBin1 = psMetadataLookupS32(&status, recipe, "BIN1.XBIN"); 259 263 if (!status) { 260 264 psWarning("BIN1.XBIN not found in recipe: setting to default value.\n"); 261 options->xBin1 = 4;265 options->xBin1 = 4; 262 266 } 263 267 options->yBin1 = psMetadataLookupS32(&status, recipe, "BIN1.YBIN"); … … 320 324 options->fringeKeep = psMetadataLookupF32(NULL, recipe, "FRINGE.KEEP"); 321 325 322 // Pattern noise 323 options->patternOrder = psMetadataLookupS32(NULL, recipe, "PATTERN.ORDER"); 324 options->patternIter = psMetadataLookupS32(NULL, recipe, "PATTERN.ITER"); 325 options->patternRej = psMetadataLookupF32(NULL, recipe, "PATTERN.REJ"); 326 options->patternThresh = psMetadataLookupF32(NULL, recipe, "PATTERN.THRESH"); 327 options->patternMean = psStatsOptionFromString(psMetadataLookupStr(NULL, recipe, "PATTERN.MEAN")); 328 options->patternStdev = psStatsOptionFromString(psMetadataLookupStr(NULL, recipe, "PATTERN.STDEV")); 326 // Pattern correction 327 options->patternRowOrder = psMetadataLookupS32(NULL, recipe, "PATTERN.ROW.ORDER"); 328 options->patternRowIter = psMetadataLookupS32(NULL, recipe, "PATTERN.ROW.ITER"); 329 options->patternRowRej = psMetadataLookupF32(NULL, recipe, "PATTERN.ROW.REJ"); 330 options->patternRowThresh = psMetadataLookupF32(NULL, recipe, "PATTERN.ROW.THRESH"); 331 options->patternRowMean = psStatsOptionFromString(psMetadataLookupStr(NULL, recipe, "PATTERN.ROW.MEAN")); 332 options->patternRowStdev = psStatsOptionFromString(psMetadataLookupStr(NULL, recipe, "PATTERN.ROW.STDEV")); 333 options->patternCellBG = psStatsOptionFromString(psMetadataLookupStr(NULL, recipe, "PATTERN.CELL.BG")); 334 options->patternCellMean = psStatsOptionFromString(psMetadataLookupStr(NULL, recipe, "PATTERN.CELL.MEAN")); 329 335 330 336 // Remnance options -
trunk/ppImage/src/ppImageParseCamera.c
r24492 r26895 79 79 int nScanRows = psMetadataLookupS32(&status, recipe, "SCAN.ROWS"); 80 80 pmDetrendSetThreadTasks(nScanRows); 81 } 82 83 if (options->doPatternRow || options->doPatternCell) { 84 pmFPAfile *outPattern = pmFPAfileDefineOutput(config, input->fpa, "PPIMAGE.PATTERN"); 85 if (!outPattern) { 86 psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.PATTERN")); 87 psFree(options); 88 return NULL; 89 } 90 outPattern->save = true; 81 91 } 82 92 … … 255 265 pmFPAfile *psphotInput = pmFPAfileDefineFromFile (config, chipImage, 1, 1, "PSPHOT.INPUT"); 256 266 PS_ASSERT (psphotInput, false); 267 268 // specify the number of psphot input images 269 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1); 257 270 258 271 // define associated psphot input/output files -
trunk/ppImage/src/ppImageReplaceBackground.c
r25759 r26895 80 80 // the background model has not been defined, or at least not generated 81 81 if (!modelFile || !modelRO) { 82 if (!psphotModelBackground (config, &roView, "PPIMAGE.CHIP")) {82 if (!psphotModelBackgroundReadoutFileIndex(config, &roView, "PPIMAGE.CHIP", 0)) { 83 83 psError(PS_ERR_UNKNOWN, false, "Unable to model background"); 84 84 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
