IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15160


Ignore:
Timestamp:
Oct 2, 2007, 9:33:35 AM (19 years ago)
Author:
gusciora
Message:

First version of these tests

Location:
trunk/psModules/test/detrend
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/test/detrend/tap_pmFlatField.c

    r13879 r15160  
    1 /** @file tst_pmFlatField.c
    2  *
    3  *  @brief Contains the tests for pmFlatField.c:
    4  *
    5  *    Test A - Divide input image by flat image
    6  *    Test B - Mask flat image data
    7  *    Test C - Mask flat image data starting with non-null mask
    8  *    Test E - Attempt to use null input image
    9  *    Test F - Attempt tp use null flat image
    10  *    Test G - Attempt to use input image bigger than flat image
    11  *    Test H - Attempt to use input image mask bigger than flat image
    12  *    Test I - Attempt to use offset greater than input image
    13  *    Test J - Attempt to use complex input image
    14  *    Test K - Attempt to use complex flat image
    15  *    Test L - Attempt to use non-equal input and flat image types
    16  *    Test M - Attempt to use non-mask type mask image
     1/** @file tap_pmFlatField.c
    172 *
    183 * XXX: Added a mask argument to pmFlatField().  Must add tests.  For now, all
    194 * masks are NULL.
    205 *
    21  *  @author Ross Harman, MHPCC
    22  *
    236 *  XXX: I added the CELL.TRIMSEC region code but there are not tests for it.
    247 *
    25  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    26  *  @date $Date: 2007-06-19 18:28:38 $
    27  *
    28  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    298 */
    309#include <stdio.h>
     
    3413#include "tap.h"
    3514#include "pstap.h"
    36 #define BADFLAT 0
    37 
    38 #define CREATE_AND_SET_IMAGE(NAME,TYPE,VALUE,NROWS,NCOLS)                                                    \
    39 psImage *NAME = (psImage*)psImageAlloc(NCOLS,NROWS,PS_TYPE_##TYPE);                                          \
    40 for(int i=0; i<NAME->numRows; i++) {                                                                         \
    41     for(int j=0; j<NAME->numCols; j++) {                                                                     \
    42         NAME->data.TYPE[i][j] = VALUE;                                                                       \
    43     }                                                                                                        \
     15#define BADFLAT                 0
     16#define VERBOSE                 1
     17#define ERR_TRACE_LEVEL         10
     18#define TEST_NUM_ROWS           8
     19#define TEST_NUM_COLS           8
     20#define NUM_BIAS_DATA           2
     21#define NUM_HDUS                8
     22#define MISC_NUM                32
     23#define MISC_NAME              "META00"
     24#define CELL_ALLOC_NAME        "CellName"
     25#define NUM_READOUTS            3
     26#define BASE_IMAGE              10
     27#define BASE_MASK               40
     28#define BASE_WEIGHT             70
     29
     30/******************************************************************************
     31generateSimpleReadout(): This function generates a pmReadout data structure and then
     32populates its members with real data.
     33 *****************************************************************************/
     34pmReadout *generateSimpleReadout(pmCell *cell)
     35{
     36    pmReadout *readout = pmReadoutAlloc(cell);
     37    readout->image = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     38    for (int i=0;i<TEST_NUM_ROWS;i++) {
     39        for (int j=0;j<TEST_NUM_COLS;j++) {
     40            readout->image->data.F32[i][j] = (float) (i + j);
     41        }
     42    }
     43    readout->mask = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8);
     44    readout->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     45    for (psS32 i = 0 ; i < NUM_BIAS_DATA ; i++) {
     46        psImage *tmpImage = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     47        psImageInit(tmpImage, (double) i);
     48        psListAdd(readout->bias, PS_LIST_HEAD, tmpImage);
     49        psFree(tmpImage);
     50    }
     51    psMetadataAddS32(readout->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     52    return(readout);
    4453}
    4554
    46 
    47 void testFlatField()
     55/******************************************************************************
     56generateSimpleCell(): This function generates a pmCell data structure and then
     57populates its members with real data.
     58 *****************************************************************************/
     59pmCell *generateSimpleCell(pmChip *chip)
    4860{
    49     // Test A - Divide input image by flat image
    50     CREATE_AND_SET_IMAGE(inImage,F64,6.0,3,3)
    51     pmReadout *inReadout = pmReadoutAlloc(NULL);
    52     inReadout->image = inImage;
    53     inReadout->row0 = 0;
    54     inReadout->col0 = 0;
    55     CREATE_AND_SET_IMAGE(inMask, U8, 0, 3,3);
    56     inReadout->mask = inMask;
    57     CREATE_AND_SET_IMAGE(flatImage1,F64,2.0,3,3)
    58     pmReadout *flatReadout = pmReadoutAlloc(NULL);
    59     flatReadout->row0 = 0;
    60     flatReadout->col0 = 0;
    61     flatReadout->image = flatImage1;
    62     if ( !pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    63         psError(PS_ERR_UNKNOWN,true,"Test A - Returned false should be true");
    64         return;
    65     }
    66 
    67 
    68     // Test B - Mask flat image data
    69     CREATE_AND_SET_IMAGE(flatImage2,F64,0.0,3,3)
    70     flatReadout->image = flatImage2;
    71     if ( !pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    72         psError(PS_ERR_UNKNOWN,true,"Test B - Returned false should be true");
    73         return;
    74     }
    75 
    76 
    77     // Test C - Mask flat image data starting with non-null mask
    78     flatImage2->data.F64[0][0] = 3.0;
    79     flatImage2->data.F64[0][1] = -3.0;
    80     CREATE_AND_SET_IMAGE(mask1,U8,0,3,3);
    81     psFree(inReadout->mask);
    82     inReadout->mask = mask1;
    83     if ( !pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    84         psError(PS_ERR_UNKNOWN,true,"Test C - Returned false should be true");
    85         return;
    86     }
    87 
    88 
    89     // Test D - Attempt to use null flat readout
    90     if( pmFlatField(inReadout, NULL, BADFLAT) ) {
    91         psError(PS_ERR_UNKNOWN,true,"Test D - Returned true should be false");
    92         return;
    93     }
    94 
    95 
    96 
    97     // Test E - Attempt to use null input image
    98     psImage *temp = inReadout->image;
    99     inReadout->image = NULL;
    100     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    101         psError(PS_ERR_UNKNOWN,true,"Test E - Returned true should be false" );
    102         return;
    103     }
    104     inReadout->image = temp    ;
    105 
    106 
    107 
    108     // Test F - Attempt tp use null flat image
    109     temp = flatReadout->image;
    110     flatReadout->image = NULL;
    111     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    112         psError(PS_ERR_UNKNOWN,true,"Test F - Returned true should be false" );
    113         return;
    114     }
    115     flatReadout->image = temp;
    116 
    117 
    118 
    119     // Test G - Attempt to use input image bigger than flat image
    120     CREATE_AND_SET_IMAGE(smallFlat,F64,0.0,2,2);
    121     temp = flatReadout->image;
    122     flatReadout->image = smallFlat;
    123     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    124         psError(PS_ERR_UNKNOWN,true,"Test G - Returned true should be false");
    125         return;
    126     }
    127     flatReadout->image = temp;
    128 
    129 
    130 
    131     // Test H - Attempt to use input image mask bigger than flat image
    132     CREATE_AND_SET_IMAGE(largeMask,F64,0.0,5,5);
    133     inReadout->mask = largeMask;
    134     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    135         psError(PS_ERR_UNKNOWN,true,"Test H - Returned true should be false");
    136         return;
    137     }
    138     inReadout->mask = mask1;
    139 
    140 
    141 
    142     // Test I - Attempt to use offset greater than input image
    143     *(int*)&inReadout->col0 = 50;
    144     *(int*)&inReadout->row0 = 50;
    145     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    146         psError(PS_ERR_UNKNOWN,true,"Test I - Returned true should be false");
    147         return;
    148     }
    149     *(int*)&inReadout->col0 = 0;
    150     *(int*)&inReadout->row0 = 0;
    151 
    152 
    153 
    154 //    // Test J - Attempt to use complex input image
    155 //    *(psElemType* ) & inReadout->image->type.type = PS_TYPE_C64;
    156 //    if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    157 //        psError(PS_ERR_UNKNOWN,true,"Test J - Returned true should be false");
    158 //        return;
    159 //    }
    160 //    *(psElemType* ) & inReadout->image->type.type = PS_TYPE_F64;
    161 
    162 
    163 
    164 //    // Test K - Attempt to use complex flat image
    165 //    *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_C64;
    166 //    if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    167 //        psError(PS_ERR_UNKNOWN,true,"Test K - Returned ture should be false");
    168 //        return;
    169 //    }
    170 //    *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_F64;
    171 
    172 
    173     // Test L - Attempt to use non-equal input and flat image types
    174     *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_F32;
    175     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    176         psError(PS_ERR_UNKNOWN,true,"Test L - Returned true should be false");
    177         return;
    178     }
    179     *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_F64;
    180 
    181 
    182     // Test M - Attempt to use non-mask type mask image
    183     *(psElemType* ) & inReadout->mask->type.type = PS_TYPE_F32;
    184     if ( pmFlatField(inReadout, flatReadout, BADFLAT) ) {
    185         psError(PS_ERR_UNKNOWN,true,"Test M - Returned true should be false");
    186         return;
    187     }
    188     *(psElemType* ) & inReadout->mask->type.type = PS_TYPE_MASK;
    189 
    190 
    191     // Free memory
    192     psFree(inReadout);
    193     psFree(flatReadout);
    194     //psFree(inImage);
    195     psFree(flatImage1);
    196     //psFree(flatImage1);
    197     psFree(smallFlat);
    198     psFree(largeMask);
     61    pmCell *cell = pmCellAlloc(chip, CELL_ALLOC_NAME);
     62
     63    psMetadataAddS32(cell->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     64    psMetadataAddS32(cell->concepts, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     65    psArrayRealloc(cell->readouts, NUM_READOUTS);
     66    cell->hdu = pmHDUAlloc("cellExtName");
     67    for (int i = 0 ; i < NUM_READOUTS ; i++) {
     68        cell->readouts->data[i] = generateSimpleReadout(cell);
     69    }
     70
     71    bool rc = pmConfigFileRead(&cell->hdu->format, "../camera/data/camera0/format0.config", "Camera format 0");
     72    if (!rc) {
     73        diag("pmConfigFileRead() was unsuccessful (from generateSimpleCell())");
     74    }
     75
     76    cell->hdu->images = psArrayAlloc(NUM_HDUS);
     77    cell->hdu->masks = psArrayAlloc(NUM_HDUS);
     78    cell->hdu->weights = psArrayAlloc(NUM_HDUS);
     79    for (int k = 0 ; k < NUM_HDUS ; k++) {
     80        cell->hdu->images->data[k]  = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     81        cell->hdu->masks->data[k]   = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_MASK);
     82        cell->hdu->weights->data[k] = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     83        psImageInit(cell->hdu->images->data[k], (float) (BASE_IMAGE+k));
     84        psImageInit(cell->hdu->masks->data[k], (psU8) (BASE_MASK+k));
     85        psImageInit(cell->hdu->weights->data[k], (float) (BASE_WEIGHT+k));
     86    }
     87
     88    //XXX: Should the region be set some other way?  Like through the various config files?
     89//    psRegion *region = psRegionAlloc(0.0, TEST_NUM_COLS-1, 0.0, TEST_NUM_ROWS-1);
     90    psRegion *region = psRegionAlloc(0.0, 0.0, 0.0, 0.0);
     91    // You shouldn't have to remove the key from the metadata.  Find out how to simply change the key value.
     92    psMetadataRemoveKey(cell->concepts, "CELL.TRIMSEC");
     93    psMetadataAddPtr(cell->concepts, PS_LIST_TAIL|PS_META_REPLACE, "CELL.TRIMSEC", PS_DATA_REGION, "I am a region", region);
     94    psFree(region);
     95    return(cell);
     96}
     97
     98void myFreeCell(pmCell *cell)
     99{
     100    for (int k = 0 ; k < cell->readouts->n ; k++) {
     101        psFree(cell->readouts->data[k]);
     102    }
     103    psFree(cell);
    199104}
    200105
     
    203108    psLogSetFormat("HLNM");
    204109    psLogSetLevel(PS_LOG_INFO);
    205     plan_tests(20);
    206 
    207     testFlatField();
     110    plan_tests(28);
     111
     112
     113    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     114    // Test pmFlatField() with NULL input psReadout
     115    {
     116        psMemId id = psMemGetId();
     117        pmReadout *in = generateSimpleReadout(NULL);
     118        pmReadout *flat = generateSimpleReadout(NULL);
     119        ok(!pmFlatField(NULL, flat, 0), "pmFlatField(NULL, flat, 0) returned FALSE");
     120        psFree(in);
     121        psFree(flat);
     122        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     123    }
     124
     125
     126    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     127    // Test pmFlatField() with NULL input psReadout->image
     128    {
     129        psMemId id = psMemGetId();
     130        pmReadout *in = generateSimpleReadout(NULL);
     131        psFree(in->image);
     132        in->image = NULL;
     133        pmReadout *flat = generateSimpleReadout(NULL);
     134        ok(!pmFlatField(in, flat, 0), "pmFlatField(in, flat, 0) returned FALSE with NULL input psReadout->image");
     135        psFree(in);
     136        psFree(flat);
     137        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     138    }
     139
     140    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     141    // Test pmFlatField() with NULL input psReadout->image
     142    {
     143        psMemId id = psMemGetId();
     144        pmReadout *in = generateSimpleReadout(NULL);
     145        psFree(in->image);
     146        in->image = psImageAlloc(0, 0, PS_TYPE_F32);
     147        pmReadout *flat = generateSimpleReadout(NULL);
     148        ok(!pmFlatField(in, flat, 0), "pmFlatField(in, flat, 0) returned FALSE with empty input psReadout->image");
     149        psFree(in);
     150        psFree(flat);
     151        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     152    }
     153
     154
     155    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     156    // Test pmFlatField() with NULL input flat
     157    {
     158        psMemId id = psMemGetId();
     159        pmReadout *in = generateSimpleReadout(NULL);
     160        pmReadout *flat = generateSimpleReadout(NULL);
     161        ok(!pmFlatField(in, NULL, 0), "pmFlatField(in, NULL, 0) returned FALSE");
     162        psFree(in);
     163        psFree(flat);
     164        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     165    }
     166
     167
     168    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     169    // Test pmFlatField() with NULL input flat->image
     170    {
     171        psMemId id = psMemGetId();
     172        pmReadout *in = generateSimpleReadout(NULL);
     173        pmReadout *flat = generateSimpleReadout(NULL);
     174        psFree(flat->image);
     175        flat->image = NULL;
     176        ok(!pmFlatField(in, NULL, 0), "pmFlatField(in, flat, 0) returned FALSE with NULL input flat->image");
     177        psFree(in);
     178        psFree(flat);
     179        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     180    }
     181
     182
     183    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     184    // Test pmFlatField() with NULL input flat->image
     185    {
     186        psMemId id = psMemGetId();
     187        pmReadout *in = generateSimpleReadout(NULL);
     188        pmReadout *flat = generateSimpleReadout(NULL);
     189        psFree(flat->image);
     190        flat->image = psImageAlloc(0, 0, PS_TYPE_F32);
     191        ok(!pmFlatField(in, NULL, 0), "pmFlatField(in, flat, 0) returned FALSE with empty input flat->image");
     192        psFree(in);
     193        psFree(flat);
     194        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     195    }
     196
     197
     198    // bool pmFlatField(pmReadout *in, pmReadout *flat, psMaskType badFlat)
     199    // Test pmFlatField() with differing types of flat/in image
     200    {
     201        psMemId id = psMemGetId();
     202        pmReadout *in = generateSimpleReadout(NULL);
     203        pmReadout *flat = generateSimpleReadout(NULL);
     204        psFree(flat->image);
     205        flat->image = psImageAlloc(0, 0, PS_TYPE_F64);
     206        ok(!pmFlatField(in, NULL, 0), "pmFlatField(in, flat, 0) returned FALSE with differing types of flat/in image");
     207        psFree(in);
     208        psFree(flat);
     209        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     210    }
     211
     212
     213    // Test pmFlatField() with input image larger than flat image
     214    {
     215        psMemId id = psMemGetId();
     216        pmReadout *in = generateSimpleReadout(NULL);
     217        pmReadout *flat = generateSimpleReadout(NULL);
     218        psFree(flat->image);
     219        flat->image = psImageAlloc(TEST_NUM_ROWS/2, TEST_NUM_COLS/2, PS_TYPE_F32);
     220        ok(!pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned FALSE with input image larger than flat image");
     221        psFree(in);
     222        psFree(flat);
     223        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     224    }
     225
     226
     227    // Test pmFlatField() with input image and flat image of differing types
     228    {
     229        psMemId id = psMemGetId();
     230        pmReadout *in = generateSimpleReadout(NULL);
     231        pmReadout *flat = generateSimpleReadout(NULL);
     232        psFree(flat->image);
     233        flat->image = psImageAlloc(TEST_NUM_ROWS, TEST_NUM_COLS, PS_TYPE_F64);
     234        ok(!pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned FALSE with input image and flat image of differing types");
     235        psFree(in);
     236        psFree(flat);
     237        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     238    }
     239
     240
     241    // Test pmFlatField() with input image mask smaller than input image
     242    {
     243        psMemId id = psMemGetId();
     244        pmReadout *in = generateSimpleReadout(NULL);
     245        pmReadout *flat = generateSimpleReadout(NULL);
     246        psFree(in->mask);
     247        in->mask = psImageAlloc(TEST_NUM_ROWS/2, TEST_NUM_COLS/2, PS_TYPE_MASK);
     248        ok(!pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned FALSE with input image mask smaller than input image");
     249        psFree(in);
     250        psFree(flat);
     251        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     252    }
     253
     254
     255    // Test pmFlatField() with input image mask of incorrect type
     256    {
     257        psMemId id = psMemGetId();
     258        pmReadout *in = generateSimpleReadout(NULL);
     259        pmReadout *flat = generateSimpleReadout(NULL);
     260        psFree(in->mask);
     261        in->mask = psImageAlloc(TEST_NUM_ROWS, TEST_NUM_COLS, PS_TYPE_F32);
     262        ok(!pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned FALSE with input image mask of incorrect type");
     263        psFree(in);
     264        psFree(flat);
     265        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     266    }
     267
     268
     269    // Test pmFlatField() with offset greater than input image
     270    // XXX: Must rewrite with offsets coming from metadata
     271    if (0) {
     272        psMemId id = psMemGetId();
     273        pmReadout *in = generateSimpleReadout(NULL);
     274        pmReadout *flat = generateSimpleReadout(NULL);
     275        *(int*)&in->col0 = 50;
     276        *(int*)&in->row0 = 50;
     277        ok(!pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned FALSE with offset greater than input image");
     278        psFree(in);
     279        psFree(flat);
     280        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     281    }
     282
     283
     284    // Test pmFlatField() with acceptable input data
     285    // Set the flat field to 1
     286    {
     287        psMemId id = psMemGetId();
     288        pmCell *cell = generateSimpleCell(NULL);
     289        pmReadout *in = generateSimpleReadout(cell);
     290        pmReadout *flat = generateSimpleReadout(cell);
     291        psImageInit(in->image, 6.0);
     292        psImageInit(in->mask, 0);
     293        psImageInit(flat->image, 2.0);
     294        ok(pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned TRUE with acceptable input data");
     295        bool errorFlag = false;
     296        for (int i = 0 ; i < in->image->numRows ; i++) {
     297            for (int j = 0 ; j < in->image->numCols ; j++) {
     298                if (in->image->data.F32[i][j] != 3.0) {
     299                    if (VERBOSE) diag("ERROR: image[%d][%d] is %.2f, should be 3.0", i, j,
     300                        in->image->data.F32[i][j]);
     301                }
     302                if (in->mask->data.PS_TYPE_MASK_DATA[i][j] != 0) {
     303                    if (VERBOSE) diag("ERROR: mask[%d][%d] is %d, should be 0", i, j,
     304                        in->image->data.PS_TYPE_MASK_DATA[i][j]);
     305                }
     306            }
     307        }
     308        ok(!errorFlag, "pmFlatField() set the image data correctly");
     309
     310        psFree(in);
     311        psFree(flat);
     312        myFreeCell(cell);
     313        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     314    }
     315
     316
     317    // Test pmFlatField() with acceptable input data
     318    // Set the flat field to -1
     319    {
     320        psMemId id = psMemGetId();
     321        pmCell *cell = generateSimpleCell(NULL);
     322        pmReadout *in = generateSimpleReadout(cell);
     323        pmReadout *flat = generateSimpleReadout(cell);
     324        psImageInit(in->image, 6.0);
     325        psImageInit(in->mask, 0);
     326        psImageInit(flat->image, -1.0);
     327        ok(pmFlatField(in, flat, 1), "pmFlatField(in, flat, 0) returned TRUE with acceptable input data");
     328        bool errorFlag = false;
     329        for (int i = 0 ; i < in->image->numRows ; i++) {
     330            for (int j = 0 ; j < in->image->numCols ; j++) {
     331                if (!isnan(in->image->data.F32[i][j])) {
     332                    if (VERBOSE) diag("ERROR: image[%d][%d] is %.2f, should be NAN", i, j,
     333                        in->image->data.F32[i][j]);
     334                }
     335                if (in->mask->data.PS_TYPE_MASK_DATA[i][j] != 1) {
     336                    if (VERBOSE) diag("ERROR: mask[%d][%d] is %d, should be 0", i, j,
     337                        in->image->data.PS_TYPE_MASK_DATA[i][j]);
     338                }
     339            }
     340        }
     341        ok(!errorFlag, "pmFlatField() set the image data correctly");
     342
     343        psFree(in);
     344        psFree(flat);
     345        myFreeCell(cell);
     346        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     347    }
    208348}
    209 
    210 
Note: See TracChangeset for help on using the changeset viewer.