IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 15, 2021, 6:45:21 AM (5 years ago)
Author:
eugene
Message:

adding simple percentile stack

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ppStack.20211015/src/ppStackReadout.c

    r36886 r41841  
    5353}
    5454
     55bool ppStackReadoutPercentThread(psThreadJob *job)
     56{
     57    PS_ASSERT_THREAD_JOB_NON_NULL(job, false);
     58
     59    psArray *args = job->args;          // Arguments
     60    ppStackThread *thread = args->data[0]; // Thread
     61    ppStackOptions *options = args->data[1]; // Options
     62    pmConfig *config = args->data[2];   // Configuration
     63
     64    pmReadout *outRO = options->outRO;  // Output readout
     65    psVector *mask = options->inputMask; // Mask for inputs
     66    psVector *weightings = options->weightings; // Weightings (1/noise^2) for each image
     67    psVector *exposures = options->exposures;   // Exposure times for each image
     68    psVector *addVariance = options->matchChi2; // Additional variance when rejecting
     69
     70    job->results = ppStackReadoutInitial(config, outRO, thread->readouts, mask,
     71                                         weightings, exposures, addVariance);
     72    thread->busy = false;
     73
     74    return job->results ? true : false;
     75}
     76
     77////////////////////////////////////
    5578
    5679bool ppStackInspect(psThreadJob *job)
     
    316339    return true;
    317340}
     341
     342psArray *ppStackReadoutPercent(const pmConfig *config, pmReadout *outRO, const psArray *readouts,
     343                               const psVector *mask, const psVector *weightings, const psVector *exposures,
     344                               const psVector *addVariance)
     345{
     346    assert(config);
     347    assert(outRO);
     348    assert(readouts);
     349    assert(mask && mask->n == readouts->n && mask->type.type == PS_TYPE_VECTOR_MASK);
     350    assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32);
     351    assert(addVariance && addVariance->n == readouts->n && addVariance->type.type == PS_TYPE_F32);
     352    static int sectionNum = 0;          // Section number; for debugging outputs
     353
     354    // Get the recipe values
     355    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     356    psAssert(recipe, "We've thrown an error on this before.");
     357
     358    bool mdok;                          // Status of MD lookup
     359    float iter = psMetadataLookupF32(NULL, recipe, "COMBINE.ITER"); // Rejection iterations
     360    float minRange = psMetadataLookupF32(NULL, recipe, "COMBINE.MIN.RANGE"); // Combination threshold
     361    float maxRange = psMetadataLookupF32(NULL, recipe, "COMBINE.MAX.RANGE"); // Combination threshold
     362
     363    psMetadata *ppsub = psMetadataLookupMetadata(NULL, config->recipes, "PPSUB"); // PPSUB recipe
     364    int kernelSize = psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Kernel half-size
     365
     366    psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask for bad
     367    psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
     368
     369    psString maskSuspectStr = psMetadataLookupStr(NULL, recipe, "MASK.SUSPECT"); // Name of suspect mask bits
     370    psImageMaskType maskSuspect = pmConfigMaskGet(maskSuspectStr, config); // Suspect bits
     371
     372    bool status = false;
     373    psImageMaskType maskBlank;
     374    psString maskBlankStr = psMetadataLookupStr(&status, recipe, "MASK.BLANK"); // Name of bits to set for empty pixels
     375    if (maskBlankStr) {
     376      maskBlank = pmConfigMaskGet(maskBlankStr, config); // Bits to mask for bad pixels
     377    } else {
     378      maskBlankStr = psMetadataLookupStr(&status, recipe, "MASK.BAD"); // Old name for MASK.BLANK
     379      if (maskBlankStr) {
     380        maskBlank = pmConfigMaskGet(maskBlankStr, config); // Bits to mask for bad pixels
     381      } else {
     382        maskBlank = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels
     383      }
     384    }
     385
     386    int num = readouts->n;              // Number of inputs
     387    psArray *stack = psArrayAlloc(num); // Array for stacking
     388
     389    for (int i = 0; i < num; i++) {
     390        pmReadout *ro = readouts->data[i];
     391        if (!ro || mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
     392            // Bad image
     393            continue;
     394        }
     395
     396        // Ensure there is a mask, or pmStackCombine will complain
     397        if (!ro->mask) {
     398            ro->mask = psImageAlloc(ro->image->numCols, ro->image->numRows, PS_TYPE_IMAGE_MASK);
     399            psImageInit(ro->mask, 0);
     400        }
     401
     402        stack->data[i] = pmStackDataAlloc(ro, weightings->data.F32[i], exposures->data.F32[i],
     403                                          addVariance->data.F32[i]);
     404    }
     405
     406    if (!pmStackCombineByPercentile(outRO, stack, minRange, maxRange, maskBad, maskSuspect, maskBlank)) {
     407        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
     408        psFree(stack);
     409        return false;
     410    }
     411
     412    sectionNum++;
     413
     414    psArray *results = psArrayAlloc(2); // Array of results
     415    results->data[0] = inspect;
     416    results->data[1] = reject;
     417
     418    return results;
     419}
     420
     421
Note: See TracChangeset for help on using the changeset viewer.