IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:41:23 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackMatch.c

    r26454 r26898  
    144144    psMetadataAddU8(psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskBad);
    145145
    146     psImage *binned = psphotBackgroundModel(ro, config); // Binned background model
     146    psImage *binned = psphotModelBackgroundReadoutNoFile(ro, config); // Binned background model
    147147    psImageBinning *binning = psMetadataLookupPtr(NULL, ro->analysis,
    148148                                                  "PSPHOT.BACKGROUND.BINNING"); // Binning for model
     
    274274                                                                PM_SUBTRACTION_ANALYSIS_KERNEL);
    275275
    276             pmSubtractionAnalysis(readout->analysis, NULL, kernels, region,
     276            pmSubtractionAnalysis(conv->analysis, NULL, kernels, region,
    277277                                  readout->image->numCols, readout->image->numRows);
    278278
    279279            psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0, false); // Convolution kernel
     280            bool oldThreads = psImageCovarianceSetThreads(true);              // Old thread setting
    280281            psKernel *covar = psImageCovarianceCalculate(kernel, readout->covariance); // Covariance matrix
     282            psImageCovarianceSetThreads(oldThreads);
    281283            psFree(readout->covariance);
    282284            readout->covariance = covar;
     
    298300            float rej = psMetadataLookupF32(NULL, ppsub, "REJ"); // Rejection threshold
    299301            float kernelError = psMetadataLookupF32(NULL, ppsub, "KERNEL.ERR"); // Relative systematic error in kernel
     302            float normFrac = psMetadataLookupF32(NULL, ppsub, "NORM.FRAC"); // Fraction of window for normalisn windw
    300303            float sysError = psMetadataLookupF32(NULL, ppsub, "SYS.ERR"); // Relative systematic error in images
     304            float skyErr = psMetadataLookupF32(NULL, ppsub, "SKY.ERR"); // Additional error in sky
     305            float covarFrac = psMetadataLookupF32(NULL, ppsub, "COVAR.FRAC"); // Fraction for covariance calculation
     306
    301307            const char *typeStr = psMetadataLookupStr(NULL, ppsub, "KERNEL.TYPE"); // Kernel type
    302308            pmSubtractionKernelsType type = pmSubtractionKernelsTypeFromString(typeStr); // Kernel type
     
    315321            float poorFrac = psMetadataLookupF32(&mdok, ppsub, "POOR.FRACTION"); // Fraction for "poor"
    316322
     323            bool scale = psMetadataLookupBool(NULL, ppsub, "SCALE");        // Scale kernel parameters?
     324            float scaleRef = psMetadataLookupF32(NULL, ppsub, "SCALE.REF"); // Reference for scaling
     325            float scaleMin = psMetadataLookupF32(NULL, ppsub, "SCALE.MIN"); // Minimum for scaling
     326            float scaleMax = psMetadataLookupF32(NULL, ppsub, "SCALE.MAX"); // Maximum for scaling
     327            if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) {
     328                psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     329                        "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in PPSUB recipe.",
     330                        scaleRef, scaleMin, scaleMax);
     331                return false;
     332            }
     333
     334
    317335            // These values are specified specifically for stacking
    318336            const char *stampsName = psMetadataLookupStr(NULL, config->arguments, "STAMPS");// Stamps filename
     
    358376            fake->mask = psImageCopy(NULL, readout->mask, PS_TYPE_IMAGE_MASK);
    359377
     378#if 1
    360379            // Add the background into the target image
    361380            psImage *bgImage = stackBackgroundModel(readout, config); // Image of background
    362381            psBinaryOp(fake->image, fake->image, "+", bgImage);
    363382            psFree(bgImage);
     383#endif
    364384
    365385#ifdef TESTING
     
    395415            if (kernel) {
    396416                if (!pmSubtractionMatchPrecalc(NULL, conv, fake, readout, readout->analysis,
    397                                                stride, kernelError, maskVal, maskBad, maskPoor,
     417                                               stride, kernelError, covarFrac, maskVal, maskBad, maskPoor,
    398418                                               poorFrac, badFrac)) {
    399419                    psError(PS_ERR_UNKNOWN, false, "Unable to convolve images.");
     
    408428                }
    409429            } else {
     430                // Scale the input parameters
     431                psVector *widthsCopy = psVectorCopy(NULL, widths, PS_TYPE_F32); // Copy of kernel widths
     432                if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy,
     433                                                       options->inputSeeing->data.F32[index],
     434                                                       options->targetSeeing, scaleRef, scaleMin, scaleMax)) {
     435                    psError(PS_ERR_UNKNOWN, false, "Unable to scale kernel parameters");
     436                    psFree(fake);
     437                    psFree(optWidths);
     438                    psFree(stampSources);
     439                    psFree(conv);
     440                    psFree(widthsCopy);
     441                    if (threads > 0) {
     442                        pmSubtractionThreadsFinalize(readout, fake);
     443                    }
     444                    return false;
     445                }
     446
    410447                if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing,
    411                                         threshold, stampSources, stampsName, type, size, order, widths,
     448                                        threshold, stampSources, stampsName, type, size, order, widthsCopy,
    412449                                        orders, inner, ringsOrder, binning, penalty,
    413                                         optimum, optWidths, optOrder, optThresh, iter, rej, sysError,
    414                                         kernelError, maskVal, maskBad, maskPoor, poorFrac, badFrac,
    415                                         PM_SUBTRACTION_MODE_2)) {
     450                                        optimum, optWidths, optOrder, optThresh, iter, rej, normFrac,
     451                                        sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor,
     452                                        poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) {
    416453                    psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
    417454                    psFree(fake);
     
    419456                    psFree(stampSources);
    420457                    psFree(conv);
     458                    psFree(widthsCopy);
    421459                    if (threads > 0) {
    422460                        pmSubtractionThreadsFinalize(readout, fake);
     
    424462                    return false;
    425463                }
     464                psFree(widthsCopy);
    426465            }
    427466
     
    495534            while ((item = psMetadataGetAndIncrement(iter))) {
    496535                assert(item->type == PS_DATA_UNKNOWN);
    497                 // Set the normalisation dimensions, since these will be otherwise unavailable when reading
    498                 // the images by scans.
    499536                pmSubtractionKernels *kernel = item->data.V; // Kernel used in subtraction
    500                 kernel->numCols = readout->image->numCols;
    501                 kernel->numRows = readout->image->numRows;
    502 
    503537                kernels = psArrayAdd(kernels, ARRAY_BUFFER, kernel);
    504538            }
     
    526560        }
    527561
     562        // Kernel normalisation
     563        {
     564            double sum = 0.0;           // Sum of chi^2
     565            int num = 0;                // Number of measurements of chi^2
     566            psString regex = NULL;      // Regular expression
     567            psStringAppend(&regex, "^%s$", PM_SUBTRACTION_ANALYSIS_NORM);
     568            psMetadataIterator *iter = psMetadataIteratorAlloc(conv->analysis, PS_LIST_HEAD, regex);
     569            psFree(regex);
     570            psMetadataItem *item = NULL;// Item from iteration
     571            while ((item = psMetadataGetAndIncrement(iter))) {
     572                assert(item->type == PS_TYPE_F32);
     573                float norm = item->data.F32; // Normalisation
     574                sum += norm;
     575                num++;
     576            }
     577            psFree(iter);
     578            float conv = sum/num;       // Mean normalisation from convolution
     579            float stars = powf(10.0, -0.4 * options->norm->data.F32[index]); // Normalisation from stars
     580            float renorm =  stars / conv; // Renormalisation to apply
     581            psLogMsg("ppStack", PS_LOG_INFO, "Renormalising image %d by %f (kernel: %f, stars: %f)\n",
     582                     index, renorm, conv, stars);
     583            psBinaryOp(readout->image, readout->image, "*", psScalarAlloc(renorm, PS_TYPE_F32));
     584            psBinaryOp(readout->variance, readout->variance, "*", psScalarAlloc(PS_SQR(renorm), PS_TYPE_F32));
     585        }
     586
    528587        // Reject image completely if the maximum deconvolution fraction exceeds the limit
    529588        float deconv = psMetadataLookupF32(NULL, conv->analysis,
    530589                                           PM_SUBTRACTION_ANALYSIS_DECONV_MAX); // Max deconvolution fraction
    531590        if (deconv > deconvLimit) {
    532             psWarning("Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting\n",
    533                       deconv, deconvLimit);
     591            psWarning("Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting image %d\n",
     592                      deconv, deconvLimit, index);
    534593            psFree(conv);
    535594            return NULL;
Note: See TracChangeset for help on using the changeset viewer.