IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26593


Ignore:
Timestamp:
Jan 14, 2010, 10:10:51 AM (16 years ago)
Author:
eugene
Message:

clean up residual stats calculation; add sample residual image support; change normalization to use rms not max for odd terms

Location:
branches/eam_branches/20091201/psModules/src/imcombine
Files:
4 edited

Legend:

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

    r26585 r26593  
    117117    }
    118118
     119    // sample difference images
     120    {
     121        psMetadataAddArray(analysis, PS_LIST_TAIL, "SUBTRACTION.SAMPLE.STAMP.SET", PS_META_DUPLICATE_OK, "Sample Difference Stamps", kernels->sampleStamps);
     122    }
    119123
    120124#ifdef TESTING
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c

    r26586 r26593  
    13311331}
    13321332
     1333bool pmSubtractionResidualStats(psVector *fSigRes, psVector *fMaxRes, psVector *fMinRes, psKernel *target, psKernel *source, psKernel *residual, double norm, int footprint) {
     1334
     1335    // XXX measure some useful stats on the residuals
     1336    float sum = 0.0;
     1337    float peak = 0.0;
     1338    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        }
     1343    }
     1344
     1345    // only count pixels with more than X% of the source flux
     1346    // calculate stdev(dflux)
     1347    float dflux1 = 0.0;
     1348    float dflux2 = 0.0;
     1349    int npix = 0;
     1350
     1351    float dmax = 0.0;
     1352    float dmin = 0.0;
     1353
     1354    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        }
     1364    }
     1365    float sigma = sqrt(dflux2 / npix - PS_SQR(dflux1/npix));
     1366    // fprintf (stderr, "sum: %f, peak: %f, sigma: %f, fsigma: %f, fmax: %f, fmin: %f\n", sum, peak, sigma, sigma/sum, dmax/peak, dmin/peak);
     1367    psVectorAppend(fSigRes, sigma/sum);
     1368    psVectorAppend(fMaxRes, dmax/peak);
     1369    psVectorAppend(fMinRes, dmin/peak);
     1370    return true;
     1371}
     1372
    13331373psVector *pmSubtractionCalculateDeviations(pmSubtractionStampList *stamps,
    13341374                                           pmSubtractionKernels *kernels)
     
    13531393    psVector *fMinRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    13541394    psVector *fMaxRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
     1395
     1396    // we want to save the residual images for the 9 brightest stamps.
     1397    // identify the 9 brightest stamps
     1398    psVector *keepStamps  = psVectorAlloc(stamps->num, PS_TYPE_S32);
     1399    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);
     1425    }
    13551426
    13561427    for (int i = 0; i < stamps->num; i++) {
     
    14271498            }
    14281499
    1429             // XXX measure some useful stats on the residuals
    1430             float sum = 0.0;
    1431             float peak = 0.0;
    1432             for (int y = - footprint; y <= footprint; y++) {
    1433                 for (int x = - footprint; x <= footprint; x++) {
    1434                     sum += 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
    1435                     peak = PS_MAX(peak, 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm));
    1436                 }
    1437             }
    1438 
    1439             // only count pixels with more than X% of the source flux
    1440             // calculate stdev(dflux)
    1441             float dflux1 = 0.0;
    1442             float dflux2 = 0.0;
    1443             int npix = 0;
    1444 
    1445             float dmax = 0.0;
    1446             float dmin = 0.0;
    1447 
    1448             for (int y = - footprint; y <= footprint; y++) {
    1449                 for (int x = - footprint; x <= footprint; x++) {
    1450                     float dflux = 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
    1451                     if (dflux < 0.02*sum) continue;
    1452                     dflux1 += residual->kernel[y][x];
    1453                     dflux2 += PS_SQR(residual->kernel[y][x]);
    1454                     dmax = PS_MAX(residual->kernel[y][x], dmax);
    1455                     dmin = PS_MIN(residual->kernel[y][x], dmin);
    1456                     npix ++;
    1457                 }
    1458             }
    1459             float sigma = sqrt(dflux2 / npix - PS_SQR(dflux1/npix));
    1460             // fprintf (stderr, "sum: %f, peak: %f, sigma: %f, fsigma: %f, fmax: %f, fmin: %f\n", sum, peak, sigma, sigma/sum, dmax/peak, dmin/peak);
    1461             psVectorAppend(fSigRes, sigma/sum);
    1462             psVectorAppend(fMaxRes, dmax/peak);
    1463             psVectorAppend(fMinRes, dmin/peak);
     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);
     1507
    14641508        } else {
    14651509            // Dual convolution
     
    14901534                }
    14911535            }
     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);
    14921543        }
    14931544
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionKernels.c

    r26590 r26593  
    2929    psFree(kernels->solution1);
    3030    psFree(kernels->solution2);
     31    psFree(kernels->sampleStamps);
    3132}
    3233
     
    226227    if (!forceZeroNull && ((uOrder % 2) || (vOrder % 2))) {
    227228        // Odd function
    228         scale2D = 1.0 / sqrt(sum2);
     229        scale2D = 1.0 / sqrt(sum2);
    229230    }
    230231
     
    573574    kernels->rms = NAN;
    574575    kernels->numStamps = 0;
     576    kernels->sampleStamps = NULL;
    575577
    576578    kernels->fSigResMean  = NAN;
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionKernels.h

    r26575 r26593  
    5555    float fMinResMean;                  ///< mean fractional negative swing in residuals
    5656    float fMinResStdev;                 ///< stdev of fractional negative swing in residuals
     57    psArray *sampleStamps;              ///< array of brightest set of stamps for output visualizations
    5758} pmSubtractionKernels;
    5859
Note: See TracChangeset for help on using the changeset viewer.