IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2010, 3:55:49 PM (16 years ago)
Author:
eugene
Message:

update merges from trunk

Location:
branches/eam_branches/20100225
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225

  • branches/eam_branches/20100225/ppStack/src/ppStackCombineFinal.c

    r27004 r27517  
    1414//#define TESTING                         // Enable test output
    1515
    16 bool ppStackCombineFinal(pmReadout *target, ppStackThreadData *stack, psArray *covariances,
    17                          ppStackOptions *options, pmConfig *config, bool safe, bool normalise)
     16bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options,
     17                         pmConfig *config, bool safe, bool normalise, bool grow)
    1818{
    1919    psAssert(stack, "Require stack");
     
    2121    psAssert(config, "Require configuration");
    2222
    23     if (!target->mask) {
    24         target->mask = psImageAlloc(target->image->numCols, target->image->numRows, PS_TYPE_IMAGE_MASK);
     23    pmReadout *outRO = options->outRO;                                      // Output readout
     24    pmReadout *expRO = options->expRO;                                      // Exposure readout
     25    int numCols = outRO->image->numCols, numRows = outRO->image->numRows; // Size of image
     26
     27    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     28    psAssert(recipe, "We've thrown an error on this before.");
     29    float poorFrac = psMetadataLookupF32(NULL, recipe, "POOR.FRACTION"); // Fraction for "poor"
     30
     31    // Grow the list of rejected pixels, if desired
     32    psArray *reject = psArrayAlloc(options->num); // Pixels rejected for each image
     33    for (int i = 0; i < options->num; i++) {
     34        if (options->inputMask->data.U8[i]) {
     35            continue;
     36        }
     37        if (grow) {
     38            reject->data[i] = pmStackRejectGrow(options->rejected->data[i], numCols, numRows, poorFrac,
     39                                                options->regions->data[i], options->kernels->data[i]);
     40            if (!reject->data[i]) {
     41                psError(psErrorCodeLast(), false, "Unable to grow rejected pixels for image %d", i);
     42                psFree(reject);
     43                return false;
     44            }
     45        } else {
     46            reject->data[i] = psMemIncrRefCounter(options->rejected->data[i]);
     47        }
     48    }
     49
     50    if (!outRO->mask) {
     51        outRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     52    }
     53    if (!expRO->mask) {
     54        expRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
    2555    }
    2656
     
    3262            // Something went wrong
    3363            psError(psErrorCodeLast(), false, "Unable to read chunk %d", numChunk);
     64            psFree(reject);
    3465            return false;
    3566        }
     
    3970        }
    4071
    41         // call: ppStackReadoutFinal(config, target, readouts, rejected)
     72        // call: ppStackReadoutFinal(config, outRO, readouts, rejected)
    4273        psThreadJob *job = psThreadJobAlloc("PPSTACK_FINAL_COMBINE"); // Job to start
    43         psArrayAdd(job->args, 1, target);
    4474        psArrayAdd(job->args, 1, thread);
     75        psArrayAdd(job->args, 1, reject);
    4576        psArrayAdd(job->args, 1, options);
    4677        psArrayAdd(job->args, 1, config);
     
    4980        if (!psThreadJobAddPending(job)) {
    5081            psFree(job);
     82            psFree(reject);
    5183            return false;
    5284        }
     
    5688    if (!psThreadPoolWait(true)) {
    5789        psError(psErrorCodeLast(), false, "Unable to do final combination.");
     90        psFree(reject);
    5891        return false;
    5992    }
     93
     94    psFree(reject);
    6095
    6196    // Sum covariance matrices
     
    77112        }
    78113        if (sumWeights > 0.0) {
    79             target->covariance = psImageCovarianceSum(covariances);
    80             psBinaryOp(target->covariance->image, target->covariance->image, "/",
     114            outRO->covariance = psImageCovarianceSum(covariances);
     115            psBinaryOp(outRO->covariance->image, outRO->covariance->image, "/",
    81116                       psScalarAlloc(sumWeights, PS_TYPE_F32));
    82             psImageCovarianceTransfer(target->variance, target->covariance);
     117            psImageCovarianceTransfer(outRO->variance, outRO->covariance);
    83118        }
    84119    } else {
    85         target->covariance = psImageCovarianceNone();
     120        outRO->covariance = psImageCovarianceNone();
    86121    }
    87122
     
    99134            wcsDone = true;
    100135            pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU
    101             pmHDU *outHDU = pmHDUFromCell(target->parent); // Output HDU
    102             pmChip *outChip = target->parent->parent; // Output chip
     136            pmHDU *outHDU = pmHDUFromCell(outRO->parent); // Output HDU
     137            pmChip *outChip = outRO->parent->parent; // Output chip
    103138            pmFPA *outFPA = outChip->parent; // Output FPA
    104139            if (!outHDU || !inHDU) {
     
    123158    }
    124159
     160    // Set exposure time correctly
     161    {
     162        float exptime = 0.0;            // Summed exposure time
     163        for (int i = 0; i < options->num; i++) {
     164            if (options->inputMask) {
     165                continue;
     166            }
     167            exptime += options->exposures->data.F32[i];
     168        }
     169
     170        {
     171            psMetadataItem *item = psMetadataLookup(outRO->parent->concepts, "CELL.EXPOSURE");
     172            item->data.F32 = exptime;
     173        }
     174        {
     175            psMetadataItem *item = psMetadataLookup(outRO->parent->parent->parent->concepts, "FPA.EXPOSURE");
     176            item->data.F32 = exptime;
     177        }
     178    }
     179
    125180    // Put version information into the header
    126     pmHDU *hdu = pmHDUFromCell(target->parent);
     181    pmHDU *hdu = pmHDUFromCell(outRO->parent);
    127182    if (!hdu) {
    128183        psError(PPSTACK_ERR_PROG, false, "Unable to find HDU for output.");
     
    140195    psStringAppend(&name, "combined_image_final_%d.fits", pass);
    141196    pass++;
    142     ppStackWriteImage(name, NULL, target->image, config);
     197    ppStackWriteImage(name, NULL, outRO->image, config);
    143198    psStringSubstitute(&name, "mask", "image");
    144     ppStackWriteImage(name, NULL, target->mask, config);
     199    ppStackWriteImage(name, NULL, outRO->mask, config);
    145200    psStringSubstitute(&name, "variance", "mask");
    146     ppStackWriteImage(name, NULL, target->variance, config);
     201    ppStackWriteImage(name, NULL, outRO->variance, config);
    147202    psFree(name);
    148203
    149     pmStackVisualPlotTestImage(target->image, "combined_image_final.fits");
     204    pmStackVisualPlotTestImage(outRO->image, "combined_image_final.fits");
    150205#endif
    151206
Note: See TracChangeset for help on using the changeset viewer.