IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21096


Ignore:
Timestamp:
Jan 9, 2009, 9:15:03 AM (17 years ago)
Author:
Paul Price
Message:

Attempting to explicitly set normalisation of input images after convolution. It may be that the PSF matching is not getting the normalisation as correct as we would like.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_20090108/ppStack/src/ppStackMatch.c

    r21021 r21096  
    1616#define FAINT_SOURCE_FRAC 1.0e-4         // Set minimum flux to this fraction of faintest source flux
    1717
    18 //#define TESTING                         // Enable debugging output
     18#define TESTING                         // Enable debugging output
    1919
    2020#ifdef TESTING
     
    104104
    105105// Generate a background model of the readout we're matching
     106// We only need to set the background around the sources, not everywhere.
    106107psImage *stackBackgroundModel(pmReadout *ro, psMaskType maskVal, const psArray *sources, int size)
    107108{
     
    355356            psFree(bgImage);
    356357
    357 
    358358#ifdef TESTING
    359359            {
     
    580580    psFree(bg);
    581581
     582#define RADIUS 10                       // Radius of photometry
     583#define MIN_ERR 0.05                    // Minimum photometric error, mag
     584
     585    // Ensure the normalisation is correct
     586    // XXX Ideally, would like to do proper PSF-fit photometry, but will settle for aperture photometry
     587    int numSources = sources->n;        // Number of sources
     588    psVector *ratio = psVectorAlloc(numSources, PS_TYPE_F32); // Flux ratios for sources
     589    psVector *ratioMask = psVectorAlloc(numSources, PS_TYPE_MASK); // Mask for flux ratios
     590    psVectorInit(ratioMask, 0xFF);
     591    psImage *image = readout->image;    // Image of interest
     592    psImage *mask = readout->mask;      // Mask of interest
     593    int numCols = image->numCols, numRows = image->numRows; // Size of image
     594    for (int i = 0; i < numSources; i++) {
     595        pmSource *source = sources->data[i]; // Source of interest
     596        if (!source || source->mode & SOURCE_MASK || !isfinite(source->psfMag) || !isfinite(source->errMag) ||
     597            source->errMag > MIN_ERR) {
     598            continue;
     599        }
     600
     601        float xSrc = source->peak->xf, ySrc = source->peak->yf; // Source coordinates
     602        int xMin = PS_MAX(0, xSrc - RADIUS), xMax = PS_MIN(numCols - 1, xSrc + RADIUS); // Bounds in x
     603        int yMin = PS_MAX(0, ySrc - RADIUS), yMax = PS_MIN(numRows - 1, ySrc + RADIUS); // Bounds in y
     604        int numPix = 0;                 // Number of pixels
     605        float sum = 0.0;                // Sum of pixels
     606        for (int y = yMin; y <= yMax; y++) {
     607            for (int x = xMin; x <= xMax; x++) {
     608                if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskBad) {
     609                    continue;
     610                }
     611                sum += image->data.F32[y][x];
     612                numPix++;
     613            }
     614        }
     615        if (sum >= 0 && numPix > 0) {
     616            float mag = -2.5 * log10(sum * M_PI * PS_SQR(RADIUS) / numPix); // Instrumental magnitude
     617            ratio->data.F32[i] = mag - source->psfMag;
     618            ratioMask->data.PS_TYPE_MASK_DATA[i] = 0;
     619        }
     620    }
     621
     622    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics
     623    if (!psVectorStats(stats, ratio, NULL, ratioMask, 0xFF)) {
     624        psWarning("Unable to measure normalisation --- assuming correct.");
     625    } else {
     626        psLogMsg("ppStack", PS_LOG_INFO, "Renormalising image by %f (+/- %f) mag\n",
     627                 stats->robustMedian, stats->robustStdev);
     628        float norm = powf(10.0, -0.4 * stats->robustMedian); // Normalisation to apply
     629        psBinaryOp(image, image, "*", psScalarAlloc(norm, PS_TYPE_F32));
     630    }
     631    psFree(stats);
     632    psFree(ratio);
     633    psFree(ratioMask);
     634
     635#ifdef TESTING
     636    {
     637        psString name = NULL;
     638        psStringAppend(&name, "convolved_%03d.fits", numInput);
     639        psFits *fits = psFitsOpen(name, "w");
     640        psFree(name);
     641        psFitsWriteImage(fits, NULL, output->image, 0, NULL);
     642        psFitsClose(fits);
     643    }
     644#endif
     645
    582646    psFree(output);
    583647
Note: See TracChangeset for help on using the changeset viewer.