IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2006, 2:55:23 PM (20 years ago)
Author:
Paul Price
Message:

Addition of a vast quantity of assertions in public functions. Adopted a policy of using assert() within file-static functions (since they are only called internally, any errors there are problems with the program) and using the PS_ASSERT_WHATEVER() macros within public functions. Cleaned a few things up in the process.

Location:
trunk/psModules/src/detrend
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmFlatField.c

    r6873 r7278  
    1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
    3 // one that was being worked on.
    4 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    5 
    6 
    71/** @file  pmFlatField.c
    82 *
     
    2418 *  @author Ross Harman, MHPCC
    2519 *
    26  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    27  *  @date $Date: 2006-04-17 18:10:08 $
     20 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     21 *  @date $Date: 2006-06-02 00:55:23 $
    2822 *
    2923 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4640bool pmFlatField(pmReadout *in, const pmReadout *flat)
    4741{
    48     int i = 0;
    49     int j = 0;
     42    PS_ASSERT_PTR_NON_NULL(in, false);
     43    PS_ASSERT_PTR_NON_NULL(in->image, false);
     44    PS_ASSERT_IMAGE_NON_EMPTY(in->image, false);
     45    PS_ASSERT_PTR_NON_NULL(flat, false);
     46    PS_ASSERT_PTR_NON_NULL(flat->image, false);
     47    PS_ASSERT_IMAGE_NON_EMPTY(flat->image, false);
     48    if (in->mask) {
     49        PS_ASSERT_IMAGE_TYPE(in->mask, PS_TYPE_U8, false);
     50    }
     51    PS_ASSERT_IMAGE_TYPE(flat->image, in->image->type.type, false);
     52
    5053    int totOffCol = 0;
    5154    int totOffRow = 0;
     
    147150
    148151    // Macro for all PS types
    149     #define PM_FLAT_DIVISION(TYPE)                                                                           \
    150 case PS_TYPE_##TYPE:                                                                                         \
    151     /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */  \
    152     for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
    153         for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
    154             if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
    155                 /* Negative or zero flat pixels shall be masked in input image as  PM_MASK_FLAT */           \
    156                 if (inMask) {                                                                                \
    157                     inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT;                                    \
    158                 }                                                                                            \
    159                 flatImage->data.TYPE[j][i] = 0.0;                                                            \
    160             }                                                                                                \
    161         }                                                                                                    \
    162     }                                                                                                        \
    163     for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
    164         for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
    165             if(inMask && !inMask->data.PS_TYPE_MASK_DATA[j][i]) {                                            \
    166                 /* Module shall divide the input image by the flat-fielded image */                          \
    167                 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
    168             }                                                                                                \
    169         }                                                                                                    \
    170     }                                                                                                        \
     152    #define FLAT_DIVISION_CASE(TYPE) \
     153case PS_TYPE_##TYPE: \
     154    for (long j = totOffRow; j < inImage->numRows; j++) { \
     155        for (long i = totOffCol; i < inImage->numCols; i++) { \
     156            if (flatImage->data.TYPE[j][i] <= 0.0) { \
     157                if (inMask) { \
     158                    inMask->data.U8[j][i] |= PM_MASK_FLAT; \
     159                } \
     160                flatImage->data.TYPE[j][i] = 0.0; \
     161            } else { \
     162                if (!inMask || !inMask->data.U8[j][i]) { \
     163                    inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \
     164                } \
     165            } \
     166        } \
     167    } \
    171168    break;
    172169
    173170    switch(inType) {
    174         PM_FLAT_DIVISION(U8);
    175         PM_FLAT_DIVISION(U16);
    176         PM_FLAT_DIVISION(U32);
    177         PM_FLAT_DIVISION(U64);
    178         PM_FLAT_DIVISION(S8);
    179         PM_FLAT_DIVISION(S16);
    180         PM_FLAT_DIVISION(S32);
    181         PM_FLAT_DIVISION(S64);
    182         PM_FLAT_DIVISION(F32);
    183         PM_FLAT_DIVISION(F64);
     171        FLAT_DIVISION_CASE(U8);
     172        FLAT_DIVISION_CASE(U16);
     173        FLAT_DIVISION_CASE(U32);
     174        FLAT_DIVISION_CASE(U64);
     175        FLAT_DIVISION_CASE(S8);
     176        FLAT_DIVISION_CASE(S16);
     177        FLAT_DIVISION_CASE(S32);
     178        FLAT_DIVISION_CASE(S64);
     179        FLAT_DIVISION_CASE(F32);
     180        FLAT_DIVISION_CASE(F64);
    184181    default:
    185182        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
  • trunk/psModules/src/detrend/pmFlatField.h

    r6872 r7278  
    1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
    3 // one that was being worked on.
    4 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    5 
    6 
    71/** @file  pmFlatField.h
    82 *
     
    2418 *  @author Ross Harman, MHPCC
    2519 *
    26  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    27  *  @date $Date: 2006-04-17 18:01:05 $
     20 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     21 *  @date $Date: 2006-06-02 00:55:23 $
    2822 *
    2923 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psModules/src/detrend/pmFlatNormalize.c

    r7179 r7278  
    1515                         )
    1616{
     17    PS_ASSERT_PTR_NON_NULL(chipGains, NULL);
     18    PS_ASSERT_PTR_NON_NULL(fluxLevels, NULL);
     19
    1720    int numSources = fluxLevels->numRows; // Number of integrations
    1821    int numChips = fluxLevels->numCols; // Number of chips with which each integration is made
  • trunk/psModules/src/detrend/pmFringeStats.c

    r7126 r7278  
    33 *  @author Eugene Magnier, IfA
    44 *
    5  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-05-17 00:55:35 $
     5 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-02 00:55:23 $
    77 *
    88 *  Copyright 2004 IfA
     
    6161bool pmFringeRegionsCreatePoints(pmFringeRegions *fringe, const psImage *image)
    6262{
     63    PS_ASSERT_PTR_NON_NULL(fringe, false);
     64    PS_ASSERT_PTR_NON_NULL(image, false);
     65    PS_ASSERT_IMAGE_NON_EMPTY(image, false);
    6366
    6467    double frnd;
     
    106109pmFringeStats *pmFringeStatsAlloc(pmFringeRegions *regions)
    107110{
     111    PS_ASSERT_PTR_NON_NULL(regions, false);
     112
    108113    pmFringeStats *stats = psAlloc(sizeof(pmFringeStats));
    109114    (void)psMemSetDeallocator(stats, (psFreeFunc)fringeStatsFree);
     
    120125pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, pmReadout *readout, psMaskType maskVal)
    121126{
     127    PS_ASSERT_PTR_NON_NULL(fringe, NULL);
     128    PS_ASSERT_PTR_NON_NULL(readout, NULL);
     129    PS_ASSERT_PTR_NON_NULL(readout->image, NULL);
     130    PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL);
     131
    122132    if (!fringe->x || !fringe->y) {
    123133        // create the fringe vectors for this image
     
    364374                                    unsigned int nIter, float keepFrac)
    365375{
     376    PS_ASSERT_PTR_NON_NULL(science, NULL);
     377    PS_ASSERT_PTR_NON_NULL(fringes, NULL);
     378    PS_ASSERT_INT_POSITIVE(fringes->n, NULL);
     379    PS_ASSERT_INT_POSITIVE(nIter, NULL);
     380
    366381    pmFringeRegions *regions = science->regions; // The fringe regions
    367382    int numRegions = regions->nRequested; // Number of regions
     
    439454                         unsigned int nIter, float keepFrac)
    440455{
     456    PS_ASSERT_PTR_NON_NULL(readout, NULL);
     457    PS_ASSERT_PTR_NON_NULL(readout->image, NULL);
     458    PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL);
     459    PS_ASSERT_PTR_NON_NULL(fringes, NULL);
     460    PS_ASSERT_PTR_NON_NULL(fringeImages, NULL);
     461    PS_ASSERT_PTR_NON_NULL(fringeStats, NULL);
     462    PS_ASSERT_INT_EQUAL(fringeImages->n, fringeStats->n, NULL);
     463    PS_ASSERT_INT_POSITIVE(nIter, NULL);
     464
    441465    // measure the fringe stats for the science frame and solve for the scales
    442466    pmFringeStats *scienceStats = pmFringeStatsMeasure(fringes, readout, maskVal);
  • trunk/psModules/src/detrend/pmSubtractBias.c

    r7018 r7278  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-05-01 01:56:29 $
     13 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-06-02 00:55:23 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    146146
    147147
    148 #if 0
    149 /******************************************************************************
    150 ImageSubtractScalar(): subtract a scalar from the input image.
    151  
    152 XXX: Use a psLib function for this.
    153  
    154 XXX: This should
    155  *****************************************************************************/
    156 static psImage *ImageSubtractScalar(psImage *image,
    157                                     psF32 scalar)
    158 {
    159     for (psS32 i=0;i<image->numRows;i++) {
    160         for (psS32 j=0;j<image->numCols;j++) {
    161             image->data.F32[i][j]-= scalar;
    162         }
    163     }
    164     return(image);
    165 }
    166 #endif
    167 
    168148/******************************************************************************
    169149GenNewStatOptions(): this routine will take as input the options member of the
     
    175155static psStatsOptions GenNewStatOptions(const psStats *stat)
    176156{
     157    assert(stat);
     158
    177159    psS32 numOptions = 0;
    178160    psStatsOptions opt = 0;
     
    210192    if (numOptions != 1) {
    211193        psLogMsg(__func__, PS_LOG_WARN,
    212                  "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options have been specified\n");
    213     }
    214     return(opt);
    215 }
    216 
    217 
    218 
    219 #if 0
    220 /******************************************************************************
    221 ScaleOverscanVector(): this routine takes as input an arbitrary vector,
    222 creates a new vector of length n, and fills the new vector with the
    223 interpolated values of the old vector.  The type of interpolation is:
    224     PM_FIT_POLYNOMIAL: fit a polynomial to the entire input vector data.
    225     PM_FIT_SPLINE: fit splines to the input vector data.
    226 XXX: Doesn't it make more sense to do polynomial interpolation on a few
    227 elements of the input vector, rather than fit a polynomial to the entire
    228 vector?
    229  *****************************************************************************/
    230 static psVector *ScaleOverscanVector(psVector *overscanVector,
    231                                      psS32 n,
    232                                      void *fitSpec,
    233                                      pmFit fit)
    234 {
    235     psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4,
    236             "---- ScaleOverscanVector() begin (%d -> %d) ----\n", overscanVector->n, n);
    237     //    PS_VECTOR_PRINT_F32(overscanVector);
    238 
    239     if (NULL == overscanVector) {
    240         return(overscanVector);
    241     }
    242 
    243     // Allocate the new vector.
    244     psVector *newVec = psVectorAlloc(n, PS_TYPE_F32);
    245 
    246     //
    247     // If the new vector is the same size as the old, simply copy the data.
    248     //
    249     if (n == overscanVector->n) {
    250         for (psS32 i = 0 ; i < n ; i++) {
    251             newVec->data.F32[i] = overscanVector->data.F32[i];
    252         }
    253         return(newVec);
    254     }
    255     psPolynomial1D *myPoly;
    256     psSpline1D *mySpline;
    257     psF32 x;
    258     psS32 i;
    259     if (fit == PM_FIT_POLYNOMIAL) {
    260         // Fit a polynomial to the old overscan vector.
    261         myPoly = (psPolynomial1D *) fitSpec;
    262         PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
    263         myPoly = psVectorFitPolynomial1D(myPoly, NULL, 0, overscanVector, NULL, NULL);
    264         if (myPoly == NULL) {
    265             psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector()(1): Could not fit a polynomial to the psVector.\n");
    266             return(NULL);
    267         }
    268 
    269         // For each element of the new vector, convert the x-ordinate to that
    270         // of the old vector, use the fitted polynomial to determine the
    271         // interpolated value at that point, and set the new vector.
    272         for (i=0;i<n;i++) {
    273             x = ((psF32) i) * ((psF32) overscanVector->n) / ((psF32) n);
    274             newVec->data.F32[i] = psPolynomial1DEval(myPoly, x);
    275         }
    276     } else if (fit == PM_FIT_SPLINE) {
    277         psS32 mustFreeSpline = 0;
    278         // Fit a spline to the old overscan vector.
    279         mySpline = (psSpline1D *) fitSpec;
    280         // XXX: Does it make any sense to have a psSpline argument?
    281         if (mySpline == NULL) {
    282             mustFreeSpline = 1;
    283         }
    284 
    285         //
    286         // NOTE: Since the X arg in the psVectorFitSpline1D() function is NULL,
    287         // splines endpoints will be from 0.0 to overscanVector->n-1.  Must scale
    288         // properly when doing the spline eval.
    289         //
    290         //        mySpline = psVectorFitSpline1D(mySpline, NULL, overscanVector, NULL);
    291         mySpline = psVectorFitSpline1D(NULL, overscanVector);
    292         if (mySpline == NULL) {
    293             psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector()(2): Could not fit a spline to the psVector.\n");
    294             return(NULL);
    295         }
    296         //        PS_PRINT_SPLINE(mySpline);
    297 
    298         // For each element of the new vector, convert the x-ordinate to that
    299         // of the old vector, use the fitted polynomial to determine the
    300         // interpolated value at that point, and set the new vector.
    301         for (i=0;i<n;i++) {
    302             // Scale to [0 : overscanVector->n - 1]
    303             x = ((psF32) i) * ((psF32) (overscanVector->n-1)) / ((psF32) n);
    304             newVec->data.F32[i] = psSpline1DEval(mySpline, x);
    305         }
    306         if (mustFreeSpline ==1) {
    307             psFree(mySpline);
    308         }
    309         //        PS_VECTOR_PRINT_F32(newVec);
    310 
    311 
    312     } else {
    313         psError(PS_ERR_UNKNOWN, true, "unknown fit type.  Returning NULL.\n");
    314         psFree(newVec);
    315         return(NULL);
    316     }
    317 
    318     psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4,
    319             "---- ScaleOverscanVector() exit ----\n");
    320     return(newVec);
    321 }
    322 
    323 #endif
     194                 "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options "
     195                 "have been specified\n");
     196    }
     197    return opt;
     198}
     199
    324200
    325201// Produce an overscan vector from an array of pixels
     
    329205                               )
    330206{
     207    assert(overscanOpts);
     208    assert(pixels);
     209    assert(myStats);
     210
    331211    // Reduce the overscans
    332212    psVector *reduced = psVectorAlloc(pixels->n, PS_TYPE_F32); // Overscan for each row
     
    416296    psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4,
    417297            "---- pmSubtractBias() begin ----\n");
    418     PS_ASSERT_READOUT_NON_NULL(in, NULL);
    419     PS_ASSERT_READOUT_NON_EMPTY(in, NULL);
    420     PS_ASSERT_READOUT_TYPE(in, PS_TYPE_F32, NULL);
     298    PS_ASSERT_PTR_NON_NULL(in, NULL);
     299    PS_ASSERT_IMAGE_NON_NULL(in->image, NULL);
     300    PS_ASSERT_IMAGE_TYPE(in->image, PS_TYPE_F32, NULL);
     301    PS_ASSERT_PTR_NON_NULL(overscanOpts, NULL);
     302    if (bias) {
     303        PS_ASSERT_IMAGE_NON_NULL(bias->image, NULL);
     304        PS_ASSERT_IMAGE_TYPE(bias->image, PS_TYPE_F32, NULL);
     305    }
     306    if (dark) {
     307        PS_ASSERT_IMAGE_NON_NULL(dark->image, NULL);
     308        PS_ASSERT_IMAGE_TYPE(dark->image, PS_TYPE_F32, NULL);
     309    }
    421310
    422311    psImage *image = in->image;         // The input image
Note: See TracChangeset for help on using the changeset viewer.