IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17249


Ignore:
Timestamp:
Mar 31, 2008, 12:39:06 PM (18 years ago)
Author:
Paul Price
Message:

Adding assertion macros for readouts (about time too!). Adding function to renormalise the weight map to correspond to the measured image stdev.

Location:
trunk/psModules/src/camera
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPA.h

    r16396 r17249  
    66 * @author Eugene Magnier, IfA
    77 *
    8  * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2008-02-12 01:52:56 $
     8 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2008-03-31 22:39:06 $
    1010 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    1111 */
     
    178178bool pmFPACheckParents(pmFPA *fpa);     ///< FPA to check
    179179
     180
     181/// Assertions
     182
     183/// Check that the fundamentals of a readout are set
     184#define PM_ASSERT_READOUT_NON_NULL(READOUT, RETVAL) { \
     185    if (!(READOUT) || !(READOUT)->bias || !(READOUT)->analysis) { \
     186        psError(PS_ERR_UNEXPECTED_NULL, true, "Readout %s or one of its components is NULL.", #READOUT); \
     187        return RETVAL; \
     188    } \
     189    int numCols = 0, numRows = 0; /* Size of readout images */ \
     190    psImage *image = (READOUT)->image; /* Image pixels */ \
     191    if (image) { \
     192        PS_ASSERT_IMAGE_TYPE((READOUT)->image, PS_TYPE_F32, RETVAL); \
     193        numCols = image->numCols; \
     194        numRows = image->numRows; \
     195    } \
     196    psImage *mask = (READOUT)->mask; /* Mask pixels */ \
     197    if (mask) { \
     198        PS_ASSERT_IMAGE_NON_NULL((READOUT)->mask, RETVAL); \
     199        if ((numCols != 0 || numRows != 0) && (mask->numCols != numCols || mask->numRows != numRows)) { \
     200            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Mask in readout %s has wrong size (%dx%d vs %dx%d)", \
     201                    #READOUT, mask->numCols, mask->numRows, numCols, numRows); \
     202            return RETVAL; \
     203        } else { \
     204            numCols = mask->numCols; \
     205            numRows = mask->numRows; \
     206        } \
     207    } \
     208    psImage *weight = (READOUT)->weight; /* Weight map pixels */ \
     209    if (weight) { \
     210        PS_ASSERT_IMAGE_NON_NULL((READOUT)->weight, RETVAL); \
     211        if ((numCols != 0 || numRows != 0) && (weight->numCols != numCols || weight->numRows != numRows)) { \
     212            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Weight in readout %s has wrong size (%dx%d vs %dx%d)", \
     213                    #READOUT, weight->numCols, weight->numRows, numCols, numRows); \
     214            return RETVAL; \
     215        } \
     216    } \
     217}
     218
     219/// Assert that a readout contains an image
     220#define PM_ASSERT_READOUT_IMAGE(READOUT, RETVAL) \
     221    PS_ASSERT_IMAGE_NON_NULL((READOUT)->image, RETVAL);
     222
     223/// Assert that a readout contains a mask
     224#define PM_ASSERT_READOUT_MASK(READOUT, RETVAL) \
     225    PS_ASSERT_IMAGE_NON_NULL((READOUT)->mask, RETVAL);
     226
     227/// Assert that a readout contains a weight map
     228#define PM_ASSERT_READOUT_WEIGHT(READOUT, RETVAL) \
     229    PS_ASSERT_IMAGE_NON_NULL((READOUT)->weight, RETVAL);
     230
    180231/// @}
    181232#endif // #ifndef PM_FPA_H
  • trunk/psModules/src/camera/pmFPAMaskWeight.c

    r15307 r17249  
    305305    for (int i = 0; i < readouts->n; i++) {
    306306        pmReadout *readout = readouts->data[i]; // The readout
    307         pmReadoutGenerateMaskWeight(readout, poisson, satMask, badMask);
     307        success &= pmReadoutGenerateMaskWeight(readout, poisson, satMask, badMask);
    308308    }
    309309
     
    311311}
    312312
     313
     314bool pmReadoutWeightRenorm(const pmReadout *readout, psMaskType maskVal, psStatsOptions meanStat,
     315                           psStatsOptions stdevStat, int width, psRandom *rng)
     316{
     317    PM_ASSERT_READOUT_NON_NULL(readout, false);
     318    PM_ASSERT_READOUT_IMAGE(readout, false);
     319    PM_ASSERT_READOUT_WEIGHT(readout, false);
     320    PS_ASSERT_INT_POSITIVE(width, false);
     321
     322    if (!psMemIncrRefCounter(rng)) {
     323        rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     324    }
     325
     326    psImage *image = readout->image, *mask = readout->mask, *weight = readout->weight; // Readout images
     327    int numCols = image->numCols, numRows = image->numRows; // Size of images
     328    int xNum = numCols / width + 1, yNum = numRows / width + 1; // Number of renormalisation regions
     329    float xSize = numCols / (float)xNum, ySize = numRows / (float)yNum; // Size of renormalisation regions
     330
     331    psStats *meanStats = psStatsAlloc(meanStat), *stdevStats = psStatsAlloc(stdevStat); // Statistics
     332    psVector *buffer = NULL;
     333
     334    for (int j = 0; j < yNum; j++) {
     335        // Bounds in y
     336        int yMin = j * ySize;
     337        int yMax = (j + 1) * ySize;
     338        for (int i = 0; i < xNum; i++) {
     339            // Bounds in x
     340            int xMin = i * xSize;
     341            int xMax = (i + 1) * xSize;
     342
     343            psRegion region = psRegionSet(xMin, xMax, yMin, yMax); // Region of interest
     344            psImage *subImage = psImageSubset(image, region); // Sub-image of the image pixels
     345            psImage *subWeight = psImageSubset(weight, region); // Sub image of the weight pixels
     346            psImage *subMask = mask ? psImageSubset(mask, region) : NULL; // Sub-image of the mask pixels
     347
     348            if (!psImageBackground(stdevStats, &buffer, subImage, subMask, maskVal, rng) ||
     349                !psImageBackground(meanStats, &buffer, subWeight, subMask, maskVal, rng)) {
     350                // Nothing we can do about it, but don't want to keel over and die, so do our best to flag it.
     351                psString regionStr = psRegionToString(region); // String with region
     352                psWarning("Unable to measure statistics over %s", regionStr);
     353                psFree(regionStr);
     354                psErrorClear();
     355                psImageInit(subWeight, NAN);
     356                if (subMask) {
     357                    psImageInit(subMask, maskVal);
     358                }
     359            } else {
     360                float meanVar = psStatsGetValue(meanStats, meanStat); // Mean of variance map
     361                float stdev = psStatsGetValue(stdevStats, stdevStat); // Standard deviation of image
     362                psBinaryOp(subWeight, subWeight, "*", psScalarAlloc(PS_SQR(stdev) / meanVar, PS_TYPE_F32));
     363            }
     364
     365            psFree(subImage);
     366            psFree(subWeight);
     367            psFree(subMask);
     368        }
     369    }
     370    psFree(meanStats);
     371    psFree(stdevStats);
     372    psFree(rng);
     373    psFree(buffer);
     374
     375    return true;
     376}
  • trunk/psModules/src/camera/pmFPAMaskWeight.h

    r13591 r17249  
    55 * @author Eugene Magnier, IfA
    66 *
    7  * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-06-02 03:51:03 $
     7 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2008-03-31 22:39:06 $
    99 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    9393                              bool poisson ///< Use poisson weights (in addition to read noise)?
    9494                             );
     95
     96/// Renormalise the weight map to match the actual variance
     97///
     98/// The variance in the image is measured in patches, and the variance map is adjusted so that the mean for
     99/// that patch corresponds.
     100bool pmReadoutWeightRenorm(const pmReadout *readout, // Readout to normalise
     101                           psMaskType maskVal, // Value to mask
     102                           psStatsOptions meanStat, // Statistic to measure the mean (of the variance map)
     103                           psStatsOptions stdevStat, // Statistic to measure the stdev (of the image)
     104                           int width,   // Width of patch (pixels)
     105                           psRandom *rng // Random number generator (for sub-sampling images)
     106    );
     107
     108
     109
    95110/// @}
    96111#endif
Note: See TracChangeset for help on using the changeset viewer.