IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41908


Ignore:
Timestamp:
Nov 8, 2021, 7:57:10 AM (5 years ago)
Author:
eugene
Message:

merge changes from ppStack.20211015: adding stack-by-percent, some code cleanups (remove commented out blocks), fix thread failure error

Location:
branches/eam_branches/ipp-20211108/ppStack
Files:
15 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20211108/ppStack

  • branches/eam_branches/ipp-20211108/ppStack/src/Makefile.am

    r38034 r41908  
    2929        ppStackPrepare.c        \
    3030        ppStackConvolve.c       \
     31        ppStackLoopByPercent.c  \
     32        ppStackCombinePercent.c \
    3133        ppStackCombinePrepare.c \
    3234        ppStackCombineInitial.c \
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStack.h

    r36855 r41908  
    115115bool ppStackReadoutFinalThread(psThreadJob *job // Job to process
    116116    );
     117
     118// Thread entry point for ppStackReadoutPercent
     119bool ppStackReadoutPercentThread(psThreadJob *job);
     120
     121bool ppStackReadoutPercent(const pmConfig *config,
     122                           pmReadout *outRO,
     123                           const psArray *readouts,
     124                           const psVector *mask,
     125                           const psVector *weightings,
     126                           const psVector *exposures,
     127                           const psVector *addVariance);
     128
    117129// Perform median stacking for background
    118130bool ppStackCombineBackground(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackCombineFinal.c

    r36855 r41908  
    22
    33// This is the doomsday switch.
    4 // #define TESTING                         // Enable test output
     4// # define TESTING                         // Enable test output
    55
    66//MEH -- adhoc addition to blank mask border of final stack since rejection different/none on order of KERNEL.SIZE with overlap in CombineInitial
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackCombineInitial.c

    r33093 r41908  
    99    psAssert(options, "Require options");
    1010    psAssert(config, "Require configuration");
    11 
    12 /*     if (!options->convolve) { */
    13 /*         // No need to do initial combination when we haven't convolved */
    14 /*         // XXX either allocate inspect and rejected here, or do not require them downstream */
    15 /*         return true; */
    16 /*     } */
    1711
    1812    psTimerStart("PPSTACK_INITIAL");
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackCombinePrepare.c

    r34859 r41908  
    3131      options->expRO = pmReadoutAlloc(expCell); //Output readout
    3232    }
    33 /*     else { */
    34 /*       options->expRO = NULL; */
    35 /*     } */
     33
    3634    int bkg_r0 = 0,bkg_c0 = 0;
    3735    int bkg_nC = 0,bkg_nR = 0;
     
    5351     
    5452      options->bkgRO = pmReadoutAlloc(bkgCell); // BKG readout
    55       //      if (!pmHDUGenerateForFPA(options->bkgRO->parent->parent->parent)) {
    5653      options->bkgRO->parent->parent->parent->hdu = pmHDUAlloc(NULL);
     54
    5755      if (!options->bkgRO->parent->parent->parent->hdu) {
    5856        fprintf(stderr,"failed to generate a HDU for this thing.\n");
     
    6866                                                                        ro->parent->parent->parent->concepts);
    6967
    70     }
    71     else {
     68    } else {
    7269      options->bkgRO = NULL;
    7370    }
     
    9794        return false;
    9895      }
    99      
    100 
    101      
    10296    }
    10397
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackLoop.c

    r41529 r41908  
    3131    ppStackMemDump("prepare");
    3232    if (options->quality) return true; // Can't do anything else
     33
     34    // if we want to skip the rejection steps, and instead use a percentile clipping:
     35    if (options->clipPercent) {
     36      bool result = ppStackLoopByPercent (config, options);
     37      return result;
     38    }
    3339
    3440    // Convolve inputs
     
    8894        pmCellFreeData(options->cells->data[i]);
    8995    }
    90     //MEH -- must uncomment back out -- unclear is should be moved after pixel rejection
     96    // MEH -- must uncomment back out -- unclear is should be moved after pixel rejection
    9197    psFree(stack);
    9298
     
    126132        return false;
    127133      }
    128     }
    129     else {
     134    } else {
    130135      // Since we haven't convolved, I believe we do need to normalize here.
    131       //MEH -- see below for comment on ppStackCombineFinal and bscaleOffset
    132       if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true, true)) {
     136      // MEH -- see below for comment on ppStackCombineFinal and bscaleOffset
     137      // last 4 parameters are: safe, normalize, grow, bscaleoffset
     138      // EAM : looks like we do NOT need to normalize here eithr because ppStackConvolve is still called and
     139      // the inputs are normalized
     140      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true, true)) {
    133141        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
    134142        psFree(stack);
     
    154162      return false;
    155163    }
    156     ppStackFileActivation(config,PPSTACK_FILES_BKG ,false);   
     164    ppStackFileActivation(config, PPSTACK_FILES_BKG, false);   
     165
    157166    // Photometry
    158167    psTrace("ppStack", 1, "Photometering stacked image....\n");
     
    184193        return false;
    185194    }
    186     //MEH -- also must uncomment back out..
     195    // MEH -- also must uncomment back out..
    187196    psFree(stack);
    188197    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackLoop.h

    r36855 r41908  
    77    ppStackOptions *options             // Options for stacking
    88    );
     9
    910// Median only loop.
    1011bool ppStackMedianLoop(
     
    1213    ppStackOptions *options             // Options for stacking
    1314    );
     15
     16// stack by percentile range
     17bool ppStackLoopByPercent(
     18  pmConfig *config,
     19  ppStackOptions *options
     20  );
    1421
    1522// Setup
     
    9299
    93100
     101bool ppStackCombinePercent(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
     102
    94103bool ppStackUpdateHeader(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
    95104bool ppStackJPEGs(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackMatch.c

    r36364 r41908  
    524524        psFree(conv);
    525525    } else {
     526        // this branch is done if options->convolve is FALSE
    526527        // Match the normalisation
    527528        float norm = powf(10.0, -0.4 * options->norm->data.F32[index]); // Normalisation
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackOptions.c

    r36855 r41908  
    5656    options->num = 0;
    5757    options->quality = 0;
     58
     59    options->clipPercent = false;
     60
    5861    options->psf = NULL;
    5962    options->sumExposure = NAN;
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackOptions.h

    r36855 r41908  
    1616    int num;                            // Number of inputs
    1717    int quality;                        // Bad data quality flag
     18
     19    bool clipPercent;                   // use percentile range to clip?
     20
    1821    // Prepare
    1922    pmPSF *psf;                         // Target PSF
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackReadout.c

    r36886 r41908  
    1919                                         weightings, exposures, addVariance);
    2020    thread->busy = false;
     21
     22    thread->status = job->results ? PPSTACK_THREAD_SUCCESS : PPSTACK_THREAD_FAILURE;
     23
     24    psAssert(job->results, "Stacking failed.");
    2125
    2226    return job->results ? true : false;
     
    4852    thread->busy = false;
    4953
     54    thread->status = status ? PPSTACK_THREAD_SUCCESS : PPSTACK_THREAD_FAILURE;
     55
    5056    psAssert(status, "Stacking failed.");
    5157
     
    5359}
    5460
     61bool ppStackReadoutPercentThread(psThreadJob *job)
     62{
     63    PS_ASSERT_THREAD_JOB_NON_NULL(job, false);
     64
     65    psArray *args = job->args;          // Arguments
     66    ppStackThread *thread = args->data[0]; // Thread
     67    ppStackOptions *options = args->data[1]; // Options
     68    pmConfig *config = args->data[2];   // Configuration
     69
     70    pmReadout *outRO = options->outRO;  // Output readout
     71    psVector *mask = options->inputMask; // Mask for inputs
     72    psVector *weightings = options->weightings; // Weightings (1/noise^2) for each image
     73    psVector *exposures = options->exposures;   // Exposure times for each image
     74    psVector *addVariance = options->matchChi2; // Additional variance when rejecting
     75
     76    // fprintf (stderr, "start thread %d : scan range %d - %d\n", thread->entry, thread->firstScan, thread->lastScan);
     77
     78    bool status = ppStackReadoutPercent(config, outRO, thread->readouts, mask, weightings, exposures, addVariance);
     79
     80    thread->busy = false;
     81
     82    thread->status = status ? PPSTACK_THREAD_SUCCESS : PPSTACK_THREAD_FAILURE;
     83
     84    // fprintf (stderr, "finished thread %d, status %d : scan range %d - %d\n", thread->entry, thread->status, thread->firstScan, thread->lastScan);
     85
     86    psAssert(status, "Stacking failed.");
     87
     88    return status;
     89}
     90
     91////////////////////////////////////
    5592
    5693bool ppStackInspect(psThreadJob *job)
     
    145182
    146183    int num = readouts->n;              // Number of inputs
    147     psArray *stack = psArrayAlloc(num); // Array for stacking
     184    psArray *stackData = psArrayAlloc(num); // Array of data to be stacked
    148185
    149186    for (int i = 0; i < num; i++) {
     
    160197        }
    161198
    162         stack->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
     199        // stackData is an array of pmStackData structures
     200        stackData->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
    163201                                          addVariance->data.F32[i]);
    164202    }
    165203
    166     if (!pmStackCombine(outRO, NULL, stack, maskBad, maskSuspect, maskBlank, kernelSize, iter,
     204    if (!pmStackCombine(outRO, NULL, stackData, maskBad, maskSuspect, maskBlank, kernelSize, iter,
    167205                        combineRej, combineSys, combineDiscard, useVariance, safe, nminpix, false)) {
    168206        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
    169         psFree(stack);
     207        psFree(stackData);
     208       
     209        // XXX EAM : if pmStackCombine fails above this return will cause the thread to block.
     210        // The failure status results in a psThread.fault.  the psThreadLauncher function, which
     211        // each background thread runs as a loop, will sleep until the fault is cleared externally
     212        // by the handler.  psThreadPoolWait() catches, counts, and clears these faults, but
     213        // ppStackThreadRead does not. 
    170214        return false;
    171215    }
     
    175219    psArray *reject = psArrayAlloc(num);  // List of pixels rejected
    176220    for (int i = 0; i < num; i++) {
    177         pmStackData *data = stack->data[i]; // Data for this image
     221        pmStackData *data = stackData->data[i]; // Data for this image
    178222        if (!data) {
    179223            continue;
     
    186230        reject->data[i] = psMemIncrRefCounter(data->reject);
    187231    }
    188     psFree(stack);
     232    psFree(stackData);
    189233
    190234    //MEH change to trace
     
    247291
    248292    int num = readouts->n;              // Number of inputs
    249     psArray *stack = psArrayAlloc(num); // Array for stacking
     293    psArray *stackData = psArrayAlloc(num); // Array of data to be stacked
    250294
    251295    // We have rejection from a previous combination: combine without flagging pixels to inspect
     
    272316                                             addVariance ? addVariance->data.F32[i] : NAN);
    273317        data->reject = rejected ? psMemIncrRefCounter(rejected->data[i]) : NULL;
    274         stack->data[i] = data;
     318        stackData->data[i] = data;
    275319
    276320        //MEH -- apply bscale offset before norm   
     
    288332    }
    289333
    290     if (!pmStackCombine(outRO, expRO, stack, maskBad, maskSuspect, maskBlank, 0, iter, combineRej,
     334    if (!pmStackCombine(outRO, expRO, stackData, maskBad, maskSuspect, maskBlank, 0, iter, combineRej,
    291335                        combineSys, combineDiscard, useVariance, safe, nminpix, rejected)) {
    292336        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts.");
    293         psFree(stack);
     337        psFree(stackData);
    294338        return false;
    295339    }
     
    307351    expChip->data_exists = true;
    308352
    309     psFree(stack);
     353    psFree(stackData);
    310354
    311355    //MEH change to trace
     
    316360    return true;
    317361}
     362
     363bool ppStackReadoutPercent(const pmConfig *config, pmReadout *outRO, const psArray *readouts,
     364                               const psVector *mask, const psVector *weightings, const psVector *exposures,
     365                               const psVector *addVariance)
     366{
     367    assert(config);
     368    assert(outRO);
     369    assert(readouts);
     370    assert(mask && mask->n == readouts->n && mask->type.type == PS_TYPE_VECTOR_MASK);
     371    assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32);
     372    assert(addVariance && addVariance->n == readouts->n && addVariance->type.type == PS_TYPE_F32);
     373    static int sectionNum = 0;          // Section number; for debugging outputs
     374
     375    // fprintf (stderr, "starting ReadoutPercent, %d\n", sectionNum);
     376
     377    // Get the recipe values
     378    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     379    psAssert(recipe, "We've thrown an error on this before.");
     380
     381    bool mdok;                          // Status of MD lookup
     382    psF64 minRange = psMetadataLookupF32(&mdok, recipe, "COMBINE.MIN.RANGE"); // Combination threshold
     383
     384    char defaultBlankStr[16] = "BLANK";
     385
     386    psString maskBadStr     = psMetadataLookupStr(&mdok, recipe, "MASK.VAL"); // Name of bits to mask for bad
     387    psString maskSuspectStr = psMetadataLookupStr(&mdok, recipe, "MASK.SUSPECT"); // Name of suspect mask bits
     388    psString maskBlankStr   = psMetadataLookupStr(&mdok, recipe, "MASK.BLANK"); // Name of bits to set for empty pixels
     389    if (!maskBlankStr) {
     390      maskBlankStr = psMetadataLookupStr(&mdok, recipe, "MASK.BAD"); // Old name for MASK.BLANK
     391    }
     392    if (!maskBlankStr) {
     393      maskBlankStr = defaultBlankStr; // this is statically allocated above
     394    }
     395
     396    psImageMaskType maskBad     = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
     397    psImageMaskType maskSuspect = pmConfigMaskGet(maskSuspectStr, config); // Suspect bits
     398    psImageMaskType maskBlank   = pmConfigMaskGet(maskBlankStr, config); // Bits to mask for bad pixels
     399
     400    int num = readouts->n;              // Number of inputs
     401    psArray *stackData = psArrayAlloc(num); // Array of data to be stacked
     402
     403    for (int i = 0; i < num; i++) {
     404        pmReadout *ro = readouts->data[i];
     405        if (!ro || mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
     406            // Bad image
     407            continue;
     408        }
     409
     410        // Ensure there is a mask, or pmStackCombine will complain
     411        if (!ro->mask) {
     412            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_IMAGE_MASK);
     413            psImageInit(ro->mask, 0);
     414        }
     415
     416        stackData->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
     417                                              addVariance->data.F32[i]);
     418    }
     419
     420    // XXX rename minRange to rejectFraction
     421    // XXX add expmaps
     422    if (!pmStackCombineByPercentile(outRO, NULL, stackData, minRange, maskBad, maskSuspect, maskBlank)) {
     423        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
     424        psFree(stackData);
     425        return false;
     426    }
     427
     428    outRO->data_exists = true; // output readout
     429    outRO->parent->data_exists = true; // output cell
     430    outRO->parent->parent->data_exists = true; // output chip
     431
     432# if 0
     433      pmCell *expCell = expRO->parent;    // Exposure cell
     434      pmChip *expChip = expCell->parent;  // Exposure chip
     435      expRO->data_exists = true;
     436      expCell->data_exists = true;
     437      expChip->data_exists = true;
     438# endif
     439
     440    psFree(stackData);
     441    sectionNum++;
     442
     443    return true;
     444}
     445
     446
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackSetup.c

    r35167 r41908  
    1818    options->convolve = psMetadataLookupBool(NULL, recipe, "CONVOLVE"); // Convolve images?
    1919    options->doBackground = psMetadataLookupBool(NULL, recipe, "BACKGROUND.MODEL");
     20
     21    options->clipPercent  = psMetadataLookupBool(NULL, recipe, "COMBINE.PERCENT"); // use percentile range to clip?
    2022
    2123    if (!psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) {
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackThread.c

    r36855 r41908  
    1919    thread->firstScan = 0;
    2020    thread->lastScan = 0;
     21    thread->entry = -1; // this gets assigned after allocation
     22    thread->status = PPSTACK_THREAD_NEW;
    2123    return thread;
    2224}
     
    124126            readouts->data[j] = ro;
    125127        }
    126         threads->data[i] = ppStackThreadAlloc(readouts);
     128        ppStackThread *thread = ppStackThreadAlloc(readouts);
     129        thread->entry = i;
     130        threads->data[i] = thread;
    127131        psFree(readouts);               // Drop reference
    128132    }
     
    157161    while (true) {
    158162        // check for any groups which can read data
     163        // NOTE: threads->n is set (in ppStackThreadDataSetup) to be 1 more than the argument to -threads
    159164        for (int j = 0; j < threads->n; j++) {
    160165            ppStackThread *thread = threads->data[j];
     166            // fprintf (stderr, "grab thread %d, scan: %d - %d : busy: %d read: %d status: %d\n", thread->entry, thread->firstScan, thread->lastScan, thread->busy, thread->read, thread->status);
    161167            if (thread->read) {
    162168                continue;
     
    166172            thread->lastScan = stack->lastScan + rows;
    167173            stack->lastScan = thread->lastScan;
     174            thread->status = PPSTACK_THREAD_READ;
    168175
    169176            psArray *readouts = thread->readouts;
     
    172179
    173180            psTrace("ppStack", 2, "Reading data for chunk %d into group %d....\n", numChunk, j);
     181            // fprintf (stderr, "Reading data for chunk %d into group %d (thread %d, scan: %d - %d)....\n", numChunk, j, thread->entry, thread->firstScan, thread->lastScan);
    174182            for (int i = 0; i < readouts->n; i++) {
    175183                pmReadout *ro = readouts->data[i]; // Input readout
     
    177185                    continue;
    178186                }
     187
     188                // fprintf (stderr, "read data for readout %d\n", i);
    179189
    180190                // override the recorded last scan
     
    232242
    233243            thread->read = thread->busy = true;
     244            thread->status = PPSTACK_THREAD_RUN;
    234245            return thread;
    235246        }
     
    239250        for (int j = 0; j < threads->n; j++) {
    240251            ppStackThread *thread = threads->data[j];
     252            // fprintf (stderr, "test thread %d, scan: %d - %d : busy: %d, read: %d, status: %d\n", thread->entry, thread->firstScan, thread->lastScan, thread->busy, thread->read, thread->status);
     253
    241254            if (thread->busy) {
    242255                continue;
    243256            }
     257            thread->status = PPSTACK_THREAD_NEW;
    244258            thread->read = false;
    245259            wait = false;
     
    283297    }
    284298
     299    {
     300        psThreadTask *task = psThreadTaskAlloc("PPSTACK_PERCENT_COMBINE", 3);
     301        task->function = &ppStackReadoutPercentThread;
     302        psThreadTaskAdd(task);
     303        psFree(task);
     304    }
    285305    return;
    286306}
  • branches/eam_branches/ipp-20211108/ppStack/src/ppStackThread.h

    r34800 r41908  
    1111    int firstScan;                      // First row of the chunk to be read for this group
    1212    int lastScan;                       // Last row of the chunk to be read for this group
     13    int entry;                          // thread number for tracking progress
     14    int status;                         // thread number for tracking progress
    1315} ppStackThread;
    1416
     
    4749
    4850
     51enum {PPSTACK_THREAD_NEW, PPSTACK_THREAD_READ, PPSTACK_THREAD_RUN, PPSTACK_THREAD_SUCCESS, PPSTACK_THREAD_FAILURE};
     52
     53
    4954#endif
Note: See TracChangeset for help on using the changeset viewer.