IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 17, 2014, 12:32:26 PM (12 years ago)
Author:
eugene
Message:

merge changes (from past YEAR) into trunk

Location:
branches/eam_branches/ipp-ops-20130712/ppStack/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-ops-20130712/ppStack/src

  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStack.h

    r34849 r37067  
    108108                         const psVector *addVariance, // Additional variance for rejection
    109109                         bool safety,                 // Enable safety switch?
    110                          const psVector *norm         // Normalisations to apply
     110                         const psVector *norm,         // Normalisations to apply
     111                         const psVector *bscaleApplyOffset  // hack for offset based on bscale
    111112    );
    112113
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackCombineFinal.c

    r33093 r37067  
    44// #define TESTING                         // Enable test output
    55
     6//MEH -- adhoc addition to blank mask border of final stack since rejection different/none on order of KERNEL.SIZE with overlap in CombineInitial
     7static void stackBorderMask(psImage *image, // Image to mark as blank
     8                            psImage *mask, // Mask to mark as blank (or NULL)
     9                            psImage *variance, // Weight map to mark as blank (or NULL)
     10                            int numCols, int numRows, // Size of image
     11                            int size, // Size to mark blank
     12                            psImageMaskType blank // Blank mask value
     13    )
     14{
     15    for (int y = size; y < numRows - size; y++) {
     16        for (int x = 0; x < size; x++) {
     17            image->data.F32[y][x] = NAN;
     18            mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = blank;
     19            variance->data.F32[y][x] = NAN;
     20        }
     21        for (int x = numCols - size; x < numCols; x++) {
     22            image->data.F32[y][x] = NAN;
     23            mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = blank;
     24            variance->data.F32[y][x] = NAN;
     25        }
     26    }
     27    for (int y = 0; y < size; y++) {
     28        for (int x = 0; x < numCols; x++) {
     29            image->data.F32[y][x] = NAN;
     30            mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = blank;
     31            variance->data.F32[y][x] = NAN;
     32        }
     33    }
     34    for (int y = numRows - size; y < numRows; y++) {
     35        for (int x = 0; x < numCols; x++) {
     36            image->data.F32[y][x] = NAN;
     37            mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = blank;
     38            variance->data.F32[y][x] = NAN;
     39        }
     40    }
     41    return;
     42}
     43
     44
    645bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options,
    7                          pmConfig *config, bool safe, bool normalise, bool grow)
     46                         pmConfig *config, bool safe, bool normalise, bool grow, bool bscaleoffset)
    847{
    948    psAssert(stack, "Require stack");
     
    2059    psAssert(recipe, "We've thrown an error on this before.");
    2160    float poorFrac = psMetadataLookupF32(NULL, recipe, "POOR.FRACTION"); // Fraction for "poor"
     61
     62    int sizeBlank = psMetadataLookupS32(NULL, recipe, "MASK.BLANKBORDER"); // Pixels to mask BLANK from edge
     63    psImageMaskType maskBlank = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels
    2264
    2365    // Grow the list of rejected pixels, if desired
     
    65107        PS_ARRAY_ADD_SCALAR(job->args, safe, PS_TYPE_U8);
    66108        PS_ARRAY_ADD_SCALAR(job->args, normalise, PS_TYPE_U8);
     109        PS_ARRAY_ADD_SCALAR(job->args, bscaleoffset, PS_TYPE_U8);
    67110        if (!psThreadJobAddPending(job)) {
    68111            psFree(reject);
     
    109152#endif
    110153
     154    //MEH blank mask/manual reject border on final stack --
     155    if (sizeBlank > 0) {
     156        stackBorderMask(outRO->image,outRO->mask,outRO->variance,numCols,numRows,sizeBlank,maskBlank);
     157        stackBorderMask(expRO->image,expRO->mask,expRO->variance,numCols,numRows,sizeBlank,0);
     158    }
     159
    111160    if (options->stats) {
    112161        // only add the timer if it has not been set (convolved stack)
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackLoop.c

    r35167 r37067  
    8787        pmCellFreeData(options->cells->data[i]);
    8888    }
    89     //    psFree(stack);
     89    //MEH -- must uncomment back out -- unclear is should be moved after pixel rejection
     90    psFree(stack);
    9091
    9192    // Pixel rejection
     
    119120    psTrace("ppStack", 2, "Final stack of convolved images....\n");
    120121    if (options->convolve) {
    121       if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {
     122      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true, false)) {
    122123        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
    123124        psFree(stack);
     
    127128    else {
    128129      // Since we haven't convolved, I believe we do need to normalize here.
    129       if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true)) {
     130      //MEH -- see below for comment on ppStackCombineFinal and bscaleOffset
     131      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true, true)) {
    130132        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
    131133        psFree(stack);
     
    181183        return false;
    182184    }
    183     //    psFree(stack);
     185    //MEH -- also must uncomment back out..
     186    psFree(stack);
    184187    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
    185188    ppStackMemDump("cleanup");
     
    205208        // generate the unconvolved stack. NOTE: this one must be normalized since the inputs have not been
    206209        psTrace("ppStack", 2, "Stack of unconvolved images....\n");
    207         if (!ppStackCombineFinal(stack, options->origCovars, options, config, false, true, false)) {
     210        //MEH -- terrible hack for bscale offset to input warps -- treat like normalization
     211        // -- if BSCALEOFFSET TRUE, 0.5*bscale for offset values, otherwise value 0.0
     212        // -- bscaleOffset set when files read in and applied in CombineFinal (if arg true, only valid for unconv case)
     213        if (!ppStackCombineFinal(stack, options->origCovars, options, config, false, true, false, true)) {
    208214            psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
    209215            psFree(stack);
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackLoop.h

    r34800 r37067  
    6565    bool safe,                          // Allow safe combination?
    6666    bool norm,                          // Normalise images?
    67     bool grow                           // Grow rejection masks?
     67    bool grow,                           // Grow rejection masks?
     68    bool bscaleoffset                   // Apply bscale offset?
    6869    );
    6970
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackMatch.c

    r35908 r37067  
    66#define COVAR_FRAC 0.01                 // Truncation fraction for covariance matrix
    77
    8 // #define TESTING                         // Enable debugging output
     8// #define TESTING                      // Enable debugging output
    99// #define TESTING_REUSE_CONV           // Enable debugging for re-using convolved outputs from previous run
    10 
    1110// #define TESTING_CZW
    1211
     
    156155    if (options->convolve) {
    157156        pmReadout *conv = pmReadoutAlloc(NULL); // Conv readout, for holding results temporarily
     157
     158        // MEH -- earlier defn needed with new simple mode modifications to  use TESTING_REUSE_CONV...
     159        //const char *typeStr = psMetadataLookupStr(NULL, ppsub, "KERNEL.TYPE"); // Kernel type
     160        //pmSubtractionKernelsType type = pmSubtractionKernelsTypeFromString(typeStr); // Kernel type
     161
    158162#ifdef TESTING_REUSE_CONV
    159163        // This is a hack to use the temporary convolved images and kernel generated previously.
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackOptions.c

    r35167 r37067  
    1919    psFree(options->inputMask);
    2020    psFree(options->sourceLists);
     21    psFree(options->bscaleOffset);
    2122    psFree(options->norm);
    2223    psFree(options->sources);
     
    6566    options->inputMask = NULL;
    6667    options->sourceLists = NULL;
     68    options->bscaleOffset = NULL;
    6769    options->norm = NULL;
    6870    options->sources = NULL;
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackOptions.h

    r35167 r37067  
    3535    float clippedMean;                  // clipped mean of input fwhm
    3636    float clippedStdev;                 // clipped stdev of input fwhm
     37    psVector *bscaleOffset;             // hack offset of bzero using 0.5*bscale if option, 0.0 if not
    3738    // Convolve
    3839    psArray *cells;                     // Cells for convolved images --- a handle for reading again
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackPrepare.c

    r35941 r37067  
    148148    }
    149149
     150    //MEH -- bscale offset hack for warps
     151    options->bscaleOffset = psVectorAlloc(options->num, PS_TYPE_F32);
     152    psVectorInit(options->bscaleOffset, 0.0);
     153    bool setbscaleoffset = psMetadataLookupBool(NULL,recipe, "BSCALEOFFSET");
     154
    150155    psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope
    151156    int numCols = 0, numRows = 0;   // Size of image
     
    162167        }
    163168        options->sumExposure += options->exposures->data.F32[i];
     169
     170        //MEH -- hdu get redefn again below if conv (lots of this happening..)
     171        if (setbscaleoffset) {
     172            pmHDU *hdu = pmHDUFromCell(cell);
     173            assert(hdu && hdu->header);
     174            float bscale = psMetadataLookupF32(NULL, hdu->header, "BSCALE");
     175            options->bscaleOffset->data.F32[i] = 0.5*bscale;
     176        }
     177        psLogMsg("ppStack", PS_LOG_INFO, "bscaleOffset: %d %f", i,options->bscaleOffset->data.F32[i]);
    164178
    165179        // Get list of PSFs, to determine target PSF
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackReadout.c

    r34800 r37067  
    3434    bool safety = PS_SCALAR_VALUE(args->data[4], U8);    // Safety switch on?
    3535    bool normalise = PS_SCALAR_VALUE(args->data[5], U8); // Normalise images?
     36    bool bscaleoffset = PS_SCALAR_VALUE(args->data[6], U8); // Apply bscale offset?
    3637
    3738    psVector *mask = options->inputMask; // Mask for inputs
     
    4041    psVector *addVariance = options->matchChi2; // Additional variance when rejecting
    4142    psVector *norm = normalise ? options->norm : NULL; // Normalisations to apply to images
     43    psVector *bscaleApplyOffset = bscaleoffset ? options->bscaleOffset : NULL; // BSCALE offset to apply to images
    4244
    4345    bool status = ppStackReadoutFinal(config, options->outRO, options->expRO, thread->readouts, mask, reject,
    44                                       weightings, exposures, addVariance, safety, norm); // Status of operation
     46                                      weightings, exposures, addVariance, safety, norm, bscaleApplyOffset); // Status of operation
    4547
    4648    thread->busy = false;
     
    116118    bool useVariance = psMetadataLookupBool(&mdok, recipe, "VARIANCE"); // Use variance for rejection?
    117119    bool safe = psMetadataLookupBool(&mdok, recipe, "SAFE"); // Be safe when combining small numbers of pixels
     120   
     121    int nminpix = psMetadataLookupS32(&mdok, recipe, "NMINPIX"); // Minimum input per pixel to combine with
    118122
    119123    psMetadata *ppsub = psMetadataLookupMetadata(NULL, config->recipes, "PPSUB"); // PPSUB recipe
     
    161165
    162166    if (!pmStackCombine(outRO, NULL, stack, maskBad, maskSuspect, maskBlank, kernelSize, iter,
    163                         combineRej, combineSys, combineDiscard, useVariance, safe, false)) {
     167                        combineRej, combineSys, combineDiscard, useVariance, safe, nminpix, false)) {
    164168        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
    165169        psFree(stack);
     
    184188    psFree(stack);
    185189
     190    //MEH change to trace
     191    //psLogMsg("ppStack", PS_LOG_INFO, "initial stack image sectionNum %d", sectionNum);
     192
    186193    sectionNum++;
    187194
     
    197204                         const psVector *mask, const psArray *rejected, const psVector *weightings,
    198205                         const psVector *exposures, const psVector *addVariance, bool safety,
    199                          const psVector *norm)
     206                         const psVector *norm, const psVector *bscaleApplyOffset)
    200207{
    201208    assert(config);
     
    216223    bool useVariance = psMetadataLookupBool(&mdok, recipe, "VARIANCE"); // Use variance for rejection?
    217224    bool safe = psMetadataLookupBool(&mdok, recipe, "SAFE"); // Be safe when combining small numbers of pixels
     225
     226    int nminpix = psMetadataLookupS32(&mdok, recipe, "NMINPIX"); // Minimum input per pixel to combine with
    218227
    219228    psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask for bad
     
    265274        stack->data[i] = data;
    266275
     276        //MEH -- apply bscale offset before norm   
     277        if (bscaleApplyOffset) {
     278            //MEH change to trace
     279            //psLogMsg("ppStack", PS_LOG_INFO, "bscaleApplyOffset: %d %f", i, bscaleApplyOffset->data.F32[i]);
     280            psBinaryOp(ro->image, ro->image, "-", psScalarAlloc(bscaleApplyOffset->data.F32[i], PS_TYPE_F32));
     281        }
     282
    267283        if (norm) {
    268284            float normalise = powf(10.0, -0.4 * norm->data.F32[i]); // Normalisation
     
    273289
    274290    if (!pmStackCombine(outRO, expRO, stack, maskBad, maskSuspect, maskBlank, 0, iter, combineRej,
    275                         combineSys, combineDiscard, useVariance, safe, rejected)) {
     291                        combineSys, combineDiscard, useVariance, safe, nminpix, rejected)) {
    276292        psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts.");
    277293        psFree(stack);
     
    293309    psFree(stack);
    294310
     311    //MEH change to trace
     312    //psLogMsg("ppStack", PS_LOG_INFO, "final stack image sectionNum %d", sectionNum);
     313
    295314    sectionNum++;
    296315
  • branches/eam_branches/ipp-ops-20130712/ppStack/src/ppStackThread.c

    r34800 r37067  
    277277
    278278    {
    279         psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 6);
     279        psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 7);
    280280        task->function = &ppStackReadoutFinalThread;
    281281        psThreadTaskAdd(task);
Note: See TracChangeset for help on using the changeset viewer.