IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34353 for trunk/psphot/src


Ignore:
Timestamp:
Aug 24, 2012, 12:37:46 PM (14 years ago)
Author:
bills
Message:

Change psphotEfficiency to not fault if one of the readouts fails. Print message
clear the error and move on to next readout (if any).
When calculating the normilization and sourceRadius sample a number of points to avoid
failures if the input happens to not have pixels near the center of the image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotEfficiency.c

    r34319 r34353  
    5757    psFree(stats);
    5858
     59#ifndef USE_SINGLE_POINT_FOR_MODEL
    5960    // Need to normalise out difference between Gaussian and real PSF
     61    int sizeX = ro->variance->numCols / 16;
     62    int sizeY = ro->variance->numRows / 16;
     63    int numPoints = 0;
     64    float sum =  0;
     65    for (int y = sizeY * 0.5 ; y < ro->variance->numRows; y += sizeY) {
     66        for (int x = sizeX * 0.5 ; x < ro->variance->numCols; x += sizeX) {
     67            pmModel *normModel = pmModelFromPSFforXY(psf, (float) x, (float) y, 1.0); // model for normalization
     68
     69            if (!normModel || (normModel->flags & MODEL_MASK)) {
     70                psFree(normModel);
     71                continue;
     72            }
     73            float flux = normModel->modelFlux(normModel->params); // Total flux for peak of 1.0
     74            psFree(normModel);
     75            if (!isfinite(flux)) {
     76                continue;
     77            }
     78            numPoints++;
     79            sum += flux;
     80        }
     81    }
     82    if (!isfinite(sum) || numPoints == 0) {
     83        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate PSF model for any of %d points.", sizeX * sizeY);
     84        return false;
     85    }
     86    *norm = sum / numPoints;
     87#else
     88    // This can fail for readout that has few good pixels. It's better to sample many points.
    6089    pmModel *normModel = pmModelFromPSFforXY(psf, 0.5 * ro->variance->numCols,
    61                                              0.5 * ro->variance->numRows, 1.0); // Model for normalisation
     90                                         0.5 * ro->variance->numRows, 1.0); // Model for normalisation
     91    psFree(normModel);
    6292    if (!normModel || (normModel->flags & MODEL_MASK)) {
    6393        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate PSF model.");
     
    6797    *norm = normModel->modelFlux(normModel->params); // Total flux for peak of 1.0
    6898    psFree(normModel);
     99#endif
    69100
    70101    // The signal-to-noise of the smoothed image is: S/N ~ I_smooth / sqrt(variance * factor)
     
    188219        if (!psphotEfficiencyReadout (config, view, filerule, i, recipe)) {
    189220            psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for %s entry %d", filerule, i);
    190             return false;
     221            psErrorStackPrint(stderr, " ");
     222            psErrorClear();
     223            // send message to log as well
     224            psLogMsg ("psphot", PS_LOG_WARN, "failed to measure detection efficiency for %s entry %d", filerule, i);
    191225        }
    192226    }
     
    376410        float mag = magLim + magOffsets->data.F32[i]; // Magnitude for bin
    377411        float peak = powf(10.0, -0.4 * mag) / norm;   // Peak flux
     412#ifndef USE_SINGLE_POINT_FOR_MODEL
     413        int sizeX = numCols / 16;
     414        int sizeY = numRows / 16;
     415        int numPoints = 0;
     416        float sum =  0;
     417        for (int y = sizeY * 0.5 ; y < numRows; y += sizeY) {
     418            for (int x = sizeX * 0.5 ; x < numCols; x += sizeX) {
     419                // Need to normalise out difference between Gaussian and real PSF
     420                pmModel *model = pmModelFromPSFforXY(psf, (float) x, (float) y, peak);
     421
     422                if (!model || (model->flags & MODEL_MASK)) {
     423                    psFree(model);
     424                    continue;
     425                }
     426                float sourceRadius = PS_MAX(radius, model->modelRadius(model->params, minFlux)); // Radius for source
     427                psFree(model);
     428                if (!isfinite(sourceRadius)) {
     429                    continue;
     430                }
     431                numPoints++;
     432                sum += sourceRadius;
     433            }
     434        }
     435        if (!isfinite(sum) || numPoints == 0) {
     436            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate PSF model for any of %d points.", sizeX * sizeY);
     437            return false;
     438        }
     439        float sourceRadius = sum / numPoints;
     440#else
     441        // This old way can fail for heavily masked images
    378442        pmModel *model = pmModelFromPSFforXY(psf, numCols / 2.0, numRows / 2.0, peak); // Model for source
    379443        if (!model || (model->flags & MODEL_MASK)) {
     
    384448        float sourceRadius = PS_MAX(radius, model->modelRadius(model->params, minFlux)); // Radius for source
    385449        psFree(model);
     450#endif
    386451
    387452        psArray *sources = psArrayAllocEmpty(numSources); // Sources in this bin
Note: See TracChangeset for help on using the changeset viewer.