IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 28, 2022, 3:01:31 PM (4 years ago)
Author:
eugene
Message:

some cleanup of ppStackFiles: JPEG1 & JPEG2 are not part of the "convolved" output: they are activated explicitly in ppStackJPEGs.c; add option to generate stacks using the pmStackCombineByPercent method; trap failures in the ppStackReadout threads; fix normalization for both convolved and unconvolved versions (was inconsistent in ppStackLoop)

Location:
trunk/ppStack
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack

  • trunk/ppStack/src/ppStackReadout.c

    r36886 r42094  
    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    pmReadout *expRO = options->expRO;  // Expmap readout
     72    psVector *mask = options->inputMask; // Mask for inputs
     73    psVector *weightings = options->weightings; // Weightings (1/noise^2) for each image
     74    psVector *exposures = options->exposures;   // Exposure times for each image
     75    psVector *addVariance = options->matchChi2; // Additional variance when rejecting
     76
     77    // fprintf (stderr, "start thread %d : scan range %d - %d\n", thread->entry, thread->firstScan, thread->lastScan);
     78
     79    bool status = ppStackReadoutPercent(config, outRO, expRO, thread->readouts, mask, weightings, exposures, addVariance);
     80
     81    thread->busy = false;
     82
     83    thread->status = status ? PPSTACK_THREAD_SUCCESS : PPSTACK_THREAD_FAILURE;
     84
     85    // fprintf (stderr, "finished thread %d, status %d : scan range %d - %d\n", thread->entry, thread->status, thread->firstScan, thread->lastScan);
     86
     87    psAssert(status, "Stacking failed.");
     88
     89    return status;
     90}
     91
     92////////////////////////////////////
    5593
    5694bool ppStackInspect(psThreadJob *job)
     
    145183
    146184    int num = readouts->n;              // Number of inputs
    147     psArray *stack = psArrayAlloc(num); // Array for stacking
     185    psArray *stackData = psArrayAlloc(num); // Array of data to be stacked
    148186
    149187    for (int i = 0; i < num; i++) {
     
    160198        }
    161199
    162         stack->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
     200        // stackData is an array of pmStackData structures
     201        stackData->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
    163202                                          addVariance->data.F32[i]);
    164203    }
    165204
    166     if (!pmStackCombine(outRO, NULL, stack, maskBad, maskSuspect, maskBlank, kernelSize, iter,
     205    if (!pmStackCombine(outRO, NULL, stackData, maskBad, maskSuspect, maskBlank, kernelSize, iter,
    167206                        combineRej, combineSys, combineDiscard, useVariance, safe, nminpix, false)) {
    168207        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
    169         psFree(stack);
     208        psFree(stackData);
     209       
     210        // XXX EAM : if pmStackCombine fails above this return will cause the thread to block.
     211        // The failure status results in a psThread.fault.  the psThreadLauncher function, which
     212        // each background thread runs as a loop, will sleep until the fault is cleared externally
     213        // by the handler.  psThreadPoolWait() catches, counts, and clears these faults, but
     214        // ppStackThreadRead does not. 
    170215        return false;
    171216    }
     
    175220    psArray *reject = psArrayAlloc(num);  // List of pixels rejected
    176221    for (int i = 0; i < num; i++) {
    177         pmStackData *data = stack->data[i]; // Data for this image
     222        pmStackData *data = stackData->data[i]; // Data for this image
    178223        if (!data) {
    179224            continue;
     
    186231        reject->data[i] = psMemIncrRefCounter(data->reject);
    187232    }
    188     psFree(stack);
     233    psFree(stackData);
    189234
    190235    //MEH change to trace
     
    247292
    248293    int num = readouts->n;              // Number of inputs
    249     psArray *stack = psArrayAlloc(num); // Array for stacking
     294    psArray *stackData = psArrayAlloc(num); // Array of data to be stacked
    250295
    251296    // We have rejection from a previous combination: combine without flagging pixels to inspect
     
    272317                                             addVariance ? addVariance->data.F32[i] : NAN);
    273318        data->reject = rejected ? psMemIncrRefCounter(rejected->data[i]) : NULL;
    274         stack->data[i] = data;
     319        stackData->data[i] = data;
    275320
    276321        //MEH -- apply bscale offset before norm   
     
    288333    }
    289334
    290     if (!pmStackCombine(outRO, expRO, stack, maskBad, maskSuspect, maskBlank, 0, iter, combineRej,
     335    if (!pmStackCombine(outRO, expRO, stackData, maskBad, maskSuspect, maskBlank, 0, iter, combineRej,
    291336                        combineSys, combineDiscard, useVariance, safe, nminpix, rejected)) {
    292337        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts.");
    293         psFree(stack);
     338        psFree(stackData);
    294339        return false;
    295340    }
     
    307352    expChip->data_exists = true;
    308353
    309     psFree(stack);
     354    psFree(stackData);
    310355
    311356    //MEH change to trace
     
    316361    return true;
    317362}
     363
     364// NOTE: expRO is allowed to be NULL
     365bool ppStackReadoutPercent(const pmConfig *config, pmReadout *outRO, pmReadout *expRO, const psArray *readouts,
     366                               const psVector *mask, const psVector *weightings, const psVector *exposures,
     367                               const psVector *addVariance)
     368{
     369    assert(config);
     370    assert(outRO);
     371    assert(readouts);
     372    assert(mask && mask->n == readouts->n && mask->type.type == PS_TYPE_VECTOR_MASK);
     373    assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32);
     374    assert(addVariance && addVariance->n == readouts->n && addVariance->type.type == PS_TYPE_F32);
     375    static int sectionNum = 0;          // Section number; for debugging outputs
     376
     377    // fprintf (stderr, "starting ReadoutPercent, %d\n", sectionNum);
     378
     379    // Get the recipe values
     380    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     381    psAssert(recipe, "We've thrown an error on this before.");
     382
     383    bool mdok;                          // Status of MD lookup
     384    psF64 rejectFraction = psMetadataLookupF32(&mdok, recipe, "COMBINE.REJECT.FRACTION"); // fraction of outliers to reject
     385
     386    char defaultBlankStr[16] = "BLANK";
     387
     388    psString maskBadStr     = psMetadataLookupStr(&mdok, recipe, "MASK.VAL"); // Name of bits to mask for bad
     389    psString maskSuspectStr = psMetadataLookupStr(&mdok, recipe, "MASK.SUSPECT"); // Name of suspect mask bits
     390    psString maskBlankStr   = psMetadataLookupStr(&mdok, recipe, "MASK.BLANK"); // Name of bits to set for empty pixels
     391    if (!maskBlankStr) {
     392      maskBlankStr = psMetadataLookupStr(&mdok, recipe, "MASK.BAD"); // Old name for MASK.BLANK
     393    }
     394    if (!maskBlankStr) {
     395      maskBlankStr = defaultBlankStr; // this is statically allocated above
     396    }
     397
     398    psImageMaskType maskBad     = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
     399    psImageMaskType maskSuspect = pmConfigMaskGet(maskSuspectStr, config); // Suspect bits
     400    psImageMaskType maskBlank   = pmConfigMaskGet(maskBlankStr, config); // Bits to mask for bad pixels
     401
     402    int num = readouts->n;              // Number of inputs
     403    psArray *stackData = psArrayAlloc(num); // Array of data to be stacked
     404
     405    for (int i = 0; i < num; i++) {
     406        stackData->data[i] = NULL;
     407
     408        pmReadout *ro = readouts->data[i];
     409        if (!ro || mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
     410            // Bad image
     411            continue;
     412        }
     413
     414        // Ensure there is a mask, or pmStackCombine will complain
     415        if (!ro->mask) {
     416            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_IMAGE_MASK);
     417            psImageInit(ro->mask, 0);
     418        }
     419
     420        stackData->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
     421                                              addVariance->data.F32[i]);
     422    }
     423
     424    if (!pmStackCombineByPercentile(outRO, expRO, stackData, rejectFraction, maskBad, maskSuspect, maskBlank)) {
     425        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
     426        psFree(stackData);
     427        return false;
     428    }
     429
     430    outRO->data_exists = true;                 // output readout
     431    outRO->parent->data_exists = true;         // output cell
     432    outRO->parent->parent->data_exists = true; // output chip
     433
     434    if (expRO) {
     435      expRO->data_exists = true;                 // expmap readout
     436      expRO->parent->data_exists = true;               // expmap cell   
     437      expRO->parent->parent->data_exists = true; // expmap chip
     438    }
     439     
     440    psFree(stackData);
     441    sectionNum++;
     442
     443    return true;
     444}
     445
     446
Note: See TracChangeset for help on using the changeset viewer.