IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18287


Ignore:
Timestamp:
Jun 23, 2008, 12:41:08 PM (18 years ago)
Author:
Paul Price
Message:

Merging in dual-convolution development branch.

Location:
trunk/psModules/src/imcombine
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r18190 r18287  
    33 *  @author Paul Price, IfA
    44 *  @author GLG, MHPCC
    5  *
    6  *  @version $Revision: 1.95 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2008-06-19 03:03:53 $
    85 *
    96 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    512509    PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, -1);
    513510
    514     double totalSquareDev = 0.0;        // Total square deviation from zero
     511    // I used to measure the rms deviation about zero, and use that as the sigma against which to clip, but
     512    // the distribution is actually something like a chi^2 or Student's t, both of which become Gaussian-like
     513    // with large N.  Therefore, let's just treat this as a Gaussian distribution.
     514
     515    double mean = 0.0;                  // Mean deviation
    515516    int numStamps = 0;                  // Number of used stamps
    516517    for (int i = 0; i < stamps->num; i++) {
     
    519520            continue;
    520521        }
    521         totalSquareDev += PS_SQR(deviations->data.F32[i]);
     522        mean += deviations->data.F32[i];
    522523        numStamps++;
    523524    }
    524 
    525     float rms = sqrt(totalSquareDev / (double)numStamps); // Convert to RMS
     525    mean /= numStamps;
     526
     527    double rms = 0.0;                   // Standard deviation
     528    for (int i = 0; i < stamps->num; i++) {
     529        pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     530        if (stamp->status != PM_SUBTRACTION_STAMP_USED) {
     531            continue;
     532        }
     533        rms += PS_SQR(deviations->data.F32[i] - mean);
     534    }
     535    rms = sqrt(rms / (numStamps - 1));
    526536
    527537    if (rmsPtr) {
     
    549559    int numRejected = 0;                // Number of stamps rejected
    550560    int numGood = 0;                    // Number of good stamps
    551     double newSquareDev = 0.0;          // New square deviation
     561    double newMean = 0.0;               // New mean
    552562    for (int i = 0; i < stamps->num; i++) {
    553563        pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
    554564        if (stamp->status == PM_SUBTRACTION_STAMP_USED) {
    555             if (deviations->data.F32[i] > limit) {
     565            // Should we reject stars with low deviation?  Well, if this is really a Gaussian-like
     566            // distribution and they're low, then we have the right to ask why.  Isn't it suspicious that
     567            // they're anomalously low, compared to the rest of the population which (we hope) is indicative
     568            // of normality?  Besides, the standard deviation is going to be blown up by stars that didn't
     569            // subtract well, in which case very few (if any) stars will be legitimately rejected for being
     570            // low.
     571            if (deviations->data.F32[i] - mean > limit) {
    556572                // Mask out the stamp in the image so you it's not found again
    557573                psTrace("psModules.imcombine", 3, "Rejecting stamp %d (%d,%d)\n", i,
     
    587603            } else {
    588604                numGood++;
    589                 newSquareDev += PS_SQR(deviations->data.F32[i]);
     605                newMean += deviations->data.F32[i];
    590606            }
    591607        }
    592608    }
     609    newMean /= numGood;
    593610
    594611    if (numRejected > 0) {
    595612        psLogMsg("psModules.imcombine", PS_LOG_INFO,
    596                  "%d good stamps; %d rejected.\nRMS deviation: %f --> %f\n",
    597                  numGood, numRejected, rms,
    598                  sqrt(newSquareDev / (double)numGood));
     613                 "%d good stamps; %d rejected.\nMean deviation: %lf --> %lf\n",
     614                 numGood, numRejected, mean, newMean);
    599615    } else {
    600616        psLogMsg("psModules.imcombine", PS_LOG_INFO,
    601                  "%d good stamps; 0 rejected.\nRMS deviation: %f\n",
    602                  numGood, rms);
     617                 "%d good stamps; 0 rejected.\nMean deviation: %lf\n",
     618                 numGood, mean);
    603619    }
    604620
  • trunk/psModules/src/imcombine/pmSubtractionEquation.c

    r17825 r18287  
    3030    for (int y = - footprint; y <= footprint; y++) {
    3131        for (int x = - footprint; x <= footprint; x++) {
    32             sum += image1->kernel[y][x] * image2->kernel[y][x] / weight->kernel[y][x];
     32            sum += image1->kernel[y][x] * image2->kernel[y][x] / 1.0; // weight->kernel[y][x];
    3333        }
    3434    }
     
    194194            for (int y = - footprint; y <= footprint; y++) {
    195195                for (int x = - footprint; x <= footprint; x++) {
    196                     sumC += conv->kernel[y][x] / weight->kernel[y][x];
     196                    sumC += conv->kernel[y][x] / 1.0; // weight->kernel[y][x];
    197197                }
    198198            }
     
    217217        for (int y = - footprint; y <= footprint; y++) {
    218218            for (int x = - footprint; x <= footprint; x++) {
    219                 double invNoise2 = 1.0 / weight->kernel[y][x];
     219                double invNoise2 = 1.0 / 1.0; // weight->kernel[y][x];
    220220                double value = input->kernel[y][x] * invNoise2;
    221221                sumI += value;
     
    276276        for (int y = - footprint; y <= footprint; y++) {
    277277            for (int x = - footprint; x <= footprint; x++) {
    278                     sumTC += target->kernel[y][x] * conv->kernel[y][x] / weight->kernel[y][x];
     278                sumTC += target->kernel[y][x] * conv->kernel[y][x] / 1.0; // weight->kernel[y][x];
    279279            }
    280280        }
     
    296296        for (int y = - footprint; y <= footprint; y++) {
    297297            for (int x = - footprint; x <= footprint; x++) {
    298                 float value = target->kernel[y][x] / weight->kernel[y][x];
     298                float value = target->kernel[y][x] / 1.0; // weight->kernel[y][x];
    299299                sumIT += value * input->kernel[y][x];
    300300                sumT += value;
     
    365365        for (int y = - footprint; y <= footprint; y++) {
    366366            for (int x = - footprint; x <= footprint; x++) {
    367                 sumC += conv->kernel[y][x] / weight->kernel[y][x];
     367                sumC += conv->kernel[y][x] / 1.0; // weight->kernel[y][x];
    368368            }
    369369        }
     
    382382}
    383383
     384
     385// Add in penalty term to least-squares vector
     386static bool calculatePenalty(psVector *vector, // Vector to which to add in penalty term
     387                             const pmSubtractionKernels *kernels // Kernel parameters
     388    )
     389{
     390    if (kernels->penalty == 0.0) {
     391        return true;
     392    }
     393
     394    psVector *penalties = kernels->penalties; // Penalties for each kernel component
     395    int spatialOrder = kernels->spatialOrder; // Order of spatial variations
     396    int numKernels = kernels->num; // Number of kernel components
     397    for (int i = 0; i < numKernels; i++) {
     398        for (int yOrder = 0, index = i; yOrder <= spatialOrder; yOrder++) {
     399            for (int xOrder = 0; xOrder <= spatialOrder - yOrder; xOrder++, index += numKernels) {
     400                vector->data.F64[index] -= penalties->data.F32[i];
     401            }
     402        }
     403    }
     404
     405    return true;
     406}
     407
    384408//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    385409// Semi-public functions
    386 // XXX EAM these cannot be inline :: talk to Josh
     410// XXX We might like to define these functions as "extern inline" but gcc currently doesn't handle this in c99
     411// mode.  See http://gcc.gnu.org/ml/gcc/2006-11/msg00006.html
    387412//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    388413
     
    675700        psVectorInit(sumVector, 0.0);
    676701        psImageInit(sumMatrix, 0.0);
     702        int numStamps = 0;              // Number of good stamps
    677703        for (int i = 0; i < stamps->num; i++) {
    678704            pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     
    680706                (void)psBinaryOp(sumMatrix, sumMatrix, "+", stamp->matrix1);
    681707                (void)psBinaryOp(sumVector, sumVector, "+", stamp->vector1);
    682             }
    683         }
     708                numStamps++;
     709            }
     710        }
     711        calculatePenalty(sumVector, kernels);
    684712
    685713        psVector *permutation = NULL;       // Permutation vector, required for LU decomposition
     
    716744        psVectorInit(sumVector2, 0.0);
    717745
     746        int numStamps = 0;              // Number of good stamps
    718747        for (int i = 0; i < stamps->num; i++) {
    719748            pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     
    724753                (void)psBinaryOp(sumVector1, sumVector1, "+", stamp->vector1);
    725754                (void)psBinaryOp(sumVector2, sumVector2, "+", stamp->vector2);
    726             }
    727         }
     755                numStamps++;
     756            }
     757        }
     758        calculatePenalty(sumVector1, kernels);
     759        calculatePenalty(sumVector2, kernels);
    728760
    729761#if 0
     
    778810        psImage *F = (psImage*)psBinaryOp(NULL, CtBiC, "-", A);
    779811        assert(F->numRows == numParams && F->numCols == numParams);
    780         float det = NAN;
     812        float det = 0.0;
    781813        psImage *Fi = psMatrixInvert(NULL, F, &det);
    782814        assert(Fi->numRows == numParams && Fi->numCols == numParams);
  • trunk/psModules/src/imcombine/pmSubtractionEquation.h

    r15809 r18287  
    2121
    2222/// Calculate the value of a polynomial, specified by coefficients and polynomial values
    23 inline double p_pmSubtractionCalculatePolynomial(const psVector *coeff, ///< Coefficients
    24                                                  const psImage *polyValues, ///< Polynomial values
    25                                                  int order, ///< Order of polynomials
    26                                                  int index, ///< Index at which to begin
    27                                                  int step ///< Step between subsequent indices
     23double p_pmSubtractionCalculatePolynomial(const psVector *coeff, ///< Coefficients
     24                                          const psImage *polyValues, ///< Polynomial values
     25                                          int order, ///< Order of polynomials
     26                                          int index, ///< Index at which to begin
     27                                          int step ///< Step between subsequent indices
    2828    );
    2929
    3030/// Return the specified coefficient in the solution
    31 inline double p_pmSubtractionSolutionCoeff(const pmSubtractionKernels *kernels, ///< Kernel parameters
    32                                            const psImage *polyValues, ///< Polynomial values
    33                                            int index, ///< Coefficient index to calculate
    34                                            bool wantDual ///< Calculate the coefficient for the dual solution?
     31double p_pmSubtractionSolutionCoeff(const pmSubtractionKernels *kernels, ///< Kernel parameters
     32                                    const psImage *polyValues, ///< Polynomial values
     33                                    int index, ///< Coefficient index to calculate
     34                                    bool wantDual ///< Calculate the coefficient for the dual solution?
    3535    );
    3636
    3737/// Return the normalisation in the solution
    38 inline double p_pmSubtractionSolutionNorm(const pmSubtractionKernels *kernels ///< Kernel parameters
     38double p_pmSubtractionSolutionNorm(const pmSubtractionKernels *kernels ///< Kernel parameters
    3939    );
    4040
    4141/// Return the background (difference) in the solution
    42 inline double p_pmSubtractionSolutionBackground(const pmSubtractionKernels *kernels, ///< Kernel parameters
    43                                                 const psImage *polyValues ///< Polynomial values
     42double p_pmSubtractionSolutionBackground(const pmSubtractionKernels *kernels, ///< Kernel parameters
     43                                         const psImage *polyValues ///< Polynomial values
    4444    );
    4545
  • trunk/psModules/src/imcombine/pmSubtractionKernels.c

    r18146 r18287  
    2424    psFree(kernels->vStop);
    2525    psFree(kernels->preCalc);
     26    psFree(kernels->penalties);
    2627    psFree(kernels->solution1);
    2728    psFree(kernels->solution2);
     
    6061    kernels->v = psVectorRealloc(kernels->v, start + numNew);
    6162    kernels->preCalc = psArrayRealloc(kernels->preCalc, start + numNew);
     63    kernels->penalties = psVectorRealloc(kernels->penalties, start + numNew);
    6264    kernels->inner = start;
    6365
     
    7476            kernels->v->data.S32[index] = v;
    7577            kernels->preCalc->data[index] = NULL;
     78            kernels->penalties->data.F32[index] = kernels->penalty * (PS_SQR(u) + PS_SQR(v));
    7679
    7780            psTrace("psModules.imcombine", 7, "Kernel %d: %d %d\n", index, u, v);
     
    8487pmSubtractionKernels *p_pmSubtractionKernelsRawISIS(int size, int spatialOrder,
    8588                                                    const psVector *fwhms, const psVector *orders,
    86                                                     pmSubtractionMode mode)
     89                                                    float penalty, pmSubtractionMode mode)
    8790{
    8891    PS_ASSERT_VECTOR_NON_NULL(fwhms, NULL);
     
    104107    }
    105108
    106     pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS,
    107                                                               size, spatialOrder, mode); // The kernels
    108     psStringAppend(&kernels->description, "ISIS(%d,%s,%d)", size, params, spatialOrder);
     109    pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS, size,
     110                                                              spatialOrder, penalty, mode); // The kernels
     111    psStringAppend(&kernels->description, "ISIS(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty);
    109112
    110113    psLogMsg("psModules.imcombine", PS_LOG_INFO, "ISIS kernel: %s,%d --> %d elements",
     
    122125                psKernel *preCalc = psKernelAlloc(-size, size, -size, size);
    123126                double sum = 0.0;       // Normalisation
     127                double moment = 0.0;    // Moment, for penalty
    124128                for (int v = -size; v <= size; v++) {
    125129                    for (int u = -size; u <= size; u++) {
    126130                        sum += preCalc->kernel[v][u] = norm * power(u, uOrder) * power(v, vOrder) *
    127131                            expf(-0.5 * (PS_SQR(u) + PS_SQR(v)) / PS_SQR(sigma));
     132                        moment += preCalc->kernel[v][u] * (PS_SQR(u) + PS_SQR(v));
    128133                    }
    129134                }
     
    146151                }
    147152                kernels->preCalc->data[index] = preCalc;
    148 
    149                 psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d\n", index,
    150                         fwhms->data.F32[i], uOrder, vOrder);
     153                kernels->penalties->data.F32[index] = kernels->penalty * fabsf(moment);
     154
     155                psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d %f\n", index,
     156                        fwhms->data.F32[i], uOrder, vOrder, fabsf(moment));
    151157            }
    152158        }
     
    161167
    162168pmSubtractionKernels *pmSubtractionKernelsAlloc(int numBasisFunctions, pmSubtractionKernelsType type,
    163                                                 int size, int spatialOrder, pmSubtractionMode mode)
     169                                                int size, int spatialOrder, float penalty,
     170                                                pmSubtractionMode mode)
    164171{
    165172    pmSubtractionKernels *kernels = psAlloc(sizeof(pmSubtractionKernels)); // Kernels, to return
     
    173180    kernels->widths = psVectorAlloc(numBasisFunctions, PS_TYPE_F32);
    174181    kernels->preCalc = psArrayAlloc(numBasisFunctions);
     182    kernels->penalty = penalty;
     183    kernels->penalties = psVectorAlloc(numBasisFunctions, PS_TYPE_F32);
    175184    kernels->uStop = NULL;
    176185    kernels->vStop = NULL;
     
    188197}
    189198
    190 pmSubtractionKernels *pmSubtractionKernelsPOIS(int size, int spatialOrder, pmSubtractionMode mode)
     199pmSubtractionKernels *pmSubtractionKernelsPOIS(int size, int spatialOrder, float penalty,
     200                                               pmSubtractionMode mode)
    191201{
    192202    PS_ASSERT_INT_POSITIVE(size, NULL);
     
    195205    int num = PS_SQR(2 * size + 1) - 1; // Number of basis functions
    196206
    197     pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_POIS,
    198                                                               size, spatialOrder, mode); // The kernels
    199     psStringAppend(&kernels->description, "POIS(%d,%d)", size, spatialOrder);
     207    pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_POIS, size,
     208                                                              spatialOrder, penalty, mode); // The kernels
     209    psStringAppend(&kernels->description, "POIS(%d,%d,%.2e)", size, spatialOrder, penalty);
    200210    psLogMsg("psModules.imcombine", PS_LOG_INFO, "POIS kernel: %d,%d --> %d elements",
    201211             size, spatialOrder, num);
     
    211221pmSubtractionKernels *pmSubtractionKernelsISIS(int size, int spatialOrder,
    212222                                               const psVector *fwhms, const psVector *orders,
    213                                                pmSubtractionMode mode)
    214 {
    215     pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder,
    216                                                                   fwhms, orders, mode); // Kernels
     223                                               float penalty, pmSubtractionMode mode)
     224{
     225    pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders,
     226                                                                  penalty, mode); // Kernels
    217227    if (!kernels) {
    218228        return NULL;
     
    242252
    243253pmSubtractionKernels *pmSubtractionKernelsSPAM(int size, int spatialOrder, int inner, int binning,
    244                                                pmSubtractionMode mode)
     254                                               float penalty, pmSubtractionMode mode)
    245255{
    246256    PS_ASSERT_INT_POSITIVE(size, NULL);
     
    262272    psTrace("psModules.imcombine", 3, "Number of basis functions: %d\n", num);
    263273
    264     pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_SPAM,
    265                                                               size, spatialOrder, mode); // The kernels
    266     psStringAppend(&kernels->description, "SPAM(%d,%d,%d,%d)", size, inner, binning, spatialOrder);
     274    pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_SPAM, size,
     275                                                              spatialOrder, penalty, mode); // The kernels
     276    psStringAppend(&kernels->description, "SPAM(%d,%d,%d,%d,%.2e)", size, inner, binning, spatialOrder,
     277                   penalty);
    267278
    268279    psLogMsg("psModules.imcombine", PS_LOG_INFO, "SPAM kernel: %d,%d,%d,%d --> %d elements",
     
    324335    psFree(widths);
    325336
     337    psWarning("Kernel penalty for dual-convolution is not configured for SPAM kernels.");
     338    psVectorInit(kernels->penalties, 0.0);
     339
    326340    return kernels;
    327341}
    328342
    329343
    330 pmSubtractionKernels *pmSubtractionKernelsFRIES(int size, int spatialOrder, int inner, pmSubtractionMode mode)
     344pmSubtractionKernels *pmSubtractionKernelsFRIES(int size, int spatialOrder, int inner, float penalty,
     345                                                pmSubtractionMode mode)
    331346{
    332347    PS_ASSERT_INT_POSITIVE(size, NULL);
     
    354369    psTrace("psModules.imcombine", 3, "Number of basis functions: %d\n", num);
    355370
    356     pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_FRIES,
    357                                                               size, spatialOrder, mode); // The kernels
    358     psStringAppend(&kernels->description, "FRIES(%d,%d,%d)", size, inner, spatialOrder);
     371    pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_FRIES, size,
     372                                                              spatialOrder, penalty, mode); // The kernels
     373    psStringAppend(&kernels->description, "FRIES(%d,%d,%d,%.2e)", size, inner, spatialOrder, penalty);
    359374
    360375    psLogMsg("psModules.imcombine", PS_LOG_INFO, "FRIES kernel: %d,%d,%d --> %d elements",
     
    414429    psFree(stop);
    415430
     431    psWarning("Kernel penalty for dual-convolution is not configured for FRIES kernels.");
     432    psVectorInit(kernels->penalties, 0.0);
     433
    416434    return kernels;
    417435}
     
    419437// Grid United with Normal Kernel
    420438pmSubtractionKernels *pmSubtractionKernelsGUNK(int size, int spatialOrder, const psVector *fwhms,
    421                                                const psVector *orders, int inner, pmSubtractionMode mode)
     439                                               const psVector *orders, int inner, float penalty,
     440                                               pmSubtractionMode mode)
    422441{
    423442    PS_ASSERT_INT_POSITIVE(size, NULL);
     
    431450    PS_ASSERT_INT_LESS_THAN(inner, size, NULL);
    432451
    433     pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder,
    434                                                                   fwhms, orders, mode); // Kernels
     452    // XXX GUNK doesn't seem to work --- doesn't add the POIS components, or at least, they're not noticed
     453
     454    pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders,
     455                                                                  penalty, mode); // Kernels
    435456    psStringPrepend(&kernels->description, "GUNK=");
    436457    psStringAppend(&kernels->description, "+POIS(%d,%d)", inner, spatialOrder);
     
    447468// RINGS --- just what it says
    448469pmSubtractionKernels *pmSubtractionKernelsRINGS(int size, int spatialOrder, int inner, int ringsOrder,
    449                                                 pmSubtractionMode mode)
     470                                                float penalty, pmSubtractionMode mode)
    450471{
    451472    PS_ASSERT_INT_POSITIVE(size, NULL);
     
    477498    int num = numRings * numPoly; // Total number of basis functions
    478499
    479     pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_RINGS,
    480                                                               size, spatialOrder, mode); // The kernels
    481     psStringAppend(&kernels->description, "RINGS(%d,%d,%d,%d)", size, inner, ringsOrder, spatialOrder);
     500    pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_RINGS, size,
     501                                                              spatialOrder, penalty, mode); // The kernels
     502    psStringAppend(&kernels->description, "RINGS(%d,%d,%d,%d,%.2e)", size, inner, ringsOrder, spatialOrder,
     503                   penalty);
    482504
    483505    psLogMsg("psModules.imcombine", PS_LOG_INFO, "RINGS kernel: %d,%d,%d,%d --> %d elements",
     
    520542                psVector *vCoords = data->data[1] = psVectorAllocEmpty(RINGS_BUFFER, PS_TYPE_S32); // v coords
    521543                psVector *poly = data->data[2] = psVectorAllocEmpty(RINGS_BUFFER, PS_TYPE_F32); // Polynomial
     544                double moment = 0.0;    // Moment, for penalty
    522545
    523546                if (i == 0) {
     
    527550                    uCoords->n = vCoords->n = poly->n = 1;
    528551                    radiusLast = 0;
     552                    moment = 0.0;
    529553                } else {
    530554                    int j = 0;          // Index for data
     
    546570                                    poly->data.F32[j] = polyVal;
    547571                                    norm += polyVal;
     572                                    moment += polyVal * (PS_SQR(u) + PS_SQR(v));
    548573
    549574                                    psVectorExtend(uCoords, RINGS_BUFFER, 1);
     
    571596                        psBinaryOp(poly, poly, "*", psScalarAlloc(1.0 / norm, PS_TYPE_F32));
    572597                    }
     598//                    moment /= norm;
    573599                }
    574600
     
    578604                kernels->u->data.S32[index] = uOrder;
    579605                kernels->v->data.S32[index] = vOrder;
     606                kernels->penalties->data.F32[index] = kernels->penalty * fabsf(moment);
    580607
    581608                psTrace("psModules.imcombine", 7, "Kernel %d: %d %d %d\n", index,
     
    590617pmSubtractionKernels *pmSubtractionKernelsGenerate(pmSubtractionKernelsType type, int size, int spatialOrder,
    591618                                                   const psVector *fwhms, const psVector *orders, int inner,
    592                                                    int binning, int ringsOrder, pmSubtractionMode mode)
     619                                                   int binning, int ringsOrder, float penalty,
     620                                                   pmSubtractionMode mode)
    593621{
    594622    switch (type) {
    595623      case PM_SUBTRACTION_KERNEL_POIS:
    596         return pmSubtractionKernelsPOIS(size, spatialOrder, mode);
     624        return pmSubtractionKernelsPOIS(size, spatialOrder, penalty, mode);
    597625      case PM_SUBTRACTION_KERNEL_ISIS:
    598         return pmSubtractionKernelsISIS(size, spatialOrder, fwhms, orders, mode);
     626        return pmSubtractionKernelsISIS(size, spatialOrder, fwhms, orders, penalty, mode);
    599627      case PM_SUBTRACTION_KERNEL_SPAM:
    600         return pmSubtractionKernelsSPAM(size, spatialOrder, inner, binning, mode);
     628        return pmSubtractionKernelsSPAM(size, spatialOrder, inner, binning, penalty, mode);
    601629      case PM_SUBTRACTION_KERNEL_FRIES:
    602         return pmSubtractionKernelsFRIES(size, spatialOrder, inner, mode);
     630        return pmSubtractionKernelsFRIES(size, spatialOrder, inner, penalty, mode);
    603631      case PM_SUBTRACTION_KERNEL_GUNK:
    604         return pmSubtractionKernelsGUNK(size, spatialOrder, fwhms, orders, inner, mode);
     632        return pmSubtractionKernelsGUNK(size, spatialOrder, fwhms, orders, inner, penalty, mode);
    605633      case PM_SUBTRACTION_KERNEL_RINGS:
    606         return pmSubtractionKernelsRINGS(size, spatialOrder, inner, ringsOrder, mode);
     634        return pmSubtractionKernelsRINGS(size, spatialOrder, inner, ringsOrder, penalty, mode);
    607635      default:
    608636        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unknown kernel type: %x", type);
     
    657685    int binning = 0;                    // Binning to use
    658686    int ringsOrder = 0;                 // Polynomial order for rings
     687    float penalty = 0.0;                // Penalty for wideness
    659688
    660689    if (strncmp(description, "ISIS", 4) == 0) {
     
    684713
    685714            ptr++;                      // Eat ','
    686             spatialOrder = parseStringInt(ptr);
     715            PARSE_STRING_NUMBER(spatialOrder, ptr, ',', parseStringInt);
     716            penalty = parseStringFloat(ptr);
    687717        }
    688718    } else if (strncmp(description, "RINGS", 5) == 0) {
     
    692722        PARSE_STRING_NUMBER(inner, ptr, ',', parseStringInt);
    693723        PARSE_STRING_NUMBER(ringsOrder, ptr, ',', parseStringInt);
    694         PARSE_STRING_NUMBER(spatialOrder, ptr, ')', parseStringInt);
     724        PARSE_STRING_NUMBER(spatialOrder, ptr, ',', parseStringInt);
     725        PARSE_STRING_NUMBER(penalty, ptr, ')', parseStringInt);
    695726    } else {
    696727        psAbort("Deciphering kernels other than ISIS and RINGS is not currently supported.");
     
    699730
    700731    return pmSubtractionKernelsGenerate(type, size, spatialOrder, fwhms, orders,
    701                                         inner, binning, ringsOrder, mode);
     732                                        inner, binning, ringsOrder, penalty, mode);
    702733}
    703734
  • trunk/psModules/src/imcombine/pmSubtractionKernels.h

    r18146 r18287  
    3333    psVector *uStop, *vStop;            ///< Width of kernel element (SPAM,FRIES only)
    3434    psArray *preCalc;                   ///< Array of images containing pre-calculated kernel (for ISIS)
     35    float penalty;                      ///< Penalty for wideness
     36    psVector *penalties;                ///< Penalty for each kernel component
    3537    int size;                           ///< The half-size of the kernel
    3638    int inner;                          ///< The size of an inner region
     
    107109                                                int size, ///< Half-size of kernel
    108110                                                int spatialOrder, ///< Order of spatial variations
     111                                                float penalty, ///< Penalty for wideness
    109112                                                pmSubtractionMode mode ///< Mode for subtraction
    110113    );
     
    113116pmSubtractionKernels *pmSubtractionKernelsPOIS(int size, ///< Half-size of the kernel (in both dims)
    114117                                               int spatialOrder, ///< Order of spatial variations
     118                                               float penalty, ///< Penalty for wideness
    115119                                               pmSubtractionMode mode ///< Mode for subtraction
    116120    );
     
    121125                                                    const psVector *fwhms, ///< Gaussian FWHMs
    122126                                                    const psVector *orders, ///< Polynomial order of gaussians
     127                                                    float penalty, ///< Penalty for wideness
    123128                                                    pmSubtractionMode mode ///< Mode for subtraction
    124129    );
     
    129134                                               const psVector *fwhms, ///< Gaussian FWHMs
    130135                                               const psVector *orders, ///< Polynomial order of gaussians
     136                                               float penalty, ///< Penalty for wideness
    131137                                               pmSubtractionMode mode ///< Mode for subtraction
    132138                                               );
     
    137143                                               int inner, ///< Inner radius to preserve unbinned
    138144                                               int binning, ///< Kernel binning factor
     145                                               float penalty, ///< Penalty for wideness
    139146                                               pmSubtractionMode mode ///< Mode for subtraction
    140147    );
     
    144151                                                int spatialOrder, ///< Order of spatial variations
    145152                                                int inner, ///< Inner radius to preserve unbinned
     153                                                float penalty, ///< Penalty for wideness
    146154                                                pmSubtractionMode mode ///< Mode for subtraction
    147155    );
     
    153161                                               const psVector *orders, ///< Polynomial order of gaussians
    154162                                               int inner, ///< Inner radius containing grid of delta functions
     163                                               float penalty, ///< Penalty for wideness
    155164                                               pmSubtractionMode mode ///< Mode for subtraction
    156165    );
     
    161170                                                int inner, ///< Inner radius to preserve unbinned
    162171                                                int ringsOrder, ///< Polynomial order
     172                                                float penalty, ///< Penalty for wideness
    163173                                                pmSubtractionMode mode ///< Mode for subtraction
    164174    );
     
    174184                                                   int binning, ///< Kernel binning factor
    175185                                                   int ringsOrder, ///< Polynomial order for RINGS
     186                                                   float penalty, ///< Penalty for wideness
    176187                                                   pmSubtractionMode mode ///< Mode for subtraction
    177188    );
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r18202 r18287  
    117117                        pmSubtractionKernelsType type, int size, int spatialOrder,
    118118                        const psVector *isisWidths, const psVector *isisOrders,
    119                         int inner, int ringsOrder, int binning, bool optimum, const psVector *optFWHMs,
    120                         int optOrder, float optThreshold, int iter, float rej, psMaskType maskBad,
    121                         psMaskType maskBlank, float badFrac, pmSubtractionMode mode)
     119                        int inner, int ringsOrder, int binning, float penalty,
     120                        bool optimum, const psVector *optFWHMs, int optOrder, float optThreshold,
     121                        int iter, float rej, psMaskType maskBad, psMaskType maskBlank,
     122                        float badFrac, pmSubtractionMode mode)
    122123{
    123124    if (mode != PM_SUBTRACTION_MODE_2) {
     
    320321            if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) {
    321322                kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder,
    322                                                           stamps, footprint, optThreshold, mode);
     323                                                          stamps, footprint, optThreshold, penalty, mode);
    323324                if (!kernels) {
    324325                    psErrorClear();
     
    329330                // Not an ISIS/GUNK kernel, or the optimum kernel search failed
    330331                kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders,
    331                                                        inner, binning, ringsOrder, mode);
     332                                                       inner, binning, ringsOrder, penalty, mode);
    332333            }
    333334
     
    450451                // Generate image with convolution kernels
    451452                int fullSize = 2 * size + 1 + 1;    // Full size of kernel
    452                 psImage *convKernels = psImageAlloc(5 * fullSize - 1, 5 * fullSize - 1, PS_TYPE_F32);
     453                int imageSize = (2 * KERNEL_MOSAIC + 1) * fullSize;
     454                psImage *convKernels = psImageAlloc((mode == PM_SUBTRACTION_MODE_DUAL ? 2 : 1) *
     455                                                    imageSize - 1 +
     456                                                    (mode == PM_SUBTRACTION_MODE_DUAL ? 4 : 0),
     457                                                    imageSize - 1, PS_TYPE_F32);
    453458                psImageInit(convKernels, NAN);
    454459                for (int j = -KERNEL_MOSAIC; j <= KERNEL_MOSAIC; j++) {
     
    471476                        }
    472477                        psFree(kernel);
     478
     479                        if (mode == PM_SUBTRACTION_MODE_DUAL) {
     480                            kernel = pmSubtractionKernelImage(kernels, (float)i / (float)KERNEL_MOSAIC,
     481                                                              (float)j / (float)KERNEL_MOSAIC,
     482                                                              true); // Image of the kernel
     483                            if (!kernel) {
     484                                psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image.");
     485                                psFree(convKernels);
     486                                goto MATCH_ERROR;
     487                            }
     488
     489                            if (psImageOverlaySection(convKernels, kernel,
     490                                                      (2 * KERNEL_MOSAIC + 1 + i + KERNEL_MOSAIC) * fullSize +
     491                                                      4,
     492                                                      (j + KERNEL_MOSAIC) * fullSize, "=") == 0) {
     493                                psError(PS_ERR_UNKNOWN, false, "Unable to overlay kernel image.");
     494                                psFree(kernel);
     495                                psFree(convKernels);
     496                                goto MATCH_ERROR;
     497                            }
     498                            psFree(kernel);
     499                        }
     500
    473501                    }
    474502                }
  • trunk/psModules/src/imcombine/pmSubtractionMatch.h

    r18181 r18287  
    3737                        int ringsOrder, ///< RINGS polynomial order
    3838                        int binning,    ///< SPAM kernel binning
     39                        float penalty,  ///< Penalty for wideness
    3940                        bool optimum,   ///< Search for optimum ISIS kernel?
    4041                        const psVector *optFWHMs, ///< FWHMs for optimum search
  • trunk/psModules/src/imcombine/pmSubtractionParams.c

    r15756 r18287  
    204204                                                      int spatialOrder, const psVector *fwhms, int maxOrder,
    205205                                                      const pmSubtractionStampList *stamps, int footprint,
    206                                                       float tolerance, pmSubtractionMode mode)
     206                                                      float tolerance, float penalty, pmSubtractionMode mode)
    207207{
    208208    if (type != PM_SUBTRACTION_KERNEL_ISIS && type != PM_SUBTRACTION_KERNEL_GUNK) {
     
    231231    psVector *orders = psVectorAlloc(numGaussians, PS_TYPE_S32); // Polynomial orders
    232232    psVectorInit(orders, maxOrder);
    233     pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder,
    234                                                                   fwhms, orders, mode); // Kernels
     233    pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders,
     234                                                                  penalty, mode); // Kernels
    235235    psFree(orders);
    236236    psFree(kernels->description);
  • trunk/psModules/src/imcombine/pmSubtractionParams.h

    r15443 r18287  
    1616                                                      int footprint, ///< Convolution footprint for stamps
    1717                                                      float tolerance, ///< Maximum difference in chi^2
     18                                                      float penalty, ///< Penalty for wideness
    1819                                                      pmSubtractionMode mode // Mode for subtraction
    1920    );
Note: See TracChangeset for help on using the changeset viewer.