IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41894 for trunk/ppImage


Ignore:
Timestamp:
Nov 4, 2021, 6:07:14 PM (5 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-dev-20210817 (threaded analysis of pattern row, add pattern row amplitude file I/O)

Location:
trunk/ppImage/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/Makefile.am

    r40453 r41894  
    4242        ppImageDefineFile.c \
    4343        ppImageSetMaskBits.c \
     44        ppImageSetThreads.c \
    4445        ppImageBurntoolMask.c \
    4546        ppImageParityFlip.c \
  • trunk/ppImage/src/ppImage.h

    r41382 r41894  
    193193bool ppImageBurntoolApply(pmConfig *config, ppImageOptions *options, pmFPAview *view, pmReadout *readout);
    194194
    195 bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView, const ppImageOptions *options);
     195bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView, ppImageOptions *options);
     196bool ppImageDetrendPatternApplyCell (pmConfig *config, pmFPA *fpa, pmChip *chip, pmCell *cell, pmFPAview *view, ppImageOptions *options);
    196197
    197198// Do background continuity step
     
    326327bool ppImageAuxiliaryMask(pmConfig *config, const pmFPAview *view, const ppImageOptions *options, psMetadata *stats);
    327328
     329bool ppImageSetThreads (void);
     330
    328331#endif
  • trunk/ppImage/src/ppImageArguments.c

    r35685 r41894  
    116116    pmConfigFileSetsMD (config->arguments, &argc, argv, "FRINGE", "-fringe", "-fringelist");
    117117    pmConfigFileSetsMD (config->arguments, &argc, argv, "LINEARITY", "-linearity", "-linearlist");
     118    pmConfigFileSetsMD (config->arguments, &argc, argv, "PATTERN.ROW.AMP", "-pattern-row-amplitude", "-not-defined");
    118119
    119120    if ((argnum = psArgumentGet(argc, argv, "-burntool"))) {
  • trunk/ppImage/src/ppImageDetrendPattern.c

    r41265 r41894  
    1414
    1515bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView,
    16                                 const ppImageOptions *options)
     16                                ppImageOptions *options)
    1717{
    1818    pmCell *cell = NULL;
     
    3131    // CELLS in the format:CHIPS metadata table)
    3232
     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
    3342    // We also check the chip header for the boolean 'PTRN_ROW' : if this is true, we have
    3443    // already applied this correct to this data, so we simply skip the correction for this
     
    5261
    5362        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       
    5470        pmFPAview *view = pmFPAviewAlloc(0); // View for local processing
    5571        *view = *inputView;
     
    7591            }
    7692
     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
    77106            bool doPattern = false;
    78107            if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.ROW.SUBSET")) {
    79108                ESCAPE(false, "Unable to determine whether row pattern matching should be applied.");
    80109            }
    81             //psWarning ("Row: %d\n", doPattern);
    82110            if (!doPattern) continue;
    83111
    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
    109147        psMetadataAddBool(hdu->header, PS_LIST_TAIL, "PTRN_ROW",PS_META_REPLACE,"PATTERN.ROW correction applied",true);
    110148        psFree(view);
     
    266304    return false;
    267305}
     306
     307// thread safety :
     308bool 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
  • trunk/ppImage/src/ppImageParseCamera.c

    r36169 r41894  
    117117        pmDetrendSetThreadTasks(nScanRows);
    118118    }
     119    ppImageSetThreads (); // even if threading is off, we need to identify the ppImageDetrendPattern thread function
    119120
    120121    if (options->doPatternRow || options->doPatternCell) {
     
    180181            psError (PS_ERR_IO, false, "Can't find a fringe image source");
    181182            return NULL;
     183        }
     184    }
     185
     186    if (options->doPatternRow) {
     187        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.PATTERN.ROW.AMP", "PATTERN.ROW.AMP",
     188                               PM_FPA_FILE_PATTERN_ROW_AMP, PM_DETREND_TYPE_PATTERN_ROW_AMP)) {
     189            psWarning ("Can't find a pattern row amplitude source, will apply to all cells or defined subset");
     190            // an empty or invalid file may have been generated -- we want to skip, not raise an error
     191            pmFPAfile *PRAfile = psMetadataLookupPtr (NULL, config->files, "PPIMAGE.PATTERN.ROW.AMP");
     192            if (PRAfile) {
     193              PRAfile->state |= PM_FPA_STATE_INACTIVE;
     194            }
    182195        }
    183196    }
  • trunk/ppImage/src/ppImageSetThreads.c

    r18823 r41894  
    1515}
    1616
    17 bool ppImageSetThreads () {
     17bool ppImageThread_ppImageDetrendPatternApplyCell (psThreadJob *job) {
    1818
    19     psThreadTask *task = NULL;
     19    pmConfig *config        = job->args->data[0];
     20    pmFPA *fpa              = job->args->data[1];
     21    pmChip *chip            = job->args->data[2];
     22    pmCell *cell            = job->args->data[3];
     23    pmFPAview *view         = job->args->data[4];
     24    ppImageOptions *options = job->args->data[5];
    2025
    21     task = psThreadTaskAlloc ("PPIMAGE_DETREND_READOUT", 3);
    22     task->function = &ppImageThread_ppImageDetrendReadout;
    23     psThreadTaskAdd (task);
     26    bool status = ppImageDetrendPatternApplyCell (config, fpa, chip, cell, view, options);
     27    return status;
     28}
    2429
     30bool ppImageSetThreads (void) {
     31
     32# if (0)
     33    // *** Detrend Readout (now unused : threading is done at the readout level in pmDetrend)
     34    {
     35        psThreadTask *task = psThreadTaskAlloc ("PPIMAGE_DETREND_READOUT", 3);
     36        task->function = &ppImageThread_ppImageDetrendReadout;
     37        psThreadTaskAdd (task);
     38    }
     39# endif
     40
     41    // *** Detrend Pattern Row
     42    {
     43        psThreadTask *task = psThreadTaskAlloc("PPIMAGE_PATTERN_ROW_CELL", 6);
     44        task->function = &ppImageThread_ppImageDetrendPatternApplyCell;
     45        psThreadTaskAdd(task);
     46        psFree(task);
     47    }
    2548    return true;
    2649}
Note: See TracChangeset for help on using the changeset viewer.