IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41841


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

adding simple percentile stack

Location:
branches/eam_branches/ppStack.20211015/src
Files:
2 added
10 edited

Legend:

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

    r33093 r41841  
    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/ppStack.20211015/src/ppStackCombinePrepare.c

    r34859 r41841  
    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/ppStack.20211015/src/ppStackLoop.c

    r41529 r41841  
    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
     136      // MEH -- see below for comment on ppStackCombineFinal and bscaleOffset
    132137      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true, true)) {
    133138        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
     
    154159      return false;
    155160    }
    156     ppStackFileActivation(config,PPSTACK_FILES_BKG ,false);   
     161    ppStackFileActivation(config, PPSTACK_FILES_BKG, false);   
     162
    157163    // Photometry
    158164    psTrace("ppStack", 1, "Photometering stacked image....\n");
     
    184190        return false;
    185191    }
    186     //MEH -- also must uncomment back out..
     192    // MEH -- also must uncomment back out..
    187193    psFree(stack);
    188194    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
  • branches/eam_branches/ppStack.20211015/src/ppStackLoop.h

    r36855 r41841  
    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/ppStack.20211015/src/ppStackMatch.c

    r36364 r41841  
    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/ppStack.20211015/src/ppStackOptions.c

    r36855 r41841  
    5656    options->num = 0;
    5757    options->quality = 0;
     58
     59    options->clipPercent = false;
     60    options->clipMinRange = 0.16; // 1-sigma default
     61    options->clipMaxRange = 0.84; // 1-sigma default
     62
    5863    options->psf = NULL;
    5964    options->sumExposure = NAN;
  • branches/eam_branches/ppStack.20211015/src/ppStackOptions.h

    r36855 r41841  
    1616    int num;                            // Number of inputs
    1717    int quality;                        // Bad data quality flag
     18
     19    bool clipPercent;                   // use percentile range to clip?
     20    psF32 clipMinRange;                 // min percentile
     21    psF32 clipMaxRange;                 // max percentile
     22
    1823    // Prepare
    1924    pmPSF *psf;                         // Target PSF
  • 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
  • branches/eam_branches/ppStack.20211015/src/ppStackSetup.c

    r35167 r41841  
    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?
     22    options->clipMinRange = psMetadataLookupF32 (NULL, recipe, "COMBINE.MIN.RANGE"); // min percentile
     23    options->clipMaxRange = psMetadataLookupF32 (NULL, recipe, "COMBINE.MAX.RANGE"); // max percentile
     24
    2025
    2126    if (!psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) {
  • branches/eam_branches/ppStack.20211015/src/ppStackThread.c

    r36855 r41841  
    283283    }
    284284
     285    {
     286        psThreadTask *task = psThreadTaskAlloc("PPSTACK_PERCENT_COMBINE", 3);
     287        task->function = &ppStackReadoutPercentThread;
     288        psThreadTaskAdd(task);
     289        psFree(task);
     290    }
    285291    return;
    286292}
Note: See TracChangeset for help on using the changeset viewer.