IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 12, 2010, 12:38:23 PM (16 years ago)
Author:
eugene
Message:

re-scale kernels by fwhm2 to avoid excessive dynamic range; modify residual stats to be more sensible; add threshold to min significant element of SVD inversion (1e-6); adjust penalties again (still not clear what is best...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100823/psModules/src/imcombine/pmSubtractionEquation.c

    r29126 r29148  
    972972            pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
    973973            if (stamp->status == PM_SUBTRACTION_STAMP_USED) {
     974               
    974975                (void)psBinaryOp(sumMatrix, sumMatrix, "+", stamp->matrix);
    975976                (void)psBinaryOp(sumVector, sumVector, "+", stamp->vector);
     977
    976978                psVectorAppend(norms, stamp->norm);
     979
    977980                pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green");
    978981                numStamps++;
     
    11071110        }
    11081111
    1109 #ifdef TESTING
    1110         psFitsWriteImageSimple ("sumMatrix.fits", sumMatrix, NULL);
     1112#if 0
     1113        psImage *save = psImageCopy(NULL, sumMatrix, PS_TYPE_F32);
     1114        psFitsWriteImageSimple ("sumMatrix.fits", save, NULL);
    11111115        psVectorWriteFile("sumVector.dat", sumVector);
     1116        psFree (save);
    11121117#endif
    11131118
     
    11911196            sumVector->data.F64[normIndex] = 0.0;
    11921197
    1193             solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN);
    1194 
     1198// save the matrix and vector after the NULLs have been set
     1199#if 0
     1200            psImage *save = psImageCopy(NULL, sumMatrix, PS_TYPE_F32);
     1201            psFitsWriteImageSimple ("sumMatrix.fits", save, NULL);
     1202            psVectorWriteFile("sumVector.dat", sumVector);
     1203            psFree (save);
     1204#endif
     1205
     1206            solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-6);
     1207            // solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 3e-4);
     1208            // psVectorCopy (solution, sumVector, PS_TYPE_F64);
     1209            // psMatrixGJSolve(sumMatrix, solution);
    11951210            solution->data.F64[normIndex] = normValue;
    11961211        }
     
    12651280}
    12661281
    1267 bool pmSubtractionResidualStats(psVector *fSigRes, psVector *fMaxRes, psVector *fMinRes, psKernel *target, psKernel *source, psKernel *residual, double norm, int footprint) {
    1268 
    1269     // XXX measure some useful stats on the residuals
     1282// measure some useful stats on the stamp residuals:
     1283// fResSigma : the residual stdev / total flux
     1284// fResOuter : the residual fabs / total flux for R > 2 pix
     1285// fResTotal : the residual fabs / total flux for R > 0 pix
     1286bool pmSubtractionResidualStats(psVector *fResSigma, psVector *fResOuter, psVector *fResTotal, psKernel *target, psKernel *source, psKernel *residual, double norm, int footprint) {
     1287
    12701288    float sum = 0.0;
    12711289    float peak = 0.0;
     
    12771295    }
    12781296
    1279     // only count pixels with more than X% of the source flux
    1280     // calculate stdev(dflux)
     1297    // init counters
     1298    int npix = 0;
    12811299    float dflux1 = 0.0;
    12821300    float dflux2 = 0.0;
    1283     int npix = 0;
    1284 
    1285     float dmax = 0.0;
    1286     float dmin = 0.0;
    1287 
    1288     // XXX update these with a bit more rigour
     1301    float dOuter = 0.0;
     1302    float dTotal = 0.0;
     1303
    12891304    for (int y = - footprint; y <= footprint; y++) {
    12901305        for (int x = - footprint; x <= footprint; x++) {
    1291           // float dflux = 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm);
    1292             // if (dflux < 0.02*sum) continue;
    12931306            dflux1 += residual->kernel[y][x];
    12941307            dflux2 += PS_SQR(residual->kernel[y][x]);
    1295             // dmax = PS_MAX(residual->kernel[y][x], dmax);
    1296             // dmin = PS_MIN(residual->kernel[y][x], dmin);
    1297             dmax += fabs(residual->kernel[y][x]);
    1298 
     1308            dTotal += fabs(residual->kernel[y][x]);
    12991309            if (hypot(x,y) > 2.0) {
    1300               dmin += fabs(residual->kernel[y][x]);
     1310              dOuter += fabs(residual->kernel[y][x]);
    13011311            }
    13021312            npix ++;
     
    13051315    float sigma = sqrt(dflux2 / npix - PS_SQR(dflux1/npix));
    13061316    if (!isfinite(sum))  return false;
    1307     if (!isfinite(dmax)) return false;
    1308     if (!isfinite(dmin)) return false;
    13091317    if (!isfinite(peak)) return false;
    1310 
    1311     fprintf (stderr, "sum: %f, peak: %f, sigma: %f, fsigma: %f, fmax: %f, fmin: %f\n", sum, peak, sigma, sigma/sum, dmax/sum, dmin/sum);
    1312     psVectorAppend(fSigRes, sigma/sum);
    1313     psVectorAppend(fMaxRes, dmax/sum);
    1314     psVectorAppend(fMinRes, dmin/sum);
     1318    if (!isfinite(dOuter)) return false;
     1319    if (!isfinite(dTotal)) return false;
     1320
     1321    fprintf (stderr, "sum: %f, peak: %f, sigma: %f, fsigma: %f, fmax: %f, fmin: %f\n", sum, peak, sigma, sigma/sum, dOuter/sum, dTotal/sum);
     1322    psVectorAppend(fResSigma, sigma/sum);
     1323    psVectorAppend(fResOuter, dOuter/sum);
     1324    psVectorAppend(fResTotal, dTotal/sum);
    13151325    return true;
    13161326}
     
    13351345    pmSubtractionVisualShowFitInit (stamps);
    13361346
    1337     psVector *fSigRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    1338     psVector *fMinRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    1339     psVector *fMaxRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
     1347    psVector *fResSigma = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
     1348    psVector *fResOuter = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
     1349    psVector *fResTotal = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    13401350
    13411351    // we want to save the residual images for the 9 brightest stamps.
     
    14491459            }
    14501460
    1451             pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, target, source, residual, norm, footprint);
     1461            pmSubtractionResidualStats(fResSigma, fResOuter, fResTotal, target, source, residual, norm, footprint);
    14521462
    14531463        } else {
     
    14851495            }
    14861496
    1487             pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, image1, image2, residual, norm, footprint);
     1497            pmSubtractionResidualStats(fResSigma, fResOuter, fResTotal, image1, image2, residual, norm, footprint);
    14881498        }
    14891499
     
    15641574
    15651575        psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    1566         psVectorStats (stats, fSigRes, NULL, NULL, 0);
    1567         kernels->fSigResMean = stats->robustMedian;
    1568         kernels->fSigResStdev = stats->robustStdev;
     1576        psVectorStats (stats, fResSigma, NULL, NULL, 0);
     1577        kernels->fResSigmaMean = stats->robustMedian;
     1578        kernels->fResSigmaStdev = stats->robustStdev;
    15691579
    15701580        psStatsInit (stats);
    1571         psVectorStats (stats, fMaxRes, NULL, NULL, 0);
    1572         kernels->fMaxResMean = stats->robustMedian;
    1573         kernels->fMaxResStdev = stats->robustStdev;
     1581        psVectorStats (stats, fResOuter, NULL, NULL, 0);
     1582        kernels->fResOuterMean = stats->robustMedian;
     1583        kernels->fResOuterStdev = stats->robustStdev;
    15741584
    15751585        psStatsInit (stats);
    1576         psVectorStats (stats, fMinRes, NULL, NULL, 0);
    1577         kernels->fMinResMean = stats->robustMedian;
    1578         kernels->fMinResStdev = stats->robustStdev;
     1586        psVectorStats (stats, fResTotal, NULL, NULL, 0);
     1587        kernels->fResTotalMean = stats->robustMedian;
     1588        kernels->fResTotalStdev = stats->robustStdev;
    15791589
    15801590        // XXX save these values somewhere
    1581         psLogMsg("psModules.imcombine", PS_LOG_INFO, "fSigma: %f +/- %f, fMaxRes: %f +/- %f, fMinRes: %f +/- %f",
    1582                  kernels->fSigResMean, kernels->fSigResStdev,
    1583                  kernels->fMaxResMean, kernels->fMaxResStdev,
    1584                  kernels->fMinResMean, kernels->fMinResStdev);
    1585 
    1586         psFree (fSigRes);
    1587         psFree (fMaxRes);
    1588         psFree (fMinRes);
     1591        psLogMsg("psModules.imcombine", PS_LOG_INFO, "fResSigma: %f +/- %f, fResOuter: %f +/- %f, fResTotal: %f +/- %f",
     1592                 kernels->fResSigmaMean, kernels->fResSigmaStdev,
     1593                 kernels->fResOuterMean, kernels->fResOuterStdev,
     1594                 kernels->fResTotalMean, kernels->fResTotalStdev);
     1595
     1596        psFree (fResSigma);
     1597        psFree (fResOuter);
     1598        psFree (fResTotal);
    15891599        psFree (stats);
    15901600    }
     
    15921602    psFree(residual);
    15931603    psFree(polyValues);
    1594 
    15951604
    15961605    return deviations;
Note: See TracChangeset for help on using the changeset viewer.