IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26609


Ignore:
Timestamp:
Jan 14, 2010, 11:15:29 AM (16 years ago)
Author:
Paul Price
Message:

Had wrong sign for penalty function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c

    r26593 r26609  
    1515#include "pmSubtractionVisual.h"
    1616
    17 // #define TESTING                         // TESTING output for debugging; may not work with threads!
     17//#define TESTING                         // TESTING output for debugging; may not work with threads!
    1818
    1919//#define USE_WEIGHT                      // Include weight (1/variance) in equation?
     
    487487                // Contribution to chi^2: a_i^2 P_i
    488488                psAssert(isfinite(penalties->data.F32[i]), "Invalid penalty");
    489                 matrix->data.F64[index][index] -= norm * penalties->data.F32[i];
     489                matrix->data.F64[index][index] += norm * penalties->data.F32[i];
    490490            }
    491491        }
     
    13371337    float peak = 0.0;
    13381338    for (int y = - footprint; y <= footprint; y++) {
    1339         for (int x = - footprint; x <= footprint; x++) {
    1340             sum += 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
    1341             peak = PS_MAX(peak, 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm));
    1342         }
     1339        for (int x = - footprint; x <= footprint; x++) {
     1340            sum += 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
     1341            peak = PS_MAX(peak, 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm));
     1342        }
    13431343    }
    13441344
     
    13531353
    13541354    for (int y = - footprint; y <= footprint; y++) {
    1355         for (int x = - footprint; x <= footprint; x++) {
    1356             float dflux = 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
    1357             if (dflux < 0.02*sum) continue;
    1358             dflux1 += residual->kernel[y][x];
    1359             dflux2 += PS_SQR(residual->kernel[y][x]);
    1360             dmax = PS_MAX(residual->kernel[y][x], dmax);
    1361             dmin = PS_MIN(residual->kernel[y][x], dmin);
    1362             npix ++;
    1363         }
     1355        for (int x = - footprint; x <= footprint; x++) {
     1356            float dflux = 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
     1357            if (dflux < 0.02*sum) continue;
     1358            dflux1 += residual->kernel[y][x];
     1359            dflux2 += PS_SQR(residual->kernel[y][x]);
     1360            dmax = PS_MAX(residual->kernel[y][x], dmax);
     1361            dmin = PS_MIN(residual->kernel[y][x], dmin);
     1362            npix ++;
     1363        }
    13641364    }
    13651365    float sigma = sqrt(dflux2 / npix - PS_SQR(dflux1/npix));
     
    13981398    psVector *keepStamps  = psVectorAlloc(stamps->num, PS_TYPE_S32);
    13991399    psVectorInit (keepStamps, 0);
    1400     { 
    1401         psVector *flux  = psVectorAlloc(stamps->num, PS_TYPE_F32);
    1402         psVectorInit (flux, 0.0);
    1403        
    1404         for (int i = 0; i < stamps->num; i++) {
    1405             pmSubtractionStamp *stamp = stamps->stamps->data[i];
    1406             if (!isfinite(stamp->flux)) continue;
    1407             flux->data.F32[i] = stamp->flux;
    1408         }
    1409 
    1410         psVector *index = psVectorSortIndex(NULL, flux);
    1411         for (int i = 0; (i < stamps->num) && (i < 9); i++) {
    1412             int n = stamps->num - i - 1;
    1413             keepStamps->data.S32[index->data.S32[n]] = 1;
    1414             fprintf (stderr, "keeping %d (%d of %d)\n", index->data.S32[n], n, 9);
    1415         }
    1416         psFree (flux);
    1417         psFree (index);
    1418 
    1419         // this function is called multiple times in the iteration, but
    1420         // we only know after the interation is done if we will try again.
    1421         // therefore we must save the sample each time, and blow away the old one
    1422         // if it exists.
    1423         psFree (kernels->sampleStamps);
    1424         kernels->sampleStamps = psArrayAllocEmpty(9);
     1400    {
     1401        psVector *flux  = psVectorAlloc(stamps->num, PS_TYPE_F32);
     1402        psVectorInit (flux, 0.0);
     1403
     1404        for (int i = 0; i < stamps->num; i++) {
     1405            pmSubtractionStamp *stamp = stamps->stamps->data[i];
     1406            if (!isfinite(stamp->flux)) continue;
     1407            flux->data.F32[i] = stamp->flux;
     1408        }
     1409
     1410        psVector *index = psVectorSortIndex(NULL, flux);
     1411        for (int i = 0; (i < stamps->num) && (i < 9); i++) {
     1412            int n = stamps->num - i - 1;
     1413            keepStamps->data.S32[index->data.S32[n]] = 1;
     1414            fprintf (stderr, "keeping %d (%d of %d)\n", index->data.S32[n], n, 9);
     1415        }
     1416        psFree (flux);
     1417        psFree (index);
     1418
     1419        // this function is called multiple times in the iteration, but
     1420        // we only know after the interation is done if we will try again.
     1421        // therefore we must save the sample each time, and blow away the old one
     1422        // if it exists.
     1423        psFree (kernels->sampleStamps);
     1424        kernels->sampleStamps = psArrayAllocEmpty(9);
    14251425    }
    14261426
     
    14981498            }
    14991499
    1500             if (keepStamps->data.S32[i]) {
    1501                 psImage *sample = psImageCopy(NULL, residual->image, PS_TYPE_F32);
    1502                 psArrayAdd (kernels->sampleStamps, 9, sample);
    1503                 psFree (sample);
    1504             }
    1505 
    1506             pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, target, source, residual, norm, footprint);
     1500            if (keepStamps->data.S32[i]) {
     1501                psImage *sample = psImageCopy(NULL, residual->image, PS_TYPE_F32);
     1502                psArrayAdd (kernels->sampleStamps, 9, sample);
     1503                psFree (sample);
     1504            }
     1505
     1506            pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, target, source, residual, norm, footprint);
    15071507
    15081508        } else {
     
    15341534                }
    15351535            }
    1536             if (keepStamps->data.S32[i]) {
    1537                 psImage *sample = psImageCopy(NULL, residual->image, PS_TYPE_F32);
    1538                 psArrayAdd (kernels->sampleStamps, 9, sample);
    1539                 psFree (sample);
    1540             }
    1541 
    1542             pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, image1, image2, residual, norm, footprint);
     1536            if (keepStamps->data.S32[i]) {
     1537                psImage *sample = psImageCopy(NULL, residual->image, PS_TYPE_F32);
     1538                psArrayAdd (kernels->sampleStamps, 9, sample);
     1539                psFree (sample);
     1540            }
     1541
     1542            pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, image1, image2, residual, norm, footprint);
    15431543        }
    15441544
Note: See TracChangeset for help on using the changeset viewer.