IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26895


Ignore:
Timestamp:
Feb 10, 2010, 7:38:09 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201 (main change was PATTERN to PATTERN.ROW, added PATTERN.CELL)

Location:
trunk/ppImage/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImage.h

    r25930 r26895  
    3838    bool doShutter;                     // Shutter correction
    3939    bool doFlat;                        // Flat-field normalisation
    40     bool doPattern;                     // Pattern noise subtraction
     40    bool doPatternRow;                  // Row pattern correction
     41    bool doPatternCell;                 // Cell pattern correction
    4142    bool doFringe;                      // Fringe subtraction
    4243    bool doPhotom;                      // Source identification and photometry
     
    9596    float fringeKeep;                   // Fringe keep fraction
    9697
    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
    104107
    105108    int remnanceSize;                   // Size for remnance detection
  • trunk/ppImage/src/ppImageBurntoolMask.c

    r25299 r26895  
    33#endif
    44
    5 /* #define PPIMAGE_BURNTOOL_DEBUG 1 */
     5#define PPIMAGE_BURNTOOL_DEBUG 0
    66
    77#include "ppImage.h"
     
    2323    return(false);
    2424  }
    25   long Nrows = psFitsTableSize(fits); 
     25  long Nrows = psFitsTableSize(fits);
    2626
    2727  long row = 0;
     
    3333  psImage *image = mask->mask;
    3434
    35  
     35
    3636  /* Set the maskValue from the recipes. */
    3737  psImageMaskType maskValue = options->burntoolMask;
    38 #ifdef PPIMAGE_BURNTOOL_DEBUG
     38#if PPIMAGE_BURNTOOL_DEBUG
    3939  psLogMsg("ppImageBurntoolMask", 4, "Status: %ld %d\n",Nrows,maskValue);
    4040#endif
     
    4747
    4848    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.  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 #ifdef 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                   );
     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                  );
    6565#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++) {
    6969
    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        }
    8989
    9090      }
     
    9595  return(status);
    9696}
    97            
    98 
    99 
    100    
  • trunk/ppImage/src/ppImageDetrendFringe.c

    r25930 r26895  
    1414    psArray *references = psMemIncrRefCounter(psMetadataLookupPtr(NULL, fringe->analysis, "FRINGE.MEASUREMENTS"));
    1515    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;
    1818    }
    1919
     
    4040    char *scienceFringes = NULL;
    4141    if (isResidual) {
    42         scienceFringes = psStringCopy ("FRINGE.RESIDUALS");
     42        scienceFringes = psStringCopy ("FRINGE.RESIDUALS");
    4343    } else {
    44         scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");
     44        scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");
    4545    }
    4646
     
    8585    psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return
    8686    int video_cell_zero = 0;
    87    
     87
    8888    for (int i = 0; i < cells->n; i++) {
    8989        fringes->data[i] = NULL;
     
    9191        pmCell *cell = cells->data[i];  // Cell of interest
    9292
    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
    118118        fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source));
    119119    }
     
    123123      pmFringeStats *fringe     = pmFringeStatsAlloc(prevFringe->regions);
    124124      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;
    127127      }
    128128      fringes->data[0] = fringe;
    129129    }
    130    
     130
    131131    return fringes;
    132132}
     
    143143    psArray *science = NULL;
    144144    if (isResidual) {
    145         science = getFringes(scienceChip,  "FRINGE.RESIDUALS"); // Fringe residuals on science chip
     145        science = getFringes(scienceChip,  "FRINGE.RESIDUALS"); // Fringe residuals on science chip
    146146    } else {
    147         science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
     147        science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
    148148    }
    149149
     
    160160        for (int j = 0; j < references->n; j++) {     // Iterate over cells
    161161            psArray *ref = references->data[j];       // Array of references for this cell
    162            
     162
    163163            refs->data[j] = psMemIncrRefCounter(ref->data[i]);
    164164        }
    165         referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);
     165        referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);
    166166        psFree(refs);
    167167    }
     
    174174
    175175    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);
    177177    } 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);
    179179    }
    180180
     
    184184    pmHDU *hdu = pmHDUFromCell(science);// HDU  of interest
    185185    for (int i = 0; i < solution->nFringeFrames; i++) {
    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);
     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);
    204204    }
    205205# endif
     
    265265
    266266# if (0)
    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);
     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);
    278278# endif
    279279
     
    291291        }
    292292
    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         }
     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        }
    302302
    303303        // XXX: Make generic, so subregions may be subtracted as well
     
    307307        // }
    308308
    309         // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
    310         ppImageDetrendFringeMeasure (readout, fringes, true, options);
     309        // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
     310        ppImageDetrendFringeMeasure (readout, fringes, true, options);
    311311    }
    312312    psFree(sumFringe);
     
    320320    psFree(timeString);
    321321
    322     return sumFringe;
     322    return true;
    323323}
    324324
     
    338338    pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE");
    339339    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;
    343343    }
    344344
    345345    // Solve the fringe system
    346346    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;
    350350    }
    351351
     
    353353    view->cell = view->readout = -1;
    354354    while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) {
    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         }
     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        }
    379379    }
    380380
    381381    // Solve the residual fringe system
    382382    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;
    386386    }
    387387
  • trunk/ppImage/src/ppImageDetrendPattern.c

    r26694 r26895  
    55#include "ppImage.h"
    66
    7 #define ESCAPE(MESSAGE) {                               \
    8         psError(PS_ERR_UNKNOWN, false, MESSAGE);        \
     7#define ESCAPE(STATUS,...) {                    \
     8        psError(PS_ERR_UNKNOWN, STATUS, __VA_ARGS__);   \
    99        psFree(view);                                   \
    1010        return false;                                   \
    1111    }
     12
     13static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipename, const char *recipevalue);
    1214
    1315bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView,
     
    1618    pmCell *cell = NULL;
    1719
    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);
    2424
    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            }
    2737
    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) {
    6339                continue;
    6440            }
    6541
    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                }
    7275            }
    7376        }
     77        psFree(view);
    7478    }
    7579
    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
    77108    return(true);
    78109}
    79110
     111static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipeName, const char *recipeValue) {
    80112
     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  
    163163        }
    164164
    165         // Apply the pattern noise correction
    166         if (options->doPattern) {
     165        // Apply the pattern correction
     166        if (options->doPatternRow || options->doPatternCell) {
    167167          if (!ppImageDetrendPatternApply(config,chip,view,options)) {
    168168            ESCAPE("Unable to apply pattern corrections");
  • trunk/ppImage/src/ppImageOptions.c

    r25930 r26895  
    3232    options->doShutter       = false;   // Shutter correction
    3333    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
    3536    options->doFringe        = false;   // Fringe subtraction
    3637    options->doPhotom        = false;   // Source identification and photometry
     
    9091    options->fringeKeep      = 1.0;     // Fringe keep fraction
    9192
    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
    100103
    101104    // Remnance values
     
    238241    options->doFringe = psMetadataLookupBool(NULL, recipe, "FRINGE");
    239242    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");
    241245
    242246    options->doStats = false;
     
    250254    options->burntoolTrails = psMetadataLookupS32(&status, recipe, "BURNTOOL.TRAILS");
    251255    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);
    253257    if (!status) {
    254258      psWarning("BURNTOOL.TRAILS not found in recipe: setting to default value.\n");
    255259    }
    256    
     260
    257261    // binned image options
    258262    options->xBin1 = psMetadataLookupS32(&status, recipe, "BIN1.XBIN");
    259263    if (!status) {
    260264        psWarning("BIN1.XBIN not found in recipe: setting to default value.\n");
    261         options->xBin1 = 4;
     265        options->xBin1 = 4;
    262266    }
    263267    options->yBin1 = psMetadataLookupS32(&status, recipe, "BIN1.YBIN");
     
    320324    options->fringeKeep = psMetadataLookupF32(NULL, recipe, "FRINGE.KEEP");
    321325
    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"));
    329335
    330336    // Remnance options
  • trunk/ppImage/src/ppImageParseCamera.c

    r24492 r26895  
    7979        int nScanRows = psMetadataLookupS32(&status, recipe, "SCAN.ROWS");
    8080        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;
    8191    }
    8292
     
    255265        pmFPAfile *psphotInput = pmFPAfileDefineFromFile (config, chipImage, 1, 1, "PSPHOT.INPUT");
    256266        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);
    257270
    258271        // define associated psphot input/output files
  • trunk/ppImage/src/ppImageReplaceBackground.c

    r25759 r26895  
    8080    // the background model has not been defined, or at least not generated
    8181    if (!modelFile || !modelRO) {
    82         if (!psphotModelBackground(config, &roView, "PPIMAGE.CHIP")) {
     82        if (!psphotModelBackgroundReadoutFileIndex(config, &roView, "PPIMAGE.CHIP", 0)) {
    8383            psError(PS_ERR_UNKNOWN, false, "Unable to model background");
    8484            return false;
Note: See TracChangeset for help on using the changeset viewer.