IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 28, 2008, 5:10:17 PM (18 years ago)
Author:
Paul Price
Message:

Merging pap_branch_080328 so we can use the modernised version of ppMerge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r16600 r17228  
    7878    corr->offset = 0.0;
    7979    corr->offref = 0.0;
     80    corr->num = 0;
     81    corr->stdev = NAN;
    8082
    8183    return corr;
     
    190192
    191193// linear fit to the counts and exptime, given a value for offref
    192 pmShutterCorrection *pmShutterCorrectionLinFit(const psVector *exptime,
    193         const psVector *counts,
    194         const psVector *cntError,
    195         const psVector *mask,
    196         float offref,
    197         int nIter,
    198         float rej,
    199         psMaskType maskVal
    200                                               )
     194pmShutterCorrection *pmShutterCorrectionLinFit(const psVector *exptime, const psVector *counts,
     195                                               const psVector *cntError, const psVector *mask, float offref,
     196                                               int nIter, float rej, psMaskType maskVal)
    201197{
    202198    PS_ASSERT_VECTOR_NON_NULL(exptime, NULL);
     
    249245        return NULL;
    250246    }
    251     psFree(stats);
    252247
    253248    pmShutterCorrection *corr = pmShutterCorrectionAlloc();
     
    255250    corr->scale  = line->coeff[1][0];
    256251    corr->offset = line->coeff[0][1] / line->coeff[1][0];
    257 
     252    corr->num = stats->clippedNvalues;
     253    corr->stdev = stats->clippedStdev;
     254
     255    psFree(stats);
    258256    psFree(x);
    259257    psFree(y);
     
    263261}
    264262
    265 static psF32 pmShutterCorrectionModel(psVector *deriv,
    266                                       const psVector *params,
    267                                       const psVector *x)
     263static psF32 pmShutterCorrectionModel(psVector *deriv, const psVector *params, const psVector *x)
    268264{
    269265    // This is in a tight loop, so we won't assert here.
     
    283279
    284280// non-linear fit to the counts and exptime, given a guess for the three parameters
    285 pmShutterCorrection *pmShutterCorrectionFullFit(const psVector *exptime,
    286         const psVector *counts,
    287         const psVector *cntError,
    288         const pmShutterCorrection *guess
    289                                                )
     281pmShutterCorrection *pmShutterCorrectionFullFit(const psVector *exptime, const psVector *counts,
     282                                                const psVector *cntError, const pmShutterCorrection *guess)
    290283{
    291284    PS_ASSERT_VECTOR_NON_NULL(exptime, NULL);
     
    638631
    639632
    640 bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter)
     633bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter, psMaskType blank)
    641634{
    642635    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    682675    }
    683676    psImage *image = readout->image;    // Image to correct
     677    psImage *mask = readout->mask;      // Corresponding mask
    684678
    685679    if (exptime <= 0.0) {
     
    688682        for (int y = 0; y < image->numRows; y++) {
    689683            for (int x = 0; x < image->numCols; x++) {
     684                if (mask && !isfinite(shutterImage->data.F32[y][x])) {
     685                    mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
     686                    image->data.F32[y][x] = NAN;
     687                    continue;
     688                }
    690689                image->data.F32[y][x] *= 1.0 / (exptime + shutterImage->data.F32[y][x]);
    691690            }
     
    699698        for (int y = 0; y < image->numRows; y++) {
    700699            for (int x = 0; x < image->numCols; x++) {
     700                if (mask && !isfinite(shutterImage->data.F32[y][x])) {
     701                    mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
     702                    image->data.F32[y][x] = NAN;
     703                    continue;
     704                }
    701705                image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]);
    702706            }
     
    903907    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
    904908    PS_ASSERT_INT_EQUAL(data->num, inputs->n, false);
     909    PS_ASSERT_INT_NONNEGATIVE(nIter, false);
     910    PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false);
    905911
    906912    int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
     
    915921    if (pattern) {
    916922        pmReadoutUpdateSize(pattern, minInputCols, minInputRows, xSize, ySize, false, false, maskVal);
     923    }
     924
     925    psImage *nums = pmReadoutAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT, xSize, ySize,
     926                                           PS_TYPE_U16, 0); // Image with number fitted per pixel
     927    if (!nums) {
     928        return false;
     929    }
     930    psImage *sigma = pmReadoutAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA, xSize, ySize,
     931                                            PS_TYPE_F32, NAN); // Image with stdev per pixel
     932    if (!sigma) {
     933        psFree(nums);
     934        return false;
    917935    }
    918936
     
    955973            pmShutterCorrection *corr = pmShutterCorrectionLinFit(data->exptimes, counts, errors, mask,
    956974                                                                  reference, nIter, rej, maskVal);
     975            if (!corr) {
     976                // Nothing we can do about it
     977                psErrorClear();
     978                shutterImage->data.F32[yOut][xOut] = NAN;
     979                patternImage->data.F32[yOut][xOut] = NAN;
     980                nums->data.U16[yOut][xOut] = 0;
     981                sigma->data.F32[yOut][xOut] = NAN;
     982                continue;
     983            }
    957984            shutterImage->data.F32[yOut][xOut] = corr->offset;
    958985            patternImage->data.F32[yOut][xOut] = corr->scale;
     986            nums->data.U16[yOut][xOut] = corr->num;
     987            sigma->data.F32[yOut][xOut] = corr->stdev;
    959988            psFree(corr);
    960989        }
     
    963992    psFree(errors);
    964993    psFree(counts);
     994    psFree(nums);
     995    psFree(sigma);
    965996
    966997    // Update the "concepts"
Note: See TracChangeset for help on using the changeset viewer.